ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
client_session Class Referencefinal

Client-side session manager providing auth-aware request handling. More...

#include <client_session.hpp>

Collaboration diagram for client_session:
Collaboration graph

Public Member Functions

 client_session (const client_session &)=delete
 
client_sessionoperator= (const client_session &)=delete
 
 client_session (client_session &&)=delete
 
client_sessionoperator= (client_session &&)=delete
 
std::expected< void, session_errorconnect (client_options options)
 Connect to the server.
 
void disconnect ()
 Disconnect from the server.
 
bool is_connected () const noexcept
 Check if connected to server.
 
bool is_logged_in () const noexcept
 Check if logged in.
 
void set_session_info (client_session_info info)
 Set session info after successful login.
 
void clear_session_info () noexcept
 Clear session info on logout.
 
bool is_admin () const noexcept
 Check if logged in as admin.
 
const std::optional< client_session_info > & session_info () const noexcept
 Get current session info if logged in.
 
template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_errorprocess_request (RequestType request)
 Process a request that does not require authentication.
 
template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_errorprocess_authenticated_request (RequestType request)
 Process a request that requires authentication.
 
template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_errorprocess_admin_request (RequestType request)
 Process a request that requires admin privileges.
 
template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_errorprocess_request (RequestType request)
 Process a request using message_traits (does not require auth).
 
template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_errorprocess_authenticated_request (RequestType request)
 Process a request using message_traits (requires authentication).
 
template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_errorprocess_admin_request (RequestType request)
 Process a request using message_traits (requires admin).
 
bool subscribe (const std::string &event_type)
 Subscribe to notifications for an event type.
 
bool unsubscribe (const std::string &event_type)
 Unsubscribe from notifications for an event type.
 
bool is_subscribed (const std::string &event_type) const
 Check if currently subscribed to an event type.
 
std::set< std::string > get_subscriptions () const
 Get the set of currently subscribed event types.
 
std::vector< pending_notificationtake_pending_notifications ()
 Get all pending notifications and clear the queue.
 
bool has_pending_notifications () const
 Check if there are any pending notifications.
 

Detailed Description

Client-side session manager providing auth-aware request handling.

This class wraps a net::client and provides:

Designed to be shared between ores.shell and ores.qt clients.

Member Function Documentation

◆ connect()

std::expected< void, session_error > connect ( client_options  options)

Connect to the server.

Parameters
optionsConnection options
Returns
Empty expected on success, error on failure
Here is the caller graph for this function:

◆ disconnect()

void disconnect ( )

Disconnect from the server.

Will logout first if logged in.

Here is the caller graph for this function:

◆ set_session_info()

void set_session_info ( client_session_info  info)

Set session info after successful login.

Called by the application layer after processing a login response.

Parameters
infoSession information from login response
Here is the caller graph for this function:

◆ clear_session_info()

void clear_session_info ( )
noexcept

Clear session info on logout.

Called by the application layer after logout or disconnect.

Here is the caller graph for this function:

◆ process_request() [1/2]

template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_error > process_request ( RequestType  request)

Process a request that does not require authentication.

Use this for messages like bootstrap_status_request that don't need login.

Template Parameters
RequestTypeRequest message type (must be Serializable)
ResponseTypeResponse message type (must be Deserializable)
RequestMsgTypeThe message_type enum value for the request
Parameters
requestThe request to send
Returns
Response on success, error on failure
Here is the caller graph for this function:

◆ process_authenticated_request() [1/2]

template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_error > process_authenticated_request ( RequestType  request)

Process a request that requires authentication.

Checks if logged in before sending. Use this for most requests.

Template Parameters
RequestTypeRequest message type (must be Serializable)
ResponseTypeResponse message type (must be Deserializable)
RequestMsgTypeThe message_type enum value for the request
Parameters
requestThe request to send
Returns
Response on success, error on failure (including not_logged_in)
Here is the caller graph for this function:

◆ process_admin_request() [1/2]

template<Serializable RequestType, Deserializable ResponseType, messaging::message_type RequestMsgType>
std::expected< ResponseType, session_error > 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 be Serializable)
ResponseTypeResponse message type (must be Deserializable)
RequestMsgTypeThe message_type enum value for the request
Parameters
requestThe request to send
Returns
Response on success, error on failure (including not_logged_in, admin_required)
Here is the caller graph for this function:

◆ process_request() [2/2]

template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_error > process_request ( RequestType  request)

Process a request using message_traits (does not require auth).

Uses message_traits to automatically determine the response type and message_type enum value from the request 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() [2/2]

template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_error > process_authenticated_request ( RequestType  request)

Process a request using message_traits (requires authentication).

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

◆ process_admin_request() [2/2]

template<typename RequestType >
requires messaging::has_message_traits<RequestType>
std::expected< typename messaging::message_traits< RequestType >::response_type, session_error > process_admin_request ( RequestType  request)

Process a request using message_traits (requires admin).

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

◆ subscribe()

bool subscribe ( const std::string &  event_type)

Subscribe to notifications for an event type.

Delegates to remote_event_adapter to send a SUBSCRIBE protocol message. Received notifications are queued for retrieval via take_pending_notifications().

Parameters
event_typeThe fully qualified event type name (e.g., "ores.risk.currency_changed")
Returns
True if subscription succeeded, false otherwise
Here is the caller graph for this function:

◆ unsubscribe()

bool unsubscribe ( const std::string &  event_type)

Unsubscribe from notifications for an event type.

Delegates to remote_event_adapter to send an UNSUBSCRIBE protocol message.

Parameters
event_typeThe fully qualified event type name
Returns
True if unsubscription succeeded, false otherwise
Here is the caller graph for this function:

◆ is_subscribed()

bool is_subscribed ( const std::string &  event_type) const

Check if currently subscribed to an event type.

Parameters
event_typeThe event type to check
Returns
True if subscribed, false otherwise
Here is the caller graph for this function:

◆ get_subscriptions()

std::set< std::string > get_subscriptions ( ) const

Get the set of currently subscribed event types.

Returns
Set of event type names
Here is the caller graph for this function:

◆ take_pending_notifications()

std::vector< pending_notification > take_pending_notifications ( )

Get all pending notifications and clear the queue.

Returns notifications in the order they were received. The internal queue is cleared after this call.

Returns
Vector of pending notifications
Here is the caller graph for this function:

◆ has_pending_notifications()

bool has_pending_notifications ( ) const

Check if there are any pending notifications.

Returns
True if there are pending notifications