|
OMNeT++ API 6.1
Discrete Event Simulation Library
|
|
16 #ifndef __OMNETPP_CCOMPONENT_H
17 #define __OMNETPP_CCOMPONENT_H
20 #include <unordered_set>
21 #include "simkerneldefs.h"
22 #include "cownedobject.h"
24 #include "csoftowner.h"
27 #include "clistener.h"
38 class cResultRecorder;
51 friend class cComponentDescriptor;
52 friend class cComponent__SignalListenerListDescriptor;
61 enum ComponentKind { KIND_MODULE, KIND_CHANNEL, KIND_OTHER };
65 FL_PARAMSFINALIZED = 1 << 2,
66 FL_INITIALIZED = 1 << 3,
68 FL_DISPSTR_CHECKED = 1 << 5,
69 FL_DISPSTR_NOTEMPTY = 1 << 6,
70 FL_LOGLEVEL_SHIFT = 7,
80 short lastCompletedInitStage;
93 struct SignalListenerList {
97 SignalListenerList() {signalID=SIMSIGNAL_NULL; listeners=
nullptr;}
98 const char *getSignalName()
const;
99 std::string str()
const;
100 void dispose() {
delete [] listeners;}
104 bool hasListener()
const {
return listeners && listeners[0];}
105 int countListeners()
const;
106 cIListener *getListener(
int k)
const {
return listeners[k];}
107 static bool gt(
const SignalListenerList& e1,
const SignalListenerList& e2) {
return e1.signalID > e2.signalID;}
111 typedef std::vector<SignalListenerList> SignalTable;
112 SignalTable *signalTable;
114 std::unordered_set<void**> *selfPointers =
nullptr;
117 static struct SignalNameMapping {
118 std::map<std::string,simsignal_t> signalNameToID;
119 std::map<simsignal_t,std::string> signalIDToName;
120 } *signalNameMapping;
121 static int lastSignalID;
124 static std::vector<int> signalListenerCounts;
128 static int notificationSP;
131 static bool checkSignals;
134 struct ResultRecorderList {
136 std::vector<cResultRecorder*> recorders;
140 static std::vector<ResultRecorderList*> cachedResultRecorderLists;
143 SignalListenerList *findListenerList(
simsignal_t signalID)
const;
144 SignalListenerList *findOrCreateListenerList(
simsignal_t signalID);
145 void throwInvalidSignalID(
simsignal_t signalID)
const;
150 void releaseLocalListeners();
151 const SignalListenerList& getListenerList(
int k)
const {
return (*signalTable)[k];}
152 int getSignalTableSize()
const {
return signalTable ? signalTable->size() : 0;}
153 void collectResultRecorders(std::vector<cResultRecorder*>& result)
const;
158 virtual cModule *doFindModuleByPath(
const char *s)
const = 0;
162 LogLevel getLogLevel()
const {
return (
LogLevel)((flags >> FL_LOGLEVEL_SHIFT) & 0x7); }
163 virtual void setLogLevel(
LogLevel logLevel);
166 virtual void setRNGMap(
short size,
int *map) {rngMapSize=size; rngMap=map;}
173 virtual void addPar(
cParImpl *value);
176 void reallocParamv(
int size);
179 virtual void recordParameters();
180 virtual void recordParameterAsScalar(
cPar *par);
183 bool parametersFinalized()
const {
return flags&FL_PARAMSFINALIZED;}
186 virtual void addResultRecorders();
187 virtual void emitStatisticInitialValues();
190 bool initialized()
const {
return flags&FL_INITIALIZED;}
193 virtual void callRefreshDisplay() = 0;
196 virtual void callPreDelete(
cComponent *root) = 0;
200 bool hasDisplayString();
203 static void clearSignalState();
206 static void clearSignalRegistrations();
211 static uint64_t getSignalMask(
simsignal_t signalID);
214 static void setCheckSignals(
bool b) {checkSignals = b;}
215 static bool getCheckSignals() {
return checkSignals;}
218 const std::vector<cResultRecorder*>& getResultRecorders()
const;
219 static void invalidateCachedResultRecorderLists();
223 void registerSelfPointer(T *&ptr) {
224 ASSERT(
dynamic_cast<cComponent*
>(ptr) ==
this);
226 selfPointers =
new std::unordered_set<void**>;
227 selfPointers->insert((
void**)&ptr);
231 void deregisterSelfPointer(T *&ptr) {
232 ASSERT(
dynamic_cast<cComponent*
>(ptr) ==
this);
233 ASSERT(selfPointers !=
nullptr && selfPointers->find((
void**)&ptr) != selfPointers->end());
234 selfPointers->erase((
void**)&ptr);
275 virtual void initialize();
281 virtual void finish();
306 virtual void handleParameterChange(
const char *parname);
334 virtual void refreshDisplay()
const;
376 virtual void forEachChild(
cVisitor *v)
override;
392 virtual void finalizeParameters();
407 virtual void setDisplayName(
const char *name);
433 int getId()
const {
return componentId;}
442 virtual const char *getNedTypeName()
const;
450 virtual std::string getNedTypeAndFullName()
const;
458 virtual std::string getNedTypeAndFullPath()
const;
465 virtual ComponentKind getComponentKind()
const = 0;
470 bool isModule()
const {
return getComponentKind() == KIND_MODULE;}
475 bool isChannel()
const {
return getComponentKind() == KIND_CHANNEL;}
482 virtual cModule *getParentModule()
const = 0;
488 virtual cModule *getSystemModule()
const;
514 virtual cModule *getModuleByPath(
const char *path)
const;
524 virtual cModule *findModuleByPath(
const char *path)
const;
536 virtual void callInitialize() = 0;
542 virtual bool callInitialize(
int stage) = 0;
548 virtual void callFinish() = 0;
563 virtual cPar& par(
int k);
575 virtual cPar& par(
const char *parname);
587 virtual int findPar(
const char *parname)
const;
592 bool hasPar(
const char *s)
const {
return findPar(s)>=0;}
602 virtual cRNG *getRNG(
int k)
const;
607 virtual uint32_t
intrand(uint32_t r,
int rng=0)
const {
return getRNG(rng)->intRand(r);}
612 virtual double dblrand(
int rng=0)
const {
return getRNG(rng)->doubleRand();}
653 virtual double normal(
double mean,
double stddev,
int rng=0)
const {
return omnetpp::normal(getRNG(rng), mean, stddev);};
731 virtual double beta(
double alpha1,
double alpha2,
int rng=0)
const {
return omnetpp::beta(getRNG(rng), alpha1, alpha2);};
808 virtual double triang(
double a,
double b,
double c,
int rng=0)
const {
return omnetpp::triang(getRNG(rng), a, b, c);};
964 static simsignal_t registerSignal(
const char *name);
970 static const char *getSignalName(
simsignal_t signalID);
1054 if (signalID < 0 || signalID > lastSignalID)
1055 throwInvalidSignalID(signalID);
1056 return signalListenerCounts[signalID] > 0;
1086 virtual void subscribe(
const char *signalName,
cIListener *listener);
1098 virtual void unsubscribe(
const char *signalName,
cIListener *listener);
1111 virtual bool isSubscribed(
const char *signalName,
cIListener *listener)
const;
1116 virtual std::vector<simsignal_t> getLocalListenedSignals()
const;
1121 virtual std::vector<cIListener*> getLocalSignalListeners(
simsignal_t signalID)
const;
1135 virtual bool hasGUI()
const;
1146 virtual void setDisplayString(
const char *dispstr);
1152 virtual void bubble(
const char *text)
const;
1166 virtual std::string resolveResourcePath(
const char *fileName)
const;
1175 virtual void recordScalar(
const char *name,
double value,
const char *unit=
nullptr);
1187 virtual void recordStatistic(
cStatistic *stats,
const char *unit=
nullptr);
1194 virtual void recordStatistic(
const char *name,
cStatistic *stats,
const char *unit=
nullptr);
virtual int geometric(double p, int rng=0) const
Definition: ccomponent.h:914
SIM_API double normal(cRNG *rng, double mean, double stddev)
Returns a random variate from the normal distribution with the given mean and standard deviation.
SIM_API double chi_square(cRNG *rng, unsigned int k)
Returns a random variate from the chi-square distribution with k degrees of freedom.
This class represents modules in the simulation.
Definition: cmodule.h:48
SIM_API double gamma_d(cRNG *rng, double alpha, double theta)
Returns a random variate from the gamma distribution with parameters alpha>0, theta>0....
int simsignal_t
Signal handle.
Definition: clistener.h:27
virtual double chi_square(unsigned int k, int rng=0) const
Definition: ccomponent.h:768
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
virtual SimTime uniform(SimTime a, SimTime b, int rng=0) const
Definition: ccomponent.h:629
virtual double beta(double alpha1, double alpha2, int rng=0) const
Definition: ccomponent.h:731
virtual double gamma_d(double alpha, double theta, int rng=0) const
Definition: ccomponent.h:717
SIM_API double cauchy(cRNG *rng, double a, double b)
Returns a random variate from the Cauchy distribution (also called Lorentzian distribution) with para...
virtual void initialize(int stage)
Definition: ccomponent.h:262
virtual double triang(double a, double b, double c, int rng=0) const
Definition: ccomponent.h:808
virtual void emit(simsignal_t signalID, unsigned char c, cObject *details=nullptr)
Definition: ccomponent.h:1015
virtual double exponential(double mean, int rng=0) const
Definition: ccomponent.h:638
Simulation manager class.
Definition: csimulation.h:64
virtual double pareto_shifted(double a, double b, double c, int rng=0) const
Definition: ccomponent.h:853
virtual void emit(simsignal_t signalID, const cObject *obj, cObject *details=nullptr)
Definition: ccomponent.h:1009
const cPar & par(const char *parname) const
Definition: ccomponent.h:581
virtual void recordScalar(const char *name, SimTime value, const char *unit=nullptr)
Definition: ccomponent.h:1180
virtual double cauchy(double a, double b, int rng=0) const
Definition: ccomponent.h:797
SIM_API int geometric(cRNG *rng, double p)
Returns a random integer from the geometric distribution with parameter p, that is,...
bool isChannel() const
Definition: ccomponent.h:475
virtual double student_t(unsigned int i, int rng=0) const
Definition: ccomponent.h:781
virtual double dblrand(int rng=0) const
Definition: ccomponent.h:612
virtual void emit(simsignal_t signalID, unsigned int i, cObject *details=nullptr)
Definition: ccomponent.h:1027
double lognormal(cRNG *rng, double m, double w)
Returns a random variate from the lognormal distribution with "scale" parameter m and "shape" paramet...
Definition: distrib.h:251
Interface for listeners in a simulation model.
Definition: clistener.h:71
virtual int negbinomial(int n, double p, int rng=0) const
Definition: ccomponent.h:928
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
Base class for channels.
Definition: cchannel.h:46
virtual double normal(double mean, double stddev, int rng=0) const
Definition: ccomponent.h:653
int bernoulli(cRNG *rng, double p)
Returns the result of a Bernoulli trial with probability p, that is, 1 with probability p and 0 with ...
Definition: distrib.h:324
bool isModule() const
Definition: ccomponent.h:470
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual void emit(simsignal_t signalID, unsigned short i, cObject *details=nullptr)
Definition: ccomponent.h:1021
SIM_API int negbinomial(cRNG *rng, int n, double p)
Returns a random integer from the negative binomial distribution with parameters n and p,...
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
SIM_API double triang(cRNG *rng, double a, double b, double c)
Returns a random variate from the triangular distribution with parameters a <= b <= c.
virtual double truncnormal(double mean, double stddev, int rng=0) const
Definition: ccomponent.h:675
SIM_API int poisson(cRNG *rng, double lambda)
Returns a random integer from the Poisson distribution with parameter lambda, that is,...
SIM_API int intuniform(cRNG *rng, int a, int b)
Returns a random integer with uniform distribution in the range [a,b], inclusive. (Note that the func...
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition: csoftowner.h:33
virtual int poisson(double lambda, int rng=0) const
Definition: ccomponent.h:945
Represents a module gate.
Definition: cgate.h:62
bool hasPar(const char *s) const
Definition: ccomponent.h:592
A collection of properties (cProperty).
Definition: cproperties.h:34
SIM_API double uniform(cRNG *rng, double a, double b)
Returns a random variate with uniform distribution in the range [a,b).
virtual void emit(simsignal_t signalID, long double d, cObject *details=nullptr)
Definition: ccomponent.h:1045
Abstract interface for random number generator classes.
Definition: crng.h:48
virtual double weibull(double a, double b, int rng=0) const
Definition: ccomponent.h:842
virtual int intuniformexcl(int a, int b, int rng=0) const
Definition: ccomponent.h:875
SIM_API double erlang_k(cRNG *rng, unsigned int k, double mean)
Returns a random variate from the Erlang distribution with k phases and mean mean.
virtual void emit(simsignal_t signalID, int i, cObject *details=nullptr)
Definition: ccomponent.h:1024
virtual uint32_t intrand(uint32_t r, int rng=0) const
Definition: ccomponent.h:607
Represents a module or channel parameter.
Definition: cpar.h:70
virtual int intuniform(int a, int b, int rng=0) const
Definition: ccomponent.h:866
Common base class for cModuleType and cChannelType.
Definition: ccomponenttype.h:49
virtual const char * getDisplayName() const
Definition: ccomponent.h:414
int getId() const
Definition: ccomponent.h:433
cSimulation * getSimulation() const
Definition: ccomponent.h:424
bool mayHaveListeners(simsignal_t signalID) const
Definition: ccomponent.h:1053
SIM_API int intuniformexcl(cRNG *rng, int a, int b)
Returns a random integer with uniform distribution over [a,b), that is, from [a,b-1].
virtual void emit(simsignal_t signalID, unsigned long long i, cObject *details=nullptr)
Definition: ccomponent.h:1039
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
virtual double lognormal(double m, double w, int rng=0) const
Definition: ccomponent.h:821
Internal class that stores values for cPar objects.
Definition: cparimpl.h:46
virtual void emit(simsignal_t signalID, unsigned long i, cObject *details=nullptr)
Definition: ccomponent.h:1033
const cComponent * getThisPtr() const
Definition: ccomponent.h:382
SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c)
Returns a random variate from the shifted generalized Pareto distribution.
double dbl() const
Definition: simtime.h:346
Common base for module and channel classes.
Definition: ccomponent.h:49
virtual void emit(simsignal_t signalID, char c, cObject *details=nullptr)
Definition: ccomponent.h:1012
virtual int numInitStages() const
Definition: ccomponent.h:269
virtual double uniform(double a, double b, int rng=0) const
Definition: ccomponent.h:624
virtual void emit(simsignal_t signalID, short i, cObject *details=nullptr)
Definition: ccomponent.h:1018
const cPar & par(int k) const
Definition: ccomponent.h:569
Definition: opp_pooledstring.h:63
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
virtual int bernoulli(double p, int rng=0) const
Definition: ccomponent.h:886
SIM_API double student_t(cRNG *rng, unsigned int i)
Returns a random variate from the student-t distribution with i degrees of freedom....
virtual SimTime normal(SimTime mean, SimTime stddev, int rng=0) const
Definition: ccomponent.h:658
Base class for all simple module classes.
Definition: csimplemodule.h:202
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
SIM_API double truncnormal(cRNG *rng, double mean, double stddev)
Normal distribution truncated to nonnegative values.
SIM_API double beta(cRNG *rng, double alpha1, double alpha2)
Returns a random variate from the beta distribution with parameters alpha1, alpha2.
virtual int binomial(int n, double p, int rng=0) const
Definition: ccomponent.h:900
Represents a display string.
Definition: cdisplaystring.h:67
virtual void emit(simsignal_t signalID, long i, cObject *details=nullptr)
Definition: ccomponent.h:1030
SIM_API double weibull(cRNG *rng, double a, double b)
Returns a random variate from the Weibull distribution with parameters a, b > 0, where a is the "scal...
virtual SimTime truncnormal(SimTime mean, SimTime stddev, int rng=0) const
Definition: ccomponent.h:680
virtual double erlang_k(unsigned int k, double mean, int rng=0) const
Definition: ccomponent.h:751
virtual SimTime exponential(SimTime mean, int rng=0) const
Definition: ccomponent.h:643
LogLevel
Classifies log messages based on detail and importance.
Definition: clog.h:33
SIM_API int binomial(cRNG *rng, int n, double p)
Returns a random integer from the binomial distribution with parameters n and p, that is,...
virtual void emit(simsignal_t signalID, long long i, cObject *details=nullptr)
Definition: ccomponent.h:1036
SIM_API double exponential(cRNG *rng, double mean)
Returns a random variate from the exponential distribution with the given mean (that is,...
virtual void emit(simsignal_t signalID, float f, cObject *details=nullptr)
Definition: ccomponent.h:1042
virtual int getNumParams() const
Definition: ccomponent.h:557