INET Framework for OMNeT++/OMNEST
|
#include <NAMTrace.h>
Public Member Functions | |
NAMTrace () | |
virtual | ~NAMTrace () |
virtual int | assignNamId (cModule *node, int namid=-1) |
virtual int | getNamId (cModule *node) const |
virtual bool | isEnabled () const |
std::ostream & | out () |
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
Protected Attributes | |
std::ofstream * | nams |
int | lastnamid |
std::map< int, int > | modid2namid |
Provides a central place for storing the output stream of an ns2 nam trace.
Only one NAMTrace module should be in a network (or, per subnetwork), and hosts/routers should contain a NAMTraceWriter module each. Every NAMTraceWriters write to an output stream which they obtain from the out() method of the shared NAMTrace module.
See NED file for more info.
NAMTrace::NAMTrace | ( | ) |
{ nams = NULL; }
int NAMTrace::assignNamId | ( | cModule * | node, |
int | namid = -1 |
||
) | [virtual] |
Assign a nam ID to the given getModule(host or router). -1 means auto-assigned ID.
Referenced by NAMTraceWriter::initialize().
{ // FIXME make sure nobody's using that namid yet return modid2namid[node->getId()] = namid==-1 ? ++lastnamid : namid; }
int NAMTrace::getNamId | ( | cModule * | node | ) | const [virtual] |
Returns the nam ID of the given getModule(host or router). assignNamId() must have been called for the given module before, at least with -1 (auto-ID).
{ int modid = node->getId(); std::map<int,int>::const_iterator it = modid2namid.find(modid); if (it == modid2namid.end()) error("getNamId(): assignNamId() on module '%s' not yet called", node->getFullPath().c_str()); return it->second; }
void NAMTrace::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
{
error("This module doesn't process messages");
}
void NAMTrace::initialize | ( | ) | [protected, virtual] |
{ lastnamid = 0; nams = NULL; const char *namlog = par("logfile"); if (namlog && namlog[0]) { EV << "nam tracing enabled (file " << namlog << ")" << endl; // open namlog for write if (unlink(namlog)!=0 && errno!=ENOENT) error("cannot remove old `%s' file: %s", namlog, strerror(errno)); nams = new std::ofstream; nams->open(namlog, std::ios::out); if (nams->fail()) error("cannot open `%s' for write", namlog); // print prolog into the file const char *prolog = par("prolog"); if (strlen(prolog)) { cStringTokenizer tokenizer(prolog, ";"); const char *token; while((token = tokenizer.nextToken())!=NULL) *nams << token << endl; *nams << std::flush; } } }
virtual bool NAMTrace::isEnabled | ( | ) | const [inline, virtual] |
Returns true if nam trace recording is enabled (filename was not "").
Referenced by NAMTraceWriter::initialize(), NAMTraceWriter::receiveChangeNotification(), NAMTraceWriter::recordLinkEvent(), NAMTraceWriter::recordNodeEvent(), and NAMTraceWriter::recordPacketEvent().
{return nams!=NULL;}
std::ostream& NAMTrace::out | ( | ) | [inline] |
Returns the stream to which the trace events can be written.
Referenced by NAMTraceWriter::recordLinkEvent(), NAMTraceWriter::recordNodeEvent(), and NAMTraceWriter::recordPacketEvent().
int NAMTrace::lastnamid [protected] |
Referenced by assignNamId(), and initialize().
std::map<int,int> NAMTrace::modid2namid [protected] |
Referenced by assignNamId(), and getNamId().
std::ofstream* NAMTrace::nams [protected] |
Referenced by initialize(), NAMTrace(), and ~NAMTrace().