mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-12 13:12:32 +00:00
* Added "create_link" and "delete_link" options for creating and
deleting symbolic links to downloads. * Added "on_*" options for calling commands on state changes. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@849 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+10
-65
@@ -49,31 +49,13 @@
|
||||
#include <torrent/data/file_list.h>
|
||||
|
||||
#include "utils/variable_generic.h"
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "download.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
template <typename Target, typename GetFunc, typename SetFunc>
|
||||
utils::Variable*
|
||||
var_d_value(Target target, GetFunc getFunc, SetFunc setFunc) {
|
||||
return new utils::VariableDownloadValueSlot(rak::ftor_fn1(rak::on(std::mem_fun(target), std::mem_fun(getFunc))),
|
||||
rak::ftor_fn2(rak::on2(std::mem_fun(target), std::mem_fun(setFunc))));
|
||||
}
|
||||
|
||||
template <typename Target, typename GetFunc, typename SetFunc>
|
||||
utils::Variable*
|
||||
var_d2_value(Target target, GetFunc getFunc, SetFunc setFunc) {
|
||||
return new utils::VariableDownloadValueSlot(rak::ftor_fn1(rak::on(rak::on(std::mem_fun(&Download::download), std::mem_fun(target)), std::mem_fun(getFunc))),
|
||||
rak::ftor_fn2(rak::on2(rak::on(std::mem_fun(&Download::download), std::mem_fun(target)), std::mem_fun(setFunc))));
|
||||
}
|
||||
|
||||
template <typename Target, typename GetFunc>
|
||||
utils::Variable*
|
||||
var_d2_get_value(Target target, GetFunc getFunc) {
|
||||
return new utils::VariableDownloadValueSlot(rak::ftor_fn1(rak::on(rak::on(std::mem_fun(&Download::download), std::mem_fun(target)), std::mem_fun(getFunc))), NULL);
|
||||
}
|
||||
|
||||
Download::Download(download_type d) :
|
||||
m_download(d),
|
||||
m_trackerList(d.tracker_list()),
|
||||
@@ -87,51 +69,6 @@ Download::Download(download_type d) :
|
||||
m_connStorageError = m_download.signal_storage_error(sigc::mem_fun(*this, &Download::receive_storage_error));
|
||||
|
||||
m_download.signal_chunk_failed(sigc::mem_fun(*this, &Download::receive_chunk_failed));
|
||||
|
||||
m_variables.insert("connection_current", new utils::VariableDownloadStringSlot(rak::ftor_fn1(std::mem_fun(&Download::connection_current)),
|
||||
rak::ftor_fn2(std::mem_fun(&Download::set_connection_current))));
|
||||
|
||||
m_variables.insert("connection_leech", new utils::VariableAny(connection_type_to_string(download_type::CONNECTION_LEECH)));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(connection_type_to_string(download_type::CONNECTION_SEED)));
|
||||
|
||||
// 0 - stopped
|
||||
// 1 - started
|
||||
m_variables.insert("state", new utils::VariableObject("rtorrent", "state", torrent::Object::TYPE_VALUE));
|
||||
m_variables.insert("complete", new utils::VariableObject("rtorrent", "complete", torrent::Object::TYPE_VALUE));
|
||||
|
||||
// 0 - Not hashing
|
||||
// 1 - Normal hashing
|
||||
// 2 - Download finished, hashing
|
||||
m_variables.insert("hashing", new utils::VariableObject("rtorrent", "hashing", torrent::Object::TYPE_VALUE));
|
||||
m_variables.insert("tied_to_file", new utils::VariableObject("rtorrent", "tied_to_file", torrent::Object::TYPE_STRING));
|
||||
|
||||
// The "state_changed" variable is required to be a valid unix time
|
||||
// value, it indicates the last time the torrent changed its state,
|
||||
// resume/pause.
|
||||
m_variables.insert("state_changed", new utils::VariableObject("rtorrent", "state_changed", torrent::Object::TYPE_VALUE));
|
||||
|
||||
m_variables.insert("directory", new utils::VariableDownloadStringSlot(rak::ftor_fn1(rak::on(std::mem_fun(&Download::file_list), std::mem_fun(&torrent::FileList::root_dir))),
|
||||
rak::ftor_fn2(std::mem_fun(&Download::set_root_directory))));
|
||||
m_variables.insert("min_peers", var_d_value(&Download::download, &download_type::peers_min, &download_type::set_peers_min));
|
||||
m_variables.insert("max_peers", var_d_value(&Download::download, &download_type::peers_max, &download_type::set_peers_max));
|
||||
m_variables.insert("max_uploads", var_d_value(&Download::download, &download_type::uploads_max, &download_type::set_uploads_max));
|
||||
|
||||
m_variables.insert("max_file_size", var_d_value(&Download::file_list, &file_list_type::max_file_size, &file_list_type::set_max_file_size));
|
||||
|
||||
// m_variables.insert("split_file_size", new utils::VariableValueSlot(rak::mem_fn(file_list(), &file_list_type::split_file_size), rak::mem_fn(file_list(), &file_list_type::set_split_file_size)));
|
||||
// m_variables.insert("split_suffix", new utils::VariableStringSlot(rak::mem_fn(file_list(), &file_list_type::split_suffix), rak::mem_fn(file_list(), &file_list_type::set_split_suffix)));
|
||||
|
||||
m_variables.insert("up_rate", var_d2_get_value(&download_type::mutable_up_rate, &torrent::Rate::rate));
|
||||
m_variables.insert("up_total", var_d2_get_value(&download_type::mutable_up_rate, &torrent::Rate::total));
|
||||
m_variables.insert("down_rate", var_d2_get_value(&download_type::mutable_down_rate, &torrent::Rate::rate));
|
||||
m_variables.insert("down_total", var_d2_get_value(&download_type::mutable_down_rate, &torrent::Rate::total));
|
||||
m_variables.insert("skip_rate", var_d2_get_value(&download_type::mutable_skip_rate, &torrent::Rate::rate));
|
||||
m_variables.insert("skip_total", var_d2_get_value(&download_type::mutable_skip_rate, &torrent::Rate::total));
|
||||
|
||||
m_variables.insert("priority", new utils::VariableDownloadValueSlot(rak::ftor_fn1(std::mem_fun(&Download::priority)), rak::ftor_fn2(std::mem_fun(&Download::set_priority))));
|
||||
m_variables.insert("tracker_numwant", var_d_value(&Download::tracker_list, &tracker_list_type::numwant, &tracker_list_type::set_numwant));
|
||||
|
||||
m_variables.insert("ignore_commands", new utils::VariableObject("rtorrent", "ignore_commands", torrent::Object::TYPE_VALUE));
|
||||
}
|
||||
|
||||
Download::~Download() {
|
||||
@@ -269,6 +206,14 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) {
|
||||
m_chunksFailed++;
|
||||
}
|
||||
|
||||
int64_t Download::get_value(const char* key) { return control->download_variables()->get_d_value(this, key); }
|
||||
const std::string& Download::get_string(const char* key) { return control->download_variables()->get_d_string(this, key); }
|
||||
int64_t Download::get_std_value(const std::string& key) { return control->download_variables()->get_d_value(this, key.c_str()); }
|
||||
const std::string& Download::get_std_string(const std::string& key) { return control->download_variables()->get_d_string(this, key.c_str()); }
|
||||
void Download::set(const char* key, const torrent::Object& value) { return control->download_variables()->set_d(this, key, value); }
|
||||
void Download::set_value(const char* key, int64_t value) { return control->download_variables()->set_d_value(this, key, value); }
|
||||
void Download::set_string(const char* key, const std::string& value) { return control->download_variables()->set_d_string(this, key, value); }
|
||||
|
||||
// Clean up.
|
||||
void
|
||||
Download::set_root_directory(const std::string& path) {
|
||||
|
||||
+12
-17
@@ -43,7 +43,7 @@
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/data/file_list.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "globals.h"
|
||||
|
||||
namespace torrent {
|
||||
class TrackerList;
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
typedef torrent::FileList file_list_type;
|
||||
typedef torrent::TrackerList tracker_list_type;
|
||||
typedef download_type::ConnectionType connection_type;
|
||||
typedef utils::VariableMap variable_map_type;
|
||||
|
||||
static const int variable_hashing_stopped = 0;
|
||||
static const int variable_hashing_initial = 1;
|
||||
@@ -101,18 +100,18 @@ public:
|
||||
uint32_t priority();
|
||||
void set_priority(uint32_t p);
|
||||
|
||||
// variable_map_type* variable() { return &m_variables; }
|
||||
int64_t get_value(const char* key);
|
||||
const std::string& get_string(const char* key);
|
||||
|
||||
int64_t get_value(const char* key) { return m_variables.get_d_value(this, key); }
|
||||
const std::string& get_string(const char* key) { return m_variables.get_d_string(this, key); }
|
||||
int64_t get_std_value(const std::string& key);
|
||||
const std::string& get_std_string(const std::string& key);
|
||||
|
||||
int64_t get_std_value(const std::string& key) { return m_variables.get_d_value(this, key.c_str()); }
|
||||
const std::string& get_std_string(const std::string& key) { return m_variables.get_d_string(this, key.c_str()); }
|
||||
void set(const char* key, const torrent::Object& value);
|
||||
|
||||
void set(const char* key, const torrent::Object& value) { return m_variables.set_d(this, key, value); }
|
||||
void set_value(const char* key, int64_t value);
|
||||
void set_string(const char* key, const std::string& value);
|
||||
|
||||
void set_value(const char* key, int64_t value) { return m_variables.set_d_value(this, key, value); }
|
||||
void set_string(const char* key, const std::string& value) { return m_variables.set_d_string(this, key, value); }
|
||||
void set_root_directory(const std::string& path);
|
||||
|
||||
bool operator == (const std::string& str) const;
|
||||
|
||||
@@ -121,6 +120,9 @@ public:
|
||||
static connection_type string_to_connection_type(const std::string& name);
|
||||
static const char* connection_type_to_string(connection_type t);
|
||||
|
||||
const char* connection_current() const { return connection_type_to_string(m_download.connection_type()); }
|
||||
void set_connection_current(const std::string& t) { return m_download.set_connection_type(string_to_connection_type(t.c_str())); }
|
||||
|
||||
static uint32_t string_to_priority(const std::string& name);
|
||||
static const char* priority_to_string(uint32_t p);
|
||||
|
||||
@@ -135,11 +137,6 @@ private:
|
||||
|
||||
void receive_chunk_failed(uint32_t idx);
|
||||
|
||||
const char* connection_current() const { return connection_type_to_string(m_download.connection_type()); }
|
||||
void set_connection_current(const std::string& t) { return m_download.set_connection_type(string_to_connection_type(t.c_str())); }
|
||||
|
||||
void set_root_directory(const std::string& path);
|
||||
|
||||
// Store the FileList instance so we can use slots etc on it.
|
||||
download_type m_download;
|
||||
tracker_list_type m_trackerList;
|
||||
@@ -149,8 +146,6 @@ private:
|
||||
std::string m_message;
|
||||
uint32_t m_chunksFailed;
|
||||
|
||||
variable_map_type m_variables;
|
||||
|
||||
sigc::connection m_connTrackerSucceded;
|
||||
sigc::connection m_connTrackerFailed;
|
||||
sigc::connection m_connStorageError;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "utils/variable_generic.h"
|
||||
|
||||
#include "curl_get.h"
|
||||
#include "control.h"
|
||||
#include "http_queue.h"
|
||||
#include "globals.h"
|
||||
#include "manager.h"
|
||||
|
||||
@@ -39,14 +39,16 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sigc++/bind.h>
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/object_stream.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "rak/functional.h"
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
#include "manager.h"
|
||||
|
||||
|
||||
+2
-1
@@ -59,6 +59,7 @@
|
||||
|
||||
#include "globals.h"
|
||||
#include "curl_get.h"
|
||||
#include "control.h"
|
||||
#include "download.h"
|
||||
#include "download_factory.h"
|
||||
#include "download_store.h"
|
||||
@@ -241,7 +242,7 @@ Manager::initialize_second() {
|
||||
m_downloadList->slot_map_insert()["1_connect_storage_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_storage_log), sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
m_downloadList->slot_map_insert()["1_connect_tracker_dump"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_dump), sigc::ptr_fun(&receive_tracker_dump));
|
||||
|
||||
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::mem_fun(this, &Manager::delete_tied);
|
||||
m_downloadList->slot_map_erase()["9_delete_tied"] = sigc::mem_fun(this, &Manager::delete_tied);
|
||||
|
||||
torrent::connection_manager()->set_signal_handshake_log(sigc::mem_fun(this, &Manager::handshake_log));
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "download.h"
|
||||
#include "download_list.h"
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <rak/functional.h>
|
||||
#include <sigc++/bind.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "download.h"
|
||||
#include "download_list.h"
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <algorithm>
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user