basicModule

  
①.basic module 在blackboard 的基础上面,提供了findHost 这个函数,它是得到指向host module 的指针。还提供了hostIndex 返回host module 的下标
The latter one correspondes to the index shown in tkenv and comes in very handy for testing and
debugging using tkenv. It is used e.g. in all the 'print' macros used for debugging.
任何在Blackboard 中的publishing 在第一阶段初始化,但是其它任何subscription 必须在第二阶段初始化。
③const char *logName(void)const
 
       return loggingName.c_str();
 }
  这个函数的功能:得到host 的logging name,logging name 是host 中ned 模块的名字(除非host ned 变量的loggingName 是具体的)。这个函数可以用来在TKEnv 中调试用,可以纪录logging message.
/**
 * Any publishing on the Blackboard has to be in the first stage of
 * the initialization whereas any subscription to items published on
 * the Blackboard should go into the second stage of the
 * initialization. This concept avoids the "subscribe before
 * publish" problem.
 *
 * Search for the Blackboard module and assign a pointer to it.
 *
 * NOTE: You have to call this in the initialize() function of the
 * inherited class!
 */
void BasicModule::initialize(int stage)
{
  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->name();
    sprintf( &tmp[0], "[%d]", parent->index() );
    loggingName += tmp;
    // get a pointer to the bb module
    bb = dynamic_cast<Blackboard *>(findHost()->submodule("blackboard"));
    if(bb == 0){
      error("cannot find Blackboard");
    }
   
  }
  else if(stage==1){}
  else{
    error("initialize: no stage %d defined!", stage);
  }
}
cModule* BasicModule::findHost(void) const
{
  cModule *mod;
  for(mod=parentModule(); mod != 0; mod = mod->parentModule()){
    if( strstr(mod->name(), "host") != NULL ||
 strstr(mod->name(), "Host") != NULL)
      break;
  }
  if( !mod )
    error("findHost: no host module found!");
 
  return mod;
}
/**
 * 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.
 *
 * @param id Id of the module for the desired logging name
 * @return logging name of module id or NULL if not found
 * @sa logName
 **/
const char* BasicModule::getLogName( int id )
{
  BasicModule* mod;
  mod = (BasicModule*)simulation.module(id);
  if( mod->isSimple() )
    return mod->logName();
  else if( mod->submodule("snrEval") )
    return ((BasicModule*) mod->submodule("snrEval"))->logName();
  else if( mod->submodule("phy") )
    return ((BasicModule*) mod->submodule("phy"))->logName();
  else
    return NULL;
};

你可能感兴趣的:(function,Module,null,logging,initialization,debugging)