JSON RPC
JSON-RPC 2.0 library for C++
wwa::json_rpc::dispatcher Class Reference

A class that manages JSON RPC method handlers and processes JSON RPC requests. More...

#include <dispatcher.h>

+ Collaboration diagram for wwa::json_rpc::dispatcher:

Public Types

using context_t = std::pair<std::any, nlohmann::json>
 Optional context data for method handlers.
 

Public Member Functions

 dispatcher ()
 Class constructor.
 
 dispatcher (const dispatcher &)=delete
 
 dispatcher (dispatcher &&rhs)=default
 Move constructor.
 
virtual ~dispatcher ()
 Class destructor.
 
template<typename F>
void add (std::string_view method, F &&f)
 Adds a method handler f for the method method.
 
template<typename C, typename F>
void add (std::string_view method, F &&f, C instance)
 Adds a method to the dispatcher with the specified instance and function.
 
template<typename F>
void add_ex (std::string_view method, F &&f)
 Adds a method handler with a context parameter.
 
template<typename C, typename F>
void add_ex (std::string_view method, F &&f, C instance)
 Adds a method handler with a context parameter and a class instance.
 
dispatcheroperator= (const dispatcher &)=delete
 
dispatcheroperator= (dispatcher &&rhs)=default
 Move assignment operator.
 
nlohmann::json process_request (const nlohmann::json &request, const std::any &data={})
 Processes a JSON RPC request.
 

Protected Member Functions

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.
 
virtual nlohmann::json invoke (const std::string &method, const nlohmann::json &params, const dispatcher::context_t &ctx, std::uint64_t unique_id)
 Invokes a method handler.
 
virtual nlohmann::json process_batch_request (const nlohmann::json &request, const std::any &data, std::uint64_t unique_id)
 Processes a batch 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 void request_parsed (const jsonrpc_request &request, const std::any &data, std::uint64_t unique_id)
 Invoked after the request has been parsed.
 

Private Types

using handler_t = std::function<nlohmann::json(const context_t& ctx, const nlohmann::json& params)>
 Method handler type.
 

Private Member Functions

void add_internal_method (std::string_view method, handler_t &&handler)
 Adds a method handler for the specified method.
 
template<typename C, typename F, typename Context, typename Args>
constexpr auto create_closure (C inst, F &&f) const
 Creates a closure for invoking a member function with JSON parameters.
 

Private Attributes

std::unique_ptr< dispatcher_privated_ptr
 Pointer to the implementation (Pimpl idiom).
 

Friends

class dispatcher_private
 

Detailed Description

A class that manages JSON RPC method handlers and processes JSON RPC requests.

The dispatcher class allows adding method handlers for JSON RPC methods and processes JSON RPC requests. It supports adding plain functions, static class methods, lambda functions, and member functions as handlers. The handlers can accept and return values that can be converted to and from nlohmann::json values.

Note
The dispatcher class is non-copyable but movable.

The dispatcher class provides the following functionalities:

  • Adding method handlers for JSON RPC methods.
  • Parsing and processing JSON RPC requests.
  • Invoking method handlers with the appropriate arguments.
  • Handling exceptions thrown by method handlers and returning appropriate JSON RPC error responses.
Example Usage:
d.add("subtract", [](const nlohmann::json& params) {
int minuend = params["minuend"];
int subtrahend = params["subtrahend"];
return minuend - subtrahend;
});
const auto request = R"({"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 1})";
const auto response = d.process_request(nlohmann::json::parse(request)).dump();
nlohmann::json process_request(const nlohmann::json &request, const std::any &data={})
Processes a JSON RPC request.
void add(std::string_view method, F &&f)
Adds a method handler f for the method method.
Definition dispatcher.h:203
dispatcher()
Class constructor.
Adding Method Handlers:
Method handlers can be added using the add method. The handler function can accept any number of arguments as long as they can be converted from a nlohmann::json value. The handler function can also return any type that can be converted to a nlohmann::json value.
Handling Exceptions:
If a handler function throws an exception derived from std::exception, the exception will be caught and an appropriate JSON RPC error response will be returned.

Definition at line 77 of file dispatcher.h.

Member Typedef Documentation

◆ context_t

using wwa::json_rpc::dispatcher::context_t = std::pair<std::any, nlohmann::json>

Optional context data for method handlers.

