Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
WavelengthEventBroker Class Referencefinal

A singleton event broker for decoupling components within the Wavelength application. More...

#include <wavelength_event_broker.h>

Inheritance diagram for WavelengthEventBroker:
Collaboration diagram for WavelengthEventBroker:

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 WavelengthEventBrokerGetInstance ()
 Gets the singleton instance of the WavelengthEventBroker.
 

Private Member Functions

WavelengthEventBrokeroperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ WavelengthEventBroker() [1/2]

WavelengthEventBroker::WavelengthEventBroker ( QObject * parent = nullptr)
inlineexplicitprivate

Private constructor to enforce the singleton pattern.

Parameters
parentOptional parent QObject.
Here is the caller graph for this function:

◆ ~WavelengthEventBroker()

WavelengthEventBroker::~WavelengthEventBroker ( )
overrideprivatedefault

Private destructor.

◆ WavelengthEventBroker() [2/2]

WavelengthEventBroker::WavelengthEventBroker ( const WavelengthEventBroker & )
privatedelete

Deleted copy constructor to prevent copying.

Here is the call graph for this function:

Member Function Documentation

◆ ActiveWavelengthChanged()

void WavelengthEventBroker::ActiveWavelengthChanged ( const QString & frequency)

Publishes an "active_wavelength_changed" event. Data: {"frequency": QString}.

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

◆ AuthenticationFailed()

void WavelengthEventBroker::AuthenticationFailed ( const QString & frequency)

Publishes an "authentication_failed" event. Data: {"frequency": QString}.

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

◆ ConnectionError()

void WavelengthEventBroker::ConnectionError ( const QString & error_message)

Publishes a "connection_error" event. Data: {"error": QString}.

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

◆ eventPublished

void WavelengthEventBroker::eventPublished ( const QString & eventType,
const QVariantMap & data )
signal

Signal emitted whenever any event is published via PublishEvent(). Subscribed components connect to this signal and filter based on eventType.

Parameters
eventTypeThe string identifier of the published event.
dataThe QVariantMap containing data associated with the event.
Here is the caller graph for this function:

◆ GetInstance()

static WavelengthEventBroker * WavelengthEventBroker::GetInstance ( )
inlinestatic

Gets the singleton instance of the WavelengthEventBroker.

Returns
Pointer to the singleton WavelengthEventBroker instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MessageReceived()

void WavelengthEventBroker::MessageReceived ( const QString & frequency,
const QString & message )

Publishes a "message_received" event. Data: {"frequency": QString, "message": QString}.

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

◆ MessageSent()

void WavelengthEventBroker::MessageSent ( const QString & frequency,
const QString & message )

Publishes a "message_sent" event. Data: {"frequency": QString, "message": QString}.

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

◆ operator=()

WavelengthEventBroker & WavelengthEventBroker::operator= ( const WavelengthEventBroker & )
privatedelete

Deleted assignment operator to prevent assignment.

Here is the call graph for this function:

◆ PublishEvent()

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.

Parameters
event_typeA string identifying the type of event (e.g., "message_received").
dataOptional QVariantMap containing data associated with the event.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SubscribeToEvent()

template<typename Receiver, typename Func>
requires std::derived_from<Receiver, QObject> && std::invocable<Func, const QVariantMap &>
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.

Template Parameters
ReceiverThe type of the receiving object (must derive from QObject).
FuncThe type of the slot/lambda function (must accept const QVariantMap&).
Parameters
event_typeThe string identifier of the event to subscribe to.
receiverPointer to the QObject instance that will receive the event.
slotA pointer to a member function or a lambda function to be called when the event occurs.
Here is the call graph for this function:

◆ SystemMessage()

void WavelengthEventBroker::SystemMessage ( const QString & frequency,
const QString & message )

Publishes a "system_message" event. Data: {"frequency": QString, "message": QString}.

Here is the call graph for this function:

◆ UiStateChanged()

void WavelengthEventBroker::UiStateChanged ( const QString & component,
const QVariant & state )

Publishes a "ui_state_changed" event. Data: {"component": QString, "state": QVariant}.

Here is the call graph for this function:

◆ UserKicked()

void WavelengthEventBroker::UserKicked ( const QString & frequency,
const QString & reason )

Publishes a "user_kicked" event. Data: {"frequency": QString, "reason": QString}.

Here is the call graph for this function:

◆ WavelengthClosed()

void WavelengthEventBroker::WavelengthClosed ( const QString & frequency)

Publishes a "wavelength_closed" event. Data: {"frequency": QString}.

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

◆ WavelengthCreated()

void WavelengthEventBroker::WavelengthCreated ( const QString & frequency)

Publishes a "wavelength_created" event. Data: {"frequency": QString}.

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

◆ WavelengthJoined()

void WavelengthEventBroker::WavelengthJoined ( const QString & frequency)

Publishes a "wavelength_joined" event. Data: {"frequency": QString}.

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

◆ WavelengthLeft()

void WavelengthEventBroker::WavelengthLeft ( const QString & frequency)

Publishes a "wavelength_left" event. Data: {"frequency": QString}.

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

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