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 ()
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

Constructor & Destructor Documentation

NAMTrace::NAMTrace (  ) 

00024 {
00025     nams = NULL;
00026 }

NAMTrace::~NAMTrace (  )  [virtual]

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


Member Function Documentation

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

00038 {
00039     lastnamid = 0;
00040     nams = NULL;
00041     const char *namlog = par("logfile");
00042     if (namlog && namlog[0])
00043     {
00044         EV << "nam tracing enabled (file " << namlog << ")" << endl;
00045 
00046         // open namlog for write
00047         if (unlink(namlog)!=0 && errno!=ENOENT)
00048             error("cannot remove old `%s' file: %s", namlog, strerror(errno));
00049         nams = new std::ofstream;
00050         nams->open(namlog, std::ios::out);
00051         if (nams->fail())
00052             error("cannot open `%s' for write", namlog);
00053 
00054         // print prolog into the file
00055         const char *prolog = par("prolog");
00056         if (strlen(prolog))
00057         {
00058             cStringTokenizer tokenizer(prolog, ";");
00059             const char *token;
00060             while((token = tokenizer.nextToken())!=NULL)
00061                     *nams << token << endl;
00062             *nams << std::flush;
00063         }
00064     }
00065 }

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

00068 {
00069     error("This module doesn't process messages");
00070 }

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().

00073 {
00074     // FIXME make sure nobody's using that namid yet
00075     return modid2namid[node->getId()] = namid==-1 ? ++lastnamid : namid;
00076 }

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).

00079 {
00080     int modid = node->getId();
00081     std::map<int,int>::const_iterator it = modid2namid.find(modid);
00082     if (it == modid2namid.end())
00083         error("getNamId(): assignNamId() on module '%s' not yet called", node->getFullPath().c_str());
00084     return it->second;
00085 }

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().

00069 {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().

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


Member Data Documentation

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

Referenced by initialize(), NAMTrace(), and ~NAMTrace().

int NAMTrace::lastnamid [protected]

Referenced by assignNamId(), and initialize().

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

Referenced by assignNamId(), and getNamId().


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:20 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5