Cleaned up option_handler_rules.*, it now uses the slot_map_* properly.

Erases the screen upon quit.

Added option for checking the hash for completed downloads.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@471 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-06-21 16:23:34 +00:00
parent 7e77635353
commit bc27fd19cb
11 changed files with 122 additions and 108 deletions
+5 -1
View File
@@ -30,6 +30,10 @@
# Port range to use for listening.
#port = 6890-6999
# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no
#
# Do not modify the following parameters unless you know what you're doing.
#
@@ -44,4 +48,4 @@
#max_open_files = 100
# Dump data received from trackers to the files "./tracker_dump.<time>".
#dump_tracker = no
#tracker_dump = no
+7
View File
@@ -39,6 +39,13 @@ Download::set_download(torrent::Download d) {
m_connStorageError = m_download.signal_storage_error(sigc::mem_fun(*this, &Download::receive_tracker_msg));
}
void
Download::set_root_directory(const std::string& d) {
m_download.set_root_dir(d +
(!d.empty() && *d.rbegin() != '/' ? "/" : "") +
(m_download.get_entry_size() > 1 ? m_download.get_name() : ""));
}
void
Download::release_download() {
m_connTrackerSucceded.disconnect();
+12 -7
View File
@@ -31,7 +31,7 @@ namespace core {
class Download {
public:
bool is_open() { return m_download.is_open(); }
bool is_done() { return m_download.get_chunks_done() == m_download.get_chunks_total(); }
inline bool is_done();
void set_download(torrent::Download d);
void release_download();
@@ -41,15 +41,15 @@ public:
const std::string& get_message() { return m_message; }
void start() { m_download.start(); }
void stop() { m_download.stop(); }
void set_root_directory(const std::string& d);
void open() { m_download.open(); }
void close() { m_download.close(); }
template <typename Ret, Ret (torrent::Download::*func)()>
void call() { (m_download.*func)(); }
void hash_resume_save() { m_download.hash_resume_save(); }
template <typename Ret, typename Arg1, Ret (torrent::Download::*func)(Arg1)>
void call(Arg1 a1) { (m_download.*func)(a1); }
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
private:
void receive_tracker_msg(std::string msg);
@@ -64,6 +64,11 @@ private:
sigc::connection m_connStorageError;
};
inline bool
Download::is_done() {
return m_download.get_chunks_done() == m_download.get_chunks_total();
}
}
#endif
+34
View File
@@ -57,6 +57,40 @@ DownloadList::erase(iterator itr) {
return Base::erase(itr);
}
void
DownloadList::open(Download* d) {
if (d->get_download().is_open())
return;
m_slotMapOpen.for_each(d);
}
void
DownloadList::close(Download* d) {
if (!d->get_download().is_open())
return;
stop(d);
m_slotMapClose.for_each(d);
}
void
DownloadList::start(Download* d) {
if (d->get_download().is_active())
return;
open(d);
m_slotMapStart.for_each(d);
}
void
DownloadList::stop(Download* d) {
if (!d->get_download().is_active())
return;
m_slotMapStop.for_each(d);
}
void
DownloadList::clear() {
std::for_each(begin(), end(), rak::call_delete<Download>());
+4 -4
View File
@@ -56,11 +56,11 @@ public:
iterator insert(std::istream* str);
iterator erase(iterator itr);
void open(Download* d) { m_slotMapOpen.for_each(d); }
void close(Download* d) { m_slotMapClose.for_each(d); }
void open(Download* d);
void close(Download* d);
void start(Download* d) { m_slotMapStart.for_each(d); }
void stop(Download* d) { m_slotMapStop.for_each(d); }
void start(Download* d);
void stop(Download* d);
DownloadSlotMap& slot_map_insert() { return m_slotMapInsert; }
DownloadSlotMap& slot_map_erase() { return m_slotMapErase; }
+1
View File
@@ -37,6 +37,7 @@ public:
typedef std::map<std::string, SlotDownload> Base;
void insert(const std::string& key, SlotDownload s) { Base::operator[](key) = s; }
void erase(const std::string& key) {}
void for_each(Download* d);
};
+9 -13
View File
@@ -56,27 +56,26 @@ Manager::initialize() {
// Register slots to be called when a download is inserted/erased,
// opened or closed.
m_downloadList.slot_map_insert().insert("1_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
m_downloadList.slot_map_insert().insert("2_manager_start", sigc::mem_fun(*this, &Manager::start));
m_downloadList.slot_map_insert().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
m_downloadList.slot_map_insert().insert("2_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
m_downloadList.slot_map_insert().insert("3_manager_start", sigc::mem_fun(*this, &Manager::start));
m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
m_downloadList.slot_map_erase().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
m_downloadList.slot_map_erase().insert("1_store_remove", sigc::mem_fun(m_downloadStore, &DownloadStore::remove));
m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::open));
//m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::open));
m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::call<void, &torrent::Download::open>));
// Currently does not call stop, might want to add a function that
// checks if we're running, and if so stop?
m_downloadList.slot_map_close().insert("1_download_close", sigc::mem_fun(&Download::close));
m_downloadList.slot_map_close().insert("1_download_close", sigc::mem_fun(&Download::call<void, &torrent::Download::close>));
m_downloadList.slot_map_close().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::start));
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::call<void, &torrent::Download::start>));
m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::stop));
m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::hash_resume_save));
m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::call<void, &torrent::Download::stop>));
m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::call<void, &torrent::Download::hash_resume_save>));
m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
//m_downloadList.slot_map_finished().insert("1_check_hash", sigc::mem_fun(*this, &Manager::check_hash));
}
void
@@ -146,9 +145,6 @@ Manager::check_hash(Download* d) {
bool restart = d->get_download().is_active();
try {
if (d->get_download().is_active())
m_downloadList.stop(d);
m_downloadList.close(d);
d->get_download().hash_resume_clear();
m_downloadList.open(d);
+1
View File
@@ -50,6 +50,7 @@ public:
void set_background(chtype c) { return wbkgdset(m_window, c); }
void erase() { werase(m_window); }
static void erase_std() { werase(stdscr); }
void print_border(chtype ls, chtype rs,
chtype ts, chtype bs,
+18 -16
View File
@@ -89,7 +89,7 @@ do_shutdown(ui::Control* c) {
// Close all torrents, this will stop all tracker connections and cause
// a quick shutdown.
std::for_each(c->get_core().get_download_list().begin(), c->get_core().get_download_list().end(),
std::mem_fun(&core::Download::close));
std::mem_fun(&core::Download::call<void, &torrent::Download::close>));
}
}
@@ -113,23 +113,22 @@ parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** arg
void
initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) {
core::DownloadSlotMap* dsmInsert = &c->get_core().get_download_list().slot_map_insert();
optionHandler->insert("min_peers", new OptionHandlerDownloadInt(dsmInsert, &apply_download_min_peers, &validate_download_peers));
optionHandler->insert("max_peers", new OptionHandlerDownloadInt(dsmInsert, &apply_download_max_peers, &validate_download_peers));
optionHandler->insert("max_uploads", new OptionHandlerDownloadInt(dsmInsert, &apply_download_max_uploads, &validate_download_peers));
optionHandler->insert("max_peers", new OptionHandlerInt(c, &apply_download_max_peers, &validate_download_peers));
optionHandler->insert("max_uploads", new OptionHandlerInt(c, &apply_download_max_uploads, &validate_download_peers));
optionHandler->insert("min_peers", new OptionHandlerInt(c, &apply_download_min_peers, &validate_download_peers));
optionHandler->insert("download_rate", new OptionHandlerInt(c, &apply_global_download_rate, &validate_rate));
optionHandler->insert("upload_rate", new OptionHandlerInt(c, &apply_global_upload_rate, &validate_rate));
optionHandler->insert("hash_read_ahead", new OptionHandlerInt(c, &apply_hash_read_ahead, &validate_read_ahead));
optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files, &validate_fd));
optionHandler->insert("upload_rate", new OptionHandlerInt(c, &apply_global_upload_rate, &validate_rate));
optionHandler->insert("directory", new OptionHandlerDownloadString(dsmInsert, &apply_download_directory, &validate_directory));
optionHandler->insert("dump_tracker", new OptionHandlerDownloadString(dsmInsert, &apply_download_dump_tracker, &validate_yes_no));
optionHandler->insert("check_hash", new OptionHandlerString(c, &apply_check_hash, &validate_yes_no));
optionHandler->insert("directory", new OptionHandlerString(c, &apply_download_directory, &validate_directory));
optionHandler->insert("tracker_dump", new OptionHandlerString(c, &apply_tracker_dump, &validate_yes_no));
optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip));
optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip));
optionHandler->insert("port", new OptionHandlerString(c, &apply_port_range, &validate_port_range));
optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip));
optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip));
optionHandler->insert("port", new OptionHandlerString(c, &apply_port_range, &validate_port_range));
}
void
@@ -231,10 +230,13 @@ main(int argc, char** argv) {
}
uiRoot.cleanup();
display::Canvas::cleanup();
uiControl.get_core().cleanup();
display::Canvas::erase_std();
display::Canvas::refresh_std();
display::Canvas::do_update();
display::Canvas::cleanup();
} catch (std::exception& e) {
display::Canvas::cleanup();
@@ -247,7 +249,7 @@ main(int argc, char** argv) {
void
do_panic(int signum) {
// Use the default signal handler in the future to avoid infint
// Use the default signal handler in the future to avoid infinit
// loops.
SignalHandler::set_default(signum);
display::Canvas::cleanup();
@@ -275,7 +277,7 @@ do_panic(int signum) {
}
void
receive_dump_tracker(std::istream* s) {
receive_tracker_dump(std::istream* s) {
std::stringstream filename;
filename << "./tracker_dump." << utils::Timer::current().sec();
+26 -17
View File
@@ -29,7 +29,7 @@
#include "ui/control.h"
#include "option_handler_rules.h"
void receive_dump_tracker(std::istream* s);
void receive_tracker_dump(std::istream* s);
bool
validate_ip(const std::string& arg) {
@@ -73,34 +73,27 @@ validate_read_ahead(int arg) {
bool
validate_fd(int arg) {
return arg >= 10 && arg < 1024;
return arg >= 10 && arg < (1 << 16);
}
void
apply_download_min_peers(core::Download* d, int arg) {
d->get_download().set_peers_min(arg);
apply_download_min_peers(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().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(core::Download* d, int arg) {
d->get_download().set_peers_max(arg);
apply_download_max_peers(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().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(core::Download* d, int arg) {
d->get_download().set_uploads_max(arg);
apply_download_max_uploads(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().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(core::Download* d, const std::string& arg) {
d->get_download().set_root_dir(arg +
(!arg.empty() && *arg.rbegin() != '/' ? "/" : "") +
(d->get_download().get_entry_size() > 1 ? d->get_download().get_name() : ""));
}
void
apply_download_dump_tracker(core::Download* d, const std::string& arg) {
d->get_download().signal_tracker_dump(sigc::ptr_fun(&receive_dump_tracker));
apply_download_directory(ui::Control* m, const std::string& arg) {
m->get_core().get_download_list().slot_map_insert().insert("1_directory", sigc::bind(sigc::mem_fun(&core::Download::set_root_directory), arg));
}
void
@@ -143,3 +136,19 @@ apply_port_range(ui::Control* m, const std::string& arg) {
m->get_core().set_port_range(a, b);
}
void
apply_tracker_dump(ui::Control* m, const std::string& arg) {
if (arg == "yes")
m->get_core().get_download_list().slot_map_insert().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
m->get_core().get_download_list().slot_map_insert().erase("1_tracker_dump");
}
void
apply_check_hash(ui::Control* m, const std::string& arg) {
if (arg == "yes")
m->get_core().get_download_list().slot_map_finished().insert("1_check_hash", sigc::mem_fun(m->get_core(), &core::Manager::check_hash));
else
m->get_core().get_download_list().slot_map_finished().erase("1_check_hash");
}
+5 -50
View File
@@ -44,12 +44,11 @@ bool validate_rate(int arg);
bool validate_read_ahead(int arg);
bool validate_fd(int arg);
void apply_download_min_peers(core::Download* d, int arg);
void apply_download_max_peers(core::Download* d, int arg);
void apply_download_max_uploads(core::Download* d, 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(core::Download* d, const std::string& arg);
void apply_download_dump_tracker(core::Download* d, const std::string& arg);
void apply_download_directory(ui::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);
@@ -61,6 +60,7 @@ 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_tracker_dump(ui::Control* m, const std::string& arg);
void apply_check_hash(ui::Control* m, const std::string& arg);
class OptionHandlerInt : public OptionHandlerBase {
public:
@@ -107,49 +107,4 @@ private:
Validate m_validate;
};
class OptionHandlerDownloadInt : public OptionHandlerBase {
public:
typedef void (*Apply)(core::Download*, int);
typedef bool (*Validate)(int);
OptionHandlerDownloadInt(core::DownloadSlotMap* m, Apply a, Validate v) :
m_map(m), m_apply(a), m_validate(v) {}
virtual void process(const std::string& key, const std::string& arg) {
int a;
if (std::sscanf(arg.c_str(), "%i", &a) != 1 ||
!m_validate(a))
throw std::runtime_error("Invalid argument for \"" + key + "\": \"" + arg + "\"");
(*m_map)[key] = sigc::bind(sigc::ptr_fun(m_apply), a);
}
private:
core::DownloadSlotMap* m_map;
Apply m_apply;
Validate m_validate;
};
class OptionHandlerDownloadString : public OptionHandlerBase {
public:
typedef void (*Apply)(core::Download*, const std::string&);
typedef bool (*Validate)(const std::string&);
OptionHandlerDownloadString(core::DownloadSlotMap* m, Apply a, Validate v) :
m_map(m), m_apply(a), m_validate(v) {}
virtual void process(const std::string& key, const std::string& arg) {
if (!m_validate(arg))
throw std::runtime_error("Invalid argument for \"" + key + "\": \"" + arg + "\"");
(*m_map)[key] = sigc::bind(sigc::ptr_fun(m_apply), arg);
}
private:
core::DownloadSlotMap* m_map;
Apply m_apply;
Validate m_validate;
};
#endif