#include <rtt/Timer.hpp>

In Order to use this class, derive your class from Timer and implement the timeout() method. The resolution of this class depends completely on the timer resolution of the underlying operating system.
Definition at line 23 of file Timer.hpp.
Public Types | |
| typedef int | TimerId |
| A positive numeric ID representing a timer. | |
Public Member Functions | |
| Timer (TimerId max_timers, int scheduler=-1, int priority=0) | |
| Create a timer object which can hold max_timers timers. | |
| ~Timer () | |
| virtual void | timeout (TimerId timer_id) |
| This function is called each time an armed or periodic timer expires. | |
| void | setMaxTimers (TimerId max) |
| Change the maximum number of timers in this object. | |
| bool | startTimer (TimerId timer_id, Seconds period) |
| Start a periodic timer which starts first over period seconds and then every period seconds. | |
| bool | arm (TimerId timer_id, Seconds wait_time) |
| Arm a timer to fire once over wait_time seconds. | |
| TimeService::Seconds | timeRemaining (TimerId timer_id) const |
| Returns the remaining time before this timer elapses. | |
| bool | isActive (TimerId timer_id) const |
| Check if a given timer id is armed. | |
| bool | killTimer (TimerId timer_id) |
| Disable an armed timer. | |
Protected Types | |
|
typedef TimeService::nsecs | Time |
| typedef std::vector < std::pair< Time, Time > > | TimerIds |
| Index in vector is the timer id. | |
Protected Member Functions | |
| bool | initialize () |
| The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started. | |
| void | finalize () |
| The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped. | |
| void | step () |
| The method that will be periodically executed when this class is run in a periodic thread. | |
| void | loop () |
| The method that will be executed once when this class is run in a non periodic thread. | |
| bool | breakLoop () |
| This method is called by the framework to break out of the loop() method. | |
| ThreadInterface * | getThread () const |
| Get the thread this object is run in. | |
| virtual void | setThread (ThreadInterface *t) |
| Set the thread this object will be run in. | |
Protected Attributes | |
| TimeService * | mTimeserv |
| OS::ThreadInterface * | mThread |
| OS::Semaphore | msem |
| OS::Mutex | m |
| TimerIds | mtimers |
| bool | mdo_quit |
Create a timer object which can hold max_timers timers.
A Timer must be executed in a SingleThread or it will refuse to start. If scheduler is set to -1 (default) no thread is created and you need to attach a thread yourself to this Timer.
| max_timers | The initial amount of timers this Timer can monitor. Keep as low as possible. See also setMaxTimers(). | |
| scheduler | The Orocos scheduler type for this timer. ORO_SCHED_OTHER or ORO_SCHED_RT or -1 to attach your own thread. | |
| priority | The priority within the scheduler of this timer. |
Definition at line 83 of file Timer.cpp.
References TimeService::Instance(), Timer::mThread, Timer::mtimers, Timer::mTimeserv, and ThreadInterface::start().
| void loop | ( | ) | [protected, virtual] |
The method that will be executed once when this class is run in a non periodic thread.
The default implementation calls step() once.
Reimplemented from RunnableInterface.
Definition at line 18 of file Timer.cpp.
References TimeService::getNSecs(), TimeService::InfiniteNSecs, Timer::m, Timer::mdo_quit, Timer::msem, Timer::mtimers, Timer::mTimeserv, Timer::timeout(), and Semaphore::waitUntil().
| bool breakLoop | ( | ) | [protected, virtual] |
This method is called by the framework to break out of the loop() method.
Reimplement this method to signal loop() to return and return true on success. When this method is not reimplemented by you, it will always return false, denoting that the loop can not be broken. If breakLoop() returns true, the caller will wait until loop() returns.
Reimplemented from RunnableInterface.
Definition at line 76 of file Timer.cpp.
References Timer::mdo_quit, Timer::msem, and Semaphore::signal().
| void timeout | ( | TimerId | timer_id | ) | [virtual] |
This function is called each time an armed or periodic timer expires.
The user must implement this method to catch the time outs.
| timer_id | The number of the timer that expired. |
Definition at line 100 of file Timer.cpp.
Referenced by Timer::loop().
| void setMaxTimers | ( | TimerId | max | ) |
Change the maximum number of timers in this object.
Any added timer with id >= max will be removed.
Definition at line 105 of file Timer.cpp.
References Timer::m, and Timer::mtimers.
Start a periodic timer which starts first over period seconds and then every period seconds.
| timer_id | The number of the timer, starting from zero. | |
| period | The period when the timer should expire. This is a floating point number. |
Definition at line 111 of file Timer.cpp.
References TimeService::getNSecs(), Timer::m, Timer::msem, Timer::mtimers, Timer::mTimeserv, RTT::Seconds_to_nsecs(), and Semaphore::signal().
Arm a timer to fire once over wait_time seconds.
| timer_id | The number of the timer, starting from zero. | |
| wait_time | The time in seconds from now, when the timer should expire. This is a floating point number. |
Definition at line 127 of file Timer.cpp.
References TimeService::getNSecs(), Timer::m, Timer::msem, Timer::mtimers, Timer::mTimeserv, RTT::Seconds_to_nsecs(), and Semaphore::signal().
| double timeRemaining | ( | TimerId | timer_id | ) | const |
Returns the remaining time before this timer elapses.
| 0.0 | if the timer is not armed or has already elapsed. |
Definition at line 152 of file Timer.cpp.
References TimeService::getNSecs(), Timer::m, Timer::mtimers, Timer::mTimeserv, and RTT::nsecs_to_Seconds().
| bool isActive | ( | TimerId | timer_id | ) | const |
Check if a given timer id is armed.
| timer_id | The number of the timer, starting from zero. |
Definition at line 144 of file Timer.cpp.
References Timer::m, and Timer::mtimers.
| bool killTimer | ( | TimerId | timer_id | ) |
Disable an armed timer.
| timer_id | The number of the timer, starting from zero. |
Definition at line 165 of file Timer.cpp.
References Timer::m, and Timer::mtimers.
| ThreadInterface * getThread | ( | ) | const [inherited] |
Get the thread this object is run in.
Definition at line 69 of file RunnableInterface.cpp.
Referenced by Timer::initialize().
1.5.3