Electroneum
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; \
uint64_t ticks = epee::misc_utils::get_tick_count(); \
epee::serialization::portable_storage ps; \
if (!ps.load_from_json(req_data)) \
{ \
epee::net_utils::jsonrpc2::make_error_resp_json(-32700, "Parse error", resp_data); \
return true; \
} \
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;
uint64_t get_tick_count()
::std::string string
Definition: gtest-port.h:1097
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
std::string & make_error_resp_json(int64_t code, const std::string &message, std::string &response_data, const epee::serialization::storage_entry &id=nullptr)
return true

Definition at line 11 of file jsonrpc_server_handlers_map.h.

◆ 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.

◆ 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"; \
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
LOG_PRINT("[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2);
uint64_t get_tick_count()
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
unsigned __int64 uint64_t
Definition: stdint.h:136

Definition at line 56 of file jsonrpc_server_handlers_map.h.

◆ 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; \
}
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
response< dummy_result, error > error_response

Definition at line 64 of file jsonrpc_server_handlers_map.h.

◆ 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_; \
epee::json_rpc::request<command_type::request>& req = static_cast<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; \
} \
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
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_); \
resp.jsonrpc = "2.0"; \
resp.id = req.id;
uint64_t get_tick_count()
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 41 of file jsonrpc_server_handlers_map.h.