This type alias defines a context data type that can be passed to method handlers. The context data is a pair of two values:

  • The first value is an std::any object that is passed to the process_request() method;
  • The second value is a nlohmann::json object that contains additional fields extracted from the JSON RPC request.

Definition at line 87 of file dispatcher.h.

◆ handler_t

using wwa::json_rpc::dispatcher::handler_t = std::function<nlohmann::json(const context_t& ctx, const nlohmann::json& params)>
private

Method handler type.

This type alias defines a method handler function that takes two parameters:

  • ctx: An additional parameter that can be used to pass additional information to the handler.
  • params: A JSON object containing the parameters for the method.

The handler function returns a JSON object as a result.

This type alias is used to define the signature of functions that handle method calls in the dispatcher.

Definition at line 103 of file dispatcher.h.

Constructor & Destructor Documentation

◆ dispatcher() [1/3]

wwa::json_rpc::dispatcher::dispatcher ( )

Class constructor.

Definition at line 14 of file dispatcher.cpp.

14: d_ptr(std::make_unique<dispatcher_private>()) {}
std::unique_ptr< dispatcher_private > d_ptr
Pointer to the implementation (Pimpl idiom).
Definition dispatcher.h:411

◆ ~dispatcher()

wwa::json_rpc::dispatcher::~dispatcher ( )
virtualdefault

Class destructor.

◆ dispatcher() [2/3]

wwa::json_rpc::dispatcher::dispatcher ( const dispatcher & )
delete

◆ dispatcher() [3/3]

wwa::json_rpc::dispatcher::dispatcher ( dispatcher && rhs)
default

Move constructor.

Parameters
rhsRight-hand side object.

Member Function Documentation

◆ add() [1/2]

template<typename F>
void wwa::json_rpc::dispatcher::add ( std::string_view method,
F && f )
inline

Adds a method handler f for the method method.

Template Parameters
FType of the handler function f.
Parameters
methodThe name of the method to add the handler for.
fThe handler function.

This overload is used to add a plain function, a static class method, or a lambda function as a handler.

Internally, the handler is a function that accepts a nlohmann::json as its argument and returns a nlohmann::json value. However, the handler function can accept any number of arguments, as long as they can be converted from a nlohmann::json value. The same is true for the return value: it can be any type that can be converted to a nlohmann::json value (or void). Of course, the handler can accept and/or return nlohmann::json values directly.

Accepting Arguments in a Handler:
The Specification defines two types of parameters: named and positional. Since there is no easy way to match named parameters to the handler function arguments, the named parameters are treated as a single structured value.
For example, if the parameters are passed like this: "params": {"subtrahend": 23, "minuend": 42}, the handler function must accept a single argument of a struct type:
struct subtract_params {
int minuend;
int subtrahend;
};
int subtract(const subtract_params& params)
{
return params.minuend - params.subtrahend;
}
Because there is no automatic conversion from a JSON object to subtract_params, you must define the conversion function yourself. The easiest way is to use a macro:
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subtract_params, minuend, subtrahend);
In the case of positional parameters, the handler function must accept the same number of arguments as the number of parameters passed in the request.
If the handler needs to accept a variable number of arguments, it must accept a single nlohmann::json argument and parse it as needed, like this:
dispatcher.add("sum", [](const nlohmann::json& params) {
std::vector<int> v;
params.get_to(v);
return std::accumulate(v.begin(), v.end(), 0);
});
Note
If the handler accepts a single nlohmann::json argument, it will accept any parameters. For example:
void handler(const nlohmann::json& params)
{
if (params.is_null()) {
// No parameters
}
else if (params.is_array()) {
// Array of positional parameters
}
else if (params.is_object()) {
// Named parameters
}
}
Returning Values from a Handler:
  1. The handler can return any value as long as it can be converted to a nlohmann::json value. If there is no default conversion available, the handler can either return a nlohmann::json value directly, or use a custom to_json() function.
  2. If the handler function returns void, it will be automatically converted to null in the JSON response.
Exception Handling:
If the hander function throws an exception (derived from std::exception), the exception will be caught, and the error will be returned in the JSON response:
  1. json_rpc::exception will be converted to a JSON RPC error object using json_rpc::exception::to_json();
  2. other exceptions derived from std::exception will be converted to a JSON RPC error object with code -32603 (exception::INTERNAL_ERROR) and the exception message (what()) as the error message.

