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 loggedIn ()
 
void disconnected ()
 
void reconnecting ()
 
void reconnected ()
 
void connectionError (const QString &message)
 
void notificationReceived (const QString &eventType, const QDateTime &timestamp, const QStringList &entityIds)
 Emitted when a notification is received from the server.
 
void recordingStarted (const QString &filePath)
 Emitted when session recording starts.
 
void recordingStopped ()
 Emitted when session recording stops.
 
void streamingStarted ()
 Emitted when telemetry streaming starts.
 
void streamingStopped ()
 Emitted when telemetry streaming stops.
 

Public Member Functions

 ClientManager (std::shared_ptr< eventing::service::event_bus > event_bus, QObject *parent=nullptr)
 
LoginResult connect (const std::string &host, std::uint16_t port)
 Connect to the server without logging in.
 
LoginResult login (const std::string &username, const std::string &password)
 Login on an already connected client.
 
LoginResult connectAndLogin (const std::string &host, std::uint16_t port, const std::string &username, const std::string &password)
 Connect to the server and perform login.
 
LoginResult testConnection (const std::string &host, std::uint16_t port, const std::string &username, const std::string &password)
 Test a connection without affecting main client state.
 
SignupResult signup (const std::string &host, std::uint16_t port, const std::string &username, const std::string &email, const std::string &password)
 Connect to the server and attempt signup.
 
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.
 
bool isAdmin () const
 Check if the logged-in user has admin privileges.
 
bool isLoggedIn () const
 Check if currently logged in.
 
std::string currentUsername () const
 Get the current logged-in user's username.
 
std::string currentEmail () const
 Get the current logged-in user's email.
 
void setCurrentEmail (const std::string &email)
 Set the current logged-in user's email.
 
std::optional< boost::uuids::uuid > accountId () const
 Get the account ID if logged in.
 
std::string serverAddress () const
 Get the server address string.
 
std::string connectedHost () const
 Get the connected server hostname.
 
std::uint16_t connectedPort () const
 Get the connected server port.
 
std::expected< comms::messaging::frame, ores::utility::serialization::error_code > sendRequest (comms::messaging::frame request)
 Send a request if connected.
 
template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_request (RequestType request)
 Process a request that does not require authentication.
 
template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_authenticated_request (RequestType request)
 Process a request that requires authentication.
 
template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_admin_request (RequestType request)
 Process a request that requires admin privileges.
 
comms::net::client_sessionsession ()
 Get the underlying client session.
 
std::optional< SessionListResultlistSessions (const boost::uuids::uuid &accountId, std::uint32_t limit=100, std::uint32_t offset=0)
 List sessions for an account.
 
std::optional< std::vector< iam::domain::session > > getActiveSessions ()
 Get active sessions for the current user.
 
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.
 
bool enableRecording (const std::filesystem::path &outputDirectory)
 Enable session recording to the specified directory.
 
void disableRecording ()
 Disable session recording.
 
bool isRecording () const
 Check if session recording is currently active.
 
std::filesystem::path recordingFilePath () const
 Get the path to the current recording file.
 
void setRecordingDirectory (const std::filesystem::path &directory)
 Set the recording output directory.
 
std::filesystem::path recordingDirectory () const
 Get the current recording output directory.
 
void enableStreaming (const comms::service::telemetry_streaming_options &options)
 Enable telemetry streaming to the server.
 
void disableStreaming ()
 Disable telemetry streaming.
 
bool isStreaming () const
 Check if telemetry streaming is currently active.
 
std::size_t streamingPendingCount () const
 Get the number of pending telemetry records.
 
std::uint64_t streamingTotalSent () const
 Get total telemetry records sent successfully.
 
std::uint64_t streamingTotalDropped () const
 Get total telemetry records dropped.
 

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

◆ connect()

LoginResult connect ( const std::string &  host,
std::uint16_t  port 
)

Connect to the server without logging in.

Establishes a connection and checks bootstrap status. If the system is in bootstrap mode, returns with bootstrap_mode=true and the client remains connected (but not logged in). Otherwise, the client is connected and ready for a login() call.

Parameters
hostServer hostname
portServer port
Returns
LoginResult with bootstrap_mode=true if in bootstrap mode, success=true if connected and ready for login, or success=false with error_message on failure

◆ login()

LoginResult login ( const std::string &  username,
const std::string &  password 
)

Login on an already connected client.

Assumes the client is already connected via connect(). Sets up session info, stores credentials for reconnection, and emits the loggedIn signal.

Parameters
usernameLogin username
passwordLogin password
Returns
LoginResult containing success status, error message, and password_reset_required flag

◆ connectAndLogin()

LoginResult connectAndLogin ( const std::string &  host,
std::uint16_t  port,
const std::string &  username,
const std::string &  password 
)

Connect to the server and perform login.

Convenience method that calls connect() followed by login(). If bootstrap mode is detected, returns early with bootstrap_mode=true.

Parameters
hostServer hostname
portServer port
usernameLogin username
passwordLogin password
Returns
LoginResult containing success status, error message, and password_reset_required flag

◆ testConnection()

LoginResult testConnection ( const std::string &  host,
std::uint16_t  port,
const std::string &  username,
const std::string &  password 
)

Test a connection without affecting main client state.

Creates a temporary connection to verify credentials. Does not modify the main connection, emit signals, or publish events. Use this for testing saved connections from dialogs.

Parameters
hostServer hostname
portServer port
usernameLogin username
passwordLogin password
Returns
LoginResult containing success status and error message

◆ signup()

