27#include <system_error>
87 virtual auto on_receive(std::span<const uint8_t> data) ->
void = 0;
103 virtual auto on_disconnected(std::optional<std::string_view> reason = std::nullopt) ->
void
110 virtual auto on_error(std::error_code ec) ->
void = 0;
134 auto on_receive(std::span<const uint8_t> ) ->
void override {}
137 auto on_error(std::error_code ) ->
void override {}
169 using receive_fn = std::function<void(std::span<const uint8_t>)>;
175 using error_fn = std::function<void(std::error_code)>;
222 auto on_receive(std::span<const uint8_t> data) ->
void override
Adapter to use function callbacks with the observer pattern.
disconnected_fn disconnected_callback_
auto on_disconnected(std::optional< std::string_view > reason) -> void override
Called when the connection is closed.
std::function< void()> connected_fn
Callback type for connection established.
std::function< void(std::error_code)> error_fn
Callback type for errors.
auto on_error(error_fn fn) -> callback_adapter &
Sets the callback for errors.
auto on_error(std::error_code ec) -> void override
Called when an error occurs.
auto on_disconnected(disconnected_fn fn) -> callback_adapter &
Sets the callback for disconnection.
std::function< void(std::optional< std::string_view >)> disconnected_fn
Callback type for disconnection.
auto on_receive(std::span< const uint8_t > data) -> void override
Called when data is received from the server.
auto on_receive(receive_fn fn) -> callback_adapter &
Sets the callback for received data.
receive_fn receive_callback_
auto on_connected() -> void override
Called when the connection is established.
std::function< void(std::span< const uint8_t >)> receive_fn
Callback type for received data (using span)
connected_fn connected_callback_
auto on_connected(connected_fn fn) -> callback_adapter &
Sets the callback for connection established.
Observer interface for client connection events.
virtual auto on_connected() -> void=0
Called when the connection is established.
virtual auto on_receive(std::span< const uint8_t > data) -> void=0
Called when data is received from the server.
virtual auto on_disconnected(std::optional< std::string_view > reason=std::nullopt) -> void=0
Called when the connection is closed.
virtual auto on_error(std::error_code ec) -> void=0
Called when an error occurs.
virtual ~connection_observer()=default
No-op implementation of connection_observer.
auto on_disconnected(std::optional< std::string_view >) -> void override
Called when the connection is closed.
auto on_error(std::error_code) -> void override
Called when an error occurs.
auto on_connected() -> void override
Called when the connection is established.
auto on_receive(std::span< const uint8_t >) -> void override
Called when data is received from the server.