From 9193d6fb5be92df732af18b08b1e052f84cc2f9d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 29 Jan 2015 17:10:53 -0500 Subject: Daemonize changes pulled in -- daemon builds many RPC functions added by the daemonize changes (and related changes on the upstream dev branch that were not merged) were commented out (apart from return). Other than that, this *should* work...at any rate, it builds, and that's something. --- contrib/epee/include/console_handler.h | 105 ++++++++++++++++----------------- 1 file changed, 51 insertions(+), 54 deletions(-) (limited to 'contrib/epee') diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index ab3cf67c6..147fd9ce0 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -26,11 +26,13 @@ #pragma once +#include "misc_log_ex.h" #include #include #include #include #include +#include namespace epee { @@ -290,7 +292,7 @@ namespace epee private: async_stdin_reader m_stdin_reader; - bool m_running = true; + std::atomic m_running = {true}; }; @@ -350,17 +352,11 @@ namespace epee return true; }*/ - /************************************************************************/ - /* */ - /************************************************************************/ - class console_handlers_binder - { - typedef boost::function &)> console_command_handler; - typedef std::map > command_handlers_map; - std::unique_ptr m_console_thread; - command_handlers_map m_command_handlers; - async_console_handler m_console_handler; + class command_handler { public: + typedef boost::function &)> callback; + typedef std::map > lookup; + std::string get_usage() { std::stringstream ss; @@ -376,12 +372,14 @@ namespace epee } return ss.str(); } - void set_handler(const std::string& cmd, const console_command_handler& hndlr, const std::string& usage = "") + + void set_handler(const std::string& cmd, const callback& hndlr, const std::string& usage = "") { - command_handlers_map::mapped_type & vt = m_command_handlers[cmd]; + lookup::mapped_type & vt = m_command_handlers[cmd]; vt.first = hndlr; vt.second = usage; } + bool process_command_vec(const std::vector& cmd) { if(!cmd.size()) @@ -399,14 +397,20 @@ namespace epee boost::split(cmd_v,cmd,boost::is_any_of(" "), boost::token_compress_on); return process_command_vec(cmd_v); } + private: + lookup m_command_handlers; + }; - /*template - bool start_handling(t_srv& srv, const std::string& usage_string = "") - { - start_default_console_handler_no_srv_param(&srv, boost::bind(&console_handlers_binder::process_command_str, this, _1)); - return true; - }*/ - + /************************************************************************/ + /* */ + /************************************************************************/ + class console_handlers_binder : public command_handler + { + typedef command_handler::callback console_command_handler; + typedef command_handler::lookup command_handlers_map; + std::unique_ptr m_console_thread; + async_console_handler m_console_handler; + public: bool start_handling(const std::string& prompt, const std::string& usage_string = "") { m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string))); @@ -423,40 +427,33 @@ namespace epee { return m_console_handler.run(boost::bind(&console_handlers_binder::process_command_str, this, _1), prompt, usage_string); } - - /*template - bool run_handling(t_srv& srv, const std::string& usage_string) - { - return run_default_console_handler_no_srv_param(&srv, boost::bind(&console_handlers_binder::process_command_str, this, _1), usage_string); - }*/ }; - /* work around because of broken boost bind */ - template - class srv_console_handlers_binder: public console_handlers_binder - { - bool process_command_str(t_server* /*psrv*/, const std::string& cmd) - { - return console_handlers_binder::process_command_str(cmd); - } - public: - bool start_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string = "") - { - boost::thread(boost::bind(&srv_console_handlers_binder::run_handling, this, psrv, prompt, usage_string)).detach(); - return true; - } - - bool run_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string) - { - return m_console_handler.run(psrv, boost::bind(&srv_console_handlers_binder::process_command_str, this, _1, _2), prompt, usage_string); - } - - void stop_handling() - { - m_console_handler.stop(); - } - - private: - async_console_handler m_console_handler; - }; + ///* work around because of broken boost bind */ + //template + //class srv_console_handlers_binder: public command_handler + //{ + // async_console_handler m_console_handler; + //public: + // bool start_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string = "") + // { + // boost::thread(boost::bind(&srv_console_handlers_binder::run_handling, this, psrv, prompt, usage_string)).detach(); + // return true; + // } + + // bool run_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string) + // { + // return m_console_handler.run(psrv, boost::bind(&srv_console_handlers_binder::process_command_str, this, _1, _2), prompt, usage_string); + // } + + // void stop_handling() + // { + // m_console_handler.stop(); + // } + //private: + // bool process_command_str(t_server* /*psrv*/, const std::string& cmd) + // { + // return console_handlers_binder::process_command_str(cmd); + // } + //}; } -- cgit v1.2.3 From a0590d29cd9949c65a4cd67630a84410a30d33fe Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 27 Mar 2015 08:01:30 -0400 Subject: Restore daemon interactive mode Daemon interactive mode is now working again. RPC mapped calls in daemon and wallet have both had connection_context removed as an argument as that argument was not being used anywhere. --- contrib/epee/include/console_handler.h | 12 +++++++----- contrib/epee/include/net/http_server_handlers_map2.h | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'contrib/epee') diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index 147fd9ce0..fc8cc3841 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -269,17 +269,19 @@ namespace epee string_tools::trim(command); LOG_PRINT_L2("Read command: " << command); - if(0 == command.compare("exit") || 0 == command.compare("q")) - { - continue_handle = false; - }else if (command.empty()) + if (command.empty()) { continue; } else if(cmd_handler(command)) { continue; - } else + } + else if(0 == command.compare("exit") || 0 == command.compare("q")) + { + continue_handle = false; + } + else { std::cout << "unknown command: " << command << std::endl; std::cout << usage; diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index 201460130..f812077f1 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -65,7 +65,7 @@ CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \ uint64_t ticks1 = epee::misc_utils::get_tick_count(); \ boost::value_initialized resp;\ - if(!callback_f(static_cast(req), static_cast(resp), m_conn_context)) \ + if(!callback_f(static_cast(req), static_cast(resp))) \ { \ LOG_ERROR("Failed to " << #callback_f << "()"); \ response_info.m_response_code = 500; \ @@ -90,7 +90,7 @@ CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \ uint64_t ticks1 = misc_utils::get_tick_count(); \ boost::value_initialized resp;\ - if(!callback_f(static_cast(req), static_cast(resp), m_conn_context)) \ + if(!callback_f(static_cast(req), static_cast(resp))) \ { \ LOG_ERROR("Failed to " << #callback_f << "()"); \ response_info.m_response_code = 500; \ @@ -173,7 +173,7 @@ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ fail_resp.jsonrpc = "2.0"; \ fail_resp.id = req.id; \ - if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \ + if(!callback_f(req.params, resp.result, fail_resp.error)) \ { \ epee::serialization::store_t_to_json(static_cast(fail_resp), response_info.m_body); \ return true; \ @@ -202,7 +202,7 @@ else if(callback_name == method_name) \ { \ PREPARE_OBJECTS_FROM_JSON(command_type) \ - if(!callback_f(req.params, resp.result, m_conn_context)) \ + if(!callback_f(req.params, resp.result)) \ { \ epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ fail_resp.jsonrpc = "2.0"; \ -- cgit v1.2.3