Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | Related Pages

cmessage.h

00001 //==========================================================================
00002 //   CMESSAGE.H  -  header for
00003 //                     OMNeT++/OMNEST
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-2005 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   MK_PARSIM_BEGIN = -1000  
00055 };
00056 
00057 //==========================================================================
00058 
00095 class SIM_API cMessage : public cObject
00096 {
00097     friend class cMessageHeap;
00098 
00099   private:
00100     int msgkind;               // message kind -- <0 reserved, 0>= user-defined meaning
00101     int prior;                 // priority -- used for scheduling msgs with equal times
00102     long len;                  // length of message -- used for bit errors and transm.delay
00103     bool error : 1;            // bit error occurred during transmission
00104     unsigned char refcount : 7;// reference count for encapsulated message (0: not encapsulated, max 127)
00105     unsigned char srcprocid;   // reserved for use by parallel execution: id of source partition
00106     cArray *parlistp;          // ptr to list of parameters
00107     cMessage *encapmsg;        // ptr to encapsulated msg
00108     cPolymorphic *ctrlp;       // ptr to "control info"
00109     void *contextptr;          // a stored pointer -- user-defined meaning, used with self-messages
00110 
00111     int frommod,fromgate;      // source module and gate IDs -- set internally
00112     int tomod,togate;          // dest. module and gate IDs -- set internally
00113     simtime_t created;         // creation time -- set be constructor
00114     simtime_t sent,delivd;     // time of sending & delivery -- set internally
00115     simtime_t tstamp;          // time stamp -- user-defined meaning
00116 
00117     int heapindex;             // used by cMessageHeap (-1 if not on heap)
00118     unsigned long insertordr;  // used by cMessageHeap
00119 
00120     // helper function
00121     void _createparlist();
00122 
00123     // global variables for statistics
00124     static long total_msgs;
00125     static long live_msgs;
00126 
00127   public:
00130 
00134     cMessage(const cMessage& msg);
00135 
00139     explicit cMessage(const char *name=NULL, int k=0, long len=0, int pri=0, bool err=false);
00140 
00144     virtual ~cMessage();
00145 
00150     cMessage& operator=(const cMessage& msg);
00152 
00155 
00160     virtual cObject *dup() const  {return new cMessage(*this);}
00161 
00166     virtual std::string info() const;
00167 
00172     virtual void forEachChild(cVisitor *v);
00173 
00178     virtual void writeContents(std::ostream& os);
00179 
00185     virtual void netPack(cCommBuffer *buffer);
00186 
00192     virtual void netUnpack(cCommBuffer *buffer);
00194 
00197 
00202     void setKind(int k)     {msgkind=k;}
00203 
00209     void setPriority(int p) {prior=p;}
00210 
00216     void setLength(long l);
00217 
00226     void addLength(long delta);
00227 
00231     void setBitError(bool err) {error=err;}
00232 
00236     void setTimestamp() {tstamp=simulation.simTime();}
00237 
00241     void setTimestamp(simtime_t t) {tstamp=t;}
00242 
00251     void setContextPointer(void *p) {contextptr=p;}
00252 
00268     void setControlInfo(cPolymorphic *p);
00269 
00275     cPolymorphic *removeControlInfo();
00276 
00280     int  kind() const     {return msgkind;}
00281 
00285     int  priority() const {return prior;}
00286 
00290     long length() const   {return len;}
00291 
00295     bool hasBitError() const {return error;}
00296 
00300     simtime_t timestamp() const {return tstamp;}
00301 
00305     unsigned long insertOrder() const {return insertordr;}
00306 
00310     void *contextPointer() const {return contextptr;}
00311 
00315     cPolymorphic *controlInfo() const {return ctrlp;}
00317 
00320 
00334     cArray& parList()
00335         {if (!parlistp) _createparlist(); return *parlistp;}
00336 
00347     cPar& addPar(const char *s)  {cPar *p=new cPar(s);parList().add(p);return *p;}
00348 
00358     cPar& addPar(cPar *p)  {parList().add(p); return *p;}
00359 
00363     cPar& addPar(cPar& p)  {parList().add(&p); return p;}
00364 
00376     cPar& par(int n);
00377 
00390     cPar& par(const char *s);
00391 
00402     int findPar(const char *s) const;
00403 
00414     bool hasPar(const char *s) const {return findPar(s)>=0;}
00415 
00425     cObject *addObject(cObject *p)  {parList().add(p); return p;}
00426 
00437     cObject *getObject(const char *s)  {return parList().get(s);}
00438 
00448     bool hasObject(const char *s)  {return !parlistp ? false : parlistp->find(s)>=0;}
00449 
00460     cObject *removeObject(const char *s)  {return parList().remove(s);}
00461 
00472     cObject *removeObject(cObject *p)  {return parList().remove(p);}
00474 
00477 
00482     void encapsulate(cMessage *msg);
00483 
00489     cMessage *decapsulate();
00490 
00494     cMessage *encapsulatedMsg() const {return encapmsg;}
00496 
00499 
00503     bool isSelfMessage() const {return togate==-1;}
00504 
00508     bool isScheduled() const {return heapindex!=-1;}
00509 
00515     cGate *senderGate() const;
00516 
00522     cGate *arrivalGate() const;
00523 
00528     int senderModuleId() const {return frommod;}
00529 
00534     int senderGateId() const   {return fromgate;}
00535 
00540     int arrivalModuleId() const {return tomod;}
00541 
00546     int arrivalGateId() const  {return togate;}
00547 
00551     simtime_t creationTime() const {return created;}
00552 
00557     simtime_t sendingTime()  const {return sent;}
00558 
00564     simtime_t arrivalTime()  const {return delivd;}
00565 
00569     bool arrivedOn(int g) const {return g==togate;}
00570 
00575     bool arrivedOn(const char *s, int g=0);
00577 
00580 
00586     virtual void setSentFrom(cModule *module, int gate, simtime_t t);
00587 
00593     virtual void setArrival(cModule *module, int gate);
00594 
00600     virtual void setArrival(cModule *module, int gate, simtime_t t);
00601 
00606     virtual void setArrivalTime(simtime_t t);
00607 
00611     void setSrcProcId(unsigned char procId) {srcprocid=procId;}
00612 
00616     unsigned char srcProcId() {return srcprocid;}
00618 
00621 
00628     virtual const char *displayString() const;
00629 
00634     static int cmpbydelivtime(cObject *one, cObject *other);
00635 
00641     static int cmpbypriority(cObject *one, cObject *other);
00642 
00653     static long totalMessageCount() {return total_msgs;}
00654 
00662     static long liveMessageCount() {return live_msgs;}
00663 
00667     static void resetMessageCounters()  {total_msgs=live_msgs=0;}
00669 };
00670 
00671 #endif
00672 
00673 

Generated on Fri Apr 1 12:25:32 2005 for OMNeT++/OMNEST Simulation Library by  doxygen 1.3.9.1