aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-03-24 08:50:08 +0200
committerRiccardo Spagni <ric@spagni.net>2015-03-24 08:53:05 +0200
commitd7286395c97afd9d33d6170c1cf24f1e38140b37 (patch)
tree5513e1477d68755a44e0b0c7d34542b1c75eb99d /contrib/epee
parentupdated gtest to latest (diff)
parentMerge upstream to daemonize changes (diff)
downloadmonero-d7286395c97afd9d33d6170c1cf24f1e38140b37.tar.xz
Merge pull request #243
51e3579 Fixed bug in static linking boost on MINGW (Thomas Winget) f78bb00 Hopefully fixes build on Windows for real this time (Thomas Winget) 2b0583b Hopefully fixes build on Windows (Thomas Winget) 9dab105 DNS checkpoint loading for testnet should now be correct (Thomas Winget) 52f9629 sending commands to forked daemon works on testnet now (Thomas Winget) 76289d0 Fix tests building -- function signatures changed (Thomas Winget) db53e19 revert stop_daemon method to use correct exit (Thomas Winget) 96cbecf RPC calls for background daemon added in (Thomas Winget) 9193d6f Daemonize changes pulled in -- daemon builds (Thomas Winget)
Diffstat (limited to '')
-rw-r--r--contrib/epee/include/console_handler.h105
1 files changed, 51 insertions, 54 deletions
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 <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>
+#include <iostream>
namespace epee
{
@@ -290,7 +292,7 @@ namespace epee
private:
async_stdin_reader m_stdin_reader;
- bool m_running = true;
+ std::atomic<bool> m_running = {true};
};
@@ -350,17 +352,11 @@ namespace epee
return true;
}*/
- /************************************************************************/
- /* */
- /************************************************************************/
- class console_handlers_binder
- {
- typedef boost::function<bool (const std::vector<std::string> &)> console_command_handler;
- typedef std::map<std::string, std::pair<console_command_handler, std::string> > command_handlers_map;
- std::unique_ptr<boost::thread> m_console_thread;
- command_handlers_map m_command_handlers;
- async_console_handler m_console_handler;
+ class command_handler {
public:
+ typedef boost::function<bool (const std::vector<std::string> &)> callback;
+ typedef std::map<std::string, std::pair<callback, std::string> > 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<std::string>& 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<class t_srv>
- 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<boost::thread> 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<class t_srv>
- bool run_handling(t_srv& srv, const std::string& usage_string)
- {
- return run_default_console_handler_no_srv_param(&srv, boost::bind<bool>(&console_handlers_binder::process_command_str, this, _1), usage_string);
- }*/
};
- /* work around because of broken boost bind */
- template<class t_server>
- 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<t_server>::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<t_server>::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 t_server>
+ //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<t_server>::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<t_server>::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);
+ // }
+ //};
}