|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
A singleton event broker for decoupling components within the Wavelength application. More...
#include <wavelength_event_broker.h>
Signals | |
| void | eventPublished (const QString &eventType, const QVariantMap &data) |
| Signal emitted whenever any event is published via PublishEvent(). Subscribed components connect to this signal and filter based on eventType. | |
Public Member Functions | |
| void | ActiveWavelengthChanged (const QString &frequency) |
| Publishes an "active_wavelength_changed" event. Data: {"frequency": QString}. | |
| void | AuthenticationFailed (const QString &frequency) |
| Publishes an "authentication_failed" event. Data: {"frequency": QString}. | |
| void | ConnectionError (const QString &error_message) |
| Publishes a "connection_error" event. Data: {"error": QString}. | |
| void | MessageReceived (const QString &frequency, const QString &message) |
| Publishes a "message_received" event. Data: {"frequency": QString, "message": QString}. | |
| void | MessageSent (const QString &frequency, const QString &message) |
| Publishes a "message_sent" event. Data: {"frequency": QString, "message": QString}. | |
| void | PublishEvent (const QString &event_type, const QVariantMap &data=QVariantMap()) |
| Publishes an event of a specific type with associated data. Emits the eventPublished signal, which subscribed components can connect to. | |
| template<typename Receiver, typename Func> requires std::derived_from<Receiver, QObject> && std::invocable<Func, const QVariantMap &> | |
| 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 is a QObject derivative and the slot is invocable with a const QVariantMap&. Connects the internal eventPublished signal to the receiver's slot, filtering by event_type. | |
| void | SystemMessage (const QString &frequency, const QString &message) |
| Publishes a "system_message" event. Data: {"frequency": QString, "message": QString}. | |
| void | UiStateChanged (const QString &component, const QVariant &state) |
| Publishes a "ui_state_changed" event. Data: {"component": QString, "state": QVariant}. | |
| void | UserKicked (const QString &frequency, const QString &reason) |
| Publishes a "user_kicked" event. Data: {"frequency": QString, "reason": QString}. | |
| void | WavelengthClosed (const QString &frequency) |
| Publishes a "wavelength_closed" event. Data: {"frequency": QString}. | |
| void | WavelengthCreated (const QString &frequency) |
| Publishes a "wavelength_created" event. Data: {"frequency": QString}. | |
| void | WavelengthJoined (const QString &frequency) |
| Publishes a "wavelength_joined" event. Data: {"frequency": QString}. | |
| void | WavelengthLeft (const QString &frequency) |
| Publishes a "wavelength_left" event. Data: {"frequency": QString}. | |
Static Public Member Functions | |
| static WavelengthEventBroker * | GetInstance () |
| Gets the singleton instance of the WavelengthEventBroker. | |
Private Member Functions | |
| WavelengthEventBroker & | operator= (const WavelengthEventBroker &)=delete |
| Deleted assignment operator to prevent assignment. | |
| WavelengthEventBroker (const WavelengthEventBroker &)=delete | |
| Deleted copy constructor to prevent copying. | |
| WavelengthEventBroker (QObject *parent=nullptr) | |
| Private constructor to enforce the singleton pattern. | |
| ~WavelengthEventBroker () override=default | |
| Private destructor. | |
A singleton event broker for decoupling components within the Wavelength application.
This class implements a publish-subscribe pattern using Qt's signals and slots. Various parts of the application can publish events (e.g., "wavelength_created", "message_received") with associated data (QVariantMap). Other components can subscribe to specific event types and react accordingly, without needing direct references to the publisher. This promotes loose coupling and modularity.
|
inlineexplicitprivate |
Private constructor to enforce the singleton pattern.
| parent | Optional parent QObject. |
|
overrideprivatedefault |
Private destructor.
|
privatedelete |
Deleted copy constructor to prevent copying.
| void WavelengthEventBroker::ActiveWavelengthChanged | ( | const QString & | frequency | ) |
Publishes an "active_wavelength_changed" event. Data: {"frequency": QString}.
| void WavelengthEventBroker::AuthenticationFailed | ( | const QString & | frequency | ) |
Publishes an "authentication_failed" event. Data: {"frequency": QString}.
| void WavelengthEventBroker::ConnectionError | ( | const QString & | error_message | ) |
Publishes a "connection_error" event. Data: {"error": QString}.
|
signal |
Signal emitted whenever any event is published via PublishEvent(). Subscribed components connect to this signal and filter based on eventType.
| eventType | The string identifier of the published event. |
| data | The QVariantMap containing data associated with the event. |
|
inlinestatic |
Gets the singleton instance of the WavelengthEventBroker.
| void WavelengthEventBroker::MessageReceived | ( | const QString & | frequency, |
| const QString & | message ) |
Publishes a "message_received" event. Data: {"frequency": QString, "message": QString}.
| void WavelengthEventBroker::MessageSent | ( | const QString & | frequency, |
| const QString & | message ) |
Publishes a "message_sent" event. Data: {"frequency": QString, "message": QString}.
|
privatedelete |
Deleted assignment operator to prevent assignment.
| void WavelengthEventBroker::PublishEvent | ( | const QString & | event_type, |
| const QVariantMap & | data = QVariantMap() ) |
Publishes an event of a specific type with associated data. Emits the eventPublished signal, which subscribed components can connect to.
| event_type | A string identifying the type of event (e.g., "message_received"). |
| data | Optional QVariantMap containing data associated with the event. |
| void WavelengthEventBroker::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 is a QObject derivative and the slot is invocable with a const QVariantMap&. Connects the internal eventPublished signal to the receiver's slot, filtering by event_type.
| Receiver | The type of the receiving object (must derive from QObject). |
| Func | The type of the slot/lambda function (must accept const QVariantMap&). |
| event_type | The string identifier of the event to subscribe to. |
| receiver | Pointer to the QObject instance that will receive the event. |
| slot | A pointer to a member function or a lambda function to be called when the event occurs. |
| void WavelengthEventBroker::SystemMessage | ( | const QString & | frequency, |
| const QString & | message ) |
Publishes a "system_message" event. Data: {"frequency": QString, "message": QString}.
| void WavelengthEventBroker::UiStateChanged | ( | const QString & | component, |
| const QVariant & | state ) |
Publishes a "ui_state_changed" event. Data: {"component": QString, "state": QVariant}.
| void WavelengthEventBroker::UserKicked | ( | const QString & | frequency, |
| const QString & | reason ) |
Publishes a "user_kicked" event. Data: {"frequency": QString, "reason": QString}.
| void WavelengthEventBroker::WavelengthClosed | ( | const QString & | frequency | ) |
Publishes a "wavelength_closed" event. Data: {"frequency": QString}.
| void WavelengthEventBroker::WavelengthCreated | ( | const QString & | frequency | ) |
Publishes a "wavelength_created" event. Data: {"frequency": QString}.
| void WavelengthEventBroker::WavelengthJoined | ( | const QString & | frequency | ) |
Publishes a "wavelength_joined" event. Data: {"frequency": QString}.
| void WavelengthEventBroker::WavelengthLeft | ( | const QString & | frequency | ) |
Publishes a "wavelength_left" event. Data: {"frequency": QString}.