OMNeT++ Simulation Library  6.0.3
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 
189  static cComponentType *find(const char *qname);
190 
195  static cComponentType *get(const char *qname);
196 };
197 
198 
206 class SIM_API cModuleType : public cComponentType
207 {
208  friend class cModule;
209  protected:
210  // internal: create the module object
211  virtual cModule *createModuleObject() = 0;
212 
213  // internal: add parameters and gates to a newly created module object.
214  // Gate vectors will be created with zero size, and a further call to
215  // setupGateVectors() will be needed once parameter values have been finalized/
216  virtual void addParametersAndGatesTo(cModule *mod) = 0;
217 
218  // internal: set gate vector sizes on the module. This must be called AFTER all
219  // parameters have been set (see finalizeParameters()) because gate vector sizes
220  // may depend on parameter values; and it it must be invoked before connecting
221  // the gates and calling mod->buildInside().
222  virtual void setupGateVectors(cModule *mod) = 0;
223 
224  // internal: create and connect submodules of a newly created module object.
225  // addParametersAndGatesTo() and setupGateVectors() must have been already called at this point.
226  virtual void buildInside(cModule *mod) = 0;
227 
228  // internal: utility function: instantiates the given class, and tries to cast
229  // the result to cModule. Raises an error if class was not found or could not be cast.
230  cModule *instantiateModuleClass(const char *classname);
231 
232  public:
238  cModuleType(const char *qname=nullptr);
240 
246  virtual bool isNetwork() const = 0;
247 
252  virtual bool isSimple() const = 0;
254 
257 
289  virtual cModule *create(const char *name, cModule *parentmod, int index=-1);
290 
304  virtual cModule *createScheduleInit(const char *name, cModule *parentmod, int index=-1);
306 
311  static cModuleType *find(const char *qname);
312 
317  static cModuleType *get(const char *qname);
318 };
319 
320 
326 class SIM_API cChannelType : public cComponentType
327 {
328  protected:
329  static cChannelType *idealChannelType;
330  static cChannelType *delayChannelType;
331  static cChannelType *datarateChannelType;
332 
333  protected:
334  // internal: create the channel object
335  virtual cChannel *createChannelObject() = 0;
336 
337  // internal: add parameters to a newly created channel object.
338  virtual void addParametersTo(cChannel *channel) = 0;
339 
340  // internal: utility function: instantiates the given class, and tries to cast the
341  // result to cChannel. Raises an error if class was not found or could not be cast.
342  cChannel *instantiateChannelClass(const char *classname);
343 
344  public:
347 
351  cChannelType(const char *qname=nullptr);
352 
366  virtual cChannel *create(const char *name);
368 
373  static cChannelType *find(const char *qname);
374 
379  static cChannelType *get(const char *qname);
380 
385  static cChannelType *getIdealChannelType();
386 
391  static cChannelType *getDelayChannelType();
392 
397  static cChannelType *getDatarateChannelType();
398 
402  static cIdealChannel *createIdealChannel(const char *name);
403 
407  static cDelayChannel *createDelayChannel(const char *name);
408 
412  static cDatarateChannel *createDatarateChannel(const char *name);
413 };
414 
415 } // namespace omnetpp
416 
417 
418 #endif
419 
420 
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:63
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:206
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:326
omnetpp::cIdealChannel
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled.
Definition: cchannel.h:324
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