Definition at line 203 of file dispatcher.h.

204 {
205 this->add(method, std::forward<F>(f), nullptr);
206 }

◆ add() [2/2]

template<typename C, typename F>
void wwa::json_rpc::dispatcher::add ( std::string_view method,
F && f,
C instance )
inline

Adds a method to the dispatcher with the specified instance and function.

Template Parameters
CThe type of the class instance.
FThe type of the function to be added.
Parameters
methodThe name of the method to be added.
fThe function to be added, which will be bound to the instance.
instanceThe instance of the class to which the function belongs. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This template method allows adding a method to the dispatcher by binding a member function of a class instance. It uses function traits to deduce the argument types and creates a closure that is then added to the internal method map.

Definition at line 221 of file dispatcher.h.

222 {
223 using traits = details::function_traits<std::decay_t<F>>;
224 using ArgsTuple = typename traits::args_tuple;
225
226 const auto&& closure = this->create_closure<C, F, void, ArgsTuple>(instance, std::forward<F>(f));
227 this->add_internal_method(method, std::forward<decltype(closure)>(closure));
228 }
constexpr auto create_closure(C inst, F &&f) const
Creates a closure for invoking a member function with JSON parameters.
Definition dispatcher.h:453
void add_internal_method(std::string_view method, handler_t &&handler)
Adds a method handler for the specified method.

◆ add_ex() [1/2]

template<typename F>
void wwa::json_rpc::dispatcher::add_ex ( std::string_view method,
F && f )
inline

Adds a method handler with a context parameter.

Template Parameters
FThe type of the handler function.
Parameters
methodThe name of the method to add the handler for.
fThe handler function.

This method allows adding a handler function with an additional context parameter. The context parameter can be used to pass additional information to the handler function. The handler function can accept any number of arguments as long as they can be converted from a nlohmann::json value. The same is true for the return value: it can be any type that can be converted to a nlohmann::json value (or void).

This overload is used to add a plain function, a static class method, or a lambda function as a handler.

Sample Usage:
struct extra_params {
std::string ip;
};
dispatcher.add_ex("sum", [](const std::any& extra, const nlohmann::json& params) {
std::cout << "Invoking sum() method for " << std::any_cast<extra_params>(extra).ip << "\n";
std::vector<int> v;
params.get_to(v);
return std::accumulate(v.begin(), v.end(), 0);
});
A class that manages JSON RPC method handlers and processes JSON RPC requests.
Definition dispatcher.h:77
void add_ex(std::string_view method, F &&f)
Adds a method handler with a context parameter.
Definition dispatcher.h:263

See process_request() for more details on the extra parameter.

See also
add()

Definition at line 263 of file dispatcher.h.

264 {
265 this->add_ex(method, std::forward<F>(f), nullptr);
266 }

◆ add_ex() [2/2]

template<typename C, typename F>
void wwa::json_rpc::dispatcher::add_ex ( std::string_view method,
F && f,
C instance )
inline

Adds a method handler with a context parameter and a class instance.

Template Parameters
CThe type of the class instance.
FThe type of the handler function.
Parameters
methodThe name of the method to add the handler for.
fThe handler function.
instanceThe instance of the class to which the function belongs.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This method allows adding a class method handler with an additional context parameter. The context parameter can be used to pass additional information to the handler function. The handler function can accept any number of arguments as long as they can be converted from a nlohmann::json value. The same is true for the return value: it can be any type that can be converted to a nlohmann::json value (or void).

See also
add()

Definition at line 286 of file dispatcher.h.

287 {
288 using traits = details::function_traits<std::decay_t<F>>;
289 using ArgsTuple = typename traits::args_tuple;
290
291 static_assert(
292 std::tuple_size<std::decay_t<ArgsTuple>>::value > 0,
293 "Handler function must accept the `context` argument. Use `add()` for handlers without the `context` "
294 "argument."
295 );
296
297 const auto&& closure = this->create_closure<C, F, context_t, ArgsTuple>(instance, std::forward<F>(f));
298 this->add_internal_method(method, std::forward<decltype(closure)>(closure));
299 }

◆ add_internal_method()

void wwa::json_rpc::dispatcher::add_internal_method ( std::string_view method,
handler_t && handler )
private

