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

JSON-RPC 2.0 server implementation over WebSocket. More...

#include <json_rpc.hpp>

Public Member Functions

 JsonRpc (std::unique_ptr< WebsocketEndpointInterface > wsEndpoint)
 Constructs a new JSON-RPC server.
 ~JsonRpc ()
 Destructor. Stops the server if running.
 JsonRpc (const JsonRpc &)=delete
auto operator= (const JsonRpc &) -> JsonRpc &=delete
 JsonRpc (JsonRpc &&other) noexcept
auto operator= (JsonRpc &&other) noexcept -> JsonRpc &
void registerHandler (const std::string &method, const std::function< nlohmann::json(const nlohmann::json &)> &handler)
 Registers a handler function for a specific RPC method.
void registerNotification (const std::string &method, std::function< void(const nlohmann::json &)> handler)
void unregisterHandler (const std::string &method)
void registerCallbackWithWebsocket (const std::string &callbackName, std::function< void(const std::string_view)> callback)
 Registers a callback function for the WebSocket endpoint.
void unregisterCallbackFromWebsocket (const std::string &callbackName)
 Unregisters a callback function from the WebSocket endpoint.
void unregisterAllCallbacksFromWebsockets ()
 Unregisters all callbacks from the WebSocket endpoint.
auto call (const std::string &method, const nlohmann::json &params) -> std::pair< std::future< nlohmann::json >, std::function< void()> >
 Makes an asynchronous JSON-RPC call to the connected client.
void notify (const std::string &method, const nlohmann::json &params)
 Sends a notification to all connected clients.
auto getWebsocketEndpoint () const -> WebsocketEndpointInterface *
 Gets a raw pointer to the underlying websocket endpoint.

Detailed Description

JSON-RPC 2.0 server implementation over WebSocket.

Constructor & Destructor Documentation

◆ JsonRpc() [1/3]

plotly::detail::JsonRpc::JsonRpc ( std::unique_ptr< WebsocketEndpointInterface > wsEndpoint)
explicit

Constructs a new JSON-RPC server.

◆ ~JsonRpc()

plotly::detail::JsonRpc::~JsonRpc ( )

Destructor. Stops the server if running.

◆ JsonRpc() [2/3]

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

◆ JsonRpc() [3/3]

plotly::detail::JsonRpc::JsonRpc ( JsonRpc && other)
noexcept

Member Function Documentation

◆ call()

auto plotly::detail::JsonRpc::call ( const std::string & method,
const nlohmann::json & params ) -> std::pair<std::future<nlohmann::json>, std::function<void()>>

Makes an asynchronous JSON-RPC call to the connected client.

Parameters
methodThe name of the method to call.
paramsThe parameters to pass to the method.
Returns
A pair containing a future containing the result of the RPC call and a function to cancel the call.

◆ getWebsocketEndpoint()

auto plotly::detail::JsonRpc::getWebsocketEndpoint ( ) const -> WebsocketEndpointInterface *
nodiscard

Gets a raw pointer to the underlying websocket endpoint.

Returns
Raw pointer to the websocket endpoint (for compatibility).

◆ notify()

void plotly::detail::JsonRpc::notify ( const std::string & method,
const nlohmann::json & params )

Sends a notification to all connected clients.

Parameters
methodThe name of the method to call.
paramsThe parameters to pass to the method.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

auto plotly::detail::JsonRpc::operator= ( JsonRpc && other) -> JsonRpc &
noexcept

◆ registerCallbackWithWebsocket()

void plotly::detail::JsonRpc::registerCallbackWithWebsocket ( const std::string & callbackName,
std::function< void(const std::string_view)> callback )

Registers a callback function for the WebSocket endpoint.

Parameters
callbackNameThe name of the callback to register.
callbackThe callback function to be called when messages are received.

◆ registerHandler()

void plotly::detail::JsonRpc::registerHandler ( const std::string & method,
const std::function< nlohmann::json(const nlohmann::json &)> & handler )

Registers a handler function for a specific RPC method.

Parameters
methodThe name of the RPC method.
handlerThe handler function to be called when the method is invoked.

◆ registerNotification()

void plotly::detail::JsonRpc::registerNotification ( const std::string & method,
std::function< void(const nlohmann::json &)> handler )

◆ unregisterAllCallbacksFromWebsockets()

void plotly::detail::JsonRpc::unregisterAllCallbacksFromWebsockets ( )

Unregisters all callbacks from the WebSocket endpoint.

◆ unregisterCallbackFromWebsocket()

void plotly::detail::JsonRpc::unregisterCallbackFromWebsocket ( const std::string & callbackName)

Unregisters a callback function from the WebSocket endpoint.

Parameters
callbackNameThe name of the callback to unregister.

◆ unregisterHandler()

void plotly::detail::JsonRpc::unregisterHandler ( const std::string & method)

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