diff --git a/src/command_download.cc b/src/command_download.cc index 57b9e67d..4b5cd36c 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -99,21 +99,21 @@ apply_d_create_link(core::Download* download, const torrent::Object& rawArgs) { std::string link; if (type == "base_path") { - target = download->get_string("base_path"); - link = rak::path_expand(prefix + download->get_string("base_path") + postfix); + target = rpc::call_command_d_string("get_d_base_path", download); + link = rak::path_expand(prefix + rpc::call_command_d_string("get_d_base_path", download) + postfix); } else if (type == "base_filename") { - target = download->get_string("base_path"); - link = rak::path_expand(prefix + download->get_string("base_filename") + postfix); + target = rpc::call_command_d_string("get_d_base_path", download); + link = rak::path_expand(prefix + rpc::call_command_d_string("get_d_base_filename", download) + postfix); } else if (type == "tied") { - link = rak::path_expand(download->get_string("get_tied_to_file")); + link = rak::path_expand(rpc::call_command_d_string("get_d_tied_to_file", download)); if (link.empty()) return torrent::Object(); link = rak::path_expand(prefix + link + postfix); - target = download->get_string("base_path"); + target = rpc::call_command_d_string("get_d_base_path", download); } else { throw torrent::input_error("Unknown type argument."); @@ -146,13 +146,13 @@ apply_d_delete_link(core::Download* download, const torrent::Object& rawArgs) { std::string link; if (type == "base_path") { - link = rak::path_expand(prefix + download->get_string("base_path") + postfix); + link = rak::path_expand(prefix + rpc::call_command_d_string("get_d_base_path", download) + postfix); } else if (type == "base_filename") { - link = rak::path_expand(prefix + download->get_string("base_filename") + postfix); + link = rak::path_expand(prefix + rpc::call_command_d_string("get_d_base_filename", download) + postfix); } else if (type == "tied") { - link = rak::path_expand(download->get_string("get_tied_to_file")); + link = rak::path_expand(rpc::call_command_d_string("get_d_tied_to_file", download)); if (link.empty()) return torrent::Object(); @@ -175,57 +175,57 @@ apply_d_delete_link(core::Download* download, const torrent::Object& rawArgs) { #define ADD_COMMAND_DOWNLOAD_SLOT(key, function, slot, parm, doc) \ commandDownloadSlotsItr->set_slot(slot); \ - variables->insert(key, commandDownloadSlotsItr++, NULL, &utils::CommandDownloadSlot::function, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc); + rpc::commands.insert(key, commandDownloadSlotsItr++, NULL, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc); + +// 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(key, call_unknown, utils::object_d_fn(slot), "i:", "") + ADD_COMMAND_DOWNLOAD_SLOT("get_d_" key, call_unknown, rpc::object_d_fn(slot), "i:", "") #define ADD_COMMAND_DOWNLOAD_LIST(key, slot) \ ADD_COMMAND_DOWNLOAD_SLOT(key, call_list, slot, "i:", "") #define ADD_COMMAND_DOWNLOAD_VARIABLE_VALUE(key, firstKey, secondKey) \ - ADD_COMMAND_DOWNLOAD_SLOT("get_" key, call_unknown, utils::get_variable_d_fn(firstKey, secondKey), "i:", ""); \ - ADD_COMMAND_DOWNLOAD_SLOT("set_" key, call_value, utils::set_variable_d_fn(firstKey, secondKey), "i:i", ""); + ADD_COMMAND_DOWNLOAD_SLOT("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_COMMAND_DOWNLOAD_VARIABLE_STRING(key, firstKey, secondKey) \ - ADD_COMMAND_DOWNLOAD_SLOT("get_" key, call_unknown, utils::get_variable_d_fn(firstKey, secondKey), "i:", ""); \ - ADD_COMMAND_DOWNLOAD_SLOT("set_" key, call_string, utils::set_variable_d_fn(firstKey, secondKey), "i:s", ""); + ADD_COMMAND_DOWNLOAD_SLOT("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_COMMAND_DOWNLOAD_VALUE_BI(key, set, get) \ - ADD_COMMAND_DOWNLOAD_SLOT("set_" key, call_value, utils::object_value_d_fn(set), "i:i", "") \ - ADD_COMMAND_DOWNLOAD_SLOT("get_" key, call_unknown, utils::object_void_d_fn(get), "i:", "") + ADD_COMMAND_DOWNLOAD_SLOT("set_d_" key, call_value, rpc::object_value_d_fn(set), "i:i", "") \ + ADD_COMMAND_DOWNLOAD_SLOT("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "") #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_COMMAND_DOWNLOAD_VALUE_MEM_UNI(key, target, get) \ - ADD_COMMAND_DOWNLOAD_SLOT("get_" key, call_unknown, utils::object_void_d_fn(rak::on(rak::on(std::mem_fun(&core::Download::download), std::mem_fun(target)), std::mem_fun(get))), "i:", ""); + ADD_COMMAND_DOWNLOAD_SLOT("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("set_" key, call_string, utils::object_string_d_fn(set), "i:s", "") \ - ADD_COMMAND_DOWNLOAD_SLOT("get_" key, call_unknown, utils::object_void_d_fn(get), "s:", "") + ADD_COMMAND_DOWNLOAD_SLOT("set_d_" key, call_string, rpc::object_string_d_fn(set), "i:s", "") \ + ADD_COMMAND_DOWNLOAD_SLOT("get_d_" key, call_unknown, rpc::object_void_d_fn(get), "s:", "") void -add_copy_to_download(const char* key) { - utils::CommandMap::iterator itr = control->variable()->find(key); +add_copy_to_download(const char* src, const char* dest) { + rpc::CommandMap::iterator itr = rpc::commands.find(src); - if (itr == control->variable()->end()) + if (itr == rpc::commands.end()) throw torrent::internal_error("add_copy_to_download(...) key not found."); - control->download_variables()->insert(key, itr->second); + rpc::commands.insert(dest, itr->second); } void initialize_command_download() { - utils::CommandMap* variables = control->download_variables(); - ADD_COMMAND_DOWNLOAD_VOID("base_path", &retrieve_d_base_path); ADD_COMMAND_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_copy_to_download("print"); +// add_copy_to_download("print"); // 0 - stopped // 1 - started @@ -246,10 +246,10 @@ initialize_command_download() { ADD_COMMAND_DOWNLOAD_STRING_BI("connection_current", std::mem_fun(&core::Download::set_connection_current), std::mem_fun(&core::Download::connection_current)); - add_copy_to_download("get_connection_leech"); - add_copy_to_download("set_connection_leech"); - add_copy_to_download("get_connection_seed"); - add_copy_to_download("set_connection_seed"); + 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); @@ -264,9 +264,9 @@ initialize_command_download() { 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); - // variables->insert("split_file_size", new utils::VariableValueSlot(rak::mem_fn(file_list(), &torrent::FileList::split_file_size), + // 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))); - // variables->insert("split_suffix", new utils::VariableStringSlot(rak::mem_fn(file_list(), &torrent::FileList::split_suffix), + // 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); diff --git a/src/command_events.cc b/src/command_events.cc index a67311c8..5d776f1d 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -70,8 +70,7 @@ apply_on_state_change(core::DownloadList::slot_map* slotMap, const torrent::Obje if (args.back().as_string().empty()) slotMap->erase(key); else - (*slotMap)[key] = sigc::bind(sigc::bind<0>(&utils::parse_command_d_single_std, control->download_variables()), - utils::convert_list_to_command(++args.begin(), args.end())); + (*slotMap)[key] = sigc::bind(sigc::ptr_fun(&rpc::parse_command_d_single_std), rpc::convert_list_to_command(++args.begin(), args.end())); return torrent::Object(); } @@ -88,9 +87,9 @@ apply_stop_on_ratio(const torrent::Object& rawArgs) { // first argument: minimum ratio to reach // second argument: minimum upload amount to reach [optional] // third argument: maximum ratio to reach [optional] - int64_t minRatio = utils::convert_to_value(*argItr++); - int64_t minUpload = argItr != args.end() ? utils::convert_to_value(*argItr++) : 0; - int64_t maxRatio = argItr != args.end() ? utils::convert_to_value(*argItr++) : 0; + int64_t minRatio = rpc::convert_to_value(*argItr++); + int64_t minUpload = argItr != args.end() ? rpc::convert_to_value(*argItr++) : 0; + int64_t maxRatio = argItr != args.end() ? rpc::convert_to_value(*argItr++) : 0; core::DownloadList* downloadList = control->core()->download_list(); core::Manager::DListItr itr = downloadList->begin(); @@ -103,7 +102,7 @@ apply_stop_on_ratio(const torrent::Object& rawArgs) { if ((totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) || (maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio)) { downloadList->stop_try(*itr); - (*itr)->set("set_ignore_commands", (int64_t)1); + rpc::call_command_d("set_d_ignore_commands", *itr, (int64_t)1); } ++itr; @@ -115,11 +114,11 @@ apply_stop_on_ratio(const torrent::Object& rawArgs) { torrent::Object apply_start_tied() { for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) { - if ((*itr)->get_value("get_state") == 1) + if (rpc::call_command_d_value("get_d_state", *itr) == 1) continue; rak::file_stat fs; - const std::string& tiedToFile = (*itr)->get_string("get_tied_to_file"); + const std::string& tiedToFile = rpc::call_command_d_string("get_d_tied_to_file", *itr); if (!tiedToFile.empty() && fs.update(rak::path_expand(tiedToFile))) control->core()->download_list()->start_try(*itr); @@ -131,11 +130,11 @@ apply_start_tied() { torrent::Object apply_stop_untied() { for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) { - if ((*itr)->get_value("get_state") == 0) + if (rpc::call_command_d_value("get_d_state", *itr) == 0) continue; rak::file_stat fs; - const std::string& tiedToFile = (*itr)->get_string("get_tied_to_file"); + const std::string& tiedToFile = rpc::call_command_d_string("get_d_tied_to_file", *itr); if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile))) control->core()->download_list()->stop_try(*itr); @@ -148,7 +147,7 @@ torrent::Object apply_close_untied() { for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ++itr) { rak::file_stat fs; - const std::string& tiedToFile = (*itr)->get_string("get_tied_to_file"); + const std::string& tiedToFile = rpc::call_command_d_string("get_d_tied_to_file", *itr); if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)) && control->core()->download_list()->stop_try(*itr)) control->core()->download_list()->close(*itr); @@ -161,7 +160,7 @@ torrent::Object apply_remove_untied() { for (core::DownloadList::iterator itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ) { rak::file_stat fs; - const std::string& tiedToFile = (*itr)->get_string("get_tied_to_file"); + const std::string& tiedToFile = rpc::call_command_d_string("get_d_tied_to_file", *itr); if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)) && control->core()->download_list()->stop_try(*itr)) itr = control->core()->download_list()->erase(itr); @@ -185,7 +184,7 @@ apply_schedule(const torrent::Object& rawArgs) { const std::string& arg2 = (itr++)->as_string(); const std::string& arg3 = (itr++)->as_string(); - control->command_scheduler()->parse(arg1, arg2, arg3, utils::convert_list_to_command(itr, args.end())); + control->command_scheduler()->parse(arg1, arg2, arg3, rpc::convert_list_to_command(itr, args.end())); return torrent::Object(); } @@ -195,8 +194,8 @@ void apply_load_verbose(const std::string& arg) { control->core()->try_cre void apply_load_start(const std::string& arg) { control->core()->try_create_download_expand(arg, true, false, true); } void apply_load_start_verbose(const std::string& arg) { control->core()->try_create_download_expand(arg, true, true, true); } -void apply_import(const std::string& path) { if (!utils::parse_command_file(control->variable(), path)) throw torrent::input_error("Could not open option file: " + path); } -void apply_try_import(const std::string& path) { if (!utils::parse_command_file(control->variable(), path)) control->core()->push_log("Could not read resource file: " + path); } +void apply_import(const std::string& path) { if (!rpc::parse_command_file(path)) throw torrent::input_error("Could not open option file: " + path); } +void apply_try_import(const std::string& path) { if (!rpc::parse_command_file(path)) control->core()->push_log("Could not read resource file: " + path); } void apply_close_low_diskspace(int64_t arg) { @@ -216,7 +215,6 @@ apply_close_low_diskspace(int64_t arg) { void initialize_command_events() { - utils::CommandMap* variables = control->variable(); core::DownloadList* downloadList = control->core()->download_list(); ADD_VARIABLE_BOOL("check_hash", true); @@ -237,10 +235,10 @@ initialize_command_events() { ADD_COMMAND_SLOT_PRIVATE("stop_on_ratio", call_list, rak::ptr_fn(&apply_stop_on_ratio)); - ADD_COMMAND_SLOT_PRIVATE("start_tied", call_string, utils::object_fn(&apply_start_tied)); - ADD_COMMAND_SLOT_PRIVATE("stop_untied", call_string, utils::object_fn(&apply_stop_untied)); - ADD_COMMAND_SLOT_PRIVATE("close_untied", call_string, utils::object_fn(&apply_close_untied)); - ADD_COMMAND_SLOT_PRIVATE("remove_untied", call_string, utils::object_fn(&apply_remove_untied)); + ADD_COMMAND_SLOT_PRIVATE("start_tied", call_string, rpc::object_fn(&apply_start_tied)); + ADD_COMMAND_SLOT_PRIVATE("stop_untied", call_string, rpc::object_fn(&apply_stop_untied)); + ADD_COMMAND_SLOT_PRIVATE("close_untied", call_string, rpc::object_fn(&apply_close_untied)); + ADD_COMMAND_SLOT_PRIVATE("remove_untied", call_string, rpc::object_fn(&apply_remove_untied)); ADD_COMMAND_LIST("schedule", rak::ptr_fn(&apply_schedule)); ADD_COMMAND_STRING_UN("schedule_remove", rak::make_mem_fun(control->command_scheduler(), &CommandScheduler::erase_str)); diff --git a/src/command_helpers.cc b/src/command_helpers.cc index b596d843..372b6386 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -46,12 +46,12 @@ #include "control.h" #include "command_helpers.h" -utils::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; -utils::CommandSlot* commandSlotsItr = commandSlots; -utils::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; -utils::CommandVariable* commandVariablesItr = commandVariables; -utils::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; -utils::CommandDownloadSlot* commandDownloadSlotsItr = commandDownloadSlots; +rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; +rpc::CommandSlot* commandSlotsItr = commandSlots; +rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; +rpc::CommandVariable* commandVariablesItr = commandVariables; +rpc::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; +rpc::CommandDownloadSlot* commandDownloadSlotsItr = commandDownloadSlots; void initialize_command_download(); void initialize_command_events(); @@ -79,14 +79,14 @@ initialize_commands() { void add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - utils::CommandMap::generic_slot getSlot, utils::CommandMap::generic_slot setSlot, + rpc::CommandMap::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot, const torrent::Object& defaultObject) { - utils::CommandVariable* variable = commandVariablesItr++; + rpc::CommandVariable* variable = commandVariablesItr++; variable->set_variable(defaultObject); - control->variable()->insert(getKey, variable, getSlot, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, "i:", ""); - control->variable()->insert(setKey, variable, setSlot, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, "i:", ""); + rpc::commands.insert(getKey, variable, getSlot, NULL, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); + rpc::commands.insert(setKey, variable, setSlot, NULL, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); if (defaultSetKey) - control->variable()->insert(defaultSetKey, variable, setSlot, NULL, utils::CommandMap::flag_dont_delete, "i:", ""); + rpc::commands.insert(defaultSetKey, variable, setSlot, NULL, rpc::CommandMap::flag_dont_delete, "i:", ""); } diff --git a/src/command_helpers.h b/src/command_helpers.h index 262645f3..df214104 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -37,9 +37,9 @@ #ifndef RTORRENT_UTILS_COMMAND_HELPERS_H #define RTORRENT_UTILS_COMMAND_HELPERS_H -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" -namespace utils { +namespace rpc { class CommandSlot; class CommandVariable; class CommandDownloadSlot; @@ -53,77 +53,77 @@ namespace utils { #define ADDING_COMMANDS -extern utils::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; -extern utils::CommandSlot* commandSlotsItr; -extern utils::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; -extern utils::CommandVariable* commandVariablesItr; -extern utils::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; -extern utils::CommandDownloadSlot* commandDownloadSlotsItr; +extern rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; +extern rpc::CommandSlot* commandSlotsItr; +extern rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; +extern rpc::CommandVariable* commandVariablesItr; +extern rpc::CommandDownloadSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; +extern rpc::CommandDownloadSlot* commandDownloadSlotsItr; void initialize_commands(); void add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - utils::CommandMap::generic_slot getSlot, utils::CommandMap::generic_slot setSlot, + rpc::CommandMap::generic_slot getSlot, rpc::CommandMap::generic_slot setSlot, const torrent::Object& defaultObject); #define ADD_VARIABLE_BOOL(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &utils::CommandVariable::get_bool, &utils::CommandVariable::set_bool, (int64_t)defaultValue); +add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_bool, &rpc::CommandVariable::set_bool, (int64_t)defaultValue); #define ADD_VARIABLE_VALUE(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &utils::CommandVariable::get_value, &utils::CommandVariable::set_value, (int64_t)defaultValue); +add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_value, &rpc::CommandVariable::set_value, (int64_t)defaultValue); #define ADD_VARIABLE_STRING(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &utils::CommandVariable::get_string, &utils::CommandVariable::set_string, std::string(defaultValue)); +add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_string, &rpc::CommandVariable::set_string, std::string(defaultValue)); #define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \ commandSlotsItr->set_slot(slot); \ - variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc); + rpc::commands.insert(key, commandSlotsItr++, &rpc::CommandSlot::function, NULL, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); #define ADD_COMMAND_SLOT_PRIVATE(key, function, slot) \ commandSlotsItr->set_slot(slot); \ - variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete, NULL, NULL); + rpc::commands.insert(key, commandSlotsItr++, &rpc::CommandSlot::function, NULL, rpc::CommandMap::flag_dont_delete, NULL, NULL); #define ADD_COMMAND_COPY(key, function, parm, doc) \ - variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc); + rpc::commands.insert(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, NULL, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); #define ADD_COMMAND_COPY_PRIVATE(key, function) \ - variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete, NULL, NULL); + rpc::commands.insert(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, NULL, rpc::CommandMap::flag_dont_delete, NULL, NULL); #define ADD_COMMAND_VALUE_TRI(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value, utils::object_value_fn(set)) \ + ADD_COMMAND_SLOT_PRIVATE(key, call_value, rpc::object_value_fn(set)) \ ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "") + ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") #define ADD_COMMAND_VALUE_TRI_KB(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value_kb, utils::object_value_fn(set)) \ + ADD_COMMAND_SLOT_PRIVATE(key, call_value_kb, rpc::object_value_fn(set)) \ ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "") + ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") #define ADD_COMMAND_VALUE_TRI_OCT(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, utils::object_value_fn(set)) \ + ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, rpc::object_value_fn(set)) \ ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "") + ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") #define ADD_COMMAND_STRING_TRI(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_string, utils::object_string_fn(set)) \ + ADD_COMMAND_SLOT_PRIVATE(key, call_string, rpc::object_string_fn(set)) \ ADD_COMMAND_COPY("set_" key, call_string, "i:s", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "s:", "") + ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") #define ADD_COMMAND_VOID(key, slot) \ - ADD_COMMAND_SLOT(key, call_unknown, utils::object_void_fn(slot), "i:", "") + ADD_COMMAND_SLOT(key, call_unknown, rpc::object_void_fn(slot), "i:", "") #define ADD_COMMAND_VALUE(key, slot) \ ADD_COMMAND_SLOT(key, call_value, slot, "i:i", "") #define ADD_COMMAND_VALUE_UN(key, slot) \ - ADD_COMMAND_SLOT(key, call_value, utils::object_value_fn(slot), "i:i", "") + ADD_COMMAND_SLOT(key, call_value, rpc::object_value_fn(slot), "i:i", "") #define ADD_COMMAND_STRING(key, slot) \ ADD_COMMAND_SLOT(key, call_string, slot, "i:s", "") #define ADD_COMMAND_STRING_UN(key, slot) \ - ADD_COMMAND_SLOT(key, call_string, utils::object_string_fn(slot), "i:s", "") + ADD_COMMAND_SLOT(key, call_string, rpc::object_string_fn(slot), "i:s", "") #define ADD_COMMAND_LIST(key, slot) \ ADD_COMMAND_SLOT(key, call_list, slot, "i:", "") diff --git a/src/command_local.cc b/src/command_local.cc index 3a552f10..e1953db7 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -46,7 +46,7 @@ #include "core/manager.h" #include "rpc/command_slot.h" #include "rpc/command_variable.h" -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "globals.h" #include "control.h" @@ -56,7 +56,6 @@ typedef torrent::ChunkManager CM_t; void initialize_command_local() { - utils::CommandMap* variables = control->variable(); // core::DownloadList* downloadList = control->core()->download_list(); torrent::ChunkManager* chunkManager = torrent::chunk_manager(); core::DownloadList* dList = control->core()->download_list(); diff --git a/src/command_network.cc b/src/command_network.cc index b3c8ba4c..bf3f5175 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -54,7 +54,7 @@ #include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "rpc/parse.h" -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "globals.h" #include "control.h" @@ -94,7 +94,7 @@ apply_encryption(const torrent::Object& rawArgs) { torrent::Object apply_tos(const torrent::Object& rawArg) { - utils::Command::value_type value; + rpc::Command::value_type value; torrent::ConnectionManager* cm = torrent::connection_manager(); const std::string& arg = rawArg.as_string(); @@ -114,7 +114,7 @@ apply_tos(const torrent::Object& rawArg) { else if (arg == "mincost") value = torrent::ConnectionManager::iptos_mincost; - else if (!utils::parse_whole_value_nothrow(arg.c_str(), &value, 16, 1)) + else if (!rpc::parse_whole_value_nothrow(arg.c_str(), &value, 16, 1)) throw torrent::input_error("Invalid TOS identifier."); cm->set_priority(value); @@ -138,7 +138,7 @@ apply_enable_trackers(int64_t arg) { else tl.get(i).disable(); - if (arg && !control->variable()->call_command_value("get_use_udp_trackers")) + if (arg && !rpc::call_command_value("get_use_udp_trackers")) (*itr)->enable_udp_trackers(false); } } @@ -146,12 +146,12 @@ apply_enable_trackers(int64_t arg) { void initialize_xmlrpc() { control->set_xmlrpc(new rpc::XmlRpc); - control->xmlrpc()->set_slot_call_command(rak::mem_fn(control->variable(), &utils::CommandMap::call_command)); + control->xmlrpc()->set_slot_call_command(rak::ptr_fn(&rpc::call_command)); unsigned int count = 0; - for (utils::CommandMap::const_iterator itr = control->variable()->begin(), last = control->variable()->end(); itr != last; itr++) - if (itr->second.m_flags & utils::CommandMap::flag_public_xmlrpc) { + for (rpc::CommandMap::const_iterator itr = rpc::commands.begin(), last = rpc::commands.end(); itr != last; itr++) + if (itr->second.m_flags & rpc::CommandMap::flag_public_xmlrpc) { control->xmlrpc()->insert_command(itr->first, itr->second.m_parm, itr->second.m_doc); count++; @@ -215,7 +215,7 @@ apply_scgi(const std::string& arg, int type) { throw torrent::input_error("Invalid port number."); saPtr->set_port(port); - control->scgi()->open_port(saPtr, saPtr->length(), control->variable()->call_command_value("get_scgi_dont_route")); + control->scgi()->open_port(saPtr, saPtr->length(), rpc::call_command_value("get_scgi_dont_route")); break; @@ -238,7 +238,6 @@ apply_scgi(const std::string& arg, int type) { void initialize_command_network() { - utils::CommandMap* variables = control->variable(); // core::DownloadList* downloadList = control->core()->download_list(); torrent::ConnectionManager* cm = torrent::connection_manager(); core::CurlStack* httpStack = control->core()->get_poll_manager()->get_http_stack(); diff --git a/src/command_ui.cc b/src/command_ui.cc index ca603bc4..2a32aeca 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -90,7 +90,7 @@ apply_view_sort(const torrent::Object& rawArgs) { int32_t value = 0; if (args.size() == 2) - value = utils::convert_to_value(args.back()); + value = rpc::convert_to_value(args.back()); control->view_manager()->sort(name, value); @@ -99,12 +99,9 @@ apply_view_sort(const torrent::Object& rawArgs) { void initialize_command_ui() { - utils::CommandMap* variables = control->variable(); -// core::DownloadList* downloadList = control->core()->download_list(); - ADD_VARIABLE_STRING("key_layout", "qwerty"); - ADD_COMMAND_STRING("view_add", utils::object_string_fn(rak::make_mem_fun(control->view_manager(), &core::ViewManager::insert_throw))); + ADD_COMMAND_STRING("view_add", rpc::object_string_fn(rak::make_mem_fun(control->view_manager(), &core::ViewManager::insert_throw))); ADD_COMMAND_LIST("view_filter", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_filter)); ADD_COMMAND_LIST("view_filter_on", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_filter_on)); @@ -115,5 +112,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", utils::object_string_fn(rak::make_mem_fun(control->core(), &core::Manager::push_log))); + ADD_COMMAND_STRING("print", rpc::object_string_fn(rak::make_mem_fun(control->core(), &core::Manager::push_log))); } diff --git a/src/control.cc b/src/control.cc index dc0170cd..e000867b 100644 --- a/src/control.cc +++ b/src/control.cc @@ -55,7 +55,6 @@ #include "rpc/scgi.h" #include "rpc/xmlrpc.h" #include "ui/root.h" -#include "rpc/command_map.h" #include "command_scheduler.h" @@ -71,8 +70,6 @@ Control::Control() : m_inputStdin(new input::InputEvent(STDIN_FILENO)), m_commandScheduler(new CommandScheduler()), - m_variables(new utils::CommandMap()), - m_downloadVariables(new utils::CommandMap()), m_fastCgi(NULL), m_scgi(NULL), @@ -88,7 +85,7 @@ Control::Control() : m_taskShutdown.set_slot(rak::mem_fn(this, &Control::handle_shutdown)); - m_commandScheduler->set_slot_command(rak::bind_ptr_fn(&utils::parse_command_single_std, m_variables)); + m_commandScheduler->set_slot_command(rak::ptr_fn(&rpc::parse_command_single_std)); m_commandScheduler->set_slot_error_message(rak::mem_fn(m_core, &core::Manager::push_log)); } @@ -97,8 +94,6 @@ Control::~Control() { delete m_input; delete m_commandScheduler; - delete m_variables; - delete m_downloadVariables; delete m_viewManager; @@ -119,7 +114,7 @@ Control::initialize() { m_core->initialize_second(); m_core->listen_open(); - m_core->download_store()->enable(m_variables->call_command_value("get_session_lock")); + m_core->download_store()->enable(rpc::call_command_value("get_session_lock")); m_core->set_hashing_view(*m_viewManager->find_throw("hashing")); m_scheduler->set_view(*m_viewManager->find_throw("scheduler")); diff --git a/src/control.h b/src/control.h index 82f1ecea..f6f77ff0 100644 --- a/src/control.h +++ b/src/control.h @@ -68,10 +68,6 @@ namespace rpc { class XmlRpc; } -namespace utils { - class CommandMap; -} - class CommandScheduler; class Control { @@ -104,9 +100,6 @@ public: CommandScheduler* command_scheduler() { return m_commandScheduler; } - utils::CommandMap* variable() { return m_variables; } - utils::CommandMap* download_variables() { return m_downloadVariables; } - rpc::FastCgi* fast_cgi() { return m_fastCgi; } void set_fast_cgi(rpc::FastCgi* f) { m_fastCgi = f; } @@ -142,8 +135,6 @@ private: input::InputEvent* m_inputStdin; CommandScheduler* m_commandScheduler; - utils::CommandMap* m_variables; - utils::CommandMap* m_downloadVariables; rpc::FastCgi* m_fastCgi; rpc::SCgi* m_scgi; diff --git a/src/core/download.cc b/src/core/download.cc index 18e44cf0..25f46e00 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -48,7 +48,7 @@ #include #include -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "control.h" #include "download.h" @@ -205,15 +205,6 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) { m_chunksFailed++; } -int64_t Download::get_value(const char* key) { return control->download_variables()->call_command_d_value(key, this); } -const std::string Download::get_string(const char* key) { return control->download_variables()->call_command_d_string(key, this); } -int64_t Download::get_std_value(const std::string& key) { return control->download_variables()->call_command_d_value(key.c_str(), this); } -const std::string Download::get_std_string(const std::string& key) { return control->download_variables()->call_command_d_string(key.c_str(), this); } - -void Download::set(const char* key, const torrent::Object& value) { control->download_variables()->call_command_d(key, this, value); } -void Download::set_value(const char* key, int64_t value) { control->download_variables()->call_command_d_set_value(key, this, value); } -void Download::set_string(const char* key, const std::string& value) { control->download_variables()->call_command_d_set_string(key, this, value); } - // Clean up. void Download::set_root_directory(const std::string& path) { diff --git a/src/core/download.h b/src/core/download.h index 85d660cc..832e4671 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -100,17 +100,6 @@ public: uint32_t priority(); void set_priority(uint32_t p); - int64_t get_value(const char* key); - const std::string get_string(const char* key); - - int64_t get_std_value(const std::string& key); - const std::string get_std_string(const std::string& key); - - void set(const char* key, const torrent::Object& value); - - void set_value(const char* key, int64_t value); - void set_string(const char* key, const std::string& value); - void set_root_directory(const std::string& path); bool operator == (const std::string& str) const; diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 63139486..77615207 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -47,7 +47,7 @@ #include #include -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "curl_get.h" #include "control.h" @@ -75,9 +75,9 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) : m_taskLoad.set_slot(rak::mem_fn(this, &DownloadFactory::receive_load)); m_taskCommit.set_slot(rak::mem_fn(this, &DownloadFactory::receive_commit)); - m_variables["connection_leech"] = control->variable()->call_command_void("get_connection_leech"); - m_variables["connection_seed"] = control->variable()->call_command_void("get_connection_seed"); - m_variables["directory"] = control->variable()->call_command_void("get_directory"); + m_variables["connection_leech"] = rpc::call_command_void("get_connection_leech"); + m_variables["connection_seed"] = rpc::call_command_void("get_connection_seed"); + m_variables["directory"] = rpc::call_command_void("get_directory"); m_variables["tied_to_file"] = torrent::Object((int64_t)false); } @@ -173,44 +173,44 @@ DownloadFactory::receive_success() { initialize_rtorrent(download, rtorrent); // Move to 'rtorrent'. - download->set("set_connection_leech", m_variables["connection_leech"]); - download->set("set_connection_seed", m_variables["connection_seed"]); + rpc::call_command_d("set_d_connection_leech", download, m_variables["connection_leech"]); + rpc::call_command_d("set_d_connection_seed", download, m_variables["connection_seed"]); - download->set("set_max_uploads", control->variable()->call_command_void("get_max_uploads")); - download->set("set_min_peers", control->variable()->call_command_void("get_min_peers")); - download->set("set_max_peers", control->variable()->call_command_void("get_max_peers")); - download->set("set_tracker_numwant", control->variable()->call_command_void("get_tracker_numwant")); + rpc::call_command_d("set_d_max_uploads", download, rpc::call_command_void("get_max_uploads")); + rpc::call_command_d("set_d_min_peers", download, rpc::call_command_void("get_min_peers")); + rpc::call_command_d("set_d_max_peers", download, rpc::call_command_void("get_max_peers")); + rpc::call_command_d("set_d_tracker_numwant", download, rpc::call_command_void("get_tracker_numwant")); - if (download->get_value("get_complete") != 0) { - if (control->variable()->call_command_value("get_min_peers_seed") >= 0) - download->set("set_min_peers", control->variable()->call_command_void("get_min_peers_seed")); + if (rpc::call_command_d_value("get_d_complete", download) != 0) { + if (rpc::call_command_value("get_min_peers_seed") >= 0) + rpc::call_command_d("set_d_min_peers", download, rpc::call_command_void("get_min_peers_seed")); - if (control->variable()->call_command_value("get_max_peers_seed") >= 0) - download->set("set_max_peers", control->variable()->call_command_void("get_max_peers_seed")); + if (rpc::call_command_value("get_max_peers_seed") >= 0) + rpc::call_command_d("set_d_max_peers", download, rpc::call_command_void("get_max_peers_seed")); } - if (!control->variable()->call_command_value("get_use_udp_trackers")) + if (!rpc::call_command_value("get_use_udp_trackers")) download->enable_udp_trackers(false); - if (control->variable()->call_command_value("get_max_file_size") > 0) - download->set("set_max_file_size", control->variable()->call_command_void("get_max_file_size")); + if (rpc::call_command_value("get_max_file_size") > 0) + rpc::call_command_d("set_d_max_file_size", download, rpc::call_command_void("get_max_file_size")); // Check first if we already have these values set in the session // torrent, so that it is safe to change the values. // // Need to also catch the exceptions. - if (control->variable()->call_command_value("get_split_file_size") >= 0) + if (rpc::call_command_value("get_split_file_size") >= 0) torrent::file_split_all(download->download()->file_list(), - control->variable()->call_command_value("get_split_file_size"), - control->variable()->call_command_string("split_suffix")); + rpc::call_command_value("get_split_file_size"), + rpc::call_command_string("split_suffix")); if (!rtorrent->has_key_string("directory")) - download->set("set_directory", m_variables["directory"]); + rpc::call_command_d("set_d_directory", download, m_variables["directory"]); else - download->set("set_directory", rtorrent->get_key("directory")); + rpc::call_command_d("set_d_directory", download, rtorrent->get_key("directory")); if (!m_session && m_variables["tied_to_file"].as_value()) - download->set("set_tied_to_file", m_uri); + rpc::call_command_d("set_d_tied_to_file", download, m_uri); torrent::Object& resumeObject = root->has_key_map("libtorrent_resume") ? root->get_key("libtorrent_resume") @@ -235,8 +235,8 @@ DownloadFactory::receive_success() { if (m_session) { // This torrent was queued for hashing or hashing when the session // file was saved. Or it was in a started state. - if (download->get_value("get_hashing") != Download::variable_hashing_stopped || - download->get_value("get_state") != 0) + if (rpc::call_command_d_value("get_d_hashing", download) != Download::variable_hashing_stopped || + rpc::call_command_d_value("get_d_state", download) != 0) m_manager->download_list()->resume(download); } else { @@ -285,9 +285,9 @@ DownloadFactory::initialize_rtorrent(Download* download, torrent::Object* rtorre rtorrent->insert_key("tied_to_file", std::string()); if (rtorrent->has_key_value("priority")) - download->set("set_priority", rtorrent->get_key_value("priority") % 4); + rpc::call_command_d("set_d_priority", download, rtorrent->get_key_value("priority") % 4); else - download->set("set_priority", (int64_t)2); + rpc::call_command_d("set_d_priority", download, (int64_t)2); if (rtorrent->has_key_value("key")) { download->tracker_list()->set_key(rtorrent->get_key_value("key")); diff --git a/src/core/download_list.cc b/src/core/download_list.cc index fb40c366..e5a285ea 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -46,7 +46,7 @@ #include #include -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "control.h" #include "globals.h" @@ -242,7 +242,7 @@ DownloadList::close_throw(Download* download) { download->download()->close(); - if (!download->is_hash_failed() && download->get_value("get_hashing") != Download::variable_hashing_stopped) + if (!download->is_hash_failed() && rpc::call_command_d_value("get_d_hashing", download) != Download::variable_hashing_stopped) throw torrent::internal_error("DownloadList::close_throw(...) called but we're going into a hashing loop."); std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download)); @@ -256,7 +256,7 @@ DownloadList::start_normal(Download* download) { // Clear hash failed as we're doing a manual start and want to try // hashing again. download->set_hash_failed(false); - download->set("set_state", (int64_t)1); + rpc::call_command_d("set_d_state", download, (int64_t)1); resume(download); } @@ -268,12 +268,12 @@ DownloadList::start_try(Download* download) { // Also don't start if the state is one of those that indicate we // were manually stopped? - if (download->is_hash_failed() || download->get_value("get_ignore_commands") != 0) + if (download->is_hash_failed() || rpc::call_command_d_value("get_d_ignore_commands", download) != 0) return false; // Don't clear the hash failed as this function is used by scripts, // etc. - download->set("set_state", (int64_t)1); + rpc::call_command_d("set_d_state", download, (int64_t)1); resume(download); return true; @@ -283,7 +283,7 @@ void DownloadList::stop_normal(Download* download) { check_contains(download); - download->set("set_state", (int64_t)0); + rpc::call_command_d("set_d_state", download, (int64_t)0); pause(download); } @@ -292,10 +292,10 @@ bool DownloadList::stop_try(Download* download) { check_contains(download); - if (download->get_value("get_ignore_commands") != 0) + if (rpc::call_command_d_value("get_d_ignore_commands", download) != 0) return false; - download->set("set_state", (int64_t)0); + rpc::call_command_d("set_d_state", download, (int64_t)0); pause(download); return true; @@ -321,8 +321,8 @@ DownloadList::resume(Download* download) { if (download->is_hash_failed()) return; - if (download->get_value("get_hashing") == Download::variable_hashing_stopped) - download->set("set_hashing", Download::variable_hashing_initial); + if (rpc::call_command_d_value("get_d_hashing", download) == Download::variable_hashing_stopped) + rpc::call_command_d("set_d_hashing", download, Download::variable_hashing_initial); std::for_each(slot_map_hash_queued().begin(), slot_map_hash_queued().end(), download_list_call(download)); return; @@ -331,12 +331,12 @@ DownloadList::resume(Download* download) { // This will never actually do anything due to the above hash check. // open_throw(download); - download->set("set_state_changed", cachedTime.seconds()); + rpc::call_command_d("set_d_state_changed", download, cachedTime.seconds()); if (download->is_done()) { - download->set_connection_type(download->get_string("get_connection_seed")); + download->set_connection_type(rpc::call_command_d_string("get_d_connection_seed", download)); } else { - download->set_connection_type(download->get_string("get_connection_leech")); + download->set_connection_type(rpc::call_command_d_string("get_d_connection_leech", download)); // For the moment, clear the resume data so we force hash-check // on non-complete downloads after a crash. This shouldn't be @@ -365,9 +365,9 @@ DownloadList::pause(Download* download) { // Always clear hashing on pause. When a hashing request is added, // it should have cleared the hash resume data. - if (download->get_value("get_hashing") != Download::variable_hashing_stopped) { + if (rpc::call_command_d_value("get_d_hashing", download) != Download::variable_hashing_stopped) { download->download()->hash_stop(); - download->set_value("set_hashing", Download::variable_hashing_stopped); + rpc::call_command_d_set_value("set_d_hashing", download, Download::variable_hashing_stopped); std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download)); } @@ -380,7 +380,7 @@ DownloadList::pause(Download* download) { std::for_each(slot_map_stop().begin(), slot_map_stop().end(), download_list_call(download)); - download->set("set_state_changed", cachedTime.seconds()); + rpc::call_command_d("set_d_state_changed", download, cachedTime.seconds()); // Save the state after all the slots, etc have been called so we // include the modifications they may make. @@ -397,7 +397,7 @@ DownloadList::check_hash(Download* download) { try { - if (download->get_value("get_hashing") != Download::variable_hashing_stopped) + if (rpc::call_command_d_value("get_d_hashing", download) != Download::variable_hashing_stopped) return; hash_queue(download, Download::variable_hashing_rehash); @@ -430,8 +430,8 @@ DownloadList::hash_done(Download* download) { // confirm all the data, avoiding large BW usage on f.ex. the // ReiserFS bug with >4GB files. - int64_t hashing = download->get_value("get_hashing"); - download->set_value("set_hashing", Download::variable_hashing_stopped); + int64_t hashing = rpc::call_command_d_value("get_d_hashing", download); + rpc::call_command_d_set_value("set_d_hashing", download, Download::variable_hashing_stopped); switch (hashing) { case Download::variable_hashing_initial: @@ -440,17 +440,17 @@ DownloadList::hash_done(Download* download) { // If the download was previously completed but the files were // f.ex deleted, then we clear the state and complete. - if (download->get_value("get_complete") && !download->is_done()) { - download->set("set_state", (int64_t)0); + if (rpc::call_command_d_value("get_d_complete", download) && !download->is_done()) { + rpc::call_command_d("set_d_state", download, (int64_t)0); download->set_message("Download registered as completed, but hash check returned unfinished chunks."); } // Save resume data so we update time-stamps and priorities if // they were invalid/changed while loading/hashing. - download->set("set_complete", (int64_t)download->is_done()); + rpc::call_command_d("set_d_complete", download, (int64_t)download->is_done()); torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume")); - if (download->get_value("get_state") == 1) + if (rpc::call_command_d_value("get_d_state", download) == 1) resume(download); break; @@ -480,14 +480,14 @@ void DownloadList::hash_queue(Download* download, int type) { check_contains(download); - if (download->get_value("get_hashing") != Download::variable_hashing_stopped) + if (rpc::call_command_d_value("get_d_hashing", download) != Download::variable_hashing_stopped) throw torrent::internal_error("DownloadList::hash_queue(...) hashing already queued."); close_throw(download); torrent::resume_clear_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume")); download->set_hash_failed(false); - download->set_value("set_hashing", type); + rpc::call_command_d_set_value("set_d_hashing", download, type); if (download->is_open()) throw torrent::internal_error("DownloadList::hash_clear(...) download still open."); @@ -501,7 +501,7 @@ void DownloadList::received_finished(Download* download) { check_contains(download); - if (control->variable()->call_command_value("get_check_hash")) { + if (rpc::call_command_value("get_check_hash")) { // Set some 'checking_finished_thingie' variable to make hash_done // trigger correctly, also so it can bork on missing data. hash_queue(download, Download::variable_hashing_last); @@ -516,20 +516,20 @@ void DownloadList::confirm_finished(Download* download) { check_contains(download); - download->set("set_complete", (int64_t)1); + rpc::call_command_d("set_d_complete", download, (int64_t)1); - download->set_connection_type(download->get_string("get_connection_seed")); + download->set_connection_type(rpc::call_command_d_string("get_d_connection_seed", download)); download->set_priority(download->priority()); - if (download->get_value("get_min_peers") == control->variable()->call_command_value("get_min_peers") && control->variable()->call_command_value("get_min_peers_seed") >= 0) - download->set("set_min_peers", control->variable()->call_command_void("get_min_peers_seed")); + if (rpc::call_command_d_value("get_d_min_peers", download) == rpc::call_command_value("get_min_peers") && rpc::call_command_value("get_min_peers_seed") >= 0) + rpc::call_command_d("set_d_min_peers", download, rpc::call_command_void("get_min_peers_seed")); - if (download->get_value("get_max_peers") == control->variable()->call_command_value("get_max_peers") && control->variable()->call_command_value("get_max_peers_seed") >= 0) - download->set("set_max_peers", control->variable()->call_command_void("get_max_peers_seed")); + if (rpc::call_command_d_value("get_d_max_peers", download) == rpc::call_command_value("get_max_peers") && rpc::call_command_value("get_max_peers_seed") >= 0) + rpc::call_command_d("set_d_max_peers", download, rpc::call_command_void("get_max_peers_seed")); // Do this before the slots are called in case one of them closes // the download. - if (!download->is_active() && control->variable()->call_command_value("get_session_on_completion") != 0) { + if (!download->is_active() && rpc::call_command_value("get_session_on_completion") != 0) { torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume")); control->core()->download_store()->save(download); } @@ -540,7 +540,7 @@ DownloadList::confirm_finished(Download* download) { std::for_each(slot_map_finished().begin(), slot_map_finished().end(), download_list_call(download)); - if (!download->is_active() && download->get_value("get_state") == 1) + if (!download->is_active() && rpc::call_command_d_value("get_d_state", download) == 1) resume(download); } diff --git a/src/core/manager.cc b/src/core/manager.cc index 893edce5..667f898c 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -55,7 +55,7 @@ #include #include -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "globals.h" #include "curl_get.h" @@ -85,13 +85,13 @@ connect_signal_storage_log(Download* d, torrent::Download::slot_string_type s) { // Need a proper logging class for this. static void connect_signal_tracker_dump(Download* d, torrent::Download::slot_dump_type s) { - if (!control->variable()->call_command_string("get_tracker_dump").empty()) + if (!rpc::call_command_string("get_tracker_dump").empty()) d->download()->signal_tracker_dump(s); } static void receive_tracker_dump(const std::string& url, const char* data, size_t size) { - const std::string& filename = control->variable()->call_command_string("get_tracker_dump"); + const std::string& filename = rpc::call_command_string("get_tracker_dump"); if (filename.empty()) return; @@ -108,7 +108,7 @@ receive_tracker_dump(const std::string& url, const char* data, size_t size) { void Manager::handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash) { - if (!control->variable()->call_command_value("get_handshake_log")) + if (!rpc::call_command_value("get_handshake_log")) return; std::string peer; @@ -168,7 +168,7 @@ Manager::handshake_log(const sockaddr* sa, int msg, int err, const torrent::Hash // Hmm... find some better place for all this. void Manager::delete_tied(Download* download) { - const std::string& tie = download->get_string("get_tied_to_file"); + const std::string& tie = rpc::call_command_d_string("get_d_tied_to_file", download); // This should be configurable, need to wait for the variable // thingie to be implemented. @@ -178,7 +178,7 @@ Manager::delete_tied(Download* download) { if (::unlink(rak::path_expand(tie).c_str()) == -1) push_log("Could not unlink tied file: " + std::string(rak::error_number::current().c_str())); - download->set("set_tied_to_file", std::string()); + rpc::call_command_d("set_d_tied_to_file", download, std::string()); } Manager::Manager() : @@ -276,11 +276,11 @@ void Manager::listen_open() { // This stuff really should be moved outside of manager, make it // part of the init script. - if (!control->variable()->call_command_value("get_port_open")) + if (!rpc::call_command_value("get_port_open")) return; int portFirst, portLast; - torrent::Object portRange = control->variable()->call_command_void("get_port_range"); + torrent::Object portRange = rpc::call_command_void("get_port_range"); if (portRange.is_string()) { if (std::sscanf(portRange.as_string().c_str(), "%i-%i", &portFirst, &portLast) != 2) @@ -295,7 +295,7 @@ Manager::listen_open() { if (portFirst > portLast || portLast >= (1 << 16)) throw torrent::input_error("Invalid port range."); - if (control->variable()->call_command_value("get_port_random")) { + if (rpc::call_command_value("get_port_random")) { int boundary = portFirst + random() % (portLast - portFirst + 1); if (torrent::connection_manager()->listen_open(boundary, portLast) || @@ -473,6 +473,11 @@ path_expand(std::vector* paths, const std::string& pattern) { std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::get_path)); } +bool +manager_equal_tied(const std::string& path, Download* download) { + return path == rpc::call_command_d_string("get_d_tied_to_file", download); +} + void Manager::try_create_download_expand(const std::string& uri, bool start, bool printLog, bool tied) { std::vector paths; @@ -482,7 +487,7 @@ Manager::try_create_download_expand(const std::string& uri, bool start, bool pri if (tied) for (std::vector::iterator itr = paths.begin(); itr != paths.end(); ) - if (std::find_if(m_downloadList->begin(), m_downloadList->end(), rak::equal(*itr, rak::bind2nd(std::mem_fun(&Download::get_string), "get_tied_to_file"))) + if (std::find_if(m_downloadList->begin(), m_downloadList->end(), rak::bind1st(std::ptr_fun(&manager_equal_tied), *itr)) != m_downloadList->end()) itr = paths.erase(itr); else @@ -514,7 +519,7 @@ Manager::receive_hashing_changed() { continue; bool tryQuick = - (*itr)->get_value("get_hashing") == Download::variable_hashing_initial && + rpc::call_command_d_value("get_d_hashing", *itr) == Download::variable_hashing_initial && (*itr)->download()->file_list()->bitfield()->empty(); if (!tryQuick && foundHashing) @@ -537,7 +542,7 @@ Manager::receive_hashing_changed() { (*itr)->download()->hash_stop(); if (foundHashing) { - (*itr)->set_value("set_hashing", Download::variable_hashing_rehash); + rpc::call_command_d_set_value("set_d_hashing", *itr, Download::variable_hashing_rehash); continue; } } @@ -548,7 +553,7 @@ Manager::receive_hashing_changed() { } catch (torrent::local_error& e) { if (tryQuick) { // Make sure we don't repeat the quick hashing. - (*itr)->set_value("set_hashing", Download::variable_hashing_rehash); + rpc::call_command_d_set_value("set_d_hashing", *itr, Download::variable_hashing_rehash); } else { (*itr)->set_hash_failed(true); diff --git a/src/core/view_manager.cc b/src/core/view_manager.cc index 0012a31b..c680dfa1 100644 --- a/src/core/view_manager.cc +++ b/src/core/view_manager.cc @@ -42,6 +42,8 @@ #include #include "globals.h" +#include "control.h" +#include "rpc/parse_commands.h" #include "download.h" #include "download_list.h" @@ -71,8 +73,8 @@ public: virtual bool operator () (Download* d1, Download* d2) const { return - d1->get_string(m_name) == m_value && - d2->get_string(m_name) != m_value; + rpc::call_command_d_string(m_name, d1) == m_value && + rpc::call_command_d_string(m_name, d2) != m_value; } private: @@ -86,9 +88,9 @@ public: virtual bool operator () (Download* d1, Download* d2) const { if (m_reverse) - return d2->get_value(m_name) < d1->get_value(m_name); + return rpc::call_command_d_value(m_name, d2) < rpc::call_command_d_value(m_name, d1); else - return d1->get_value(m_name) < d2->get_value(m_name); + return rpc::call_command_d_value(m_name, d1) < rpc::call_command_d_value(m_name, d2); } private: @@ -115,7 +117,7 @@ public: m_name(name), m_value(v), m_inverse(inverse) {} virtual bool operator () (Download* d1) const { - return (d1->get_value(m_name) == m_value) != m_inverse; + return (rpc::call_command_d_value(m_name, d1) == m_value) != m_inverse; } private: @@ -134,19 +136,19 @@ ViewManager::ViewManager(DownloadList* dl) : m_sort["name"] = new ViewSortName(); m_sort["name_reverse"] = new ViewSortReverse(new ViewSortName()); - m_sort["stopped"] = new ViewSortVariableValue("get_state"); - m_sort["started"] = new ViewSortVariableValue("get_state", true); - m_sort["complete"] = new ViewSortVariableValue("get_complete"); - m_sort["incomplete"] = new ViewSortVariableValue("get_complete", true); + m_sort["stopped"] = new ViewSortVariableValue("get_d_state"); + m_sort["started"] = new ViewSortVariableValue("get_d_state", true); + m_sort["complete"] = new ViewSortVariableValue("get_d_complete"); + m_sort["incomplete"] = new ViewSortVariableValue("get_d_complete", true); - m_sort["state_changed"] = new ViewSortVariableValue("get_state_changed"); - m_sort["state_changed_reverse"] = new ViewSortVariableValue("get_state_changed", true); + m_sort["state_changed"] = new ViewSortVariableValue("get_d_state_changed"); + m_sort["state_changed_reverse"] = new ViewSortVariableValue("get_d_state_changed", true); - m_filter["started"] = new ViewFilterVariableValue("get_state", 1); - m_filter["stopped"] = new ViewFilterVariableValue("get_state", 0); - m_filter["complete"] = new ViewFilterVariableValue("get_complete", 0, true); - m_filter["incomplete"] = new ViewFilterVariableValue("get_complete", 0); - m_filter["hashing"] = new ViewFilterVariableValue("get_hashing", 0, true); + m_filter["started"] = new ViewFilterVariableValue("get_d_state", 1); + m_filter["stopped"] = new ViewFilterVariableValue("get_d_state", 0); + m_filter["complete"] = new ViewFilterVariableValue("get_d_complete", 0, true); + m_filter["incomplete"] = new ViewFilterVariableValue("get_d_complete", 0); + m_filter["hashing"] = new ViewFilterVariableValue("get_d_hashing", 0, true); } void diff --git a/src/display/text_element_helpers.h b/src/display/text_element_helpers.h index 56e8b419..16f6c16e 100644 --- a/src/display/text_element_helpers.h +++ b/src/display/text_element_helpers.h @@ -44,6 +44,7 @@ #include #include "core/download.h" +#include "rpc/parse_commands.h" #include "text_element_lambda.h" #include "text_element_string.h" @@ -92,8 +93,8 @@ te_string(Return (torrent::FileList::*fptr)() const, int flags = TextElementStri } inline TextElementStringBase* -te_variable_string(const std::string& variable, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) { - return text_element_string_slot(rak::bind2nd(std::mem_fun(&core::Download::get_std_string), variable), flags, attributes); +te_variable_string(const char* variable, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) { + return text_element_string_slot(rak::bind1st(std::ptr_fun(&rpc::call_command_d_string), variable), flags, attributes); } // Value stuff: @@ -117,8 +118,8 @@ te_value(Return (torrent::File::*fptr)() const, int flags = TextElementValueBase } inline TextElementValueBase* -te_variable_value(const std::string& variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) { - return text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::get_std_value), variable), flags, attributes); +te_variable_value(const char* variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) { + return text_element_value_slot(rak::bind1st(std::ptr_fun(&rpc::call_command_d_value), variable), flags, attributes); } template diff --git a/src/display/utils.cc b/src/display/utils.cc index aa39b524..2fa225c9 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -52,6 +52,7 @@ #include "core/download.h" #include "core/manager.h" +#include "rpc/parse_commands.h" #include "control.h" #include "globals.h" @@ -159,8 +160,8 @@ print_download_info(char* first, char* last, core::Download* d) { } first = print_buffer(first, last, " [%c%c R: %3.2f", - d->get_string("get_tied_to_file").empty() ? ' ' : 'T', - d->get_value("get_ignore_commands") == 0 ? ' ' : 'I', + rpc::call_command_d_string("get_d_tied_to_file", d).empty() ? ' ' : 'T', + rpc::call_command_d_value("get_d_ignore_commands", d) == 0 ? ' ' : 'I', d->download()->bytes_done() > 0 ? (double)(100 * d->download()->up_rate()->total() / d->download()->bytes_done()) / 100 : 0.0); if (d->priority() != 2) @@ -178,7 +179,7 @@ char* print_download_status(char* first, char* last, core::Download* d) { if (d->is_active()) ; - else if (d->get_value("get_hashing") != 0) + else if (rpc::call_command_d_value("get_d_hashing", d) != 0) first = print_buffer(first, last, "Hashing: "); else if (!d->is_active()) first = print_buffer(first, last, "Inactive: "); diff --git a/src/main.cc b/src/main.cc index d96a74f5..17097855 100644 --- a/src/main.cc +++ b/src/main.cc @@ -60,7 +60,6 @@ #include "rpc/parse_commands.h" #include "utils/directory.h" -#include "rpc/command_map.h" #include "control.h" #include "globals.h" @@ -82,14 +81,14 @@ parse_options(Control* c, int argc, char** argv) { optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); optionParser.insert_flag('n', OptionParser::Slot()); - optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "bind")); - optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "directory")); - optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "ip")); - optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "port_range")); - optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "session")); + optionParser.insert_option('b', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "bind")); + optionParser.insert_option('d', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "directory")); + optionParser.insert_option('i', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "ip")); + optionParser.insert_option('p', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "port_range")); + optionParser.insert_option('s', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "session")); - optionParser.insert_option('O', sigc::bind<0>(&utils::parse_command_single_std, c->variable())); - optionParser.insert_option_list('o', sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_std_string)); + optionParser.insert_option('O', sigc::ptr_fun(&rpc::parse_command_single_std)); + optionParser.insert_option_list('o', sigc::ptr_fun(&rpc::call_command_set_std_string)); return optionParser.process(argc, argv); @@ -166,7 +165,7 @@ main(int argc, char** argv) { // torrent::ConnectionManager* are valid etc. initialize_commands(); - utils::parse_command_multiple(control->variable(), + rpc::parse_command_multiple( // Currently not doing any sorting on main. "view_add = main\n" @@ -232,7 +231,7 @@ main(int argc, char** argv) { if (OptionParser::has_flag('n', argc, argv)) control->core()->push_log("Ignoring ~/.rtorrent.rc."); else - utils::parse_command_single(control->variable(), "try_import = ~/.rtorrent.rc"); + rpc::parse_command_single("try_import = ~/.rtorrent.rc"); int firstArg = parse_options(control, argc, argv); diff --git a/src/rpc/command.h b/src/rpc/command.h index 387b30de..6a388b57 100644 --- a/src/rpc/command.h +++ b/src/rpc/command.h @@ -34,12 +34,12 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_VARIABLE_H -#define RTORRENT_UTILS_VARIABLE_H +#ifndef RTORRENT_RPC_VARIABLE_H +#define RTORRENT_RPC_VARIABLE_H #include -namespace utils { +namespace rpc { class Command { public: diff --git a/src/rpc/command_download_slot.cc b/src/rpc/command_download_slot.cc index 2d4e0c18..b796e19a 100644 --- a/src/rpc/command_download_slot.cc +++ b/src/rpc/command_download_slot.cc @@ -37,11 +37,11 @@ #include "config.h" #include "core/download.h" -#include "rpc/parse.h" +#include "parse.h" #include "command_download_slot.h" -namespace utils { +namespace rpc { const torrent::Object CommandDownloadSlot::call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) { @@ -86,7 +86,7 @@ CommandDownloadSlot::call_value_base(Command* rawCommand, core::Download* downlo { torrent::Object argValue(torrent::Object::TYPE_VALUE); - if (!utils::parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) + if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) throw torrent::input_error("Not a value."); return command->m_slot(download, argValue); diff --git a/src/rpc/command_download_slot.h b/src/rpc/command_download_slot.h index 886c1d98..a3964efe 100644 --- a/src/rpc/command_download_slot.h +++ b/src/rpc/command_download_slot.h @@ -34,8 +34,8 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_COMMAND_DOWNLOAD_SLOT_H -#define RTORRENT_UTILS_COMMAND_DOWNLOAD_SLOT_H +#ifndef RTORRENT_RPC_COMMAND_DOWNLOAD_SLOT_H +#define RTORRENT_RPC_COMMAND_DOWNLOAD_SLOT_H #include #include @@ -43,13 +43,13 @@ #include #include -#include "rpc/command.h" +#include "command.h" namespace core { class Download; } -namespace utils { +namespace rpc { class CommandDownloadSlot : public Command { public: diff --git a/src/rpc/command_map.cc b/src/rpc/command_map.cc index d70b3f8b..93d70073 100644 --- a/src/rpc/command_map.cc +++ b/src/rpc/command_map.cc @@ -48,7 +48,7 @@ #include "command.h" #include "command_map.h" -namespace utils { +namespace rpc { struct command_map_get_ptr : std::unary_function { Command* operator () (CommandMap::value_type& value) { return value.second.m_variable; } diff --git a/src/rpc/command_map.h b/src/rpc/command_map.h index 27a9f62e..6bb68e68 100644 --- a/src/rpc/command_map.h +++ b/src/rpc/command_map.h @@ -34,8 +34,8 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_COMMAND_MAP_H -#define RTORRENT_UTILS_COMMAND_MAP_H +#ifndef RTORRENT_RPC_COMMAND_MAP_H +#define RTORRENT_RPC_COMMAND_MAP_H #include #include @@ -46,7 +46,7 @@ namespace core { class Download; } -namespace utils { +namespace rpc { class Command; @@ -93,10 +93,6 @@ public: using base_type::end; using base_type::find; - static const int max_size_key = 128; - static const int max_size_opt = 1024; - static const int max_size_line = max_size_key + max_size_opt + 64; - static const int flag_dont_delete = 0x1; static const int flag_public_xmlrpc = 0x2; @@ -112,21 +108,21 @@ public: void insert(key_type key, const command_map_data_type src); const mapped_type call_command(key_type key, const mapped_type& arg); - const mapped_type call_command_void(key_type key) { return call_command(key, torrent::Object()); } - const std::string call_command_string(key_type key) { return call_command(key, torrent::Object()).as_string(); } - mapped_value_type call_command_value(key_type key) { return call_command(key, torrent::Object()).as_value(); } +// const mapped_type call_command_void(key_type key) { return call_command(key, torrent::Object()); } +// const std::string call_command_string(key_type key) { return call_command(key, torrent::Object()).as_string(); } +// mapped_value_type call_command_value(key_type key) { return call_command(key, torrent::Object()).as_value(); } - void call_command_set_string(key_type key, const std::string& arg) { call_command(key, mapped_type(arg)); } - void call_command_set_std_string(const std::string& key, const std::string& arg) { call_command(key.c_str(), mapped_type(arg)); } +// void call_command_set_string(key_type key, const std::string& arg) { call_command(key, mapped_type(arg)); } +// void call_command_set_std_string(const std::string& key, const std::string& arg) { call_command(key.c_str(), mapped_type(arg)); } const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg); - const mapped_type call_command_d_void(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()); } - const std::string call_command_d_string(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_string(); } - mapped_value_type call_command_d_value(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_value(); } +// const mapped_type call_command_d_void(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()); } +// const std::string call_command_d_string(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_string(); } +// mapped_value_type call_command_d_value(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_value(); } - void call_command_d_set_value(key_type key, core::Download* download, mapped_value_type arg) { call_command_d(key, download, mapped_type(arg)); } - void call_command_d_set_string(key_type key, core::Download* download, const std::string& arg) { call_command_d(key, download, mapped_type(arg)); } - void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { call_command_d(key.c_str(), download, mapped_type(arg)); } +// void call_command_d_set_value(key_type key, core::Download* download, mapped_value_type arg) { call_command_d(key, download, mapped_type(arg)); } +// void call_command_d_set_string(key_type key, core::Download* download, const std::string& arg) { call_command_d(key, download, mapped_type(arg)); } +// void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { call_command_d(key.c_str(), download, mapped_type(arg)); } private: CommandMap(const CommandMap&); diff --git a/src/rpc/command_slot.cc b/src/rpc/command_slot.cc index 1d69b99d..5a2f855c 100644 --- a/src/rpc/command_slot.cc +++ b/src/rpc/command_slot.cc @@ -36,11 +36,11 @@ #include "config.h" -#include "rpc/parse.h" +#include "parse.h" #include "command_slot.h" -namespace utils { +namespace rpc { const torrent::Object CommandSlot::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) { @@ -85,7 +85,7 @@ CommandSlot::call_value_base(Command* rawCommand, const torrent::Object& rawArgs { torrent::Object argValue(torrent::Object::TYPE_VALUE); - if (!utils::parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) + if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) throw torrent::input_error("Not a value."); return command->m_slot(argValue); diff --git a/src/rpc/command_slot.h b/src/rpc/command_slot.h index 01d8b542..bae18079 100644 --- a/src/rpc/command_slot.h +++ b/src/rpc/command_slot.h @@ -34,8 +34,8 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_COMMAND_SLOT_H -#define RTORRENT_UTILS_COMMAND_SLOT_H +#ifndef RTORRENT_RPC_COMMAND_SLOT_H +#define RTORRENT_RPC_COMMAND_SLOT_H #include #include @@ -43,9 +43,9 @@ #include #include -#include "rpc/command.h" +#include "command.h" -namespace utils { +namespace rpc { class CommandSlot : public Command { public: diff --git a/src/rpc/command_variable.cc b/src/rpc/command_variable.cc index c8406fd2..998982e8 100644 --- a/src/rpc/command_variable.cc +++ b/src/rpc/command_variable.cc @@ -36,11 +36,10 @@ #include "config.h" -#include "rpc/parse.h" - +#include "parse.h" #include "command_variable.h" -namespace utils { +namespace rpc { const torrent::Object CommandVariable::set_bool(Command* rawCommand, const torrent::Object& rawArgs) { diff --git a/src/rpc/command_variable.h b/src/rpc/command_variable.h index 0fd7f411..2d70f3fb 100644 --- a/src/rpc/command_variable.h +++ b/src/rpc/command_variable.h @@ -34,17 +34,17 @@ // Skomakerveien 33 // 3185 Skoppum, NORWAY -#ifndef RTORRENT_UTILS_COMMAND_VARIABLES_H -#define RTORRENT_UTILS_COMMAND_VARIABLES_H +#ifndef RTORRENT_RPC_COMMAND_VARIABLES_H +#define RTORRENT_RPC_COMMAND_VARIABLES_H #include #include #include #include -#include "rpc/command.h" +#include "command.h" -namespace utils { +namespace rpc { class CommandVariable : public Command { public: diff --git a/src/rpc/parse.cc b/src/rpc/parse.cc index c4021129..29ea2182 100644 --- a/src/rpc/parse.cc +++ b/src/rpc/parse.cc @@ -41,7 +41,7 @@ #include "parse.h" -namespace utils { +namespace rpc { const char* parse_skip_wspace(const char* first, const char* last) { diff --git a/src/rpc/parse.h b/src/rpc/parse.h index 7315f6fe..496c3bd7 100644 --- a/src/rpc/parse.h +++ b/src/rpc/parse.h @@ -40,7 +40,7 @@ #include #include -namespace utils { +namespace rpc { // parse_* functions do the bare minimum necessary to parse what was // asked for. If a whitespace is found, it will be treated as empty diff --git a/src/rpc/parse_commands.cc b/src/rpc/parse_commands.cc index f28376be..b2c4c555 100644 --- a/src/rpc/parse_commands.cc +++ b/src/rpc/parse_commands.cc @@ -45,9 +45,10 @@ #include "parse.h" #include "parse_commands.h" -#include "command_map.h" -namespace utils { +namespace rpc { + +CommandMap commands; struct command_map_is_space : std::unary_function { bool operator () (char c) const { @@ -74,12 +75,12 @@ parse_command_name(const char* first, const char* last, std::string* dest) { } const char* -parse_command_single(CommandMap* varMap, const char* first) { - return parse_command_single(varMap, first, first + std::strlen(first)); +parse_command_single(const char* first) { + return parse_command_single(first, first + std::strlen(first)); } const char* -parse_command_single(CommandMap* varMap, const char* first, const char* last) { +parse_command_single(const char* first, const char* last) { first = std::find_if(first, last, std::not1(command_map_is_space())); if (first == last || *first == '#') @@ -96,13 +97,13 @@ parse_command_single(CommandMap* varMap, const char* first, const char* last) { torrent::Object args; parse_whole_list(first + 1, last, &args); - varMap->call_command(key.c_str(), args); + commands.call_command(key.c_str(), args); return last; } const char* -parse_command_d_single(CommandMap* varMap, core::Download* download, const char* first, const char* last) { +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())); if (first == last || *first == '#') @@ -118,13 +119,13 @@ parse_command_d_single(CommandMap* varMap, core::Download* download, const char* torrent::Object args; parse_whole_list(first + 1, last, &args); - varMap->call_command_d(key.c_str(), download, args); + commands.call_command_d(key.c_str(), download, args); return last; } void -parse_command_multiple(CommandMap* varMap, const char* first) { +parse_command_multiple(const char* first) { try { while (first != '\0') { const char* last = first; @@ -133,7 +134,7 @@ parse_command_multiple(CommandMap* varMap, const char* first) { // Should we check the return value? Probably not necessary as // parse_args throws on unquoted multi-word input. - parse_command_single(varMap, first, last); + parse_command_single(first, last); if (*last == '\0') return; @@ -147,7 +148,7 @@ parse_command_multiple(CommandMap* varMap, const char* first) { } bool -parse_command_file(CommandMap* varMap, const std::string& path) { +parse_command_file(const std::string& path) { std::fstream file(rak::path_expand(path).c_str(), std::ios::in); if (!file.is_open()) @@ -161,7 +162,7 @@ parse_command_file(CommandMap* varMap, const std::string& path) { while (file.getline(buffer, 2048).good()) { lineNumber++; // Would be nice to make this zero-copy. - parse_command_single(varMap, buffer, buffer + std::strlen(buffer)); + parse_command_single(buffer, buffer + std::strlen(buffer)); } } catch (torrent::input_error& e) { diff --git a/src/rpc/parse_commands.h b/src/rpc/parse_commands.h index 9a8f8ba4..e1a3dd2b 100644 --- a/src/rpc/parse_commands.h +++ b/src/rpc/parse_commands.h @@ -39,34 +39,56 @@ #include +#include "command_map.h" + namespace core { class Download; } -namespace utils { +namespace rpc { -class CommandMap; +// class CommandMap; const char* parse_command_name(const char* first, const char* last, std::string* dest); -const char* parse_command_single(CommandMap* varMap, const char* first); -const char* parse_command_single(CommandMap* varMap, const char* first, const char* last); +const char* parse_command_single(const char* first); +const char* parse_command_single(const char* first, const char* last); -const char* parse_command_d_single(CommandMap* varMap, core::Download* download, const char* first, const char* last); +const char* parse_command_d_single(core::Download* download, const char* first, const char* last); -void parse_command_multiple(CommandMap* varMap, const char* first); -bool parse_command_file(CommandMap* varMap, const std::string& path); +void parse_command_multiple(const char* first); +bool parse_command_file(const std::string& path); inline void -parse_command_single_std(CommandMap* varMap, const std::string& cmd) { - parse_command_single(varMap, cmd.c_str(), cmd.c_str() + cmd.size()); +parse_command_single_std(const std::string& cmd) { + parse_command_single(cmd.c_str(), cmd.c_str() + cmd.size()); } inline void -parse_command_d_single_std(CommandMap* varMap, core::Download* download, const std::string& cmd) { - parse_command_d_single(varMap, download, cmd.c_str(), cmd.c_str() + cmd.size()); +parse_command_d_single_std(core::Download* download, const std::string& cmd) { + parse_command_d_single(download, cmd.c_str(), cmd.c_str() + cmd.size()); } +// Move to anoher file? +extern CommandMap commands; + +inline torrent::Object call_command(const char* key, const torrent::Object& obj) { return commands.call_command(key, obj); } +inline torrent::Object call_command_void(const char* key) { return commands.call_command(key, torrent::Object()); } +inline std::string call_command_string(const char* key) { return commands.call_command(key, torrent::Object()).as_string(); } +inline int64_t call_command_value(const char* key) { return commands.call_command(key, torrent::Object()).as_value(); } + +inline void call_command_set_string(const char* key, const std::string& arg) { commands.call_command(key, torrent::Object(arg)); } +inline void call_command_set_std_string(const std::string& key, const std::string& arg) { commands.call_command(key.c_str(), torrent::Object(arg)); } + +inline torrent::Object call_command_d(const char* key, core::Download* download, const torrent::Object& obj) { return commands.call_command_d(key, download, obj); } +inline torrent::Object call_command_d_void(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()); } +inline std::string call_command_d_string(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()).as_string(); } +inline int64_t call_command_d_value(const char* key, core::Download* download) { return commands.call_command_d(key, download, torrent::Object()).as_value(); } + +inline void call_command_d_set_value(const char* key, core::Download* download, int64_t arg) { commands.call_command_d(key, download, torrent::Object(arg)); } +inline void call_command_d_set_string(const char* key, core::Download* download, const std::string& arg) { commands.call_command_d(key, download, torrent::Object(arg)); } +inline void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { commands.call_command_d(key.c_str(), download, torrent::Object(arg)); } + } #endif diff --git a/src/rpc/xmlrpc.h b/src/rpc/xmlrpc.h index d10f6e4d..2a2ba047 100644 --- a/src/rpc/xmlrpc.h +++ b/src/rpc/xmlrpc.h @@ -52,7 +52,7 @@ namespace rpc { class XmlRpc { public: typedef rak::function2 slot_write; - typedef rak::function2 slot_call_command; + typedef rak::function2 slot_call_command; XmlRpc(); ~XmlRpc(); diff --git a/src/ui/download.cc b/src/ui/download.cc index 7cc2be2a..6342085a 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -154,13 +154,13 @@ Download::create_info() { element->push_back(""); element->push_column("Directory:", te_string(&torrent::FileList::root_dir)); - element->push_column("Tied to file:", te_variable_string("get_tied_to_file")); + element->push_column("Tied to file:", te_variable_string("get_d_tied_to_file")); element->push_back(""); element->push_column("Chunks:", te_value(&torrent::FileList::completed_chunks), " / ", te_value(&torrent::FileList::size_chunks), " * ", te_value(&torrent::FileList::chunk_size)); - element->push_column("Priority:", te_variable_value("get_priority")); + element->push_column("Priority:", te_variable_value("get_d_priority")); - element->push_column("State changed:", te_variable_value("get_state_changed", value_base::flag_timer | value_base::flag_elapsed)); + element->push_column("State changed:", te_variable_value("get_d_state_changed", value_base::flag_timer | value_base::flag_elapsed)); element->push_back(""); element->push_column("Memory usage:", te_value(&torrent::ChunkManager::memory_usage, value_base::flag_mb), " MB"); @@ -174,9 +174,9 @@ Download::create_info() { element->push_column("Receive buffer:", te_value(&torrent::ConnectionManager::receive_buffer_size, value_base::flag_kb), " KB"); element->push_back(""); - element->push_column("Upload:", te_variable_value("get_up_rate", value_base::flag_kb), " KB / ", te_variable_value("get_up_total", value_base::flag_xb)); - element->push_column("Download:", te_variable_value("get_down_rate", value_base::flag_kb), " KB / ", te_variable_value("get_down_total", value_base::flag_xb)); - element->push_column("Skipped:", te_variable_value("get_skip_rate", value_base::flag_kb), " KB / ", te_variable_value("get_skip_total", value_base::flag_xb)); + element->push_column("Upload:", te_variable_value("get_d_up_rate", value_base::flag_kb), " KB / ", te_variable_value("get_d_up_total", value_base::flag_xb)); + element->push_column("Download:", te_variable_value("get_d_down_rate", value_base::flag_kb), " KB / ", te_variable_value("get_d_down_total", value_base::flag_xb)); + element->push_column("Skipped:", te_variable_value("get_d_skip_rate", value_base::flag_kb), " KB / ", te_variable_value("get_d_skip_total", value_base::flag_xb)); element->push_column("Preload:", te_value(&torrent::ChunkManager::preload_type), " / ", te_value(&torrent::ChunkManager::stats_preloaded), " / ", te_value(&torrent::ChunkManager::stats_not_preloaded)); element->set_column_width(element->column_width() + 1); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 8318621e..5a0ea75b 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -56,7 +56,6 @@ #include "display/window_log.h" #include "display/window_title.h" -#include "rpc/command_map.h" #include "rpc/parse_commands.h" #include "control.h" @@ -233,7 +232,7 @@ DownloadList::receive_view_input(Input type) { case INPUT_CHANGE_DIRECTORY: title = "change_directory"; - input->str() = control->variable()->call_command_string("get_directory"); + input->str() = rpc::call_command_string("get_directory"); input->set_pos(input->str().length()); break; @@ -286,12 +285,12 @@ DownloadList::receive_exit_input(Input type) { if (current_view()->focus() == current_view()->end_visible()) throw torrent::input_error("No download in focus to change root directory."); - control->download_variables()->call_command_d("set_directory", *current_view()->focus(), rak::trim(input->str())); - control->core()->push_log("New root directory \"" + (*current_view()->focus())->get_string("get_directory") + "\" for torrent."); + rpc::call_command_d("set_d_directory", *current_view()->focus(), rak::trim(input->str())); + control->core()->push_log("New root directory \"" + rpc::call_command_d_string("get_d_directory", *current_view()->focus()) + "\" for torrent."); break; case INPUT_COMMAND: - utils::parse_command_single_std(control->variable(), input->str()); + rpc::parse_command_single_std(input->str()); break; default: diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 69da5921..17eddaf4 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -47,6 +47,7 @@ #include "display/frame.h" #include "display/manager.h" #include "input/manager.h" +#include "rpc/parse_commands.h" #include "control.h" #include "element_download_list.h" @@ -151,7 +152,7 @@ ElementDownloadList::receive_stop_download() { if (m_view->focus() == m_view->end_visible()) return; - if ((*m_view->focus())->get_value("get_state") == 1) + 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()); @@ -166,7 +167,7 @@ ElementDownloadList::receive_close_download() { core::Download* download = *m_view->focus(); - download->set("set_ignore_commands", (int64_t)1); + rpc::call_command_d("set_d_ignore_commands", download, (int64_t)1); control->core()->download_list()->stop_normal(download); control->core()->download_list()->close(download); @@ -205,11 +206,11 @@ ElementDownloadList::receive_ignore_ratio() { if (m_view->focus() == m_view->end_visible()) return; - if ((*m_view->focus())->get_value("get_ignore_commands") != 0) { - (*m_view->focus())->set("set_ignore_commands", (int64_t)0); + if (rpc::call_command_d_value("get_d_ignore_commands", *m_view->focus()) != 0) { + rpc::call_command_d_set_value("set_d_ignore_commands", *m_view->focus(), (int64_t)0); control->core()->push_log("Torrent set to heed commands."); } else { - (*m_view->focus())->set("set_ignore_commands", (int64_t)1); + rpc::call_command_d_set_value("set_d_ignore_commands", *m_view->focus(), (int64_t)1); control->core()->push_log("Torrent set to ignore commands."); } } @@ -219,7 +220,7 @@ ElementDownloadList::receive_clear_tied() { if (m_view->focus() == m_view->end_visible()) return; - const std::string& tiedFile = (*m_view->focus())->get_string("get_tied_to_file"); + const std::string& tiedFile = rpc::call_command_d_string("get_d_tied_to_file", *m_view->focus()); if (!tiedFile.empty()) { // Move this into core? diff --git a/src/ui/root.cc b/src/ui/root.cc index 2b3494cc..021705f6 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -49,7 +49,7 @@ #include "display/window_statusbar.h" #include "input/manager.h" #include "input/text_input.h" -#include "rpc/command_map.h" +#include "rpc/parse_commands.h" #include "control.h" #include "download_list.h" @@ -126,7 +126,7 @@ void Root::setup_keys() { m_control->input()->push_back(&m_bindings); - const std::string& keyLayout = control->variable()->call_command_string("get_key_layout"); + const std::string& keyLayout = rpc::call_command_string("get_key_layout"); if (strcasecmp(keyLayout.c_str(), "azerty") == 0) { m_bindings['q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1); @@ -187,14 +187,14 @@ Root::set_down_throttle(unsigned int throttle) { torrent::set_down_throttle(throttle * 1024); - int64_t div = control->variable()->call_command_value("get_max_downloads_div"); + int64_t div = rpc::call_command_value("get_max_downloads_div"); if (throttle == 0 || div <= 0) { torrent::set_max_download_unchoked(m_maxDownloadsGlobal); return; } - throttle /= control->variable()->call_command_value("get_max_downloads_div"); + throttle /= rpc::call_command_value("get_max_downloads_div"); unsigned int maxUnchoked; @@ -216,14 +216,14 @@ Root::set_up_throttle(unsigned int throttle) { torrent::set_up_throttle(throttle * 1024); - int64_t div = control->variable()->call_command_value("get_max_uploads_div"); + int64_t div = rpc::call_command_value("get_max_uploads_div"); if (throttle == 0 || div <= 0) { torrent::set_max_unchoked(m_maxUploadsGlobal); return; } - throttle /= control->variable()->call_command_value("get_max_uploads_div"); + throttle /= rpc::call_command_value("get_max_uploads_div"); unsigned int maxUnchoked;