#include <senf/Scheduler/EventHook.hh>
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.
void beforeEventHook(); void afterEventHook(); senf::scheduler::EventHook beforeEventHookEvent ( "beforeEventHook", beforeEventHook, true, senf::scheduler::EventHook::POST); senf::scheduler::EventHook afterEventHookEvent ( "afterEventHook", afterEventHook, true, senf::scheduler::EventHook::PRE);
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 67 of file EventHook.hh.
Public Types |
|
typedef boost::function< void()> | Callback |
Public Member Functions |
|
void | disable () |
Disable event. |
|
void | enable () |
Enable event. |
|
void | action (Callback const &cb) |
Change event callback. |
|
Static Public Attributes |
|
static Priority const | PRE = PRIORITY_HIGH |
Execute hook BEFORE all other events. |
|
static Priority const | POST = PRIORITY_LOW |
Execute hook AFTER all other events. |
|
Structors and default members |
|
EventHook (std::string const &name, Callback const &cb, Priority priority, bool initiallyEnabled=true) | |
Register an event hook. |
|
~EventHook () |
typedef boost::function<void ()> senf::scheduler::EventHook:: | ||||
Callback | ||||
Definition at line 75 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 |
Definition at line 36 of file EventHook.cci.
senf::scheduler::EventHook:: | ||||
~EventHook | () | |||
Definition at line 45 of file EventHook.cci.
void senf::scheduler::EventHook:: | ||||
action | ( | Callback const & | cb | ) |
Change event callback.
Definition at line 65 of file EventHook.cci.
void senf::scheduler::EventHook:: | ||||
disable | () | |||
Disable event.
Definition at line 51 of file EventHook.cci.
void senf::scheduler::EventHook:: | ||||
enable | () | |||
Enable event.
Definition at line 57 of file EventHook.cci.
Priority const senf::scheduler::EventHook::POST = PRIORITY_LOW | ||||
[static] | ||||
Execute hook AFTER all other events.
Definition at line 78 of file EventHook.hh.
Priority const senf::scheduler::EventHook::PRE = PRIORITY_HIGH | ||||
[static] | ||||
Execute hook BEFORE all other events.
Definition at line 77 of file EventHook.hh.