Adds a method handler for the specified method.

Parameters
methodThe name of the method.
handlerThe handler function.

This method registers a handler function for a given method name. The handler function will be invoked when a request for the specified method is received.

Definition at line 18 of file dispatcher.cpp.

19{
20 this->d_ptr->add_handler(std::string(method), std::move(handler));
21}

◆ create_closure()

template<typename C, typename F, typename Context, typename Args>
auto wwa::json_rpc::dispatcher::create_closure ( C inst,
F && f ) const
inlineconstexprprivate

Creates a closure for invoking a member function with JSON parameters.

Template Parameters
CThe type of the class instance (can be a pointer or null pointer).
FThe type of the member function (if C is not std::nullptr_t) or the function.
ContextThe type of the context parameter that can be passed to the member function (can be void or context_t).
ArgsThe type of the arguments tuple.
Parameters
instThe instance of the class (can be a pointer or null pointer).
fThe member function to be invoked.
Returns
A lambda function that takes a JSON object as a parameter and invokes the member function with the appropriate arguments.

This method creates a closure (lambda function) that can be used to invoke a member function with arguments extracted from a JSON object.

The closure performs the following steps:

  1. Checks if the JSON object is an array.
  2. If the JSON object is an array and the member function takes a single argument of type nlohmann::json, it directly passes the JSON object to the member function.
  3. If the JSON object is an array and the number of elements matches the number of arguments expected by the member function, it extracts the arguments from the JSON array and invokes the member function.
  4. If the JSON object is not an array or the number of elements does not match the number of arguments, it throws a json_rpc::exception with the exception::INVALID_PARAMS code.

The invoke_function method is used to invoke the member function with the extracted arguments.

The std::apply function is used to unpack the tuple and pass the arguments to the member function.

Compile-time checks ensure that the code is type-safe and that certain conditions are met before the code is compiled. This helps catch potential errors early in the development process and improves the overall robustness of the code.

Definition at line 453 of file dispatcher.h.

454 {
455 static_assert((std::is_pointer_v<C> && std::is_class_v<std::remove_pointer_t<C>>) || std::is_null_pointer_v<C>);
456 return [func = std::forward<F>(f), inst](const context_t& ctx, const nlohmann::json& params) {
457 assert(params.is_array());
458 constexpr auto args_size = std::tuple_size<std::decay_t<Args>>::value;
459 constexpr auto arg_pos = std::is_void_v<Context> ? 0 : 1;
460
461 if constexpr (args_size == arg_pos + 1) {
462 if constexpr (std::is_same_v<std::decay_t<std::tuple_element_t<arg_pos, Args>>, nlohmann::json>) {
463 auto&& tuple_args = std::tuple_cat(
465 std::make_tuple(params)
466 );
467
468 return details::invoke_function(func, std::forward<decltype(tuple_args)>(tuple_args));
469 }
470 }
471
472 if (params.size() + arg_pos == args_size) {
473 constexpr auto offset = std::is_void_v<Context> ? 0U : 1U;
474 auto&& tuple_args = std::tuple_cat(
477 params, details::offset_sequence_t<offset, std::make_index_sequence<args_size - offset>>{}
478 )
479 );
480
481 return details::invoke_function(func, std::forward<decltype(tuple_args)>(tuple_args));
482 }
483
485 };
486 }
std::pair< std::any, nlohmann::json > context_t
Optional context data for method handlers.
Definition dispatcher.h:87
static constexpr int INVALID_PARAMS
Invalid method parameter(s).
Definition exception.h:115
static constexpr std::string_view err_invalid_params_passed_to_method
Error message for when the parameters passed to the method are not correct.
Definition exception.h:44
typename offset_sequence< N, Seq >::type offset_sequence_t
Alias template for creating an offset sequence.
Definition details.h:217
constexpr auto convert_args(const nlohmann::json &params, std::index_sequence< Indices... >)
Converts JSON parameters to a tuple of arguments based on the specified types.
Definition details.h:335
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...
Definition details.h:239
constexpr auto make_context_tuple(const std::pair< std::any, nlohmann::json > &ctx)
Creates a tuple from the provided context object based on the type of Context.
Definition details.h:260
nlohmann::json invoke_function(F &&f, Tuple &&tuple)
Invokes a function with the provided arguments handling void return type.
Definition details.h:288

