![]() |
IRSOL
C++ code implementing socket server for interacting with Baumer camera.
|
Represents a single connected client session. More...
#include <session.hpp>
Public Member Functions | |
ClientSession (const irsol::types::client_id_t &id, irsol::types::socket_t &&sock, App &app) | |
Constructs a new ClientSession. | |
void | run () |
Starts the client's session logic. | |
void | handleOutMessages (std::vector< protocol::OutMessage > &&messages) |
Handles multiple outbound messages to the client. | |
void | handleOutMessage (protocol::OutMessage &&message) |
Handles a single outbound message to the client. | |
void | handleSerializedMessage (const protocol::internal::SerializedMessage &serializedMessage) |
Sends an already-serialized message to the client. | |
const App & | app () const |
Returns a const reference to the owning App instance. | |
App & | app () |
Returns a mutable reference to the owning App instance. | |
const irsol::types::client_id_t & | id () const |
Returns the unique client identifier. | |
const irsol::types::socket_t & | socket () const |
Returns a const reference to the client socket. | |
irsol::types::socket_t & | socket () |
Returns a mutable reference to the client socket. | |
std::mutex & | socketMutex () |
Returns a reference to the socket mutex used for synchronization. | |
const irsol::server::internal::UserSessionData & | userData () const |
Returns a const reference to client-specific session state. | |
irsol::server::internal::UserSessionData & | userData () |
Returns a mutable reference to client-specific session state. | |
Private Member Functions | |
void | processInMessageBuffer (std::string &messageBuffer) |
Processes accumulated raw data into complete protocol messages. | |
void | processInRawMessage (const std::string &rawMessage) |
Parses and processes a complete incoming raw message. | |
void | send (const std::string &message) |
Sends a text message over the socket to the client. | |
void | send (const irsol::types::byte_t *const data, size_t size) |
Sends binary data over the socket. | |
Private Attributes | |
irsol::types::client_id_t | m_id |
Unique ID identifying this session (maps to client_id_t). | |
irsol::types::socket_t | m_socket |
Socket used for communication with the client. | |
std::mutex | m_socketMutex {} |
Mutex to synchronize socket access from multiple threads. | |
irsol::server::internal::UserSessionData | m_sessionData {} |
Session-specific data (e.g., stream rate, frame subscriptions). | |
App & | m_app |
Reference to the central App instance for server-wide coordination. | |
Represents a single connected client session.
Each instance of ClientSession
corresponds to exactly one connected client. It owns the socket connection, manages message transmission and reception, and encapsulates session-specific state (e.g., frame stream preferences).
The class is responsible for all communication with the client: reading inbound messages from the socket, parsing and dispatching them, and sending outbound messages. All session-specific state is stored here, including a irsol::server::internal::UserSessionData structure.
In addition, the session holds a reference to the central irsol::server::App instance, which enables it to interact with the global server context (e.g., for broadcasting).
Definition at line 43 of file session.hpp.
irsol::server::ClientSession::ClientSession | ( | const irsol::types::client_id_t & | id, |
irsol::types::socket_t && | sock, | ||
App & | app | ||
) |
Constructs a new ClientSession.
id | Unique client identifier (e.g., UUID or socket-derived). |
sock | Already-established TCP socket to the client. |
app | Reference to the server application instance. |
Definition at line 16 of file session.cpp.
|
inline |
Returns a mutable reference to the owning App instance.
Definition at line 110 of file session.hpp.
|
inline |
Returns a const reference to the owning App instance.
Definition at line 104 of file session.hpp.
void irsol::server::ClientSession::handleOutMessage | ( | protocol::OutMessage && | message | ) |
Handles a single outbound message to the client.
Serializes and sends one message through the socket.
message | The message to transmit. |
Definition at line 77 of file session.cpp.
void irsol::server::ClientSession::handleOutMessages | ( | std::vector< protocol::OutMessage > && | messages | ) |
Handles multiple outbound messages to the client.
Serializes and sends a vector of outbound messages through the socket.
messages | The list of messages to transmit. |
Definition at line 68 of file session.cpp.
void irsol::server::ClientSession::handleSerializedMessage | ( | const protocol::internal::SerializedMessage & | serializedMessage | ) |
Sends an already-serialized message to the client.
serializedMessage | Message that is already serialized to text or binary form. |
Definition at line 87 of file session.cpp.
|
inline |
Returns the unique client identifier.
Definition at line 116 of file session.hpp.
|
private |
Processes accumulated raw data into complete protocol messages.
Splits the incoming input buffer into individual protocol messages and dispatches each one for parsing and handling.
Invokes ClientSession::processInRawMessage.
messageBuffer | Text buffer containing raw data received from the client's socket. |
Definition at line 100 of file session.cpp.
|
private |
Parses and processes a complete incoming raw message.
Invokes the registered message handler for the message type.
rawMessage | Complete raw protocol message string. |
Definition at line 118 of file session.cpp.
void irsol::server::ClientSession::run | ( | ) |
Starts the client's session logic.
Initiates the processing loop for the session, including reading incoming messages from the socket and handling disconnections.
Definition at line 21 of file session.cpp.
|
private |
Sends binary data over the socket.
m_socketMutex
.data | Pointer to binary data buffer. |
size | Size of the data in bytes. |
Definition at line 169 of file session.cpp.
|
private |
Sends a text message over the socket to the client.
This is the way the server communicates to the client.
m_socketMutex
.message | The message string to send. |
Definition at line 148 of file session.cpp.
|
inline |
Returns a mutable reference to the client socket.
Definition at line 128 of file session.hpp.
|
inline |
Returns a const reference to the client socket.
Definition at line 122 of file session.hpp.
|
inline |
Returns a reference to the socket mutex used for synchronization.
Definition at line 134 of file session.hpp.
|
inline |
Returns a mutable reference to client-specific session state.
Definition at line 146 of file session.hpp.
|
inline |
Returns a const reference to client-specific session state.
Definition at line 140 of file session.hpp.
|
private |
Reference to the central App instance for server-wide coordination.
Definition at line 207 of file session.hpp.
|
private |
Unique ID identifying this session (maps to client_id_t).
Definition at line 195 of file session.hpp.
|
private |
Session-specific data (e.g., stream rate, frame subscriptions).
Definition at line 204 of file session.hpp.
|
private |
Socket used for communication with the client.
Definition at line 198 of file session.hpp.
|
private |
Mutex to synchronize socket access from multiple threads.
Definition at line 201 of file session.hpp.