Plotly.cpp 0.1.0
A C++ plotting library for expressive, interactive, real-time & streaming data visualization
Loading...
Searching...
No Matches
plotly::detail::WebsocketServer Class Referencefinal

#include <websockets_server.hpp>

Inheritance diagram for plotly::detail::WebsocketServer:
Collaboration diagram for plotly::detail::WebsocketServer:

Public Member Functions

 WebsocketServer ()
 ~WebsocketServer ()
 WebsocketServer (const WebsocketServer &)=delete
auto operator= (const WebsocketServer &) -> WebsocketServer &=delete
 WebsocketServer (WebsocketServer &&)=delete
auto operator= (WebsocketServer &&) -> WebsocketServer &=delete
auto serve (std::string_view address, int port) -> bool
auto hasClient () const -> bool
void waitUntilNoClient () const
auto getPort () const -> int
void stop () override
 Stop the endpoint and clean up resources.
auto waitConnection (std::chrono::milliseconds timeout) const -> bool override
 Wait for a connection to be established.
auto isConnected () const -> bool override
 Check if the endpoint is currently connected.
auto send (const std::string_view &message) -> bool override
 Send a message through the WebSocket connection.
auto getName () const -> std::string override
 Get the name/identifier of this endpoint.
Public Member Functions inherited from plotly::detail::WebsocketEndpointImpl
void stopCallbackExecutor ()
 Stop the callback executor thread and clean up resources.
void registerCallback (const std::string_view &eventName, callback_t callback) override
 Register a callback for a specific event (override)
void unregisterCallback (const std::string_view &eventName) override
 Unregister a callback for a specific event (override)
Public Member Functions inherited from plotly::detail::WebsocketEndpointInterface
 WebsocketEndpointInterface ()
 Default constructor.
virtual ~WebsocketEndpointInterface ()
 Virtual destructor.
 WebsocketEndpointInterface (const WebsocketEndpointInterface &)=delete
 Copy constructor (deleted)
auto operator= (const WebsocketEndpointInterface &) -> WebsocketEndpointInterface &=delete
 Copy assignment operator (deleted)

Protected Member Functions

void serviceLoop () override
 Pure virtual method for the main service loop.
Protected Member Functions inherited from plotly::detail::WebsocketEndpointImpl
void callbackExecutorLoop ()
 Main loop for the callback executor thread.
void handleMessage (const std::string &message)
 Handle an incoming message by queuing it for callback processing.
void startCallbackExecutor ()
 Start the callback executor thread.

Additional Inherited Members

Public Types inherited from plotly::detail::WebsocketEndpointInterface
using callback_t = std::function<void(const std::string_view &)>
 Callback function type for handling incoming messages.
Protected Attributes inherited from plotly::detail::WebsocketEndpointImpl
std::atomic< bool > running {false}
 Atomic flag indicating if the endpoint is running.
std::thread serviceThread
 Service thread for handling WebSocket operations.
std::mutex recvMessagesMutex
 Mutex protecting the received messages queue.
std::condition_variable recvMessagesCv
 Condition variable for notifying about new received messages.
std::queue< std::string > recvMessages
 Queue of received messages waiting to be processed.
std::mutex callbackMutex
 Mutex protecting the callbacks map.
std::unordered_map< std::string, callback_tcallbacks
 Map of event names to their associated callback functions.
std::thread callbackExecutorThread
 Thread for executing callbacks.

Constructor & Destructor Documentation

◆ WebsocketServer() [1/3]

plotly::detail::WebsocketServer::WebsocketServer ( )

◆ ~WebsocketServer()

plotly::detail::WebsocketServer::~WebsocketServer ( )

◆ WebsocketServer() [2/3]

plotly::detail::WebsocketServer::WebsocketServer ( const WebsocketServer & )
delete

◆ WebsocketServer() [3/3]

plotly::detail::WebsocketServer::WebsocketServer ( WebsocketServer && )
delete

Member Function Documentation

◆ getName()

auto plotly::detail::WebsocketServer::getName ( ) const -> std::string
overridevirtual

Get the name/identifier of this endpoint.

Returns
A string identifying this endpoint

This method returns a human-readable name or identifier for the endpoint, useful for logging and debugging purposes.

Implements plotly::detail::WebsocketEndpointInterface.

◆ getPort()

auto plotly::detail::WebsocketServer::getPort ( ) const -> int

◆ hasClient()

auto plotly::detail::WebsocketServer::hasClient ( ) const -> bool

◆ isConnected()

auto plotly::detail::WebsocketServer::isConnected ( ) const -> bool
overridevirtual

Check if the endpoint is currently connected.

Returns
true if connected, false otherwise

This method provides a non-blocking way to check the current connection status of the endpoint.

Implements plotly::detail::WebsocketEndpointInterface.

◆ operator=() [1/2]

auto plotly::detail::WebsocketServer::operator= ( const WebsocketServer & ) -> WebsocketServer &=delete
delete

◆ operator=() [2/2]

auto plotly::detail::WebsocketServer::operator= ( WebsocketServer && ) -> WebsocketServer &=delete
delete

◆ send()

auto plotly::detail::WebsocketServer::send ( const std::string_view & message) -> bool
overridevirtual

Send a message through the WebSocket connection.

Parameters
messageThe message to send
Returns
true if message was sent successfully, false otherwise

This method attempts to send a message through the WebSocket connection. The operation may fail if the connection is not established or if there are network issues.

Implements plotly::detail::WebsocketEndpointInterface.

◆ serve()

auto plotly::detail::WebsocketServer::serve ( std::string_view address,
int port ) -> bool

◆ serviceLoop()

void plotly::detail::WebsocketServer::serviceLoop ( )
overrideprotectedvirtual

Pure virtual method for the main service loop.

Derived classes must implement this method to provide specific WebSocket client or server behavior. This method runs in the service thread and should handle connection management and message reception.

Implements plotly::detail::WebsocketEndpointImpl.

◆ stop()

void plotly::detail::WebsocketServer::stop ( )
overridevirtual

Stop the endpoint and clean up resources.

This method stops all endpoint operations, closes connections, and performs necessary cleanup. After calling this method, the endpoint should not be used for further operations.

Implements plotly::detail::WebsocketEndpointInterface.

◆ waitConnection()

auto plotly::detail::WebsocketServer::waitConnection ( std::chrono::milliseconds timeout) const -> bool
overridevirtual

Wait for a connection to be established.

Parameters
timeoutMaximum time to wait for connection
Returns
true if connection was established within timeout, false otherwise

This method blocks until either a connection is established or the timeout expires. It's useful for synchronizing with connection establishment in client scenarios or waiting for incoming connections in server scenarios.

Implements plotly::detail::WebsocketEndpointInterface.

◆ waitUntilNoClient()

void plotly::detail::WebsocketServer::waitUntilNoClient ( ) const

The documentation for this class was generated from the following files: