Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cModule Class Reference

#include <cmodule.h>

Inheritance diagram for cModule::

cObject cCompoundModule cNetMod cSimpleModule List of all members.

Public Methods

Constructors, destructor, assignment.
 cModule (const cModule &mod)
 cModule (const char *name, cModule *parentmod)
virtual ~cModule ()
cModule& operator= (const cModule &mod)
Redefined cObject functions.
virtual void forEach (ForeachFunc f)
virtual const char* fullName () const
virtual const char* fullPath () const
virtual const char* fullPath (char *buffer, int bufsize) const
Setting up the module.
virtual void setId (int n)
void setIndex (int i, int n)
void setModuleType (cModuleType *mtype)
cGateaddGate (const char *s, char tp)
void setGateSize (const char *s, int size)
cParaddPar (const char *s)
void addMachinePar (const char *pnam)
void setMachinePar (const char *pnam, const char *val)
virtual int buildInside ()
Information about the module itself.
virtual bool isSimple () const=0
cModuleTypemoduleType () const
int id () const
cModule* parentModule () const
bool isOnLocalMachine () const
bool isVector () const
int index () const
int size () const
Submodule access.
int findSubmodule (const char *submodname, int idx=-1)
cModule* submodule (const char *submodname, int idx=-1)
cModule* moduleByRelativePath (const char *path)
Gates.
int gates () const
cGategate (int g)
const cGategate (int g) const
cGategate (const char *gatename, int sn=-1)
const cGategate (const char *gatename, int sn=-1) const
int findGate (const char *gatename, int sn=-1) const
bool hasGate (const char *gatename, int sn=-1) const
bool checkInternalConnections () const
Parameters.
int params () const
cParpar (int p)
cParpar (const char *parname)
int findPar (const char *parname) const
cParancestorPar (const char *parname)
bool hasPar (const char *s) const
Machine parameters (used by parallel execution).
int machinePars () const
const char* machinePar (int i)
const char* machinePar (const char *machinename)
Interface for calling initialize()/finish().
Those functions may not be called directly, only via callInitialize() and callFinish() provided here.

virtual void callInitialize ()
virtual bool callInitialize (int stage)=0
virtual void callFinish ()=0
Dynamic module creation.
virtual void scheduleStart (simtime_t t)=0
virtual void deleteModule ()=0
Display strings.
const char* displayString ()
void setDisplayString (const char *dispstr, bool immediate=true)
const char* displayStringAsParent ()
void setDisplayStringAsParent (const char *dispstr, bool immediate=true)
const char* displayString (int type)
void setDisplayString (int type, const char *dispstr, bool immediate=true)
void setDisplayStringNotify (DisplayStringNotifyFunc notify_func, void *data)

Protected Methods

Initialization and finish hooks.
Initialize and finish functions should (may) be provided by the user, to perform special tasks at the beginning and the end of the simulation. The functions are made protected because they are supposed to be called only via callInitialize() and callFinish().

The initialization process was designed to support multi-stage initialization of compound modules (i.e. initialization in several 'waves'). (Calling the initialize() function of a simple module is hence a special case). The initialization process is performed on a module like this. First, the number of necessary initialization stages is determined by calling numInitStages(), then initialize(stage) is called with 0,1,...numstages-1 as argument. The default implementation of numInitStages() and initialize(stage) provided here defaults to single-stage initialization, that is, numInitStages() returns 1 and initialize(stage) simply calls initialize() if stage is 0.

All initialization and finish functions are redefined in cCompoundModule to recursively traverse all submodules.

virtual void doBuildInside ()
virtual void initialize (int stage)
virtual int numInitStages () const
virtual void initialize ()
virtual void finish ()

Detailed Description

Common base for cSimpleModule and cCompoundModule. Provides gates, parameters, error handling, etc.

NOTE: dup() cannot be use with modules. Use mod->moduleType()->create()/buildInside() instead.


Constructor & Destructor Documentation

cModule::cModule ( const cModule & mod )
 

Copy constructor.

cModule::cModule ( const char * name,
cModule * parentmod )
 

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.).

cModule::~cModule ( ) [virtual]
 

Destructor.


Member Function Documentation

cGate * cModule::addGate ( const char * s,
char tp )
 

Adds a gate. The type character tp can be 'I' or 'O' for input and output, respectively.

void cModule::addMachinePar ( const char * pnam )
 

Adds a machine parameter to the module.

cPar * cModule::addPar ( const char * s )
 

Adds a parameter to the module.

cPar & cModule::ancestorPar ( const char * parname )
 

Searches for the parameter in the parent modules, up to the system module. It the parameter is not found, throws cException.

int cModule::buildInside ( ) [virtual]
 

In compound modules, this method can be called to build submodules and internal connections after module creation. This method is a wrapper around doBuildInside().

It does the following:

  • 1. checks if module parameters and gates conform to the module interface (cModuleInterface object, generated from NED declaration of module)
  • 2. calls doBuildInside(), switching to the context of this module for the duration of the call (using simulation.setContextModule()).
