Health-GPS 3.0.0.0
Global Health Policy Simulation model (Health-GPS)
Loading...
Searching...
No Matches
event_aggregator.h
Go to the documentation of this file.
1#pragma once
2#include <functional>
3#include <stdexcept>
4
5#include "event_message.h"
6#include <memory>
7
8namespace hgps {
9
13
17 EventHandlerIdentifier(std::string identifier) : identifier_{identifier} {
18 if (identifier.empty()) {
19 throw std::invalid_argument("Event handler identifier must not be empty.");
20 }
21 }
22
25 const std::string str() const noexcept { return identifier_; }
26
30 auto operator<=>(const EventHandlerIdentifier &other) const = default;
31
32 private:
33 std::string identifier_;
34};
35
38 public:
40 EventSubscriber() = default;
41
46
48 virtual ~EventSubscriber() = default;
49
51 virtual void unsubscribe() const = 0;
52
55 [[nodiscard]] virtual EventHandlerIdentifier id() const noexcept = 0;
56};
57
60 public:
62 EventAggregator() = default;
63
66 EventAggregator(EventAggregator &&other) = default;
67
72
75
77 virtual ~EventAggregator() = default;
78
83 [[nodiscard]] virtual std::unique_ptr<EventSubscriber>
85 std::function<void(std::shared_ptr<EventMessage> message)> handler) = 0;
86
90 virtual bool unsubscribe(const EventSubscriber &subscriber) = 0;
91
94 virtual void publish(std::unique_ptr<EventMessage> message) const = 0;
95
98 virtual void publish_async(std::unique_ptr<EventMessage> message) const = 0;
99};
100
101} // namespace hgps
Defines the event aggregator interface type.
Definition event_aggregator.h:59
EventAggregator & operator=(const EventAggregator &)=delete
virtual bool unsubscribe(const EventSubscriber &subscriber)=0
Unsubscribes from an event notification.
EventAggregator(const EventAggregator &)=delete
EventAggregator & operator=(EventAggregator &&other)=default
Replaces the EventAggregator contents with the other using move semantics.
EventAggregator()=default
Initialises a new instance of the EventAggregator class.
virtual void publish_async(std::unique_ptr< EventMessage > message) const =0
Publishes a message to all subscribers asynchronous.
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.
virtual ~EventAggregator()=default
Destroys a EventAggregator instance.
EventAggregator(EventAggregator &&other)=default
Constructs the EventAggregator using move semantics.
virtual void publish(std::unique_ptr< EventMessage > message) const =0
Publishes a message to all subscribers synchronous.
Defines the event subscriber interface type.
Definition event_aggregator.h:37
EventSubscriber(const EventSubscriber &)=delete
EventSubscriber()=default
Initialises a new instance of the EventSubscriber class.
EventSubscriber & operator=(EventSubscriber &&)=delete
EventSubscriber(EventSubscriber &&)=delete
virtual ~EventSubscriber()=default
Destroys a EventSubscriber instance.
virtual EventHandlerIdentifier id() const noexcept=0
Gets the subscriber unique identifier.
EventSubscriber & operator=(const EventSubscriber &)=delete
virtual void unsubscribe() const =0
Unsubscribes from the event.
Top-level namespace for Health-GPS Console host application.
Definition command_options.cpp: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
auto operator<=>(const EventHandlerIdentifier &other) const =default
Compare this instance with other EventHandlerIdentifier instance.