#include <Timer.hpp>
Classes | |
struct | TimerInfo |
Public Types | |
typedef int | TimerId |
Public Types inherited from RTT::base::RunnableInterface | |
enum | WorkReason { TimeOut = 0, Trigger, IOReady } |
Public Member Functions | |
bool | arm (TimerId timer_id, Seconds wait_time) |
bool | isArmed (TimerId timer_id) const |
bool | killTimer (TimerId timer_id) |
void | setMaxTimers (TimerId max) |
bool | startTimer (TimerId timer_id, Seconds period) |
virtual void | timeout (TimerId timer_id) |
Timer (TimerId max_timers, int scheduler=-1, int priority=0, const std::string &name=std::string("Timer")) | |
TimeService::Seconds | timeRemaining (TimerId timer_id) const |
bool | waitFor (RTT::os::Timer::TimerId id) |
bool | waitForUntil (RTT::os::Timer::TimerId id, nsecs abs_time) |
~Timer () | |
Public Member Functions inherited from RTT::base::RunnableInterface | |
ActivityInterface * | getActivity () const |
Query for the task this interface is run in. More... | |
virtual os::ThreadInterface * | getThread () const |
virtual bool | hasWork () |
RunnableInterface () | |
virtual void | setActivity (ActivityInterface *task) |
Set the task this interface is run in. More... | |
virtual void | work (WorkReason reason) |
virtual | ~RunnableInterface () |
Protected Types | |
typedef TimeService::nsecs | Time |
typedef std::vector< TimerInfo > | TimerIds |
Protected Member Functions | |
bool | breakLoop () |
void | finalize () |
bool | initialize () |
void | loop () |
void | step () |
Protected Attributes | |
Condition | mcond |
bool | mdo_quit |
Mutex | mmutex |
base::ActivityInterface * | mThread |
TimerIds | mtimers |
This class allows to define a timer object which can be armed in single shot and periodic mode. 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.
If you do not attach an activity, the Timer will create a thread of its own and start it. That thread will be stopped and cleaned up when the Timer is destroyed.
|
protected |
typedef int RTT::os::Timer::TimerId |
|
protected |
Timer::Timer | ( | TimerId | max_timers, |
int | scheduler = -1 , |
||
int | priority = 0 , |
||
const std::string & | name = std::string("Timer") |
||
) |
Create a named timer object which can hold max_timers timers. A Timer must be executed in a non periodic thread (or the main thread) 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. |
name | The name of the timer (ie the underlying Activity/Thread) |
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. |
|
protectedvirtual |
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 RTT::base::RunnableInterface.
|
protectedvirtual |
The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped.
Implements RTT::base::RunnableInterface.
|
protectedvirtual |
The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started.
Implements RTT::base::RunnableInterface.
bool Timer::isArmed | ( | TimerId | timer_id | ) | const |
bool Timer::killTimer | ( | TimerId | timer_id | ) |
|
protectedvirtual |
The method that will be executed once when this class is run in a non periodic Activity. The default implementation calls step() once.
Reimplemented from RTT::base::RunnableInterface.
void Timer::setMaxTimers | ( | TimerId | max | ) |
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. |
|
protectedvirtual |
The method that will be (periodically) executed when this object is run in an Activity.
Implements RTT::base::RunnableInterface.
|
virtual |
double Timer::timeRemaining | ( | TimerId | timer_id | ) | const |
bool Timer::waitFor | ( | RTT::os::Timer::TimerId | id | ) |
bool Timer::waitForUntil | ( | RTT::os::Timer::TimerId | id, |
nsecs | abs_time | ||
) |
Wait for a timer to expire with timeout.
timer_id | The number of the timer, starting from zero. |
abs_time | The absolute time to wait until before the condition happens. Use rtos_get_time_ns() to get the current time and Seconds_to_nsecs to add a certain amount to the result. |
|
protected |