senf::scheduler::EventHook Class Reference

Event hook event. More...

#include <senf/Scheduler/EventHook.hh>

Inheritance diagram for senf::scheduler::EventHook:

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 ()
 

Detailed Description

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.

void beforeEventHook();
void afterEventHook();
senf::scheduler::EventHook beforeEventHookEvent (
"beforeEventHook", beforeEventHook, senf::scheduler::EventHook::POST);
senf::scheduler::EventHook afterEventHookEvent (
"afterEventHook", afterEventHook, 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 58 of file EventHook.hh.

Member Typedef Documentation

◆ Callback

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

Definition at line 66 of file EventHook.hh.

Constructor & Destructor Documentation

◆ EventHook()

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.

Parameters
[in]nameDescriptive event name (purely informational)
[in]cbCallback to call
[in]initiallyEnabledif set false, do not enable callback automatically.
[in]priorityevent priority, defaults to POST

◆ ~EventHook()

senf::scheduler::EventHook::~EventHook ( )

Member Function Documentation

◆ action()

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

Change event callback.

◆ disable()

void senf::scheduler::EventHook::disable ( )

Disable event.

◆ enable()

void senf::scheduler::EventHook::enable ( )

Enable event.

Member Data Documentation

◆ POST

Priority const senf::scheduler::EventHook::POST = PRIORITY_LOW
static

Execute hook AFTER all other events.

Definition at line 69 of file EventHook.hh.

◆ PRE

Priority const senf::scheduler::EventHook::PRE = PRIORITY_HIGH
static

Execute hook BEFORE all other events.

Definition at line 68 of file EventHook.hh.


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