Go to the documentation of this file. 1 #ifndef JSONRPC_SERVER_HANDLERS_MAP_H 2 #define JSONRPC_SERVER_HANDLERS_MAP_H 11 #define BEGIN_JSONRPC2_MAP(t_connection_context) \ 12 bool handle_rpc_request(const std::string& req_data, \ 13 std::string& resp_data, \ 14 t_connection_context& m_conn_context) \ 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)) \ 21 epee::net_utils::jsonrpc2::make_error_resp_json(-32700, "Parse error", resp_data); \ 24 epee::serialization::storage_entry id_; \ 25 id_ = epee::serialization::storage_entry(std::string()); \ 26 if (!ps.get_value("id", id_, nullptr)) \ 28 epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data); \ 31 std::string callback_name; \ 32 if (!ps.get_value("method", callback_name, nullptr)) \ 34 epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data, id_); \ 37 if (false) return true; //just a stub to have "else if" 41 #define PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \ 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_);\ 47 epee::net_utils::jsonrpc2::make_error_resp_json(-32602, "Invalid params", resp_data, req.id); \ 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"; \ 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); \ 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); 64 #define MAP_JSONRPC2_WE(method_name, callback_f, command_type) \ 65 else if (callback_name == method_name) \ 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)) \ 73 epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), resp_data, 0, false); \ 77 FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \ 81 #define END_JSONRPC2_MAP() \ 82 epee::net_utils::jsonrpc2::make_error_resp_json(-32601, "Method not found", resp_data, id_); \