Singleton class responsible for handling WebSocket message operations.
More...
#include <message_handler.h>
|
| void | ClearProcessedMessages () |
| | Clears the internal cache of processed message IDs.
|
| |
| bool | IsMessageProcessed (const QString &message_id) const |
| | Checks if a message with the given ID has already been processed.
|
| |
| void | MarkMessageAsProcessed (const QString &message_id) |
| | Marks a message ID as processed by adding it to the internal set. Also manages the size of the processed ID cache, removing older entries if the maximum size is exceeded.
|
| |
|
| static QJsonObject | CreateAuthRequest (const QString &frequency, const QString &password, const QString &client_id) |
| | Creates a JSON object representing an authentication request.
|
| |
| static QJsonObject | CreateLeaveRequest (const QString &frequency, bool is_host) |
| | Creates a JSON object representing a request to leave or close a frequency.
|
| |
| static QJsonObject | CreateRegisterRequest (const QString &frequency, bool is_password_protected, const QString &password, const QString &host_id) |
| | Creates a JSON object representing a request to register a new frequency.
|
| |
| static QString | GenerateMessageId () |
| | Generates a unique message identifier using UUID.
|
| |
| static MessageHandler * | GetInstance () |
| | Gets the singleton instance of the MessageHandler.
|
| |
| static QString | GetMessageContent (const QJsonObject &message_object) |
| | Extracts the message content string from a parsed message object.
|
| |
| static QString | GetMessageFrequency (const QJsonObject &message_object) |
| | Extracts the frequency string from a parsed message object.
|
| |
| static QString | GetMessageId (const QJsonObject &message_object) |
| | Extracts the message ID string from a parsed message object.
|
| |
| static QString | GetMessageSenderId (const QJsonObject &message_object) |
| | Extracts the sender ID string from a parsed message object.
|
| |
| static QString | GetMessageType (const QJsonObject &message_object) |
| | Extracts the message type string from a parsed message object.
|
| |
| static QJsonObject | ParseMessage (const QString &message, bool *ok=nullptr) |
| | Parses a JSON string message into a QJsonObject.
|
| |
| static bool | SendSystemCommand (QWebSocket *socket, const QString &command, const QJsonObject ¶ms=QJsonObject()) |
| | Sends a JSON-formatted system command over the specified WebSocket. Constructs a JSON object with the given command type and parameters, converts it to a JSON string, and sends it as a text message.
|
| |
|
| QSet< QString > | processed_message_ids_ |
| | Set storing the IDs of messages that have already been processed to prevent duplicates.
|
| |
|
| static constexpr int | kMaxCachedMessageIds = 200 |
| | Maximum number of message IDs to keep in the processed cache before removing older ones.
|
| |
Singleton class responsible for handling WebSocket message operations.
Provides static methods for creating, parsing, and extracting information from JSON-based messages used in the WebSocket communication protocol. It also manages to send system commands and keeps track of processed message IDs to prevent duplicates.
◆ MessageHandler() [1/2]
| MessageHandler::MessageHandler |
( |
QObject * | parent = nullptr | ) |
|
|
inlineexplicitprivate |
Private constructor to enforce the singleton pattern.
- Parameters
-
| parent | Optional parent QObject. |
◆ ~MessageHandler()
| MessageHandler::~MessageHandler |
( |
| ) |
|
|
overrideprivatedefault |
◆ MessageHandler() [2/2]
Deleted copy constructor to prevent copying.
◆ ClearProcessedMessages()
| void MessageHandler::ClearProcessedMessages |
( |
| ) |
|
|
inline |
Clears the internal cache of processed message IDs.
◆ CreateAuthRequest()
| QJsonObject MessageHandler::CreateAuthRequest |
( |
const QString & | frequency, |
|
|
const QString & | password, |
|
|
const QString & | client_id ) |
|
static |
Creates a JSON object representing an authentication request.
- Parameters
-
| frequency | The frequency the client wants to join. |
| password | The password for the frequency (if required). |
| client_id | The unique identifier of the client sending the request. |
- Returns
- A QJsonObject formatted as an authentication request.
◆ CreateLeaveRequest()
| QJsonObject MessageHandler::CreateLeaveRequest |
( |
const QString & | frequency, |
|
|
bool | is_host ) |
|
static |
Creates a JSON object representing a request to leave or close a frequency.
- Parameters
-
| frequency | The frequency to leave or close. |
| is_host | True if the client is the host (closing the frequency), false otherwise (leaving). |
- Returns
- A QJsonObject formatted as a leave or close request.
◆ CreateRegisterRequest()
| QJsonObject MessageHandler::CreateRegisterRequest |
( |
const QString & | frequency, |
|
|
bool | is_password_protected, |
|
|
const QString & | password, |
|
|
const QString & | host_id ) |
|
static |
Creates a JSON object representing a request to register a new frequency.
- Parameters
-
| frequency | The desired name for the new frequency. |
| is_password_protected | Flag indicating if the frequency should require a password. |
| password | The password to set for the frequency (if protected). |
| host_id | The unique identifier of the client hosting the frequency. |
- Returns
- A QJsonObject formatted as a frequency registration request.
◆ GenerateMessageId()
| static QString MessageHandler::GenerateMessageId |
( |
| ) |
|
|
inlinestatic |
Generates a unique message identifier using UUID.
- Returns
- A unique QString identifier (UUID without braces).
◆ GetInstance()
◆ GetMessageContent()
| static QString MessageHandler::GetMessageContent |
( |
const QJsonObject & | message_object | ) |
|
|
inlinestatic |
Extracts the message content string from a parsed message object.
- Parameters
-
| message_object | The QJsonObject representing the parsed message. |
- Returns
- The value of the "content" field as a QString.
◆ GetMessageFrequency()
| static QString MessageHandler::GetMessageFrequency |
( |
const QJsonObject & | message_object | ) |
|
|
inlinestatic |
Extracts the frequency string from a parsed message object.
- Parameters
-
| message_object | The QJsonObject representing the parsed message. |
- Returns
- The value of the "frequency" field as a QString.
◆ GetMessageId()
| static QString MessageHandler::GetMessageId |
( |
const QJsonObject & | message_object | ) |
|
|
inlinestatic |
Extracts the message ID string from a parsed message object.
- Parameters
-
| message_object | The QJsonObject representing the parsed message. |
- Returns
- The value of the "messageId" field as a QString.
◆ GetMessageSenderId()
| static QString MessageHandler::GetMessageSenderId |
( |
const QJsonObject & | message_object | ) |
|
|
inlinestatic |
Extracts the sender ID string from a parsed message object.
- Parameters
-
| message_object | The QJsonObject representing the parsed message. |
- Returns
- The value of the "senderId" field as a QString.
◆ GetMessageType()
| static QString MessageHandler::GetMessageType |
( |
const QJsonObject & | message_object | ) |
|
|
inlinestatic |
Extracts the message type string from a parsed message object.
- Parameters
-
| message_object | The QJsonObject representing the parsed message. |
- Returns
- The value of the "type" field as a QString.
◆ IsMessageProcessed()
| bool MessageHandler::IsMessageProcessed |
( |
const QString & | message_id | ) |
const |
|
inline |
Checks if a message with the given ID has already been processed.
- Parameters
-
| message_id | The unique identifier of the message to check. |
- Returns
- True if the message ID exists in the processed set, false otherwise.
◆ MarkMessageAsProcessed()
| void MessageHandler::MarkMessageAsProcessed |
( |
const QString & | message_id | ) |
|
Marks a message ID as processed by adding it to the internal set. Also manages the size of the processed ID cache, removing older entries if the maximum size is exceeded.
- Parameters
-
| message_id | The unique identifier of the message to mark as processed. |
◆ operator=()
Deleted assignment operator to prevent assignment.
◆ ParseMessage()
| QJsonObject MessageHandler::ParseMessage |
( |
const QString & | message, |
|
|
bool * | ok = nullptr ) |
|
static |
Parses a JSON string message into a QJsonObject.
- Parameters
-
| message | The QString containing the JSON message data. |
| ok | Optional pointer to a boolean flag that will be set to true on success, false on failure. |
- Returns
- The parsed QJsonObject on success, or an empty QJsonObject on failure.
◆ SendSystemCommand()
| bool MessageHandler::SendSystemCommand |
( |
QWebSocket * | socket, |
|
|
const QString & | command, |
|
|
const QJsonObject & | params = QJsonObject() ) |
|
static |
Sends a JSON-formatted system command over the specified WebSocket. Constructs a JSON object with the given command type and parameters, converts it to a JSON string, and sends it as a text message.
- Parameters
-
| socket | Pointer to the QWebSocket to send the command through. |
| command | The type string for the command (e.g., "auth", "register_wavelength"). |
| params | Optional QJsonObject containing additional parameters for the command. |
- Returns
- True if the command was sent successfully (socket valid), false otherwise.
◆ kMaxCachedMessageIds
| int MessageHandler::kMaxCachedMessageIds = 200 |
|
staticconstexprprivate |
Maximum number of message IDs to keep in the processed cache before removing older ones.
◆ processed_message_ids_
| QSet<QString> MessageHandler::processed_message_ids_ |
|
private |
Set storing the IDs of messages that have already been processed to prevent duplicates.
The documentation for this class was generated from the following files: