Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::interface_event_bus Class Referenceabstract

Pure virtual interface for event bus implementation. More...

#include <event_bus_interface.h>

Inheritance diagram for kcenon::monitoring::interface_event_bus:
Inheritance graph
Collaboration diagram for kcenon::monitoring::interface_event_bus:
Collaboration graph

Public Member Functions

virtual ~interface_event_bus ()=default
 
template<concepts::EventType E>
common::VoidResult publish_event (const E &event)
 Publish an event to all subscribers.
 
template<concepts::EventType E>
common::Result< subscription_tokensubscribe_event (std::function< void(const E &)> handler, event_priority priority=event_priority::normal)
 Subscribe to events of a specific type.
 
template<concepts::EventType E, concepts::EventHandler< E > H>
common::Result< subscription_tokensubscribe_event (H &&handler, event_priority priority=event_priority::normal)
 Subscribe to events with a callable handler.
 
virtual common::VoidResult unsubscribe_event (const subscription_token &token)=0
 Unsubscribe from events using subscription token.
 
template<concepts::EventType E>
common::VoidResult clear_subscriptions ()
 Clear all subscriptions for a specific event type.
 
template<concepts::EventType E>
size_t get_subscriber_count () const
 Get the number of subscribers for an event type.
 
virtual bool is_active () const =0
 Check if event bus is active.
 
virtual common::VoidResult start ()=0
 Start the event bus.
 
virtual common::VoidResult stop ()=0
 Stop the event bus.
 
virtual size_t get_pending_event_count () const =0
 Get pending event count.
 
virtual common::VoidResult process_pending_events ()=0
 Process all pending events synchronously.
 

Protected Member Functions

virtual common::VoidResult publish_event_impl (std::type_index event_type, std::any event)=0
 
virtual common::Result< subscription_tokensubscribe_event_impl (std::type_index event_type, std::function< void(const std::any &)> handler, uint64_t handler_id, event_priority priority)=0
 
virtual common::VoidResult clear_subscriptions_impl (std::type_index event_type)=0
 
virtual size_t get_subscriber_count_impl (std::type_index event_type) const =0
 

Detailed Description

Pure virtual interface for event bus implementation.

The event bus provides a centralized communication mechanism for loosely coupled components using publish-subscribe pattern. It supports typed events, priority-based handler execution, and subscription management via tokens.

Thread Safety:
Implementations MUST be thread-safe. Publishing and subscribing can occur from multiple threads simultaneously. Handler execution order is determined by priority, and handlers should not block for extended periods.

Definition at line 251 of file event_bus_interface.h.

Constructor & Destructor Documentation

◆ ~interface_event_bus()

virtual kcenon::monitoring::interface_event_bus::~interface_event_bus ( )
virtualdefault

Member Function Documentation

◆ clear_subscriptions()

template<concepts::EventType E>
common::VoidResult kcenon::monitoring::interface_event_bus::clear_subscriptions ( )
inline

Clear all subscriptions for a specific event type.

Template Parameters
EThe event type to clear subscriptions for (must satisfy concepts::EventType)
Returns
Result indicating success or failure
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

Definition at line 321 of file event_bus_interface.h.

321 {
322 return clear_subscriptions_impl(std::type_index(typeid(E)));
323 }
virtual common::VoidResult clear_subscriptions_impl(std::type_index event_type)=0

References clear_subscriptions_impl().

Here is the call graph for this function:

◆ clear_subscriptions_impl()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::clear_subscriptions_impl ( std::type_index event_type)
protectedpure virtual

◆ get_pending_event_count()

virtual size_t kcenon::monitoring::interface_event_bus::get_pending_event_count ( ) const
pure virtual

Get pending event count.

Returns
Number of events waiting to be processed

Implemented in kcenon::monitoring::event_bus.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

◆ get_subscriber_count()

template<concepts::EventType E>
size_t kcenon::monitoring::interface_event_bus::get_subscriber_count ( ) const
inline

Get the number of subscribers for an event type.

Template Parameters
EThe event type to check (must satisfy concepts::EventType)
Returns
Number of subscribers
Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

Definition at line 331 of file event_bus_interface.h.

331 {
332 return get_subscriber_count_impl(std::type_index(typeid(E)));
333 }
virtual size_t get_subscriber_count_impl(std::type_index event_type) const =0

References get_subscriber_count_impl().

Here is the call graph for this function:

◆ get_subscriber_count_impl()

