OpenRTM  1.0.0
Classes | Public Member Functions
coil::Timer Class Reference

Timer class. More...

#include <Timer.h>

Inheritance diagram for coil::Timer:
coil::Task

List of all members.

Classes

struct  Task

Public Member Functions

 Timer (TimeValue &interval)
 Constructor.
virtual ~Timer ()
 Destructor.
virtual int open (void *args)
 Create thread for Timer.
virtual int svc (void)
 Thread execution function for Timer.
void start ()
 Start Timer task.
void stop ()
void invoke ()
 Invoke Timer task.
ListenerId registerListener (ListenerBase *listener, TimeValue tm)
 Register listener.
template<class ListenerClass >
ListenerId registerListenerObj (ListenerClass *obj, void(ListenerClass::*cbf)(), TimeValue tm)
 Register listener.
ListenerId registerListenerFunc (void(*cbf)(), TimeValue tm)
 Register listener.
bool unregisterListener (ListenerId id)
 Unregister listener.

Detailed Description

Timer class.

Invoke the callback function of registered listener periodically at the set cycle.

Since:
0.4.0

Constructor & Destructor Documentation

coil::Timer::Timer ( TimeValue interval)

Constructor.

Constructor

Parameters:
intervalThe interval of timer
virtual coil::Timer::~Timer ( ) [virtual]

Destructor.

Destructor


Member Function Documentation

Invoke Timer task.

Subtract the interval of timer from the waiting time for invocation of each registered listener. If the listener whose waiting time reached 0 exists, invoke the callback function.

virtual int coil::Timer::open ( void *  args) [virtual]

Create thread for Timer.

Create an internal thread for Timer and launch it. This is an override of ACE_Task service class method.

Parameters:
argsUsually 0
Returns:
Creation processing result

Reimplemented from coil::Task.

Register listener.

Register the listener of callback function invoked from this Timer by specifying the interval. If the same listener has already been regiseterd, the value specified the invocation interval of listener will be updated.

Parameters:
listenerListener for the registration
tmThe invocation interval of listener
Returns:
ID of the registerd listener

Referenced by registerListenerFunc(), and registerListenerObj().

ListenerId coil::Timer::registerListenerFunc ( void(*)()  cbf,
TimeValue  tm 
) [inline]

Register listener.

Register listener by specifying the method for callback and the invocation interval.

Parameters:
cbfTarget method for callback
tmThe invocation interval of listener
Returns:
ID of the registerd listener

References registerListener().

template<class ListenerClass >
ListenerId coil::Timer::registerListenerObj ( ListenerClass *  obj,
void(ListenerClass::*)()  cbf,
TimeValue  tm 
) [inline]

Register listener.

Register listener by specifying the object for callback, the method for callback and the invocation interval.

Parameters:
objTarget object for callback
cbfTarget method for callback
tmThe invocation interval of listener
Returns:
ID of the registerd listener

References registerListener().

Start Timer task.

Create a new theread for Timer and start processing.

Stop Timer task.

virtual int coil::Timer::svc ( void  ) [virtual]

Thread execution function for Timer.

Thread execution function for Timer. Invoke the callback function of registered listener.

Returns:
Execution result

Reimplemented from coil::Task.

Unregister listener.

Unregister the listener specified by ID. If the listener specified by ID is not registerd, false will be returned.

Parameters:
idID of the unregisterd listener
Returns:
Unregistration result