MIRA
Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
DispatcherThread::Timer Class Reference

Class representing timers and tasks that can be registered and executed by the dispatcher thread. More...

#include <fw/DispatcherThread.h>

Inheritance diagram for DispatcherThread::Timer:
Inheritance graph
[legend]

Public Member Functions

bool isActive () const
 Returns if the timer is active. More...
 
void setPeriod (Duration period)
 Changes the period of the timer. More...
 
Duration getPeriod () const
 Returns the current period of the timer. More...
 
void setTolerance (Duration tolerance)
 Set the tolerance that is allowed to exceed the next invocation time before issuing a warning and resetting the invocation time. More...
 
Duration getTolerance () const
 Get the tolerance for exceed the next invocation time. More...
 
Duration getExceedance () const
 Checks and returns the amount of time the timer has exceeded the expected invocation time. More...
 
void start ()
 Start the timer (activates it) More...
 
void stop ()
 Stops a timer (deactivates it) More...
 
Time getNextInvocationTime () const
 Return next time of execution. More...
 

Public Attributes

Time last
 time the last callback happened More...
 
Time currentExpected
 time the current callback should be happening More...
 
Time current
 time the current callback was actually called (Time::now() as of the beginning of the callback) More...
 
Duration lastDuration
 How long the last callback ran for. More...
 

Protected Member Functions

 Timer (TimerCallback callback, Duration period, Duration tolerance=Duration::invalid())
 Constructs a timer with a given callback that is called whenever the timers invocation time is due and a period in which the timer is rescheduled after invocation. More...
 
 Timer (TimerCallback callback, Time invokationTime)
 Constructs a one shot timer or task with a given callback that is called once at the timers/tasks invocation time and a specified time. More...
 
void updateInvocationTime ()
 Called by dispatcher when timer is rescheduled. More...
 
virtual void run (DispatcherThread *dispatcher)
 Called from dispatcher thread this runnable is attached to, whenever the runnable should be executed. More...
 

Friends

class DispatcherThread
 Only dispatcher thread can create us. More...
 

Detailed Description

Class representing timers and tasks that can be registered and executed by the dispatcher thread.

Timers have an invocation time when they will be executed again. Timers will be rescheduled after invocation based on their period. Tasks form a kind of single shot timer that will be executed once at a given time.

Examples:
tutorials/FloatProducer.C.

Constructor & Destructor Documentation

◆ Timer() [1/2]

Timer ( TimerCallback  callback,
Duration  period,
Duration  tolerance = Duration::invalid() 
)
protected

Constructs a timer with a given callback that is called whenever the timers invocation time is due and a period in which the timer is rescheduled after invocation.

◆ Timer() [2/2]

Timer ( TimerCallback  callback,
Time  invokationTime 
)
protected

Constructs a one shot timer or task with a given callback that is called once at the timers/tasks invocation time and a specified time.

Member Function Documentation

◆ updateInvocationTime()

void updateInvocationTime ( )
inlineprotected

Called by dispatcher when timer is rescheduled.

◆ run()

virtual void run ( DispatcherThread dispatcher)
protectedvirtual

Called from dispatcher thread this runnable is attached to, whenever the runnable should be executed.

Implements IRunnable.

◆ isActive()

bool isActive ( ) const
inline

Returns if the timer is active.

◆ setPeriod()

void setPeriod ( Duration  period)
inline

Changes the period of the timer.

New period will be used next time the timer gets rescheduled.

◆ getPeriod()

Duration getPeriod ( ) const
inline

Returns the current period of the timer.

◆ setTolerance()

void setTolerance ( Duration  tolerance)
inline

Set the tolerance that is allowed to exceed the next invocation time before issuing a warning and resetting the invocation time.

If invalid then there is no limit for exceeding the time.

◆ getTolerance()

Duration getTolerance ( ) const
inline

Get the tolerance for exceed the next invocation time.

Invalid if not specified.

◆ getExceedance()

Duration getExceedance ( ) const
inline

Checks and returns the amount of time the timer has exceeded the expected invocation time.

Returns 0 for timers that have 0 as period or if the exceeded time is inside the specified tolerance.

◆ start()

void start ( )

Start the timer (activates it)

◆ stop()

void stop ( )

Stops a timer (deactivates it)

◆ getNextInvocationTime()

Time getNextInvocationTime ( ) const
inline

Return next time of execution.

Friends And Related Function Documentation

◆ DispatcherThread

friend class DispatcherThread
friend

Only dispatcher thread can create us.

Member Data Documentation

◆ last

Time last

time the last callback happened

◆ currentExpected

Time currentExpected

time the current callback should be happening

◆ current

Time current

time the current callback was actually called (Time::now() as of the beginning of the callback)

◆ lastDuration

Duration lastDuration

How long the last callback ran for.


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