JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
jsonrpc::server::Server Class Reference

A JSON-RPC server for handling requests and notifications. More...

#include <server.hpp>

Collaboration diagram for jsonrpc::server::Server:

Public Member Functions

 Server (std::unique_ptr< transport::Transport > transport)
 Constructs a Server with the specified transport.
 
void Start ()
 Starts the server to handle incoming JSON-RPC requests.
 
void Stop ()
 Stops the server from handling requests.
 
void RegisterMethodCall (const std::string &method, const MethodCallHandler &handler)
 Registers an RPC method handler with the dispatcher.
 
void RegisterNotification (const std::string &method, const NotificationHandler &handler)
 Registers an RPC notification handler with the dispatcher.
 
auto IsRunning () const -> bool
 Checks if the server is currently running.
 

Detailed Description

A JSON-RPC server for handling requests and notifications.

Manages the lifecycle of a JSON-RPC server, including starting and stopping, and registering RPC methods and notifications.

Definition at line 19 of file server.hpp.

Constructor & Destructor Documentation

◆ Server()

jsonrpc::server::Server::Server ( std::unique_ptr< transport::Transport > transport)
explicit

Constructs a Server with the specified transport.

Parameters
transportA unique pointer to the transport layer to use for communication.

Definition at line 7 of file server.cpp.

8 : transport_(std::move(transport)) {
9 dispatcher_ = std::make_unique<Dispatcher>();
10 spdlog::info("Server initialized with transport");
11}

Member Function Documentation

◆ IsRunning()

auto jsonrpc::server::Server::IsRunning ( ) const -> bool
nodiscard

Checks if the server is currently running.

Definition at line 24 of file server.cpp.

24 {
25 return running_.load();
26}

◆ RegisterMethodCall()

void jsonrpc::server::Server::RegisterMethodCall ( const std::string & method,
const MethodCallHandler & handler )

Registers an RPC method handler with the dispatcher.

Parameters
methodThe name of the RPC method to handle.
handlerThe function to handle the RPC method call.
See also
MethodCallHandler for the signature of the handler function.

Definition at line 50 of file server.cpp.

51 {
52 dispatcher_->RegisterMethodCall(method, handler);
53}

◆ RegisterNotification()

void jsonrpc::server::Server::RegisterNotification ( const std::string & method,
const NotificationHandler & handler )

Registers an RPC notification handler with the dispatcher.

Parameters
methodThe name of the RPC notification to handle.
handlerThe function to handle the RPC notification.
See also
NotificationHandler for the signature of the handler function.

Definition at line 55 of file server.cpp.

56 {
57 dispatcher_->RegisterNotification(method, handler);
58}

◆ Start()

void jsonrpc::server::Server::Start ( )

Starts the server to handle incoming JSON-RPC requests.

Definition at line 13 of file server.cpp.

13 {
14 spdlog::info("Server starting");
15 running_.store(true);
16 Listen();
17}

◆ Stop()

void jsonrpc::server::Server::Stop ( )

Stops the server from handling requests.

Definition at line 19 of file server.cpp.

19 {
20 spdlog::info("Server stopping");
21 running_.store(false);
22}

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