Plotly.cpp 0.1.0
A C++ plotting library for expressive, interactive, real-time & streaming data visualization
Loading...
Searching...
No Matches
websockets_client.hpp
Go to the documentation of this file.
1#ifndef PLOTLY_DETAILS_WEBSOCKETS_CLIENT_HPP
2#define PLOTLY_DETAILS_WEBSOCKETS_CLIENT_HPP
3
4#include "websocketpp/config/asio_no_tls_client.hpp"
5#include "websocketpp/roles/client_endpoint.hpp"
7
8namespace plotly::detail {
9
10using client_config = websocketpp::config::asio_client;
11using client_t = websocketpp::client<client_config>;
12using connection_hdl = websocketpp::connection_hdl;
13
15public:
19 auto operator=(const WebsocketClient &) -> WebsocketClient & = delete;
22 auto connect(const std::string_view &endpoint) -> bool;
23 void stop() override;
24
25 // Interface implementations
26 auto waitConnection(std::chrono::milliseconds timeout) const -> bool override;
27 auto isConnected() const -> bool override;
28 auto send(const std::string_view &message) -> bool override;
29 auto getName() const -> std::string override;
30
31protected:
32 void serviceLoop() override;
33
34private:
35 client_t _client;
36 connection_hdl _currentConnection;
37 std::string _endpointUri;
38 std::thread _serviceThread;
39 mutable std::mutex _connectionMutex;
40 mutable std::condition_variable _connectionCv;
41 std::atomic<bool> _connected{false};
42
43 void setupClientHandlers();
44 void onFail(const connection_hdl &hdl);
45};
46
47} // namespace plotly::detail
48
49#endif
auto connect(const std::string_view &endpoint) -> bool
Definition websockets_client.cpp:28
WebsocketClient(const WebsocketClient &)=delete
WebsocketClient()
Definition websockets_client.cpp:17
auto waitConnection(std::chrono::milliseconds timeout) const -> bool override
Wait for a connection to be established.
Definition websockets_client.cpp:118
~WebsocketClient()
Definition websockets_client.cpp:26
auto getName() const -> std::string override
Get the name/identifier of this endpoint.
Definition websockets_client.cpp:143
void serviceLoop() override
Pure virtual method for the main service loop.
Definition websockets_client.cpp:109
auto operator=(const WebsocketClient &) -> WebsocketClient &=delete
void stop() override
Stop the endpoint and clean up resources.
Definition websockets_client.cpp:101
auto isConnected() const -> bool override
Check if the endpoint is currently connected.
Definition websockets_client.cpp:125
auto operator=(WebsocketClient &&) -> WebsocketClient &=delete
WebsocketClient(WebsocketClient &&)=delete
auto send(const std::string_view &message) -> bool override
Send a message through the WebSocket connection.
Definition websockets_client.cpp:127
Base implementation class for WebSocket endpoints.
Definition websockets_endpoint.hpp:157
Definition browser.cpp:27
websocketpp::client< client_config > client_t
Definition websockets_client.hpp:11
websocketpp::connection_hdl connection_hdl
Definition websockets_client.hpp:12
websocketpp::config::asio_client client_config
Definition websockets_client.hpp:10
WebSocket endpoint interface and implementation for plotly.cpp.