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

Protected Member Functions

void run () override
 the execution thread main method More...
 

Protected Attributes

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

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.

Definition at line 58 of file Timer.h.

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

Definition at line 37 of file Timer.cpp.

+ Here is the call graph for this function:

◆ ~Timer()

~Timer ( )
override

Definition at line 189 of file Timer.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ call()

void call ( )
overridevirtual

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

Implements CallbackReceiver.

Definition at line 143 of file Timer.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 77 of file Timer.cpp.

◆ 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()!

Definition at line 157 of file Timer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUseSystemTime()

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

Definition at line 152 of file Timer.cpp.

◆ run()

void run ( )
overrideprotected

the execution thread main method

Definition at line 105 of file Timer.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 54 of file Timer.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 72 of file Timer.cpp.

Member Data Documentation

◆ callbackWaitMutex

std::mutex callbackWaitMutex
protected

used for waiting for a callback from the LocalTimeServer

Definition at line 121 of file Timer.h.

◆ called

bool called
protected

if call() has been called.

Used together with condWait.

Definition at line 141 of file Timer.h.

◆ condWait

std::condition_variable condWait
protected

used for waiting for a callback from the LocalTimeServer

Definition at line 126 of file Timer.h.

◆ iceTimer

IceUtil::TimerPtr iceTimer
protected

timer for use in system time mode

Definition at line 146 of file Timer.h.

◆ running

bool running
protected

set to false to stop the execution thread

Definition at line 136 of file Timer.h.

◆ scheduledTasks

std::vector<ScheduledTask> scheduledTasks
protected

list of scheduled tasks

Definition at line 151 of file Timer.h.

◆ scheduledTasksMutex

std::mutex scheduledTasksMutex
protected

used for locking scheduledTasks

Definition at line 131 of file Timer.h.

◆ useSystemTime

bool useSystemTime
protected

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

Definition at line 116 of file Timer.h.


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