◆ do_process_request()

nlohmann::json wwa::json_rpc::dispatcher::do_process_request ( const nlohmann::json & request,
const std::any & data,
bool is_batch,
std::uint64_t unique_id )
protectedvirtual

Processes a single, non-batch JSON RPC request.

Parameters
requestThe JSON RPC request as a JSON object.
dataAdditional information to pass to the method handlers as a part of the context.
is_batchIndicates whether the request is a part of a batch request.
unique_idThe unique request ID.
Returns
JSON response.

This method processes a JSON RPC request by invoking the method handlers for the specified method. If the request is a batch request, it will call process_batch_request().

Definition at line 34 of file dispatcher.cpp.

35{
36 nlohmann::json discarded = nlohmann::json::value_t::discarded;
37
38 auto request_id = get_request_id(request);
39 bool is_discarded = false;
40 try {
41 const auto req = jsonrpc_request::from_json(request);
42 this->request_parsed(req, data, unique_id);
43 is_discarded = req.id.is_discarded();
44
45 const dispatcher::context_t ctx = std::make_pair(data, req.extra);
46 const auto res = this->invoke(req.method, req.params, ctx, unique_id);
47 if (!request_id.is_null()) {
48 // clang-format off
49 return {
50 {"jsonrpc", "2.0"},
51 {"result", res},
52 {"id", req.id}
53 };
54 // clang-format on
55 }
56
57 return discarded;
58 }
59 catch (const std::exception& e) {
60 this->request_failed(request_id, &e, false, unique_id);
61 const auto* eptr = dynamic_cast<const exception*>(&e);
62 const auto ex = eptr != nullptr ? *eptr : exception(exception::INTERNAL_ERROR, e.what());
63 return is_discarded ? discarded : generate_error_response(ex, request_id);
64 }
65}
virtual void request_parsed(const jsonrpc_request &request, const std::any &data, std::uint64_t unique_id)
Invoked after the request has been parsed.
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 &params, const dispatcher::context_t &ctx, std::uint64_t unique_id)
Invokes a method handler.
static constexpr int INTERNAL_ERROR
Internal JSON-RPC error.
Definition exception.h:120
WWA_JSONRPC_EXPORT nlohmann::json generate_error_response(const exception &e, const nlohmann::json &id=nlohmann::json::value_t::null)
Generates an error response.
Definition utils.cpp:43
WWA_JSONRPC_EXPORT nlohmann::json get_request_id(const nlohmann::json &request)
Get the request id object.
Definition utils.cpp:17
static jsonrpc_request from_json(const nlohmann::json &request)
Parses and validates a JSON RPC request.
Definition request.cpp:62

◆ invoke()

nlohmann::json wwa::json_rpc::dispatcher::invoke ( const std::string & method,
const nlohmann::json & params,
const dispatcher::context_t & ctx,
std::uint64_t unique_id )
protectedvirtual

Invokes a method handler.

Parameters
methodThe name of the method to invoke.
paramsThe parameters for the method.
ctxThe context to pass to the method handlers.
unique_idThe unique request ID.
Returns
The result of the method invocation as a JSON object.

This method finds the handler for the specified method and invokes it with the provided parameters.

Exceptions
exceptionIf the method is not found or the invocation fails.
See also
exception::METHOD_NOT_FOUND

Definition at line 100 of file dispatcher.cpp.

103{
104 if (const auto handler = this->d_ptr->find_handler(method); handler != nullptr) {
105 return handler(ctx, params);
106 }
107
108 throw method_not_found_exception();
109}

◆ operator=() [1/2]

dispatcher & wwa::json_rpc::dispatcher::operator= ( const dispatcher & )
delete

◆ operator=() [2/2]

dispatcher & wwa::json_rpc::dispatcher::operator= ( dispatcher && rhs)
default

Move assignment operator.

Parameters
rhsRight-hand side object.
Returns
Reference to this object.

◆ process_batch_request()

nlohmann::json wwa::json_rpc::dispatcher::process_batch_request ( const nlohmann::json & request,
const std::any & data,
std::uint64_t unique_id )
protectedvirtual

Processes a batch request.

Parameters
requestThe batch request as a JSON array.
dataAdditional information to pass to the method handlers as a part of the context.
unique_idThe unique request ID.
Returns
The response as a JSON array.

