16 #ifndef __OMNETPP_CCOMPONENT_H 17 #define __OMNETPP_CCOMPONENT_H 20 #include "simkerneldefs.h" 21 #include "cownedobject.h" 23 #include "cdefaultlist.h" 26 #include "clistener.h" 37 class cResultRecorder;
50 friend class cComponentDescriptor;
51 friend class cComponent__SignalListenerListDescriptor;
60 enum ComponentKind { KIND_MODULE, KIND_CHANNEL, KIND_OTHER };
64 FL_PARAMSFINALIZED = 1 << 2,
65 FL_INITIALIZED = 1 << 3,
67 FL_DISPSTR_CHECKED = 1 << 5,
68 FL_DISPSTR_NOTEMPTY = 1 << 6,
69 FL_LOGLEVEL_SHIFT = 7,
85 struct SignalListenerList {
89 SignalListenerList() {signalID=SIMSIGNAL_NULL; listeners=
nullptr;}
90 const char *getSignalName()
const;
91 std::string str()
const;
92 void dispose() {
delete [] listeners;}
96 bool hasListener()
const {
return listeners && listeners[0];}
97 int countListeners()
const;
98 cIListener *getListener(
int k)
const {
return listeners[k];}
99 static bool gt(
const SignalListenerList& e1,
const SignalListenerList& e2) {
return e1.signalID > e2.signalID;}
102 typedef std::vector<SignalListenerList> SignalTable;
103 SignalTable *signalTable;
106 static struct SignalNameMapping {
107 std::map<std::string,simsignal_t> signalNameToID;
108 std::map<simsignal_t,std::string> signalIDToName;
109 } *signalNameMapping;
110 static int lastSignalID;
113 static std::vector<int> signalListenerCounts;
117 static int notificationSP;
120 static bool checkSignals;
123 struct ResultRecorderList {
125 std::vector<cResultRecorder*> recorders;
129 static std::vector<ResultRecorderList*> cachedResultRecorderLists;
132 SignalListenerList *findListenerList(
simsignal_t signalID)
const;
133 SignalListenerList *findOrCreateListenerList(
simsignal_t signalID);
134 void throwInvalidSignalID(
simsignal_t signalID)
const;
139 void releaseLocalListeners();
140 const SignalListenerList& getListenerList(
int k)
const {
return (*signalTable)[k];}
141 int getSignalTableSize()
const {
return signalTable ? signalTable->size() : 0;}
142 void collectResultRecorders(std::vector<cResultRecorder*>& result)
const;
146 LogLevel getLogLevel()
const {
return (
LogLevel)((flags >> FL_LOGLEVEL_SHIFT) & 0x7); }
147 virtual void setLogLevel(
LogLevel logLevel);
150 virtual void setRNGMap(
short size,
int *map) {rngMapSize=size; rngMap=map;}
157 virtual void addPar(
cParImpl *value);
160 void reallocParamv(
int size);
163 virtual void recordParametersAsScalars();
166 bool parametersFinalized()
const {
return flags&FL_PARAMSFINALIZED;}
169 virtual void addResultRecorders();
172 bool initialized()
const {
return flags&FL_INITIALIZED;}
175 virtual void callRefreshDisplay() = 0;
179 bool hasDisplayString();
182 static void clearSignalState();
185 static void clearSignalRegistrations();
190 static uint64_t getSignalMask(
simsignal_t signalID);
193 static void setCheckSignals(
bool b) {checkSignals = b;}
194 static bool getCheckSignals() {
return checkSignals;}
197 const std::vector<cResultRecorder*>& getResultRecorders()
const;
198 static void invalidateCachedResultRecorderLists();
238 virtual void initialize();
244 virtual void finish();
264 virtual void handleParameterChange(
const char *parname);
292 virtual void refreshDisplay()
const;
318 virtual void forEachChild(
cVisitor *v)
override;
334 virtual void finalizeParameters();
363 int getId()
const {
return componentId;}
372 virtual const char *getNedTypeName()
const;
379 virtual ComponentKind getComponentKind()
const = 0;
384 bool isModule()
const {
return getComponentKind() == KIND_MODULE;}
389 bool isChannel()
const {
return getComponentKind() == KIND_CHANNEL;}
396 virtual cModule *getParentModule()
const = 0;
402 virtual cModule *getSystemModule()
const;
414 virtual void callInitialize() = 0;
420 virtual bool callInitialize(
int stage) = 0;
426 virtual void callFinish() = 0;
441 virtual cPar& par(
int k);
453 virtual cPar& par(
const char *parname);
465 virtual int findPar(
const char *parname)
const;
470 bool hasPar(
const char *s)
const {
return findPar(s)>=0;}
480 virtual cRNG *getRNG(
int k)
const;
485 virtual unsigned long intrand(
long r,
int rng=0)
const {
return getRNG(rng)->
intRand(r);}
531 virtual double normal(
double mean,
double stddev,
int rng=0)
const {
return omnetpp::normal(getRNG(rng), mean, stddev);};
609 virtual double beta(
double alpha1,
double alpha2,
int rng=0)
const {
return omnetpp::beta(getRNG(rng), alpha1, alpha2);};
686 virtual double triang(
double a,
double b,
double c,
int rng=0)
const {
return omnetpp::triang(getRNG(rng), a, b, c);};
842 static simsignal_t registerSignal(
const char *name);
848 static const char *getSignalName(
simsignal_t signalID);
933 if (signalID < 0 || signalID > lastSignalID)
934 throwInvalidSignalID(signalID);
935 return signalListenerCounts[signalID] > 0;
965 virtual void subscribe(
const char *signalName,
cIListener *listener);
977 virtual void unsubscribe(
const char *signalName,
cIListener *listener);
990 virtual bool isSubscribed(
const char *signalName,
cIListener *listener)
const;
995 virtual std::vector<simsignal_t> getLocalListenedSignals()
const;
1000 virtual std::vector<cIListener*> getLocalSignalListeners(
simsignal_t signalID)
const;
1014 virtual bool hasGUI()
const;
1025 virtual void setDisplayString(
const char *dispstr);
1031 virtual void bubble(
const char *text)
const;
1045 virtual std::string resolveResourcePath(
const char *fileName)
const;
1054 virtual void recordScalar(
const char *name,
double value,
const char *unit=
nullptr);
1066 virtual void recordStatistic(
cStatistic *stats,
const char *unit=
nullptr);
1073 virtual void recordStatistic(
const char *name,
cStatistic *stats,
const char *unit=
nullptr);
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...
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition: cdefaultlist.h:33
virtual unsigned long intRand()=0
Common base for module and channel classes.
Definition: ccomponent.h:48
Represents a module gate.
Definition: cgate.h:63
SIM_API double cauchy(cRNG *rng, double a, double b)
Returns a random variate from the Cauchy distribution (also called Lorentzian distribution) with para...
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual void emit(simsignal_t signalID, short i, cObject *details=nullptr)
Definition: ccomponent.h:909
virtual double uniform(double a, double b, int rng=0) const
Definition: ccomponent.h:502
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].
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Base class for all simple module classes.
Definition: csimplemodule.h:62
virtual double exponential(double mean, int rng=0) const
Definition: ccomponent.h:516
virtual int intuniform(int a, int b, int rng=0) const
Definition: ccomponent.h:744
virtual int poisson(double lambda, int rng=0) const
Definition: ccomponent.h:823
SIM_API double truncnormal(cRNG *rng, double mean, double stddev)
Normal distribution truncated to nonnegative values.
SIM_API double pareto_shifted(cRNG *rng, double a, double b, double c)
Returns a random variate from the shifted generalized Pareto distribution.
virtual void emit(simsignal_t signalID, char c, cObject *details=nullptr)
Definition: ccomponent.h:903
virtual void emit(simsignal_t signalID, unsigned short i, cObject *details=nullptr)
Definition: ccomponent.h:912
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...
const cPar & par(int k) const
Definition: ccomponent.h:447
SIM_API double student_t(cRNG *rng, unsigned int i)
Returns a random variate from the student-t distribution with i degrees of freedom. If Y1 has a normal distribution and Y2 has a chi-square distribution with k degrees of freedom then X = Y1 / sqrt(Y2/k) has a student-t distribution with k degrees of freedom.
SIM_API double chi_square(cRNG *rng, unsigned int k)
Returns a random variate from the chi-square distribution with k degrees of freedom.
LogLevel
Classifies log messages based on detail and importance.
Definition: clog.h:33
virtual void emit(simsignal_t signalID, unsigned char c, cObject *details=nullptr)
Definition: ccomponent.h:906
virtual SimTime uniform(SimTime a, SimTime b, int rng=0) const
Definition: ccomponent.h:507
virtual int binomial(int n, double p, int rng=0) const
Definition: ccomponent.h:778
Abstract interface for random number generator classes.
Definition: crng.h:49
Simulation manager class.
Definition: csimulation.h:62
virtual void initialize(int stage)
Definition: ccomponent.h:225
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...
SIM_API int geometric(cRNG *rng, double p)
Returns a random integer from the geometric distribution with parameter p, that is, the number of independent trials with probability p until the first success.
Represents a module or channel parameter.
Definition: cpar.h:68
virtual double cauchy(double a, double b, int rng=0) const
Definition: ccomponent.h:675
bool hasPar(const char *s) const
Definition: ccomponent.h:470
SIM_API int negbinomial(cRNG *rng, int n, double p)
Returns a random integer from the negative binomial distribution with parameters n and p...
int getId() const
Definition: ccomponent.h:363
virtual double beta(double alpha1, double alpha2, int rng=0) const
Definition: ccomponent.h:609
virtual double normal(double mean, double stddev, int rng=0) const
Definition: ccomponent.h:531
virtual int getNumParams() const
Definition: ccomponent.h:435
virtual void emit(simsignal_t signalID, float f, cObject *details=nullptr)
Definition: ccomponent.h:921
virtual double gamma_d(double alpha, double theta, int rng=0) const
Definition: ccomponent.h:595
virtual double pareto_shifted(double a, double b, double c, int rng=0) const
Definition: ccomponent.h:731
virtual void emit(simsignal_t signalID, int i, cObject *details=nullptr)
Definition: ccomponent.h:915
SIM_API int poisson(cRNG *rng, double lambda)
Returns a random integer from the Poisson distribution with parameter lambda, that is...
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...
virtual double weibull(double a, double b, int rng=0) const
Definition: ccomponent.h:720
bool isModule() const
Definition: ccomponent.h:384
const cPar & par(const char *parname) const
Definition: ccomponent.h:459
SIM_API double beta(cRNG *rng, double alpha1, double alpha2)
Returns a random variate from the beta distribution with parameters alpha1, alpha2.
double dbl() const
Definition: simtime.h:301
virtual double student_t(unsigned int i, int rng=0) const
Definition: ccomponent.h:659
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:317
This class represents modules in the simulation.
Definition: cmodule.h:47
virtual double lognormal(double m, double w, int rng=0) const
Definition: ccomponent.h:699
bool mayHaveListeners(simsignal_t signalID) const
Definition: ccomponent.h:932
const cComponent * getThisPtr() const
Definition: ccomponent.h:324
virtual unsigned long intrand(long r, int rng=0) const
Definition: ccomponent.h:485
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 double triang(double a, double b, double c, int rng=0) const
Definition: ccomponent.h:686
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. Alpha is known as the "shape" parameter, and theta as the "scale" parameter.
virtual double doubleRand()=0
virtual int intuniformexcl(int a, int b, int rng=0) const
Definition: ccomponent.h:753
virtual void recordScalar(const char *name, SimTime value, const char *unit=nullptr)
Definition: ccomponent.h:1059
virtual int negbinomial(int n, double p, int rng=0) const
Definition: ccomponent.h:806
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
virtual SimTime exponential(SimTime mean, int rng=0) const
Definition: ccomponent.h:521
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:244
Common base class for cModuleType and cChannelType.
Definition: ccomponenttype.h:49
Definition: cabstracthistogram.h:21
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.
A collection of properties (cProperty).
Definition: cproperties.h:34
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
virtual SimTime truncnormal(SimTime mean, SimTime stddev, int rng=0) const
Definition: ccomponent.h:558
virtual double truncnormal(double mean, double stddev, int rng=0) const
Definition: ccomponent.h:553
SIM_API double exponential(cRNG *rng, double mean)
Returns a random variate from the exponential distribution with the given mean (that is...
virtual double dblrand(int rng=0) const
Definition: ccomponent.h:490
virtual int geometric(double p, int rng=0) const
Definition: ccomponent.h:792
Represents a display string.
Definition: cdisplaystring.h:58
Interface for listeners in a simulation model.
Definition: clistener.h:66
virtual SimTime normal(SimTime mean, SimTime stddev, int rng=0) const
Definition: ccomponent.h:536
virtual double erlang_k(unsigned int k, double mean, int rng=0) const
Definition: ccomponent.h:629
virtual double chi_square(unsigned int k, int rng=0) const
Definition: ccomponent.h:646
virtual void emit(simsignal_t signalID, unsigned int i, cObject *details=nullptr)
Definition: ccomponent.h:918
int simsignal_t
Signal handle.
Definition: clistener.h:24
SIM_API double uniform(cRNG *rng, double a, double b)
Returns a random variate with uniform distribution in the range [a,b).
bool isChannel() const
Definition: ccomponent.h:389
virtual int bernoulli(double p, int rng=0) const
Definition: ccomponent.h:764
Base class for channels.
Definition: cchannel.h:34
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
cSimulation * getSimulation()
Returns the currently active simulation, or nullptr if there is none.
Definition: csimulation.h:575
Internal class that stores values for cPar objects.
Definition: cparimpl.h:44
virtual int numInitStages() const
Definition: ccomponent.h:232
virtual void emit(simsignal_t signalID, long double d, cObject *details=nullptr)
Definition: ccomponent.h:924
virtual void emit(simsignal_t signalID, const cObject *obj, cObject *details=nullptr)
Definition: ccomponent.h:900