13#include <unordered_map>
34 std::string_view session_id,
35 std::string_view client_address,
37 std::weak_ptr<core::http_server>
server);
39 [[nodiscard]]
auto id()
const -> std::string_view
override;
40 [[nodiscard]]
auto is_connected()
const ->
bool override;
41 [[nodiscard]]
auto send(std::vector<uint8_t>&& data) ->
VoidResult override;
42 auto close() ->
void override;
121 [[nodiscard]]
auto is_running() const ->
bool override;
146 static auto
make_session_id(const std::
string& address, uint16_t port, uint64_t request_id) -> std::
string;
Unified interface for all protocol server implementations.
std::function< void(std::string_view)> disconnection_callback_t
Callback type for disconnections (session_id)
std::function< void(std::string_view, const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data (session_id, data)
std::function< void(std::string_view, std::error_code)> error_callback_t
Callback type for errors (session_id, error)
std::function< void(std::shared_ptr< i_session >)> connection_callback_t
Callback type for new connections.
Interface for a single client session on the server side.
Session wrapper for HTTP request connections implementing i_session.
std::weak_ptr< core::http_server > server_
auto is_connected() const -> bool override
Checks if the session is currently connected.
http_request_session(std::string_view session_id, std::string_view client_address, uint16_t client_port, std::weak_ptr< core::http_server > server)
std::vector< uint8_t > response_data_
std::atomic< bool > is_connected_
auto id() const -> std::string_view override
Gets the unique identifier for this session.
auto get_response_data() const -> const std::vector< uint8_t > &
Gets the stored response data.
auto close() -> void override
Closes the session.
auto set_response_data(std::vector< uint8_t > data) -> void
Stores the response data to be sent back to client.
std::string client_address_
Adapter that wraps http_server to implement i_protocol_server.
std::unordered_map< std::string, std::shared_ptr< http_request_session > > sessions_
receive_callback_t receive_callback_
http_server_adapter(http_server_adapter &&)=delete
auto wait_for_stop() -> void override
Blocks until the component has stopped.
http_server_adapter(std::string_view server_id)
Constructs an adapter with a unique server ID.
~http_server_adapter() override
Destructor ensures proper cleanup.
std::mutex sessions_mutex_
auto set_connection_callback(connection_callback_t callback) -> void override
Sets the callback for new connections.
http_server_adapter & operator=(http_server_adapter &&)=delete
auto is_running() const -> bool override
Checks if the component is currently running.
auto setup_internal_routes() -> void
Sets up internal HTTP routes to bridge to i_protocol_server callbacks.
auto remove_session(const std::string &session_id) -> void
Removes a session after request processing.
static auto make_session_id(const std::string &address, uint16_t port, uint64_t request_id) -> std::string
Creates a unique session ID from request info.
auto set_disconnection_callback(disconnection_callback_t callback) -> void override
Sets the callback for disconnections.
std::mutex callbacks_mutex_
auto get_or_create_session(const std::string &address, uint16_t port) -> std::shared_ptr< http_request_session >
Gets or creates a session for the given request.
connection_callback_t connection_callback_
http_server_adapter(const http_server_adapter &)=delete
std::atomic< uint64_t > request_counter_
std::shared_ptr< core::http_server > server_
error_callback_t error_callback_
std::atomic< bool > is_running_
auto set_error_callback(error_callback_t callback) -> void override
Sets the callback for errors.
auto set_receive_callback(receive_callback_t callback) -> void override
Sets the callback for received data.
auto stop() -> VoidResult override
Stops the server and closes all connections.
auto connection_count() const -> size_t override
Gets the number of active client connections.
http_server_adapter & operator=(const http_server_adapter &)=delete
auto start(uint16_t port) -> VoidResult override
Starts the server and begins listening for connections.
disconnection_callback_t disconnection_callback_
Protocol-specific server interface extending i_server.