An observable implementation of the observers/observable design pattern. More...
#include <observable.hpp>
Public Member Functions | |
| Observable () | |
| virtual | ~Observable () |
| bool | addObserver (anch::events::Observer< T > &observer) |
| void | removeObserver (anch::events::Observer< T > &observer) |
| void | notifyObservers (const T &event, const std::map< std::string, std::string > &headers={}) |
| void | notifyObservers (const anch::events::Event< T > &event) |
An observable implementation of the observers/observable design pattern.
This class maintains an observer list which have to be notified on event.
Notifications are synchronous (observers are called in the notifying thread, in their registration order). Observers can add or remove observers, or notify again, from their handle method. When removeObserver returns, the observer will not be notified anymore and can be destroyed.
| anch::events::Observable< T >::Observable | ( | ) |
Observable default constructor
|
virtual |
Observable destructor
| bool anch::events::Observable< T >::addObserver | ( | anch::events::Observer< T > & | observer | ) |
Add observer for notifications
| observer | The observer to add |
true if observer has been added, false otherwise | void anch::events::Observable< T >::notifyObservers | ( | const anch::events::Event< T > & | event | ) |
Notify every observer that an event has been fired
| event | the event to fire |
| void anch::events::Observable< T >::notifyObservers | ( | const T & | event, |
| const std::map< std::string, std::string > & | headers = {} ) |
Notify every observer that an event has been fired
| event | the event to fire |
| headers | the event's headers (default to empty) |
| void anch::events::Observable< T >::removeObserver | ( | anch::events::Observer< T > & | observer | ) |
Remove observer for notifications.
Wait for notifications running in other threads.
| observer | The observer to remove |