senf::scheduler::TimerEvent Class Reference

Deadline timer event. More...

#include <senf/Scheduler/TimerEvent.hh>

Inheritance diagram for senf::scheduler::TimerEvent:

Public Types

typedef boost::function< void()> Callback
 
- Public Types inherited from senf::scheduler::detail::FIFORunner::TaskInfo
enum  Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 }
 

Public Member Functions

void disable ()
 Disable timer. More...
 
void enable ()
 Enable timer. More...
 
void action (Callback const &cb)
 Change timer event callback. More...
 
void timeout (ClockService::clock_type const &timeout, bool initiallyEnabled=true)
 Re-arm or move timeout. More...
 
ClockService::clock_type const & timeout () const
 Get current/last timeout value. More...
 
- Public Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo
 TaskInfo (std::string const &name, Priority priority=PRIORITY_NORMAL)
 
virtual ~TaskInfo ()
 
void run ()
 
bool runnable () const
 
- Public Member Functions inherited from senf::scheduler::detail::Event
std::string const & name () const
 Get event name. More...
 
bool enabled () const
 true, if event is enabled, false otherwise More...
 
unsigned runCount () const
 Number of times, event was fired. More...
 
char const * type () const
 Event type code. More...
 
std::string info () const
 Additional event information. More...
 
 Event (std::string const &name)
 
virtual ~Event ()
 

Structors and default members

 TimerEvent (std::string const &name, Callback const &cb, ClockService::clock_type timeout, bool initiallyEnabled=true)
 Register a timer event. More...
 
 TimerEvent (std::string const &name, Callback const &cb)
 Create a timer event. More...
 
 ~TimerEvent ()
 

Additional Inherited Members

- Protected Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo
void setRunnable ()
 
- Protected Member Functions inherited from senf::scheduler::detail::Event
void countRun ()
 

Detailed Description

Deadline timer event.

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 59 of file TimerEvent.hh.

Member Typedef Documentation

◆ Callback

typedef boost::function<void ()> senf::scheduler::TimerEvent::Callback

Definition at line 67 of file TimerEvent.hh.

Constructor & Destructor Documentation

◆ TimerEvent() [1/2]

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.

Parameters
[in]nameDescriptive timer name (purely informational)
[in]cbCallback to call
[in]timeouttimeout time after the timer will be disabled
[in]initiallyEnabledif set false, do not enable callback automatically.

◆ TimerEvent() [2/2]

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.

Parameters
[in]nameDescriptive timer name (purely informational)
[in]cbCallback to call.

◆ ~TimerEvent()

senf::scheduler::TimerEvent::~TimerEvent ( )

Member Function Documentation

◆ action()

void senf::scheduler::TimerEvent::action ( Callback const &  cb)

Change timer event callback.

◆ disable()

void senf::scheduler::TimerEvent::disable ( )

Disable timer.

◆ enable()

void senf::scheduler::TimerEvent::enable ( )

Enable timer.

◆ timeout() [1/2]

void senf::scheduler::TimerEvent::timeout ( ClockService::clock_type const &  timeout,
bool  initiallyEnabled = true 
)

Re-arm or move timeout.

Parameters
[in]timeoutnew timeout time
[in]initiallyEnabledif set false, do not enable callback automatically.

◆ timeout() [2/2]

ClockService::clock_type const& senf::scheduler::TimerEvent::timeout ( ) const

Get current/last timeout value.


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