Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
wavelength_event_broker.h
Go to the documentation of this file.
1#ifndef WAVELENGTH_EVENT_BROKER_H
2#define WAVELENGTH_EVENT_BROKER_H
3
4#include <QMap>
5#include <QObject>
6
16class WavelengthEventBroker final : public QObject {
17 Q_OBJECT
18
19public:
25 static WavelengthEventBroker instance;
26 return &instance;
27 }
28
35 void PublishEvent(const QString &event_type, const QVariantMap &data = QVariantMap());
36
48 template<typename Receiver, typename Func>
49 requires std::derived_from<Receiver, QObject> &&
50 std::invocable<Func, const QVariantMap &>
51 void SubscribeToEvent(const QString &event_type, Receiver *receiver, Func slot);
52
54 void WavelengthCreated(const QString &frequency);
55
57 void WavelengthJoined(const QString &frequency);
58
60 void WavelengthLeft(const QString &frequency);
61
63 void WavelengthClosed(const QString &frequency);
64
66 void MessageReceived(const QString &frequency, const QString &message);
67
69 void MessageSent(const QString &frequency, const QString &message);
70
72 void ConnectionError(const QString &error_message);
73
75 void AuthenticationFailed(const QString &frequency);
76
78 void UserKicked(const QString &frequency, const QString &reason);
79
81 void UiStateChanged(const QString &component, const QVariant &state);
82
84 void SystemMessage(const QString &frequency, const QString &message);
85
87 void ActiveWavelengthChanged(const QString &frequency);
88
89signals:
96 void eventPublished(const QString &eventType, const QVariantMap &data);
97
98private:
103 explicit WavelengthEventBroker(QObject *parent = nullptr) : QObject(parent) {
104 }
105
109 ~WavelengthEventBroker() override = default;
110
115
120};
121#endif // WAVELENGTH_EVENT_BROKER_H
void WavelengthClosed(const QString &frequency)
Publishes a "wavelength_closed" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:41
void WavelengthLeft(const QString &frequency)
Publishes a "wavelength_left" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:35
WavelengthEventBroker & operator=(const WavelengthEventBroker &)=delete
Deleted assignment operator to prevent assignment.
void UserKicked(const QString &frequency, const QString &reason)
Publishes a "user_kicked" event. Data: {"frequency": QString, "reason": QString}.
Definition wavelength_event_broker.cpp:73
void AuthenticationFailed(const QString &frequency)
Publishes an "authentication_failed" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:67
void MessageSent(const QString &frequency, const QString &message)
Publishes a "message_sent" event. Data: {"frequency": QString, "message": QString}...
Definition wavelength_event_broker.cpp:54
void WavelengthJoined(const QString &frequency)
Publishes a "wavelength_joined" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:29
void ActiveWavelengthChanged(const QString &frequency)
Publishes an "active_wavelength_changed" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:94
void WavelengthCreated(const QString &frequency)
Publishes a "wavelength_created" event. Data: {"frequency": QString}.
Definition wavelength_event_broker.cpp:23
void ConnectionError(const QString &error_message)
Publishes a "connection_error" event. Data: {"error": QString}.
Definition wavelength_event_broker.cpp:61
WavelengthEventBroker(const WavelengthEventBroker &)=delete
Deleted copy constructor to prevent copying.
WavelengthEventBroker(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern.
Definition wavelength_event_broker.h:103
void UiStateChanged(const QString &component, const QVariant &state)
Publishes a "ui_state_changed" event. Data: {"component": QString, "state": QVariant}...
Definition wavelength_event_broker.cpp:80
static WavelengthEventBroker * GetInstance()
Gets the singleton instance of the WavelengthEventBroker.
Definition wavelength_event_broker.h:24
void PublishEvent(const QString &event_type, const QVariantMap &data=QVariantMap())
Publishes an event of a specific type with associated data. Emits the eventPublished signal,...
Definition wavelength_event_broker.cpp:18
void MessageReceived(const QString &frequency, const QString &message)
Publishes a "message_received" event. Data: {"frequency": QString, "message": QString}...
Definition wavelength_event_broker.cpp:47
void SubscribeToEvent(const QString &event_type, Receiver *receiver, Func slot)
Subscribes a receiver object's slot to a specific event type. Uses a template to ensure the receiver ...
Definition wavelength_event_broker.cpp:9
void eventPublished(const QString &eventType, const QVariantMap &data)
Signal emitted whenever any event is published via PublishEvent(). Subscribed components connect to t...
~WavelengthEventBroker() override=default
Private destructor.
void SystemMessage(const QString &frequency, const QString &message)
Publishes a "system_message" event. Data: {"frequency": QString, "message": QString}...
Definition wavelength_event_broker.cpp:87