Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cmessage.h

00001 //==========================================================================
00002 //   CMESSAGE.H  -  header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cMessage : message and event object
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2003 Andras Varga
00014 
00015   This file is distributed WITHOUT ANY WARRANTY. See the file
00016   `license' for details on this and other legal matters.
00017 *--------------------------------------------------------------*/
00018 
00019 #ifndef __CMESSAGE_H
00020 #define __CMESSAGE_H
00021 
00022 #include <time.h>
00023 #include "cobject.h"
00024 #include "carray.h"
00025 #include "cpar.h"
00026 #include "csimul.h"
00027 
00028 //=== classes mentioned:
00029 class cPar;
00030 class cGate;
00031 class cChannel;
00032 class cModule;
00033 class cSimpleModule;
00034 class cCompoundModule;
00035 class cSimulation;
00036 class cMessageHeap;
00037 
00038 
00047 enum eMessageKind
00048 {
00049   MK_STARTER = -1,  
00050   MK_TIMEOUT = -2,  
00051   MK_PACKET  = -3,  
00052   MK_INFO    = -4   
00053 };
00054 
00055 //==========================================================================
00056 
00084 class SIM_API cMessage : public cObject
00085 {
00086     friend class cMessageHeap;
00087 
00088   private:
00089     int msgkind;            // message kind -- meaning is user-defined
00090     int prior;              // priority -- used for scheduling msgs with equal times
00091     long len;               // length of message -- used for bit errors and transm.delay
00092     bool error;             // bit error occurred during transmission
00093     simtime_t tstamp;       // time stamp -- user-defined meaning
00094     cArray *parlistp;       // ptr to list of parameters
00095     cMessage *encapmsg;     // ptr to encapsulated msg
00096     void *contextptr;       // a stored pointer -- user-defined meaning
00097 
00098     int frommod,fromgate;   // source module and gate IDs -- set internally
00099     int tomod,togate;       // dest. module and gate IDs -- set internally
00100     simtime_t created;      // creation time -- set be constructor
00101     simtime_t sent,delivd;  // time of sending & delivery -- set internally
00102 
00103     int heapindex;             // used by cMessageHeap (-1 if not on heap)
00104     unsigned long insertordr;  // used by cMessageHeap
00105 
00106 
00107     // helper function
00108     void _createparlist();
00109 
00110     // global variables for statistics
00111     static unsigned long total_msgs;
00112     static unsigned long live_msgs;
00113 
00114   public:
00117 
00121     cMessage(const cMessage& msg);
00122 
00126     explicit cMessage(const char *name=NULL, int k=0, long len=1, int pri=0, bool err=false);
00127 
00131     virtual ~cMessage();
00132 
00137     cMessage& operator=(const cMessage& msg);
00139 
00142 
00147     virtual cObject *dup() const  {return new cMessage(*this);}
00148 
00153     virtual void info(char *buf);
00154 
00159     virtual void forEach( ForeachFunc do_fn );
00160 
00165     virtual void writeContents(ostream& os);
00166 
00172     virtual int netPack();
00173 
00179     virtual int netUnpack();
00181 
00184 
00189     void setKind(int k)     {msgkind=k;}
00190 
00196     void setPriority(int p) {prior=p;}
00197 
00203     void setLength(long l);
00204 
00212     void addLength(long delta);
00213 
00217     void setBitError(bool err) {error=err;}
00218 
00222     void setTimestamp() {tstamp=simulation.simTime();}
00223 
00227     void setTimestamp(simtime_t t) {tstamp=t;}
00228 
00232     void setContextPointer(void *p) {contextptr=p;}
00233 
00237     int  kind() const     {return msgkind;}
00238 
00242     int  priority() const {return prior;}
00243 
00247     long length() const   {return len;}
00248 
00252     bool hasBitError() const {return error;}
00253 
00257     simtime_t timestamp() const {return tstamp;}
00258 
00262     unsigned long insertOrder() const {return insertordr;}
00263 
00267     void *contextPointer() const {return contextptr;}
00269 
00272 
00286     cArray& parList()
00287         {if (!parlistp) _createparlist(); return *parlistp;}
00288 
00299     cPar& addPar(const char *s)  {cPar *p=new cPar(s);parList().add(p);return *p;}
00300 
00310     cPar& addPar(cPar *p)  {parList().add(p); return *p;}
00311 
00315     cPar& addPar(cPar& p)  {parList().add(&p); return p;}
00316 
00328     cPar& par(int n);
00329 
00342     cPar& par(const char *s);
00343 
00354     int findPar(const char *s) const;
00355 
00366     bool hasPar(const char *s) const {return findPar(s)>=0;}
00367 
00377     cObject *addObject(cObject *p)  {parList().add(p); return p;}
00378 
00389     cObject *getObject(const char *s)  {return parList().get(s);}
00390 
00400     bool hasObject(const char *s)  {return !parlistp ? false : parlistp->find(s)>=0;}
00401 
00412     cObject *removeObject(const char *s)  {return parList().remove(s);}
00413 
00424     cObject *removeObject(cObject *p)  {return parList().remove(p);}
00426 
00429 
00434     void encapsulate(cMessage *msg);
00435 
00441     cMessage *decapsulate();
00442 
00446     cMessage *encapsulatedMsg() const {return encapmsg;}
00448 
00451 
00455     bool isSelfMessage() const {return togate==-1;}
00456 
00460     bool isScheduled() const {return heapindex!=-1;}
00461 
00467     cGate *senderGate() const;
00468 
00474     cGate *arrivalGate() const;
00475 
00480     int senderModuleId() const {return frommod;}
00481 
00486     int senderGateId() const   {return fromgate;}
00487 
00492     int arrivalModuleId() const {return tomod;}
00493 
00498     int arrivalGateId() const  {return togate;}
00499 
00503     simtime_t creationTime() const {return created;}
00504 
00509     simtime_t sendingTime()  const {return sent;}
00510 
00515     simtime_t arrivalTime()  const {return delivd;}
00516 
00520     bool arrivedOn(int g) const {return g==togate;}
00521 
00526     bool arrivedOn(const char *s, int g=0);
00528 
00531 
00537     virtual void setSentFrom(cModule *module, int gate, simtime_t t);
00538 
00544     virtual void setArrival(cModule *module, int gate);
00545 
00551     virtual void setArrival(cModule *module, int gate, simtime_t t);
00552 
00557     virtual void setArrivalTime(simtime_t t);
00559 
00562 
00569     virtual const char *displayString() const;
00570 
00575     static int cmpbydelivtime(cObject *one, cObject *other);
00576 
00582     static int cmpbypriority(cObject *one, cObject *other);
00583 
00588     static unsigned long totalMessageCount() {return total_msgs;}
00589 
00595     static unsigned long liveMessageCount() {return live_msgs;}
00596 
00600     static void resetMessageCounters()  {total_msgs=live_msgs=0L;}
00602 };
00603 
00604 #endif
00605 
00606 

Generated at Mon Jun 16 23:37:31 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001