Electroneum
Loading...
Searching...
No Matches
jsonrpc_server_handlers_map.h File Reference
Include dependency graph for jsonrpc_server_handlers_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BEGIN_JSONRPC2_MAP(t_connection_context)
#define PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type)
#define FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name)
#define MAP_JSONRPC2_WE(method_name, callback_f, command_type)
#define END_JSONRPC2_MAP()

Macro Definition Documentation

◆ BEGIN_JSONRPC2_MAP

#define BEGIN_JSONRPC2_MAP ( t_connection_context)
Value:
bool handle_rpc_request(const std::string& req_data, \
std::string& resp_data, \
t_connection_context& m_conn_context) \
{ \
bool handled = false; \
if (!ps.load_from_json(req_data)) \
{ \
epee::net_utils::jsonrpc2::make_error_resp_json(-32700, "Parse error", resp_data); \
return true; \
} \
id_ = epee::serialization::storage_entry(std::string()); \
if (!ps.get_value("id", id_, nullptr)) \
{ \
epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data); \
return true; \
} \
std::string callback_name; \
if (!ps.get_value("method", callback_name, nullptr)) \
{ \
epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data, id_); \
return true; \
} \
if (false) return true;
bool get_value(const std::string &value_name, t_value &val, hsection hparent_section)
bool load_from_json(const std::string &source)
uint64_t get_tick_count()
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
#define true
unsigned __int64 uint64_t
Definition stdint.h:136

Definition at line 11 of file jsonrpc_server_handlers_map.h.

11#define BEGIN_JSONRPC2_MAP(t_connection_context) \
12bool handle_rpc_request(const std::string& req_data, \
13 std::string& resp_data, \
14 t_connection_context& m_conn_context) \
15{ \
16 bool handled = false; \
17 uint64_t ticks = epee::misc_utils::get_tick_count(); \
18 epee::serialization::portable_storage ps; \
19 if (!ps.load_from_json(req_data)) \
20 { \
21 epee::net_utils::jsonrpc2::make_error_resp_json(-32700, "Parse error", resp_data); \
22 return true; \
23 } \
24 epee::serialization::storage_entry id_; \
25 id_ = epee::serialization::storage_entry(std::string()); \
26 if (!ps.get_value("id", id_, nullptr)) \
27 { \
28 epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data); \
29 return true; \
30 } \
31 std::string callback_name; \
32 if (!ps.get_value("method", callback_name, nullptr)) \
33 { \
34 epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data, id_); \
35 return true; \
36 } \
37 if (false) return true; //just a stub to have "else if"

◆ END_JSONRPC2_MAP

#define END_JSONRPC2_MAP ( )
Value:
epee::net_utils::jsonrpc2::make_error_resp_json(-32601, "Method not found", resp_data, id_); \
return true; \
}
std::string & make_error_resp_json(int64_t code, const std::string &message, std::string &response_data, const epee::serialization::storage_entry &id=nullptr)

Definition at line 81 of file jsonrpc_server_handlers_map.h.

81#define END_JSONRPC2_MAP() \
82 epee::net_utils::jsonrpc2::make_error_resp_json(-32601, "Method not found", resp_data, id_); \
83 return true; \
84}

◆ FINALIZE_JSONRPC2_OBJECTS_TO_JSON

#define FINALIZE_JSONRPC2_OBJECTS_TO_JSON ( method_name)
Value:
epee::serialization::store_t_to_json(resp, resp_data, 0, false); \
resp_data += "\n"; \
LOG_PRINT("[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2);

Definition at line 56 of file jsonrpc_server_handlers_map.h.

56#define FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \
57 uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
58 epee::serialization::store_t_to_json(resp, resp_data, 0, false); \
59 resp_data += "\n"; \
60 uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
61 LOG_PRINT("[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2);

◆ MAP_JSONRPC2_WE

#define MAP_JSONRPC2_WE ( method_name,
callback_f,
command_type )
Value:
else if (callback_name == method_name) \
{ \
PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \
fail_resp.jsonrpc = "2.0"; \
fail_resp.id = req.id; \
if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), resp_data, 0, false); \
resp_data += "\n"; \
return true; \
} \
FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \
return true; \
}
#define AUTO_VAL_INIT(v)
response< dummy_result, error > error_response
epee::serialization::storage_entry id

Definition at line 64 of file jsonrpc_server_handlers_map.h.

64#define MAP_JSONRPC2_WE(method_name, callback_f, command_type) \
65 else if (callback_name == method_name) \
66 { \
67 PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \
68 epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
69 fail_resp.jsonrpc = "2.0"; \
70 fail_resp.id = req.id; \
71 if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
72 { \
73 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), resp_data, 0, false); \
74 resp_data += "\n"; \
75 return true; \
76 } \
77 FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \
78 return true; \
79 }

◆ PREPARE_JSONRPC2_OBJECTS_FROM_JSON

#define PREPARE_JSONRPC2_OBJECTS_FROM_JSON ( command_type)
Value:
handled = true; \
boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
if(!req.load(ps)) \
{ \
epee::net_utils::jsonrpc2::make_error_resp_json(-32602, "Invalid params", resp_data, req.id); \
return true; \
} \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
resp.jsonrpc = "2.0"; \
resp.id = req.id;
epee::serialization::storage_entry id

Definition at line 41 of file jsonrpc_server_handlers_map.h.

41#define PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \
42 handled = true; \
43 boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
44 epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
45 if(!req.load(ps)) \
46 { \
47 epee::net_utils::jsonrpc2::make_error_resp_json(-32602, "Invalid params", resp_data, req.id); \
48 return true; \
49 } \
50 uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
51 boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
52 epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
53 resp.jsonrpc = "2.0"; \
54 resp.id = req.id;