* Converted some internal sigc++ calls to lightweight function

wrappers.

* Some client code cleanup.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@576 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-10-04 11:06:06 +00:00
parent 33b7217627
commit 65573ec1ee
18 changed files with 120 additions and 99 deletions
+36 -7
View File
@@ -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 <typename Ret>
class function0 {
public:
virtual bool is_valid() const = 0;
virtual Ret operator () () = 0;
};
template <typename Object, typename Ret>
class mem_fn {
class mem_fn0 : public function0<Ret> {
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 <typename Object, typename Ret, typename Arg1>
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 <typename Object, typename Ret>
inline mem_fn<Object, Ret>
inline mem_fn0<Object, Ret>
make_mem_fn(Object* o, Ret (Object::*f)()) {
return mem_fn<Object, Ret>(o, f);
return mem_fn0<Object, Ret>(o, f);
}
template <typename Object, typename Ret, typename Arg1>
inline mem_fn1<Object, Ret, Arg1>
make_mem_fn(Object* o, Ret (Object::*f)(Arg1)) {
return mem_fn1<Object, Ret, Arg1>(o, f);
}
}
+2
View File
@@ -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 \
-4
View File
@@ -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);
}
}
}
+3 -8
View File
@@ -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
+7 -7
View File
@@ -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<std::string> 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));
+23 -23
View File
@@ -41,7 +41,7 @@
#include <netinet/in.h>
#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<void, uint32_t, &torrent::Download::set_peers_min>), 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<void, uint32_t, &torrent::Download::set_peers_max>), 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<void, uint32_t, &torrent::Download::set_uploads_max>), 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::connection, torrent::Download::SlotIStream, &torrent::Download::signal_tracker_dump>), 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);
}
+29 -31
View File
@@ -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;
};
-2
View File
@@ -1,8 +1,6 @@
noinst_LIBRARIES = libsub_ui.a
libsub_ui_a_SOURCES = \
control.cc \
control.h \
download.cc \
download.h \
download_list.cc \
+2 -1
View File
@@ -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 {
+2 -1
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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;
+2 -1
View File
@@ -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: