#include <cmodule.h>
Inheritance diagram for cSimpleModule::
Public Methods | |
Constructors, destructor, assignment. | |
cSimpleModule (const cSimpleModule &mod) | |
cSimpleModule (const char *name, cModule *parentmod, unsigned stk) | |
virtual | ~cSimpleModule () |
cSimpleModule& | operator= (const cSimpleModule &mod) |
Redefined cObject functions. | |
virtual cObject* | dup () const |
virtual void | info (char *buf) |
virtual void | forEach (ForeachFunc f) |
Redefined cModule functions. | |
virtual void | setId (int n) |
virtual bool | isSimple () const |
virtual bool | callInitialize (int stage) |
virtual void | callFinish () |
virtual void | scheduleStart (simtime_t t) |
virtual void | deleteModule () |
Information about the module. | |
bool | usesActivity () const |
Simulation time. | |
simtime_t | simTime () const |
Debugging aids. | |
void | setPhase (const char *phase) |
const char* | phase () const |
bool | snapshot (cObject *obj=&simulation, const char *label=NULL) |
void | breakpoint (const char *label) |
void | pause (const char *phase=NULL) |
Message sending. | |
int | send (cMessage *msg, int gateid) |
int | send (cMessage *msg, const char *gatename, int sn=-1) |
int | send (cMessage *msg, cGate *outputgate) |
int | sendDelayed (cMessage *msg, double delay, int gateid) |
int | sendDelayed (cMessage *msg, double delay, const char *gatename, int sn=-1) |
int | sendDelayed (cMessage *msg, double delay, cGate *outputgate) |
int | sendDirect (cMessage *msg, double delay, cModule *mod, int inputgateid) |
int | sendDirect (cMessage *msg, double delay, cModule *mod, const char *inputgatename, int sn=-1) |
int | sendDirect (cMessage *msg, double delay, cGate *inputgate) |
Self-messages. | |
int | scheduleAt (simtime_t t, cMessage *msg) |
cMessage* | cancelEvent (cMessage *msg) |
Parallel simulation. | |
void | syncpoint (simtime_t t, int gateid) |
void | syncpoint (simtime_t t, const char *gatename, int sn=-1) |
void | cancelSyncpoint (simtime_t t, int gateid) |
void | cancelSyncpoint (simtime_t t, const char *gatename, int sn=-1) |
Receiving messages. | |
These functions can only be used with activity(), but not with handleMessage(). | |
bool | isThereMessage () const |
cMessage* | receive () |
cMessage* | receive (simtime_t timeout) |
cMessage* | receiveOn (const char *gatename, int sn=-1, simtime_t timeout=MAXTIME) |
cMessage* | receiveOn (int gateid, simtime_t timeout=MAXTIME) |
cMessage* | receiveNew () |
cMessage* | receiveNew (simtime_t timeout) |
cMessage* | receiveNewOn (const char *gatename, int sn=-1, simtime_t timeout=MAXTIME) |
cMessage* | receiveNewOn (int gateid, simtime_t timeout=MAXTIME) |
Waiting. | |
void | wait (simtime_t time) |
void | waitAndEnqueue (simtime_t time, cQueue *queue) |
Stopping the module or the simulation. | |
void | end () |
void | endSimulation () |
void | error (const char *fmt,...) const |
Statistics collection | |
void | recordScalar (const char *name, double value) |
void | recordScalar (const char *name, const char *text) |
void | recordStats (const char *name, cStatistic *stats) |
virtual bool | stackOverflow () const |
virtual unsigned | stackSize () const |
virtual unsigned | stackUsage () const |
Miscellaneous. | |
void* | memAlloc (size_t m) |
void | memFree (void *&p) |
int | moduleState () const |
Public Attributes | |
cQueue | putAsideQueue |
Protected Methods | |
Hooks for defining module behavior. | |
Exactly one of activity() and handleMessage() must be redefined by the user to add functionality to the simple module. See the manual for detailed guidance on how use to these two methods.
These methods are made protected because they shouldn't be called directly from outside. | |
virtual void | activity () |
virtual void | handleMessage (cMessage *msg) |
One has to redefine either activity() or handleMessage() to contain the internal logic of the module. activity() and handleMessage() implement different event processing strategies: activity() is a coroutine-based solution which implements the process-interaction approach (coroutines are non-preemptive [cooperative] threads). handleMessage() is a method that is called by the simulation kernel when the module receives a message.
The finish() functions are called when the simulation terminates successfully. Typical use of finish() is recording statistics collected during simulation.
The activity() functions run as coroutines during simulation. Coroutines are brought to cSimpleModule from the cCoroutine base class.
|
Copy constructor. |
|
Constructor. Note that module objects should not be created directly, only via their cModuleType objects. See cModule constructor for more info. |
|
Destructor. |
|
Should be redefined to contain the module activity function. This default implementation issues an error message (throws cException). |
|
Specifies a breakpoint. During simulation, if execution gets to a breakpoint() call (and breakpoints are active etc.), the simulation will be stopped, if the user interface can handle breakpoints. |
|
Calls finish() in the context of this module. Reimplemented from cModule. |
|
Calls initialize(int stage) in the context of this module. It does a single stage of initialization, and returns Reimplemented from cModule. |
|
Removes the given message from the future events. The message needs to have been sent using the scheduleAt() function. This function can be used to cancel a timer implemented with scheduleAt(). |
|
Used with parallel execution: cancel a synchronization point set by a syncpoint() call. |
|
Used with parallel execution: cancel a synchronization point set by a syncpoint() call. |
|
Deletes a dynamically created module. A running module can also delete itself. Reimplemented from cModule. |
|
Creates and returns an exact copy of this object. See cObject for more details. Reimplemented from cObject. |
|
Ends the run of the simple module. The simulation is not stopped (unless this is the last running module.) The implementation simply throws a cEndModuleException. Note that end() does NOT delete the module; its state is simply set to Ended and it won't take part in further simulation. If you also want to delete the module, use deleteModule(); however, this implies that the module's finish() method won't be called at the end of the simulation. |
|
Causes the whole simulation to stop. The implementation simply throws a cTerminationException. |
|
DEPRECATED. Equivalent to |
|
Call the passed function for each contained object. See cObject for more details. Reimplemented from cModule. |
|
Should be redefined to contain the module's message handling function. This default implementation issues an error message (throws cException). |
|
Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cObject. |
|
Returns true. Reimplemented from cModule. |
|
DEPRECATED. Tells if the next message in the event queue is for the same module and has the same arrival time. (Returns true only if two or more messages arrived to the module at the same time.) |
|
Dynamic memory allocation. This function should be used instead of the global malloc() from inside the module function (activity()), if deallocation by the simple module constructor is not provided. Dynamic allocations are discouraged in general unless you put the pointer into the class declaration of the simple module class and provide a proper destructor. Or, you can use container classes (cArray, cQueue)! |
|
Frees a memory block reserved with the malloc() described above and NULLs the pointer. |
|
Returns module state. |
|
Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details. |
|
Sets phase string and temporarily yield control to the user interface. If the user interface supports step-by-step execution, one can stop execution at each receive() call of the module function and examine the objects, variables, etc. If the state of simulation between receive() calls is also of interest, one can use pause() calls. The string argument (if given) sets the phase string, so pause("here") is the same as setPhase("here"); pause(). |
|
DEPRECATED. Returns pointer to the current phase string. |
|
Returns the first message from the put-aside queue or, if it is empty, calls receiveNew() to return a message from the event queue with the given timeout. Note that the arrival time of the message returned by receive() can be earlier than the current simulation time. |
|
Receives a message from the put-aside queue or the FES. |
|
Removes the next message from the event queue and returns a pointer to it. Ignores put-aside queue. If there is no message in the event queue, the function waits with t timeout until a message will be available. If the timeout expires and there is still no message in the queue, the function returns NULL. IMPORTANT: This function should not be used. As putAsideQueue is deprecated, it will be removed at some point in the future. This means that then the receive() method will act exactly as this one, and this method will no longer be needed. See the API-doc on putAsideQueue, wait() and waitAndEnqueue() for more explanation. |
|
Remove the next message from the event queue and return a pointer to it. Ignores put-aside queue. IMPORTANT: This function should not be used. As putAsideQueue is deprecated, it will be removed at some point in the future. This means that then the receive() method will act exactly as this one, and this method will no longer be needed. See the API-doc on putAsideQueue, wait() and waitAndEnqueue() for more explanation. |
|
Same as the previous function except that the gate must be specified with its index in the gate array. Using this function instead the previous one may speed up the simulation if the function is called frequently. IMPORTANT: This function should not be used. As putAsideQueue is deprecated, it will be removed at some point in the future. This means that then the receiveOn() method will act exactly as this one, and this method will no longer be needed. See the API-doc on putAsideQueue, wait() and waitAndEnqueue() for more explanation. |
|
The same as receiveNew(), except that it returns the next message that arrives on the gate specified with its name and index. All messages received meanwhile are inserted into the put-aside queue. If the timeout expires and there is still no such message in the queue, the function returns NULL. In order to process messages that may have been put in the put-aside queue, the user is expected to call receive() or receiveOn(), or to examine the put-aside queue directly sometime. IMPORTANT: This function should not be used. As putAsideQueue is deprecated, it will be removed at some point in the future. This means that then the receiveOn() method will act exactly as this one, and this method will no longer be needed. See the API-doc on putAsideQueue, wait() and waitAndEnqueue() for more explanation. |
|
Same as the previous function except that the gate must be specified with its index in the gate array. Using this function instead the previous one may speed up the simulation if the function is called frequently. IMPORTANT: The put-aside queue has been deprecated, and the semantics of this function will be changed in the future. It will be intended for use only if you do not expect other messages to arrive at the module on other gates than the specified one. To assert this, it will throw an exception if an inappropriate message arrives, as it will probably signal a logic error in the model. On the other hand, if you do expect to receive other messages during the call, you should not use receiveOn() but implement similar functionality using a loop (for() or while()) and receive(), which will make your intent more conspicuous to the reader of your source code. See the API-doc on putAsideQueue for more explanation. |
|
Scans the put-aside queue for the first message that has arrived on the gate specified with its name and index. If there is no such message in the put-aside queue, calls receiveNew() to return a message from the event queue with the given timeout. Note that the arrival time of the message returned by receive() can be earlier than the current simulation time. IMPORTANT: The put-aside queue has been deprecated, and the semantics of this function will be changed in the future. It will be intended for use only if you do not expect other messages to arrive at the module on other gates than the specified one. To assert this, it will throw an exception if an inappropriate message arrives, as it will probably signal a logic error in the model. On the other hand, if you do expect to receive other messages during the call, you should not use receiveOn() but implement similar functionality using a loop (for() or while()) and receive(), which will make your intent more conspicuous to the reader of your source code. See the API-doc on putAsideQueue for more explanation. |
|
Records a string into the scalar result file. |
|
Records a double into the scalar result file. |
|
Records a statistics object into the scalar result file. |
|
Schedules a self-message. Receive() will return the message at t simulation time. |
|
Creates a starting message for the module. Reimplemented from cModule. |
|
Sends a message through the gate given with its pointer. |
|
Sends a message through the gate given with its name and index (if multiple gate). |
|
Sends a message through the gate given with its ID. |
|
Sends a message through the gate given with its pointer as if it was sent delay seconds later. |
|
Delayed sending. Sends a message through the gate given with its name and index (if multiple gate) as if it was sent delay seconds later. |
|
Delayed sending. Sends a message through the gate given with its index as if it was sent delay seconds later. |
|
Sends a message directly to another module (to an input gate). |
|
Send a message directly to another module (to an input gate). |
|
Send a message directly to another module (to an input gate). |
|
FIXME: redefined cModule functions: Reimplemented from cModule. |
|
DEPRECATED. Sets the phase string which can be displayed as some kind of status. The module creates its own copy of the string. |
|
Returns the current simulation time (that is, the arrival time of the last message returned by a receiveNew() call). |
|
To be called from module functions. Outputs textual information about all objects of the simulation (including the objects created in module functions by the user!) into the snapshot file. The output is detailed enough to be used for debugging the simulation: by regularly calling snapshot(), one can trace how the values of variables, objects changed over the simulation. The arguments: label is a string that will appear in the output file; obj is the object whose inside is of interest. By default, the whole simulation (all modules etc) will be written out. Tkenv also supports making snapshots manually, from menu. See also class cWatch and the WATCH() macro. |
|
Returns true if there was a stack overflow during execution of the coroutine. (Not implemented for every coroutine package - see cCoroutine documentation for more info.) If the module uses handleMessage(), this method always returns false.
|
|
Returns the stack size of the coroutine. If the module uses handleMessage(), this method always returns 0. |
|
Returns the amount of stack actually used by the coroutine. (Not implemented for every coroutine package - see cCoroutine documentation for more info.) If the module uses handleMessage(), this method always returns 0.
|
|
Used with parallel execution: synchronize with receiver segment. Blocks receiver at t until a message arrives. |
|
Used with parallel execution: synchronize with receiver segment. Blocks receiver at t until a message arrives. |
|
Returns event handling scheme. |
|
Waits for the given interval. (Some other simulators call this functionality hold()). The messages received meanwhile are inserted into the put-aside queue, but if you expect to receive messages during the call, you should use the waitAndEnqueue() method instead (see the following note). This function can only be used with activity(), but not with handleMessage(). IMPORTANT: The put-aside queue has been deprecated, and the semantics of this function will be changed in the future. It will be intended for use only if you do not expect other messages to arrive at the module during the wait period. To assert this, it will throw an exception if a message arrives during the wait, as it will probably signal a logic error in the model. On the other hand, if you do expect to receive messages during the call, you should use waitAndEnqueue(), which makes this assumption much more conspicuous to the reader of your source code than the old wait() method with its implicit putAsideQueue would. See the API-doc on putAsideQueue for more explanation. |
|
Waits for the given interval. The messages received during the wait period are inserted into the queue passed as argument. This function can only be used with activity(), but not with handleMessage(). |
|
DEPRECATED. putAsideQueue will be removed at some point in the future, and this will affect the message receiving functions. Details below. putAsideQueue is used implicitly by the methods wait(), receiveOn() and receiveNewOn() to insert messages that arrive during the wait period or not on the specified gate. The receive() functions looked first on the putAsideQueue and only then at the future events. As practice has shown, the purpose of the putAsideQueue was very often misunderstood, and its implicit use by wait() and the message receiving functions was highly error-prone. It will be removed at some point in the future. Be prepared: use wait() and receiveOn() if you do not expect other messages to arrive at the module; use waitAndEnqueue() where you mean it; do not use the receiveNew..() functions as they will be made redundant when putAsideQueue goes away. |