AceSmartSoft API Documentation
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SmartACE::TimerManagerThread Class Reference

single/continuous timer. More...

#include <smartTimerManagerThread.hh>

Inheritance diagram for SmartACE::TimerManagerThread:

Public Member Functions

 TimerManagerThread ()
 Constructor. More...
 
virtual ~TimerManagerThread ()
 Destructor. Properly shuts down the timer thread. More...
 
virtual TimerId scheduleTimer (Smart::ITimerHandler *handler, const void *act, const Smart::Duration &first_time, const Smart::Duration &interval=Smart::Duration::zero()) override
 Schedule a timer. More...
 
virtual int cancelTimer (const TimerId &timer_id, const void **act=0) override
 Cancel a single timer. More...
 
virtual int cancelTimersOf (Smart::ITimerHandler *handler) override
 Cancel all timers associated with a handler. More...
 
virtual void deleteAllTimers () override
 
virtual int resetTimerInterval (const TimerId &timer_id, const Smart::Duration &interval) override
 Resets the interval of a timer. More...
 
int startTimerThread ()
 Start execution of the internal timer thread. More...
 
int startTimerThread (const ACE_Sched_Params &sched_params, const int &cpuAffinity=-1)
 Start execution of the internal timer thread. More...
 
void shutdownTimer (const bool &waitOnCompletion=true)
 Initializes timer thread to permanently shutdown. More...
 

Protected Member Functions

virtual int svc (void)
 Run by a daemon thread to handle deferred processing. More...
 
int setSchedParams (const ACE_Sched_Params &sched_params)
 
int setCpuAffinity (const int &cpuCore)
 

Protected Attributes

TimerHeap timer_queue
 
std::set< Smart::ITimerHandler * > handlers
 
ACE_Auto_Event timer_event_
 Event to wait on. More...
 
int shutting_down_
 Flag used to indicate when we are shutting down. More...
 

Detailed Description

single/continuous timer.

This object has a thread that waits on the earliest time in a list of timers and an event. When a timer expires, the apropriate handler is called in the context of this thread.

It is based on ACE_Time_Heap and friends.

Some code taken from ace/Proactor.cpp

Constructor & Destructor Documentation

◆ TimerManagerThread()

SmartACE::TimerManagerThread::TimerManagerThread ( )

Constructor.

◆ ~TimerManagerThread()

virtual SmartACE::TimerManagerThread::~TimerManagerThread ( )
virtual

Destructor. Properly shuts down the timer thread.

Member Function Documentation

◆ cancelTimer()

virtual int SmartACE::TimerManagerThread::cancelTimer ( const TimerId &  timer_id,
const void **  act = 0 
)
overridevirtual

Cancel a single timer.

Parameters
timer_idto cancel
actpointer to retrive the act that was given on scheduleTimer(). Can be used to release ressources owned by act. If act == 0, nothing is retrieved.
Returns
0 on success
-1 on error

◆ cancelTimersOf()

virtual int SmartACE::TimerManagerThread::cancelTimersOf ( Smart::ITimerHandler *  handler)
overridevirtual

Cancel all timers associated with a handler.

Parameters
handlercancel timers associated with this handler
Returns
number of timers canceled.

◆ deleteAllTimers()

virtual void SmartACE::TimerManagerThread::deleteAllTimers ( )
overridevirtual

◆ resetTimerInterval()

virtual int SmartACE::TimerManagerThread::resetTimerInterval ( const TimerId &  timer_id,
const Smart::Duration &  interval 
)
overridevirtual

Resets the interval of a timer.

Parameters
timer_idto change
intervalnew timer interval (relative to the current time)
Returns
0 on success
-1 on error

◆ scheduleTimer()

virtual TimerId SmartACE::TimerManagerThread::scheduleTimer ( Smart::ITimerHandler *  handler,
const void *  act,
const Smart::Duration &  first_time,
const Smart::Duration &  interval = Smart::Duration::zero() 
)
overridevirtual

Schedule a timer.

Parameters
handlerThe handler that will be called when the timer expires.
acta value that will be passed to the handler.
first_timerelative time for the first timer expiration
intervalInterval for periodic timers. A single shot timer is scheduled by default.
Returns
timer_id: -1 on failure. Unique time id else. This id can be used to cancel a timer before it expires with cancelTimer() and to change the the interval of a timer with resetTimerInterval().

◆ setCpuAffinity()

int SmartACE::TimerManagerThread::setCpuAffinity ( const int &  cpuCore)
protected

◆ setSchedParams()

int SmartACE::TimerManagerThread::setSchedParams ( const ACE_Sched_Params &  sched_params)
protected

◆ shutdownTimer()

void SmartACE::TimerManagerThread::shutdownTimer ( const bool &  waitOnCompletion = true)

Initializes timer thread to permanently shutdown.

Parameters
waitOnCompletionindicates, whether this method should block until timer is completely down

◆ startTimerThread() [1/2]

int SmartACE::TimerManagerThread::startTimerThread ( )

Start execution of the internal timer thread.

Returns
>=0 on success
-1 on error

◆ startTimerThread() [2/2]

int SmartACE::TimerManagerThread::startTimerThread ( const ACE_Sched_Params &  sched_params,
const int &  cpuAffinity = -1 
)

Start execution of the internal timer thread.

Parameters
sched_paramsinitializes a specific scheduler
cpuAffinityassigns the thread to one specific CPU core
Returns
>=0 on success
-1 on error

◆ svc()

virtual int SmartACE::TimerManagerThread::svc ( void  )
protectedvirtual

Run by a daemon thread to handle deferred processing.

In other words, this method will do the waiting on the earliest timer and event.

Member Data Documentation

◆ handlers

std::set<Smart::ITimerHandler*> SmartACE::TimerManagerThread::handlers
protected

◆ shutting_down_

int SmartACE::TimerManagerThread::shutting_down_
protected

Flag used to indicate when we are shutting down.

◆ timer_event_

ACE_Auto_Event SmartACE::TimerManagerThread::timer_event_
protected

Event to wait on.

◆ timer_queue

TimerHeap SmartACE::TimerManagerThread::timer_queue
protected

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