#include <NAMTrace.h>
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.
Public Member Functions | |
NAMTrace () | |
virtual | ~NAMTrace () |
int | assignNamId (cModule *node, int namid=-1) |
int | getNamId (cModule *node) const |
bool | enabled () const |
std::ostream & | out () |
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
Private Attributes | |
std::ofstream * | nams |
int | lastnamid |
std::map< int, int > | modid2namid |
|
00026 { 00027 nams = NULL; 00028 }
|
|
|
|
Assign a nam ID to the given module (host or router). -1 means auto-assigned ID. 00075 { 00076 // FIXME make sure nobody's using that namid yet 00077 return modid2namid[node->id()] = namid==-1 ? ++lastnamid : namid; 00078 }
|
|
Returns true if nam trace recording is enabled (filename was not ""). 00070 {return nams!=NULL;}
|
|
Returns the nam ID of the given module (host or router). assignNamId() must have been called for the given module before, at least with -1 (auto-ID). 00081 { 00082 int modid = node->id(); 00083 std::map<int,int>::const_iterator it = modid2namid.find(modid); 00084 if (it == modid2namid.end()) 00085 error("getNamId(): assignNamId() on module '%s' not yet called", node->fullPath().c_str()); 00086 return it->second; 00087 }
|
|
00070 {
00071 error("This module doesn't process messages");
00072 }
|
|
00040 { 00041 lastnamid = 0; 00042 nams = NULL; 00043 const char *namlog = par("logfile"); 00044 if (namlog && namlog[0]) 00045 { 00046 EV << "nam tracing enabled (file " << namlog << ")" << endl; 00047 00048 // open namlog for write 00049 if (unlink(namlog)!=0 && errno!=ENOENT) 00050 error("cannot remove old `%s' file: %s", namlog, strerror(errno)); 00051 nams = new std::ofstream; 00052 nams->open(namlog, std::ios::out); 00053 if (nams->fail()) 00054 error("cannot open `%s' for write", namlog); 00055 00056 // print prolog into the file 00057 const char *prolog = par("prolog"); 00058 if (strlen(prolog)) 00059 { 00060 cStringTokenizer tokenizer(prolog, ";"); 00061 const char *token; 00062 while((token = tokenizer.nextToken())!=NULL) 00063 *nams << token << endl; 00064 *nams << std::flush; 00065 } 00066 } 00067 }
|
|
Returns the stream to which the trace events can be written. 00075 {ASSERT(nams!=NULL); return *nams;}
|
|
|
|
|
|
|