From ea192b342c6bb62e2a85e69845e6a5ee406056dd Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 6 Aug 2011 08:01:09 +0000 Subject: [PATCH] * Fixed 'd.group.set' for the mainline version. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1264 e378c898-3ddf-0310-93e7-cc216c733640 --- src/command_download.cc | 25 +++++++++++++------------ src/command_groups.cc | 16 ++++++++++++++++ src/core/download.cc | 3 ++- src/core/download.h | 6 ++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/command_download.cc b/src/command_download.cc index bbdde74d..c933f3b9 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -599,10 +599,8 @@ d_list_remove(core::Download* download, const torrent::Object& rawArgs, const ch std::placeholders::_1, std::placeholders::_2, \ first_key, second_key)); -torrent::choke_group* cg_get_group(const torrent::Object& raw_args); -int64_t cg_get_index(const torrent::Object& raw_args); - -#define CG_GROUP_INDEX() std::bind(&cg_get_index, std::placeholders::_2) +int64_t cg_d_group(core::Download* download); +void cg_d_group_set(core::Download* download, const torrent::Object& arg); void initialize_command_download() { @@ -808,15 +806,18 @@ initialize_command_download() { CMD2_DL ("d.priority_str", std::bind(&retrieve_d_priority_str, std::placeholders::_1)); CMD2_DL_VALUE_V ("d.priority.set", std::bind(&core::Download::set_priority, std::placeholders::_1, std::placeholders::_2)); - CMD2_DL ("d.group", std::bind(&torrent::resource_manager_entry::group, - std::bind(&torrent::ResourceManager::entry_at, torrent::resource_manager(), - std::bind(&core::Download::main, std::placeholders::_1)))); + // CMD2_DL ("d.group", std::bind(&torrent::resource_manager_entry::group, + // std::bind(&torrent::ResourceManager::entry_at, torrent::resource_manager(), + // std::bind(&core::Download::main, std::placeholders::_1)))); - CMD2_DL_V ("d.group.set", std::bind(&torrent::ResourceManager::set_group, - torrent::resource_manager(), - std::bind(&torrent::ResourceManager::find_throw, torrent::resource_manager(), - std::bind(&core::Download::main, std::placeholders::_1)), - CG_GROUP_INDEX())); + // CMD2_DL_V ("d.group.set", std::bind(&torrent::ResourceManager::set_group, + // torrent::resource_manager(), + // std::bind(&torrent::ResourceManager::find_throw, torrent::resource_manager(), + // std::bind(&core::Download::main, std::placeholders::_1)), + // CG_GROUP_INDEX())); + + CMD2_DL ("d.group", std::bind(&cg_d_group, std::placeholders::_1));; + CMD2_DL_V ("d.group.set", std::bind(&cg_d_group_set, std::placeholders::_1, std::placeholders::_2)); CMD2_DL ("d.initialize_logs", std::bind(&cmd_d_initialize_logs, std::placeholders::_1)); diff --git a/src/command_groups.cc b/src/command_groups.cc index 8dfdd1f2..abdff5fd 100644 --- a/src/command_groups.cc +++ b/src/command_groups.cc @@ -49,6 +49,9 @@ #include "control.h" #include "command_helpers.h" +// For cg_d_group. +#include "core/download.h" + // A hack to allow testing of the new choke_group API without the // working parts present. #define USE_CHOKE_GROUP 0 @@ -80,6 +83,16 @@ cg_get_group(const torrent::Object& raw_args) { return torrent::resource_manager()->group_at(cg_get_index(raw_args)); } +int64_t +cg_d_group(core::Download* download) { + return torrent::resource_manager()->entry_at(download->main())->group(); +} + +void +cg_d_group_set(core::Download* download, const torrent::Object& arg) { + torrent::resource_manager::set_group(torrent::resource_manager()->find_throw(download->main()), cg_get_index(arg)); +} + torrent::Object apply_cg_list() { torrent::Object::list_type result; @@ -151,6 +164,9 @@ cg_get_group(const torrent::Object& raw_args) { return cg_list_hack.at(index); } +int64_t cg_d_group(core::Download* download) { return download->group(); } +void cg_d_group_set(core::Download* download, const torrent::Object& arg) { download->set_group(cg_get_index(arg)); } + torrent::Object apply_cg_list() { torrent::Object::list_type result; diff --git a/src/core/download.cc b/src/core/download.cc index c93c667f..bebdaaad 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -61,7 +61,8 @@ Download::Download(download_type d) : m_hashFailed(false), m_chunksFailed(0), - m_resumeFlags(~uint32_t()) { + m_resumeFlags(~uint32_t()), + m_group(0) { m_connTrackerSucceeded = m_download.info()->signal_tracker_success().connect(sigc::bind(sigc::mem_fun(*this, &Download::receive_tracker_msg), "")); m_connTrackerFailed = m_download.info()->signal_tracker_failed().connect(sigc::mem_fun(*this, &Download::receive_tracker_msg)); diff --git a/src/core/download.h b/src/core/download.h index 9f5b28d5..a5b72bfd 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -129,6 +129,10 @@ public: float distributed_copies() const; + // HACK: Choke group setting. + unsigned int group() const { return m_group; } + void set_group(unsigned int g) { m_group = g; } + private: Download(const Download&); void operator () (const Download&); @@ -151,6 +155,8 @@ private: sigc::connection m_connTrackerSucceeded; sigc::connection m_connTrackerFailed; sigc::connection m_connStorageError; + + unsigned int m_group; }; inline bool