OMNeT++ Simulation Library  6.0.3
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 
136  virtual ~cChannel();
138 
145  virtual std::string str() const override;
147 
158  virtual void callInitialize() override;
159 
164  virtual bool callInitialize(int stage) override;
165 
169  virtual void callFinish() override;
171 
177  virtual ComponentKind getComponentKind() const override {return KIND_CHANNEL;}
178 
186  virtual cModule *getParentModule() const override;
187 
191  cChannelType *getChannelType() const {return (cChannelType *)getComponentType();}
192 
197  virtual cProperties *getProperties() const override;
198 
202  virtual cGate *getSourceGate() const {return srcGate;}
203 
210  virtual bool isTransmissionChannel() const = 0;
212 
239  virtual Result processMessage(cMessage *msg, const SendOptions& options, simtime_t t) = 0;
240 
251  virtual double getNominalDatarate() const = 0;
252 
275  virtual simtime_t calculateDuration(cMessage *msg) const = 0;
276 
285  virtual simtime_t getTransmissionFinishTime() const = 0;
286 
294  virtual bool isBusy() const;
295 
307  [[deprecated]] virtual void forceTransmissionFinishTime(simtime_t t) {}
308 
313  virtual bool isDisabled() const { return false; }
315 };
316 
317 
324 class SIM_API cIdealChannel : public cChannel //implies noncopyable
325 {
326  public:
334  explicit cIdealChannel(const char *name=nullptr) : cChannel(name) {}
335 
339  virtual ~cIdealChannel() {}
340 
345  static cIdealChannel *create(const char *name);
347 
353  virtual Result processMessage(cMessage *msg, const SendOptions& options, simtime_t t) override {return Result();}
354 
358  virtual double getNominalDatarate() const override {return 0;}
359 
363  virtual bool isTransmissionChannel() const override {return false;}
364 
368  virtual simtime_t calculateDuration(cMessage *msg) const override {return SIMTIME_ZERO;}
369 
373  virtual simtime_t getTransmissionFinishTime() const override {return SIMTIME_ZERO;}
374 
378  virtual bool isBusy() const override {return false;}
380 };
381 
382 } // namespace omnetpp
383 
384 
385 #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:191
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:334
omnetpp::cChannel::getSourceGate
virtual cGate * getSourceGate() const
Definition: cchannel.h:202
omnetpp::cIdealChannel::isBusy
virtual bool isBusy() const override
Definition: cchannel.h:378
omnetpp::cChannel
Base class for channels.
Definition: cchannel.h:46
omnetpp::cChannel::isDisabled
virtual bool isDisabled() const
Definition: cchannel.h:313
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:339
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:363
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:368
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:326
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:324
omnetpp::cIdealChannel::processMessage
virtual Result processMessage(cMessage *msg, const SendOptions &options, simtime_t t) override
Definition: cchannel.h:353
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:373
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:177
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:358
omnetpp::cChannel::forceTransmissionFinishTime
virtual void forceTransmissionFinishTime(simtime_t t)
Definition: cchannel.h:307
omnetpp::cChannel::MessageSentSignalValue
Signal value that accompanies the "messageSent" signal.
Definition: cchannel.h:83