6#ifndef KCENON_NETWORK_INTERNAL_CORE_UNIFIED_MESSAGING_CLIENT_H_
7#define KCENON_NETWORK_INTERNAL_CORE_UNIFIED_MESSAGING_CLIENT_H_
30#ifdef BUILD_TLS_SUPPORT
31#include <asio/ssl.hpp>
37#ifdef BUILD_TLS_SUPPORT
38 class secure_tcp_socket;
81template <protocol::Protocol Protocol, policy::TlsPolicy TlsPolicy = policy::no_tls>
82 requires std::same_as<Protocol, protocol::tcp_protocol>
84 :
public std::enable_shared_from_this<unified_messaging_client<Protocol, TlsPolicy>>
169 [[nodiscard]] auto
client_id() const -> const std::
string&;
217#ifdef BUILD_TLS_SUPPORT
249 auto do_connect(std::string_view host, uint16_t port) -> void;
255#ifdef BUILD_TLS_SUPPORT
256 auto on_handshake_complete(std::error_code ec) ->
void
283 std::unique_ptr<asio::executor_work_guard<asio::io_context::executor_type>>
287#ifdef BUILD_TLS_SUPPORT
288 std::unique_ptr<asio::ssl::context> ssl_context_;
289 [[no_unique_address]] TlsPolicy tls_config_;
313#ifdef BUILD_TLS_SUPPORT
325#include "unified_messaging_client.inl"
Thread-safe callback registration and invocation manager.
Unified TCP client template parameterized by protocol and TLS policy.
auto invoke_error_callback(std::error_code ec) -> void
auto invoke_connected_callback() -> void
auto invoke_disconnected_callback() -> void
auto do_start_impl(std::string_view host, uint16_t port) -> VoidResult
auto set_receive_callback(receive_callback_t callback) -> void
Sets the callback for received data.
std::shared_ptr< asio::io_context > io_context_
auto set_connected(bool connected) -> void
std::shared_ptr< asio::ip::tcp::socket > pending_socket_
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > work_guard_
auto on_receive(std::span< const uint8_t > data) -> void
static constexpr bool is_secure
Indicates whether TLS is enabled for this client.
std::mutex pending_mutex_
~unified_messaging_client() noexcept
Destructor; automatically calls stop_client() if still running.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
auto do_connect(std::string_view host, uint16_t port) -> void
std::atomic< bool > stop_initiated_
unified_messaging_client(std::string_view client_id, const TlsPolicy &tls_config)
Constructs a secure client with TLS configuration.
std::future< void > io_context_future_
utils::lifecycle_manager lifecycle_
auto set_error_callback(error_callback_t callback) -> void
Sets the callback for errors.
auto is_connected() const noexcept -> bool
Checks if the client is connected to the server.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
auto set_disconnected_callback(disconnected_callback_t callback) -> void
Sets the callback for disconnection.
auto get_socket() const -> std::shared_ptr< socket_type >
auto stop_client() -> VoidResult
Stops the client and disconnects from the server.
auto is_running() const noexcept -> bool
Checks if the client is currently running.
std::shared_ptr< socket_type > socket_
auto invoke_receive_callback(const std::vector< uint8_t > &data) -> void
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Sends data to the connected server.
auto set_connected_callback(connected_callback_t callback) -> void
Sets the callback for connection established.
auto wait_for_stop() -> void
Blocks until stop_client() is called.
std::function< void()> connected_callback_t
Callback type for connection established.
unified_messaging_client(std::string_view client_id)
Constructs a client with a given identifier.
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
auto start_client(std::string_view host, uint16_t port) -> VoidResult
Starts the client and connects to the specified host and port.
auto do_send_impl(std::vector< uint8_t > &&data) -> VoidResult
auto on_connection_failed(std::error_code ec) -> void
auto do_stop_impl() -> VoidResult
auto client_id() const -> const std::string &
Returns the client identifier.
auto on_error(std::error_code ec) -> void
auto on_connect(std::error_code ec) -> void
std::atomic< bool > is_connected_
std::shared_ptr< asio::ip::tcp::resolver > pending_resolver_
A lightweight wrapper around asio::ssl::stream<asio::ip::tcp::socket>, enabling asynchronous TLS/SSL ...
A lightweight wrapper around asio::ip::tcp::socket, enabling asynchronous read and write operations.
Thread-safe lifecycle state management for network components.
Component lifecycle management (start, stop, restart).
constexpr bool is_tls_enabled_v
Helper variable template to check if TLS is enabled at compile time.
Result< std::monostate > VoidResult
tcp_client_callback
Callback indices for messaging_client and secure_messaging_client.
Network-specific error and result type definitions.
Policy-based TLS configuration (no_tls, require_tls, optional_tls).