cISimulationLifecycleListener Class Reference

API: cISimulationLifecycleListener Class Reference
API
cISimulationLifecycleListener Class Referenceabstract
Inheritance diagram for cISimulationLifecycleListener:
[legend]

Public Member Functions

virtual ~cISimulationLifecycleListener ()
virtual void lifecycleEvent (SimulationLifecycleEventType eventType, cObject *details)=0
virtual void listenerAdded ()
virtual void listenerRemoved ()

Static Public Member Functions

static const char * getSimulationLifecycleEventName (SimulationLifecycleEventType eventType)

Description

A callback interface for receiving notifications at various stages simulations, including setting up, running, and tearing down..

Listeners can be added to cEnvir with its addLifecycleListener() method, and removed with removeLifecycleListener().

Simulation lifecycle listeners are mainly intended for use by plug-in classes that extend the simulator's functionality: schedulers, output vector/scalar managers, parallel simulation algorithms and so on. The lifecycle of a such plug-in class is managed by OMNeT++, so one can use their constructor to add the listener to cEnvir, and the destructor to remove it. (The latter is done automatically.)

Notifications always refer to the active simulation (see cSimulation::getActiveSimulation()).

For standalone listeners that have no other way to be invoked, one can use the EXECUTE_ON_STARTUP(code) macro to automatically add a listener when the program starts:

EXECUTE_ON_STARTUP(getEnvir()->addLifecycleListener(new MyListener()));
cEnvir * getEnvir()
Returns the environment object for the currently active simulation. This function never returns nullp...
Definition csimulation.h:631

Note that listeners will not be deleted automatically when the program exits. To delete a listener on shutdown, add delete this; into the listenerRemoved() method.

Constructor & Destructor Documentation

◆ ~cISimulationLifecycleListener()

virtual ~cISimulationLifecycleListener ( )
virtual

The destructor removes the listener from cEnvir if it is still added.

Member Function Documentation

◆ lifecycleEvent()

virtual void lifecycleEvent ( SimulationLifecycleEventType eventType,
cObject * details )
pure virtual

The main listener method, called on simulation lifecycle events.

Implemented in cIOutputScalarManager, cIOutputVectorManager, cISnapshotManager, and cScheduler.

◆ listenerAdded()

virtual void listenerAdded ( )
inlinevirtual

Fired after this listener was added to cEnvir, via addLifecycleListener().

◆ listenerRemoved()

virtual void listenerRemoved ( )
inlinevirtual

Fired after this listener was removed from cEnvir, via removeLifecycleListener(). It is OK for the listener to delete itself in the body of this method (delete this).

◆ getSimulationLifecycleEventName()

const char * getSimulationLifecycleEventName ( SimulationLifecycleEventType eventType)
static

Returns the string representation of the simulation lifecycle event type.