cmessage.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CMESSAGE_H
00021 #define __CMESSAGE_H
00022
00023 #include "cownedobject.h"
00024 #include "carray.h"
00025 #include "cmsgpar.h"
00026 #include "csimulation.h"
00027
00028 NAMESPACE_BEGIN
00029
00030 class cMsgPar;
00031 class cGate;
00032 class cChannel;
00033 class cModule;
00034 class cSimpleModule;
00035 class cSimulation;
00036 class cMessageHeap;
00037 class LogBuffer;
00038
00039
00048 enum eMessageKind
00049 {
00050 MK_STARTER = -1,
00051 MK_TIMEOUT = -2,
00052 MK_PACKET = -3,
00053 MK_INFO = -4,
00054
00055 MK_PARSIM_BEGIN = -1000
00056 };
00057
00064
00065 #define MAX_PARSIM_PARTITIONS 32768 // srcprocid in cMessage
00066
00067
00068 #ifdef WITHOUT_CPACKET
00069 #undef cMessage
00070 #endif
00071
00109
00110 class SIM_API cMessage : public cOwnedObject
00111 {
00112 friend class cMessageHeap;
00113 friend class LogBuffer;
00114
00115 private:
00116
00117 short msgkind;
00118 short prior;
00119 short srcprocid;
00120 cArray *parlistp;
00121 cObject *ctrlp;
00122 void *contextptr;
00123
00124 int frommod, fromgate;
00125 int tomod, togate;
00126 simtime_t created;
00127 simtime_t sent,delivd;
00128 simtime_t tstamp;
00129
00130 int heapindex;
00131 unsigned long insertordr;
00132
00133 eventnumber_t prev_event_num;
00134
00135 long msgid;
00136 long msgtreeid;
00137 static long next_id;
00138
00139
00140 static long total_msgs;
00141 static long live_msgs;
00142
00143 private:
00144
00145 void _createparlist();
00146
00147 void copy(const cMessage& msg);
00148
00149
00150 void setId(long id) {msgid = id;}
00151
00152 public:
00153
00154
00155 eventnumber_t getPreviousEventNumber() const {return prev_event_num;}
00156
00157
00158 void setPreviousEventNumber(eventnumber_t num) {prev_event_num = num;}
00159
00160
00161 unsigned long getInsertOrder() const {return insertordr;}
00162
00163
00164
00165
00166 void setSentFrom(cModule *module, int gateId, simtime_t_cref t);
00167
00168
00169
00170
00171 void setArrival(cModule *module, int gateId);
00172
00173
00174
00175
00176 void setArrival(cModule *module, int gate, simtime_t_cref t);
00177
00178
00179
00180 void setArrivalTime(simtime_t t);
00181
00182
00183 void setSrcProcId(int procId) {srcprocid = (short)procId;}
00184
00185
00186 int getSrcProcId() const {return srcprocid;}
00187
00188 public:
00191
00195 cMessage(const cMessage& msg);
00196
00200 explicit cMessage(const char *name=NULL, short kind=0);
00201
00205 virtual ~cMessage();
00206
00213 cMessage& operator=(const cMessage& msg);
00215
00220 virtual bool isPacket() const {return false;}
00221
00224
00231 virtual cMessage *dup() const {return new cMessage(*this);}
00232
00237 virtual std::string info() const;
00238
00243 virtual std::string detailedInfo() const;
00244
00249 virtual void forEachChild(cVisitor *v);
00250
00256 virtual void parsimPack(cCommBuffer *buffer);
00257
00263 virtual void parsimUnpack(cCommBuffer *buffer);
00265
00268
00274 void setKind(short k) {msgkind=k;}
00275
00281 void setSchedulingPriority(short p) {prior=p;}
00282
00286 void setTimestamp() {tstamp=simulation.getSimTime();}
00287
00291 void setTimestamp(simtime_t t) {tstamp=t;}
00292
00301 void setContextPointer(void *p) {contextptr=p;}
00302
00318 void setControlInfo(cObject *p);
00319
00325 cObject *removeControlInfo();
00326
00330 short getKind() const {return msgkind;}
00331
00335 short getSchedulingPriority() const {return prior;}
00336
00340 simtime_t_cref getTimestamp() const {return tstamp;}
00341
00345 void *getContextPointer() const {return contextptr;}
00346
00350 cObject *getControlInfo() const {return ctrlp;}
00352
00355
00369 virtual cArray& getParList() {if (!parlistp) _createparlist(); return *parlistp;}
00370
00381 virtual cMsgPar& addPar(const char *s) {cMsgPar *p=new cMsgPar(s);getParList().add(p);return *p;}
00382
00392 virtual cMsgPar& addPar(cMsgPar *p) {getParList().add(p); return *p;}
00393
00397 _OPPDEPRECATED cMsgPar& addPar(cMsgPar& p) {return addPar(&p);}
00398
00410 virtual cMsgPar& par(int n);
00411
00424 virtual cMsgPar& par(const char *s);
00425
00436 virtual int findPar(const char *s) const;
00437
00448 virtual bool hasPar(const char *s) const {return findPar(s)>=0;}
00449
00459 virtual cObject *addObject(cObject *p) {getParList().add(p); return p;}
00460
00471 virtual cObject *getObject(const char *s) {return getParList().get(s);}
00472
00482 virtual bool hasObject(const char *s) {return !parlistp ? false : parlistp->find(s)>=0;}
00483
00494 virtual cObject *removeObject(const char *s) {return getParList().remove(s);}
00495
00506 virtual cObject *removeObject(cObject *p) {return getParList().remove(p);}
00508
00511
00515 bool isSelfMessage() const {return togate==-1;}
00516
00520 bool isScheduled() const {return heapindex!=-1;}
00521
00527 cModule *getSenderModule() const {return simulation.getModule(frommod);}
00528
00534 cGate *getSenderGate() const;
00535
00541 cModule *getArrivalModule() const {return simulation.getModule(tomod);}
00542
00548 cGate *getArrivalGate() const;
00549
00556 int getSenderModuleId() const {return frommod;}
00557
00565 int getSenderGateId() const {return fromgate;}
00566
00573 int getArrivalModuleId() const {return tomod;}
00574
00582 int getArrivalGateId() const {return togate;}
00583
00589 simtime_t_cref getCreationTime() const {return created;}
00590
00595 simtime_t_cref getSendingTime() const {return sent;}
00596
00611 simtime_t_cref getArrivalTime() const {return delivd;}
00612
00616 bool arrivedOn(int gateId) const {return gateId==togate;}
00617
00623 bool arrivedOn(const char *gatename) const;
00624
00629 bool arrivedOn(const char *gatename, int gateindex) const;
00630
00634 long getId() const {return msgid;}
00635
00640 long getTreeId() const {return msgtreeid;}
00642
00645
00651 virtual const char *getDisplayString() const;
00653
00664 static long getTotalMessageCount() {return total_msgs;}
00665
00673 static long getLiveMessageCount() {return live_msgs;}
00674
00678 static void resetMessageCounters() {total_msgs=live_msgs=0;}
00680 };
00681
00682
00710 class SIM_API cPacket : public cMessage
00711 {
00712 private:
00713 enum {
00714 FL_ISRECEPTIONSTART = 4,
00715 FL_BITERROR = 8,
00716 };
00717 int64 len;
00718 simtime_t duration;
00719 cPacket *encapmsg;
00720 unsigned short sharecount;
00721
00722
00723
00724
00725
00726 private:
00727 void copy(const cPacket& packet);
00728
00729 public:
00730
00731 void setDuration(simtime_t d) {duration = d;}
00732
00733
00734 void setReceptionStart(bool b) {setFlag(FL_ISRECEPTIONSTART, b);}
00735
00736
00737
00738 long getEncapsulationId() const;
00739
00740
00741
00742 long getEncapsulationTreeId() const;
00743
00744
00745
00746
00747
00748
00749
00750
00751 void _detachEncapMsg();
00752
00753
00754 void _deleteEncapMsg();
00755
00756
00757 int getShareCount() const {return sharecount;}
00758
00759 public:
00765 cPacket(const cPacket& packet);
00766
00771 explicit cPacket(const char *name=NULL, short kind=0, int64 bitLength=0);
00772
00776 virtual ~cPacket();
00777
00782 cPacket& operator=(const cPacket& packet);
00784
00787
00792 virtual cPacket *dup() const {return new cPacket(*this);}
00793
00798 virtual std::string info() const;
00799
00804 virtual std::string detailedInfo() const;
00805
00810 virtual void forEachChild(cVisitor *v);
00811
00817 virtual void parsimPack(cCommBuffer *buffer);
00818
00824 virtual void parsimUnpack(cCommBuffer *buffer);
00825
00829 virtual bool isPacket() const {return true;}
00831
00839 virtual void setBitLength(int64 l);
00840
00846 void setByteLength(int64 l) {setBitLength(l<<3);}
00847
00858 virtual void addBitLength(int64 delta);
00859
00866 void addByteLength(int64 delta) {addBitLength(delta<<3);}
00867
00871 virtual int64 getBitLength() const {return len;}
00872
00877 int64 getByteLength() const {return (len+7)>>3;}
00878
00882 virtual void setBitError(bool e) {setFlag(FL_BITERROR,e);}
00883
00887 virtual bool hasBitError() const {return flags&FL_BITERROR;}
00889
00892
00906 virtual void encapsulate(cPacket *packet);
00907
00915 virtual cPacket *decapsulate();
00916
00924 virtual cPacket *getEncapsulatedPacket() const;
00925
00930 _OPPDEPRECATED cPacket *getEncapsulatedMsg() const {return getEncapsulatedPacket();}
00931
00938 virtual bool hasEncapsulatedPacket() const;
00940
00949 simtime_t_cref getDuration() const {return duration;}
00950
00959 bool isReceptionStart() const {return flags & FL_ISRECEPTIONSTART;}
00961 };
00962
00963 #ifdef WITHOUT_CPACKET
00964 #define cMessage cPacket
00965 #endif
00966
00967 NAMESPACE_END
00968
00969 #endif
00970
00971