INET Framework for OMNeT++/OMNEST
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 BasicDecider BasicMobility ChannelAccess Decider80211 SnrDecider CircleMobility ConstSpeedMobility LinearMobility LineSegmentsMobilityBase MassMobility NullMobility RectangleMobility AbstractRadio BasicSnrEval

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

Member Function Documentation

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

Function to get a pointer to the host module.

Referenced by AbstractRadio::changeChannel(), ChannelAccess::initialize(), initialize(), and BasicMobility::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:
idId of the module for the desired logging name
Returns:
logging name of module id or NULL if not found
See also:
logName
{
    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!

Reimplemented in Decider80211, SnrDecider, GilbertElliotSnr, SnrEval, SnrEval80211, BasicDecider, BasicSnrEval, AbstractRadio, ANSimMobility, BasicMobility, BonnMotionMobility, CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, RandomWPMobility, RectangleMobility, TurtleMobility, and ChannelAccess.

{
    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.

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.

Reimplemented in ChannelAccess.

{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.

{}

Member Data Documentation

bool BasicModule::coreDebug [protected]

Debug switch for the core modules.

Referenced by initialize().

bool BasicModule::debug [protected]

Debug switch for all other modules.

Referenced by initialize().

std::string BasicModule::loggingName [protected]

Log name of the host module.

Referenced by initialize().


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