Timer Class Reference

Timer implementation with TimeServer support. More...

#include <ArmarXCore/core/time/Timer.h>

+ Inheritance diagram for Timer:

Public Member Functions

void call () override
 wakes up the execution thread to check if a task has to run
 
bool cancel (const IceUtil::TimerTaskPtr &task)
 cancels a task, returns true if the task was successfully canceled (i.e.
 
void destroy ()
 destroys the Timer and detaches the exection thread if the calling thread is the timer thread, joins the thread otherwise
 
bool getUseSystemTime () const
 
void schedule (const IceUtil::TimerTaskPtr &task, const IceUtil::Time &interval)
 schedules a task for execution
 
void scheduleRepeated (const IceUtil::TimerTaskPtr &task, const IceUtil::Time &interval)
 schedules a task for repeated execution
 
 Timer (bool forceSystemTime=false)
 constructs a new Timer and starts its execution thread.
 
 ~Timer () override
 
- Public Member Functions inherited from CallbackReceiver
virtual ~CallbackReceiver ()
 

Protected Member Functions

void run () override
 the execution thread main method
 

Protected Attributes

std::mutex callbackWaitMutex
 used for waiting for a callback from the LocalTimeServer
 
bool called
 if call() has been called.
 
std::condition_variable condWait
 used for waiting for a callback from the LocalTimeServer
 
IceUtil::TimerPtr iceTimer
 timer for use in system time mode
 
bool running
 set to false to stop the execution thread
 
std::vector< ScheduledTask > scheduledTasks
 list of scheduled tasks
 
std::mutex scheduledTasksMutex
 used for locking scheduledTasks
 
bool useSystemTime
 if we are using the system time (or the TimeServer time)
 

Detailed Description

Timer implementation with TimeServer support.

The Timer class provides a timer following the same interface as IceUtil::Timer, but adding the option to use time from a TimeServer.

Using system time for scheduling is still possible using forceSystemTime=true in the constructor.

Constructor & Destructor Documentation

◆ Timer()

Timer ( bool forceSystemTime = false)

constructs a new Timer and starts its execution thread.

Parameters
forceSystemTimeif set to true, system time will be used even if a TimeServer is available

◆ ~Timer()

~Timer ( )
override

Member Function Documentation

◆ call()

void call ( )
overridevirtual

wakes up the execution thread to check if a task has to run

Implements CallbackReceiver.

◆ cancel()

bool cancel ( const IceUtil::TimerTaskPtr & task)

cancels a task, returns true if the task was successfully canceled (i.e.

was found in the queue), false otherwise

Parameters
tasktask to cancel
Returns
if cancelling was successful

◆ destroy()

void destroy ( )

destroys the Timer and detaches the exection thread if the calling thread is the timer thread, joins the thread otherwise

The Timer must not be used to schedule anything new after a call to destroy()!

◆ getUseSystemTime()

bool getUseSystemTime ( ) const
Returns
true if system time is used, false if VirtualTime is used.

◆ run()

void run ( )
overrideprotected

the execution thread main method

◆ schedule()

void schedule ( const IceUtil::TimerTaskPtr & task,
const IceUtil::Time & interval )

schedules a task for execution

Parameters
taskthe task to execute (an object extending IceUtil::TimerTask
intervalhow long to wait before the task is run

◆ scheduleRepeated()

void scheduleRepeated ( const IceUtil::TimerTaskPtr & task,
const IceUtil::Time & interval )

schedules a task for repeated execution

Parameters
taskthe task to execute (an object extending IceUtil::TimerTask
intervalthe interval in which the task is executed

Member Data Documentation

◆ callbackWaitMutex

std::mutex callbackWaitMutex
protected

used for waiting for a callback from the LocalTimeServer

◆ called

bool called
protected

if call() has been called.

Used together with condWait.

◆ condWait

std::condition_variable condWait
protected

used for waiting for a callback from the LocalTimeServer

◆ iceTimer

IceUtil::TimerPtr iceTimer
protected

timer for use in system time mode

◆ running

bool running
protected

set to false to stop the execution thread

◆ scheduledTasks

std::vector<ScheduledTask> scheduledTasks
protected

list of scheduled tasks

◆ scheduledTasksMutex

std::mutex scheduledTasksMutex
protected

used for locking scheduledTasks

◆ useSystemTime

bool useSystemTime
protected

if we are using the system time (or the TimeServer time)


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