|
Plotly.cpp 0.1.0
A C++ plotting library for expressive, interactive, real-time & streaming data visualization
|
Base implementation class for WebSocket endpoints. More...
#include <websockets_endpoint.hpp>


Public Member Functions | |
| 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) | |
| virtual auto | waitConnection (std::chrono::milliseconds timeout) const -> bool=0 |
| Wait for a connection to be established. | |
| virtual auto | isConnected () const -> bool=0 |
| Check if the endpoint is currently connected. | |
| virtual auto | send (const std::string_view &message) -> bool=0 |
| Send a message through the WebSocket connection. | |
| virtual void | stop ()=0 |
| Stop the endpoint and clean up resources. | |
| virtual auto | getName () const -> std::string=0 |
| Get the name/identifier of this endpoint. | |
Protected Member Functions | |
| virtual void | serviceLoop ()=0 |
| Pure virtual method for the main service loop. | |
| 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. | |
Protected Attributes | |
| 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_t > | callbacks |
| Map of event names to their associated callback functions. | |
| std::thread | callbackExecutorThread |
| Thread for executing callbacks. | |
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. | |
Base implementation class for WebSocket endpoints.
This class provides a concrete implementation of the WebsocketEndpointInterface with common functionality shared between client and server endpoints. It handles message queuing, callback management, and threading infrastructure.
The implementation uses a multi-threaded design:
Derived classes need to implement the pure virtual serviceLoop() method to provide specific client or server behavior.
|
protected |
Main loop for the callback executor thread.
This method runs in the callback executor thread and processes received messages by invoking the appropriate registered callbacks.
|
protected |
Handle an incoming message by queuing it for callback processing.
| message | The received message to handle |
This method is called by the service thread to queue received messages for processing by the callback executor thread.
|
overridevirtual |
Register a callback for a specific event (override)
| eventName | The name of the event to listen for |
| callback | The callback function to invoke when the event occurs |
This implementation stores the callback in the callbacks map in a thread-safe manner using the callback mutex.
Implements plotly::detail::WebsocketEndpointInterface.
|
protectedpure virtual |
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.
Implemented in plotly::detail::WebsocketClient, and plotly::detail::WebsocketServer.
|
protected |
Start the callback executor thread.
This method initializes and starts the callback executor thread that processes incoming messages and invokes registered callbacks.
| void plotly::detail::WebsocketEndpointImpl::stopCallbackExecutor | ( | ) |
Stop the callback executor thread and clean up resources.
This method stops the callback executor thread and performs necessary cleanup. It's called automatically by the destructor but can also be called explicitly if needed.
|
overridevirtual |
Unregister a callback for a specific event (override)
| eventName | The name of the event to stop listening for |
This implementation removes the callback from the callbacks map in a thread-safe manner using the callback mutex.
Implements plotly::detail::WebsocketEndpointInterface.
|
protected |
Thread for executing callbacks.
|
protected |
Mutex protecting the callbacks map.
|
protected |
Map of event names to their associated callback functions.
|
protected |
Queue of received messages waiting to be processed.
|
protected |
Condition variable for notifying about new received messages.
|
protected |
Mutex protecting the received messages queue.
|
protected |
Atomic flag indicating if the endpoint is running.
|
protected |
Service thread for handling WebSocket operations.