OMNeT++ API 6.2.0
Discrete Event Simulation Library
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 class cModule;
28 struct SendOptions;
29 
33 struct SIM_API ChannelResult
34 {
35  bool discard = false;
37  simtime_t duration = SIMTIME_ZERO;
38  simtime_t remainingDuration = SIMTIME_ZERO;
39 };
40 
46 class SIM_API cChannel : public cComponent //implies noncopyable
47 {
48  friend class cModule; // for setting prevSibling/nextSibling
49  protected:
50  cGate *srcGate = nullptr; // gate the channel is attached to
51  int nedConnectionElementId = -1; // for cChannel::getProperties(); usually the NED connection element's id
52 
53  public:
54  // internal: called from cGate
55  void setSourceGate(cGate *g) {srcGate=g;}
56 
57  // internal: sets/gets nedConnectionElementId
58  void setNedConnectionElementId(int id) {nedConnectionElementId = id;}
59  int getNedConnectionElementId() {return nedConnectionElementId;}
60 
61  // internal: called from callInitialize(). Does one stage for this
62  // channel, and returns true if there are more stages to do
63  virtual bool initializeChannel(int stage);
64 
65  // internal: overridden to perform additional checks
66  virtual void finalizeParameters() override;
67 
68  // internal: calls refreshDisplay() recursively
69  virtual void callRefreshDisplay() override;
70 
71  // internal: calls preDelete() recursively
72  virtual void callPreDelete(cComponent *root) override;
73 
74  protected:
75  virtual cModule *doFindModuleByPath(const char *s) const override;
76 
77  public:
78  typedef ChannelResult Result;
79 
84  {
85  public:
86  simtime_t timestamp;
87  cMessage *msg;
88  Result *result;
89  private:
90  void error() const;
91  public:
93  MessageSentSignalValue(simtime_t_cref t, cMessage *m, Result *r) {timestamp=t; msg=m; result=r;}
94 
98  virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override {return timestamp;}
99 
101  virtual SimsignalType getValueType(simsignal_t signalID) const override {return SIMSIGNAL_OBJECT;}
102 
104  virtual cObject *objectValue(simsignal_t signalID) const override {return msg;}
106 
108  cMessage *getMessage() const {return msg;}
109 
111  Result *getChannelResult() const {return result;}
112 
115  virtual bool boolValue(simsignal_t signalID) const override {error(); return false;}
116  virtual intval_t intValue(simsignal_t signalID) const override {error(); return 0;}
117  virtual uintval_t uintValue(simsignal_t signalID) const override {error(); return 0;}
118  virtual double doubleValue(simsignal_t signalID) const override {error(); return 0;}
119  virtual SimTime simtimeValue(simsignal_t signalID) const override {error(); return timestamp;}
120  virtual const char *stringValue(simsignal_t signalID) const override {error(); return nullptr;}
122  };
123 
124  public:
130  explicit cChannel(const char *name=nullptr);
131 
138  virtual ~cChannel();
140 
147  virtual std::string str() const 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 Result processMessage(cMessage *msg, const SendOptions& options, simtime_t t) = 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 
309  [[deprecated]] virtual void forceTransmissionFinishTime(simtime_t t) {}
310 
315  virtual bool isDisabled() const { return false; }
317 };
318 
319 
326 class SIM_API cIdealChannel : public cChannel //implies noncopyable
327 {
328  public:
336  explicit cIdealChannel(const char *name=nullptr) : cChannel(name) {}
337 
341  virtual ~cIdealChannel() {}
342 
347  static cIdealChannel *create(const char *name);
349 
355  virtual Result processMessage(cMessage *msg, const SendOptions& options, simtime_t t) override {return Result();}
356 
360  virtual double getNominalDatarate() const override {return 0;}
361 
365  virtual bool isTransmissionChannel() const override {return false;}
366 
370  virtual simtime_t calculateDuration(cMessage *msg) const override {return SIMTIME_ZERO;}
371 
375  virtual simtime_t getTransmissionFinishTime() const override {return SIMTIME_ZERO;}
376 
380  virtual bool isBusy() const override {return false;}
382 };
383 
384 } // namespace omnetpp
385 
386 
387 #endif
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::cModule
This class represents modules in the simulation.
Definition: cmodule.h:48
omnetpp::ChannelResult
Allows returning multiple values from the processMessage() method.
Definition: cchannel.h:33
omnetpp::simsignal_t
int simsignal_t
Signal handle.
Definition: clistener.h:27
omnetpp::cChannel::getChannelType
cChannelType * getChannelType() const
Definition: cchannel.h:193
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cIdealChannel::cIdealChannel
cIdealChannel(const char *name=nullptr)
Definition: cchannel.h:336
omnetpp::cChannel::getSourceGate
virtual cGate * getSourceGate() const
Definition: cchannel.h:204
omnetpp::cIdealChannel::isBusy
virtual bool isBusy() const override
Definition: cchannel.h:380
omnetpp::cChannel
Base class for channels.
Definition: cchannel.h:46
omnetpp::cChannel::isDisabled
virtual bool isDisabled() const
Definition: cchannel.h:315
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::cIdealChannel::~cIdealChannel
virtual ~cIdealChannel()
Definition: cchannel.h:341
omnetpp::SendOptions
Options for the cSimpleModule::send() and cSimpleModule::sendDirect() calls.
Definition: csimplemodule.h:82
omnetpp::cChannel::MessageSentSignalValue::getTimestamp
virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override
Definition: cchannel.h:98
omnetpp::cIdealChannel::isTransmissionChannel
virtual bool isTransmissionChannel() const override
Definition: cchannel.h:365
omnetpp::cGate
Represents a module gate.
Definition: cgate.h:62
omnetpp::cProperties
A collection of properties (cProperty).
Definition: cproperties.h:34
omnetpp::cIdealChannel::calculateDuration
virtual simtime_t calculateDuration(cMessage *msg) const override
Definition: cchannel.h:370
omnetpp::cITimestampedValue
Interface for emitting timestamped values as signals, primarily for result recording.
Definition: ctimestampedvalue.h:35
omnetpp::cChannel::MessageSentSignalValue::getMessage
cMessage * getMessage() const
Definition: cchannel.h:108
omnetpp::cChannel::MessageSentSignalValue::getChannelResult
Result * getChannelResult() const
Definition: cchannel.h:111
omnetpp::cChannel::MessageSentSignalValue::getValueType
virtual SimsignalType getValueType(simsignal_t signalID) const override
Definition: cchannel.h:101
omnetpp::SimsignalType
SimsignalType
Signal data types.
Definition: clistener.h:47
SIMTIME_ZERO
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:70
omnetpp::cChannelType
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:331
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cIdealChannel
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled.
Definition: cchannel.h:326
omnetpp::cIdealChannel::processMessage
virtual Result processMessage(cMessage *msg, const SendOptions &options, simtime_t t) override
Definition: cchannel.h:355
omnetpp::cMessage
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::cIdealChannel::getTransmissionFinishTime
virtual simtime_t getTransmissionFinishTime() const override
Definition: cchannel.h:375
omnetpp::cChannel::MessageSentSignalValue::MessageSentSignalValue
MessageSentSignalValue(simtime_t_cref t, cMessage *m, Result *r)
Definition: cchannel.h:93
omnetpp::cChannel::getComponentKind
virtual ComponentKind getComponentKind() const override
Definition: cchannel.h:179
omnetpp::cChannel::MessageSentSignalValue::objectValue
virtual cObject * objectValue(simsignal_t signalID) const override
Definition: cchannel.h:104
omnetpp::cIdealChannel::getNominalDatarate
virtual double getNominalDatarate() const override
Definition: cchannel.h:360
omnetpp::cChannel::forceTransmissionFinishTime
virtual void forceTransmissionFinishTime(simtime_t t)
Definition: cchannel.h:309
omnetpp::cChannel::MessageSentSignalValue
Signal value that accompanies the "messageSent" signal.
Definition: cchannel.h:83