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-2001 Andras Varga
00014   Technical University of Budapest, Dept. of Telecommunications,
00015   Stoczek u.2, H-1111 Budapest, Hungary.
00016 
00017   This file is distributed WITHOUT ANY WARRANTY. See the file
00018   `license' for details on this and other legal matters.
00019 *--------------------------------------------------------------*/
00020 
00021 #ifndef __CMESSAGE_H
00022 #define __CMESSAGE_H
00023 
00024 #include <time.h>
00025 #include "cobject.h"
00026 #include "carray.h"
00027 #include "cpar.h"
00028 #include "csimul.h"
00029 
00030 //=== classes mentioned:
00031 class cPar;
00032 class cGate;
00033 class cModule;
00034 class cSimpleModule;
00035 class cCompoundModule;
00036 class cSimulation;
00037 class cMessageHeap;
00038 
00039 //=== classes declared here:
00040 class  cMessage;
00041 
00050 enum eMessageKind {
00051   MK_STARTER = -1,  
00052   MK_TIMEOUT = -2,  
00053   MK_PACKET  = -3,  
00054   MK_INFO    = -4   
00055 };
00056 
00057 //==========================================================================
00058 
00074 class SIM_API cMessage : public cObject
00075 {
00076     friend class cGate;
00077     friend class cModule;
00078     friend class cSimpleModule;
00079     friend class cCompoundModule;
00080     friend class cSimulation;
00081     friend class cMessageHeap;
00082 
00083   private:
00084     int msgkind;            // message kind -- meaning is user-defined
00085     int prior;              // priority -- used for scheduling msgs with equal times
00086     long len;               // length of message -- used for bit errors and transm.delay
00087     bool error;             // bit error occurred during transmission
00088     simtime_t tstamp;       // time stamp -- user-defined meaning
00089     cArray *parlistp;       // ptr to list of parameters
00090     cMessage *encapmsg;     // ptr to encapsulated msg
00091     void *contextptr;       // a stored pointer -- user-defined meaning
00092 
00093     int frommod,fromgate;   // source module and gate IDs -- set internally
00094     int tomod,togate;       // dest. module and gate IDs -- set internally
00095     simtime_t created;      // creation time -- set be constructor
00096     simtime_t sent,delivd;  // time of sending & delivery -- set internally
00097 
00098     int heapindex;             // used by cMessageHeap (-1 if not on heap)
00099     unsigned long insertordr;  // used by cMessageHeap
00100 
00101 
00102     // helper function
00103     void _createparlist();
00104 
00105     // global variables for statistics
00106     static unsigned long total_msgs;
00107     static unsigned long live_msgs;
00108 
00109   public:
00112 
00116     cMessage(const cMessage& msg);
00117 
00121     explicit cMessage(const char *name=NULL, int k=0, long len=1, int pri=0, bool err=false);
00122 
00126     virtual ~cMessage();
00127 
00132     cMessage& operator=(const cMessage& msg);
00134 
00137 
00141     virtual const char *className() const {return "cMessage";}
00142 
00147     virtual cObject *dup() const  {return new cMessage(*this);}
00148 
00153     virtual void info(char *buf);
00154 
00159     virtual const char *inspectorFactoryName() const {return "cMessageIFC";}
00160 
00165     virtual void forEach( ForeachFunc do_fn );
00166 
00171     virtual void writeContents(ostream& os);
00172 
00178     virtual int netPack();
00179 
00185     virtual int netUnpack();
00187 
00190 
00195     void setKind(int k)     {msgkind=k;}
00196 
00202     void setPriority(int p) {prior=p;}
00203 
00209     void setLength(long l);
00210 
00216     void addLength(long l);
00217 
00221     void setBitError(bool err) {error=err;}
00222 
00226     void setTimestamp() {tstamp=simulation.simTime();}
00227 
00231     void setTimestamp(simtime_t t) {tstamp=t;}
00232 
00236     void setContextPointer(void *p) {contextptr=p;}
00237 
00241     int  kind() const     {return msgkind;}
00242 
00246     int  priority() const {return prior;}
00247 
00251     long length() const   {return len;}
00252 
00256     bool hasBitError() const {return error;}
00257 
00261     simtime_t timestamp() const {return tstamp;}
00262 
00266     unsigned long insertOrder() const {return insertordr;}
00267 
00271     void *contextPointer() const {return contextptr;}
00273 
00276 
00283     cArray& parList()
00284         {if (!parlistp) _createparlist(); return *parlistp;}
00285 
00289     cPar& addPar(const char *s)  {cPar *p=new cPar(s);parList().add(p);return *p;}
00290 
00294     cPar& addPar(cPar *p)  {parList().add(p); return *p;}
00295 
00299     cPar& addPar(cPar& p)  {parList().add(&p); return p;}
00300 
00305     cPar& par(int n);
00306 
00311     cPar& par(const char *s);
00312 
00317     int findPar(const char *s) const;
00318 
00322     bool hasPar(const char *s) const {return findPar(s)>=0;}
00324 
00327 
00332     void encapsulate(cMessage *msg);
00333 
00339     cMessage *decapsulate();
00340 
00344     cMessage *encapsulatedMsg() const {return encapmsg;}
00346 
00349 
00353     bool isSelfMessage() const {return togate==-1;}
00354 
00358     bool isScheduled() const {return heapindex!=-1;}
00359 
00365     cGate *senderGate() const;
00366 
00372     cGate *arrivalGate() const;
00373 
00378     int senderModuleId() const {return frommod;}
00379 
00384     int senderGateId() const   {return fromgate;}
00385 
00390     int arrivalModuleId() const {return tomod;}
00391 
00396     int arrivalGateId() const  {return togate;}
00397 
00398 
00402     simtime_t creationTime() const {return created;}
00403 
00408     simtime_t sendingTime()  const {return sent;}
00409 
00414     simtime_t arrivalTime()  const {return delivd;}
00415 
00416 
00420     bool arrivedOn(int g) const {return g==togate;}
00421 
00426     bool arrivedOn(const char *s, int g=0);
00428 
00431 
00437     virtual const char *displayString() const;
00438 
00443     static int cmpbydelivtime(cObject *one, cObject *other);
00444 
00450     static int cmpbypriority(cObject *one, cObject *other);
00451 
00456     static unsigned long totalMessageCount() {return total_msgs;}
00457 
00463     static unsigned long liveMessageCount() {return live_msgs;}
00464 
00468     static void resetMessageCounters()  {total_msgs=live_msgs=0L;}
00470 };
00471 
00472 #endif
00473 
00474 

Generated at Sat May 4 15:45:48 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001