Event hook event. More...
#include <senf/Scheduler/EventHook.hh>
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 event. More... | |
void | enable () |
Enable event. More... | |
void | action (Callback const &cb) |
Change event callback. 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 () |
Static Public Attributes | |
static Priority const | PRE = PRIORITY_HIGH |
Execute hook BEFORE all other events. More... | |
static Priority const | POST = PRIORITY_LOW |
Execute hook AFTER all other events. More... | |
Structors and default members | |
EventHook (std::string const &name, Callback const &cb, Priority priority, bool initiallyEnabled=true) | |
Register an event hook. More... | |
~EventHook () | |
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 () |
Event hook event.
This event is special: It is not a real event, it is a kind of hook which is called, whenever any other event is signaled. Combining this with explicit priority specification, this can be used to implement hooks which are called before or after any other callback.
The EventHook class is an implementation of the RAII idiom: The event will be automatically unregistered in the EventHook destructor. The EventHook 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 58 of file EventHook.hh.
typedef boost::function<void ()> senf::scheduler::EventHook::Callback |
Definition at line 66 of file EventHook.hh.
senf::scheduler::EventHook::EventHook | ( | std::string const & | name, |
Callback const & | cb, | ||
Priority | priority, | ||
bool | initiallyEnabled = true |
||
) |
Register an event hook.
Registers cb to be called whenever any other event is signaled by the scheduler. If initiallyEnabled is set false
, the callback will not be enabled automatically. Use enable() to do so.
[in] | name | Descriptive event name (purely informational) |
[in] | cb | Callback to call |
[in] | initiallyEnabled | if set false , do not enable callback automatically. |
[in] | priority | event priority, defaults to POST |
senf::scheduler::EventHook::~EventHook | ( | ) |
void senf::scheduler::EventHook::action | ( | Callback const & | cb | ) |
Change event callback.
void senf::scheduler::EventHook::disable | ( | ) |
Disable event.
void senf::scheduler::EventHook::enable | ( | ) |
Enable event.
|
static |
Execute hook AFTER all other events.
Definition at line 69 of file EventHook.hh.
|
static |
Execute hook BEFORE all other events.
Definition at line 68 of file EventHook.hh.