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>
58 using return_type = R;
59 using args_tuple = std::tuple<Args...>;
63
64
65
66
67
68template<
typename R,
typename...
Args>
72
73
74
75
76
77
78template<
typename R,
typename C,
typename... Args>
80 using return_type = R;
81 using args_tuple = std::tuple<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>
162 using return_type = R;
163 using args_tuple = std::tuple<Args...>;
167
168
169
170
177 using return_type =
typename call_type::return_type;
178 using args_tuple =
typename call_type::args_tuple;
183
184
185
186
187
188
191
192
193
194
195
196template<std::size_t N,
typename Seq>
197struct offset_sequence;
200
201
202
203
204
211
212
213
214
215
216template<std::size_t N,
typename Seq>
217using offset_sequence_t =
typename offset_sequence<N, Seq>::type;
222
223
224
225
226
229
230
231
232
233
234
235
236
237
251
252
253
254
255
256
257
258
259
260
261
262template<
typename Extra>
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298template<
typename F,
typename Tuple>
313
314
315
316
317
318
319
320
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345template<
typename Extra,
typename Args, std::size_t... Indices>
348 constexpr std::size_t offset = std::is_void_v<Extra> ? 0 : 1;
350 return std::make_tuple(params[Indices - offset].
template get<tuple_element<Indices, Args>>()...);
352 catch (
const nlohmann::json::exception& e) {
353 throw wwa::json_rpc::exception(wwa::json_rpc::exception::INVALID_PARAMS, e.what());
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).
#define WWA_JSONRPC_EXPORT
Macro for exporting symbols when building the library dynamically or importing symbols when using the...
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.