* Cleaned up torrent/download.h.

* Removed raw_value as it is redundant.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1145 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2010-03-15 18:31:50 +00:00
parent 19be810642
commit c5e839287d
9 changed files with 74 additions and 50 deletions
+33 -25
View File
@@ -107,16 +107,16 @@ apply_d_change_link(int changeType, core::Download* download, const torrent::Obj
std::string link;
if (type == "base_path") {
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
link = rak::path_expand(prefix + rpc::call_command_string("d.get_base_path", rpc::make_target(download)) + postfix);
target = rpc::call_command_string("d.base_path", rpc::make_target(download));
link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix);
} else if (type == "base_filename") {
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
target = rpc::call_command_string("d.base_path", rpc::make_target(download));
link = rak::path_expand(prefix + rpc::call_command_string("d.get_base_filename", rpc::make_target(download)) + postfix);
// } else if (type == "directory_path") {
// target = rpc::call_command_string("d.get_directory", rpc::make_target(download));
// link = rak::path_expand(prefix + rpc::call_command_string("d.get_base_path", rpc::make_target(download)) + postfix);
// link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix);
} else if (type == "tied") {
link = rak::path_expand(rpc::call_command_string("d.get_tied_to_file", rpc::make_target(download)));
@@ -125,7 +125,7 @@ apply_d_change_link(int changeType, core::Download* download, const torrent::Obj
return torrent::Object();
link = rak::path_expand(prefix + link + postfix);
target = rpc::call_command_string("d.get_base_path", rpc::make_target(download));
target = rpc::call_command_string("d.base_path", rpc::make_target(download));
} else {
throw torrent::input_error("Unknown type argument.");
@@ -191,9 +191,9 @@ apply_d_directory(core::Download* download, const std::string& name) {
if (!download->file_list()->is_multi_file())
download->set_root_directory(name);
else if (name.empty() || *name.rbegin() == '/')
download->set_root_directory(name + download->download()->name());
download->set_root_directory(name + download->info()->name());
else
download->set_root_directory(name + "/" + download->download()->name());
download->set_root_directory(name + "/" + download->info()->name());
}
const char*
@@ -232,28 +232,28 @@ retrieve_d_ratio(core::Download* download) {
return int64_t();
int64_t bytesDone = download->download()->bytes_done();
int64_t upTotal = download->download()->up_rate()->total();
int64_t upTotal = download->info()->up_rate()->total();
return bytesDone > 0 ? (1000 * upTotal) / bytesDone : 0;
}
torrent::Object
retrieve_d_hash(core::Download* download) {
const torrent::HashString* hashString = &download->download()->info_hash();
const torrent::HashString* hashString = &download->info()->hash();
return torrent::Object(rak::transform_hex(hashString->begin(), hashString->end()));
}
torrent::Object
retrieve_d_local_id(core::Download* download) {
const torrent::HashString* hashString = &download->download()->local_id();
const torrent::HashString* hashString = &download->info()->local_id();
return torrent::Object(rak::transform_hex(hashString->begin(), hashString->end()));
}
torrent::Object
retrieve_d_local_id_html(core::Download* download) {
const torrent::HashString* hashString = &download->download()->local_id();
const torrent::HashString* hashString = &download->info()->local_id();
return torrent::Object(rak::copy_escape_html(hashString->begin(), hashString->end()));
}
@@ -562,15 +562,22 @@ add_copy_to_download(const char* src, const char* dest) {
rpc::commands.insert(dest, itr->second);
}
#define CMD_ON_INFO(func) \
rak::on(std::mem_fun(&core::Download::info), std::mem_fun(&torrent::DownloadInfo::func))
void
initialize_command_download() {
ADD_CD_VOID("hash", &retrieve_d_hash);
ADD_CD_VOID("local_id", &retrieve_d_local_id);
ADD_CD_VOID("local_id_html", &retrieve_d_local_id_html);
ADD_CD_VOID("bitfield", &retrieve_d_bitfield);
ADD_CD_VOID("base_path", &retrieve_d_base_path);
ADD_CD_VOID("base_filename", &retrieve_d_base_filename);
ADD_CD_STRING_UNI("name", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::name)));
CMD_D_VOID("d.hash", &retrieve_d_hash);
CMD_D_VOID("d.local_id", &retrieve_d_local_id);
CMD_D_VOID("d.local_id_html", &retrieve_d_local_id_html);
CMD_D_VOID("d.bitfield", &retrieve_d_bitfield);
CMD_D_VOID("d.base_path", &retrieve_d_base_path);
CMD_D_VOID("d.base_filename", &retrieve_d_base_filename);
CMD_D_VOID_SLOT("d.name", CMD_ON_INFO(name));
CMD_D_VOID_SLOT("d.creation_date", CMD_ON_INFO(creation_date));
CMD_D_VOID_SLOT("d.load_date", CMD_ON_INFO(load_date));
// ?????
ADD_CD_LIST_OBSOLETE("create_link", rak::bind_ptr_fn(&apply_d_change_link, 0));
@@ -676,17 +683,18 @@ initialize_command_download() {
ADD_CD_VALUE_UNI("peers_complete", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::peers_complete)));
ADD_CD_VALUE_UNI("peers_accounted", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::peers_accounted)));
ADD_CD_VALUE_MEM_UNI("up_rate", &torrent::Download::mutable_up_rate, &torrent::Rate::rate);
ADD_CD_VALUE_MEM_UNI("up_total", &torrent::Download::mutable_up_rate, &torrent::Rate::total);
ADD_CD_VALUE_MEM_UNI("down_rate", &torrent::Download::mutable_down_rate, &torrent::Rate::rate);
ADD_CD_VALUE_MEM_UNI("down_total", &torrent::Download::mutable_down_rate, &torrent::Rate::total);
ADD_CD_VALUE_MEM_UNI("skip_rate", &torrent::Download::mutable_skip_rate, &torrent::Rate::rate);
ADD_CD_VALUE_MEM_UNI("skip_total", &torrent::Download::mutable_skip_rate, &torrent::Rate::total);
//
CMD_D_VOID_SLOT("d.up.rate", rak::on(CMD_ON_INFO(up_rate), std::mem_fun(&torrent::Rate::rate)));
CMD_D_VOID_SLOT("d.up.total", rak::on(CMD_ON_INFO(up_rate), std::mem_fun(&torrent::Rate::total)));
CMD_D_VOID_SLOT("d.down.rate", rak::on(CMD_ON_INFO(down_rate), std::mem_fun(&torrent::Rate::rate)));
CMD_D_VOID_SLOT("d.down.total", rak::on(CMD_ON_INFO(down_rate), std::mem_fun(&torrent::Rate::total)));
CMD_D_VOID_SLOT("d.skip.rate", rak::on(CMD_ON_INFO(skip_rate), std::mem_fun(&torrent::Rate::rate)));
CMD_D_VOID_SLOT("d.skip.total", rak::on(CMD_ON_INFO(skip_rate), std::mem_fun(&torrent::Rate::total)));
//
ADD_CD_STRING("set_throttle_name", std::mem_fun(&core::Download::set_throttle_name));
ADD_CD_SLOT_PUBLIC("d.get_throttle_name", call_unknown, rpc::get_variable_d_fn("rtorrent", "throttle_name"), "i:", "");
ADD_CD_VALUE_UNI("creation_date", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::creation_date)));
ADD_CD_VALUE_UNI("bytes_done", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::bytes_done)));
ADD_CD_VALUE_UNI("ratio", std::ptr_fun(&retrieve_d_ratio));
ADD_CD_VALUE_UNI("chunks_hashed", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::chunks_hashed)));
+2 -2
View File
@@ -94,7 +94,7 @@ apply_on_ratio(const torrent::Object& rawArgs) {
// rpc::parse_command_single(rpc::make_target(*itr), "print={Checked ratio of download.}");
int64_t totalDone = (*itr)->download()->bytes_done();
int64_t totalUpload = (*itr)->download()->up_rate()->total();
int64_t totalUpload = (*itr)->info()->up_rate()->total();
if (!(totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) &&
!(maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio))
@@ -264,7 +264,7 @@ apply_download_list(const torrent::Object& rawArgs) {
torrent::Object::list_type& resultList = result.as_list();
for (core::View::const_iterator itr = (*viewItr)->begin_visible(), last = (*viewItr)->end_visible(); itr != last; itr++) {
const torrent::HashString* hashString = &(*itr)->download()->info_hash();
const torrent::HashString* hashString = &(*itr)->info()->hash();
resultList.push_back(rak::transform_hex(hashString->begin(), hashString->end()));
}
+1 -1
View File
@@ -152,7 +152,7 @@ private:
inline bool
Download::operator == (const std::string& str) const {
return str.size() == torrent::HashString::size_data && *torrent::HashString::cast_from(str) == m_download.info_hash();
return str.size() == torrent::HashString::size_data && *torrent::HashString::cast_from(str) == m_download.info()->hash();
}
}
+2 -2
View File
@@ -304,7 +304,7 @@ DownloadFactory::receive_success() {
}
// Save the info-hash just in case the commands decide to delete it.
torrent::HashString infohash = download->download()->info_hash();
torrent::HashString infohash = download->info()->hash();
try {
std::for_each(m_commands.begin(), m_commands.end(), rak::bind1st(std::ptr_fun(&rpc::parse_command_d_multiple_std), download));
@@ -382,7 +382,7 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre
}
if (rtorrent->has_key_value("total_uploaded"))
download->download()->up_rate()->set_total(rtorrent->get_key_value("total_uploaded"));
download->info()->mutable_up_rate()->set_total(rtorrent->get_key_value("total_uploaded"));
if (rtorrent->has_key_value("chunks_done"))
download->download()->set_chunks_done(std::min<uint32_t>(rtorrent->get_key_value("chunks_done"),
+2 -2
View File
@@ -94,7 +94,7 @@ DownloadList::session_save() {
DownloadList::iterator
DownloadList::find(const torrent::HashString& hash) {
return std::find_if(begin(), end(), rak::equal(hash, rak::on(std::mem_fun(&Download::download), std::mem_fun(&torrent::Download::info_hash))));
return std::find_if(begin(), end(), rak::equal(hash, rak::on(std::mem_fun(&Download::info), std::mem_fun(&torrent::DownloadInfo::hash))));
}
DownloadList::iterator
@@ -104,7 +104,7 @@ DownloadList::find_hex(const char* hash) {
for (torrent::HashString::iterator itr = key.begin(), last = key.end(); itr != last; itr++, hash += 2)
*itr = (rak::hexchar_to_value(*hash) << 4) + rak::hexchar_to_value(*(hash + 1));
return std::find_if(begin(), end(), rak::equal(key, rak::on(std::mem_fun(&Download::download), std::mem_fun(&torrent::Download::info_hash))));
return std::find_if(begin(), end(), rak::equal(key, rak::on(std::mem_fun(&Download::info), std::mem_fun(&torrent::DownloadInfo::hash))));
}
Download*
+2 -2
View File
@@ -138,7 +138,7 @@ DownloadStore::save(Download* d, int flags) {
// Move this somewhere else?
rtorrent_base->insert_key("chunks_done", d->download()->file_list()->completed_chunks());
rtorrent_base->insert_key("total_uploaded", d->download()->up_rate()->total());
rtorrent_base->insert_key("total_uploaded", d->info()->up_rate()->total());
// Don't save for completed torrents when we've cleared the uncertain_pieces.
torrent::resume_save_progress(*d->download(), *resume_base);
@@ -214,7 +214,7 @@ DownloadStore::is_correct_format(const std::string& f) {
std::string
DownloadStore::create_filename(Download* d) {
return m_path + rak::transform_hex(d->download()->info_hash().begin(), d->download()->info_hash().end()) + ".torrent";
return m_path + rak::transform_hex(d->info()->hash().begin(), d->info()->hash().end()) + ".torrent";
}
}
+5 -5
View File
@@ -127,7 +127,7 @@ print_address(char* first, char* last, const sockaddr* sa) {
char*
print_download_title(char* first, char* last, core::Download* d) {
return print_buffer(first, last, " %s", d->download()->name().c_str());
return print_buffer(first, last, " %s", d->info()->name().c_str());
}
char*
@@ -147,9 +147,9 @@ print_download_info(char* first, char* last, core::Download* d) {
(double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
first = print_buffer(first, last, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB",
(double)d->download()->up_rate()->rate() / (1 << 10),
(double)d->download()->down_rate()->rate() / (1 << 10),
(double)d->download()->up_rate()->total() / (1 << 20));
(double)d->info()->up_rate()->rate() / (1 << 10),
(double)d->info()->down_rate()->rate() / (1 << 10),
(double)d->info()->up_rate()->total() / (1 << 20));
if (d->download()->info()->is_active() && !d->is_done()) {
first = print_buffer(first, last, " ");
@@ -216,7 +216,7 @@ print_download_status(char* first, char* last, core::Download* d) {
char*
print_download_time_left(char* first, char* last, core::Download* d) {
uint32_t rate = d->download()->down_rate()->rate();
uint32_t rate = d->info()->down_rate()->rate();
if (rate < 512)
return print_buffer(first, last, "--d --:--");
+18 -2
View File
@@ -249,8 +249,8 @@ main(int argc, char** argv) {
"view_add = default\n"
"view_add = name\n"
"view_sort_new = name,less=d.get_name=\n"
"view_sort_current = name,less=d.get_name=\n"
"view_sort_new = name,less=d.name=\n"
"view_sort_current = name,less=d.name=\n"
"view_add = active\n"
"view_filter = active,false=\n"
@@ -351,7 +351,23 @@ main(int argc, char** argv) {
"method.insert = get_max_memory_usage,redirect|const,pieces.memory.max\n"
"method.insert = set_max_memory_usage,redirect|const,pieces.memory.max.set\n"
"method.insert = d.get_hash,redirect|const,d.hash\n"
"method.insert = d.get_local_id,redirect|const,d.local_id\n"
"method.insert = d.get_local_id_html,redirect|const,d.local_id_html\n"
"method.insert = d.get_bitfield,redirect|const,d.bitfield\n"
"method.insert = d.get_base_path,redirect|const,d.base_path\n"
"method.insert = d.get_name,redirect|const,d.name\n"
"method.insert = d.get_creation_date,redirect|const,d.creation_date\n"
"method.insert = d.get_peer_exchange,redirect|const,d.peer_exchange\n"
"method.insert = d.get_up_rate,redirect|const,d.up.rate\n"
"method.insert = d.get_up_total,redirect|const,d.up.total\n"
"method.insert = d.get_down_rate,redirect|const,d.down.rate\n"
"method.insert = d.get_down_total,redirect|const,d.down.total\n"
"method.insert = d.get_skip_rate,redirect|const,d.skip.rate\n"
"method.insert = d.get_skip_total,redirect|const,d.skip.total\n"
);
}
+9 -9
View File
@@ -149,14 +149,14 @@ Download::create_info() {
// Get these bindings with some kind of string map.
element->push_column("Name:", te_command("d.get_name="));
element->push_column("Local id:", te_command("d.get_local_id_html="));
element->push_column("Info hash:", te_command("d.get_hash="));
element->push_column("Created:", te_command("cat=$to_date=$d.get_creation_date=,\" \",$to_time=$d.get_creation_date="));
element->push_column("Name:", te_command("d.name="));
element->push_column("Local id:", te_command("d.local_id_html="));
element->push_column("Info hash:", te_command("d.hash="));
element->push_column("Created:", te_command("cat=$to_date=$d.creation_date=,\" \",$to_time=$d.creation_date="));
element->push_back("");
element->push_column("Directory:", te_command("d.get_directory="));
element->push_column("Base Path:", te_command("d.get_base_path="));
element->push_column("Base Path:", te_command("d.base_path="));
element->push_column("Tied to file:", te_command("d.get_tied_to_file="));
element->push_column("File stats:", te_command("cat=$if=$d.is_multi_file=\\,multi\\,single,\" \",$d.get_size_files=,\" files\""));
@@ -191,9 +191,9 @@ Download::create_info() {
"cat=\"global\""));
element->push_back("");
element->push_column("Upload:", te_command("cat=$to_kb=$d.get_up_rate=,\" KB / \",$to_xb=$d.get_up_total="));
element->push_column("Download:", te_command("cat=$to_kb=$d.get_down_rate=,\" KB / \",$to_xb=$d.get_down_total="));
element->push_column("Skipped:", te_command("cat=$to_kb=$d.get_skip_rate=,\" KB / \",$to_xb=$d.get_skip_total="));
element->push_column("Upload:", te_command("cat=$to_kb=$d.up.rate=,\" KB / \",$to_xb=$d.up.total="));
element->push_column("Download:", te_command("cat=$to_kb=$d.down.rate=,\" KB / \",$to_xb=$d.down.total="));
element->push_column("Skipped:", te_command("cat=$to_kb=$d.skip.rate=,\" KB / \",$to_xb=$d.skip.total="));
element->push_column("Preload:", te_command("cat=$pieces.preload.type=,\" / \",$pieces.stats_preloaded=,\" / \",$pieces.stats_preloaded="));
element->set_column_width(element->column_width() + 1);
@@ -289,7 +289,7 @@ Download::activate_display(Display displayType, bool focusDisplay) {
// Set title.
switch (displayType) {
case DISPLAY_MAX_SIZE: break;
default: control->ui()->window_title()->set_title(m_download->download()->name()); break;
default: control->ui()->window_title()->set_title(m_download->info()->name()); break;
}
control->display()->adjust_layout();