This method processes a batch request by invoking the method handlers for each request in the batch.

Definition at line 68 of file dispatcher.cpp.

69{
70 if (request.empty()) {
72 this->request_failed(nullptr, &e, true, unique_id);
73 return generate_error_response(e, nlohmann::json(nullptr));
74 }
75
76 auto response = nlohmann::json::array();
77 for (const auto& req : request) {
78 if (!req.is_object()) {
80 this->request_failed(nullptr, &e, false, unique_id);
81
82 response.push_back(generate_error_response(e, nlohmann::json(nullptr)));
83 }
84 else if (const auto res =
86 !res.is_discarded())
87 {
88 response.push_back(res);
89 }
90 }
91
92 return response.empty() ? nlohmann::json(nlohmann::json::value_t::discarded) : response;
93}
static std::uint64_t get_and_increment_counter() noexcept
Generates a unique request ID.
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.
static constexpr int INVALID_REQUEST
The JSON sent is not a valid Request object.
Definition exception.h:105
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.
Definition exception.h:31
static constexpr std::string_view err_empty_batch
Error message for when the batch request is empty.
Definition exception.h:77

◆ process_request()

nlohmann::json wwa::json_rpc::dispatcher::process_request ( const nlohmann::json & request,
const std::any & data = {} )

Processes a JSON RPC request.

Parameters
requestThe JSON RPC request as a nlohmann::json object.
dataOptional data that can be passed to the handler function (only for handlers added with add_ex()).
Returns
The response as a nlohmann::json object. If the request is a Notification, it will be of the discarded_t type.

This method processes a JSON RPC request.

Exceptions derived from std::exception thrown by the handler function are caught and returned as JSON RPC error responses:

For the handlers that accept the context parameter, this method will construct the context as follows:

  1. The data parameter will be passed as the first element of the context tuple.
  2. The extra fields from the JSON RPC request will be passed as the second element of the context tuple as a JSON object.

For example, given this request:

{
"jsonrpc": "2.0",
"method": "subtract",
"params": {"minuend": 42, "subtrahend": 23},
"id": 1,
"auth": "secret",
"user": "admin"
}

and data set to std::string("some_data"), the context parameter passed to the handler will be a pair of values:

  • std::string("some_data") as std::any;
  • nlohmann::json representing the object { "auth": "secret", "user": "admin" }.

Definition at line 23 of file dispatcher.cpp.

24{
25 const auto unique_id = dispatcher_private::get_and_increment_counter();
26 if (request.is_array()) {
27 return this->process_batch_request(request, data, unique_id);
28 }
29
30 return this->do_process_request(request, data, false, unique_id);
31}
virtual nlohmann::json process_batch_request(const nlohmann::json &request, const std::any &data, std::uint64_t unique_id)
Processes a batch request.

◆ request_failed()

void wwa::json_rpc::dispatcher::request_failed ( const nlohmann::json & request_id,
const std::exception * e,
bool is_batch,
std::uint64_t unique_id )
protectedvirtual

Invoked when a request fails.

Parameters
request_idJSON RPC request ID.
eException that is the reason for the failure.
is_batchWhether this is a top-level batch request.
unique_idUnique request ID.

Definition at line 111 of file dispatcher.cpp.

112{
113 // Do nothing
114}

◆ request_parsed()

void wwa::json_rpc::dispatcher::request_parsed ( const jsonrpc_request & request,
const std::any & data,
std::uint64_t unique_id )
protectedvirtual

Invoked after the request has been parsed.

Parameters
requestThe parsed request.
dataAdditional information to pass to the method handlers as a part of the context.
unique_idThe unique request ID.

Definition at line 95 of file dispatcher.cpp.

96{
97 // Do nothing
98}

Friends And Related Symbol Documentation

◆ dispatcher_private

friend class dispatcher_private
friend

Definition at line 90 of file dispatcher.h.

Member Data Documentation

◆ d_ptr

std::unique_ptr<dispatcher_private> wwa::json_rpc::dispatcher::d_ptr
private

Pointer to the implementation (Pimpl idiom).

This unique pointer holds the private implementation details of the dispatcher class. It is used to hide the implementation details and reduce compilation dependencies.

Definition at line 411 of file dispatcher.h.


The documentation for this class was generated from the following files: