#include <senf/Scheduler/TimerEvent.hh>
The TimerEvent class registers a deadline timer callback which will be called when the timer expires.
Timer events are implemented using POSIX timers. Depending on kernel features, the timer resolution will be far more precise than the linux clock tick resolution. The nominal timer resolution is 1 nanosecond.
The timeout time is set as absolute time as returned by the senf::ClockService. After expiration, the timer will be disabled. It may be re-enabled by setting a new timeout time. It is also possible to change a running timer resetting the timeout time.
The TimerEvent class is an implementation of the RAII idiom: The event will be automatically unregistered in the TimerEvent destructor. The TimerEvent instance should be created within the same scope or on a scope below where the callback is defined (e.g. if the callback is a member function it should be defined as a class member).
Definition at line 67 of file TimerEvent.hh.
Public Types |
|
typedef boost::function< void()> | Callback |
Public Member Functions |
|
void | disable () |
Disable timer. |
|
void | enable () |
Enable timer. |
|
void | action (Callback const &cb) |
Change timer event callback. |
|
void | timeout (ClockService::clock_type timeout, bool initiallyEnabled=true) |
Re-arm or move timeout. |
|
ClockService::clock_type | timeout () const |
Get current/last timeout value. |
|
Structors and default members |
|
TimerEvent (std::string const &name, Callback const &cb, ClockService::clock_type timeout, bool initiallyEnabled=true) | |
Register a timer event. |
|
TimerEvent (std::string const &name, Callback const &cb) | |
Create a timer event. |
|
~TimerEvent () |
typedef boost::function<void ()> senf::scheduler::TimerEvent:: | ||||
Callback | ||||
Definition at line 75 of file TimerEvent.hh.
senf::scheduler::TimerEvent:: | ||||
TimerEvent | ( | std::string const & | name, | |
Callback const & | cb, | |||
ClockService::clock_type | timeout, | |||
bool |
initiallyEnabled = true
|
) | ||
Register a timer event.
Registers cb to be called as soon as possible after the time timeout is reached. If initiallyEnabled is set false
, the callback will not be enabled automatically. Use enable() to do so.
[in] | name | Descriptive timer name (purely informational) |
[in] | cb | Callback to call |
[in] | timeout | timeout time after the timer will be disabled |
[in] | initiallyEnabled | if set false , do not enable callback automatically. |
Definition at line 37 of file TimerEvent.cci.
senf::scheduler::TimerEvent:: | ||||
TimerEvent | ( | std::string const & | name, | |
Callback const & | cb | ) | ||
Create a timer event.
Creates a timer event for callback cb. The timer is initially disabled. Use the timeout() member to set the timeout time.
[in] | name | Descriptive timer name (purely informational) |
[in] | cb | Callback to call. |
Definition at line 46 of file TimerEvent.cci.
senf::scheduler::TimerEvent:: | ||||
~TimerEvent | () | |||
Definition at line 50 of file TimerEvent.cci.
void senf::scheduler::TimerEvent:: | ||||
action | ( | Callback const & | cb | ) |
Change timer event callback.
Definition at line 68 of file TimerEvent.cci.
void senf::scheduler::TimerEvent:: | ||||
disable | () | |||
Disable timer.
Definition at line 62 of file TimerEvent.cci.
void senf::scheduler::TimerEvent:: | ||||
enable | () | |||
Enable timer.
Definition at line 56 of file TimerEvent.cci.
senf::ClockService::clock_type senf::scheduler::TimerEvent:: | ||||
timeout | () | |||
Get current/last timeout value.
Definition at line 82 of file TimerEvent.cci.
void senf::scheduler::TimerEvent:: | ||||
timeout | ( | ClockService::clock_type | timeout, | |
bool |
initiallyEnabled = true
|
) | ||
Re-arm or move timeout.
[in] | timeout | new timeout time |
[in] | initiallyEnabled | if set false , do not enable callback automatically. |
Definition at line 73 of file TimerEvent.cci.