#include <Timer.hpp>
Public Types | |
typedef int | TimerId |
typedef int | TimerId |
Public Member Functions | |
bool | arm (TimerId timer_id, Seconds wait_time) |
bool | arm (TimerId timer_id, Seconds wait_time) |
bool | isArmed (TimerId timer_id) const |
bool | isArmed (TimerId timer_id) const |
bool | killTimer (TimerId timer_id) |
bool | killTimer (TimerId timer_id) |
void | setMaxTimers (TimerId max) |
void | setMaxTimers (TimerId max) |
bool | startTimer (TimerId timer_id, Seconds period) |
bool | startTimer (TimerId timer_id, Seconds period) |
virtual void | timeout (TimerId timer_id) |
virtual void | timeout (TimerId timer_id) |
Timer (TimerId max_timers, int scheduler=-1, int priority=0) | |
Timer (TimerId max_timers, int scheduler=-1, int priority=0) | |
TimeService::Seconds | timeRemaining (TimerId timer_id) const |
TimeService::Seconds | timeRemaining (TimerId timer_id) const |
~Timer () | |
~Timer () | |
Protected Types | |
typedef TimeService::nsecs | Time |
typedef TimeService::nsecs | Time |
typedef std::vector< std::pair < Time, Time > > | TimerIds |
typedef std::vector< std::pair < Time, Time > > | TimerIds |
Protected Member Functions | |
bool | breakLoop () |
bool | breakLoop () |
void | finalize () |
void | finalize () |
bool | initialize () |
bool | initialize () |
void | loop () |
void | loop () |
void | step () |
void | step () |
Protected Attributes | |
Mutex | m |
bool | mdo_quit |
Semaphore | msem |
base::ActivityInterface * | mThread |
TimerIds | mtimers |
TimeService * | mTimeserv |
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.
Definition at line 66 of file install/include/rtt/os/Timer.hpp.
typedef TimeService::nsecs RTT::os::Timer::Time [protected] |
Definition at line 79 of file rtt/os/Timer.hpp.
typedef TimeService::nsecs RTT::os::Timer::Time [protected] |
Definition at line 79 of file install/include/rtt/os/Timer.hpp.
typedef int RTT::os::Timer::TimerId |
A positive numeric ID representing a timer.
Definition at line 73 of file rtt/os/Timer.hpp.
typedef int RTT::os::Timer::TimerId |
A positive numeric ID representing a timer.
Definition at line 73 of file install/include/rtt/os/Timer.hpp.
typedef std::vector<std::pair<Time, Time> > RTT::os::Timer::TimerIds [protected] |
Index in vector is the timer id. 1st Time is the absolute time upon which the timer expires. 2nd Time is the optional period of the timer.
Definition at line 85 of file rtt/os/Timer.hpp.
typedef std::vector<std::pair<Time, Time> > RTT::os::Timer::TimerIds [protected] |
Index in vector is the timer id. 1st Time is the absolute time upon which the timer expires. 2nd Time is the optional period of the timer.
Definition at line 85 of file install/include/rtt/os/Timer.hpp.
RTT::Timer::Timer | ( | TimerId | max_timers, | |
int | scheduler = -1 , |
|||
int | priority = 0 | |||
) |
Create a 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. |
RTT::os::Timer::Timer | ( | TimerId | max_timers, | |
int | scheduler = -1 , |
|||
int | priority = 0 | |||
) |
Create a 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. |
RTT::os::Timer::~Timer | ( | ) |
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. |
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. |
bool RTT::os::Timer::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 RTT::base::RunnableInterface.
bool RTT::Timer::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 RTT::base::RunnableInterface.
void RTT::os::Timer::finalize | ( | ) | [protected, virtual] |
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.
void RTT::Timer::finalize | ( | ) | [protected, virtual] |
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.
bool RTT::os::Timer::initialize | ( | ) | [protected, virtual] |
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 RTT::Timer::initialize | ( | ) | [protected, virtual] |
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 RTT::os::Timer::isArmed | ( | TimerId | timer_id | ) | const |
Check if a given timer id is armed.
timer_id | The number of the timer, starting from zero. |
bool RTT::Timer::isArmed | ( | TimerId | timer_id | ) | const |
bool RTT::os::Timer::killTimer | ( | TimerId | timer_id | ) |
Disable an armed timer.
timer_id | The number of the timer, starting from zero. |
bool RTT::Timer::killTimer | ( | TimerId | timer_id | ) |
void RTT::os::Timer::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 RTT::base::RunnableInterface.
void RTT::Timer::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 RTT::base::RunnableInterface.
void RTT::os::Timer::setMaxTimers | ( | TimerId | max | ) |
Change the maximum number of timers in this object. Any added timer with id >= max will be removed.
void RTT::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. |
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. |
void RTT::os::Timer::step | ( | ) | [protected, virtual] |
The method that will be periodically executed when this class is run in a periodic thread.
Implements RTT::base::RunnableInterface.
void RTT::Timer::step | ( | ) | [protected, virtual] |
The method that will be periodically executed when this class is run in a periodic thread.
Implements RTT::base::RunnableInterface.
virtual void RTT::os::Timer::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. |
void RTT::Timer::timeout | ( | TimerId | timer_id | ) | [virtual] |
TimeService::Seconds RTT::os::Timer::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. |
double RTT::Timer::timeRemaining | ( | TimerId | timer_id | ) | const |
Mutex RTT::os::Timer::m [mutable, protected] |
Definition at line 78 of file install/include/rtt/os/Timer.hpp.
bool RTT::os::Timer::mdo_quit [protected] |
Definition at line 87 of file install/include/rtt/os/Timer.hpp.
Semaphore RTT::os::Timer::msem [protected] |
Definition at line 77 of file install/include/rtt/os/Timer.hpp.
base::ActivityInterface * RTT::os::Timer::mThread [protected] |
Definition at line 76 of file install/include/rtt/os/Timer.hpp.
TimerIds RTT::os::Timer::mtimers [protected] |
Definition at line 86 of file install/include/rtt/os/Timer.hpp.
TimeService * RTT::os::Timer::mTimeserv [protected] |
Definition at line 75 of file install/include/rtt/os/Timer.hpp.