OMNeT++ Simulation Library  5.6.1
cchannel.h
1 //==========================================================================
2 // CCHANNEL.H - header for
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CCHANNEL_H
17 #define __OMNETPP_CCHANNEL_H
18 
19 #include "ccomponent.h"
20 #include "ccomponenttype.h"
21 #include "cmessage.h"
22 #include "ctimestampedvalue.h"
23 
24 namespace omnetpp {
25 
26 class cGate;
27 
28 
34 class SIM_API cChannel : public cComponent //implies noncopyable
35 {
36  protected:
37  cGate *srcGate; // gate the channel is attached to
38  int nedConnectionElementId; // for cChannel::getProperties(); usually the NED connection element's id
39 
40  public:
41  // internal: called from cGate
42  void setSourceGate(cGate *g) {srcGate=g;}
43 
44  // internal: sets/gets nedConnectionElementId
45  void setNedConnectionElementId(int id) {nedConnectionElementId = id;}
46  int getNedConnectionElementId() {return nedConnectionElementId;}
47 
48  // internal: called from callInitialize(). Does one stage for this
49  // channel, and returns true if there are more stages to do
50  virtual bool initializeChannel(int stage);
51 
52  // internal: overridden to perform additional checks
53  virtual void finalizeParameters() override;
54 
55  // internal: calls refreshDisplay() recursively
56  virtual void callRefreshDisplay() override;
57 
58  public:
64  struct result_t
65  {
66  result_t() : delay(SIMTIME_ZERO), duration(SIMTIME_ZERO), discard(false) {}
69  bool discard;
70  };
71 
76  {
77  public:
78  simtime_t timestamp;
79  cMessage *msg;
80  result_t *result;
81  private:
82  void error() const;
83  public:
85  MessageSentSignalValue(simtime_t_cref t, cMessage *m, result_t *r) {timestamp=t; msg=m; result=r;}
86 
90  virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override {return timestamp;}
91 
93  virtual SimsignalType getValueType(simsignal_t signalID) const override {return SIMSIGNAL_OBJECT;}
94 
96  virtual cObject *objectValue(simsignal_t signalID) const override {return msg;}
98 
100  cMessage *getMessage() const {return msg;}
101 
103  result_t *getChannelResult() const {return result;}
104 
107  virtual bool boolValue(simsignal_t signalID) const override {error(); return false;}
108  virtual long longValue(simsignal_t signalID) const override {error(); return 0;}
109  virtual unsigned long unsignedLongValue(simsignal_t signalID) const override {error(); return 0;}
110  virtual double doubleValue(simsignal_t signalID) const override {error(); return 0;}
111  virtual SimTime simtimeValue(simsignal_t signalID) const override {error(); return timestamp;}
112  virtual const char *stringValue(simsignal_t signalID) const override {error(); return nullptr;}
114  };
115 
116  public:
122  explicit cChannel(const char *name=nullptr);
123 
128  virtual ~cChannel();
130 
137  virtual std::string str() const override;
138 
142  virtual void parsimPack(cCommBuffer *buffer) const override;
143 
147  virtual void parsimUnpack(cCommBuffer *buffer) override;
149 
160  virtual void callInitialize() override;
161 
166  virtual bool callInitialize(int stage) override;
167 
171  virtual void callFinish() override;
173 
179  virtual ComponentKind getComponentKind() const override {return KIND_CHANNEL;}
180 
188  virtual cModule *getParentModule() const override;
189 
193  cChannelType *getChannelType() const {return (cChannelType *)getComponentType();}
194 
199  virtual cProperties *getProperties() const override;
200 
204  virtual cGate *getSourceGate() const {return srcGate;}
205 
212  virtual bool isTransmissionChannel() const = 0;
214 
241  virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) = 0;
242 
253  virtual double getNominalDatarate() const = 0;
254 
277  virtual simtime_t calculateDuration(cMessage *msg) const = 0;
278 
287  virtual simtime_t getTransmissionFinishTime() const = 0;
288 
296  virtual bool isBusy() const;
297 
316  virtual void forceTransmissionFinishTime(simtime_t t) = 0;
318 };
319 
320 
327 class SIM_API cIdealChannel : public cChannel //implies noncopyable
328 {
329  public:
337  explicit cIdealChannel(const char *name=nullptr) : cChannel(name) {}
338 
342  virtual ~cIdealChannel() {}
343 
348  static cIdealChannel *create(const char *name);
350 
356  virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) override {}
357 
361  virtual double getNominalDatarate() const override {return 0;}
362 
366  virtual bool isTransmissionChannel() const override {return false;}
367 
371  virtual simtime_t calculateDuration(cMessage *msg) const override {return SIMTIME_ZERO;}
372 
376  virtual simtime_t getTransmissionFinishTime() const override {return SIMTIME_ZERO;}
377 
381  virtual bool isBusy() const override {return false;}
382 
386  virtual void forceTransmissionFinishTime(simtime_t t) override {}
388 };
389 
390 } // namespace omnetpp
391 
392 
393 #endif
virtual simtime_t calculateDuration(cMessage *msg) const override
Definition: cchannel.h:371
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
simtime_t delay
Propagation delay.
Definition: cchannel.h:67
Common base for module and channel classes.
Definition: ccomponent.h:48
Represents a module gate.
Definition: cgate.h:63
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual ComponentKind getComponentKind() const override
Definition: cchannel.h:179
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual bool isBusy() const override
Definition: cchannel.h:381
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled...
Definition: cchannel.h:327
Allows returning multiple values from the processMessage() method.
Definition: cchannel.h:64
cIdealChannel(const char *name=nullptr)
Definition: cchannel.h:337
cChannelType * getChannelType() const
Definition: cchannel.h:193
virtual cObject * objectValue(simsignal_t signalID) const override
Definition: cchannel.h:96
virtual simtime_t getTransmissionFinishTime() const override
Definition: cchannel.h:376
Signal value that accompanies the "messageSent" signal.
Definition: cchannel.h:75
virtual double getNominalDatarate() const override
Definition: cchannel.h:361
virtual cGate * getSourceGate() const
Definition: cchannel.h:204
cMessage * getMessage() const
Definition: cchannel.h:100
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:73
This class represents modules in the simulation.
Definition: cmodule.h:47
virtual SimsignalType getValueType(simsignal_t signalID) const override
Definition: cchannel.h:93
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override
Definition: cchannel.h:90
MessageSentSignalValue(simtime_t_cref t, cMessage *m, result_t *r)
Definition: cchannel.h:85
virtual bool isTransmissionChannel() const override
Definition: cchannel.h:366
Interface for emitting timestamped values as signals, primarily for result recording.
Definition: ctimestampedvalue.h:35
Definition: cabstracthistogram.h:21
virtual void processMessage(cMessage *msg, simtime_t t, result_t &result) override
Definition: cchannel.h:356
A collection of properties (cProperty).
Definition: cproperties.h:34
SimsignalType
Signal data types.
Definition: clistener.h:44
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:312
virtual void forceTransmissionFinishTime(simtime_t t) override
Definition: cchannel.h:386
int simsignal_t
Signal handle.
Definition: clistener.h:24
virtual ~cIdealChannel()
Definition: cchannel.h:342
Base class for channels.
Definition: cchannel.h:34
simtime_t duration
Transmission duration.
Definition: cchannel.h:68
result_t * getChannelResult() const
Definition: cchannel.h:103
bool discard
Whether the channel has lost the message.
Definition: cchannel.h:69