8#ifndef PLUGIN_EVENT_BUS_HPP
9#define PLUGIN_EVENT_BUS_HPP
14#include <shared_mutex>
148 m_observers.push_back(std::weak_ptr<IPluginEventObserver>(observer));
170 [observer](
const auto& weak) {
171 auto shared = weak.lock();
172 return !shared || shared.get() == observer;
197 if (
auto observer = weak.lock()) {
199 observer->OnPluginEvent(event);
200 }
catch (
const std::exception& e) {
250 return "ConfigChanged";
252 return "PanelCreated";
254 return "PanelDestroyed";
278 auto erased = std::remove_if(
280 [](
const auto& weak) { return weak.expired(); });
282 size_t count = std::distance(erased,
m_observers.end());
Logging facade for application-wide logging.
Interface for observing plugin events.
Definition PluginEventBus.hpp:70
virtual ~IPluginEventObserver()=default
virtual void OnPluginEvent(const PluginEvent &event)=0
Called when a plugin event occurs.
Central event bus for plugin lifecycle notifications.
Definition PluginEventBus.hpp:113
std::shared_ptr< IPluginEventObserver > ObserverPtr
Shared pointer to observer.
Definition PluginEventBus.hpp:116
PluginEventBus(const PluginEventBus &)=delete
void LogEvent(const PluginEvent &event) const
Logs event details for debugging.
Definition PluginEventBus.hpp:231
void Unsubscribe(const IPluginEventObserver *observer)
Unsubscribes observer from plugin events.
Definition PluginEventBus.hpp:161
void Subscribe(ObserverPtr observer)
Subscribes observer to plugin events.
Definition PluginEventBus.hpp:140
std::vector< std::weak_ptr< IPluginEventObserver > > m_observers
Definition PluginEventBus.hpp:224
PluginEventBus & operator=(const PluginEventBus &)=delete
void PublishEvent(const PluginEvent &event)
Publishes an event to all subscribed observers.
Definition PluginEventBus.hpp:188
static PluginEventBus & GetInstance()
Gets singleton instance.
Definition PluginEventBus.hpp:122
size_t GetObserverCount() const
Gets number of active observers.
Definition PluginEventBus.hpp:214
std::shared_mutex m_observersMutex
Definition PluginEventBus.hpp:223
void CleanupDeadObserversUnlocked()
Removes expired weak_ptr observers.
Definition PluginEventBus.hpp:276
static void Warn(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:297
static void Trace(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:279
static void Error(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logger.hpp:303
Definition IFieldConversionPlugin.hpp:8
PluginEventType
Fine-grained plugin lifecycle events.
Definition PluginEventBus.hpp:27
@ Enabled
State change events.
@ InitializationCompleted
Plugin Initialize() succeeded.
@ PanelCreated
Resource lifecycle.
@ ConfigurationChanged
Configuration events.
@ Loaded
Basic lifecycle events.
@ Unloaded
Plugin binary unloaded from memory.
@ Disabled
Plugin disabled/deactivated.
@ ErrorOccurred
Error events.
@ InitializationStarted
Initialization lifecycle.
@ InitializationFailed
Plugin Initialize() failed.
@ PanelDestroyed
UI panel destroyed.
Detailed information about plugin state change.
Definition PluginEventBus.hpp:56
std::chrono::system_clock::time_point timestamp
Event timestamp.
Definition PluginEventBus.hpp:61
void * plugin
Plugin instance (nullptr for Unloaded)
Definition PluginEventBus.hpp:59
std::string details
Additional details (error msg, config key)
Definition PluginEventBus.hpp:60
std::string pluginId
Plugin ID.
Definition PluginEventBus.hpp:58
PluginEventType type
Event type.
Definition PluginEventBus.hpp:57