Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
RTT::os::Timer Class Reference

#include <Timer.hpp>

Inheritance diagram for RTT::os::Timer:
Inheritance graph
[legend]

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
ActivityInterfacegetActivity () const
 Query for the task this interface is run in. More...
 
virtual os::ThreadInterfacegetThread () 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< TimerInfoTimerIds
 

Protected Member Functions

bool breakLoop ()
 
void finalize ()
 
bool initialize ()
 
void loop ()
 
void step ()
 

Protected Attributes

Condition mcond
 
bool mdo_quit
 
Mutex mmutex
 
base::ActivityInterfacemThread
 
TimerIds mtimers
 

Detailed Description

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 68 of file Timer.hpp.

Member Typedef Documentation

Definition at line 80 of file Timer.hpp.

A positive numeric ID representing a timer.

Definition at line 75 of file Timer.hpp.

typedef std::vector<TimerInfo> 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 97 of file Timer.hpp.

Constructor & Destructor Documentation

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.

Parameters
max_timersThe initial amount of timers this Timer can monitor. Keep as low as possible. See also setMaxTimers().
schedulerThe Orocos scheduler type for this timer. ORO_SCHED_OTHER or ORO_SCHED_RT or -1 to attach your own thread.
priorityThe priority within the scheduler of this timer.
nameThe name of the timer (ie the underlying Activity/Thread)

Definition at line 137 of file Timer.cpp.

Timer::~Timer ( )

Definition at line 147 of file Timer.cpp.

Member Function Documentation

bool Timer::arm ( TimerId  timer_id,
Seconds  wait_time 
)

Arm a timer to fire once over wait_time seconds.

Parameters
timer_idThe number of the timer, starting from zero.
wait_timeThe time in seconds from now, when the timer should expire. This is a floating point number.
See also
killTimer to disable it before it fires.

Definition at line 183 of file Timer.cpp.

bool Timer::breakLoop ( )
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.

Returns
true if the loop could be notified to return.

Reimplemented from RTT::base::RunnableInterface.

Definition at line 126 of file Timer.cpp.

void Timer::finalize ( )
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.

Definition at line 55 of file Timer.cpp.

bool Timer::initialize ( )
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.

Definition at line 50 of file Timer.cpp.

bool Timer::isArmed ( TimerId  timer_id) const

Check if a given timer id is armed.

Parameters
timer_idThe number of the timer, starting from zero.

Definition at line 203 of file Timer.cpp.

bool Timer::killTimer ( TimerId  timer_id)

Disable an armed timer.

Parameters
timer_idThe number of the timer, starting from zero.

Definition at line 230 of file Timer.cpp.

void Timer::loop ( )
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.

Definition at line 61 of file Timer.cpp.

void Timer::setMaxTimers ( TimerId  max)

Change the maximum number of timers in this object. Any added timer with id >= max will be removed.

Definition at line 158 of file Timer.cpp.

bool Timer::startTimer ( TimerId  timer_id,
Seconds  period 
)

Start a periodic timer which starts first over period seconds and then every period seconds.

Parameters
timer_idThe number of the timer, starting from zero.
periodThe period when the timer should expire. This is a floating point number.
See also
killTimer to disable it again.

Definition at line 164 of file Timer.cpp.

void Timer::step ( )
protectedvirtual

The method that will be (periodically) executed when this object is run in an Activity.

Implements RTT::base::RunnableInterface.

Definition at line 57 of file Timer.cpp.

void 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.

Parameters
timer_idThe number of the timer that expired.

Definition at line 153 of file Timer.cpp.

double Timer::timeRemaining ( TimerId  timer_id) const

Returns the remaining time before this timer elapses.

Return values
0.0if the timer is not armed or has already elapsed.
Returns
the remaining time in seconds.

Definition at line 214 of file Timer.cpp.

bool Timer::waitFor ( RTT::os::Timer::TimerId  id)

Wait for a timer to expire.

Parameters
timer_idThe number of the timer, starting from zero.
Returns
true if timer has expired or if it was killed and false if the timer is not armed

Definition at line 244 of file Timer.cpp.

bool Timer::waitForUntil ( RTT::os::Timer::TimerId  id,
nsecs  abs_time 
)

Wait for a timer to expire with timeout.

Parameters
timer_idThe number of the timer, starting from zero.
abs_timeThe 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.
Returns
true if timer has expired or if it was killed before abs_time and false if the timer is not armed

Definition at line 257 of file Timer.cpp.

Member Data Documentation

Condition RTT::os::Timer::mcond
protected

Definition at line 78 of file Timer.hpp.

bool RTT::os::Timer::mdo_quit
protected

Definition at line 99 of file Timer.hpp.

Mutex RTT::os::Timer::mmutex
mutableprotected

Definition at line 79 of file Timer.hpp.

base::ActivityInterface* RTT::os::Timer::mThread
protected

Definition at line 77 of file Timer.hpp.

TimerIds RTT::os::Timer::mtimers
protected

Definition at line 98 of file Timer.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:47