JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <memory>
5#include <string>
6
10
11namespace jsonrpc::server {
12
19class Server {
20 public:
27 explicit Server(std::unique_ptr<transport::Transport> transport);
28
30 void Start();
31
33 void Stop();
34
44 const std::string &method, const MethodCallHandler &handler);
45
55 const std::string &method, const NotificationHandler &handler);
56
58 [[nodiscard]] auto IsRunning() const -> bool;
59
60 private:
62 void Listen();
63
65 std::unique_ptr<Dispatcher> dispatcher_;
66
68 std::unique_ptr<transport::Transport> transport_;
69
71 std::atomic<bool> running_{false};
72};
73
74} // namespace jsonrpc::server
A JSON-RPC server for handling requests and notifications.
Definition server.hpp:19
void Start()
Starts the server to handle incoming JSON-RPC requests.
Definition server.cpp:13
auto IsRunning() const -> bool
Checks if the server is currently running.
Definition server.cpp:24
void RegisterMethodCall(const std::string &method, const MethodCallHandler &handler)
Registers an RPC method handler with the dispatcher.
Definition server.cpp:50
void RegisterNotification(const std::string &method, const NotificationHandler &handler)
Registers an RPC notification handler with the dispatcher.
Definition server.cpp:55
Server(std::unique_ptr< transport::Transport > transport)
Constructs a Server with the specified transport.
Definition server.cpp:7
void Stop()
Stops the server from handling requests.
Definition server.cpp:19
std::function< void(const std::optional< nlohmann::json > &)> NotificationHandler
Type alias for notification handler functions.
Definition types.hpp:26
std::function< nlohmann::json(const std::optional< nlohmann::json > &)> MethodCallHandler
Type alias for method call handler functions.
Definition types.hpp:17