1#ifndef CC75354D_5C03_4B34_B773_96A9E6189611
2#define CC75354D_5C03_4B34_B773_96A9E6189611
5
6
7
8
13#include <nlohmann/json.hpp>
20
21
22
23
26
27
28
29
30
34
35
36
40
41
42
46
47
48
52
53
54
58
59
60
61
62
66
67
68
69
74
75
76
77
78
82
83
84
85
86
89
90
91
92
96
97
101
102
106
107
111
112
117
118
119
120
121
122
123
124
125
131
132
133
134
135
136
137
141
142
146
147
151
152
153
154
155
159
160
161
162
163
167
168
172
173
174
175
179
180
181
182
186
187
188
189
193
194
195
196
197
198
199
200 [[
nodiscard]]
const char*
what()
const noexcept override {
return this->m_message.c_str(); }
203
204
205
206
207
211 {
"code",
this->m_code},
212 {
"message",
this->m_message},
215 if (!
this->m_data.is_null()) {
216 j[
"data"] =
this->m_data;
Private implementation of the JSON RPC dispatcher class.
A class that manages JSON RPC method handlers and processes JSON RPC requests.
dispatcher & operator=(dispatcher &&rhs)=default
Move assignment operator.
dispatcher(dispatcher &&rhs)=default
Move constructor.
virtual void on_request(const nlohmann::json &extra)
Invoked when a request is received.
void add_ex(std::string_view method, F &&f, C instance)
Adds a method handler with an extra parameter and a class instance.
std::string parse_and_process_request(const std::string &request, const nlohmann::json &extra=nlohmann::json::object())
Parses and processes a JSON RPC request.
constexpr auto create_closure(C inst, F &&f) const
Creates a closure for invoking a member function with JSON parameters.
std::string process_request(const nlohmann::json &request, const nlohmann::json &extra=nlohmann::json::object())
Processes a JSON RPC request.
virtual void on_request_processed(const std::string &method, int code, const nlohmann::json &extra)
Invoked after the method handler is called.
void add_internal_method(std::string_view method, handler_t &&handler)
Adds a method handler for the specified method.
void add(std::string_view method, F &&f)
Adds a method handler f for the method method.
virtual void on_method(const std::string &method, const nlohmann::json &extra)
Invoked right before the method handler is called.
void add(std::string_view method, F &&f, C instance)
Adds a method to the dispatcher with the specified instance and function.
dispatcher()
Class constructor.
dispatcher(const dispatcher &)=delete
dispatcher & operator=(const dispatcher &)=delete
virtual ~dispatcher()
Class destructor.
void add_ex(std::string_view method, F &&f)
Adds a method handler with an extra parameter.
std::unique_ptr< dispatcher_private > d_ptr
Pointer to the implementation (Pimpl idiom).
JSON RPC Exception class.
exception(const exception &)=default
Default copy constructor.
~exception() override
Default destructor.
nlohmann::json m_data
Custom data associated with the error.
std::string m_message
Error message.
int code() const noexcept
Returns the error code.
const std::string & message() const noexcept
Returns the error message.
exception(exception &&)=default
Default move constructor.
exception(int code, std::string_view message)
Construct a new exception object.
exception & operator=(const exception &rhs)=default
Default copy assignment operator.
const nlohmann::json & data() const noexcept
Returns custom data associated with the error.
exception & operator=(exception &&rhs)=default
Default move assignment operator.
const char * what() const noexcept override
Returns the error message.
nlohmann::json to_json() const
Returns the error message as an Error Object.
exception(int code, std::string_view message, const T &data)
Construct a new exception object with additional data.
#define WWA_JSONRPC_EXPORT
Macro for exporting symbols when building the library dynamically or importing symbols when using the...
static constexpr int INVALID_PARAMS
Invalid method parameter(s).
static constexpr int INTERNAL_ERROR
Internal JSON-RPC error.
static constexpr int METHOD_NOT_FOUND
The method does not exist or is not available.
static constexpr int INVALID_REQUEST
The JSON sent is not a valid Request object.
static constexpr int PARSE_ERROR
Invalid JSON was received by the server.
static constexpr std::string_view err_method_not_found
Error message for when the method is not found.
static constexpr std::string_view err_not_jsonrpc_2_0_request
Error message for when the request is not a JSON-RPC 2.0 request.
static constexpr std::string_view err_empty_batch
Error message for when the batch request is empty.
static constexpr std::string_view err_empty_method
Error message for when the method is empty.
static constexpr std::string_view err_bad_params_type
Error message for when the parameters are not an array or an object.
static constexpr std::string_view err_invalid_params_passed_to_method
Error message for when the parameters passed to the method are not correct.
static constexpr std::string_view err_bad_id_type
Error message for when the ID is not a number, a string, or null.
constexpr auto convert_args(const nlohmann::json ¶ms, std::index_sequence< Indices... >)
Converts JSON parameters to a tuple of arguments based on the specified types.
constexpr auto make_inst_tuple(C inst)
Creates a tuple containing the instance if it is a class pointer, or an empty tuple if it is a null p...
Contains the implementation details of the JSON RPC library.
Primary template for function traits.