BaseUtility.cc

00001 #include "BaseUtility.h"
00002 #include "BaseWorldUtility.h"
00003 #include "FindModule.h"
00004 #include <assert.h>
00005 #include "Move.h"
00006 #include "BaseMobility.h"
00007 
00008 Define_Module(BaseUtility);
00009 
00010 void BaseUtility::initialize(int stage) {
00011   Blackboard::initialize(stage);
00012 
00013   if (stage == 0) {
00014         // subscribe to position changes
00015         Move moveBBItem;
00016         catMove = subscribe(this, &moveBBItem, findHost()->getId());
00017 
00018         catHostState = subscribe(this, &hostState, findHost()->getId());
00019         hostState.set(HostState::ACTIVE);
00020   }
00021   else if(stage == 1) {
00022     cModule* host = findHost();
00023     //check if necessary host modules are available
00024     //mobility module
00025     if(!FindModule<BaseMobility*>::findSubModule(host)) {
00026       opp_warning("No mobility module found in host with index %d!", host->getIndex());
00027     }
00028   }
00029 }
00030 
00031 cModule *BaseUtility::findHost(void)
00032 {
00033   return FindModule<>::findHost(this);
00034 }
00035 
00036 void BaseUtility::receiveBBItem(int category, const BBItem *details, int scopeModuleId)
00037 {
00038     //BaseModule::receiveBBItem(category, details, scopeModuleId);
00039 
00040     if(category == catMove)
00041     {
00042         const Move* m = static_cast<const Move*>(details);
00043         pos = m->getStartPos();
00044         coreEV << "new HostMove: " << m->info() << endl;
00045     }
00046     else if(category == catHostState)
00047     {
00048       const HostState* state = static_cast<const HostState*>(details);
00049     hostState = *state;
00050     coreEV << "new HostState: " << hostState.info() << endl;
00051     }
00052 }
00053 
00054 std::string BaseUtility::logName(void)
00055 {
00056     std::ostringstream ost;
00057   cModule *parent = findHost();
00058   parent->hasPar("logName") ?
00059     ost << parent->par("logName").stringValue() : ost << parent->getName();
00060   ost << "[" << parent->getIndex() << "]";
00061   return ost.str();
00062 }