SignupResult signup ( const std::string &  host,
std::uint16_t  port,
const std::string &  username,
const std::string &  email,
const std::string &  password 
)

Connect to the server and attempt signup.

Creates a temporary connection to register a new user account. Does not establish a persistent connection or log in the user. The connection is closed after the signup attempt completes.

Parameters
hostServer hostname
portServer port
usernameDesired username
emailUser's email address
passwordDesired password
Returns
SignupResult containing success status and error message if failed

◆ 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

◆ isAdmin()

bool isAdmin ( ) const

Check if the logged-in user has admin privileges.

Deprecated:
Permission checks are now performed server-side via RBAC. This method always returns false.
Returns
Always returns false. Use server-side permission checks instead.

◆ isLoggedIn()

bool isLoggedIn ( ) const

Check if currently logged in.

Returns
true if logged in, false otherwise.

◆ currentUsername()

std::string currentUsername ( ) const

Get the current logged-in user's username.

Returns
Username string, or empty if not logged in.

◆ currentEmail()

std::string currentEmail ( ) const

Get the current logged-in user's email.

Returns
Email string, or empty if not logged in or not set.

◆ setCurrentEmail()

void setCurrentEmail ( const std::string &  email)

Set the current logged-in user's email.

Used after successful email update to keep local state in sync.

◆ accountId()

std::optional< boost::uuids::uuid > accountId ( ) const

Get the account ID if logged in.

Returns
Account UUID if logged in, nullopt otherwise.

◆ serverAddress()

std::string serverAddress ( ) const

Get the server address string.

Returns
Server address in "host:port" format, or empty if not connected.

◆ connectedHost()

std::string connectedHost ( ) const

Get the connected server hostname.

Returns
Server hostname, or empty if not connected.

◆ connectedPort()

std::uint16_t connectedPort ( ) const

Get the connected server port.

Returns
Server port, or 0 if not connected.

◆ sendRequest()

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

Send a request if connected.

Parameters
requestThe request frame to send
Returns
Response frame or error code
Deprecated:
Use typed process_request methods instead

◆ process_request()

template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_request ( RequestType  request)

Process a request that does not require authentication.

Uses message_traits to automatically determine the response type.

Template Parameters
RequestTypeRequest message type (must have message_traits)
Parameters
requestThe request to send
Returns
Response on success, error on failure

◆ process_authenticated_request()

template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_authenticated_request ( RequestType  request)

Process a request that requires authentication.

Checks if logged in before sending.

Template Parameters
RequestTypeRequest message type (must have message_traits)
Parameters
requestThe request to send
Returns
Response on success, error on failure (including not_logged_in)

◆ process_admin_request()

template<typename RequestType >
requires comms::messaging::has_message_traits<RequestType>
auto process_admin_request ( RequestType  request)

Process a request that requires admin privileges.

Checks if logged in as admin before sending.

Template Parameters
RequestTypeRequest message type (must have message_traits)
Parameters
requestThe request to send
Returns
Response on success, error on failure

◆ session()

Get the underlying client session.

Provides access to the session for advanced use cases.

◆ listSessions()

std::optional< SessionListResult > listSessions ( const boost::uuids::uuid &  accountId,
std::uint32_t  limit = 100,
std::uint32_t  offset = 0 
)

List sessions for an account.

Parameters
accountIdThe account UUID (nil for own sessions)
limitMaximum sessions to return
offsetPagination offset
Returns
Session list result or nullopt on error

◆ getActiveSessions()

std::optional< std::vector< iam::domain::session > > getActiveSessions ( )

Get active sessions for the current user.

Returns
List of active sessions or nullopt on error

◆ 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.refdata.currency_changed_event")

◆ 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)

◆ enableRecording()

bool enableRecording ( const std::filesystem::path &  outputDirectory)

Enable session recording to the specified directory.

Creates a new session recording file in the specified directory. Recording can be enabled before or after connecting. If enabled before connecting, recording will start when the connection is established.

Parameters
outputDirectoryDirectory where session files will be created
Returns
true if recording was enabled, false on error

◆ disableRecording()

void disableRecording ( )

Disable session recording.

Stops recording and closes the session file. Safe to call when not recording.

◆ recordingFilePath()

std::filesystem::path recordingFilePath ( ) const

Get the path to the current recording file.

Returns
File path if recording, empty path otherwise.

◆ setRecordingDirectory()

void setRecordingDirectory ( const std::filesystem::path &  directory)

Set the recording output directory.

This directory is used when enableRecording() is called without a directory argument, or when auto-recording is enabled.

Parameters
directoryThe default output directory for recordings

◆ enableStreaming()

void enableStreaming ( const comms::service::telemetry_streaming_options options)

Enable telemetry streaming to the server.

Streaming can be enabled before or after connecting. If enabled before connecting, streaming will start when the connection is established.

Parameters
optionsStreaming options (batch size, flush interval, etc.)

◆ disableStreaming()

void disableStreaming ( )

Disable telemetry streaming.

Stops streaming and flushes any pending logs. Safe to call when not streaming.

◆ streamingPendingCount()

std::size_t streamingPendingCount ( ) const

Get the number of pending telemetry records.

Returns
Number of records waiting to be sent

◆ notificationReceived

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

Emitted when a notification is received from the server.

Parameters
eventTypeThe event type name (e.g., "ores.refdata.currency_changed_event")
timestampWhen the event occurred
entityIdsIdentifiers of entities that changed (e.g., currency ISO codes)

◆ recordingStarted

void recordingStarted ( const QString &  filePath)
signal

Emitted when session recording starts.

Parameters
filePathPath to the recording file