#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.
Definition at line 37 of file NAMTrace.h.
NAMTrace::NAMTrace | ( | ) |
Definition at line 23 of file NAMTrace.cc.
{ nams = NULL; }
NAMTrace::~NAMTrace | ( | ) | [virtual] |
Definition at line 28 of file NAMTrace.cc.
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.
Definition at line 72 of file NAMTrace.cc.
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).
Definition at line 78 of file NAMTrace.cc.
{ 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] |
Definition at line 67 of file NAMTrace.cc.
{
error("This module doesn't process messages");
}
void NAMTrace::initialize | ( | ) | [protected, virtual] |
Definition at line 37 of file NAMTrace.cc.
{ 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 "").
Definition at line 69 of file NAMTrace.h.
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.
Definition at line 74 of file NAMTrace.h.
Referenced by NAMTraceWriter::recordLinkEvent(), NAMTraceWriter::recordNodeEvent(), and NAMTraceWriter::recordPacketEvent().
int NAMTrace::lastnamid [protected] |
Definition at line 42 of file NAMTrace.h.
Referenced by assignNamId(), and initialize().
std::map<int,int> NAMTrace::modid2namid [protected] |
Definition at line 43 of file NAMTrace.h.
Referenced by assignNamId(), and getNamId().
std::ofstream* NAMTrace::nams [protected] |
Definition at line 40 of file NAMTrace.h.
Referenced by initialize(), NAMTrace(), and ~NAMTrace().