NAMTrace Class Reference

#include <NAMTrace.h>

List of all members.


Detailed Description

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.

Author:
Andras Varga


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


Constructor & Destructor Documentation

NAMTrace::NAMTrace (  ) 

00026 {
00027     nams = NULL;
00028 }

NAMTrace::~NAMTrace (  )  [virtual]

00031 {
00032     if (nams)
00033     {
00034         nams->close();
00035         delete nams;
00036     }
00037 }


Member Function Documentation

int NAMTrace::assignNamId ( cModule *  node,
int  namid = -1 
)

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 }

bool NAMTrace::enabled (  )  const [inline]

Returns true if nam trace recording is enabled (filename was not "").

00070 {return nams!=NULL;}

int NAMTrace::getNamId ( cModule *  node  )  const

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 }

void NAMTrace::handleMessage ( cMessage *  msg  )  [protected, virtual]

00070 {
00071     error("This module doesn't process messages");
00072 }

void NAMTrace::initialize (  )  [protected, virtual]

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 }

std::ostream& NAMTrace::out (  )  [inline]

Returns the stream to which the trace events can be written.

00075 {ASSERT(nams!=NULL); return *nams;}


Member Data Documentation

int NAMTrace::lastnamid [private]

std::map<int,int> NAMTrace::modid2namid [private]

std::ofstream* NAMTrace::nams [private]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:22 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7