* Allow "print" command to take a list of parameters.

* Added "d_{start,stop,open,close,erase}" commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@934 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-07-11 19:22:34 +00:00
parent 36251a46bf
commit 3570602a08
6 changed files with 92 additions and 57 deletions
+62 -52
View File
@@ -228,47 +228,50 @@ retrieve_d_priority_str(core::Download* download) {
}
}
#define ADD_COMMAND_DOWNLOAD_SLOT(key, function, slot, parm, doc) \
#define ADD_C_DOWNLOAD_SLOT(key, function, slot, parm, doc) \
commandDownloadSlotsItr->set_slot(slot); \
rpc::commands.insert(key, commandDownloadSlotsItr++, NULL, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc);
#define ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC(key, function, slot, parm, doc) \
#define ADD_C_DOWNLOAD_SLOT_PUBLIC(key, function, slot, parm, doc) \
commandDownloadSlotsItr->set_slot(slot); \
rpc::commands.insert(key, commandDownloadSlotsItr++, NULL, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc);
#define ADD_COMMAND_DOWNLOAD_VOID(key, slot) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_d_fn(slot), "i:", "")
#define ADD_C_DOWNLOAD_VOID(key, slot) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_d_fn(slot), "i:", "")
#define ADD_COMMAND_DOWNLOAD_V_VOID(key, slot) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("d_" key, call_unknown, rpc::object_d_fn(slot), "i:", "")
#define ADD_C_DOWNLOAD_V_VOID(key, slot) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("d_" key, call_unknown, rpc::object_d_fn(slot), "i:", "")
#define ADD_COMMAND_DOWNLOAD_LIST(key, slot) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC(key, call_list, slot, "i:", "")
#define ADD_C_DOWNLOAD_F_VOID(key, slot) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("d_" key, call_unknown, rpc::object_void_d_fn(slot), "i:", "")
#define ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE(key, firstKey, secondKey) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \
ADD_COMMAND_DOWNLOAD_SLOT("set_d_" key, call_value, rpc::set_variable_d_fn(firstKey, secondKey), "i:i", "");
#define ADD_C_DOWNLOAD_LIST(key, slot) \
ADD_C_DOWNLOAD_SLOT_PUBLIC(key, call_list, slot, "i:", "")
#define ADD_COMMAND_DOWNLOAD_VARIABLE_STRING(key, firstKey, secondKey) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \
ADD_COMMAND_DOWNLOAD_SLOT("set_d_" key, call_string, rpc::set_variable_d_fn(firstKey, secondKey), "i:s", "");
#define ADD_C_DOWNLOAD_VARIABLE_VALUE(key, firstKey, secondKey) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \
ADD_C_DOWNLOAD_SLOT("set_d_" key, call_value, rpc::set_variable_d_fn(firstKey, secondKey), "i:i", "");
#define ADD_COMMAND_DOWNLOAD_VALUE_BI(key, set, get) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("set_d_" key, call_value, rpc::object_value_d_fn(set), "i:i", "") \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "")
#define ADD_C_DOWNLOAD_VARIABLE_STRING(key, firstKey, secondKey) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \
ADD_C_DOWNLOAD_SLOT("set_d_" key, call_string, rpc::set_variable_d_fn(firstKey, secondKey), "i:s", "");
#define ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI(key, target, set, get) \
ADD_COMMAND_DOWNLOAD_VALUE_BI(key, rak::on2(std::mem_fun(target), std::mem_fun(set)), rak::on(std::mem_fun(target), std::mem_fun(get)));
#define ADD_C_DOWNLOAD_VALUE_BI(key, set, get) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("set_d_" key, call_value, rpc::object_value_d_fn(set), "i:i", "") \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "")
#define ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI(key, target, get) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(rak::on(rak::on(std::mem_fun(&core::Download::download), std::mem_fun(target)), std::mem_fun(get))), "i:", "");
#define ADD_C_DOWNLOAD_VALUE_MEM_BI(key, target, set, get) \
ADD_C_DOWNLOAD_VALUE_BI(key, rak::on2(std::mem_fun(target), std::mem_fun(set)), rak::on(std::mem_fun(target), std::mem_fun(get)));
#define ADD_COMMAND_DOWNLOAD_STRING_UNI(key, get) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
#define ADD_C_DOWNLOAD_VALUE_MEM_UNI(key, target, get) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(rak::on(rak::on(std::mem_fun(&core::Download::download), std::mem_fun(target)), std::mem_fun(get))), "i:", "");
#define ADD_COMMAND_DOWNLOAD_STRING_BI(key, set, get) \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("set_d_" key, call_string, rpc::object_string_d_fn(set), "i:s", "") \
ADD_COMMAND_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
#define ADD_C_DOWNLOAD_STRING_UNI(key, get) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
#define ADD_C_DOWNLOAD_STRING_BI(key, set, get) \
ADD_C_DOWNLOAD_SLOT_PUBLIC("set_d_" key, call_string, rpc::object_string_d_fn(set), "i:s", "") \
ADD_C_DOWNLOAD_SLOT_PUBLIC("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "")
void
add_copy_to_download(const char* src, const char* dest) {
@@ -282,58 +285,65 @@ add_copy_to_download(const char* src, const char* dest) {
void
initialize_command_download() {
ADD_COMMAND_DOWNLOAD_VOID("base_path", &retrieve_d_base_path);
ADD_COMMAND_DOWNLOAD_VOID("base_filename", &retrieve_d_base_filename);
ADD_C_DOWNLOAD_VOID("base_path", &retrieve_d_base_path);
ADD_C_DOWNLOAD_VOID("base_filename", &retrieve_d_base_filename);
ADD_COMMAND_DOWNLOAD_LIST("create_link", rak::ptr_fn(&apply_d_create_link));
ADD_COMMAND_DOWNLOAD_LIST("delete_link", rak::ptr_fn(&apply_d_delete_link));
ADD_COMMAND_DOWNLOAD_V_VOID("delete_tied", &apply_d_delete_tied);
ADD_C_DOWNLOAD_LIST("create_link", rak::ptr_fn(&apply_d_create_link));
ADD_C_DOWNLOAD_LIST("delete_link", rak::ptr_fn(&apply_d_delete_link));
ADD_C_DOWNLOAD_V_VOID("delete_tied", &apply_d_delete_tied);
ADD_C_DOWNLOAD_F_VOID("start", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::start_normal));
ADD_C_DOWNLOAD_F_VOID("stop", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::stop_normal));
ADD_C_DOWNLOAD_F_VOID("open", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::open_throw));
ADD_C_DOWNLOAD_F_VOID("close", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::close_throw));
ADD_C_DOWNLOAD_F_VOID("erase", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::erase_ptr));
ADD_C_DOWNLOAD_F_VOID("check_hash", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::check_hash));
// 0 - stopped
// 1 - started
ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE("state", "rtorrent", "state");
ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE("complete", "rtorrent", "complete");
ADD_C_DOWNLOAD_VARIABLE_VALUE("state", "rtorrent", "state");
ADD_C_DOWNLOAD_VARIABLE_VALUE("complete", "rtorrent", "complete");
// 0 - Not hashing
// 1 - Normal hashing
// 2 - Download finished, hashing
ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE("hashing", "rtorrent", "hashing");
ADD_COMMAND_DOWNLOAD_VARIABLE_STRING("tied_to_file", "rtorrent", "tied_to_file");
ADD_C_DOWNLOAD_VARIABLE_VALUE("hashing", "rtorrent", "hashing");
ADD_C_DOWNLOAD_VARIABLE_STRING("tied_to_file", "rtorrent", "tied_to_file");
// 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.
ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE("state_changed", "rtorrent", "state_changed");
ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE("ignore_commands", "rtorrent", "ignore_commands");
ADD_C_DOWNLOAD_VARIABLE_VALUE("state_changed", "rtorrent", "state_changed");
ADD_C_DOWNLOAD_VARIABLE_VALUE("ignore_commands", "rtorrent", "ignore_commands");
ADD_COMMAND_DOWNLOAD_STRING_BI("connection_current", std::ptr_fun(&apply_d_connection_type), std::ptr_fun(&retrieve_d_connection_type));
ADD_C_DOWNLOAD_STRING_BI("connection_current", std::ptr_fun(&apply_d_connection_type), std::ptr_fun(&retrieve_d_connection_type));
add_copy_to_download("get_connection_leech", "get_d_connection_leech");
add_copy_to_download("set_connection_leech", "set_d_connection_leech");
add_copy_to_download("get_connection_seed", "get_d_connection_seed");
add_copy_to_download("set_connection_seed", "set_d_connection_seed");
ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI("max_file_size", &core::Download::file_list, &torrent::FileList::set_max_file_size, &torrent::FileList::max_file_size);
ADD_C_DOWNLOAD_VALUE_MEM_BI("max_file_size", &core::Download::file_list, &torrent::FileList::set_max_file_size, &torrent::FileList::max_file_size);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI("min_peers", &core::Download::download, &torrent::Download::set_peers_min, &torrent::Download::peers_min);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI("max_peers", &core::Download::download, &torrent::Download::set_peers_max, &torrent::Download::peers_max);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI("max_uploads", &core::Download::download, &torrent::Download::set_uploads_max, &torrent::Download::uploads_max);
ADD_C_DOWNLOAD_VALUE_MEM_BI("min_peers", &core::Download::download, &torrent::Download::set_peers_min, &torrent::Download::peers_min);
ADD_C_DOWNLOAD_VALUE_MEM_BI("max_peers", &core::Download::download, &torrent::Download::set_peers_max, &torrent::Download::peers_max);
ADD_C_DOWNLOAD_VALUE_MEM_BI("max_uploads", &core::Download::download, &torrent::Download::set_uploads_max, &torrent::Download::uploads_max);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("up_rate", &torrent::Download::mutable_up_rate, &torrent::Rate::rate);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("up_total", &torrent::Download::mutable_up_rate, &torrent::Rate::total);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("down_rate", &torrent::Download::mutable_down_rate, &torrent::Rate::rate);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("down_total", &torrent::Download::mutable_down_rate, &torrent::Rate::total);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("skip_rate", &torrent::Download::mutable_skip_rate, &torrent::Rate::rate);
ADD_COMMAND_DOWNLOAD_VALUE_MEM_UNI("skip_total", &torrent::Download::mutable_skip_rate, &torrent::Rate::total);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("up_rate", &torrent::Download::mutable_up_rate, &torrent::Rate::rate);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("up_total", &torrent::Download::mutable_up_rate, &torrent::Rate::total);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("down_rate", &torrent::Download::mutable_down_rate, &torrent::Rate::rate);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("down_total", &torrent::Download::mutable_down_rate, &torrent::Rate::total);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("skip_rate", &torrent::Download::mutable_skip_rate, &torrent::Rate::rate);
ADD_C_DOWNLOAD_VALUE_MEM_UNI("skip_total", &torrent::Download::mutable_skip_rate, &torrent::Rate::total);
// rpc::commands.insert("split_file_size", new rpc::VariableValueSlot(rak::mem_fn(file_list(), &torrent::FileList::split_file_size),
// rak::mem_fn(file_list(), &torrent::FileList::set_split_file_size)));
// rpc::commands.insert("split_suffix", new rpc::VariableStringSlot(rak::mem_fn(file_list(), &torrent::FileList::split_suffix),
// rak::mem_fn(file_list(), &torrent::FileList::set_split_suffix)));
ADD_COMMAND_DOWNLOAD_VALUE_MEM_BI("tracker_numwant", &core::Download::tracker_list, &torrent::TrackerList::set_numwant, &torrent::TrackerList::numwant);
ADD_C_DOWNLOAD_VALUE_MEM_BI("tracker_numwant", &core::Download::tracker_list, &torrent::TrackerList::set_numwant, &torrent::TrackerList::numwant);
ADD_COMMAND_DOWNLOAD_STRING_BI("directory", std::mem_fun(&core::Download::set_root_directory), rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::root_dir)));
ADD_COMMAND_DOWNLOAD_VALUE_BI("priority", std::mem_fun(&core::Download::set_priority), std::mem_fun(&core::Download::priority));
ADD_COMMAND_DOWNLOAD_STRING_UNI("priority_str", std::ptr_fun(&retrieve_d_priority_str));
ADD_C_DOWNLOAD_STRING_BI("directory", std::mem_fun(&core::Download::set_root_directory), rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::root_dir)));
ADD_C_DOWNLOAD_VALUE_BI("priority", std::mem_fun(&core::Download::set_priority), std::mem_fun(&core::Download::priority));
ADD_C_DOWNLOAD_STRING_UNI("priority_str", std::ptr_fun(&retrieve_d_priority_str));
}
+22 -1
View File
@@ -97,6 +97,27 @@ apply_view_sort(const torrent::Object& rawArgs) {
return torrent::Object();
}
torrent::Object
apply_print(const torrent::Object& rawArgs) {
std::string output;
for (torrent::Object::list_type::const_iterator itr = rawArgs.as_list().begin(), last = rawArgs.as_list().end(); itr != last; itr++) {
switch (itr->type()) {
case torrent::Object::TYPE_STRING:
output += itr->as_string();
break;
case torrent::Object::TYPE_VALUE:
default:
output += "<unknown>";
}
}
control->core()->push_log(output);
return torrent::Object();
}
void
initialize_command_ui() {
ADD_VARIABLE_STRING("key_layout", "qwerty");
@@ -112,5 +133,5 @@ initialize_command_ui() {
// ADD_COMMAND_LIST("view_sort_current", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_sort_current));
ADD_COMMAND_STRING("print", rpc::object_string_fn(rak::make_mem_fun(control->core(), &core::Manager::push_log)));
ADD_COMMAND_LIST("print", rak::ptr_fn(&apply_print));
}
+1 -1
View File
@@ -164,7 +164,7 @@ DownloadList::insert(Download* download) {
}
void
DownloadList::erase(Download* download) {
DownloadList::erase_ptr(Download* download) {
erase(std::find(begin(), end(), download));
}
+1 -1
View File
@@ -86,7 +86,7 @@ public:
iterator insert(Download* d);
void erase(Download* d);
void erase_ptr(Download* d);
iterator erase(iterator itr);
//void save(Download* d);
+5 -1
View File
@@ -80,6 +80,8 @@ parse_command_single(const char* first) {
parse_command_single(first, first + std::strlen(first));
}
// Set 'download' to NULL to call the generic functions, thus reusing
// the code below for both cases.
torrent::Object
parse_command_d_single(core::Download* download, const char* first, const char* last) {
first = std::find_if(first, last, std::not1(command_map_is_space()));
@@ -97,8 +99,10 @@ parse_command_d_single(core::Download* download, const char* first, const char*
torrent::Object args;
parse_whole_list(first + 1, last, &args);
// Replace any strings starting with '$' with the result of the
// following command.
if (args.is_list()) {
for (torrent::Object::list_type::iterator itr = args.as_list().begin(), last = args.as_list().begin(); itr != last; itr++) {
for (torrent::Object::list_type::iterator itr = args.as_list().begin(), last = args.as_list().end(); itr != last; itr++) {
if (!itr->is_string())
continue;
+1 -1
View File
@@ -155,7 +155,7 @@ ElementDownloadList::receive_stop_download() {
if (rpc::call_command_d_value("get_d_state", *m_view->focus()) == 1)
control->core()->download_list()->stop_normal(*m_view->focus());
else
control->core()->download_list()->erase(*m_view->focus());
control->core()->download_list()->erase_ptr(*m_view->focus());
m_view->set_last_changed();
}