From 37bc4c85c4d40d3051c8a00611f4ae66ef91e84e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 3 Aug 2007 11:56:18 +0000 Subject: [PATCH] * Enabled 'max_downloads_div' by default. * Added 'get_{client,library}_version' commands. * Removed support for appending more than one command to 'schedule'. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@949 e378c898-3ddf-0310-93e7-cc216c733640 --- src/command_events.cc | 7 ++++--- src/command_helpers.cc | 4 +++- src/command_helpers.h | 3 +++ src/command_local.cc | 5 +++-- src/command_network.cc | 16 +++++++------- src/rpc/parse.cc | 5 ++--- src/ui/root.cc | 47 ++++++++++++------------------------------ src/ui/root.h | 9 -------- 8 files changed, 37 insertions(+), 59 deletions(-) diff --git a/src/command_events.cc b/src/command_events.cc index 065b5396..cb18ce7a 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -183,16 +183,17 @@ torrent::Object apply_schedule(const torrent::Object& rawArgs) { const torrent::Object::list_type& args = rawArgs.as_list(); - if (args.size() < 4) - throw torrent::input_error("Too few arguments."); + if (args.size() != 4) + throw torrent::input_error("Wrong number of arguments."); torrent::Object::list_type::const_iterator itr = args.begin(); const std::string& arg1 = (itr++)->as_string(); const std::string& arg2 = (itr++)->as_string(); const std::string& arg3 = (itr++)->as_string(); + const std::string& arg4 = (itr++)->as_string(); - control->command_scheduler()->parse(arg1, arg2, arg3, rpc::convert_list_to_command(itr, args.end())); + control->command_scheduler()->parse(arg1, arg2, arg3, arg4); return torrent::Object(); } diff --git a/src/command_helpers.cc b/src/command_helpers.cc index 90b0a965..bb508046 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -101,7 +101,9 @@ add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, variable->set_variable(defaultObject); rpc::commands.insert_generic(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); - rpc::commands.insert_generic(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); + + if (setKey) + rpc::commands.insert_generic(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); if (defaultSetKey) rpc::commands.insert_generic(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", ""); diff --git a/src/command_helpers.h b/src/command_helpers.h index abdf3a09..57bd689f 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -84,6 +84,9 @@ add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_value, &rpc #define ADD_VARIABLE_STRING(key, defaultValue) \ add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_string, &rpc::CommandVariable::set_string, std::string(defaultValue)); +#define ADD_VARIABLE_C_STRING(key, defaultValue) \ +add_variable("get_" key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::string(defaultValue)); + #define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \ commandSlotsItr->set_slot(slot); \ rpc::commands.insert_generic(key, commandSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); diff --git a/src/command_local.cc b/src/command_local.cc index 6252fc1e..45b5b126 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -39,7 +39,6 @@ #include #include #include -//#include #include "core/download_list.h" #include "core/download_store.h" @@ -56,11 +55,13 @@ typedef torrent::ChunkManager CM_t; void initialize_command_local() { -// core::DownloadList* downloadList = control->core()->download_list(); torrent::ChunkManager* chunkManager = torrent::chunk_manager(); core::DownloadList* dList = control->core()->download_list(); core::DownloadStore* dStore = control->core()->download_store(); + ADD_VARIABLE_C_STRING("client_version", PACKAGE_VERSION); + ADD_VARIABLE_C_STRING("library_version", torrent::version()); + ADD_VARIABLE_VALUE("max_file_size", -1); ADD_VARIABLE_VALUE("split_file_size", -1); ADD_VARIABLE_STRING("split_suffix", ".part"); diff --git a/src/command_network.cc b/src/command_network.cc index cf0861a2..c51fcc51 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -283,12 +283,17 @@ initialize_command_network() { ADD_VARIABLE_VALUE("max_peers_seed", -1); ADD_VARIABLE_VALUE("max_uploads", 15); - ADD_VARIABLE_VALUE("max_uploads_div", 1); - ADD_VARIABLE_VALUE("max_downloads_div", 0); + ADD_VARIABLE_VALUE("max_uploads_div", 1); + ADD_VARIABLE_VALUE("max_uploads_global", 0); + ADD_VARIABLE_VALUE("max_downloads_div", 1); + ADD_VARIABLE_VALUE("max_downloads_global", 0); - ADD_COMMAND_VALUE_TRI_KB("download_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_down_throttle_i64), rak::ptr_fun(&torrent::down_throttle)); - ADD_COMMAND_VALUE_TRI_KB("upload_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_up_throttle_i64), rak::ptr_fun(&torrent::up_throttle)); +// ADD_COMMAND_VALUE_TRI("max_uploads_global", rak::make_mem_fun(control->ui(), &ui::Root::set_max_uploads_global), rak::make_mem_fun(control->ui(), &ui::Root::max_uploads_global)); +// ADD_COMMAND_VALUE_TRI("max_downloads_global", rak::make_mem_fun(control->ui(), &ui::Root::set_max_downloads_global), rak::make_mem_fun(control->ui(), &ui::Root::max_downloads_global)); + + ADD_COMMAND_VALUE_TRI_KB("download_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_down_throttle_i64), rak::ptr_fun(&torrent::down_throttle)); + ADD_COMMAND_VALUE_TRI_KB("upload_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_up_throttle_i64), rak::ptr_fun(&torrent::up_throttle)); ADD_VARIABLE_VALUE("tracker_numwant", -1); @@ -306,9 +311,6 @@ initialize_command_network() { ADD_COMMAND_VALUE_TRI("send_buffer_size", rak::make_mem_fun(cm, &torrent::ConnectionManager::set_send_buffer_size), rak::make_mem_fun(cm, &torrent::ConnectionManager::send_buffer_size)); ADD_COMMAND_VALUE_TRI("receive_buffer_size", rak::make_mem_fun(cm, &torrent::ConnectionManager::set_receive_buffer_size), rak::make_mem_fun(cm, &torrent::ConnectionManager::receive_buffer_size)); - ADD_COMMAND_VALUE_TRI("max_uploads_global", rak::make_mem_fun(control->ui(), &ui::Root::set_max_uploads_global), rak::make_mem_fun(control->ui(), &ui::Root::max_uploads_global)); - ADD_COMMAND_VALUE_TRI("max_downloads_global", rak::make_mem_fun(control->ui(), &ui::Root::set_max_downloads_global), rak::make_mem_fun(control->ui(), &ui::Root::max_downloads_global)); - ADD_COMMAND_VALUE_TRI("hash_max_tries", std::ptr_fun(&torrent::set_hash_max_tries), rak::ptr_fun(&torrent::hash_max_tries)); ADD_COMMAND_VALUE_TRI("max_open_files", std::ptr_fun(&torrent::set_max_open_files), rak::ptr_fun(&torrent::max_open_files)); ADD_COMMAND_VALUE_TRI("max_open_sockets", rak::make_mem_fun(cm, &torrent::ConnectionManager::set_max_size), rak::make_mem_fun(cm, &torrent::ConnectionManager::max_size)); diff --git a/src/rpc/parse.cc b/src/rpc/parse.cc index 62afcc22..e5f9308c 100644 --- a/src/rpc/parse.cc +++ b/src/rpc/parse.cc @@ -79,9 +79,8 @@ parse_string(const char* first, const char* last, std::string* dest) { return first; } - if (parse_is_escape(*first)) - if (++first == last) - throw torrent::input_error("Escape character at end of input."); + if (parse_is_escape(*first) && ++first == last) + throw torrent::input_error("Escape character at end of input."); dest->push_back(*first); first++; diff --git a/src/ui/root.cc b/src/ui/root.cc index a8d43f80..bf462971 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -64,10 +64,7 @@ Root::Root() : m_windowTitle(NULL), m_windowHttpQueue(NULL), m_windowInput(NULL), - m_windowStatusbar(NULL), - - m_maxUploadsGlobal(0), - m_maxDownloadsGlobal(0) { + m_windowStatusbar(NULL) { } void @@ -187,10 +184,11 @@ Root::set_down_throttle(unsigned int throttle) { torrent::set_down_throttle(throttle * 1024); - int64_t div = rpc::call_command_value("get_max_downloads_div"); + unsigned int div = std::max(rpc::call_command_value("get_max_downloads_div"), 0); + unsigned int global = std::max(rpc::call_command_value("get_max_downloads_global"), 0); - if (throttle == 0 || div <= 0) { - torrent::set_max_download_unchoked(m_maxDownloadsGlobal); + if (throttle == 0 || div == 0) { + torrent::set_max_download_unchoked(global); return; } @@ -203,8 +201,8 @@ Root::set_down_throttle(unsigned int throttle) { else maxUnchoked = 10 + throttle / 5; - if (m_maxDownloadsGlobal != 0) - torrent::set_max_download_unchoked(std::min(maxUnchoked, m_maxDownloadsGlobal)); + if (global != 0) + torrent::set_max_download_unchoked(std::min(maxUnchoked, global)); else torrent::set_max_download_unchoked(maxUnchoked); } @@ -216,10 +214,11 @@ Root::set_up_throttle(unsigned int throttle) { torrent::set_up_throttle(throttle * 1024); - int64_t div = rpc::call_command_value("get_max_uploads_div"); + unsigned int div = std::max(rpc::call_command_value("get_max_uploads_div"), 0); + unsigned int global = std::max(rpc::call_command_value("get_max_uploads_global"), 0); - if (throttle == 0 || div <= 0) { - torrent::set_max_unchoked(m_maxUploadsGlobal); + if (throttle == 0 || div == 0) { + torrent::set_max_unchoked(global); return; } @@ -232,8 +231,8 @@ Root::set_up_throttle(unsigned int throttle) { else maxUnchoked = 10 + throttle / 5; - if (m_maxUploadsGlobal != 0) - torrent::set_max_unchoked(std::min(maxUnchoked, m_maxUploadsGlobal)); + if (global != 0) + torrent::set_max_unchoked(std::min(maxUnchoked, global)); else torrent::set_max_unchoked(maxUnchoked); } @@ -248,26 +247,6 @@ Root::adjust_up_throttle(int throttle) { set_up_throttle(std::max(torrent::up_throttle() / 1024 + throttle, 0)); } -void -Root::set_max_uploads_global(int64_t slots) { - if (slots < 0) - throw torrent::input_error("Out of range."); - - m_maxUploadsGlobal = slots; - - set_up_throttle(torrent::up_throttle() / 1024); -} - -void -Root::set_max_downloads_global(int64_t slots) { - if (slots < 0) - throw torrent::input_error("Out of range."); - - m_maxDownloadsGlobal = slots; - - set_down_throttle(torrent::down_throttle() / 1024); -} - void Root::enable_input(const std::string& title, input::TextInput* input) { if (m_windowInput->input() != NULL) diff --git a/src/ui/root.h b/src/ui/root.h index 7b4197fa..67868b80 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -84,12 +84,6 @@ public: void adjust_down_throttle(int throttle); void adjust_up_throttle(int throttle); - unsigned int max_uploads_global() { return m_maxUploadsGlobal; } - void set_max_uploads_global(int64_t slots); - - unsigned int max_downloads_global() { return m_maxDownloadsGlobal; } - void set_max_downloads_global(int64_t slots); - void enable_input(const std::string& title, input::TextInput* input); void disable_input(); @@ -107,9 +101,6 @@ private: WStatusbar* m_windowStatusbar; input::Bindings m_bindings; - - unsigned int m_maxUploadsGlobal; - unsigned int m_maxDownloadsGlobal; }; }