diff --git a/rak/functional.h b/rak/functional.h index 2da2492c..57b87853 100644 --- a/rak/functional.h +++ b/rak/functional.h @@ -339,16 +339,22 @@ bind2nd(const Operation& op, const Type& val) { } // Lightweight callback function including pointer to object. Should -// be replaced by TR1 stuff later. Requires an object to bind, instead -// of using a seperate functor for that. +// be replaced by TR1 stuff later. + +template +class function0 { +public: + virtual bool is_valid() const = 0; + virtual Ret operator () () = 0; +}; template -class mem_fn { +class mem_fn0 : public function0 { public: typedef Ret (Object::*Function)(); - mem_fn() : m_object(NULL) {} - mem_fn(Object* o, Function f) : m_object(o), m_function(f) {} + mem_fn0() : m_object(NULL) {} + mem_fn0(Object* o, Function f) : m_object(o), m_function(f) {} bool is_valid() const { return m_object; } @@ -359,10 +365,33 @@ private: Function m_function; }; +template +class mem_fn1 { +public: + typedef Ret (Object::*Function)(Arg1); + + mem_fn1() : m_object(NULL) {} + mem_fn1(Object* o, Function f) : m_object(o), m_function(f) {} + + bool is_valid() const { return m_object; } + + Ret operator () (Arg1 a1) { return (m_object->*m_function)(a1); } + +private: + Object* m_object; + Function m_function; +}; + template -inline mem_fn +inline mem_fn0 make_mem_fn(Object* o, Ret (Object::*f)()) { - return mem_fn(o, f); + return mem_fn0(o, f); +} + +template +inline mem_fn1 +make_mem_fn(Object* o, Ret (Object::*f)(Arg1)) { + return mem_fn1(o, f); } } diff --git a/src/Makefile.am b/src/Makefile.am index a20407f3..0b63731f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,8 @@ rtorrent_LDADD = \ $(top_srcdir)/src/utils/libsub_utils.a rtorrent_SOURCES = \ + control.cc \ + control.h \ main.cc \ option_file.cc \ option_file.h \ diff --git a/src/ui/control.cc b/src/control.cc similarity index 99% rename from src/ui/control.cc rename to src/control.cc index 99dc522d..51400141 100644 --- a/src/ui/control.cc +++ b/src/control.cc @@ -43,8 +43,6 @@ #include "control.h" -namespace ui { - Control::Control() : m_shutdownReceived(false) { @@ -97,5 +95,3 @@ Control::receive_shutdown() { m_core.shutdown(true); } } - -} diff --git a/src/ui/control.h b/src/control.h similarity index 95% rename from src/ui/control.h rename to src/control.h index 93da7f36..3aeea3ab 100644 --- a/src/ui/control.h +++ b/src/control.h @@ -43,10 +43,7 @@ #include "display/manager.h" #include "input/manager.h" #include "input/input_event.h" - -#include "root.h" - -namespace ui { +#include "ui/root.h" class Control { public: @@ -56,7 +53,7 @@ public: bool is_shutdown_completed() { return m_shutdownReceived && torrent::is_inactive(); } bool is_shutdown_received() { return m_shutdownReceived; } - Root& get_ui() { return m_ui; } + ui::Root& get_ui() { return m_ui; } core::Manager& get_core() { return m_core; } display::Manager& get_display() { return m_display; } input::Manager& get_input() { return m_input; } @@ -73,13 +70,11 @@ private: bool m_shutdownReceived; - Root m_ui; + ui::Root m_ui; core::Manager m_core; display::Manager m_display; input::Manager m_input; input::InputEvent* m_inputStdin; }; -} - #endif diff --git a/src/main.cc b/src/main.cc index 134be79e..14cb8730 100644 --- a/src/main.cc +++ b/src/main.cc @@ -58,13 +58,13 @@ #include "core/download_factory.h" #include "display/canvas.h" #include "display/window.h" -#include "ui/control.h" #include "input/bindings.h" #include "utils/task.h" #include "utils/timer.h" #include "utils/directory.h" +#include "control.h" #include "signal_handler.h" #include "option_file.h" #include "option_handler.h" @@ -95,7 +95,7 @@ is_resized() { } int -parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** argv) { +parse_options(Control* c, OptionHandler* optionHandler, int argc, char** argv) { OptionParser optionParser; // Converted. @@ -113,7 +113,7 @@ parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** arg } void -initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) { +initialize_option_handler(Control* c, OptionHandler* optionHandler) { optionHandler->insert("max_peers", new OptionHandlerInt(c, &apply_download_max_peers, &validate_download_peers)); optionHandler->insert("min_peers", new OptionHandlerInt(c, &apply_download_min_peers, &validate_download_peers)); optionHandler->insert("max_uploads", new OptionHandlerInt(c, &apply_download_max_uploads, &validate_download_peers)); @@ -160,7 +160,7 @@ load_option_file(const std::string& filename, OptionHandler* optionHandler, bool } void -load_session_torrents(ui::Control* c) { +load_session_torrents(Control* c) { // Load session torrents. std::list l = c->get_core().get_download_store().get_formated_entries().make_list(); @@ -176,7 +176,7 @@ load_session_torrents(ui::Control* c) { } void -load_arg_torrents(ui::Control* c, char** first, char** last) { +load_arg_torrents(Control* c, char** first, char** last) { //std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core())); for (; first != last; ++first) { core::DownloadFactory* f = new core::DownloadFactory(*first, &c->get_core()); @@ -194,7 +194,7 @@ main(int argc, char** argv) { utils::Timer::update(); OptionHandler optionHandler; - ui::Control uiControl; + Control uiControl; srandom(utils::Timer::cache().usec()); srand48(utils::Timer::cache().usec()); @@ -204,7 +204,7 @@ main(int argc, char** argv) { try { SignalHandler::set_ignore(SIGPIPE); - SignalHandler::set_handler(SIGINT, sigc::mem_fun(uiControl, &ui::Control::receive_shutdown)); + SignalHandler::set_handler(SIGINT, sigc::mem_fun(uiControl, &Control::receive_shutdown)); SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV)); SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); SignalHandler::set_handler(SIGFPE, sigc::bind(sigc::ptr_fun(&do_panic), SIGFPE)); diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index eb96abfa..2c9ad686 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -41,7 +41,7 @@ #include #include "utils/directory.h" -#include "ui/control.h" +#include "control.h" #include "option_handler_rules.h" void receive_tracker_dump(std::istream* s); @@ -115,22 +115,22 @@ validate_throttle_interval(int arg) { } void -apply_download_min_peers(ui::Control* m, int arg) { +apply_download_min_peers(Control* m, int arg) { m->get_core().get_download_list().slot_map_insert()["1_min_peers"] = sigc::bind(sigc::mem_fun(&core::Download::call), arg); } void -apply_download_max_peers(ui::Control* m, int arg) { +apply_download_max_peers(Control* m, int arg) { m->get_core().get_download_list().slot_map_insert()["1_max_peers"] = sigc::bind(sigc::mem_fun(&core::Download::call), arg); } void -apply_download_max_uploads(ui::Control* m, int arg) { +apply_download_max_uploads(Control* m, int arg) { m->get_core().get_download_list().slot_map_insert()["1_max_uploads"] = sigc::bind(sigc::mem_fun(&core::Download::call), arg); } void -apply_download_directory(ui::Control* m, const std::string& arg) { +apply_download_directory(Control* m, const std::string& arg) { if (!arg.empty()) m->get_core().get_download_list().slot_map_insert()["1_directory"] = sigc::bind(sigc::mem_fun(&core::Download::set_root_directory), arg); else @@ -138,69 +138,69 @@ apply_download_directory(ui::Control* m, const std::string& arg) { } void -apply_connection_leech(ui::Control* m, const std::string& arg) { +apply_connection_leech(Control* m, const std::string& arg) { m->get_core().get_download_list().slot_map_insert()["1_connection_leech"] = sigc::bind(sigc::mem_fun(&core::Download::set_connection_leech), arg); } void -apply_connection_seed(ui::Control* m, const std::string& arg) { +apply_connection_seed(Control* m, const std::string& arg) { m->get_core().get_download_list().slot_map_insert()["1_connection_seed"] = sigc::bind(sigc::mem_fun(&core::Download::set_connection_seed), arg); } void -apply_global_download_rate(ui::Control* m, int arg) { +apply_global_download_rate(Control* m, int arg) { torrent::set_down_throttle(arg * 1024); } void -apply_global_upload_rate(ui::Control* m, int arg) { +apply_global_upload_rate(Control* m, int arg) { torrent::set_up_throttle(arg * 1024); } void -apply_hash_read_ahead(ui::Control* m, int arg) { +apply_hash_read_ahead(Control* m, int arg) { torrent::set_hash_read_ahead(arg << 20); } void -apply_hash_interval(ui::Control* m, int arg) { +apply_hash_interval(Control* m, int arg) { torrent::set_hash_interval(arg * 1000); } void -apply_hash_max_tries(ui::Control* m, int arg) { +apply_hash_max_tries(Control* m, int arg) { torrent::set_hash_max_tries(arg); } void -apply_max_open_files(ui::Control* m, int arg) { +apply_max_open_files(Control* m, int arg) { torrent::set_max_open_files(arg); } void -apply_max_open_sockets(ui::Control* m, int arg) { +apply_max_open_sockets(Control* m, int arg) { torrent::set_max_open_sockets(arg); } void -apply_throttle_interval(ui::Control* m, int arg) { +apply_throttle_interval(Control* m, int arg) { torrent::set_throttle_interval(arg * 1000); } void -apply_bind(ui::Control* m, const std::string& arg) { +apply_bind(Control* m, const std::string& arg) { torrent::set_bind_address(arg); } void -apply_ip(ui::Control* m, const std::string& arg) { +apply_ip(Control* m, const std::string& arg) { torrent::set_local_address(arg); } // The arg string *must* have been checked with validate_port_range // first. void -apply_port_range(ui::Control* m, const std::string& arg) { +apply_port_range(Control* m, const std::string& arg) { int a = 0, b = 0; std::sscanf(arg.c_str(), "%i-%i", &a, &b); @@ -209,12 +209,12 @@ apply_port_range(ui::Control* m, const std::string& arg) { } void -apply_port_random(ui::Control* m, const std::string& arg) { +apply_port_random(Control* m, const std::string& arg) { m->get_core().set_port_random(arg == "yes"); } void -apply_tracker_dump(ui::Control* m, const std::string& arg) { +apply_tracker_dump(Control* m, const std::string& arg) { if (arg == "yes") m->get_core().get_download_list().slot_map_insert()["1_tracker_dump"] = sigc::bind(sigc::mem_fun(&core::Download::call), sigc::ptr_fun(&receive_tracker_dump)); else @@ -222,7 +222,7 @@ apply_tracker_dump(ui::Control* m, const std::string& arg) { } void -apply_use_udp_trackers(ui::Control* m, const std::string& arg) { +apply_use_udp_trackers(Control* m, const std::string& arg) { if (arg == "yes") m->get_core().get_download_list().slot_map_insert().erase("1_use_udp_trackers"); else @@ -230,7 +230,7 @@ apply_use_udp_trackers(ui::Control* m, const std::string& arg) { } void -apply_check_hash(ui::Control* m, const std::string& arg) { +apply_check_hash(Control* m, const std::string& arg) { if (arg == "yes") m->get_core().set_check_hash(true); else @@ -238,6 +238,6 @@ apply_check_hash(ui::Control* m, const std::string& arg) { } void -apply_session_directory(ui::Control* m, const std::string& arg) { +apply_session_directory(Control* m, const std::string& arg) { m->get_core().get_download_store().use(arg); } diff --git a/src/option_handler_rules.h b/src/option_handler_rules.h index 1e5f86e9..5110c845 100644 --- a/src/option_handler_rules.h +++ b/src/option_handler_rules.h @@ -44,9 +44,7 @@ #include "option_handler.h" #include "core/download_slot_map.h" -namespace ui { - class Control; -} +class Control; // Not pretty, but it is simple and easy to modify. @@ -65,40 +63,40 @@ bool validate_fd(int arg); bool validate_throttle_interval(int arg); -void apply_download_min_peers(ui::Control* m, int arg); -void apply_download_max_peers(ui::Control* m, int arg); -void apply_download_max_uploads(ui::Control* m, int arg); -void apply_download_directory(ui::Control* m, const std::string& arg); +void apply_download_min_peers(Control* m, int arg); +void apply_download_max_peers(Control* m, int arg); +void apply_download_max_uploads(Control* m, int arg); +void apply_download_directory(Control* m, const std::string& arg); -void apply_connection_leech(ui::Control* m, const std::string& arg); -void apply_connection_seed(ui::Control* m, const std::string& arg); +void apply_connection_leech(Control* m, const std::string& arg); +void apply_connection_seed(Control* m, const std::string& arg); -void apply_global_download_rate(ui::Control* m, int arg); -void apply_global_upload_rate(ui::Control* m, int arg); +void apply_global_download_rate(Control* m, int arg); +void apply_global_upload_rate(Control* m, int arg); -void apply_hash_read_ahead(ui::Control* m, int arg); -void apply_hash_interval(ui::Control* m, int arg); -void apply_hash_max_tries(ui::Control* m, int arg); -void apply_max_open_files(ui::Control* m, int arg); -void apply_max_open_sockets(ui::Control* m, int arg); -void apply_throttle_interval(ui::Control* m, int arg); +void apply_hash_read_ahead(Control* m, int arg); +void apply_hash_interval(Control* m, int arg); +void apply_hash_max_tries(Control* m, int arg); +void apply_max_open_files(Control* m, int arg); +void apply_max_open_sockets(Control* m, int arg); +void apply_throttle_interval(Control* m, int arg); -void apply_ip(ui::Control* m, const std::string& arg); -void apply_bind(ui::Control* m, const std::string& arg); -void apply_port_range(ui::Control* m, const std::string& arg); -void apply_port_random(ui::Control* m, const std::string& arg); -void apply_tracker_dump(ui::Control* m, const std::string& arg); -void apply_use_udp_trackers(ui::Control* m, const std::string& arg); -void apply_check_hash(ui::Control* m, const std::string& arg); +void apply_ip(Control* m, const std::string& arg); +void apply_bind(Control* m, const std::string& arg); +void apply_port_range(Control* m, const std::string& arg); +void apply_port_random(Control* m, const std::string& arg); +void apply_tracker_dump(Control* m, const std::string& arg); +void apply_use_udp_trackers(Control* m, const std::string& arg); +void apply_check_hash(Control* m, const std::string& arg); -void apply_session_directory(ui::Control* m, const std::string& arg); +void apply_session_directory(Control* m, const std::string& arg); class OptionHandlerInt : public OptionHandlerBase { public: typedef bool (*Validate)(int); - typedef void (*Apply)(ui::Control*, int); + typedef void (*Apply)(Control*, int); - OptionHandlerInt(ui::Control* c, Apply a, Validate v) : + OptionHandlerInt(Control* c, Apply a, Validate v) : m_control(c), m_apply(a), m_validate(v) {} virtual void process(const std::string& key, const std::string& arg) { @@ -112,7 +110,7 @@ public: } private: - ui::Control* m_control; + Control* m_control; Apply m_apply; Validate m_validate; }; @@ -120,9 +118,9 @@ private: class OptionHandlerString : public OptionHandlerBase { public: typedef bool (*Validate)(const std::string&); - typedef void (*Apply)(ui::Control*, const std::string&); + typedef void (*Apply)(Control*, const std::string&); - OptionHandlerString(ui::Control* c, Apply a, Validate v) : + OptionHandlerString(Control* c, Apply a, Validate v) : m_control(c), m_apply(a), m_validate(v) {} virtual void process(const std::string& key, const std::string& arg) { @@ -133,7 +131,7 @@ public: } private: - ui::Control* m_control; + Control* m_control; Apply m_apply; Validate m_validate; }; diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index f68a852b..4efdb7ff 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -1,8 +1,6 @@ noinst_LIBRARIES = libsub_ui.a libsub_ui_a_SOURCES = \ - control.cc \ - control.h \ download.cc \ download.h \ download_list.cc \ diff --git a/src/ui/download.h b/src/ui/download.h index 54724595..9fe66961 100644 --- a/src/ui/download.h +++ b/src/ui/download.h @@ -43,6 +43,8 @@ #include "utils/list_focus.h" +class Control; + namespace display { class WindowTitle; class WindowStatusbar; @@ -55,7 +57,6 @@ namespace core { namespace ui { -class Control; class ElementBase; class Download { diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 41632c3e..81b07b77 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -43,6 +43,8 @@ #include "utils/task.h" #include "utils/list_focus.h" +class Control; + namespace input { class Bindings; } @@ -58,7 +60,6 @@ namespace display { namespace ui { -class Control; class Download; class ElementBase; diff --git a/src/ui/element_download_list.h b/src/ui/element_download_list.h index 668b9b9a..d11a19ab 100644 --- a/src/ui/element_download_list.h +++ b/src/ui/element_download_list.h @@ -42,14 +42,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowDownloadList; } namespace ui { -class Control; - class ElementDownloadList : public ElementBase { public: typedef display::WindowDownloadList WDownloadList; diff --git a/src/ui/element_file_list.h b/src/ui/element_file_list.h index ca14dcd1..5535d93a 100644 --- a/src/ui/element_file_list.h +++ b/src/ui/element_file_list.h @@ -41,14 +41,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowFileList; } namespace ui { -class Control; - class ElementFileList : public ElementBase { public: typedef torrent::Entry::Priority Priority; diff --git a/src/ui/element_log_complete.h b/src/ui/element_log_complete.h index e6b5b50a..5b9830d4 100644 --- a/src/ui/element_log_complete.h +++ b/src/ui/element_log_complete.h @@ -41,14 +41,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowLogComplete; } namespace ui { -class Control; - class ElementLogComplete : public ElementBase { public: typedef display::WindowLogComplete WLogComplete; diff --git a/src/ui/element_peer_info.h b/src/ui/element_peer_info.h index 0e214f83..75f949ff 100644 --- a/src/ui/element_peer_info.h +++ b/src/ui/element_peer_info.h @@ -41,14 +41,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowPeerInfo; } namespace ui { -class Control; - class ElementPeerInfo : public ElementBase { public: typedef display::WindowPeerInfo WPeerInfo; diff --git a/src/ui/element_peer_list.h b/src/ui/element_peer_list.h index 3a7b7d70..ad6d994c 100644 --- a/src/ui/element_peer_list.h +++ b/src/ui/element_peer_list.h @@ -41,14 +41,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowPeerList; } namespace ui { -class Control; - class ElementPeerList : public ElementBase { public: typedef display::WindowPeerList WPeerList; diff --git a/src/ui/element_string_list.h b/src/ui/element_string_list.h index 6b6ffc13..c995bb2d 100644 --- a/src/ui/element_string_list.h +++ b/src/ui/element_string_list.h @@ -46,10 +46,10 @@ #include "display/window_string_list.h" -namespace ui { - class Control; +namespace ui { + class ElementStringList : public ElementBase { public: typedef display::WindowStringList WStringList; diff --git a/src/ui/element_tracker_list.h b/src/ui/element_tracker_list.h index a85f28be..470ea6f4 100644 --- a/src/ui/element_tracker_list.h +++ b/src/ui/element_tracker_list.h @@ -41,14 +41,14 @@ #include "element_base.h" +class Control; + namespace display { class WindowTrackerList; } namespace ui { -class Control; - class ElementTrackerList : public ElementBase { public: typedef display::WindowTrackerList WTrackerList; diff --git a/src/ui/root.h b/src/ui/root.h index 6b6bafce..e435a4c7 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -39,6 +39,8 @@ #include "input/bindings.h" +class Control; + namespace display { class WindowStatusbar; } @@ -46,7 +48,6 @@ namespace display { namespace ui { class DownloadList; -class Control; class Root { public: