OMNeT++ API 6.2.0
Discrete Event Simulation Library
ccomponenttype.h
1 //==========================================================================
2 // CCOMPONENTTYPE.H - part of
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_CCOMPONENTTYPE_H
17 #define __OMNETPP_CCOMPONENTTYPE_H
18 
19 #include <string>
20 #include <map>
21 #include <set>
22 #include "cpar.h"
23 #include "cgate.h"
24 #include "cownedobject.h"
25 #include "clistener.h"
26 
27 
28 namespace omnetpp {
29 
30 class cModule;
31 class cChannel;
32 class cProperty;
33 class cProperties;
34 class cIdealChannel;
35 class cDelayChannel;
36 class cDatarateChannel;
37 class cObjectFactory;
38 
39 
50 {
51  friend class cSimulation; // clearSharedParImpls()
52  protected:
53  std::string qualifiedName;
54  bool availabilityTested = false;
55  bool available = false;
56 
58  typedef std::map<std::string, cParImpl *> StringToParMap;
59  StringToParMap sharedParMap;
60 
61  struct Less {bool operator()(cParImpl *a, cParImpl *b) const;};
62  typedef std::set<cParImpl *, Less> ParImplSet;
63  ParImplSet sharedParSet;
64 
65  struct SignalDesc { SimsignalType type; cObjectFactory *objectType; bool isNullable; };
66  std::map<simsignal_t,SignalDesc> signalsSeen;
67 
68  mutable bool sourceFileDirectoryCached = false;
69  mutable std::string sourceFileDirectory;
70 
71  protected:
72  friend class cComponent;
73  friend class cModule;
74  friend class cChannel;
75  friend class cPar;
76  friend class cGate;
77 
78  // internal: returns the properties for this component.
79  virtual cProperties *getProperties() const = 0;
80 
81  // internal: returns the properties of parameter
82  virtual cProperties *getParamProperties(const char *paramName) const = 0;
83 
84  // internal: returns the properties of gate
85  virtual cProperties *getGateProperties(const char *gateName) const = 0;
86 
87  // internal: returns the properties of a submodule.
88  // (Subcomponent type is needed because with the NED "like" syntax,
89  // we need the runtime type not the NED type of the submodule.)
90  virtual cProperties *getSubmoduleProperties(const char *submoduleName, const char *submoduleType) const = 0;
91 
92  // internal: returns the properties of a contained connection.
93  // (Subcomponent type is needed because with the NED "like" syntax,
94  // we need the runtime type not the NED type of the submodule.)
95  virtual cProperties *getConnectionProperties(int connectionId, const char *channelType) const = 0;
96 
97  // internal: returns the name of the C++ class that implements this NED type
98  virtual const char *getImplementationClassName() const = 0;
99 
100  // internal: returns the default C++ namespace for the given NED type (for NED it's the @namespace package property)
101  virtual std::string getCxxNamespaceForType(const char *type) const = 0;
102 
103  // internal: apply pattern-based ("deep") parameter settings in NED
104  virtual void applyPatternAssignments(cComponent *component) = 0;
105 
106  // internal: sharedParMap access
107  cParImpl *getSharedParImpl(const char *key) const;
108  void putSharedParImpl(const char *key, cParImpl *value);
109 
110  // internal: sharedParSet access
111  cParImpl *getSharedParImpl(cParImpl *p) const;
112  void putSharedParImpl(cParImpl *p);
113 
114  // internal:
115  virtual void clearSharedParImpls();
116 
117  // internal: helper for checkSignal()
118  cObjectFactory *lookupClass(const char *className, const char *sourceType) const;
119 
120  public:
121  // internal: delegates to the similar NedTypeInfo method
122  virtual std::string getPackageProperty(const char *name) const {return "";}
123 
124  // internal: checks whether this type is available; currently tests the existence of the implementation class
125  virtual bool isAvailable();
126 
127  // internal: delegates to the similar NedTypeInfo method
128  virtual bool isInnerType() const {return false;}
129 
130  // internal: return the default C++ namespace at this NED type (for NED it's the @namespace package property)
131  virtual std::string getCxxNamespace() const {return "";}
132 
133  // internal: return the path of the source file this declaration has been loaded from, or nullptr if not available
134  virtual const char *getSourceFileName() const {return nullptr;}
135 
136  // internal: return the directory of the source file this declaration has been loaded from, or nullptr if not available
137  virtual const char *getSourceFileDirectory() const;
138 
139  // internal: used by cComponent::emit() methods to validate signals
140  virtual void checkSignal(simsignal_t signalID, SimsignalType type, cObject *obj = nullptr);
141 
142  // internal: returns the @signal property for the given signal, or nullptr if not found
143  virtual cProperty *getSignalDeclaration(const char *signalName);
144 
145  public:
151  cComponentType(const char *qname=nullptr);
152 
156  virtual ~cComponentType();
158 
177  virtual const char *getFullName() const override {return qualifiedName.c_str();}
179 
183  virtual std::string getNedSource() const = 0;
184 
188  virtual std::string getDocumentation() const = 0;
189 
194  static cComponentType *find(const char *qname);
195 
200  static cComponentType *get(const char *qname);
201 };
202 
203 
211 class SIM_API cModuleType : public cComponentType
212 {
213  friend class cModule;
214  protected:
215  // internal: create the module object
216  virtual cModule *createModuleObject() = 0;
217 
218  // internal: add parameters and gates to a newly created module object.
219  // Gate vectors will be created with zero size, and a further call to
220  // setupGateVectors() will be needed once parameter values have been finalized/
221  virtual void addParametersAndGatesTo(cModule *mod) = 0;
222 
223  // internal: set gate vector sizes on the module. This must be called AFTER all
224  // parameters have been set (see finalizeParameters()) because gate vector sizes
225  // may depend on parameter values; and it it must be invoked before connecting
226  // the gates and calling mod->buildInside().
227  virtual void setupGateVectors(cModule *mod) = 0;
228 
229  // internal: create and connect submodules of a newly created module object.
230  // addParametersAndGatesTo() and setupGateVectors() must have been already called at this point.
231  virtual void buildInside(cModule *mod) = 0;
232 
233  // internal: utility function: instantiates the given class, and tries to cast
234  // the result to cModule. Raises an error if class was not found or could not be cast.
235  cModule *instantiateModuleClass(const char *classname);
236 
237  public:
243  cModuleType(const char *qname=nullptr);
245 
251  virtual bool isNetwork() const = 0;
252 
257  virtual bool isSimple() const = 0;
259 
262 
294  virtual cModule *create(const char *name, cModule *parentmod, int index=-1);
295 
309  virtual cModule *createScheduleInit(const char *name, cModule *parentmod, int index=-1);
311 
316  static cModuleType *find(const char *qname);
317 
322  static cModuleType *get(const char *qname);
323 };
324 
325 
331 class SIM_API cChannelType : public cComponentType
332 {
333  protected:
334  static cChannelType *idealChannelType;
335  static cChannelType *delayChannelType;
336  static cChannelType *datarateChannelType;
337 
338  protected:
339  // internal: create the channel object
340  virtual cChannel *createChannelObject() = 0;
341 
342  // internal: add parameters to a newly created channel object.
343  virtual void addParametersTo(cChannel *channel) = 0;
344 
345  // internal: utility function: instantiates the given class, and tries to cast the
346  // result to cChannel. Raises an error if class was not found or could not be cast.
347  cChannel *instantiateChannelClass(const char *classname);
348 
349  public:
352 
356  cChannelType(const char *qname=nullptr);
357 
371  virtual cChannel *create(const char *name);
373 
378  static cChannelType *find(const char *qname);
379 
384  static cChannelType *get(const char *qname);
385 
390  static cChannelType *getIdealChannelType();
391 
396  static cChannelType *getDelayChannelType();
397 
402  static cChannelType *getDatarateChannelType();
403 
407  static cIdealChannel *createIdealChannel(const char *name);
408 
412  static cDelayChannel *createDelayChannel(const char *name);
413 
417  static cDatarateChannel *createDatarateChannel(const char *name);
418 };
419 
420 } // namespace omnetpp
421 
422 
423 #endif
424 
425 
omnetpp::cModule
This class represents modules in the simulation.
Definition: cmodule.h:48
omnetpp::simsignal_t
int simsignal_t
Signal handle.
Definition: clistener.h:27
omnetpp::cDelayChannel
Channel with propagation delay.
Definition: cdelaychannel.h:29
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cObjectFactory
The class behind the createOne() function and the Register_Class() macro.
Definition: cobjectfactory.h:35
omnetpp::cDatarateChannel
A transmission channel model that supports propagation delay, transmission duration computed from a d...
Definition: cdataratechannel.h:69
omnetpp::cSimulation
Simulation manager class.
Definition: csimulation.h:64
omnetpp::cChannel
Base class for channels.
Definition: cchannel.h:46
omnetpp::cModuleType
Abstract class for creating a module of a specific type.
Definition: ccomponenttype.h:211
omnetpp::cComponentType::getFullName
virtual const char * getFullName() const override
Definition: ccomponenttype.h:177
omnetpp::cGate
Represents a module gate.
Definition: cgate.h:62
omnetpp::cProperties
A collection of properties (cProperty).
Definition: cproperties.h:34
omnetpp::cPar
Represents a module or channel parameter.
Definition: cpar.h:70
omnetpp::cComponentType
Common base class for cModuleType and cChannelType.
Definition: ccomponenttype.h:49
omnetpp::SimsignalType
SimsignalType
Signal data types.
Definition: clistener.h:47
omnetpp::cChannelType
Abstract base class for creating a channel of a given type.
Definition: ccomponenttype.h:331
omnetpp::cIdealChannel
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled.
Definition: cchannel.h:326
omnetpp::internal::cParImpl
Internal class that stores values for cPar objects.
Definition: cparimpl.h:46
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cProperty
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38