cchannel.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CCHANNEL_H
00021 #define __CCHANNEL_H
00022
00023 #include "ccomponent.h"
00024 #include "ccomponenttype.h"
00025 #include "cmessage.h"
00026 #include "ctimestampedvalue.h"
00027
00028 NAMESPACE_BEGIN
00029
00030 class cGate;
00031
00032
00038 class SIM_API cChannel : public cComponent
00039 {
00040 protected:
00041 cGate *srcgatep;
00042 int nedConnectionElementId;
00043
00044 public:
00045
00046 void setSourceGate(cGate *g) {srcgatep=g;}
00047
00048
00049 void setNedConnectionElementId(int id) {nedConnectionElementId = id;}
00050 int getNedConnectionElementId() {return nedConnectionElementId;}
00051
00052
00053
00054 virtual bool initializeChannel(int stage);
00055
00056
00057 virtual void finalizeParameters();
00058
00059 public:
00064 struct result_t
00065 {
00066 result_t() : delay(SIMTIME_ZERO), duration(SIMTIME_ZERO), discard(false) {}
00067 simtime_t delay;
00068 simtime_t duration;
00069 bool discard;
00070 };
00071
00075 class MessageSentSignalValue : public cITimestampedValue, public cObject
00076 {
00077 public:
00078 simtime_t timestamp;
00079 cMessage *msg;
00080 result_t *result;
00081 public:
00083 MessageSentSignalValue(simtime_t_cref t, cMessage *m, result_t *r) {timestamp=t; msg=m; result=r;}
00084
00088 virtual simtime_t_cref getTimestamp(simsignal_t signalID) const {return timestamp;}
00089
00091 virtual SimsignalType getValueType(simsignal_t signalID) const {return SIMSIGNAL_OBJECT;}
00092
00094 virtual cObject *objectValue(simsignal_t signalID) const {return msg;}
00096
00098 cMessage *getMessage() const {return msg;}
00099
00101 result_t *getChannelResult() const {return result;}
00102
00105 virtual bool boolValue(simsignal_t signalID) const {error(); return false;}
00106 virtual long longValue(simsignal_t signalID) const {error(); return 0;}
00107 virtual unsigned long unsignedLongValue(simsignal_t signalID) const {error(); return 0;}
00108 virtual double doubleValue(simsignal_t signalID) const {error(); return 0;}
00109 virtual SimTime simtimeValue(simsignal_t signalID) const {error(); return timestamp;}
00110 virtual const char *stringValue(simsignal_t signalID) const {error(); return NULL;}
00111 void error() const;
00113 };
00114
00115 public:
00121 explicit cChannel(const char *name=NULL);
00122
00126 virtual ~cChannel();
00128
00135 virtual std::string info() const;
00136
00141 virtual void forEachChild(cVisitor *v);
00142
00146 virtual void parsimPack(cCommBuffer *buffer);
00147
00151 virtual void parsimUnpack(cCommBuffer *buffer);
00153
00164 virtual void callInitialize();
00165
00170 virtual bool callInitialize(int stage);
00171
00175 virtual void callFinish();
00177
00187 virtual cModule *getParentModule() const;
00188
00192 cChannelType *getChannelType() const {return (cChannelType *)getComponentType();}
00193
00198 virtual cProperties *getProperties() const;
00199
00203 cGate *getSourceGate() const {return srcgatep;}
00204
00211 virtual bool isTransmissionChannel() const = 0;
00213
00240 virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) = 0;
00241
00252 virtual double getNominalDatarate() const = 0;
00253
00276 virtual simtime_t calculateDuration(cMessage *msg) const = 0;
00277
00286 virtual simtime_t getTransmissionFinishTime() const = 0;
00287
00295 virtual bool isBusy() const;
00296
00315 virtual void forceTransmissionFinishTime(simtime_t t) = 0;
00317 };
00318
00319
00326 class SIM_API cIdealChannel : public cChannel
00327 {
00328 public:
00336 explicit cIdealChannel(const char *name=NULL) : cChannel(name) {}
00337
00341 virtual ~cIdealChannel() {}
00342
00347 static cIdealChannel *create(const char *name);
00349
00355 virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) {}
00356
00360 virtual double getNominalDatarate() const {return 0;}
00361
00365 virtual bool isTransmissionChannel() const {return false;}
00366
00370 virtual simtime_t calculateDuration(cMessage *msg) const {return SIMTIME_ZERO;}
00371
00375 virtual simtime_t getTransmissionFinishTime() const {return SIMTIME_ZERO;}
00376
00380 virtual bool isBusy() const {return false;}
00381
00385 virtual void forceTransmissionFinishTime(simtime_t t) {}
00387 };
00388
00389 NAMESPACE_END
00390
00391
00392 #endif
00393
00394