OMNeT++ Simulation Library
5.6.1
|
#include <cmodule.h>
This class represents modules in the simulation.
cModule can be used directly for compound modules. Simple module classes need to be subclassed from cSimpleModule, a class that adds more functionality to cModule.
For navigating the module tree, see: getParentModule(), getSubmodule(), cModule::SubmoduleIterator, cModule::getModuleByPath(), cSimulation::getModuleByPath().
Classes | |
class | ChannelIterator |
Walks along the channels inside a module, that is, the channels among the module and its submodules. More... | |
class | GateIterator |
Iterates through the gates of a module. More... | |
class | SubmoduleIterator |
Iterates through the submodules of a compound module. More... | |
Public Member Functions | |
Constructors, destructor, assignment. | |
cModule () | |
virtual | ~cModule () |
Redefined cObject member functions. | |
virtual void | forEachChild (cVisitor *v) override |
virtual void | setName (const char *s) override |
virtual const char * | getFullName () const override |
virtual std::string | getFullPath () const override |
virtual std::string | str () const override |
Setting up the module. | |
virtual cGate * | addGate (const char *gatename, cGate::Type type, bool isvector=false) |
virtual void | setGateSize (const char *gatename, int size) |
virtual cGate * | getOrCreateFirstUnconnectedGate (const char *gatename, char suffix, bool inside, bool expand) |
virtual void | getOrCreateFirstUnconnectedGatePair (const char *gatename, bool inside, bool expand, cGate *&gatein, cGate *&gateout) |
virtual void | finalizeParameters () override |
void | buildInside () |
Information about the module itself. | |
virtual bool | isSimple () const |
virtual ComponentKind | getComponentKind () const override |
virtual bool | isPlaceholder () const |
virtual cModule * | getParentModule () const override |
cModuleType * | getModuleType () const |
virtual cProperties * | getProperties () const override |
bool | isVector () const |
int | getIndex () const |
int | getVectorSize () const |
_OPPDEPRECATED int | size () const |
Submodule access. | |
virtual bool | hasSubmodules () const |
virtual int | findSubmodule (const char *name, int index=-1) const |
virtual cModule * | getSubmodule (const char *name, int index=-1) const |
virtual cModule * | getModuleByPath (const char *path) const |
virtual bool | containsModule (cModule *module) const |
Gates. | |
virtual cGate * | gate (const char *gatename, int index=-1) |
const cGate * | gate (const char *gatename, int index=-1) const |
virtual cGate * | gateHalf (const char *gatename, cGate::Type type, int index=-1) |
const cGate * | gateHalf (const char *gatename, cGate::Type type, int index=-1) const |
virtual bool | hasGate (const char *gatename, int index=-1) const |
virtual int | findGate (const char *gatename, int index=-1) const |
virtual cGate * | gate (int id) |
const cGate * | gate (int id) const |
virtual void | deleteGate (const char *gatename) |
virtual std::vector< const char * > | getGateNames () const |
virtual cGate::Type | gateType (const char *gatename) const |
virtual bool | isGateVector (const char *gatename) const |
virtual int | gateSize (const char *gatename) const |
virtual int | gateBaseId (const char *gatename) const |
virtual bool | checkInternalConnections () const |
virtual void | arrived (cMessage *msg, cGate *ongate, simtime_t t) |
Utilities. | |
virtual cPar & | getAncestorPar (const char *parname) |
virtual cCanvas * | getCanvas () const |
virtual cOsgCanvas * | getOsgCanvas () const |
virtual void | setBuiltinAnimationsAllowed (bool enabled) |
virtual bool | getBuiltinAnimationsAllowed () const |
Public methods for invoking initialize()/finish(), redefined from cComponent. | |
initialize(), numInitStages(), and finish() are themselves also declared in cComponent, and can be redefined in simple modules by the user to perform initialization and finalization (result recording, etc) tasks. | |
virtual void | callInitialize () override |
virtual bool | callInitialize (int stage) override |
virtual void | callFinish () override |
Dynamic module creation. | |
virtual void | scheduleStart (simtime_t t) |
virtual void | deleteModule () |
virtual void | changeParentTo (cModule *mod) |
Public Member Functions inherited from cComponent | |
cComponent (const char *name=nullptr) | |
virtual | ~cComponent () |
const cComponent * | getThisPtr () const |
virtual cComponentType * | getComponentType () const |
cSimulation * | getSimulation () const |
int | getId () const |
virtual const char * | getNedTypeName () const |
bool | isModule () const |
bool | isChannel () const |
virtual cModule * | getSystemModule () const |
virtual int | getNumParams () const |
virtual cPar & | par (int k) |
const cPar & | par (int k) const |
virtual cPar & | par (const char *parname) |
const cPar & | par (const char *parname) const |
virtual int | findPar (const char *parname) const |
bool | hasPar (const char *s) const |
virtual cRNG * | getRNG (int k) const |
virtual unsigned long | intrand (long r, int rng=0) const |
virtual double | dblrand (int rng=0) const |
virtual double | uniform (double a, double b, int rng=0) const |
virtual SimTime | uniform (SimTime a, SimTime b, int rng=0) const |
virtual double | exponential (double mean, int rng=0) const |
virtual SimTime | exponential (SimTime mean, int rng=0) const |
virtual double | normal (double mean, double stddev, int rng=0) const |
virtual SimTime | normal (SimTime mean, SimTime stddev, int rng=0) const |
virtual double | truncnormal (double mean, double stddev, int rng=0) const |
virtual SimTime | truncnormal (SimTime mean, SimTime stddev, int rng=0) const |
virtual double | gamma_d (double alpha, double theta, int rng=0) const |
virtual double | beta (double alpha1, double alpha2, int rng=0) const |
virtual double | erlang_k (unsigned int k, double mean, int rng=0) const |
virtual double | chi_square (unsigned int k, int rng=0) const |
virtual double | student_t (unsigned int i, int rng=0) const |
virtual double | cauchy (double a, double b, int rng=0) const |
virtual double | triang (double a, double b, double c, int rng=0) const |
virtual double | lognormal (double m, double w, int rng=0) const |
virtual double | weibull (double a, double b, int rng=0) const |
virtual double | pareto_shifted (double a, double b, double c, int rng=0) const |
virtual int | intuniform (int a, int b, int rng=0) const |
virtual int | intuniformexcl (int a, int b, int rng=0) const |
virtual int | bernoulli (double p, int rng=0) const |
virtual int | binomial (int n, double p, int rng=0) const |
virtual int | geometric (double p, int rng=0) const |
virtual int | negbinomial (int n, double p, int rng=0) const |
virtual int | poisson (double lambda, int rng=0) const |
virtual void | subscribe (simsignal_t signalID, cIListener *listener) |
virtual void | subscribe (const char *signalName, cIListener *listener) |
virtual void | unsubscribe (simsignal_t signalID, cIListener *listener) |
virtual void | unsubscribe (const char *signalName, cIListener *listener) |
virtual bool | isSubscribed (simsignal_t signalID, cIListener *listener) const |
virtual bool | isSubscribed (const char *signalName, cIListener *listener) const |
virtual std::vector< simsignal_t > | getLocalListenedSignals () const |
virtual std::vector< cIListener * > | getLocalSignalListeners (simsignal_t signalID) const |
virtual bool | hasGUI () const |
virtual cDisplayString & | getDisplayString () const |
virtual void | setDisplayString (const char *dispstr) |
virtual void | bubble (const char *text) const |
virtual std::string | resolveResourcePath (const char *fileName) const |
virtual void | recordScalar (const char *name, double value, const char *unit=nullptr) |
virtual void | recordScalar (const char *name, SimTime value, const char *unit=nullptr) |
virtual void | recordStatistic (cStatistic *stats, const char *unit=nullptr) |
virtual void | recordStatistic (const char *name, cStatistic *stats, const char *unit=nullptr) |
virtual void | emit (simsignal_t signalID, bool b, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, long l, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, unsigned long l, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, double d, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, const SimTime &t, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, const char *s, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, cObject *obj, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, const cObject *obj, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, char c, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, unsigned char c, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, short i, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, unsigned short i, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, int i, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, unsigned int i, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, float f, cObject *details=nullptr) |
virtual void | emit (simsignal_t signalID, long double d, cObject *details=nullptr) |
bool | mayHaveListeners (simsignal_t signalID) const |
bool | hasListeners (simsignal_t signalID) const |
Public Member Functions inherited from cDefaultList | |
cDefaultList (const char *name=nullptr) | |
virtual | ~cDefaultList () |
virtual bool | isSoftOwner () const override |
virtual void | parsimPack (cCommBuffer *buffer) const override |
virtual void | parsimUnpack (cCommBuffer *buffer) override |
bool | getPerformFinalGC () const |
virtual void | setPerformFinalGC (bool b) |
int | defaultListSize () const |
cOwnedObject * | defaultListGet (int k) |
bool | defaultListContains (cOwnedObject *obj) const |
Public Member Functions inherited from cNoncopyableOwnedObject | |
cNoncopyableOwnedObject (const char *name=nullptr, bool namepooling=true) | |
virtual cNoncopyableOwnedObject * | dup () const override |
Public Member Functions inherited from cOwnedObject | |
cOwnedObject () | |
cOwnedObject (const char *name, bool namepooling=true) | |
cOwnedObject (const cOwnedObject &obj) | |
virtual | ~cOwnedObject () |
cOwnedObject & | operator= (const cOwnedObject &o) |
virtual cObject * | getOwner () const override |
virtual bool | isOwnedObject () const override |
Public Member Functions inherited from cNamedObject | |
cNamedObject () | |
cNamedObject (const char *name, bool namepooling=true) | |
cNamedObject (const cNamedObject &obj) | |
virtual | ~cNamedObject () |
cNamedObject & | operator= (const cNamedObject &o) |
virtual const char * | getName () const override |
virtual void | setNamePooling (bool b) |
virtual bool | getNamePooling () |
Public Member Functions inherited from cObject | |
cObject () | |
cObject (const cObject &other) | |
virtual | ~cObject () |
virtual const char * | getClassName () const |
bool | isName (const char *s) const |
const cObject * | getThisPtr () const |
virtual _OPPDEPRECATED std::string | info () const |
virtual _OPPDEPRECATED std::string | detailedInfo () const |
cObject * | findObject (const char *name, bool deep=true) |
void | copyNotSupported () const |
Additional Inherited Members | |
Static Public Member Functions inherited from cComponent | |
static simsignal_t | registerSignal (const char *name) |
static const char * | getSignalName (simsignal_t signalID) |
Static Public Member Functions inherited from cOwnedObject | |
static long | getTotalObjectCount () |
static long | getLiveObjectCount () |
static void | resetObjectCounters () |
static cDefaultList * | getDefaultOwner () |
Protected Member Functions inherited from cComponent | |
virtual void | initialize (int stage) |
virtual int | numInitStages () const |
virtual void | initialize () |
virtual void | finish () |
virtual void | handleParameterChange (const char *parname) |
virtual void | refreshDisplay () const |
Protected Member Functions inherited from cDefaultList | |
virtual void | take (cOwnedObject *obj) override |
virtual void | drop (cOwnedObject *obj) override |
Protected Member Functions inherited from cObject | |
void | dropAndDelete (cOwnedObject *obj) |
cModule | ( | ) |
Constructor. Note that module objects should not be created directly, only via their cModuleType objects. cModuleType::create() will do all housekeeping tasks associated with module creation (assigning an ID to the module, inserting it into the global simulation
object (see cSimulation), etc.).
|
virtual |
Destructor. Note: it is not allowed delete modules directly, only via the deleteModule() method.
|
overridevirtual |
Calls v->visit(this) for each contained object. See cObject for more details.
Reimplemented from cComponent.
Reimplemented in cSimpleModule.
|
overridevirtual |
Sets object's name. Redefined to update the stored fullName string.
Reimplemented from cNamedObject.
|
overridevirtual |
|
overridevirtual |
Returns the full path name of the module. Example: "net.node[12].gen"
. The original getFullPath() was redefined in order to hide the global cSimulation instance from the path name.
Reimplemented from cObject.
|
overridevirtual |
|
virtual |
Adds a gate or gate vector to the module. Gate vectors are created with zero size. When the creation of a (non-vector) gate of type cGate::INOUT is requested, actually two gate objects will be created, "gatename$i" and "gatename$o". The specified gatename must not contain a "$i" or "$o" suffix itself.
CAUTION: The return value is only valid when a non-vector INPUT or OUTPUT gate was requested. nullptr gets returned for INOUT gates and gate vectors.
|
virtual |
Sets gate vector size. The specified gatename must not contain a "$i" or "$o" suffix: it is not possible to set different vector size for the "$i" or "$o" parts of an inout gate. Changing gate vector size is guaranteed NOT to change any gate IDs.
|
virtual |
Helper function for implementing NED's "gate++" syntax. Returns the next unconnected gate from an input or output gate vector, or input/output half of an inout vector. When gatename names an inout gate vector, the suffix parameter should be set to 'i' or 'o' to select "gatename$i" or "gatename$o"; otherwise suffix should be zero. The inside parameter selects whether to use isConnectedInside() or isConnectedOutside() to test if the gate is connected. The expand parameter tells whether the gate vector should be expanded if all its gates are used up.
|
virtual |
Helper function to implement NED's "gate++" syntax. This variant accepts inout gates only, and the result is returned in the gatein and gateout parameters. The meaning of the inside and expand parameters is the same as with getOrCreateFirstUnconnectedGate().
|
overridevirtual |
Redefined from cComponent. This method must be called as part of the module creation process, after moduleType->create() and before mod->buildInside(). It finalizes parameter values (e.g. reads the missing ones from omnetpp.ini), and adds gates and gate vectors (whose size may depend on parameter values) to the module.
So the sequence of setting up a module is:
The above sequence also explains why finalizeParameters() cannot by merged into either create() or buildInside().
Reimplemented from cComponent.
void buildInside | ( | ) |
In compound modules, this method should be called to create submodules and internal connections after module creation.
This method delegates to doBuildInside(), switching the context to this module for the duration of the call (see simulation.setContextModule()).
|
virtual |
Returns true if the C++ class of this module is a subclass of cSimpleModule, and false otherwise, i.e. it is equivalent to a dynamic_cast
.
In contrast, to check whether this module is a NED compound or simple module (i.e. whether it was declared with the "module" or with the "simple" keyword in NED), use cModuleType::isSimple()
: getModuleType()->isSimple()
.
|
inlineoverridevirtual |
Redefined from cComponent to return KIND_MODULE.
Implements cComponent.
|
inlinevirtual |
Returns true if this module is a placeholder module, i.e. represents a remote module in a parallel simulation run.
|
overridevirtual |
Returns the module containing this module. For the system module, it returns nullptr.
Implements cComponent.
|
inline |
Convenience method: casts the return value of getComponentType() to cModuleType.
|
overridevirtual |
Return the properties for this module. Properties cannot be changed at runtime. Redefined from cComponent.
Implements cComponent.
|
inline |
Returns true if this module is in a module vector.
|
inline |
Returns the index of the module if it is in a module vector, otherwise 0.
|
inline |
Returns the size of the module vector the module is in. For non-vector modules it returns 1.
|
inline |
Alias for getVectorSize().
|
inlinevirtual |
Returns true if the module has submodules, and false otherwise. To enumerate the submodules use SubmoduleIterator.
|
virtual |
Finds a direct submodule with the given name and index, and returns its module ID. If the submodule was not found, returns -1. Index must be specified exactly if the module is member of a module vector.
|
virtual |
Finds a direct submodule with the given name and index, and returns its pointer. If the submodule was not found, returns nullptr. Index must be specified exactly if the module is member of a module vector.
|
virtual |
Finds a module in the module tree, given by its absolute or relative path. The path is a string of module names separated by dots; the special module name ^ (caret) stands for the parent module. If the path starts with a dot or caret, it is understood as relative to this module, otherwise it is taken to mean an absolute path. For absolute paths, inclusion of the toplevel module's name in the path is optional. The toplevel module may also be referred to as "<root>". Returns nullptr if the module was not found or the empty string was given as input.
Examples: "" means nullptr. "." means this module; "<root>" means the toplevel module; ".sink" means the sink submodule of this module; ".queue[2].srv" means the srv submodule of the queue[2] submodule; "^.host2" or ".^.host2" means the host2 sibling module; "src" or "<root>.src" means the src submodule of the toplevel module; "Net.src" also means the src submodule of the toplevel module, provided it is called Net.
|
virtual |
Returns true of the given module has this module as an ancestor, and false otherwise.
|
virtual |
Looks up a gate by its name and index. Gate names with the "$i" or "$o" suffix are also accepted. Throws an error if the gate does not exist. The presence of the index parameter decides whether a vector or a scalar gate will be looked for.
|
inline |
Looks up a gate by its name and index. Gate names with the "$i" or "$o" suffix are also accepted. Throws an error if the gate does not exist. The presence of the index parameter decides whether a vector or a scalar gate will be looked for.
|
virtual |
Returns the "$i" or "$o" part of an inout gate, depending on the type parameter. That is, gateHalf("port", cGate::OUTPUT, 3) would return gate "port$o[3]". Throws an error if the gate does not exist. The presence of the index parameter decides whether a vector or a scalar gate will be looked for.
|
inline |
Returns the "$i" or "$o" part of an inout gate, depending on the type parameter. That is, gateHalf("port", cGate::OUTPUT, 3) would return gate "port$o[3]". Throws an error if the gate does not exist. The presence of the index parameter decides whether a vector or a scalar gate will be looked for.
|
virtual |
Checks if a gate exists. When invoked without index, it returns whether gate "gatename" or "gatename[]" exists (no matter if the gate vector size is currently zero). When invoked with an index, it returns whether the concrete "gatename[index]" gate exists (gatename being a vector gate). Gate names with the "$i" or "$o" suffix are also accepted.
|
virtual |
Returns the ID of the gate specified by name and index. Inout gates cannot be specified (since they are actually two gate objects, not one), only with a "$i" or "$o" suffix. Returns -1 if the gate does not exist. The presence of the index parameter decides whether a vector or a scalar gate will be looked for.
|
virtual |
Returns a gate by its ID. It throws an error for invalid (or stale) IDs.
Note: as of OMNeT++ 4.0, gate IDs are no longer small integers and are not suitable for enumerating all gates of a module. Use GateIterator for that purpose.
|
inline |
Returns a gate by its ID. It throws an error for invalid (or stale) IDs.
Note: as of OMNeT++ 4.0, gate IDs are no longer small integers and are not suitable for enumerating all gates of a module. Use GateIterator for that purpose.
References cModule::gate().
Referenced by cModule::gate().
|
virtual |
Deletes a gate, gate pair, or gate vector. Note: individual gates in a gate vector and one side of an inout gate (i.e. "foo$i") cannot be deleted. IDs of deleted gates will not be reused later.
|
virtual |
Returns the names of the module's gates. For gate vectors and inout gates, only the base name is returned (without gate index, "[]" or the "$i"/"$o" suffix). Zero-size gate vectors will also be included.
The strings in the returned array do not need to be deallocated and must not be modified.
|
virtual |
Returns the type of the gate (or gate vector) with the given name. Gate names with the "$i" or "$o" suffix are also accepted. Throws an error if there is no such gate or gate vector.
|
virtual |
Returns whether the given gate is a gate vector. Gate names with the "$i" or "$o" suffix are also accepted. Throws an error if there is no such gate or gate vector.
|
virtual |
Returns the size of the gate vector with the given name. It returns 1 for non-vector gates, and 0 if the gate does not exist or the vector has size 0. (Zero-size vectors are represented by a single gate whose size() returns 0.) Gate names with the "$i" or "$o" suffix are also accepted. Throws an error if there is no such gate or gate vector.
Note: The gate vector size can also be obtained by calling the cGate::size() method of any gate object.
|
virtual |
For vector gates, it returns the ID of gate 0 in the vector, even if the gate size is currently zero. All gates in the vector can be accessed by ID = gateBaseId + index. For scalar gates, it returns the ID of the gate. If there is no such gate or gate vector, an error gets thrown.
Note: Gate IDs are guaranteed to be stable, i.e. they do not change if the gate vector gets resized, or other gates get added/removed.
|
virtual |
For compound modules, it checks if all gates are connected inside the module (it returns true
if they are OK); for simple modules, it returns true
. This function is called during network setup.
This method is invoked as part of a send() call in another module. It is called when the message arrives at a gates in this module which is not further connected, that is, the gate's getNextGate() method returns nullptr. The default, cModule implementation reports an error ("message arrived at a compound module"), and the cSimpleModule implementation inserts the message into the FES after some processing.
Reimplemented in cSimpleModule.
|
virtual |
Searches for the parameter in the parent modules, up to the system module. If the parameter is not found, throws cRuntimeError.
|
virtual |
Returns the default canvas for this module, creating it if it hasn't existed before.
|
virtual |
Returns the default 3D (OpenSceneGraph) canvas for this module, creating it if it hasn't existed before.
|
inlinevirtual |
Sets whether built-in animations are requested on this module's graphical inspector.
|
inlinevirtual |
Returns true if built-in animations are requested on this module's graphical inspector, and false otherwise.
|
overridevirtual |
Interface for calling initialize() from outside.
Implements cComponent.
|
overridevirtual |
Interface for calling initialize() from outside. It does a single stage of initialization, and returns true
if more stages are required.
Implements cComponent.
|
overridevirtual |
Interface for calling finish() from outside.
Implements cComponent.
|
virtual |
Creates a starting message for modules that need it (and recursively for its submodules).
Reimplemented in cSimpleModule.
|
virtual |
Deletes the module and recursively all its submodules.
A running module can also delete itself. When an activity()-based simple module deletes itself from within its activity(), the deleteModule() call will not return (it throws an exception which gets caught by the simulation kernel, and the simulation kernel will delete the module).
When a handleMessage()-based module deletes itself, the deleteModule() returns normally – then, of course, the code should not try to access data members or functions of the deleted module, and should return as soon as possible.
It is not allowed to delete the system module. Also, a module cannot be deleted while its initialization is in progress.
|
virtual |
Moves the module under a new parent module. This functionality may be useful for some (rare) mobility scenarios.
NOTE: THIS METHOD CHANGES THE MODULE ID. To maintain a time-independent moduleId-to-fullPath mapping, this method will cause this module, and all modules under it in the module hierarchy, to be assigned a new ID. This usually causes no problem in the simulation's operation, but if your model stores module IDs somewhere, you'll need to invalidate or update them manually.
This function could bypass several rules which are enforced when you build the model using NED, so you must observe the following: