From 61098513c62c8e48c7d00afba81f510b9f235314 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 21 Oct 2007 04:27:49 +0000 Subject: [PATCH] * Cycle the order in which downloads are handled during ticks to ensure resource usage gets spread out over time. * Changed element_file_list.cc to use te_command. * File commands on file list iterators will be called on the File pointed to. * Fixed some sigc++ 2.1 compile errors. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@992 e378c898-3ddf-0310-93e7-cc216c733640 --- src/command_events.cc | 2 +- src/command_file.cc | 26 ++++++++++++++++++++++++++ src/command_ui.cc | 2 +- src/core/curl_stack.cc | 2 +- src/core/download.cc | 4 ++-- src/core/download_list.cc | 2 +- src/core/http_queue.cc | 4 ++-- src/core/manager.cc | 4 ++-- src/core/view.cc | 2 +- src/main.cc | 2 +- src/option_parser.cc | 4 ++-- src/rpc/command_map.cc | 16 ++++++++++++++-- src/ui/download.cc | 2 +- src/ui/download_list.cc | 4 ++-- src/ui/element_download_list.cc | 2 +- src/ui/element_file_list.cc | 22 ++++++---------------- src/ui/element_peer_list.cc | 2 +- src/ui/root.cc | 2 +- 18 files changed, 66 insertions(+), 38 deletions(-) diff --git a/src/command_events.cc b/src/command_events.cc index ad3fdccb..0c193433 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/command_file.cc b/src/command_file.cc index 0b1dba1a..ff88dffa 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -40,6 +40,7 @@ #include #include #include +#include #include "core/manager.h" @@ -85,6 +86,17 @@ apply_f_path_depth(torrent::File* file) { return (int64_t)file->path()->size(); } +torrent::Object +apply_fi_filename_last(torrent::FileListIterator* itr) { + if (itr->file()->path()->empty()) + return "EMPTY"; + + if (itr->depth() >= itr->file()->path()->size()) + return "ERROR"; + + return itr->file()->path()->at(itr->depth()); +} + #define ADD_CF_SLOT(key, function, slot, parm, doc) \ commandFileSlotsItr->set_slot(slot); \ rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc); @@ -106,6 +118,16 @@ apply_f_path_depth(torrent::File* file) { #define ADD_CF_STRING_UNI(key, get) \ ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") +#define ADD_CFI_SLOT_PUBLIC(key, function, slot, parm, doc) \ + commandFileItrSlotsItr->set_slot(slot); \ + rpc::commands.insert_file_itr(key, commandFileItrSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); + +#define ADD_CFI_VOID(key, slot) \ + ADD_CFI_SLOT_PUBLIC("fi.get_" key, call_unknown, rpc::object_fn(slot), "i:", "") + +#define ADD_CFI_VALUE(key, get) \ + ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_void_fn(get), "i:", "") + void initialize_command_file() { ADD_CF_VALUE_UNI("is_created", std::mem_fun(&torrent::File::is_created)); @@ -130,4 +152,8 @@ initialize_command_file() { ADD_CF_VALUE_UNI("match_depth_next", std::mem_fun(&torrent::File::match_depth_next)); ADD_CF_VALUE_UNI("last_touched", std::mem_fun(&torrent::File::last_touched)); + + ADD_CFI_VOID("filename_last", &apply_fi_filename_last); + + ADD_CFI_VALUE("is_file", std::mem_fun(&torrent::FileListIterator::is_file)); } diff --git a/src/command_ui.cc b/src/command_ui.cc index d0b630e2..62e80dab 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -38,7 +38,7 @@ #include #include -#include +#include #include "core/manager.h" #include "core/view_manager.h" diff --git a/src/core/curl_stack.cc b/src/core/curl_stack.cc index 5c4acbba..4522cf09 100644 --- a/src/core/curl_stack.cc +++ b/src/core/curl_stack.cc @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include "rak/functional.h" diff --git a/src/core/download.cc b/src/core/download.cc index de42fe17..0de6f753 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -36,8 +36,8 @@ #include "config.h" -#include -#include +#include +#include #include #include #include diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 68b97e21..aadaa88c 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/core/http_queue.cc b/src/core/http_queue.cc index 72d11188..cb5f4f3f 100644 --- a/src/core/http_queue.cc +++ b/src/core/http_queue.cc @@ -38,8 +38,8 @@ #include #include -#include -#include +#include +#include #include #include "rak/functional.h" diff --git a/src/core/manager.cc b/src/core/manager.cc index b1fb3a6c..abcdc685 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -46,8 +46,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/src/core/view.cc b/src/core/view.cc index 58fc0287..4eec2bba 100644 --- a/src/core/view.cc +++ b/src/core/view.cc @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/main.cc b/src/main.cc index d785c1c9..9baa8150 100644 --- a/src/main.cc +++ b/src/main.cc @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/option_parser.cc b/src/option_parser.cc index ff6ddb0b..f5d324ff 100644 --- a/src/option_parser.cc +++ b/src/option_parser.cc @@ -43,8 +43,8 @@ #include #include #include -#include -#include +#include +#include #include "option_parser.h" diff --git a/src/rpc/command_map.cc b/src/rpc/command_map.cc index 5d4c12a1..ecd20af3 100644 --- a/src/rpc/command_map.cc +++ b/src/rpc/command_map.cc @@ -38,6 +38,7 @@ #include #include +#include #include "command.h" #include "command_map.h" @@ -134,6 +135,7 @@ CommandMap::insert(key_type key, const command_map_data_type src) { case target_any: itr->second.m_anySlot = src.m_anySlot; break; case target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break; case target_file: itr->second.m_fileSlot = src.m_fileSlot; break; + case target_file_itr: itr->second.m_fileItrSlot = src.m_fileItrSlot; break; case target_peer: itr->second.m_peerSlot = src.m_peerSlot; break; case target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break; default: throw torrent::internal_error("CommandMap::insert(...) Invalid target."); @@ -147,10 +149,20 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe if (itr == base_type::end()) throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist."); - if ((itr->second.m_target != target.first && itr->second.m_target > target_any) || - (target.second == NULL && itr->second.m_target != target_generic && !(itr->second.m_target == target_any && target.first == target_generic))) + if (target.second == NULL && + itr->second.m_target != target_generic && + !(itr->second.m_target == target_any && target.first == target_generic)) throw torrent::input_error("Command type mis-match."); + if (itr->second.m_target != target.first && itr->second.m_target > target_any) { + // Mismatch between the target and command type. If it is not + // possible to convert, then throw an input error. + if (target.first == target_file_itr && itr->second.m_target == target_file) + target = target_type((int)target_file, static_cast(target.second)->file()); + else + throw torrent::input_error("Command type mis-match."); + } + // This _should_ be optimized int just two calls. switch (itr->second.m_target) { case target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg); diff --git a/src/ui/download.cc b/src/ui/download.cc index 3f49ddb9..e1f83021 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -36,7 +36,7 @@ #include "config.h" -#include +#include #include #include #include diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index bf30b183..39c7cda8 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -38,8 +38,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 80503699..8614b429 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -36,7 +36,7 @@ #include "config.h" -#include +#include #include #include diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index fd9c23d2..29f6f3a5 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -36,7 +36,7 @@ #include "config.h" -#include +#include #include #include #include @@ -78,17 +78,6 @@ ElementFileList::ElementFileList(core::Download* d) : m_bindings[KEY_UP] = m_bindings['P' - '@'] = sigc::mem_fun(*this, &ElementFileList::receive_prev); } -const char* -element_file_list_filename(const torrent::FileListIterator* itr) { - if ((**itr)->path()->empty()) - return "EMPTY"; - - if (itr->depth() >= (**itr)->path()->size()) - return "ERROR"; - - return (**itr)->path()->at(itr->depth()).c_str(); -} - inline ElementText* element_file_list_create_info() { using namespace display::helpers; @@ -101,12 +90,13 @@ element_file_list_create_info() { element->push_back("File info:"); element->push_back(""); - element->push_column("Filename:", te_string(&element_file_list_filename)); + element->push_column("Filename:", te_command("fi.get_filename_last=")); element->push_back(""); - element->push_column("Size:", te_branch(&torrent::FileListIterator::is_file, te_value(&torrent::File::size_bytes, value_base::flag_xb), te_string("---"))); - element->push_column("Chunks:", te_value(&torrent::File::completed_chunks), " / ", te_value(&torrent::File::size_chunks)); - element->push_column("Range:", te_value(&torrent::File::range_first), " - ", te_value(&torrent::File::range_second)); + element->push_column("Size:", te_command("if=$fi.is_file=,$to_xb=$f.get_size_bytes=,---")); + + element->push_column("Chunks:", te_command("cat=$f.get_completed_chunks=,\" / \",$f.get_size_chunks=")); + element->push_column("Range:", te_command("cat=$f.get_range_first=,\" - \",$f.get_range_second=")); element->set_column_width(element->column_width() + 1); diff --git a/src/ui/element_peer_list.cc b/src/ui/element_peer_list.cc index 560a4504..c42a0980 100644 --- a/src/ui/element_peer_list.cc +++ b/src/ui/element_peer_list.cc @@ -36,7 +36,7 @@ #include "config.h" -#include +#include #include #include #include diff --git a/src/ui/root.cc b/src/ui/root.cc index bf462971..53b6acdd 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include "core/manager.h"