virtual size_t kcenon::monitoring::interface_event_bus::get_subscriber_count_impl ( std::type_index event_type) const
protectedpure virtual

◆ is_active()

virtual bool kcenon::monitoring::interface_event_bus::is_active ( ) const
pure virtual

Check if event bus is active.

Returns
True if active, false otherwise

Implemented in kcenon::monitoring::event_bus.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

◆ process_pending_events()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::process_pending_events ( )
pure virtual

Process all pending events synchronously.

Returns
Result indicating success or failure

Implemented in kcenon::monitoring::event_bus.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

◆ publish_event()

template<concepts::EventType E>
common::VoidResult kcenon::monitoring::interface_event_bus::publish_event ( const E & event)
inline

Publish an event to all subscribers.

Template Parameters
EThe type of event to publish (must satisfy concepts::EventType)
Parameters
eventThe event to publish
Returns
Result indicating success or failure

The event type must be a class type and copy-constructible. Using C++20 Concepts provides clear compile-time error messages when these requirements are not met.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

Definition at line 266 of file event_bus_interface.h.

266 {
267 return publish_event_impl(std::type_index(typeid(E)), std::make_any<E>(event));
268 }
virtual common::VoidResult publish_event_impl(std::type_index event_type, std::any event)=0

References publish_event_impl().

Here is the call graph for this function:

◆ publish_event_impl()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::publish_event_impl ( std::type_index event_type,
std::any event )
protectedpure virtual

◆ start()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::start ( )
pure virtual

◆ stop()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::stop ( )
pure virtual

◆ subscribe_event() [1/2]

template<concepts::EventType E, concepts::EventHandler< E > H>
common::Result< subscription_token > kcenon::monitoring::interface_event_bus::subscribe_event ( H && handler,
event_priority priority = event_priority::normal )
inline

Subscribe to events with a callable handler.

Template Parameters
EThe type of event to subscribe to (must satisfy concepts::EventType)
HThe handler type (must satisfy concepts::EventHandler<E>)
Parameters
handlerThe handler callable
priorityPriority for handler execution
Returns
Subscription token for managing the subscription

This overload accepts any callable that satisfies the EventHandler concept, providing more flexibility than the std::function overload.

Definition at line 303 of file event_bus_interface.h.

304 {
305 return subscribe_event(std::function<void(const E&)>(std::forward<H>(handler)), priority);
306 }
common::Result< subscription_token > subscribe_event(std::function< void(const E &)> handler, event_priority priority=event_priority::normal)
Subscribe to events of a specific type.

References subscribe_event().

Here is the call graph for this function:

◆ subscribe_event() [2/2]

template<concepts::EventType E>
common::Result< subscription_token > kcenon::monitoring::interface_event_bus::subscribe_event ( std::function< void(const E &)> handler,
event_priority priority = event_priority::normal )
inline

Subscribe to events of a specific type.

Template Parameters
EThe type of event to subscribe to (must satisfy concepts::EventType)
Parameters
handlerThe handler function for the event
priorityPriority for handler execution
Returns
Subscription token for managing the subscription

The event type must be a class type and copy-constructible. Using C++20 Concepts provides clear compile-time error messages when these requirements are not met.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

Definition at line 282 of file event_bus_interface.h.

283 {
284 auto wrapped_handler = event_handler<E>(handler, priority);
286 std::type_index(typeid(E)),
287 [wrapped_handler](const std::any& event) { wrapped_handler(std::any_cast<E>(event)); },
288 wrapped_handler.get_id(), priority);
289 }
virtual common::Result< subscription_token > subscribe_event_impl(std::type_index event_type, std::function< void(const std::any &)> handler, uint64_t handler_id, event_priority priority)=0

References subscribe_event_impl().

Referenced by subscribe_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribe_event_impl()

virtual common::Result< subscription_token > kcenon::monitoring::interface_event_bus::subscribe_event_impl ( std::type_index event_type,
std::function< void(const std::any &)> handler,
uint64_t handler_id,
event_priority priority )
protectedpure virtual

◆ unsubscribe_event()

virtual common::VoidResult kcenon::monitoring::interface_event_bus::unsubscribe_event ( const subscription_token & token)
pure virtual

Unsubscribe from events using subscription token.

Parameters
tokenThe subscription token
Returns
Result indicating success or failure

Implemented in kcenon::monitoring::event_bus.

Examples
/home/runner/work/monitoring_system/monitoring_system/include/kcenon/monitoring/interfaces/event_bus_interface.h.

The documentation for this class was generated from the following file: