diff --git a/scripts/checks.m4 b/scripts/checks.m4 index b920c052..4909a8cd 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -160,14 +160,10 @@ AC_DEFUN([TORRENT_WITHOUT_VARIABLE_FDSET], [ AC_DEFUN([TORRENT_CHECK_FALLOCATE], [ AC_MSG_CHECKING(for fallocate) - AC_COMPILE_IFELSE( - [[#include - #include - int main() { - fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 0); - return 0; - } - ]], + AC_TRY_LINK([#include + #include + ],[ fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 0); return 0; + ], [ AC_DEFINE(HAVE_FALLOCATE, 1, Linux's fallocate supported.) AC_MSG_RESULT(yes) diff --git a/src/Makefile.am b/src/Makefile.am index 230801b6..dfb0ed50 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,6 @@ libsub_root_a_SOURCES = \ command_helpers.h \ command_local.cc \ command_network.cc \ - command_object.cc \ command_peer.cc \ command_tracker.cc \ command_scheduler.cc \ diff --git a/src/command_dynamic.cc b/src/command_dynamic.cc index 973e2d2d..7e88dcf2 100644 --- a/src/command_dynamic.cc +++ b/src/command_dynamic.cc @@ -82,9 +82,7 @@ create_new_key(const std::string& key, const char postfix[postfix_size]) { // as a command, and which takes advantage of static const char // strings, etc. torrent::Object -system_method_insert(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - const torrent::Object::list_type& args = rawArgs.as_list(); - +system_method_insert(const torrent::Object::list_type& args) { if (args.empty() || ++args.begin() == args.end()) throw torrent::input_error("Invalid argument count."); @@ -178,8 +176,8 @@ system_method_insert(__UNUSED rpc::target_type target, const torrent::Object& ra // that aren't modifiable, e.g. defined by rtorrent or set to // read-only by the user, will result in an error. torrent::Object -system_method_erase(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - rpc::CommandMap::iterator itr = rpc::commands.find(rawArgs.as_string().c_str()); +system_method_erase(const torrent::Object::string_type& args) { + rpc::CommandMap::iterator itr = rpc::commands.find(args.c_str()); if (itr == rpc::commands.end()) return torrent::Object(); @@ -193,9 +191,9 @@ system_method_erase(__UNUSED rpc::target_type target, const torrent::Object& raw } torrent::Object -system_method_get(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { +system_method_get(const torrent::Object::string_type& args) { rpc::CommandFunction* function; - rpc::CommandMap::iterator itr = rpc::commands.find(rawArgs.as_string().c_str()); + rpc::CommandMap::iterator itr = rpc::commands.find(args.c_str()); if (itr == rpc::commands.end() || (function = dynamic_cast(itr->second.m_variable)) == NULL) @@ -205,9 +203,7 @@ system_method_get(__UNUSED rpc::target_type target, const torrent::Object& rawAr } torrent::Object -system_method_set(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - const torrent::Object::list_type& args = rawArgs.as_list(); - +system_method_set(const torrent::Object::list_type& args) { if (args.empty()) throw torrent::input_error("Invalid argument count."); @@ -223,9 +219,7 @@ system_method_set(__UNUSED rpc::target_type target, const torrent::Object& rawAr } torrent::Object -system_method_set_key(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - const torrent::Object::list_type& args = rawArgs.as_list(); - +system_method_set_key(const torrent::Object::list_type& args) { if (args.empty() || ++args.begin() == args.end()) throw torrent::input_error("Invalid argument count."); @@ -248,9 +242,7 @@ system_method_set_key(__UNUSED rpc::target_type target, const torrent::Object& r } torrent::Object -system_method_has_key(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - const torrent::Object::list_type& args = rawArgs.as_list(); - +system_method_has_key(const torrent::Object::list_type& args) { if (args.size() != 2) throw torrent::input_error("Invalid argument count."); @@ -265,9 +257,9 @@ system_method_has_key(__UNUSED rpc::target_type target, const torrent::Object& r } torrent::Object -system_method_list_keys(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { +system_method_list_keys(const torrent::Object::string_type& args) { rpc::CommandFunctionList* function; - rpc::CommandMap::iterator itr = rpc::commands.find(rawArgs.as_string().c_str()); + rpc::CommandMap::iterator itr = rpc::commands.find(args.c_str()); if (itr == rpc::commands.end() || (function = dynamic_cast(itr->second.m_variable)) == NULL) @@ -284,11 +276,11 @@ system_method_list_keys(__UNUSED rpc::target_type target, const torrent::Object& void initialize_command_dynamic() { - CMD_N ("method.insert", rak::ptr_fn(&system_method_insert)); - CMD_N_STRING("method.erase", rak::ptr_fn(&system_method_erase)); - CMD_N_STRING("method.get", rak::ptr_fn(&system_method_get)); - CMD_N ("method.set", rak::ptr_fn(&system_method_set)); - CMD_N ("method.set_key", rak::ptr_fn(&system_method_set_key)); - CMD_N ("method.has_key", rak::ptr_fn(&system_method_has_key)); - CMD_N_STRING("method.list_keys", rak::ptr_fn(&system_method_list_keys)); + CMD2_ANY_LIST ("method.insert", std::tr1::bind(&system_method_insert, std::tr1::placeholders::_2)); + CMD2_ANY_STRING ("method.erase", std::tr1::bind(&system_method_erase, std::tr1::placeholders::_2)); + CMD2_ANY_STRING ("method.get", std::tr1::bind(&system_method_get, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("method.set", std::tr1::bind(&system_method_set, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("method.set_key", std::tr1::bind(&system_method_set_key, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("method.has_key", std::tr1::bind(&system_method_has_key, std::tr1::placeholders::_2)); + CMD2_ANY_STRING ("method.list_keys", std::tr1::bind(&system_method_list_keys, std::tr1::placeholders::_2)); } diff --git a/src/command_events.cc b/src/command_events.cc index d73b2a87..1892f293 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -216,7 +216,7 @@ apply_load(const torrent::Object::list_type& args, int flags) { 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_std("Could not read resource file: " + path); } -void +torrent::Object apply_close_low_diskspace(int64_t arg) { core::DownloadList* downloadList = control->core()->download_list(); @@ -239,6 +239,8 @@ apply_close_low_diskspace(int64_t arg) { if (closed) control->core()->push_log("Closed torrents due to low diskspace."); + + return torrent::Object(); } torrent::Object @@ -302,7 +304,7 @@ d_multicall(const torrent::Object::list_type& args) { } torrent::Object -test_thread_locking(const torrent::Object& rawArgs) { +test_thread_locking() { worker_thread->queue_item(&ThreadWorker::start_log_counter); return torrent::Object(); @@ -310,36 +312,38 @@ test_thread_locking(const torrent::Object& rawArgs) { void initialize_command_events() { - ADD_COMMAND_NONE("test.thread_locking", rak::ptr_fn(&test_thread_locking)); + CMD2_ANY("test.thread_locking", std::tr1::bind(&test_thread_locking)); - ADD_VARIABLE_BOOL("check_hash", true); // Rename + CMD2_VAR_BOOL ("check_hash", true); // Rename - rpc::commands.call("method.insert", rpc::create_object_list("system.session.use_lock", "bool|const", true)); - rpc::commands.call("method.insert", rpc::create_object_list("system.session.on_completion", "bool|const", true)); + CMD2_VAR_BOOL ("system.session.use_lock", true); + CMD2_VAR_BOOL ("system.session.on_completion", true); - CMD2_ANY_STRING("on_ratio", std::tr1::bind(&apply_on_ratio, std::tr1::placeholders::_2)); + CMD2_ANY_STRING ("on_ratio", std::tr1::bind(&apply_on_ratio, std::tr1::placeholders::_2)); - ADD_COMMAND_VOID("start_tied", &apply_start_tied); - ADD_COMMAND_VOID("stop_untied", &apply_stop_untied); - ADD_COMMAND_VOID("close_untied", &apply_close_untied); - ADD_COMMAND_VOID("remove_untied", &apply_remove_untied); + CMD2_ANY ("start_tied", std::tr1::bind(&apply_start_tied)); + CMD2_ANY ("stop_untied", std::tr1::bind(&apply_stop_untied)); + CMD2_ANY ("close_untied", std::tr1::bind(&apply_close_untied)); + CMD2_ANY ("remove_untied", std::tr1::bind(&apply_remove_untied)); - CMD2_ANY_LIST("schedule", std::tr1::bind(&apply_schedule, std::tr1::placeholders::_2)); - ADD_COMMAND_STRING_UN("schedule_remove", rak::make_mem_fun(control->command_scheduler(), &rpc::CommandScheduler::erase_str)); + CMD2_ANY_LIST ("schedule", std::tr1::bind(&apply_schedule, std::tr1::placeholders::_2)); + CMD2_ANY_STRING_V("schedule_remove", std::tr1::bind(&rpc::CommandScheduler::erase_str, control->command_scheduler(), std::tr1::placeholders::_2)); - ADD_COMMAND_STRING_UN("import", std::ptr_fun(&apply_import)); - ADD_COMMAND_STRING_UN("try_import", std::ptr_fun(&apply_try_import)); + CMD2_ANY_STRING_V("import", std::tr1::bind(&apply_import, std::tr1::placeholders::_2)); + CMD2_ANY_STRING_V("try_import", std::tr1::bind(&apply_try_import, std::tr1::placeholders::_2)); - CMD2_ANY_LIST("load", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_tied)); - CMD2_ANY_LIST("load_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_tied)); - CMD2_ANY_LIST("load_start", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_tied | core::Manager::create_start)); - CMD2_ANY_LIST("load_start_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_tied | core::Manager::create_start)); - CMD2_ANY_LIST("load_raw", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_raw_data)); - CMD2_ANY_LIST("load_raw_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_raw_data)); - CMD2_ANY_LIST("load_raw_start", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_start | core::Manager::create_raw_data)); + CMD2_ANY_LIST ("load", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_tied)); + CMD2_ANY_LIST ("load_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_tied)); + CMD2_ANY_LIST ("load_start", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, + core::Manager::create_quiet | core::Manager::create_tied | core::Manager::create_start)); + CMD2_ANY_LIST ("load_start_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_tied | core::Manager::create_start)); + CMD2_ANY_LIST ("load_raw", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_quiet | core::Manager::create_raw_data)); + CMD2_ANY_LIST ("load_raw_verbose", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, core::Manager::create_raw_data)); + CMD2_ANY_LIST ("load_raw_start", std::tr1::bind(&apply_load, std::tr1::placeholders::_2, + core::Manager::create_quiet | core::Manager::create_start | core::Manager::create_raw_data)); - ADD_COMMAND_VALUE_UN("close_low_diskspace", std::ptr_fun(&apply_close_low_diskspace)); + CMD2_ANY_VALUE ("close_low_diskspace", std::tr1::bind(&apply_close_low_diskspace, std::tr1::placeholders::_2)); - CMD2_ANY_LIST("download_list", std::tr1::bind(&apply_download_list, std::tr1::placeholders::_2)); - CMD2_ANY_LIST("d.multicall", std::tr1::bind(&d_multicall, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("download_list", std::tr1::bind(&apply_download_list, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("d.multicall", std::tr1::bind(&d_multicall, std::tr1::placeholders::_2)); } diff --git a/src/command_file.cc b/src/command_file.cc index ed2f2108..4a0e9f84 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -97,74 +97,40 @@ apply_fi_filename_last(torrent::FileListIterator* itr) { return itr->file()->path()->at(itr->depth()); } -#define ADD_CF_SLOT(key, function, slot, parm, doc) \ - commandFileSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandFileSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc); - -#define ADD_CF_SLOT_PUBLIC(key, function, slot, parm, doc) \ - commandFileSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandFileSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_CF_VOID(key, slot) \ - ADD_CF_SLOT_PUBLIC("f." key, call_unknown, rpc::object_fn(slot), "i:", "") - -#define ADD_CF_VALUE(key, get) \ - ADD_CF_SLOT_PUBLIC("f." key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CF_VALUE_UNI(key, get) \ - ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CF_VALUE_BI(key, set, get) \ - ADD_CF_SLOT_PUBLIC("f.set_" key, call_value, rpc::object_value_fn(set), "i:i", "") \ - ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CF_STRING_UNI(key, get) \ - ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") - -#define ADD_CFI_SLOT_PUBLIC(key, function, slot, parm, doc) \ - commandFileItrSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandFileItrSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_CFI_VOID(key, slot) \ - ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_fn(slot), "i:", "") - -#define ADD_CFI_VALUE(key, get) \ - ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_void_fn(get), "i:", "") - void initialize_command_file() { - ADD_CF_VALUE("is_created", std::mem_fun(&torrent::File::is_created)); - ADD_CF_VALUE("is_open", std::mem_fun(&torrent::File::is_open)); + CMD2_FILE("f.is_created", std::tr1::bind(&torrent::File::is_created, std::tr1::placeholders::_1)); + CMD2_FILE("f.is_open", std::tr1::bind(&torrent::File::is_open, std::tr1::placeholders::_1)); - ADD_CF_VALUE("is_create_queued", std::mem_fun(&torrent::File::is_create_queued)); - ADD_CF_VALUE("is_resize_queued", std::mem_fun(&torrent::File::is_resize_queued)); + CMD2_FILE("f.is_create_queued", std::tr1::bind(&torrent::File::is_create_queued, std::tr1::placeholders::_1)); + CMD2_FILE("f.is_resize_queued", std::tr1::bind(&torrent::File::is_resize_queued, std::tr1::placeholders::_1)); - ADD_CF_VALUE("set_create_queued", std::bind2nd(std::mem_fun(&torrent::File::set_flags), (int)torrent::File::flag_create_queued)); - ADD_CF_VALUE("set_resize_queued", std::bind2nd(std::mem_fun(&torrent::File::set_flags), (int)torrent::File::flag_resize_queued)); - ADD_CF_VALUE("unset_create_queued", std::bind2nd(std::mem_fun(&torrent::File::unset_flags), (int)torrent::File::flag_create_queued)); - ADD_CF_VALUE("unset_resize_queued", std::bind2nd(std::mem_fun(&torrent::File::unset_flags), (int)torrent::File::flag_resize_queued)); + CMD2_FILE_VALUE_V("f.set_create_queued", std::tr1::bind(&torrent::File::set_flags, std::tr1::placeholders::_1, torrent::File::flag_create_queued)); + CMD2_FILE_VALUE_V("f.set_resize_queued", std::tr1::bind(&torrent::File::set_flags, std::tr1::placeholders::_1, torrent::File::flag_resize_queued)); + CMD2_FILE_VALUE_V("f.unset_create_queued", std::tr1::bind(&torrent::File::unset_flags, std::tr1::placeholders::_1, torrent::File::flag_create_queued)); + CMD2_FILE_VALUE_V("f.unset_resize_queued", std::tr1::bind(&torrent::File::unset_flags, std::tr1::placeholders::_1, torrent::File::flag_resize_queued)); - ADD_CF_VALUE_UNI("size_bytes", std::mem_fun(&torrent::File::size_bytes)); - ADD_CF_VALUE_UNI("size_chunks", std::mem_fun(&torrent::File::size_chunks)); - ADD_CF_VALUE_UNI("completed_chunks", std::mem_fun(&torrent::File::completed_chunks)); + CMD2_FILE("f.size_bytes", std::tr1::bind(&torrent::File::size_bytes, std::tr1::placeholders::_1)); + CMD2_FILE("f.size_chunks", std::tr1::bind(&torrent::File::size_chunks, std::tr1::placeholders::_1)); + CMD2_FILE("f.completed_chunks", std::tr1::bind(&torrent::File::completed_chunks, std::tr1::placeholders::_1)); - ADD_CF_VALUE_UNI("offset", std::mem_fun(&torrent::File::offset)); - ADD_CF_VALUE_UNI("range_first", std::mem_fun(&torrent::File::range_first)); - ADD_CF_VALUE_UNI("range_second", std::mem_fun(&torrent::File::range_second)); + CMD2_FILE("f.offset", std::tr1::bind(&torrent::File::offset, std::tr1::placeholders::_1)); + CMD2_FILE("f.range_first", std::tr1::bind(&torrent::File::range_first, std::tr1::placeholders::_1)); + CMD2_FILE("f.range_second", std::tr1::bind(&torrent::File::range_second, std::tr1::placeholders::_1)); - ADD_CF_VALUE_BI("priority", std::ptr_fun(&apply_f_set_priority), std::mem_fun(&torrent::File::priority)); + CMD2_FILE("f.priority", std::tr1::bind(&torrent::File::priority, std::tr1::placeholders::_1)); + CMD2_FILE_VALUE_V("f.priority.set", std::tr1::bind(&apply_f_set_priority, std::tr1::placeholders::_1, std::tr1::placeholders::_2)); - ADD_CF_STRING_UNI("path", std::ptr_fun(&apply_f_path)); - ADD_CF_STRING_UNI("path_components", std::ptr_fun(&apply_f_path_components)); - ADD_CF_STRING_UNI("path_depth", std::ptr_fun(&apply_f_path_depth)); - ADD_CF_STRING_UNI("frozen_path", std::mem_fun(&torrent::File::frozen_path)); + CMD2_FILE("f.path", std::tr1::bind(&apply_f_path, std::tr1::placeholders::_1)); + CMD2_FILE("f.path_components", std::tr1::bind(&apply_f_path_components, std::tr1::placeholders::_1)); + CMD2_FILE("f.path_depth", std::tr1::bind(&apply_f_path_depth, std::tr1::placeholders::_1)); + CMD2_FILE("f.frozen_path", std::tr1::bind(&torrent::File::frozen_path, std::tr1::placeholders::_1)); - ADD_CF_VALUE_UNI("match_depth_prev", std::mem_fun(&torrent::File::match_depth_prev)); - ADD_CF_VALUE_UNI("match_depth_next", std::mem_fun(&torrent::File::match_depth_next)); + CMD2_FILE("f.match_depth_prev", std::tr1::bind(&torrent::File::match_depth_prev, std::tr1::placeholders::_1)); + CMD2_FILE("f.match_depth_next", std::tr1::bind(&torrent::File::match_depth_next, std::tr1::placeholders::_1)); - ADD_CF_VALUE_UNI("last_touched", std::mem_fun(&torrent::File::last_touched)); + CMD2_FILE("f.last_touched", std::tr1::bind(&torrent::File::last_touched, std::tr1::placeholders::_1)); - ADD_CFI_VOID("get_filename_last", &apply_fi_filename_last); - - ADD_CFI_VALUE("is_file", std::mem_fun(&torrent::FileListIterator::is_file)); + CMD2_FILEITR("fi.filename_last", std::tr1::bind(&apply_fi_filename_last, std::tr1::placeholders::_1)); + CMD2_FILEITR("fi.is_file", std::tr1::bind(&torrent::FileListIterator::is_file, std::tr1::placeholders::_1)); } diff --git a/src/command_helpers.cc b/src/command_helpers.cc index c977f5fb..1bab69f8 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -67,7 +67,6 @@ rpc::CommandSlot* commandAnySlotsItr = commandAnySlo rpc::command_base commandNewSlots[COMMAND_NEW_SLOTS_SIZE]; rpc::command_base* commandNewSlotItr = commandNewSlots; -void initialize_command_object(); void initialize_command_dynamic(); void initialize_command_download(); void initialize_command_events(); @@ -81,7 +80,6 @@ void initialize_command_ui(); void initialize_commands() { - initialize_command_object(); initialize_command_dynamic(); initialize_command_events(); initialize_command_network(); diff --git a/src/command_helpers.h b/src/command_helpers.h index e936da9e..961ee1ac 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -233,22 +233,36 @@ add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::stri // New std::function based command_base helper functions: // -#define CMD2_A_FUNCTION(key, function, func_type, slot, parm, doc) \ - commandNewSlotItr->set_function(slot); \ +#define CMD2_A_FUNCTION(key, function, slot, parm, doc) \ + commandNewSlotItr->set_function::type>(slot); \ rpc::commands.insert_type(key, commandNewSlotItr++, &rpc::function, \ rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, NULL, NULL); -#define CMD2_ANY(key, slot) CMD2_A_FUNCTION(key, command_base_call_any, any_function, slot, "i:", "") -#define CMD2_ANY_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_list, any_list_function, object_convert_void(slot), "i:", "") -#define CMD2_ANY_L(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_list, any_list_function, slot, "A:", "") +// #define CMD2_ANY(key, slot) CMD2_A_FUNCTION(key, command_base_call_any, slot, "i:", "") +#define CMD2_ANY(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") -#define CMD2_ANY_VALUE(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_value, any_value_function, slot, "i:i", "") -#define CMD2_ANY_VALUE_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_value, any_value_function, object_convert_void(slot), "i:i", "") +#define CMD2_ANY_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_list, object_convert_void(slot), "i:", "") +#define CMD2_ANY_L(key, slot) CMD2_A_FUNCTION(key, command_base_call_list, slot, "A:", "") -#define CMD2_ANY_STRING(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_string, any_string_function, slot, "i:s", "") -#define CMD2_ANY_STRING_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_string, any_string_function, object_convert_void(slot), "i:s", "") +#define CMD2_ANY_VALUE(key, slot) CMD2_A_FUNCTION(key, command_base_call_value, slot, "i:i", "") +#define CMD2_ANY_VALUE_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_value, object_convert_void(slot), "i:i", "") -#define CMD2_ANY_LIST(key, slot) CMD2_A_FUNCTION(key, command_base_call_any_list, any_list_function, slot, "i:", "") +#define CMD2_ANY_STRING(key, slot) CMD2_A_FUNCTION(key, command_base_call_string, slot, "i:s", "") +#define CMD2_ANY_STRING_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_string, object_convert_void(slot), "i:s", "") + +#define CMD2_ANY_LIST(key, slot) CMD2_A_FUNCTION(key, command_base_call_list, slot, "i:", "") + +#define CMD2_DOWNLOAD(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") + +#define CMD2_FILE(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") +#define CMD2_FILE_V(key, slot) CMD2_A_FUNCTION(key, command_base_call, object_convert_void(slot), "i:", "") +#define CMD2_FILE_VALUE_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_value, object_convert_void(slot), "i:i", "") + +#define CMD2_FILEITR(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") + +#define CMD2_TRACKER(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") +#define CMD2_TRACKER_V(key, slot) CMD2_A_FUNCTION(key, command_base_call, object_convert_void(slot), "i:", "") +#define CMD2_TRACKER_VALUE_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_value, object_convert_void(slot), "i:i", "") #define CMD2_VAR_BOOL(key, value) \ rpc::commands.call("method.insert", rpc::create_object_list(key, "bool|const", int64_t(value))); diff --git a/src/command_local.cc b/src/command_local.cc index 66e1f1c1..0fb72f0b 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -150,9 +150,9 @@ check_name(const std::string& str) { } torrent::Object -group_insert(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - torrent::Object::list_const_iterator itr = rawArgs.as_list().begin(); - torrent::Object::list_const_iterator last = rawArgs.as_list().end(); +group_insert(const torrent::Object::list_type& args) { + torrent::Object::list_const_iterator itr = args.begin(); + torrent::Object::list_const_iterator last = args.end(); const std::string& name = check_name(post_increment(itr, last)->as_string()); const std::string& view = check_name(post_increment(itr, last)->as_string()); @@ -176,8 +176,8 @@ initialize_command_local() { core::DownloadList* dList = control->core()->download_list(); core::DownloadStore* dStore = control->core()->download_store(); - ADD_COMMAND_VOID("system.hostname", rak::ptr_fun(&system_hostname)); - ADD_COMMAND_VOID("system.pid", rak::ptr_fun(&getpid)); + CMD2_ANY ("system.hostname", std::tr1::bind(&system_hostname)); + CMD2_ANY ("system.pid", std::tr1::bind(&getpid)); rpc::commands.call("method.insert", rpc::create_object_list("system.client_version", "string|static|const", PACKAGE_VERSION)); rpc::commands.call("method.insert", rpc::create_object_list("system.library_version", "string|static|const", torrent::version())); @@ -187,47 +187,50 @@ initialize_command_local() { rpc::commands.call("method.insert", rpc::create_object_list("system.file.split_suffix", "string|const", ".part")); rpc::commands.call("method.insert", rpc::create_object_list("system.session_name", "string|const", "")); - ADD_COMMAND_VOID("system.file_status_cache.size", rak::make_mem_fun((utils::FileStatusCache::base_type*)control->core()->file_status_cache(), - &utils::FileStatusCache::size)); - ADD_COMMAND_VOID("system.file_status_cache.prune", rak::make_mem_fun(control->core()->file_status_cache(), &utils::FileStatusCache::prune)); + CMD2_ANY ("system.file_status_cache.size", std::tr1::bind(&utils::FileStatusCache::size, + (utils::FileStatusCache::base_type*)control->core()->file_status_cache())); + CMD2_ANY_V ("system.file_status_cache.prune", std::tr1::bind(&utils::FileStatusCache::prune, control->core()->file_status_cache())); - ADD_COMMAND_VOID("system.files.opened_counter", rak::make_mem_fun(fileManager, &FM_t::files_opened_counter)); - ADD_COMMAND_VOID("system.files.closed_counter", rak::make_mem_fun(fileManager, &FM_t::files_closed_counter)); - ADD_COMMAND_VOID("system.files.failed_counter", rak::make_mem_fun(fileManager, &FM_t::files_failed_counter)); + CMD2_ANY ("system.files.opened_counter", std::tr1::bind(&FM_t::files_opened_counter, fileManager)); + CMD2_ANY ("system.files.closed_counter", std::tr1::bind(&FM_t::files_closed_counter, fileManager)); + CMD2_ANY ("system.files.failed_counter", std::tr1::bind(&FM_t::files_failed_counter, fileManager)); - ADD_COMMAND_VOID("system.time", rak::make_mem_fun(&cachedTime, &rak::timer::seconds)); - ADD_COMMAND_VOID("system.time_seconds", rak::ptr_fun(&rak::timer::current_seconds)); - ADD_COMMAND_VOID("system.time_usec", rak::ptr_fun(&rak::timer::current_usec)); + CMD2_ANY ("system.time", std::tr1::bind(&rak::timer::seconds, &cachedTime)); + CMD2_ANY ("system.time_seconds", std::tr1::bind(&rak::timer::current_seconds)); + CMD2_ANY ("system.time_usec", std::tr1::bind(&rak::timer::current_usec)); - ADD_COMMAND_VALUE_SET_OCT("system.", "umask", std::ptr_fun(&umask)); - ADD_COMMAND_STRING_PREFIX("system.", "cwd", std::ptr_fun(system_set_cwd), rak::ptr_fun(&system_get_cwd)); +// ADD_COMMAND_VALUE_SET_OCT("system.", "umask", std::ptr_fun(&umask)); +// ADD_COMMAND_STRING_PREFIX("system.", "cwd", std::ptr_fun(system_set_cwd), rak::ptr_fun(&system_get_cwd)); - ADD_COMMAND_VOID("pieces.sync.always_safe", rak::make_mem_fun(chunkManager, &CM_t::safe_sync)); - ADD_COMMAND_VALUE_UN("pieces.sync.always_safe.set", rak::make_mem_fun(chunkManager, &CM_t::set_safe_sync)); - ADD_COMMAND_VOID("pieces.sync.safe_free_diskspace", rak::make_mem_fun(chunkManager, &CM_t::safe_free_diskspace)); - ADD_COMMAND_VOID("pieces.sync.timeout", rak::make_mem_fun(chunkManager, &CM_t::timeout_sync)); - ADD_COMMAND_VALUE_UN("pieces.sync.timeout.set", rak::make_mem_fun(chunkManager, &CM_t::set_timeout_sync)); - ADD_COMMAND_VOID("pieces.sync.timeout_safe", rak::make_mem_fun(chunkManager, &CM_t::timeout_safe_sync)); - ADD_COMMAND_VALUE_UN("pieces.sync.timeout_safe.set", rak::make_mem_fun(chunkManager, &CM_t::set_timeout_safe_sync)); + CMD2_ANY ("pieces.sync.always_safe", std::tr1::bind(&CM_t::safe_sync, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.sync.always_safe.set", std::tr1::bind(&CM_t::set_safe_sync, chunkManager, std::tr1::placeholders::_2)); + CMD2_ANY ("pieces.sync.safe_free_diskspace", std::tr1::bind(&CM_t::safe_free_diskspace, chunkManager)); + CMD2_ANY ("pieces.sync.timeout", std::tr1::bind(&CM_t::timeout_sync, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.sync.timeout.set", std::tr1::bind(&CM_t::set_timeout_sync, chunkManager, std::tr1::placeholders::_2)); + CMD2_ANY ("pieces.sync.timeout_safe", std::tr1::bind(&CM_t::timeout_safe_sync, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.sync.timeout_safe.set", std::tr1::bind(&CM_t::set_timeout_safe_sync, chunkManager, std::tr1::placeholders::_2)); - ADD_COMMAND_VOID("pieces.preload.type", rak::make_mem_fun(chunkManager, &CM_t::preload_type)); - ADD_COMMAND_VALUE_UN("pieces.preload.type.set", rak::make_mem_fun(chunkManager, &CM_t::set_preload_type)); - ADD_COMMAND_VOID("pieces.preload.min_size", rak::make_mem_fun(chunkManager, &CM_t::preload_min_size)); - ADD_COMMAND_VALUE_UN("pieces.preload.min_size.set", rak::make_mem_fun(chunkManager, &CM_t::set_preload_min_size)); - ADD_COMMAND_VOID("pieces.preload.min_rate", rak::make_mem_fun(chunkManager, &CM_t::preload_required_rate)); - ADD_COMMAND_VALUE_UN("pieces.preload.min_rate.set", rak::make_mem_fun(chunkManager, &CM_t::set_preload_required_rate)); + CMD2_ANY ("pieces.preload.type", std::tr1::bind(&CM_t::preload_type, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.preload.type.set", std::tr1::bind(&CM_t::set_preload_type, chunkManager, std::tr1::placeholders::_2)); + CMD2_ANY ("pieces.preload.min_size", std::tr1::bind(&CM_t::preload_min_size, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.preload.min_size.set", std::tr1::bind(&CM_t::set_preload_min_size, chunkManager, std::tr1::placeholders::_2)); + CMD2_ANY ("pieces.preload.min_rate", std::tr1::bind(&CM_t::preload_required_rate, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.preload.min_rate.set", std::tr1::bind(&CM_t::set_preload_required_rate, chunkManager, std::tr1::placeholders::_2)); - ADD_COMMAND_VOID("pieces.memory.current", rak::make_mem_fun(chunkManager, &CM_t::memory_usage)); - ADD_COMMAND_VOID("pieces.memory.max", rak::make_mem_fun(chunkManager, &CM_t::max_memory_usage)); - ADD_COMMAND_VALUE_UN("pieces.memory.max.set", rak::make_mem_fun(chunkManager, &CM_t::set_max_memory_usage)); - ADD_COMMAND_VOID("pieces.stats_preloaded", rak::make_mem_fun(chunkManager, &CM_t::stats_preloaded)); - ADD_COMMAND_VOID("pieces.stats_not_preloaded", rak::make_mem_fun(chunkManager, &CM_t::stats_not_preloaded)); + CMD2_ANY ("pieces.memory.current", std::tr1::bind(&CM_t::memory_usage, chunkManager)); + CMD2_ANY ("pieces.memory.max", std::tr1::bind(&CM_t::max_memory_usage, chunkManager)); + CMD2_ANY_VALUE_V ("pieces.memory.max.set", std::tr1::bind(&CM_t::set_max_memory_usage, chunkManager, std::tr1::placeholders::_2)); + CMD2_ANY ("pieces.stats_preloaded", std::tr1::bind(&CM_t::stats_preloaded, chunkManager)); + CMD2_ANY ("pieces.stats_not_preloaded", std::tr1::bind(&CM_t::stats_not_preloaded, chunkManager)); + CMD2_VAR_STRING ("directory.default", "./"); - ADD_VARIABLE_STRING("directory", "./"); + // TODO: Clean up. + CMD2_ANY ("get_session", std::tr1::bind(&core::DownloadStore::path, dStore)); + CMD2_ANY_STRING_V("set_session", std::tr1::bind(&core::DownloadStore::set_path, dStore, std::tr1::placeholders::_2)); + CMD2_ANY_STRING_V("session", std::tr1::bind(&core::DownloadStore::set_path, dStore, std::tr1::placeholders::_2)); - ADD_COMMAND_STRING_TRI("session", rak::make_mem_fun(dStore, &core::DownloadStore::set_path), rak::make_mem_fun(dStore, &core::DownloadStore::path)); - ADD_COMMAND_VOID("session_save", rak::make_mem_fun(dList, &core::DownloadList::session_save)); + CMD2_ANY_V ("session_save", std::tr1::bind(&core::DownloadList::session_save, dList)); CMD2_ANY("execute", std::tr1::bind(&rpc::ExecFile::execute_object, &rpc::execFile, std::tr1::placeholders::_2, rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde)); CMD2_ANY("execute_nothrow", std::tr1::bind(&rpc::ExecFile::execute_object, &rpc::execFile, std::tr1::placeholders::_2, rpc::ExecFile::flag_expand_tilde)); @@ -239,6 +242,7 @@ initialize_command_local() { CMD2_ANY_STRING("log.execute", std::tr1::bind(&apply_log, std::tr1::placeholders::_2, 0)); CMD2_ANY_STRING("log.xmlrpc", std::tr1::bind(&apply_log, std::tr1::placeholders::_2, 1)); + // TODO: Convert to new command types: *rpc::Command::argument(0) = "placeholder.0"; *rpc::Command::argument(1) = "placeholder.1"; *rpc::Command::argument(2) = "placeholder.2"; @@ -248,5 +252,5 @@ initialize_command_local() { CMD_OBJ_P("argument.2", get_generic, rpc::Command::argument(2)); CMD_OBJ_P("argument.3", get_generic, rpc::Command::argument(3)); - CMD_N_LIST("group.insert", rak::ptr_fn(&group_insert)); + CMD2_ANY_LIST ("group.insert", std::tr1::bind(&group_insert, std::tr1::placeholders::_2)); } diff --git a/src/command_object.cc b/src/command_object.cc deleted file mode 100644 index 9b60d223..00000000 --- a/src/command_object.cc +++ /dev/null @@ -1,54 +0,0 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include - -#include "globals.h" -#include "control.h" -#include "command_helpers.h" -#include "rpc/command_variable.h" - -// torrent::Object -// list_push_back(__UNUSED rpc::target_type target, const torrent::Object& rawArgs) { - - -void -initialize_command_object() { -// CMD_N ("method.insert", rak::ptr_fn(&system_method_insert)); -// CMD_N_STRING("method.erase", rak::ptr_fn(&system_method_erase)); -} diff --git a/src/command_scheduler.cc b/src/command_scheduler.cc index a8a42318..4b4141c3 100644 --- a/src/command_scheduler.cc +++ b/src/command_scheduler.cc @@ -50,7 +50,7 @@ #include "command_helpers.h" torrent::Object -cmd_scheduler_simple_added(core::Download* download, const torrent::Object& rawArgs) { +cmd_scheduler_simple_added(core::Download* download) { unsigned int numActive = (*control->view_manager()->find("active"))->size_visible(); int64_t maxActive = rpc::call_command("scheduler.max_active", torrent::Object()).as_value(); @@ -61,7 +61,7 @@ cmd_scheduler_simple_added(core::Download* download, const torrent::Object& rawA } torrent::Object -cmd_scheduler_simple_removed(core::Download* download, const torrent::Object& rawArgs) { +cmd_scheduler_simple_removed(core::Download* download) { control->core()->download_list()->pause(download); core::View* viewActive = *control->view_manager()->find("active"); @@ -84,7 +84,7 @@ cmd_scheduler_simple_removed(core::Download* download, const torrent::Object& ra } torrent::Object -cmd_scheduler_simple_update(core::Download* download, const torrent::Object& rawArgs) { +cmd_scheduler_simple_update(core::Download* download) { core::View* viewActive = *control->view_manager()->find("active"); core::View* viewStarted = *control->view_manager()->find("started"); @@ -114,13 +114,9 @@ cmd_scheduler_simple_update(core::Download* download, const torrent::Object& raw void initialize_command_scheduler() { -// core::DownloadList* dList = control->core()->download_list(); + CMD2_VAR_VALUE("scheduler.max_active", int64_t(-1)); -// CMD_G("scheduler.active", rak::bind_ptr_fn(&cmd_call, "view.size=active")); - - rpc::commands.call("method.insert", rpc::create_object_list("scheduler.max_active", "value", (int64_t)-1)); - - CMD_D_ANY("scheduler.simple.added", rak::ptr_fn(&cmd_scheduler_simple_added)); - CMD_D_ANY("scheduler.simple.removed", rak::ptr_fn(&cmd_scheduler_simple_removed)); - CMD_D_ANY("scheduler.simple.update", rak::ptr_fn(&cmd_scheduler_simple_update)); + CMD2_DOWNLOAD("scheduler.simple.added", std::tr1::bind(&cmd_scheduler_simple_added, std::tr1::placeholders::_1)); + CMD2_DOWNLOAD("scheduler.simple.removed", std::tr1::bind(&cmd_scheduler_simple_removed, std::tr1::placeholders::_1)); + CMD2_DOWNLOAD("scheduler.simple.update", std::tr1::bind(&cmd_scheduler_simple_update, std::tr1::placeholders::_1)); } diff --git a/src/command_tracker.cc b/src/command_tracker.cc index 0ffa70f0..bbb2f7d6 100644 --- a/src/command_tracker.cc +++ b/src/command_tracker.cc @@ -45,57 +45,23 @@ #include "control.h" #include "command_helpers.h" -void -apply_t_set_enabled(torrent::Tracker* tracker, int64_t state) { - if (state) - tracker->enable(); - else - tracker->disable(); -} - -#define ADD_CT_SLOT(key, function, slot, parm, doc) \ - commandTrackerSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandTrackerSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc); - -#define ADD_CT_SLOT_PUBLIC(key, function, slot, parm, doc) \ - commandTrackerSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandTrackerSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_CT_VOID(key, slot) \ - ADD_CT_SLOT_PUBLIC("t." key, call_unknown, rpc::object_void_fn(slot), "i:", "") - -#define ADD_CT_VOID_UNI(key, get) \ - ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CT_VALUE_UNI(key, get) \ - ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CT_VALUE_BI(key, set, get) \ - ADD_CT_SLOT_PUBLIC("t.set_" key, call_value, rpc::object_value_fn(set), "i:i", "") \ - ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CT_BOOL(key, set, get) \ - ADD_CT_SLOT_PUBLIC("t.set_" key, call_value, rpc::object_value_fn(set), "i:i", "") \ - ADD_CT_SLOT_PUBLIC("t.is_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_CT_STRING_UNI(key, get) \ - ADD_CT_SLOT_PUBLIC("t.get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") - void initialize_command_tracker() { - ADD_CT_STRING_UNI("url", std::mem_fun(&torrent::Tracker::url)); - ADD_CT_VOID_UNI("group", std::mem_fun(&torrent::Tracker::group)); - ADD_CT_VOID_UNI("type", std::mem_fun(&torrent::Tracker::type)); - ADD_CT_STRING_UNI("id", std::mem_fun(&torrent::Tracker::tracker_id)); + CMD2_TRACKER ("t.is_open", std::tr1::bind(&torrent::Tracker::is_busy, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.is_enabled", std::tr1::bind(&torrent::Tracker::is_enabled, std::tr1::placeholders::_1)); + CMD2_TRACKER_VALUE_V("t.is_enabled.set", std::tr1::bind(&torrent::Tracker::set_enabled, std::tr1::placeholders::_1, std::tr1::placeholders::_2)); + CMD2_TRACKER_V ("t.enable", std::tr1::bind(&torrent::Tracker::enable, std::tr1::placeholders::_1)); + CMD2_TRACKER_V ("t.disable", std::tr1::bind(&torrent::Tracker::disable, std::tr1::placeholders::_1)); - ADD_CT_VOID("is_open", std::mem_fun(&torrent::Tracker::is_busy)); - ADD_CT_BOOL("enabled", std::ptr_fun(&apply_t_set_enabled), std::mem_fun(&torrent::Tracker::is_enabled)); - - ADD_CT_VOID_UNI("normal_interval", std::mem_fun(&torrent::Tracker::normal_interval)); - ADD_CT_VOID_UNI("min_interval", std::mem_fun(&torrent::Tracker::min_interval)); + CMD2_TRACKER ("t.url", std::tr1::bind(&torrent::Tracker::url, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.group", std::tr1::bind(&torrent::Tracker::group, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.type", std::tr1::bind(&torrent::Tracker::type, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.id", std::tr1::bind(&torrent::Tracker::tracker_id, std::tr1::placeholders::_1)); - ADD_CT_VOID_UNI("scrape_time_last", std::mem_fun(&torrent::Tracker::scrape_time_last)); - ADD_CT_VOID_UNI("scrape_complete", std::mem_fun(&torrent::Tracker::scrape_complete)); - ADD_CT_VOID_UNI("scrape_incomplete", std::mem_fun(&torrent::Tracker::scrape_incomplete)); - ADD_CT_VOID_UNI("scrape_downloaded", std::mem_fun(&torrent::Tracker::scrape_downloaded)); + CMD2_TRACKER ("t.normal_interval", std::tr1::bind(&torrent::Tracker::normal_interval, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.min_interval", std::tr1::bind(&torrent::Tracker::min_interval, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.scrape_time_last", std::tr1::bind(&torrent::Tracker::scrape_time_last, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.scrape_complete", std::tr1::bind(&torrent::Tracker::scrape_complete, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.scrape_incomplete", std::tr1::bind(&torrent::Tracker::scrape_incomplete, std::tr1::placeholders::_1)); + CMD2_TRACKER ("t.scrape_downloaded", std::tr1::bind(&torrent::Tracker::scrape_downloaded, std::tr1::placeholders::_1)); } diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 2aed01dc..0cf65c1f 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -110,7 +110,7 @@ DownloadFactory::DownloadFactory(Manager* m) : m_variables["connection_leech"] = rpc::call_command_void("connection_leech"); m_variables["connection_seed"] = rpc::call_command_void("connection_seed"); - m_variables["directory"] = rpc::call_command_void("get_directory"); + m_variables["directory"] = rpc::call_command_void("directory.default"); m_variables["tied_to_file"] = torrent::Object((int64_t)false); } diff --git a/src/main.cc b/src/main.cc index 23b66c49..e1331c3d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -89,7 +89,7 @@ parse_options(Control* c, int argc, char** argv) { optionParser.insert_flag('D', OptionParser::Slot()); optionParser.insert_option('b', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "network.bind_address.set")); - optionParser.insert_option('d', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "directory")); + optionParser.insert_option('d', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "directory.default.set")); 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.set")); optionParser.insert_option('s', sigc::bind<0>(sigc::ptr_fun(&rpc::call_command_set_string), "session")); @@ -312,16 +312,16 @@ main(int argc, char** argv) { // // List of cleaned up files: // - command_download.cc - // - command_dynamic.cc - // - command_events.cc - // - command_file.cc + // * command_dynamic.cc + // * command_events.cc + // * command_file.cc // - command_helpers.cc - // - command_local.cc + // + command_local.cc // * command_network.cc - // - command_object.cc + // * command_object.cc // - command_peer.cc - // - command_scheduler.cc - // - command_tracker.cc + // * command_scheduler.cc + // * command_tracker.cc // - command_ui.cc "method.insert = system.method.insert,redirect|const,method.insert\n" @@ -399,6 +399,14 @@ main(int argc, char** argv) { "method.insert = get_dht_throttle,redirect|const,dht.throttle\n" "method.insert = set_dht_throttle,redirect|const,dht.throttle.set\n" + "method.insert = directory,redirect|const,directory.default.set\n" + "method.insert = get_directory,redirect|const,directory.default\n" + "method.insert = set_directory,redirect|const,directory.default.set\n" + + // + // Download: + // + "method.insert = d.get_hash,redirect|const,d.hash\n" "method.insert = d.get_local_id,redirect|const,d.local_id\n" "method.insert = d.get_local_id_html,redirect|const,d.local_id_html\n" @@ -417,6 +425,42 @@ main(int argc, char** argv) { "method.insert = d.get_skip_rate,redirect|const,d.skip.rate\n" "method.insert = d.get_skip_total,redirect|const,d.skip.total\n" + // + // Tracker: + // + + "method.insert = t.get_group,redirect|const,t.get_group\n" + "method.insert = t.get_id,redirect|const,t.get_id\n" + "method.insert = t.get_min_interval,redirect|const,t.get_min_interval\n" + "method.insert = t.get_normal_interval,redirect|const,t.get_normal_interval\n" + "method.insert = t.get_scrape_complete,redirect|const,t.get_scrape_complete\n" + "method.insert = t.get_scrape_downloaded,redirect|const,t.get_scrape_downloaded\n" + "method.insert = t.get_scrape_incomplete,redirect|const,t.get_scrape_incomplete\n" + "method.insert = t.get_scrape_time_last,redirect|const,t.get_scrape_time_last\n" + "method.insert = t.get_type,redirect|const,t.get_type\n" + "method.insert = t.get_url,redirect|const,t.get_url\n" + + // + // Tracker: + // + + "method.insert = f.get_completed_chunks,redirect|const,f.completed_chunks\n" + "method.insert = f.get_frozen_path,redirect|const,f.frozen_path\n" + "method.insert = f.get_last_touched,redirect|const,f.last_touched\n" + "method.insert = f.get_match_depth_next,redirect|const,f.match_depth_next\n" + "method.insert = f.get_match_depth_prev,redirect|const,f.match_depth_prev\n" + "method.insert = f.get_offset,redirect|const,f.offset\n" + "method.insert = f.get_path,redirect|const,f.path\n" + "method.insert = f.get_path_components,redirect|const,f.path_components\n" + "method.insert = f.get_path_depth,redirect|const,f.path_depth\n" + "method.insert = f.get_priority,redirect|const,f.priority\n" + "method.insert = f.get_range_first,redirect|const,f.range_first\n" + "method.insert = f.get_range_second,redirect|const,f.range_second\n" + "method.insert = f.get_size_bytes,redirect|const,f.size_bytes\n" + "method.insert = f.get_size_chunks,redirect|const,f.size_chunks\n" + "method.insert = f.set_priority,redirect|const,f.priority.set\n" + "method.insert = fi.get_filename_last,redirect|const,fi.filename_last\n" + // Functions that might not get depracted as they are nice for // configuration files, and thus might do with just some // cleanup. diff --git a/src/rpc/command.h b/src/rpc/command.h index 07ade76a..66214d17 100644 --- a/src/rpc/command.h +++ b/src/rpc/command.h @@ -161,18 +161,30 @@ template <> struct target_type_id { static const in template <> struct target_type_id { static const int value = Command::target_download_pair; }; template <> struct target_type_id<> { static const int value = Command::target_generic; }; -template <> struct target_type_id { static const int value = Command::target_any; }; -template <> struct target_type_id { static const int value = Command::target_download; }; -template <> struct target_type_id { static const int value = Command::target_peer; }; -template <> struct target_type_id { static const int value = Command::target_tracker; }; -template <> struct target_type_id { static const int value = Command::target_file; }; -template <> struct target_type_id { static const int value = Command::target_file_itr; }; +template <> struct target_type_id { static const int value = Command::target_any; static const int proper_type = 1; }; +template <> struct target_type_id { static const int value = Command::target_download; static const int proper_type = 1; }; +template <> struct target_type_id { static const int value = Command::target_peer; static const int proper_type = 1; }; +template <> struct target_type_id { static const int value = Command::target_tracker; static const int proper_type = 1; }; +template <> struct target_type_id { static const int value = Command::target_file; static const int proper_type = 1; }; +template <> struct target_type_id { static const int value = Command::target_file_itr; static const int proper_type = 1; }; template <> struct target_type_id { static const int value = Command::target_download_pair; }; +template inline bool +is_target_compatible(const target_type& target) { return target.first == target_type_id::value; } + +template <> inline bool +is_target_compatible(const target_type& target) { return true; } + // Splitting pairs into separate targets. inline bool is_target_pair(const target_type& target) { return target.first >= Command::target_download_pair; } +template inline T +get_target_cast(target_type target, int type = target_type_id::value) { return (T)target.second; } +template <> inline target_type +get_target_cast(target_type target, int type) { return target; } + + inline target_type get_target_left(const target_type& target) { return target_type(target.first - 5, target.second); } inline target_type get_target_right(const target_type& target) { return target_type(target.first - 5, target.third); } diff --git a/src/rpc/command_new_slot.cc b/src/rpc/command_new_slot.cc index 42699aab..c43b78bb 100644 --- a/src/rpc/command_new_slot.cc +++ b/src/rpc/command_new_slot.cc @@ -41,15 +41,31 @@ #include "command_new_slot.h" +#define COMMAND_BASE_TEMPLATE_DEFINE(func_name) \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ +template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); + namespace rpc { -const torrent::Object -command_base_call_any(Command* rawCommand, target_type target, const torrent::Object& args) { - return static_cast(rawCommand)->_pod()(target, args); +template const torrent::Object +command_base_call(Command* rawCommand, target_type target, const torrent::Object& args) { + if (!is_target_compatible(target)) + throw torrent::input_error("Target of wrong type."); + + return command_base::_call::type, T>(rawCommand, target, args); } -const torrent::Object -command_base_call_any_value_base(Command* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) { +COMMAND_BASE_TEMPLATE_DEFINE(command_base_call); + +template const torrent::Object +command_base_call_value_base(Command* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) { + if (!is_target_compatible(target)) + throw torrent::input_error("Target of wrong type."); + const torrent::Object& arg = convert_to_single_argument(rawArgs); if (arg.type() == torrent::Object::TYPE_STRING) { @@ -58,40 +74,51 @@ command_base_call_any_value_base(Command* rawCommand, target_type target, const if (!parse_whole_value_nothrow(arg.as_string().c_str(), &val, base, unit)) throw torrent::input_error("Not a value."); - return static_cast(rawCommand)->_pod()(target, val); + return command_base::_call::type, T>(rawCommand, target, val); } - return static_cast(rawCommand)->_pod()(target, arg.as_value()); + return command_base::_call::type, T>(rawCommand, target, arg.as_value()); } -const torrent::Object -command_base_call_any_value(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { - return command_base_call_any_value_base(rawCommand, target, rawArgs, 0, 1); +template const torrent::Object +command_base_call_value(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { + return command_base_call_value_base(rawCommand, target, rawArgs, 0, 1); } +COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_value); + +template const torrent::Object +command_base_call_string(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { + if (!is_target_compatible(target)) + throw torrent::input_error("Target of wrong type."); -const torrent::Object -command_base_call_any_string(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { const torrent::Object& arg = convert_to_single_argument(rawArgs); if (arg.type() == torrent::Object::TYPE_RAW_STRING) - return static_cast(rawCommand)->_pod()(target, arg.as_raw_string().as_string()); + return command_base::_call::type, T>(rawCommand, target, arg.as_raw_string().as_string()); - return static_cast(rawCommand)->_pod()(target, arg.as_string()); + return command_base::_call::type, T>(rawCommand, target, arg.as_string()); } -const torrent::Object -command_base_call_any_list(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { +COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_string); + +template const torrent::Object +command_base_call_list(Command* rawCommand, target_type target, const torrent::Object& rawArgs) { + if (!is_target_compatible(target)) + throw torrent::input_error("Target of wrong type."); + if (rawArgs.type() != torrent::Object::TYPE_LIST) { torrent::Object::list_type arg; if (!rawArgs.is_empty()) arg.push_back(rawArgs); - return static_cast(rawCommand)->_pod()(target, arg); + return command_base::_call::type, T>(rawCommand, target, arg); } - return static_cast(rawCommand)->_pod()(target, rawArgs.as_list()); + return command_base::_call::type, T>(rawCommand, target, rawArgs.as_list()); } +COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_list); + } diff --git a/src/rpc/command_new_slot.h b/src/rpc/command_new_slot.h index 295e3036..77a875f0 100644 --- a/src/rpc/command_new_slot.h +++ b/src/rpc/command_new_slot.h @@ -59,7 +59,7 @@ typedef const torrent::Object (*command_base_call_type)(Command*, target_type, c typedef std::tr1::function base_function; template struct command_base_is_valid {}; -template struct command_base_is_type {}; +template struct command_base_is_type {}; class command_base : public Command { public: @@ -76,6 +76,11 @@ public: // have no idea atm. template tmpl& _pod() { return reinterpret_cast(t_pod); } + template + static const torrent::Object _call(Command* cmd, target_type target, Args args) { + return static_cast(cmd)->_pod()(get_target_cast(target), args); + } + protected: union { @@ -83,35 +88,37 @@ protected: }; }; -#define COMMAND_BASE_TYPE(func_type, func_parm) \ - typedef std::tr1::function func_type; \ - template <> struct command_base_is_valid { static const int value = 1; }; +#define COMMAND_BASE_TEMPLATE_TYPE(func_type, func_parm) \ + template ::proper_type> struct func_type { typedef std::tr1::function type; }; \ + \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; \ + template <> struct command_base_is_valid::type> { static const int value = 1; }; -#define COMMAND_BASE_CALL(func_name, func_type) \ - const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ - template <> struct command_base_is_type { static const int value = 1; }; +// template struct command_base_is_valid::type > { static const int value = 1; }; -// template <> struct command_base_is_valid { static const int value = 1; }; +COMMAND_BASE_TEMPLATE_TYPE(command_function, torrent::Object (T, const torrent::Object&)); +COMMAND_BASE_TEMPLATE_TYPE(command_value_function, torrent::Object (T, const torrent::Object::value_type&)); +COMMAND_BASE_TEMPLATE_TYPE(command_string_function, torrent::Object (T, const std::string&)); +COMMAND_BASE_TEMPLATE_TYPE(command_list_function, torrent::Object (T, const torrent::Object::list_type&)); -// const torrent::Object command_base_call_any(Command* rawCommand, target_type target, const torrent::Object& args); -// template <> struct command_base_is_type { static const int value = 1; }; +#define COMMAND_BASE_TEMPLATE_CALL(func_name, func_type) \ + template const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \ + \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; \ + template <> struct command_base_is_type > { static const int value = 1; typedef func_type::type type; }; -// -// Declare valid parameters and functions: -// - -// typedef std::tr1::function any_function; -// typedef std::tr1::function any_string_function; - -COMMAND_BASE_TYPE(any_function, torrent::Object (target_type, const torrent::Object&)); -COMMAND_BASE_TYPE(any_value_function, torrent::Object (target_type, const torrent::Object::value_type&)); -COMMAND_BASE_TYPE(any_string_function, torrent::Object (target_type, const std::string&)); -COMMAND_BASE_TYPE(any_list_function, torrent::Object (target_type, const torrent::Object::list_type&)); - -COMMAND_BASE_CALL(command_base_call_any, any_function); -COMMAND_BASE_CALL(command_base_call_any_value, any_value_function); -COMMAND_BASE_CALL(command_base_call_any_string, any_string_function); -COMMAND_BASE_CALL(command_base_call_any_list, any_list_function); +COMMAND_BASE_TEMPLATE_CALL(command_base_call, command_function); +COMMAND_BASE_TEMPLATE_CALL(command_base_call_value, command_value_function); +COMMAND_BASE_TEMPLATE_CALL(command_base_call_string, command_string_function); +COMMAND_BASE_TEMPLATE_CALL(command_base_call_list, command_list_function); } diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 1cf9296e..ae849632 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -254,7 +254,7 @@ DownloadList::receive_view_input(Input type) { case INPUT_CHANGE_DIRECTORY: title = "change_directory"; - input->str() = rpc::call_command_string("get_directory"); + input->str() = rpc::call_command_string("directory.default"); input->set_pos(input->str().length()); break; diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index 75ecec04..131a304f 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -92,9 +92,9 @@ element_file_list_create_info() { element->push_column("Filename:", te_command("fi.get_filename_last=")); element->push_back(""); - element->push_column("Size:", te_command("if=$fi.is_file=,$to_xb=$f.get_size_bytes=,---")); - element->push_column("Chunks:", te_command("cat=$f.get_completed_chunks=,\" / \",$f.get_size_chunks=")); - element->push_column("Range:", te_command("cat=$f.get_range_first=,\" - \",$f.get_range_second=")); + element->push_column("Size:", te_command("if=$fi.is_file=,$to_xb=$f.size_bytes=,---")); + element->push_column("Chunks:", te_command("cat=$f.completed_chunks=,\" / \",$f.size_chunks=")); + element->push_column("Range:", te_command("cat=$f.range_first=,\" - \",$f.range_second=")); element->push_back(""); element->push_column("Queued:", te_command("cat=\"$if=$f.is_create_queued=,create\",\" \",\"$if=$f.is_resize_queued=,resize\""));