From cf77a173998a49fd23f0156e4053200d2b5b479a Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 22 May 2012 17:19:19 +0900 Subject: [PATCH] Cleaned up command wrappers. --- src/core/download_factory.cc | 26 ++++++++++----------- src/core/download_list.cc | 44 ++++++++++++++++++------------------ src/core/manager.cc | 2 +- src/globals.cc | 2 +- src/main.cc | 14 +----------- src/rpc/parse_commands.h | 10 ++------ 6 files changed, 40 insertions(+), 58 deletions(-) diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index dc9b64ef..0ac36ba2 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -110,11 +110,11 @@ DownloadFactory::DownloadFactory(Manager* m) : m_taskLoad.slot() = std::tr1::bind(&DownloadFactory::receive_load, this); m_taskCommit.slot() = std::tr1::bind(&DownloadFactory::receive_commit, this); - // m_variables["connection_leech"] = rpc::call_command_void("protocol.connection.leech"); - // m_variables["connection_seed"] = rpc::call_command_void("protocol.connection.seed"); + // m_variables["connection_leech"] = rpc::call_command("protocol.connection.leech"); + // m_variables["connection_seed"] = rpc::call_command("protocol.connection.seed"); m_variables["connection_leech"] = std::string(); m_variables["connection_seed"] = std::string(); - m_variables["directory"] = rpc::call_command_void("directory.default"); + m_variables["directory"] = rpc::call_command("directory.default"); m_variables["tied_to_file"] = torrent::Object((int64_t)false); } @@ -255,21 +255,21 @@ DownloadFactory::receive_success() { if (!rtorrent->has_key_string("custom4")) rtorrent->insert_key("custom4", std::string()); if (!rtorrent->has_key_string("custom5")) rtorrent->insert_key("custom5", std::string()); - rpc::call_command("d.uploads_min.set", rpc::call_command_void("throttle.min_uploads"), rpc::make_target(download)); - rpc::call_command("d.uploads_max.set", rpc::call_command_void("throttle.max_uploads"), rpc::make_target(download)); - rpc::call_command("d.downloads_min.set", rpc::call_command_void("throttle.min_downloads"), rpc::make_target(download)); - rpc::call_command("d.downloads_max.set", rpc::call_command_void("throttle.max_downloads"), rpc::make_target(download)); - rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.normal"), rpc::make_target(download)); - rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.normal"), rpc::make_target(download)); - rpc::call_command("d.tracker_numwant.set", rpc::call_command_void("trackers.numwant"), rpc::make_target(download)); - rpc::call_command("d.max_file_size.set", rpc::call_command_void("system.file.max_size"), rpc::make_target(download)); + rpc::call_command("d.uploads_min.set", rpc::call_command("throttle.min_uploads"), rpc::make_target(download)); + rpc::call_command("d.uploads_max.set", rpc::call_command("throttle.max_uploads"), rpc::make_target(download)); + rpc::call_command("d.downloads_min.set", rpc::call_command("throttle.min_downloads"), rpc::make_target(download)); + rpc::call_command("d.downloads_max.set", rpc::call_command("throttle.max_downloads"), rpc::make_target(download)); + rpc::call_command("d.peers_min.set", rpc::call_command("throttle.min_peers.normal"), rpc::make_target(download)); + rpc::call_command("d.peers_max.set", rpc::call_command("throttle.max_peers.normal"), rpc::make_target(download)); + rpc::call_command("d.tracker_numwant.set", rpc::call_command("trackers.numwant"), rpc::make_target(download)); + rpc::call_command("d.max_file_size.set", rpc::call_command("system.file.max_size"), rpc::make_target(download)); if (rpc::call_command_value("d.complete", rpc::make_target(download)) != 0) { if (rpc::call_command_value("throttle.min_peers.seed") >= 0) - rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.seed"), rpc::make_target(download)); + rpc::call_command("d.peers_min.set", rpc::call_command("throttle.min_peers.seed"), rpc::make_target(download)); if (rpc::call_command_value("throttle.max_peers.seed") >= 0) - rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.seed"), rpc::make_target(download)); + rpc::call_command("d.peers_max.set", rpc::call_command("throttle.max_peers.seed"), rpc::make_target(download)); } if (!rpc::call_command_value("trackers.use_udp")) diff --git a/src/core/download_list.cc b/src/core/download_list.cc index ebf4a6bf..7d7ea96a 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -373,26 +373,26 @@ DownloadList::resume(Download* download, int flags) { rpc::call_command("d.state_counter.set", rpc::call_command_value("d.state_counter", rpc::make_target(download)) + 1, rpc::make_target(download)); if (download->is_done()) { - torrent::Object conn_current = rpc::call_command_void("d.connection_seed", rpc::make_target(download)); - torrent::Object choke_up = rpc::call_command_void("d.up.choke_heuristics.seed", rpc::make_target(download)); - torrent::Object choke_down = rpc::call_command_void("d.down.choke_heuristics.seed", rpc::make_target(download)); + torrent::Object conn_current = rpc::call_command("d.connection_seed", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_up = rpc::call_command("d.up.choke_heuristics.seed", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_down = rpc::call_command("d.down.choke_heuristics.seed", torrent::Object(), rpc::make_target(download)); - if (conn_current.is_string_empty()) conn_current = rpc::call_command_void("protocol.connection.seed", rpc::make_target(download)); - if (choke_up.is_string_empty()) choke_up = rpc::call_command_void("protocol.choke_heuristics.up.seed", rpc::make_target(download)); - if (choke_down.is_string_empty()) choke_down = rpc::call_command_void("protocol.choke_heuristics.down.seed", rpc::make_target(download)); + if (conn_current.is_string_empty()) conn_current = rpc::call_command("protocol.connection.seed", torrent::Object(), rpc::make_target(download)); + if (choke_up.is_string_empty()) choke_up = rpc::call_command("protocol.choke_heuristics.up.seed", torrent::Object(), rpc::make_target(download)); + if (choke_down.is_string_empty()) choke_down = rpc::call_command("protocol.choke_heuristics.down.seed", torrent::Object(), rpc::make_target(download)); rpc::call_command("d.connection_current.set", conn_current, rpc::make_target(download)); rpc::call_command("d.up.choke_heuristics.set", choke_up, rpc::make_target(download)); rpc::call_command("d.down.choke_heuristics.set", choke_down, rpc::make_target(download)); } else { - torrent::Object conn_current = rpc::call_command_void("d.connection_leech", rpc::make_target(download)); - torrent::Object choke_up = rpc::call_command_void("d.up.choke_heuristics.leech", rpc::make_target(download)); - torrent::Object choke_down = rpc::call_command_void("d.down.choke_heuristics.leech", rpc::make_target(download)); + torrent::Object conn_current = rpc::call_command("d.connection_leech", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_up = rpc::call_command("d.up.choke_heuristics.leech", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_down = rpc::call_command("d.down.choke_heuristics.leech", torrent::Object(), rpc::make_target(download)); - if (conn_current.is_string_empty()) conn_current = rpc::call_command_void("protocol.connection.leech", rpc::make_target(download)); - if (choke_up.is_string_empty()) choke_up = rpc::call_command_void("protocol.choke_heuristics.up.leech", rpc::make_target(download)); - if (choke_down.is_string_empty()) choke_down = rpc::call_command_void("protocol.choke_heuristics.down.leech", rpc::make_target(download)); + if (conn_current.is_string_empty()) conn_current = rpc::call_command("protocol.connection.leech", torrent::Object(), rpc::make_target(download)); + if (choke_up.is_string_empty()) choke_up = rpc::call_command("protocol.choke_heuristics.up.leech", torrent::Object(), rpc::make_target(download)); + if (choke_down.is_string_empty()) choke_down = rpc::call_command("protocol.choke_heuristics.down.leech", torrent::Object(), rpc::make_target(download)); rpc::call_command("d.connection_current.set", conn_current, rpc::make_target(download)); rpc::call_command("d.up.choke_heuristics.set", choke_up, rpc::make_target(download)); @@ -462,8 +462,8 @@ DownloadList::pause(Download* download, int flags) { // If initial seeding is complete, don't try it again when restarting. if (download->is_done() && - rpc::call_command_void("d.connection_current", rpc::make_target(download)).as_string() == "initial_seed") - rpc::call_command("d.connection_seed.set", rpc::call_command_void("d.connection_current", rpc::make_target(download)), rpc::make_target(download)); + rpc::call_command("d.connection_current", torrent::Object(), rpc::make_target(download)).as_string() == "initial_seed") + rpc::call_command("d.connection_seed.set", rpc::call_command("d.connection_current", torrent::Object(), rpc::make_target(download)), rpc::make_target(download)); // Save the state after all the slots, etc have been called so we // include the modifications they may make. @@ -625,13 +625,13 @@ DownloadList::confirm_finished(Download* download) { rpc::call_command("d.complete.set", (int64_t)1, rpc::make_target(download)); // Clean up these settings: - torrent::Object conn_current = rpc::call_command_void("d.connection_seed", rpc::make_target(download)); - torrent::Object choke_up = rpc::call_command_void("d.up.choke_heuristics.seed", rpc::make_target(download)); - torrent::Object choke_down = rpc::call_command_void("d.down.choke_heuristics.seed", rpc::make_target(download)); + torrent::Object conn_current = rpc::call_command("d.connection_seed", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_up = rpc::call_command("d.up.choke_heuristics.seed", torrent::Object(), rpc::make_target(download)); + torrent::Object choke_down = rpc::call_command("d.down.choke_heuristics.seed", torrent::Object(), rpc::make_target(download)); - if (conn_current.is_string_empty()) conn_current = rpc::call_command_void("protocol.connection.seed", rpc::make_target(download)); - if (choke_up.is_string_empty()) choke_up = rpc::call_command_void("protocol.choke_heuristics.up.seed", rpc::make_target(download)); - if (choke_down.is_string_empty()) choke_down = rpc::call_command_void("protocol.choke_heuristics.down.seed", rpc::make_target(download)); + if (conn_current.is_string_empty()) conn_current = rpc::call_command("protocol.connection.seed", torrent::Object(), rpc::make_target(download)); + if (choke_up.is_string_empty()) choke_up = rpc::call_command("protocol.choke_heuristics.up.seed", torrent::Object(), rpc::make_target(download)); + if (choke_down.is_string_empty()) choke_down = rpc::call_command("protocol.choke_heuristics.down.seed", torrent::Object(), rpc::make_target(download)); rpc::call_command("d.connection_current.set", conn_current, rpc::make_target(download)); rpc::call_command("d.up.choke_heuristics.set", choke_up, rpc::make_target(download)); @@ -641,11 +641,11 @@ DownloadList::confirm_finished(Download* download) { if (rpc::call_command_value("d.peers_min", rpc::make_target(download)) == rpc::call_command_value("throttle.min_peers.normal") && rpc::call_command_value("throttle.min_peers.seed") >= 0) - rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.seed"), rpc::make_target(download)); + rpc::call_command("d.peers_min.set", rpc::call_command("throttle.min_peers.seed"), rpc::make_target(download)); if (rpc::call_command_value("d.peers_max", rpc::make_target(download)) == rpc::call_command_value("throttle.max_peers.normal") && rpc::call_command_value("throttle.max_peers.seed") >= 0) - rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.seed"), rpc::make_target(download)); + rpc::call_command("d.peers_max.set", rpc::call_command("throttle.max_peers.seed"), rpc::make_target(download)); // Do this before the slots are called in case one of them closes // the download. diff --git a/src/core/manager.cc b/src/core/manager.cc index d27ec91e..63b53443 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -185,7 +185,7 @@ Manager::listen_open() { return; int portFirst, portLast; - torrent::Object portRange = rpc::call_command_void("network.port_range"); + torrent::Object portRange = rpc::call_command("network.port_range"); if (portRange.is_string()) { if (std::sscanf(portRange.as_string().c_str(), "%i-%i", &portFirst, &portLast) != 2) diff --git a/src/globals.cc b/src/globals.cc index a73230ef..4bbf4129 100644 --- a/src/globals.cc +++ b/src/globals.cc @@ -43,4 +43,4 @@ rak::timer cachedTime; rpc::ip_table_list ip_tables; Control* control = NULL; -ThreadWorker* worker_thread = NULL; +ThreadWorker* worker_thread = NULL; diff --git a/src/main.cc b/src/main.cc index 4f2a9184..843037f6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -239,15 +239,6 @@ main(int argc, char** argv) { rpc::parse_command_multiple (rpc::make_target(), -// "method.insert = test.value,value\n" -// "method.insert = test.value2,value,6\n" - -// "method.insert = test.string,string,6\n" -// "method.insert = test.bool,bool,true\n" - - // "method.insert.simple = test.method.simple,((print,simple_test_,$argument.0=))\n" - // "method.insert.simple = test.method.double,((print,simple_test_,$argument.0=)),\"print=simple_test_,$argument.1=\"\n" - "method.insert = event.download.inserted,multi|rlookup|static\n" "method.insert = event.download.inserted_new,multi|rlookup|static\n" "method.insert = event.download.inserted_session,multi|rlookup|static\n" @@ -895,8 +886,6 @@ handle_sigbus(int signum, siginfo_t* sa, void* ptr) { SignalHandler::set_default(signum); display::Canvas::cleanup(); - // Use printf here instead... - std::stringstream output; output << "Caught SIGBUS, dumping stack:" << std::endl; @@ -913,7 +902,6 @@ handle_sigbus(int signum, siginfo_t* sa, void* ptr) { #else output << "Stack dump not enabled." << std::endl; #endif - output << std::endl << "Error: " << rak::error_number(sa->si_errno).c_str() << std::endl; const char* signal_reason; @@ -1039,7 +1027,7 @@ print_help() { std::cout << " o View trackers" << std::endl; std::cout << std::endl; - std::cout << "Report bugs to ." << std::endl; + std::cout << "Report bugs to ." << std::endl; exit(0); } diff --git a/src/rpc/parse_commands.h b/src/rpc/parse_commands.h index 2df33723..2fa5434d 100644 --- a/src/rpc/parse_commands.h +++ b/src/rpc/parse_commands.h @@ -95,19 +95,13 @@ parse_command_multiple_d_nothrow(core::Download* download, const std::string& cm } } -inline torrent::Object call_command (const char* key, const torrent::Object& obj, target_type target = make_target()) { return commands.call_command(key, obj, target); } -inline torrent::Object call_command_void (const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target); } +inline torrent::Object call_command (const char* key, const torrent::Object& obj = torrent::Object(), target_type target = make_target()) { return commands.call_command(key, obj, target); } inline std::string call_command_string(const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target).as_string(); } inline int64_t call_command_value (const char* key, target_type target = make_target()) { return commands.call_command(key, torrent::Object(), target).as_value(); } inline void call_command_set_string(const char* key, const std::string& arg) { commands.call_command(key, torrent::Object(arg)); } inline void call_command_set_std_string(const std::string& key, const std::string& arg) { commands.call_command(key.c_str(), torrent::Object(arg)); } - -inline void call_command_d_v_void(const char* key, core::Download* download) { commands.call_command_d(key, download, torrent::Object()); } - -inline void call_command_set_value(const char* key, int64_t arg, target_type target = make_target()) { commands.call_command(key, torrent::Object(arg), target); } -inline void call_command_d_set_string(const char* key, core::Download* download, const std::string& arg) { commands.call_command_d(key, download, torrent::Object(arg)); } -inline void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { commands.call_command_d(key.c_str(), download, torrent::Object(arg)); } +inline void call_command_set_value(const char* key, int64_t arg, target_type target = make_target()) { commands.call_command(key, torrent::Object(arg), target); } inline torrent::Object call_command_d_range(const char* key, core::Download* download, torrent::Object::list_const_iterator first, torrent::Object::list_const_iterator last) {