|
SVCS - English Documentation
|
A thread-safe implementation of ISubject for centralized event distribution. More...
#include <EventBus.hxx>
Public Member Functions | |
| ~EventBus () override=default | |
| Default virtual destructor. | |
| void | attach (std::shared_ptr< IObserver > observer) override |
| Registers a new Observer. | |
| void | detach (std::shared_ptr< IObserver > observer_to_remove) override |
| Deregisters a specific Observer. | |
| void | notify (const Event &event) const override |
| Sends an event to all active Observers. | |
| Public Member Functions inherited from svcs::services::ISubject | |
| virtual | ~ISubject ()=default |
| Virtual destructor. | |
Additional Inherited Members | |
| Protected Attributes inherited from svcs::services::ISubject | |
| std::vector< IObserver * > | observers |
| Collection of registered observers. | |
A thread-safe implementation of ISubject for centralized event distribution.
This class uses std::weak_ptr to store observers, preventing circular dependencies and ensuring automatic cleanup of destroyed observers. It inherits from std::enable_shared_from_this to ensure that valid shared pointers to the bus can be created even inside its member functions.
|
inlineoverridevirtual |
Registers a new Observer.
The observer's shared pointer is stored as a weak pointer internally.
| observer | The smart pointer to the Observer to be registered. |
Implements svcs::services::ISubject.
|
inlineoverridevirtual |
Deregisters a specific Observer.
Compares the provided shared_ptr against all stored weak_ptr objects.
| observer_to_remove | The smart pointer to the Observer to be removed. |
Implements svcs::services::ISubject.
|
inlineoverridevirtual |
Sends an event to all active Observers.
Iterates over the list, safely locking each weak pointer before calling update(). Invalid (expired) weak pointers are effectively ignored.
| event | The constant reference to the Event to be published. |
Implements svcs::services::ISubject.