18 if (identifier.empty()) {
19 throw std::invalid_argument(
"Event handler identifier must not be empty.");
25 const std::string
str() const noexcept {
return identifier_; }
33 std::string identifier_;
83 [[nodiscard]]
virtual std::unique_ptr<EventSubscriber>
85 std::function<
void(std::shared_ptr<EventMessage> message)> &&handler) = 0;
94 virtual void publish(std::unique_ptr<EventMessage> message) = 0;
Defines the event aggregator interface type.
Definition: event_aggregator.h:59
virtual void publish(std::unique_ptr< EventMessage > message)=0
Publishes a message to all subscribers synchronous.
virtual std::unique_ptr< EventSubscriber > subscribe(EventType event_id, std::function< void(std::shared_ptr< EventMessage > message)> &&handler)=0
Subscribes a handler function to an event type identifier.
EventAggregator & operator=(const EventAggregator &)=delete
virtual void publish_async(std::unique_ptr< EventMessage > message)=0
Publishes a message to all subscribers asynchronous.
virtual bool unsubscribe(const EventSubscriber &subscriber)=0
Unsubscribes from an event notification.
EventAggregator(const EventAggregator &)=delete
EventAggregator()=default
Initialises a new instance of the EventAggregator class.
EventAggregator & operator=(EventAggregator &&other)=default
Replaces the EventAggregator contents with the other using move semantics.
virtual ~EventAggregator()=default
Destroys a EventAggregator instance.
EventAggregator(EventAggregator &&other)=default
Constructs the EventAggregator using move semantics.
Defines the event subscriber interface type.
Definition: event_aggregator.h:37
EventSubscriber & operator=(const EventSubscriber &)=delete
EventSubscriber(const EventSubscriber &)=delete
EventSubscriber()=default
Initialises a new instance of the EventSubscriber class.
EventSubscriber(EventSubscriber &&)=delete
virtual ~EventSubscriber()=default
Destroys a EventSubscriber instance.
virtual const EventHandlerIdentifier id() const noexcept=0
Gets the subscriber unique identifier.
EventSubscriber & operator=(EventSubscriber &&)=delete
virtual void unsubscribe() const =0
Unsubscribes from the event.
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
EventType
Event Message type enumeration.
Definition: event_message.h:10
Defines the event handler identifier type.
Definition: event_aggregator.h:11
EventHandlerIdentifier(std::string identifier)
Initialises a new instance of the EventHandlerIdentifier structure.
Definition: event_aggregator.h:17
const std::string str() const noexcept
Gets the event handle identifier string representation.
Definition: event_aggregator.h:25
EventHandlerIdentifier()=delete
auto operator<=>(const EventHandlerIdentifier &other) const =default
Compare this instance with other EventHandlerIdentifier instance.