ccomponenttype.h Source File¶

API: ccomponenttype.h Source File
API
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
28namespace omnetpp {
29
30class cModule;
31class cChannel;
32class cProperty;
33class cProperties;
34class cIdealChannel;
35class cDelayChannel;
37class cObjectFactory;
38
39
49class SIM_API cComponentType : public cNoncopyableOwnedObject
50{
51 friend class cSimulation; // clearSharedParImpls()
52 protected:
53 std::string qualifiedName;
54 bool availabilityTested = false;
55 bool available = false;
56
57 typedef internal::cParImpl cParImpl;
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:
148
151 cComponentType(const char *qname=nullptr);
152
158
161
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
211class 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:
240
243 cModuleType(const char *qname=nullptr);
245
248
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
331class 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
360
371 virtual cChannel *create(const char *name);
373
378 static cChannelType *find(const char *qname);
379
384 static cChannelType *get(const char *qname);
385
391
397
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
cChannelType(const char *qname=nullptr)
static cChannelType * get(const char *qname)
static cChannelType * find(const char *qname)
virtual cChannel * create(const char *name)
static cDelayChannel * createDelayChannel(const char *name)
static cChannelType * getDelayChannelType()
static cIdealChannel * createIdealChannel(const char *name)
static cChannelType * getIdealChannelType()
static cChannelType * getDatarateChannelType()
static cDatarateChannel * createDatarateChannel(const char *name)
Base class for channels.
Definition cchannel.h:47
static cComponentType * get(const char *qname)
virtual const char * getFullName() const override
Definition ccomponenttype.h:177
virtual std::string getDocumentation() const =0
cComponentType(const char *qname=nullptr)
static cComponentType * find(const char *qname)
virtual std::string getNedSource() const =0
A transmission channel model that supports propagation delay, transmission duration computed from a d...
Definition cdataratechannel.h:70
Channel with propagation delay.
Definition cdelaychannel.h:30
Channel with zero propagation delay, zero transmission delay (infinite datarate), and always enabled.
Definition cchannel.h:327
virtual cModule * createScheduleInit(const char *name, cModule *parentmod, int index=-1)
virtual bool isNetwork() const =0
virtual bool isSimple() const =0
static cModuleType * find(const char *qname)
cModuleType(const char *qname=nullptr)
static cModuleType * get(const char *qname)
virtual cModule * create(const char *name, cModule *parentmod, int index=-1)
This class represents modules in the simulation.
Definition cmodule.h:49
The class behind the createOne() function and the Register_Class() macro.
Definition cobjectfactory.h:36
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
A collection of properties (cProperty).
Definition cproperties.h:35
Stores a (NED) property with its (possibly compound) value.
Definition cproperty.h:39
Internal class that stores values for cPar objects.
Definition cparimpl.h:47
SimsignalType
Signal data types.
Definition clistener.h:48
int simsignal_t
Signal handle.
Definition clistener.h:37