A class which manage global events firing and events QoS. More...
#include <eventBus.hpp>
Public Member Functions | |
| EventBus () | |
| EventBus (const EventBus &)=delete | |
| ~EventBus () | |
| EventBus & | operator= (const EventBus &)=delete |
| bool | addObserver (anch::events::Observer< T > &observer) noexcept |
| void | removeObserver (anch::events::Observer< T > &observer) noexcept |
| void | fireEvent (const T &event, const std::map< std::string, std::string > &headers={}) noexcept |
| void | fireEvent (const anch::events::Event< T > &event) noexcept |
| void | release () |
| Public Member Functions inherited from anch::Singleton< EventBus< T > > | |
| Singleton & | operator= (const Singleton &)=delete |
Static Public Member Functions | |
| static bool | AddObserver (anch::events::Observer< T > &observer) noexcept |
| static void | RemoveObserver (anch::events::Observer< T > &observer) noexcept |
| static void | FireEvent (const T &event, const std::map< std::string, std::string > &headers={}) noexcept |
| static void | FireEvent (const anch::events::Event< T > &event) noexcept |
| Static Public Member Functions inherited from anch::Singleton< EventBus< T > > | |
| static T & | getInstance () |
Friends | |
| class | anch::Singleton< EventBus< T > > |
Additional Inherited Members | |
| Protected Member Functions inherited from anch::Singleton< EventBus< T > > | |
| Singleton () noexcept=default | |
| ~Singleton ()=default | |
A class which manage global events firing and events QoS.
Events are queued and notified asynchronously, in their firing order, by a dedicated thread (started on first event). fireEvent does not wait for observers: observers can fire events from their handle method.
Observers can add or remove observers from their handle method. When removeObserver returns, the observer will not be notified anymore and can be destroyed.
getInstance returns the global EventBus. Other buses can be created as plain objects.
The destructor notifies the queued events and stops the thread: it must not be called from an observer. The global bus is destroyed at program exit: its observers must not use already destroyed static objects.
| anch::events::EventBus< T >::EventBus | ( | ) |
EventBus default constructor.
This constructor is public to allow to declare other buses than the global one.
|
delete |
| anch::events::EventBus< T >::~EventBus | ( | ) |
EventBus destructor.
Notify the queued events and stop the bus thread.
|
staticnoexcept |
|
noexcept |
|
staticnoexcept |
Retrieve EventBus instance and notify all observer that an event has been fired
| event | the event which has been fired |
|
staticnoexcept |
Retrieve EventBus instance and notify all observer that an event has been fired
| event | the event which has been fired |
| headers | the event's context |
|
noexcept |
Notify all observer that an event has been fired.
The event is queued: this method does not wait for observers.
| event | the event which has been fired |
|
noexcept |
Notify all observer that an event has been fired.
The event is queued: this method does not wait for observers.
| event | the event which has been fired |
| headers | the event's context |
|
delete |
| void anch::events::EventBus< T >::release | ( | ) |
Delete this .
Only for buses allocated with new (never for the global bus returned by getInstance).
|
staticnoexcept |
|
noexcept |
Remove observer for notifications.
Wait for the running notification (when not called from an observer of this bus).
| observer | the Observer to remove |