Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | Namespace Members | Class Members

Simulator Class Reference

#include <simulator/simulator.h>

Inheritance diagram for Simulator:

Inheritance graph
[legend]
Collaboration diagram for Simulator:

Collaboration graph
[legend]
List of all members.

Detailed Description

Manager of the simulation, this class is responsible for handling simulation events.

simulatedTime |factor systemTime

simut = (syst - syst_ref) * factor + simut_ref

Author:
Nicolas Brodu


Public Member Functions

template<class A>
const GenericDispatcherpost (void(*method)(A), A argument)
 Post an event at current time.
template<class A1, class A2>
const GenericDispatcherpost (void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at current time.
template<class A1, class A2, class A3>
const GenericDispatcherpost (void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at current time.
template<class T>
const GenericDispatcherpost (T *object, void(T::*method)())
 Post an event at current time.
template<class T, class A>
const GenericDispatcherpost (T *object, void(T::*method)(A), A argument)
 Post an event at current time.
template<class T, class A1, class A2>
const GenericDispatcherpost (T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at current time.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpost (T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at current time.
template<class T>
const GenericDispatcherpostCyclic (double cycle, T *object, void(T::*method)())
 Post a cyclic event at current time.
template<class T, class A>
const GenericDispatcherpostCyclic (double cycle, T *object, void(T::*method)(A), A argument)
 Post a cyclic event at current time.
template<class T, class A1, class A2>
const GenericDispatcherpostCyclic (double cycle, T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at current time.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostCyclic (double cycle, T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at current time.
template<class A>
const GenericDispatcherpostCyclic (double cycle, void(*method)(A), A argument)
 Post a cyclic event at current time.
template<class A1, class A2>
const GenericDispatcherpostCyclic (double cycle, void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at current time.
template<class A1, class A2, class A3>
const GenericDispatcherpostCyclic (double cycle, void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at current time.
template<class A>
const GenericDispatcherpostIn (double delay, void(*method)(A), A argument)
 Post an event at current time + a certain delay in simulated time Any C "void method(..)" with one argument can be called this way.
template<class A1, class A2>
const GenericDispatcherpostIn (double delay, void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at current time + a certain delay in simulated time Any C "void method(..)" with two arguments can be called this way.
template<class A1, class A2, class A3>
const GenericDispatcherpostIn (double delay, void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at current time + a certain delay in simulated time Any C "void method(..)" with three arguments can be called this way.
template<class T>
const GenericDispatcherpostIn (double delay, T *object, void(T::*method)())
 Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A>
const GenericDispatcherpostIn (double delay, T *object, void(T::*method)(A), A argument)
 Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A1, class A2>
const GenericDispatcherpostIn (double delay, T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostIn (double delay, T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T>
const GenericDispatcherpostCyclicIn (double delay, double cycle, T *object, void(T::*method)())
 Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A>
const GenericDispatcherpostCyclicIn (double delay, double cycle, T *object, void(T::*method)(A), A argument)
 Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A1, class A2>
const GenericDispatcherpostCyclicIn (double delay, double cycle, T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostCyclicIn (double delay, double cycle, T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.
template<class A>
const GenericDispatcherpostCyclicIn (double delay, double cycle, void(*method)(A), A argument)
 Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with one argument can be called this way.
template<class A1, class A2>
const GenericDispatcherpostCyclicIn (double delay, double cycle, void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with two arguments can be called this way.
template<class A1, class A2, class A3>
const GenericDispatcherpostCyclicIn (double delay, double cycle, void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with three arguments can be called this way.
template<class A>
const GenericDispatcherpostAt (double absoluteTime, void(*method)(A), A argument)
 Post an event at an absolute simulated time.
template<class A1, class A2>
const GenericDispatcherpostAt (double absoluteTime, void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at an absolute simulated time.
template<class A1, class A2, class A3>
const GenericDispatcherpostAt (double absoluteTime, void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at an absolute simulated time.
template<class T>
const GenericDispatcherpostAt (double absoluteTime, T *object, void(T::*method)())
 Post an event at an absolute simulated time.
template<class T, class A>
const GenericDispatcherpostAt (double absoluteTime, T *object, void(T::*method)(A), A argument)
 Post an event at an absolute simulated time.
template<class T, class A1, class A2>
const GenericDispatcherpostAt (double absoluteTime, T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event at an absolute simulated time.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostAt (double absoluteTime, T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event at an absolute simulated time.
template<class T>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, T *object, void(T::*method)())
 Post a cyclic event at an absolute simulated time.
template<class T, class A>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, T *object, void(T::*method)(A), A argument)
 Post a cyclic event at an absolute simulated time.
template<class T, class A1, class A2>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at an absolute simulated time.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at an absolute simulated time.
template<class A>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, void(*method)(A), A argument)
 Post a cyclic event at an absolute simulated time.
template<class A1, class A2>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post a cyclic event at an absolute simulated time.
template<class A1, class A2, class A3>
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post a cyclic event at an absolute simulated time.
template<class T>
const GenericDispatcherpostAtStop (T *object, void(T::*method)())
 Post an event to be executed when the simulation stops.
template<class T, class A>
const GenericDispatcherpostAtStop (T *object, void(T::*method)(A), A argument)
 Post an event to be executed when the simulation stops.
template<class T, class A1, class A2>
const GenericDispatcherpostAtStop (T *object, void(T::*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event to be executed when the simulation stops.
template<class T, class A1, class A2, class A3>
const GenericDispatcherpostAtStop (T *object, void(T::*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event to be executed when the simulation stops.
template<class A>
const GenericDispatcherpostAtStop (void(*method)(A), A argument)
 Post an event to be executed when the simulation stops.
template<class A1, class A2>
const GenericDispatcherpostAtStop (void(*method)(A1, A2), A1 argument1, A2 argument2)
 Post an event to be executed when the simulation stops.
template<class A1, class A2, class A3>
const GenericDispatcherpostAtStop (void(*method)(A1, A2, A3), A1 argument1, A2 argument2, A3 argument3)
 Post an event to be executed when the simulation stops.
virtual void cancel (const GenericDispatcher *dispatcher)
 Cancels the selected event.
virtual void flush ()
 Flush all posted events without executing them.
virtual const GenericDispatcherpost (const GenericDispatcher *dispatcher)
 Post an event at current time.
const GenericDispatcherpost (void(*method)())
 Post an event at current time.
const GenericDispatcherpostCyclic (double cycle, void(*method)())
 Post a cyclic event at current time.
virtual const GenericDispatcherpostIn (double delay, const GenericDispatcher *dispatcher)
 Post an event at current time + a certain delay in simulated time Use this function together with a specialized dispatcher to post methods with more than 3 arguments, or to pass static methods and global functions Note: Template methods are provided, included postCyclic methods.
const GenericDispatcherpostIn (double delay, void(*method)())
 Post an event at current time + a certain delay in simulated time Any C "void method()" can be called this way.
const GenericDispatcherpostCyclicIn (double delay, double cycle, void(*method)())
 Post a cyclic event at current time + a certain delay in simulated time Any C "void method()" can be called this way.
virtual const GenericDispatcherpostAt (double absoluteTime, const GenericDispatcher *dispatcher)
 Post an event at an absolute simulated time Use this function together with a specialized dispatcher to post methods with more than 3 arguments, or to pass static methods and global functions Note: Template methods are provided, included postCyclic methods.
const GenericDispatcherpostAt (double absoluteTime, void(*method)())
 Post an event at an absolute simulated time.
const GenericDispatcherpostCyclicAt (double absoluteTime, double cycle, void(*method)())
 Post a cyclic event at an absolute simulated time.
virtual bool step ()
 Process next event in the queue, if possible.
virtual bool step (double absoluteTime)
 Process next events in the queue, if possible, till the given simulated time is reached.
virtual void setTimeFactor (double factor)
 Correspondance between once unit of time in system time and one unit in simulated time.
virtual double getTimeFactor () const
virtual double getTime () const
 Gets the current simulated time since the simulation started or the last reset.
virtual void resetTime ()
 Resets the current simulated time parameter to 0.
virtual void stop (bool waitForStop=false)
 Stop processing events automatically.
virtual const GenericDispatcherpostAtStop (const GenericDispatcher *dispatcher)
 Post an event to be executed when the simulation stops.
const GenericDispatcherpostAtStop (void(*method)())
 Post an event to be executed when the simulation stops.
virtual void start (bool threaded=true)
 Start processing events at a rate determined by the time factor.
virtual double getSystemTime ()
 Override this method to return the current system time, expressed in system time units (usually seconds).

Static Public Member Functions

static SimulatornewInstance (const char *ID=0)
 Gets a new simulator instance for your particular system.

Protected Member Functions

virtual void internalPostInsideLock (double absoluteTime, const GenericDispatcher *dispatcher)
 This common portion is called by all post functions It is necessary separated so as to put reading the current time in the lock for the 2 simple post functions.
virtual const GenericDispatcherinternalStepInsideLock ()
 Common portion between the 2 step functions This code is designed to be executed inside a lock, and it is very important that the returned dispatcher is called oustide the lock, because the called function may re-post itself for cyclic activation and will thus need a lock during post.
virtual bool internalStepInsideControl (double absoluteTime)
 Common portion between the step to absolute date and the event loop This code is designed to be executed in a section protected from concurrent simulation control.
virtual void eventLoop ()
 To be run in a thread, should be used by the start function.
virtual void stopEvent ()
 This stop event is posted by the stop method to cleanly exit from the event loop.
virtual void waitTimerCallBack ()
 Must be called when the wait timer expires.
 Simulator ()
 protected constructor: User API is the public newInstance, or a public constructor of a subtype
virtual void eventMutexLock ()
 Override this method to lock the mutex that will be used for event related functions.
virtual void eventMutexUnlock ()
 Override this method to unlock the mutex that will be used for event related functions No locking by default, see CPP.
virtual bool stepControlMutexTryLock ()
 Override this method to try locking a mutex that will be used for controlling the simulation.
virtual void stepControlMutexLock ()
 Override this method to locking the mutex that will be used for controlling the simulation.
virtual void stepControlMutexUnlock ()
 Override this method to unlock the mutex that will be used for controlling the simulation.
virtual void waitSemaphorePost ()
 Override this method to increment a semaphore that will be used for waiting for a new event in the event loop.
virtual void waitSemaphoreFlush ()
 Override this method to flush a semaphore that will be used for waiting for a new event in the event loop.
virtual void waitSemaphoreWait ()
 Override this method to implement the "standard wait till semaphore count >0" call on a semaphore that will be used for waiting for a new event in the event loop.
virtual void startWaitTimer (double delay)
 Override this method to start some kind of timer, that will call the timer callback provided after the given delay.
virtual void cancelWaitTimer ()
 Override this method to immediately stop the timer started by the startWaitTimer method.

Protected Attributes

double time
double timeReference
double systemTimeReference
double timeFactor
double timeFactorInverse
bool isRunning
 this flag is used by stop events to stop the event loop it should never be set to true outside the event loop but can be set to false to stop it
Event * events
Event * firstEvent
Event * nextEvent
const GenericDispatcher ** stopEvents
int numberOfStopEvents
const GenericDispatchercurrentDispatcherInExecution

Friends

class GenericDispatcher
 This file is intended to be included directly inside the simulator class.

Classes

struct  AbstractFactory
 See struct Factory. More...
struct  CyclicDispatcher
struct  CyclicDispatcher1
struct  CyclicDispatcher2
struct  CyclicDispatcher3
struct  Dispatcher
struct  Dispatcher1
struct  Dispatcher2
struct  Dispatcher3
struct  Event
struct  Factory
 Subclasses should provide an ID and a priority to compare this implementation with the default ones. More...
struct  GenericCyclicDispatcher
class  GenericDispatcher
 This base class of object method wrappers is put in the public namespace of the Simulator so it can be used with the generic post methods. More...
struct  StaticCyclicDispatcher
struct  StaticCyclicDispatcher1
struct  StaticCyclicDispatcher2
struct  StaticCyclicDispatcher3
struct  StaticDispatcher
struct  StaticDispatcher1
struct  StaticDispatcher2
struct  StaticDispatcher3


Member Function Documentation

void Simulator::cancelWaitTimer  )  [protected, virtual]
 

Override this method to immediately stop the timer started by the startWaitTimer method.

If you system does not provide such an operation, a clean implementation may be waiting for either a timout or a condition in a separate thread, and this cancel function triggers the condition. Then, by testing which of the timer or condition stopped the waiting, you can either call the timer callback or return immediately.

See also:
startWaitTimer

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

void Simulator::eventMutexLock  )  [protected, virtual]
 

Override this method to lock the mutex that will be used for event related functions.

The function should block as expected until the mutex is available No locking by default, see CPP.

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

double Simulator::getSystemTime  )  [virtual]
 

Override this method to return the current system time, expressed in system time units (usually seconds).

Note:
This function is only used for computing differences, so the time origin doesn't matter. This allows you to use system clocks using any time reference mechanism, like the POSIX monotonic high-resolution clocks.
See also:
getTime()

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

double Simulator::getTime  )  const [virtual]
 

Gets the current simulated time since the simulation started or the last reset.

The simulated time may not be the same at all as the system time, even if a factor of 1.0 is set. Indeed, the simulation may have stopped and restarted (operator takes a coffee break), or the system may not be able to process the events fast enough to keep up with real-time. In any case, both share the same time unit, usually seconds but this maybe changed by overloading the getSystemTime function. This function can be used any time, even when events are pending. Be aware that it is not thread-synchronized, so multiple runs of the same program may not return the same values. This was done on purpose for many reasons, good ones including not blocking the step and post functions, and also because most of the time thread-synchronization would be completely useless. Indeed, there is no way to guaranty that an event won't be processed during 2 consecutive unprotected instructions in your program. Rather than protecting only the getTime function, you would need to put it together with the other instructions inside a mutex protected block, which cleary cannot be done automatically for you. If this is what you really, really want, then think twice about it and see if posting an event at the right date (possibly with a 0 delay) doesn't help. If it is really not the case, overload this class to make the eventMutexLock/Unlock functions accessible, and you're on your own.

double Simulator::getTimeFactor  )  const [virtual]
 

See also:
setTimeFactor

const Simulator::GenericDispatcher * Simulator::internalStepInsideLock  )  [protected, virtual]
 

Common portion between the 2 step functions This code is designed to be executed inside a lock, and it is very important that the returned dispatcher is called oustide the lock, because the called function may re-post itself for cyclic activation and will thus need a lock during post.

Returns:
a dispatcher to call for the current step, outside the lock, or null if there is no current step.

Simulator * Simulator::newInstance const char *  ID = 0  )  [static]
 

Gets a new simulator instance for your particular system.

Depending on the current system environment, more than one simulator implementation may be available.

You can choose a specific implementation if you know its ID, or let the implementor decide which is the best implementation.

This is the default, and silent fallback when the ID does not exist. If you really wish to check on a specific ID, you may consider dynamic casting the result to the type for this ID. You may also simply call the constructor of that implementation!

Parameters:
ID A simulator implementation ID, or 0 to choose the default

const GenericDispatcher* Simulator::post void(*)()  method  )  [inline]
 

Post an event at current time.

Any C "void method()" can be called this way.

Parameters:
method any C "void method()" with no argument

const Simulator::GenericDispatcher * Simulator::post const GenericDispatcher dispatcher  )  [virtual]
 

Post an event at current time.

Use this function together with a specialized dispatcher to post methods with more than 3 arguments. Note: Template methods are provided, included postCyclic methods. Note2: You can use this method with a cyclic dispatcher too.

Parameters:
dispatcher Callback to the function or object method to call

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::post T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::post T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::post T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post an event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::post T *  object,
void(T::*)()  method
[inline]
 

Post an event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
object any C++ object
method any C++ method on this object with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::post void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at current time.

Any C "void method(..)" with three arguments can be called this way.

Parameters:
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::post void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at current time.

Any C "void method(..)" with two arguments can be called this way.

Parameters:
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::post void(*)(A)  method,
argument
[inline]
 

Post an event at current time.

Any C "void method(..)" with one argument can be called this way.

Parameters:
method any C "void method()" with one argument
argument the argument to pass to the method

const GenericDispatcher* Simulator::postAt double  absoluteTime,
void(*)()  method
[inline]
 

Post an event at an absolute simulated time.

Any C "void method()" can be called this way.

Parameters:
absoluteTime time at which to execute the event
method any C "void method()" with no argument

const Simulator::GenericDispatcher * Simulator::postAt double  absoluteTime,
const GenericDispatcher dispatcher
[virtual]
 

Post an event at an absolute simulated time Use this function together with a specialized dispatcher to post methods with more than 3 arguments, or to pass static methods and global functions Note: Template methods are provided, included postCyclic methods.

Note2: You can use this method with a cyclic dispatcher too.

Parameters:
absoluteTime time at which to execute the event
dispatcher Callback to the function or object method to call
Exceptions:
Exception when the time is already passed

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post an event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
T *  object,
void(T::*)()  method
[inline]
 

Post an event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
object any C++ object
method any C++ method on this object with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at an absolute simulated time.

Any C "void method(..)" with three arguments can be called this way.

Parameters:
absoluteTime time at which to execute the event
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at an absolute simulated time.

Any C "void method(..)" with two arguments can be called this way.

Parameters:
absoluteTime time at which to execute the event
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postAt double  absoluteTime,
void(*)(A)  method,
argument
[inline]
 

Post an event at an absolute simulated time.

Any C "void method(..)" with one argument can be called this way.

Parameters:
absoluteTime time at which to execute the event
method any C "void method()" with one argument
argument the argument to pass to the method

const GenericDispatcher* Simulator::postAtStop void(*)()  method  )  [inline]
 

Post an event to be executed when the simulation stops.

Any C "void method()" can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
method any C "void method()" with no argument

const Simulator::GenericDispatcher * Simulator::postAtStop const GenericDispatcher dispatcher  )  [virtual]
 

Post an event to be executed when the simulation stops.

These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way. Use this function together with a specialized dispatcher to post methods with more than 3 arguments, or to pass static methods and global functions

Parameters:
dispatcher Callback to the function or object method to call

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postAtStop void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postAtStop void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postAtStop void(*)(A)  method,
argument
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
method any C "void method(..)" with 1 argument
argument the argument to pass to the method

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postAtStop T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postAtStop T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postAtStop T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postAtStop T *  object,
void(T::*)()  method
[inline]
 

Post an event to be executed when the simulation stops.

Any C++ method on any arbitrary object can be called this way. These events have no execution date, but are called when the simulation stops in the order they were posted by postAtStop. The events are then consumed. No more then MAX_STOP_EVENTS can be posted this way.

Parameters:
object any C++ object
method any C++ method on this object with no argument

const GenericDispatcher* Simulator::postCyclic double  cycle,
void(*)()  method
[inline]
 

Post a cyclic event at current time.

Any C "void method()" can be called this way.

Parameters:
cycle how often the method should be called
method any C "void method()" with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclic double  cycle,
void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at current time.

Any C "void method(..)" with three arguments can be called this way.

Parameters:
cycle how often the method should be called
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postCyclic double  cycle,
void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at current time.

Any C "void method(..)" with two arguments can be called this way.

Parameters:
cycle how often the method should be called
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postCyclic double  cycle,
void(*)(A)  method,
argument
[inline]
 

Post a cyclic event at current time.

Any C "void method(..)" with one argument can be called this way.

Parameters:
cycle how often the method should be called
method any C "void method()" with one argument
argument the argument to pass to the method

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclic double  cycle,
T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
cycle how often the method should be called
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postCyclic double  cycle,
T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
cycle how often the method should be called
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postCyclic double  cycle,
T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post a cyclic event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
cycle how often the method should be called
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postCyclic double  cycle,
T *  object,
void(T::*)()  method
[inline]
 

Post a cyclic event at current time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
cycle how often the method should be called
object any C++ object
method any C++ method on this object with no argument

const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
void(*)()  method
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C "void method()" can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
method any C "void method()" with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C "void method(..)" with three arguments can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C "void method(..)" with two arguments can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
void(*)(A)  method,
argument
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C "void method(..)" with one argument can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
method any C "void method()" with one argument
argument the argument to pass to the method

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postCyclicAt double  absoluteTime,
double  cycle,
T *  object,
void(T::*)()  method
[inline]
 

Post a cyclic event at an absolute simulated time.

Any C++ method on any arbitrary object can be called this way.

Parameters:
absoluteTime time at which to execute the event
cycle how often the method should be called
object any C++ object
method any C++ method on this object with no argument

const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
void(*)()  method
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C "void method()" can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
method any C "void method()" with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with three arguments can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with two arguments can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
void(*)(A)  method,
argument
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C "void method(..)" with one argument can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
method any C "void method()" with one argument
argument the argument to pass to the method

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postCyclicIn double  delay,
double  cycle,
T *  object,
void(T::*)()  method
[inline]
 

Post a cyclic event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
cycle how often the method should be called
object any C++ object
method any C++ method on this object with no argument

const GenericDispatcher* Simulator::postIn double  delay,
void(*)()  method
[inline]
 

Post an event at current time + a certain delay in simulated time Any C "void method()" can be called this way.

Parameters:
delay after current time, should be >0.
method any C "void method()" with no argument

const Simulator::GenericDispatcher * Simulator::postIn double  delay,
const GenericDispatcher dispatcher
[virtual]
 

Post an event at current time + a certain delay in simulated time Use this function together with a specialized dispatcher to post methods with more than 3 arguments, or to pass static methods and global functions Note: Template methods are provided, included postCyclic methods.

Note2: You can use this method with a cyclic dispatcher too.

Parameters:
delay after current time, should be >0.
dispatcher Callback to the function or object method to call
Exceptions:
Exception when delay <0

template<class T, class A1, class A2, class A3>
const GenericDispatcher* Simulator::postIn double  delay,
T *  object,
void(T::*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
object any C++ object
function any C++ method on this object with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class T, class A1, class A2>
const GenericDispatcher* Simulator::postIn double  delay,
T *  object,
void(T::*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
object any C++ object
function any C++ method on this object with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class T, class A>
const GenericDispatcher* Simulator::postIn double  delay,
T *  object,
void(T::*)(A)  method,
argument
[inline]
 

Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
object any C++ object
function any C++ method on this object with one argument
argument the argument to pass to the method

template<class T>
const GenericDispatcher* Simulator::postIn double  delay,
T *  object,
void(T::*)()  method
[inline]
 

Post an event at current time + a certain delay in simulated time Any C++ method on any arbitrary object can be called this way.

Parameters:
delay after current time, should be >0.
object any C++ object
method any C++ method on this object with no argument

template<class A1, class A2, class A3>
const GenericDispatcher* Simulator::postIn double  delay,
void(*)(A1, A2, A3)  method,
A1  argument1,
A2  argument2,
A3  argument3
[inline]
 

Post an event at current time + a certain delay in simulated time Any C "void method(..)" with three arguments can be called this way.

Parameters:
delay after current time, should be >0.
method any C "void method(..)" with three arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method
argument3 the third argument to pass to the method

template<class A1, class A2>
const GenericDispatcher* Simulator::postIn double  delay,
void(*)(A1, A2)  method,
A1  argument1,
A2  argument2
[inline]
 

Post an event at current time + a certain delay in simulated time Any C "void method(..)" with two arguments can be called this way.

Parameters:
delay after current time, should be >0.
method any C "void method(..)" with two arguments
argument1 the first argument to pass to the method
argument2 the second argument to pass to the method

template<class A>
const GenericDispatcher* Simulator::postIn double  delay,
void(*)(A)  method,
argument
[inline]
 

Post an event at current time + a certain delay in simulated time Any C "void method(..)" with one argument can be called this way.

Parameters:
delay after current time, should be >0.
method any C "void method()" with one argument
argument the argument to pass to the method

void Simulator::resetTime  )  [virtual]
 

Resets the current simulated time parameter to 0.

Pending events are translated so they keep the same delay between current date and activation date.
This is especially useful before a simulation start() after a stop(), when no events are pending, to start a completely new simulation.

void Simulator::setTimeFactor double  factor  )  [virtual]
 

Correspondance between once unit of time in system time and one unit in simulated time.

Default is a factor of 1.0, meaning the simulation will try to run in soft real-time when start()ed. Higher factors mean faster than real-time, lower factors mean slower than real-time.


This function can be called at any moment, it will affect the next event. See also the

See also:
start function. Setting a factor of 0 means "process events as fast as possible"
See also the

getSystemTime function. Returning values for units a different than a second is another way to modify the range of the simulated time.
See also

getSimulatedTime,

getTimeReference and

getSimulatedTimeReference, for more details how a change in time factor affects the correspondance between simulated time and internal time

Parameters:
factor The relation between one unit(second) of system time and the time parameter, more precisely 1_unit_internal = 1_unit_system * timeFactor. If set to 0, then events are processed as fast as possible. Default is 1e-6 for microseconds.

void Simulator::start bool  threaded = true  )  [virtual]
 

Start processing events at a rate determined by the time factor.

This function returns immediately by default, and process the events in another thread. You may change this by setting the argument to false Of course, there is a limit at how fast you can process events, that is how small you can set the time factor for a fixed amount of events, depending on your system performances. Below this value, you'll probably see a large drift between simulated time and system time. In this case, you can gain an extra bit of performance by setting the factor to 0, which means "process the events as fast as possible".

Note:
The default implementation does actually NOT start a thread, but blocks. Threads are system dependant. A helper protected function eventLoop() is provided so you can easily override this class for your particular thread system, if this is not done already.
Parameters:
threaded whether a new thread should be started to process the event loop. Default is true

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

void Simulator::startWaitTimer double  delay  )  [protected, virtual]
 

Override this method to start some kind of timer, that will call the timer callback provided after the given delay.

The delay is expressed in system time units, so implementations don't need to use the time factor. If your system does not provide timers, an implementation may be to wait in another thread for either some amount of time or some unblocking condition :

See also:
cancelWaitTimer().
Parameters:
delay the time to wait before calling the timer callback, expressed in system time units as used by the getSystemTime method.

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

bool Simulator::step double  absoluteTime  )  [virtual]
 

Process next events in the queue, if possible, till the given simulated time is reached.

Parameters:
absoluteTime The simulated time to reach
Returns:
true if there was at least an event and it could be processed, false otherwise

bool Simulator::step  )  [virtual]
 

Process next event in the queue, if possible.

Returns:
true if there was an event and it could be processed, false otherwise

void Simulator::stepControlMutexLock  )  [protected, virtual]
 

Override this method to locking the mutex that will be used for controlling the simulation.

Only one thread can call step, or the event loop at the same time. The function should block as expected until the mutex is available No locking by default, see CPP.

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

bool Simulator::stepControlMutexTryLock  )  [protected, virtual]
 

Override this method to try locking a mutex that will be used for controlling the simulation.

Only one thread can call step, or the event loop at the same time. The function should return true on success, or return immediately false otherwise No locking by default, see CPP.

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.

void Simulator::stop bool  waitForStop = false  )  [virtual]
 

Stop processing events automatically.

You can use the step functions to advance in time.

Parameters:
waitForStop if the function should wait for the last event to be processed The event posted at stop will be process after the function returns, though, in case one of them restarts the loop.
See also:
comments of the start function about implementations.

void Simulator::waitSemaphoreFlush  )  [protected, virtual]
 

Override this method to flush a semaphore that will be used for waiting for a new event in the event loop.

By flushing, we mean that the semaphore count should be zero after this call. This call is done in a protected section such that no post will be done to the semaphore while calling this function. If your system doesn't propose better, you might thus try creating a new semaphore with 0 count.

Reimplemented in OpenThreadSimulator, and POSIX_Simulator.


Friends And Related Function Documentation

friend class GenericDispatcher [friend]
 

This file is intended to be included directly inside the simulator class.

It has been separated for the sake of clarity of the simulator interface.

TODO: Generate this file automatically (with perl, etc.) to ease maintainance


The documentation for this class was generated from the following files:
Generated on Mon Mar 28 11:27:48 2005 for Crogai by  doxygen 1.4.1