Protected Member Functions | Protected Attributes

BasicModule Class Reference

Base class for all simple modules of a host that want to have access to the NotificationBoard module. More...

#include <BasicModule.h>

Inheritance diagram for BasicModule:
INotifiable

List of all members.

Protected Member Functions

virtual cModule * findHost (void) const
 Function to get a pointer to the host module.
const char * getLogName (int)
 Function to get the logging name of id.
virtual void initialize (int)
 Basic initialization for all modules.
virtual int numInitStages () const
 Divide initialization into two stages.
const char * logName (void) const
 Function to get the logging name of the host.
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 Called by the NotificationBoard whenever a change of a category occurs to which we have subscribed. Redefined from INotifiable.

Protected Attributes

NotificationBoardnb
 Cached pointer to the NotificationBoard module.
bool coreDebug
 Debug switch for the core modules.
bool debug
 Debug switch for all other modules.
std::string loggingName
 Log name of the host module.

Detailed Description

Base class for all simple modules of a host that want to have access to the NotificationBoard module.

The basic module additionally provides a function findHost() which returns a pointer to the host module.

There is no Define_Module() for this class because we use BasicModule only as a base class to derive all other module. There will never be a stand-alone BasicModule module (and that is why there is no Define_Module() and no .ned file for BasicModule).

See also:
NotificationBoard
Author:
Steffen Sroka
Andreas Koepke

Definition at line 53 of file BasicModule.h.


Member Function Documentation

cModule * BasicModule::findHost ( void   )  const [protected, virtual]

Function to get a pointer to the host module.

Definition at line 65 of file BasicModule.cc.

Referenced by initialize().

{
    cModule *mod;
    for (mod = getParentModule(); mod != 0; mod = mod->getParentModule())
        if (mod->getSubmodule("notificationBoard"))
            break;
    if (!mod)
        error("findHost(): host module not found (it should have a submodule named notificationBoard)");

    return mod;
}

const char * BasicModule::getLogName ( int  id  )  [protected]

Function to get the logging name of id.

This function returns the logging name of the module with the specified id. It can be used for logging messages to simplify debugging in TKEnv.

Only supports ids from simple module derived from the BasicModule or the nic compound module id.

Parameters:
id Id of the module for the desired logging name
Returns:
logging name of module id or NULL if not found
See also:
logName

Definition at line 89 of file BasicModule.cc.

{
    BasicModule *mod;
    mod = (BasicModule *) simulation.getModule(id);
    if (mod->isSimple())
        return mod->logName();
    else if (mod->getSubmodule("snrEval"))
        return ((BasicModule *) mod->getSubmodule("snrEval"))->logName();
    else if (mod->getSubmodule("phy"))
        return ((BasicModule *) mod->getSubmodule("phy"))->logName();
    else
        return NULL;
};

void BasicModule::initialize ( int  stage  )  [protected, virtual]

Basic initialization for all modules.

Subscription to NotificationBoard should be in stage==0, and firing notifications in stage==1 or later.

NOTE: You have to call this in the initialize() function of the inherited class!

Definition at line 34 of file BasicModule.cc.

{
    cModule *parent = findHost();
    char tmp[8];

    if (stage == 0)
    {

        if (hasPar("coreDebug"))
            coreDebug = par("coreDebug").boolValue();
        else
            coreDebug = false;
        if (hasPar("debug"))
            debug = par("debug").boolValue();
        else
            debug = false;


        // get the logging name of the host
        if (parent->hasPar("logName"))
            loggingName = parent->par("logName").stringValue();
        else
            loggingName = parent->getName();
        sprintf(&tmp[0], "[%d]", parent->getIndex());
        loggingName += tmp;

        // get a pointer to the NotificationBoard module
        nb = NotificationBoardAccess().get();
    }
}

const char* BasicModule::logName ( void   )  const [inline, protected]

Function to get the logging name of the host.

The logging name is the ned module name of the host (unless the host ned variable loggingName is specified). It can be used for logging messages to simplify debugging in TKEnv.

Definition at line 97 of file BasicModule.h.

Referenced by getLogName().

    {
      return loggingName.c_str();
    };

virtual int BasicModule::numInitStages (  )  const [inline, protected, virtual]

Divide initialization into two stages.

In the first stage (stage==0), modules subscribe to notification categories at NotificationBoard. The first notifications (e.g. about the initial values of some variables such as RadioState) should take place earliest in the second stage (stage==1), when everyone interested in them has already subscribed.

Definition at line 88 of file BasicModule.h.

{return 2;}

virtual void BasicModule::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
) [inline, protected, virtual]

Called by the NotificationBoard whenever a change of a category occurs to which we have subscribed. Redefined from INotifiable.

Implements INotifiable.

Definition at line 106 of file BasicModule.h.

{}


Member Data Documentation

bool BasicModule::coreDebug [protected]

Debug switch for the core modules.

Definition at line 60 of file BasicModule.h.

Referenced by initialize().

bool BasicModule::debug [protected]

Debug switch for all other modules.

Definition at line 63 of file BasicModule.h.

Referenced by initialize().

std::string BasicModule::loggingName [protected]

Log name of the host module.

Definition at line 66 of file BasicModule.h.

Referenced by initialize().

Cached pointer to the NotificationBoard module.

Definition at line 57 of file BasicModule.h.

Referenced by initialize().


The documentation for this class was generated from the following files: