20 #ifndef _ANCH_EVENTS_EVENT_HANDLER_H_ 21 #define _ANCH_EVENTS_EVENT_HANDLER_H_ 23 #include "events/eventBus.hpp" 38 template<
typename Event,
typename Derived>
42 std::function<void(Derived&,const Event&) noexcept> _callbackFunction;
56 EventHandler(
const std::function<
void(Derived&,
const Event&) noexcept>& callbackFunction,
57 bool useEventBus =
false) {
58 _callbackFunction = callbackFunction;
62 _eventBus = &eventBus;
76 EventHandler(
const std::function<
void(Derived&,
const Event&) noexcept>& callbackFunction,
78 _callbackFunction = callbackFunction;
80 _eventBus = &eventBus;
88 if(_eventBus != NULL) {
99 virtual void notify(
const Event& event) noexcept {
100 _callbackFunction(*static_cast<Derived*>(
this), event);
108 #endif //_ANCH_EVENTS_EVENT_HANDLER_H_ An observer interface of the observers/observable design pattern.
Definition: observer.hpp:39
void removeObserver(anch::events::Observer< Event > &observer) noexcept
Definition: eventBus.hpp:118
EventHandler(const std::function< void(Derived &, const Event &) noexcept > &callbackFunction, anch::events::EventBus< Event > &eventBus)
Definition: eventHandler.hpp:76
virtual void notify(const Event &event) noexcept
Definition: eventHandler.hpp:99
A class which manage global events firing and events QoS.
Definition: eventBus.hpp:46
EventHandler(const std::function< void(Derived &, const Event &) noexcept > &callbackFunction, bool useEventBus=false)
Definition: eventHandler.hpp:56
AnCH framework base namespace.
Definition: base64.hpp:28
virtual ~EventHandler()
Definition: eventHandler.hpp:87
An event handler.
Definition: eventHandler.hpp:39
static EventBus< Event > & getInstance()
Definition: singleton.hpp:42
bool addObserver(anch::events::Observer< Event > &observer) noexcept
Definition: eventBus.hpp:98