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>
82
83
84
85
86
87
88template<
typename R,
typename C,
typename... Args>
92
93
94
95
96
97
98template<
typename R,
typename C,
typename... Args>
102
103
104
105
106
107
108template<
typename R,
typename C,
typename... Args>
112
113
114
115
116
117
118template<
typename R,
typename C,
typename... Args>
122
123
124
125
126
127
128template<
typename R,
typename C,
typename... Args>
132
133
134
135
136
137
138template<
typename R,
typename C,
typename... Args>
142
143
144
145
146
147
148template<
typename R,
typename C,
typename... Args>
152
153
154
155
156
157
158template<
typename R,
typename C,
typename... Args>
162
163
164
165
166
167
168template<
typename R,
typename C,
typename... Args>
172
173
174
175
176
177
178template<
typename R,
typename C,
typename... Args>
182
183
184
185
186
187
188template<
typename R,
typename C,
typename... Args>
192
193
194
195
196
197
198template<
typename R,
typename C,
typename... Args>
202
203
204
205
206
207
208template<
typename R,
typename C,
typename... Args>
212
213
214
215
216
217
218template<
typename R,
typename C,
typename... Args>
222
223
224
225
226
227
228template<
typename R,
typename C,
typename... Args>
232
233
234
235
236
237
238template<
typename R,
typename C,
typename... Args>
242
243
244
245
246
247
248template<
typename R,
typename C,
typename... Args>
252
253
254
255
256
257
258template<
typename R,
typename C,
typename... Args>
262
263
264
265
266
267
268template<
typename R,
typename C,
typename... Args>
272
273
274
275
276
277
278template<
typename R,
typename C,
typename... Args>
282
283
284
285
286
287
288template<
typename R,
typename C,
typename... Args>
292
293
294
295
296
297
298template<
typename R,
typename C,
typename... Args>
302
303
304
305
306
307
308template<
typename R,
typename C,
typename... Args>
312
313
314
315
320
321
322
323
329
330
331
332
333
334
337
338
339
340
341
342template<std::size_t N,
typename Seq>
346
347
348
349
350
357
358
359
360
361
362template<std::size_t N,
typename Seq>
368
369
370
371
372
375
376
377
378
379
380
381
382
383
397
398
399
400
401
402
403
404
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433template<
typename F,
typename Tuple>
448
449
450
451
452
453
454
455
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480template<
typename Extra,
typename Args, std::size_t... Indices>
483 constexpr std::size_t offset = std::is_void_v<Extra> ? 0 : 1;
485 return std::make_tuple(params[Indices - offset].
template get<tuple_element<Indices, Args>>()...);
487 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.
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.
Primary template for function traits.
Template for creating an offset sequence.
Represents a JSON RPC request.