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

Private implementation of the JSON RPC dispatcher class. More...

#include <dispatcher_p.h>

+ Collaboration diagram for wwa::json_rpc::dispatcher_private:

Public Member Functions

void add_handler (std::string &&method, dispatcher::handler_t &&handler)
 Adds a method handler.
 
dispatcher::handler_t find_handler (const std::string &method) const
 Finds a method handler.
 

Static Public Member Functions

static std::uint64_t get_and_increment_counter () noexcept
 Generates a unique request ID.
 

Private Attributes

std::unordered_map< std::string, dispatcher::handler_tm_methods
 Map of method names to handler functions.
 

Static Private Attributes

static std::atomic_uint64_t m_id_counter = 0
 Counter for generating unique request IDs.
 

Detailed Description

Private implementation of the JSON RPC dispatcher class.

This class contains the private members and methods used by the dispatcher class to manage method handlers.

Definition at line 25 of file dispatcher_p.h.

Member Function Documentation

◆ add_handler()

void wwa::json_rpc::dispatcher_private::add_handler ( std::string && method,
dispatcher::handler_t && handler )
inline

Adds a method handler.

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 36 of file dispatcher_p.h.

37 {
38 this->m_methods.try_emplace(std::move(method), std::move(handler));
39 }
std::unordered_map< std::string, dispatcher::handler_t > m_methods
Map of method names to handler functions.

◆ find_handler()

dispatcher::handler_t wwa::json_rpc::dispatcher_private::find_handler ( const std::string & method) const
inline

Finds a method handler.

Parameters
methodThe name of the method.
Returns
The handler function for the specified method.
Return values
nullptrHandler not found

This method returns the handler function for the specified method name. If no handler is found, it returns a null pointer.

Definition at line 51 of file dispatcher_p.h.

52 {
53 if (const auto it = this->m_methods.find(method); it != this->m_methods.end()) {
54 return it->second;
55 }
56
57 return nullptr;
58 }

◆ get_and_increment_counter()

static std::uint64_t wwa::json_rpc::dispatcher_private::get_and_increment_counter ( )
inlinestaticnoexcept

Generates a unique request ID.

Returns
A unique request ID.

This method generates a unique request ID by incrementing an atomic counter.

Definition at line 67 of file dispatcher_p.h.

68 {
69 return dispatcher_private::m_id_counter.fetch_add(1, std::memory_order_relaxed);
70 }
static std::atomic_uint64_t m_id_counter
Counter for generating unique request IDs.

Member Data Documentation

◆ m_id_counter

std::atomic_uint64_t wwa::json_rpc::dispatcher_private::m_id_counter = 0
inlinestaticprivate

Counter for generating unique request IDs.

Definition at line 76 of file dispatcher_p.h.

◆ m_methods

std::unordered_map<std::string, dispatcher::handler_t> wwa::json_rpc::dispatcher_private::m_methods
private

Map of method names to handler functions.

Definition at line 74 of file dispatcher_p.h.


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