Note: semantic has changed -- in OMNeT++ 2.2 and earlier versions, doBuildInside() did not exist, its role was fulfilled by this method. After 2.2, the return value of this method was changed from void to int deliberately to cause compile error in older code, in order to call attention to the semantics change. (Returned value can be ignored.)

See also:
doBuildInside()

void cModule::callFinish ( ) [pure virtual]
 

Interface for calling finish() from outside.

Reimplemented in cSimpleModule, cCompoundModule, and cNetMod.

bool cModule::callInitialize ( int stage ) [pure virtual]
 

Interface for calling initialize() from outside. It does a single stage of initialization, and returns true if more stages are required.

Reimplemented in cSimpleModule, cCompoundModule, and cNetMod.

void cModule::callInitialize ( ) [virtual]
 

Interface for calling initialize() from outside. Implements full multi-stage init for this module and its submodules.

bool cModule::checkInternalConnections ( ) const
 

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 usually called from from NEDC-generated code.

void cModule::deleteModule ( ) [pure virtual]
 

Deletes a dynamically created module and recursively all its submodules. This is a pure virtual function; it is redefined in both cCompoundModule and cSimpleModule.

Reimplemented in cSimpleModule, cCompoundModule, and cNetMod.

const char * cModule::displayString ( int type )
 

DEPRECATED. Use displayString() (without argument) or displayStringAsLocal() instead.

const char * cModule::displayString ( )
 

Returns the first display string. This display string defines presentation when the module is displayed as a submodule in a compound module graphics.

const char * cModule::displayStringAsParent ( )
 

Returns the second display string. This display string is used when this module is a compound module whose internals are being displayed in a window.

void cModule::doBuildInside ( ) [inline, protected, virtual]
 

Should be refined in subclasses representing compound modules to build submodule and internal connections of this module. This default implementation does nothing.

This method should not be called directly, only via buildInside(); this method is declared protected to enforce this.

See also:
buildInside()

int cModule::findGate ( const char * gatename,
int sn = -1 ) const
 

Returns the ID of the gate specified by name and index. Returns -1 if the gate doesn't exist.

int cModule::findPar ( const char * parname ) const
 

Returns index of the module parameter specified with its name. Returns -1 if the object doesn't exist.

int cModule::findSubmodule ( const char * submodname,
int idx = -1 )
 

Finds an immediate submodule with the given name and (optional) index, and returns its module ID. If the submodule was not found, returns -1.

void cModule::finish ( ) [protected, virtual]
 

Finish hook. finish() is called after end of simulation, if it terminated without error. This default implementation does nothing.

void cModule::forEach ( ForeachFunc f ) [virtual]
 

Call the passed function for each contained object. See cObject for more details.

Reimplemented from cObject.

Reimplemented in cSimpleModule.

const char * cModule::fullName ( ) const [virtual]
 

Returns the full name of the module, which is name() plus the index in square brackets (e.g. "module[4]"). Redefined to add the index.

Reimplemented from cObject.

const char * cModule::fullPath ( char * buffer,
int bufsize ) const [virtual]
 

Returns the full path name of the module. Example: "mynet.node[12].gen". The original fullPath() was redefined in order to hide the global cSimulation instance in the path name (it would add "simulation." to the beginning of the full path).

Reimplemented from cObject.

const char * cModule::fullPath ( ) const [virtual]
 

Redefined. (Reason: a C++ rule that overloaded virtual methods must be redefined together.)

Reimplemented from cObject.

const cGate * cModule::gate ( const char * gatename,
int sn = -1 ) const
 

Looks up a gate by its name and index. Returns NULL if the gate does not exist.

cGate * cModule::gate ( const char * gatename,
int sn = -1 )
 

Looks up a gate by its name and index. Returns NULL if the gate does not exist.

const cGate * cModule::gate ( int g ) const [inline]
 

Returns a gate by its ID. Returns NULL if the gate does not exist.

cGate * cModule::gate ( int g ) [inline]
 

Returns a gate by its ID. Returns NULL if the gate does not exist.

int cModule::gates ( ) const [inline]
 

Returns the total size of the gate array. Since the array may contain unused elements, the number of actual gates used might be less.

bool cModule::hasGate ( const char * gatename,
int sn = -1 ) const [inline]
 

Checks if a gate exists.

bool cModule::hasPar ( const char * s ) const [inline]
 

Check if a parameter exists.

int cModule::id ( ) const [inline]
 

Returns the module ID. It is actually the index of the module in the module vector within the cSimulation simulation object. Module IDs are guaranteed to be unique during a simulation run (that is, IDs of deleted modules are not given out to newly created modules).

int cModule::index ( ) const [inline]
 

Returns the index of the module if it is in a module vector, otherwise 0.

void cModule::initialize ( ) [protected, virtual]
 

Single-stage initialization hook. This default implementation does nothing.

void cModule::initialize ( int stage ) [inline, protected, virtual]
 

Multi-stage initialization hook. This default implementation does single-stage init, that is, calls initialize() if stage is 0.

bool cModule::isOnLocalMachine ( ) const
 

Used with parallel execution: determines if the module is on the local machine. See the user manual for more info.

bool cModule::isSimple ( ) const [pure virtual]
 

Returns this is a simple or compound module. Pure virtual function, redefined in cSimpleModule to return true and in cCompoundModule to return false.

Reimplemented in cSimpleModule, cCompoundModule, and cNetMod.

bool cModule::isVector ( ) const [inline]
 

Returns true if this module is in a module vector.

const char * cModule::machinePar ( const char * machinename )
 

Returns a machine parameter by its name.

const char * cModule::machinePar ( int i )
 

Returns the value of the ith machine parameter.

int cModule::machinePars ( ) const [inline]
 

Returns the number of machine parameters.

cModule * cModule::moduleByRelativePath ( const char * path )
 

Finds a submodule potentially several levels deeper, given with its relative path from this module. (The path is a string of module full names separated by dots). If the submodule was not found, returns NULL.

cModuleType * cModule::moduleType ( ) const [inline]
 

Returns the cModuleType object associated with this module type.

int cModule::numInitStages ( ) const [inline, protected, virtual]
 

Multi-stage initialization hook, should be redefined to return the number of initialization stages required. This default implementation does single-stage init, that is, returns 1.

cModule & cModule::operator= ( const cModule & mod )
 

Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details.

cPar & cModule::par ( const char * parname )
 

Returns reference to the module parameter specified with its name. Returns *NULL if the object doesn't exist.

cPar & cModule::par ( int p )
 

Returns reference to the module parameter identified with its index p. Returns *NULL if the object doesn't exist.

int cModule::params ( ) const [inline]
 

Returns total number of the module's parameters.

cModule * cModule::parentModule ( ) const [inline]
 

Returns the module's parent module. For the system module, it returns NULL.

void cModule::scheduleStart ( simtime_t t ) [pure virtual]
 

Pure virtual function; it is redefined in both cCompoundModule and cSimpleModule. It creates starting message for dynamically created module (or recursively for its submodules). See the user manual for explanation how to use dynamically created modules.

Reimplemented in cSimpleModule, cCompoundModule, and cNetMod.

void cModule::setDisplayString ( int type,
const char * dispstr,
bool immediate = true )
 

DEPRECATED. Use setDisplayString(dispstr,immediate) (without the type argument) or displayStringAsLocal(dispstr,immediate) instead.

void cModule::setDisplayString ( const char * dispstr,
bool immediate = true )
 

Sets the first display string for this module. This display string defines presentation when the module is displayed as a submodule in a compound module graphics.

The immediate flag selects whether the change should become effective right now or later (after finishing the current event).

If several display string changes are going to be done within one event, then immediate=false is useful because it reduces the number of necessary redraws. Immediate=false also uses less stack. But its drawback is that a setDisplayString() followed by a send() would actually be displayed in reverse order (message animation first), because message animations are performed immediately (actually within the send() call).

void cModule::setDisplayStringAsParent ( const char * dispstr,
bool immediate = true )
 

Sets the second display string for this module. This display string is used when this module is a compound module whose internals are being displayed in a window.

The immediate flag selects whether the change should become effective right now or later (after finishing the current event).

If several display string changes are going to be done within one event, then immediate=false is useful because it reduces the number of necessary redraws. Immediate=false also uses less stack. But its drawback is that a setDisplayString() followed by a send() would actually be displayed in reverse order (message animation first), because message animations are performed immediately (actually within the send() call).

void cModule::setDisplayStringNotify ( DisplayStringNotifyFunc notify_func,
void * data )
 

Registers a notification function to be called when the display string changes. This function is used by graphical user interfaces (e.g. Tkenv) to get notified when the network graphics needs redraw due to a display string change.

void cModule::setGateSize ( const char * s,
int size )
 

Sets gate vector size.

void cModule::setId ( int n ) [virtual]
 

Sets the module ID. Called internally as part of the module creation process.

Reimplemented in cSimpleModule.

void cModule::setIndex ( int i,
int n )
 

Sets module index within vector (if module is part of a module vector). Called internally as part of the module creation process.

void cModule::setMachinePar ( const char * pnam,
const char * val )
 

Sets value of a machine parameter.

void cModule::setModuleType ( cModuleType * mtype )
 

Sets associated cModuleType for the module. Called internally as part of the module creation process.

int cModule::size ( ) const [inline]
 

Returns the size of the module vector the module is in, or 1.

cModule * cModule::submodule ( const char * submodname,
int idx = -1 )
 

Finds an immediate submodule with the given name and (optional) index, and returns its pointer. If the submodule was not found, returns NULL.


The documentation for this class was generated from the following file:
Generated at Mon Jun 16 23:37:32 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001