1#ifndef DE443A53_EEA9_4918_BCFB_AE76A19FB197
2#define DE443A53_EEA9_4918_BCFB_AE76A19FB197
5
6
7
8
9
10
11
12
13
14
15
16
17
18
24#include <nlohmann/json.hpp>
28
29
30
34
35
36
37
38
41
42
43
44
45
46
51
52
53
54
55
56template<
typename R,
typename... Args>
63
64
65
66
67
68template<
typename R,
typename... Args>
72
73
74
75
76
77
78template<
typename R,
typename C,
typename... Args>
85
86
87
88
89
90
91template<
typename R,
typename C,
typename... Args>
95
96
97
98
99
100
101template<
typename R,
typename C,
typename... Args>
105
106
107
108
109
110
111template<
typename R,
typename C,
typename... Args>
115
116
117
118
119
120
121template<
typename R,
typename C,
typename... Args>
125
126
127
128
129
130
131template<
typename R,
typename C,
typename... Args>
135
136
137
138
139
140
141template<
typename R,
typename C,
typename... Args>
145
146
147
148
149
150
151template<
typename R,
typename C,
typename... Args>
155
156
157
158
159
160template<
typename R,
typename... Args>
167
168
169
170
183
184
185
186
187
188
191
192
193
194
195
196template<std::size_t N,
typename Seq>
200
201
202
203
204
211
212
213
214
215
216template<std::size_t N,
typename Seq>
222
223
224
225
226
229
230
231
232
233
234
235
236
237
251
252
253
254
255
256
257
258
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287template<
typename F,
typename Tuple>
302
303
304
305
306
307
308
309
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334template<
typename Extra,
typename Args, std::size_t... Indices>
337 constexpr std::size_t offset = std::is_void_v<Extra> ? 0 : 1;
339 return std::make_tuple(params[Indices - offset].
template get<tuple_element<Indices, Args>>()...);
341 catch (
const nlohmann::json::exception& e) {
Private implementation of the JSON RPC dispatcher class.
static std::uint64_t get_and_increment_counter() noexcept
Generates a unique request ID.
A class that manages JSON RPC method handlers and processes JSON RPC requests.
virtual nlohmann::json do_process_request(const nlohmann::json &request, const std::any &data, bool is_batch, std::uint64_t unique_id)
Processes a single, non-batch JSON RPC request.
dispatcher & operator=(dispatcher &&rhs)=default
Move assignment operator.
dispatcher(dispatcher &&rhs)=default
Move constructor.
void add_ex(std::string_view method, F &&f, C instance)
Adds a method handler with a context parameter and a class instance.
constexpr auto create_closure(C inst, F &&f) const
Creates a closure for invoking a member function with JSON parameters.
virtual void request_parsed(const jsonrpc_request &request, const std::any &data, std::uint64_t unique_id)
Invoked after the request has been parsed.
void add_internal_method(std::string_view method, handler_t &&handler)
Adds a method handler for the specified method.
nlohmann::json process_request(const nlohmann::json &request, const std::any &data={})
Processes a JSON RPC request.
virtual void request_failed(const nlohmann::json &request_id, const std::exception *e, bool is_batch, std::uint64_t unique_id)
Invoked when a request fails.
virtual nlohmann::json invoke(const std::string &method, const nlohmann::json ¶ms, const dispatcher::context_t &ctx, std::uint64_t unique_id)
Invokes a method handler.
void add(std::string_view method, F &&f)
Adds a method handler f for the method method.
void add(std::string_view method, F &&f, C instance)
Adds a method to the dispatcher with the specified instance and function.
virtual nlohmann::json process_batch_request(const nlohmann::json &request, const std::any &data, std::uint64_t unique_id)
Processes a batch request.
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 a context parameter.
std::unique_ptr< dispatcher_private > d_ptr
Pointer to the implementation (Pimpl idiom).
JSON RPC Exception class.
Exception thrown when the method is not found.
method_not_found_exception()
#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 INVALID_REQUEST
The JSON sent is not a valid Request object.
typename offset_sequence< N, Seq >::type offset_sequence_t
Alias template for creating an offset sequence.
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.
Contains the implementation details of the JSON RPC library.
Specialization for member function pointers.
R return_type
The return type of the member function.
std::tuple< Args... > args_tuple
A tuple of the argument types.
Specialization for function pointers.
std::tuple< Args... > args_tuple
A tuple of the argument types.
R return_type
The return type of the function.
Specialization for std::function.
R return_type
The return type of the function.
std::tuple< Args... > args_tuple
A tuple of the argument types.
Primary template for function traits.
function_traits< decltype(&T::operator())> call_type
Type traits for the call operator.
typename call_type::return_type return_type
The return type of the functor.
typename call_type::args_tuple args_tuple
A tuple of the argument types.
Template for creating an offset sequence.
Represents a JSON RPC request.