BasicModule.cc

Go to the documentation of this file.
00001 /* -*- mode:c++ -*- ********************************************************
00002  * file:        BasicModule.cc
00003  *
00004  * author:      Steffen Sroka
00005  *              Andreas Koepke
00006  *
00007  * copyright:   (C) 2004 Telecommunication Networks Group (TKN) at
00008  *              Technische Universitaet Berlin, Germany.
00009  *
00010  *              This program is free software; you can redistribute it
00011  *              and/or modify it under the terms of the GNU General Public
00012  *              License as published by the Free Software Foundation; either
00013  *              version 2 of the License, or (at your option) any later
00014  *              version.
00015  *              For further information see file COPYING
00016  *              in the top level directory
00017  ***************************************************************************
00018  * part of:     framework implementation developed by tkn
00019  **************************************************************************/
00020 
00021 
00022 #include <iostream>
00023 #include "BasicModule.h"
00024 
00025 #define coreEV (ev.isDisabled()||!coreDebug) ? (std::ostream&)ev : EV << loggingName << "::BasicModule: "
00026 
00034 void BasicModule::initialize(int stage)
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->getName();
00057         sprintf(&tmp[0], "[%d]", parent->getIndex());
00058         loggingName += tmp;
00059 
00060         // get a pointer to the NotificationBoard module
00061         nb = NotificationBoardAccess().get();
00062     }
00063 }
00064 
00065 cModule *BasicModule::findHost(void) const
00066 {
00067     cModule *mod;
00068     for (mod = getParentModule(); mod != 0; mod = mod->getParentModule())
00069         if (mod->getSubmodule("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 }
00076 
00089 const char *BasicModule::getLogName(int id)
00090 {
00091     BasicModule *mod;
00092     mod = (BasicModule *) simulation.getModule(id);
00093     if (mod->isSimple())
00094         return mod->logName();
00095     else if (mod->getSubmodule("snrEval"))
00096         return ((BasicModule *) mod->getSubmodule("snrEval"))->logName();
00097     else if (mod->getSubmodule("phy"))
00098         return ((BasicModule *) mod->getSubmodule("phy"))->logName();
00099     else
00100         return NULL;
00101 };