ORE Studio 0.0.4
Loading...
Searching...
No Matches
Signals | Public Member Functions | List of all members
ClientManager Class Reference

Manages the lifecycle of the network client and IO context. More...

#include <ClientManager.hpp>

Inherits QObject.

Collaboration diagram for ClientManager:
Collaboration graph

Signals

void connected ()
 
void disconnected ()
 
void reconnecting ()
 
void reconnected ()
 
void connectionError (const QString &message)
 
void notificationReceived (const QString &eventType, const QDateTime &timestamp)
 Emitted when a notification is received from the server.
 

Public Member Functions

 ClientManager (std::shared_ptr< eventing::service::event_bus > event_bus, QObject *parent=nullptr)
 
std::pair< bool, QString > connectAndLogin (const std::string &host, std::uint16_t port, const std::string &username, const std::string &password)
 Connect to the server and perform login.
 
void disconnect ()
 Logout the current user and disconnect from the server.
 
bool logout ()
 Logout the current user without disconnecting.
 
bool isConnected () const
 Check if currently connected.
 
std::expected< comms::messaging::frame, comms::messaging::error_code > sendRequest (comms::messaging::frame request)
 Send a request if connected.
 
std::shared_ptr< comms::net::clientgetClient () const
 Get the current client (internal use only).
 
boost::asio::any_io_executor getExecutor ()
 Get the IO context executor.
 
void subscribeToEvent (const std::string &eventType)
 Subscribe to server-push notifications for an event type.
 
void unsubscribeFromEvent (const std::string &eventType)
 Unsubscribe from server-push notifications for an event type.
 
void setSupportedCompression (std::uint8_t compression)
 Set the supported compression bitmask for client connections.
 

Detailed Description

Manages the lifecycle of the network client and IO context.

Maintains a persistent IO context/thread while allowing the client connection to be established and torn down repeatedly. Signals changes in connection state to allow UI components to update accordingly without closing.

Member Function Documentation

◆ connectAndLogin()

std::pair< bool, QString > connectAndLogin ( const std::string &  host,
std::uint16_t  port,
const std::string &  username,
const std::string &  password 
)

Connect to the server and perform login.

Parameters
hostServer hostname
portServer port
usernameLogin username
passwordLogin password
Returns
std::pair<bool, QString> Success status and error message

◆ disconnect()

void disconnect ( )

Logout the current user and disconnect from the server.

Sends a logout request to mark the user as offline before disconnecting.

◆ logout()

bool logout ( )

Logout the current user without disconnecting.

Sends a logout request to the server to mark the user as offline.

Returns
true if logout was successful, false otherwise

◆ sendRequest()

std::expected< comms::messaging::frame, comms::messaging::error_code > sendRequest ( comms::messaging::frame  request)

Send a request if connected.

Parameters
requestThe request frame to send
Returns
Response frame or error code

◆ subscribeToEvent()

void subscribeToEvent ( const std::string &  eventType)

Subscribe to server-push notifications for an event type.

This method is non-blocking - the subscription request is sent asynchronously and any errors are logged.

Parameters
eventTypeThe event type to subscribe to (e.g., "ores.risk.currency_changed_event")
Here is the caller graph for this function:

◆ unsubscribeFromEvent()

void unsubscribeFromEvent ( const std::string &  eventType)

Unsubscribe from server-push notifications for an event type.

This method is non-blocking - the unsubscription request is sent asynchronously and any errors are logged.

Parameters
eventTypeThe event type to unsubscribe from
Here is the caller graph for this function:

◆ setSupportedCompression()

void setSupportedCompression ( std::uint8_t  compression)

Set the supported compression bitmask for client connections.

Should be called before connectAndLogin(). The value is used when creating client_options for the handshake negotiation.

Parameters
compressionBitmask of supported compression types (0 = disabled)

◆ notificationReceived

void notificationReceived ( const QString &  eventType,
const QDateTime &  timestamp 
)
signal

Emitted when a notification is received from the server.

Parameters
eventTypeThe event type name (e.g., "ores.risk.currency_changed_event")
timestampWhen the event occurred
Here is the caller graph for this function: