An event handler. More...
#include <eventHandler.hpp>
Public Member Functions | |
| EventHandler (const std::function< void(Derived &, const anch::events::Event< T > &)> &callbackFunction, bool useEventBus=false) | |
| EventHandler (const std::function< void(Derived &, const anch::events::Event< T > &)> &callbackFunction, anch::events::EventBus< T > &eventBus) | |
| virtual | ~EventHandler () |
| void | unsubscribe () noexcept |
| virtual void | handle (const anch::events::Event< T > &event) noexcept |
| Public Member Functions inherited from anch::events::Observer< T > | |
| virtual | ~Observer ()=default |
An event handler.
It provides a simple way to inherits several times from Observer and cutomize event receiving method name.
The handler is registered in the EventBus by its constructor and unregistered by its destructor. These constructor and destructor run while Derived is not built (or already destroyed): when events can be fired from another thread, Derived destructor has to call unsubscribe (and events must not be fired before Derived construction ends).
| anch::events::EventHandler< T, Derived >::EventHandler | ( | const std::function< void(Derived &, const anch::events::Event< T > &)> & | callbackFunction, |
| bool | useEventBus = false ) |
EventHandler constructor.
Register callback method.
Register itself in global EventBus if set.
| callbackFunction | the callback method to use on notify |
| useEventBus | if true register itself in global EventBus, false otherwise (default) |
| anch::events::EventHandler< T, Derived >::EventHandler | ( | const std::function< void(Derived &, const anch::events::Event< T > &)> & | callbackFunction, |
| anch::events::EventBus< T > & | eventBus ) |
EventHandler constructor.
Registers callback method.
Register itself in EventBus.
| callbackFunction | the callback method to use on notify |
| eventBus | the EventBus to register itself |
|
virtual |
EventHandler destructor.
Unregister EventHandler from EventBus if needed.
|
virtualnoexcept |
Invokes callback method on receiving event.
| event | the event which has been fired |
Implements anch::events::Observer< T >.
|
noexcept |
Unregister EventHandler from EventBus if needed.
When it returns, the handler will not be notified anymore by the EventBus.