IRSOL
C++ code implementing socket server for interacting with Baumer camera.
session.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include "irsol/protocol.hpp"
14#include "irsol/types.hpp"
15
16#include <atomic>
17#include <memory>
18#include <mutex>
19#include <string>
20
21namespace irsol {
22namespace server {
23
24// Forward declaration
25class App;
26
44{
45public:
54
61 void run();
62
75 void handleOutMessages(std::vector<protocol::OutMessage>&& messages);
76
90
102
104 const App& app() const
105 {
106 return m_app;
107 }
108
111 {
112 return m_app;
113 }
114
117 {
118 return m_id;
119 }
120
123 {
124 return m_socket;
125 }
126
129 {
130 return m_socket;
131 }
132
134 std::mutex& socketMutex()
135 {
136 return m_socketMutex;
137 }
138
144
150
151private:
162 void processInMessageBuffer(std::string& messageBuffer);
163
171 void processInRawMessage(const std::string& rawMessage);
172
182 void send(const std::string& message);
183
192 void send(const irsol::types::byte_t* const data, size_t size);
193
196
199
201 std::mutex m_socketMutex{};
202
205
208};
209
210} // namespace server
211} // namespace irsol
Main server application that manages client connections and camera streaming.
Definition app.hpp:46
Represents a single connected client session.
Definition session.hpp:44
void run()
Starts the client's session logic.
Definition session.cpp:21
const irsol::types::socket_t & socket() const
Returns a const reference to the client socket.
Definition session.hpp:122
const irsol::types::client_id_t & id() const
Returns the unique client identifier.
Definition session.hpp:116
irsol::types::socket_t m_socket
Socket used for communication with the client.
Definition session.hpp:198
void handleOutMessages(std::vector< protocol::OutMessage > &&messages)
Handles multiple outbound messages to the client.
Definition session.cpp:68
std::mutex & socketMutex()
Returns a reference to the socket mutex used for synchronization.
Definition session.hpp:134
void processInMessageBuffer(std::string &messageBuffer)
Processes accumulated raw data into complete protocol messages.
Definition session.cpp:100
irsol::types::client_id_t m_id
Unique ID identifying this session (maps to client_id_t).
Definition session.hpp:195
App & app()
Returns a mutable reference to the owning App instance.
Definition session.hpp:110
void handleOutMessage(protocol::OutMessage &&message)
Handles a single outbound message to the client.
Definition session.cpp:77
std::mutex m_socketMutex
Mutex to synchronize socket access from multiple threads.
Definition session.hpp:201
const App & app() const
Returns a const reference to the owning App instance.
Definition session.hpp:104
App & m_app
Reference to the central App instance for server-wide coordination.
Definition session.hpp:207
void processInRawMessage(const std::string &rawMessage)
Parses and processes a complete incoming raw message.
Definition session.cpp:118
irsol::types::socket_t & socket()
Returns a mutable reference to the client socket.
Definition session.hpp:128
irsol::server::internal::UserSessionData & userData()
Returns a mutable reference to client-specific session state.
Definition session.hpp:146
const irsol::server::internal::UserSessionData & userData() const
Returns a const reference to client-specific session state.
Definition session.hpp:140
void handleSerializedMessage(const protocol::internal::SerializedMessage &serializedMessage)
Sends an already-serialized message to the client.
Definition session.cpp:87
irsol::server::internal::UserSessionData m_sessionData
Session-specific data (e.g., stream rate, frame subscriptions).
Definition session.hpp:204
void send(const std::string &message)
Sends a text message over the socket to the client.
Definition session.cpp:148
std::variant< Success, BinaryDataBuffer, ImageBinaryData, ColorImageBinaryData, Error > OutMessage
Variant type representing any outgoing message.
Definition variants.hpp:149
std::string client_id_t
Represents a unique client identifier. Typically used to identify connected clients by string IDs.
Definition types.hpp:55
sockpp::tcp_socket socket_t
Alias for a TCP socket.
Definition types.hpp:87
std::byte byte_t
Alias for a single byte used in serialization or binary data handling.
Definition types.hpp:165
Defines session-specific internal state structures for connected clients.
Represents a serialized protocol message with header and payload.
Encapsulates all per-client data used during a session's lifetime.
Definition state.hpp:162
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...