#include <BasicModule.h>
Inheritance diagram for BasicModule:
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).
Andreas Koepke
Protected Member Functions | |
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, cPolymorphic *details) |
Called by the NotificationBoard whenever a change of a category occurs to which we have subscribed. Redefined from INotifiable. | |
Protected Attributes | |
NotificationBoard * | nb |
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. |
cModule * BasicModule::findHost | ( | void | ) | const [protected] |
Function to get a pointer to the host module.
00066 { 00067 cModule *mod; 00068 for (mod = parentModule(); mod != 0; mod = mod->parentModule()) 00069 if (mod->submodule("notificationBoard")) 00070 break; 00071 if (!mod) 00072 error("findHost(): host module not found (it should have a submodule named notificationBoard)"); 00073 00074 return mod; 00075 }
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.
id | Id of the module for the desired logging name |
00090 { 00091 BasicModule *mod; 00092 mod = (BasicModule *) simulation.module(id); 00093 if (mod->isSimple()) 00094 return mod->logName(); 00095 else if (mod->submodule("snrEval")) 00096 return ((BasicModule *) mod->submodule("snrEval"))->logName(); 00097 else if (mod->submodule("phy")) 00098 return ((BasicModule *) mod->submodule("phy"))->logName(); 00099 else 00100 return NULL; 00101 };
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 ANSimMobility, BasicMobility, BonnMotionMobility, CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, RandomWPMobility, RectangleMobility, TurtleMobility, Decider80211, SnrDecider, GilbertElliotSnr, SnrEval, SnrEval80211, BasicDecider, BasicSnrEval, AbstractRadio, and ChannelAccess.
00035 { 00036 cModule *parent = findHost(); 00037 char tmp[8]; 00038 00039 if (stage == 0) 00040 { 00041 00042 if (hasPar("coreDebug")) 00043 coreDebug = par("coreDebug").boolValue(); 00044 else 00045 coreDebug = false; 00046 if (hasPar("debug")) 00047 debug = par("debug").boolValue(); 00048 else 00049 debug = false; 00050 00051 00052 // get the logging name of the host 00053 if (parent->hasPar("logName")) 00054 loggingName = parent->par("logName").stringValue(); 00055 else 00056 loggingName = parent->name(); 00057 sprintf(&tmp[0], "[%d]", parent->index()); 00058 loggingName += tmp; 00059 00060 // get a pointer to the NotificationBoard module 00061 nb = NotificationBoardAccess().get(); 00062 } 00063 }
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.
00098 { 00099 return loggingName.c_str(); 00100 };
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.
virtual void BasicModule::receiveChangeNotification | ( | int | category, | |
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.
bool BasicModule::coreDebug [protected] |
Debug switch for the core modules.
bool BasicModule::debug [protected] |
Debug switch for all other modules.
std::string BasicModule::loggingName [protected] |
Log name of the host module.
NotificationBoard* BasicModule::nb [protected] |
Cached pointer to the NotificationBoard module.