User Manual, Developers Guide and API Documentation

wns::events::scheduler::RealTime Class Reference

Schedules events in real time (if possible ;)). More...

#include <events/scheduler/RealTime.hpp>

Inheritance diagram for wns::events::scheduler::RealTime:

Inheritance graph
[legend]
Collaboration diagram for wns::events::scheduler::RealTime:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 RealTime ()
 Default constructor.
virtual ~RealTime ()
 Destructor.

Private Member Functions

virtual void doReset ()
 Reset scheduler to initial state.
virtual void doStart ()
 Start the scheduler.
virtual void onNewSimTime (const wns::simulator::Time &nextTime)
 New sim time (scheduler will wait here if needed ...).

Static Private Member Functions

static double timevalToDouble (const timeval *t)
 Helper to convert "timeval" to "double".

Private Attributes

bool inSync_
 In sync with real time (or lagging?).
timeval timeOfSchedulerStart_
 Reference point (start has been called there).


Detailed Description

Author:
Marc Schinnenburg <marc@schinnenburg.com>
This version of the EventScheduler will schedule events of a simulation in real time (if possible). This means it delays the execution of events until the simulation is in sync with the real time again. This works of course only, if the simulation can run in real time anyway (this scheduler can't do some magic ;))

Note:
Currently the scheduler will warn if the simulation is more than 10 ms behind the real time. The accuracy of the scheduler has been measured to be in the range of +-10 ms. From "man nanosleep"
The current implementation of nanosleep() is based on the normal kernel timer mechanism, which has a resolution of 1/HZ s (see time(7)). Therefore, nanosleep() pauses always for at least the specified time, however it can take up to 10 ms longer than specified until the process becomes runnable again. For the same reason, the value returned in case of a delivered signal in *rem is usually rounded to the next larger multiple of 1/HZ s.

Improvements to lower this are welcome ...

Definition at line 61 of file RealTime.hpp.


Constructor & Destructor Documentation

RealTime::RealTime (  )  [explicit]

Definition at line 38 of file RealTime.cpp.

RealTime::~RealTime (  )  [virtual]

Definition at line 45 of file RealTime.cpp.


Member Function Documentation

void RealTime::doReset (  )  [private, virtual]

Reimplemented from wns::events::scheduler::Map.

Definition at line 105 of file RealTime.cpp.

void RealTime::doStart (  )  [private, virtual]

Reimplemented from wns::events::scheduler::Map.

Definition at line 112 of file RealTime.cpp.

void RealTime::onNewSimTime ( const wns::simulator::Time nextTime  )  [private, virtual]

This method works as follows

		                                                      simTime
		         ----------------------------------------------------->
		         |                                     |
		         0                                     nextEvent
		                         |------ delay --------|
		                         |                           realTime
		  ---...------------------------------------------------------>
		  |      |               |
		  epoch  schedulerStart  currentTime 

Scheduler will sleep for "delay" seconds, where "delay" is:

		   delay = schedulerStart + nextTime - currentTime 

Reimplemented from wns::events::scheduler::Map.

Definition at line 50 of file RealTime.cpp.

double RealTime::timevalToDouble ( const timeval *  t  )  [static, private]

Definition at line 120 of file RealTime.cpp.


Member Data Documentation

Definition at line 127 of file RealTime.hpp.

Definition at line 122 of file RealTime.hpp.


The documentation for this class was generated from the following files:

Generated on Sat May 26 03:32:54 2012 for openWNS by  doxygen 1.5.5