Central event bus for plugin lifecycle notifications.
More...
#include <PluginEventBus.hpp>
Central event bus for plugin lifecycle notifications.
Manages subscriptions to plugin events and notifies all interested observers when events occur. Uses weak_ptr to automatically clean up destroyed observers.
- Thread Safety
- Thread-safe with shared_mutex for concurrent observer access.
- Usage Example
void OnPluginEvent(
const PluginEvent& event)
override {
if (event.
type == PluginEventType::Loaded) {
Logger::Info(
"Plugin loaded: {}", event.
pluginId);
}
}
};
auto observer = std::make_shared<MyObserver>();
bus.Subscribe(observer);
bus.PublishEvent(evt);
Interface for observing plugin events.
Definition PluginEventBus.hpp:70
static PluginEventBus & GetInstance()
Gets singleton instance.
Definition PluginEventBus.hpp:122
@ Loaded
Basic lifecycle events.
PluginEvent
Definition IPluginObserver.hpp:10
Detailed information about plugin state change.
Definition PluginEventBus.hpp:56
std::string pluginId
Plugin ID.
Definition PluginEventBus.hpp:58
PluginEventType type
Event type.
Definition PluginEventBus.hpp:57
◆ ObserverPtr
Shared pointer to observer.
◆ PluginEventBus() [1/2]
◆ PluginEventBus() [2/2]
| plugin::PluginEventBus::PluginEventBus |
( |
| ) |
|
|
privatedefault |
◆ CleanupDeadObserversUnlocked()
| void plugin::PluginEventBus::CleanupDeadObserversUnlocked |
( |
| ) |
|
|
inlineprivate |
Removes expired weak_ptr observers.
Called with lock held to clean up dead observers.
◆ GetInstance()
◆ GetObserverCount()
| size_t plugin::PluginEventBus::GetObserverCount |
( |
| ) |
const |
|
inline |
Gets number of active observers.
- Returns
- Count of subscribed observers
◆ LogEvent()
| void plugin::PluginEventBus::LogEvent |
( |
const PluginEvent & |
event | ) |
const |
|
inlineprivate |
Logs event details for debugging.
- Parameters
-
◆ operator=()
◆ PublishEvent()
| void plugin::PluginEventBus::PublishEvent |
( |
const PluginEvent & |
event | ) |
|
|
inline |
Publishes an event to all subscribed observers.
- Parameters
-
| event | The plugin event to publish |
Dead observers are automatically detected and removed. If an observer throws, the exception is logged but other observers are still notified (best-effort delivery).
◆ Subscribe()
| void plugin::PluginEventBus::Subscribe |
( |
ObserverPtr |
observer | ) |
|
|
inline |
Subscribes observer to plugin events.
- Parameters
-
| observer | Shared pointer to observer |
Observer will receive OnPluginEvent callbacks until destroyed or explicitly unsubscribed.
◆ Unsubscribe()
Unsubscribes observer from plugin events.
- Parameters
-
| observer | Observer to unsubscribe |
Safe if observer not subscribed or already destroyed.
◆ m_observers
◆ m_observersMutex
| std::shared_mutex plugin::PluginEventBus::m_observersMutex |
|
mutableprivate |
The documentation for this class was generated from the following file: