|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Thread-safe event bus for publish/subscribe pattern. More...

Classes | |
| struct | HandlerEntry |
Public Member Functions | |
| SimpleEventBus () | |
| ~SimpleEventBus () | |
| void | start () |
| Start the event bus. | |
| void | stop () |
| Stop the event bus. | |
| bool | is_running () const |
| Check if the event bus is running. | |
| template<typename Event > | |
| uint64_t | subscribe (std::function< void(const Event &)> handler) |
| Subscribe to events of a specific type. | |
| void | unsubscribe (uint64_t subscription_id) |
| Unsubscribe from events. | |
| template<typename Event > | |
| void | publish (const Event &event) |
| Publish an event to all subscribers. | |
| template<typename Event > | |
| size_t | subscriber_count () const |
| Get the number of subscribers for an event type. | |
| void | clear () |
| Clear all subscriptions. | |
Private Attributes | |
| std::shared_mutex | mutex_ |
| std::atomic< bool > | running_ |
| std::atomic< uint64_t > | next_id_ |
| std::unordered_map< std::type_index, std::vector< HandlerEntry > > | handlers_ |
Thread-safe event bus for publish/subscribe pattern.
Allows components to communicate through events without direct coupling. Supports type-safe event publishing and subscription.
Definition at line 45 of file patterns.cppm.
|
inlineexport |
Definition at line 47 of file patterns.cppm.
|
inlineexport |
Definition at line 49 of file patterns.cppm.
References stop().

|
inlineexport |
Clear all subscriptions.
Definition at line 146 of file patterns.cppm.
|
inlineexport |
Check if the event bus is running.
Definition at line 70 of file patterns.cppm.
References running_.
Referenced by publish().

|
inlineexport |
Publish an event to all subscribers.
| Event | Event type |
| event | Event to publish |
Definition at line 116 of file patterns.cppm.
References handlers_, is_running(), and mutex_.

|
inlineexport |
|
inlineexport |
Stop the event bus.
Definition at line 63 of file patterns.cppm.
References running_.
Referenced by ~SimpleEventBus().

|
inlineexport |
Subscribe to events of a specific type.
| Event | Event type to subscribe to |
| handler | Handler function to call when event is published |
Definition at line 81 of file patterns.cppm.
|
inlineexport |
Get the number of subscribers for an event type.
Definition at line 133 of file patterns.cppm.
|
inlineexport |
Unsubscribe from events.
| subscription_id | ID returned from subscribe |
Definition at line 98 of file patterns.cppm.
|
exportprivate |
Definition at line 160 of file patterns.cppm.
Referenced by clear(), publish(), subscribe(), subscriber_count(), and unsubscribe().
|
mutableexportprivate |
Definition at line 157 of file patterns.cppm.
Referenced by clear(), publish(), subscribe(), subscriber_count(), and unsubscribe().
|
exportprivate |
Definition at line 159 of file patterns.cppm.
Referenced by subscribe().
|
exportprivate |
Definition at line 158 of file patterns.cppm.
Referenced by is_running(), start(), and stop().