diff --git a/configure.ac b/configure.ac index 34a92101..7bd0131f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.8.2, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.8.3, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/rak/functional_fun.h b/rak/functional_fun.h index 0acb7c63..30a6aeae 100644 --- a/rak/functional_fun.h +++ b/rak/functional_fun.h @@ -139,6 +139,26 @@ private: std::auto_ptr m_base; }; +template +class function2 { +public: + typedef Result result_type; + typedef function_base1 base_type; + + bool is_valid() const { return m_base.get() != NULL; } + + void set(base_type* base) { m_base = std::auto_ptr(base); } + base_type* release() { return m_base.release(); } + + Result operator () (Arg2 arg2) { return (*m_base)(arg2); } + + template + Result operator () (Discard discard, Arg2 arg2) { return (*m_base)(arg2); } + +private: + std::auto_ptr m_base; +}; + template class function3 { public: diff --git a/src/command_download.cc b/src/command_download.cc index 02415bf4..29ee96d3 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -434,11 +434,11 @@ initialize_command_download() { ADD_CD_LIST("delete_link", rak::bind_ptr_fn(&apply_d_change_link, 1)); ADD_CD_V_VOID("delete_tied", &apply_d_delete_tied); - ADD_ANY_NONE("d.start", rak::bind_ptr_fn(&cmd_call, "d.set_hashing_failed=0 ;d.set_state=1 ;view.set_not_visible=stopped ;view.set_visible=started")); - ADD_ANY_NONE("d.stop", rak::bind_ptr_fn(&cmd_call, "d.set_state=0 ;view.set_visible=stopped ;view.set_not_visible=started")); - ADD_ANY_NONE("d.try_start", rak::bind_ptr_fn(&cmd_call, "branch=\"or={d.get_hashing_failed=,d.get_ignore_commands=}\",{},{d.set_state=1,view.set_not_visible=stopped,view.set_visible=started}")); - ADD_ANY_NONE("d.try_stop", rak::bind_ptr_fn(&cmd_call, "branch=d.get_ignore_commands=, {}, {d.set_state=0, view.set_visible=stopped, view.set_not_visible=started}")); - ADD_ANY_NONE("d.try_close", rak::bind_ptr_fn(&cmd_call, "branch=d.get_ignore_commands=, {}, {d.set_state=0, view.set_visible=stopped, view.set_not_visible=started, d.close=}")); + CMD_FUNC_SINGLE("d.start", "d.set_hashing_failed=0 ;d.set_state=1 ;view.set_not_visible=stopped ;view.set_visible=started"); + CMD_FUNC_SINGLE("d.stop", "d.set_state=0 ;view.set_visible=stopped ;view.set_not_visible=started"); + CMD_FUNC_SINGLE("d.try_start", "branch=\"or={d.get_hashing_failed=,d.get_ignore_commands=}\",{},{d.set_state=1,view.set_not_visible=stopped,view.set_visible=started}"); + CMD_FUNC_SINGLE("d.try_stop", "branch=d.get_ignore_commands=, {}, {d.set_state=0, view.set_visible=stopped, view.set_not_visible=started}"); + CMD_FUNC_SINGLE("d.try_close", "branch=d.get_ignore_commands=, {}, {d.set_state=0, view.set_visible=stopped, view.set_not_visible=started, d.close=}"); ADD_CD_F_VOID("resume", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::resume_default)); ADD_CD_F_VOID("pause", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::pause_default)); diff --git a/src/command_events.cc b/src/command_events.cc index ca118a7c..6dc78d35 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -339,14 +339,6 @@ d_multicall(const torrent::Object& rawArgs) { return resultRaw; } -torrent::Object -cmd_call(const char* cmd, rpc::target_type target, const torrent::Object& rawArgs) { - rpc::parse_command_multiple(target, cmd); - - return torrent::Object(); -} - - void initialize_command_events() { core::DownloadList* downloadList = control->core()->download_list(); diff --git a/src/command_helpers.cc b/src/command_helpers.cc index c2f75265..2605119d 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -108,7 +108,7 @@ initialize_commands() { void add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot, + rpc::Command::cleaned_slot getSlot, rpc::Command::cleaned_slot setSlot, const torrent::Object& defaultObject) { rpc::CommandVariable* variable = commandVariablesItr++; variable->set_variable(defaultObject); diff --git a/src/command_helpers.h b/src/command_helpers.h index 099b77f7..4144c0fd 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -38,6 +38,7 @@ #define RTORRENT_UTILS_COMMAND_HELPERS_H #include "rpc/command_slot.h" +#include "rpc/command_function.h" #include "rpc/parse_commands.h" namespace rpc { @@ -78,11 +79,9 @@ void initialize_commands(); void add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - rpc::Command::generic_slot getSlot, rpc::Command::generic_slot setSlot, + rpc::Command::cleaned_slot getSlot, rpc::Command::cleaned_slot setSlot, const torrent::Object& defaultObject); -extern torrent::Object cmd_call(const char* cmd, rpc::target_type target, const torrent::Object& rawArgs); - #define ADD_VARIABLE_BOOL(key, defaultValue) \ add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_bool, &rpc::CommandVariable::set_bool, (int64_t)defaultValue); @@ -207,4 +206,7 @@ add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::stri #define CMD_D_VOID(key, slot) \ CMD_D_SLOT(key, call_unknown, rpc::object_fn(slot), "i:", "") +#define CMD_FUNC_SINGLE(key, command) \ + rpc::commands.insert_type(key, new rpc::CommandFunction(command), &rpc::CommandFunction::call, rpc::CommandMap::flag_public_xmlrpc, NULL, NULL); + #endif diff --git a/src/core/download_list.cc b/src/core/download_list.cc index cbcb55ed..337e57c8 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -393,6 +393,9 @@ DownloadList::pause(Download* download, int flags) { download->download()->stop(flags); torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume")); + // TODO: This is actually for pause, not stop... And doesn't get + // called when the download isn't active, but was in the 'started' + // view. std::for_each(slot_map_stop().begin(), slot_map_stop().end(), download_list_call(download)); rpc::call_command("d.set_state_changed", cachedTime.seconds(), rpc::make_target(download)); diff --git a/src/rpc/Makefile.am b/src/rpc/Makefile.am index 73b2b55a..e875ba29 100644 --- a/src/rpc/Makefile.am +++ b/src/rpc/Makefile.am @@ -2,6 +2,8 @@ noinst_LIBRARIES = libsub_rpc.a libsub_rpc_a_SOURCES = \ command.h \ + command_function.cc \ + command_function.h \ command_map.cc \ command_map.h \ command_scheduler.cc \ diff --git a/src/rpc/command.h b/src/rpc/command.h index cec93db7..17919803 100644 --- a/src/rpc/command.h +++ b/src/rpc/command.h @@ -52,6 +52,20 @@ namespace torrent { namespace rpc { +template +struct target_wrapper { + typedef Target target_type; + typedef Target cleaned_type; +}; + +template <> +struct target_wrapper { + struct no_type {}; + + typedef void target_type; + typedef no_type* cleaned_type; +}; + // Since c++0x isn't out yet... template struct rt_triple : private std::pair { @@ -95,6 +109,7 @@ public: typedef torrent::Object::key_type key_type; typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&); + typedef const torrent::Object (*cleaned_slot) (Command*, target_wrapper::cleaned_type, const torrent::Object&); typedef const torrent::Object (*any_slot) (Command*, target_type, const torrent::Object&); typedef const torrent::Object (*download_slot) (Command*, core::Download*, const torrent::Object&); typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&); @@ -127,7 +142,8 @@ struct target_type_id { // Nothing here, so we cause an error. }; -template <> struct target_type_id { static const int value = Command::target_generic; }; +//template <> struct target_type_id { static const int value = Command::target_generic; }; +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; }; diff --git a/src/rpc/command_function.cc b/src/rpc/command_function.cc new file mode 100644 index 00000000..27188936 --- /dev/null +++ b/src/rpc/command_function.cc @@ -0,0 +1,54 @@ +// 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 "parse.h" +#include "parse_commands.h" +#include "command_function.h" + +namespace rpc { + +const torrent::Object +CommandFunction::call(Command* rawCommand, target_type target, const torrent::Object& args) { + CommandFunction* command = reinterpret_cast(rawCommand); + + parse_command_multiple(target, command->m_command.c_str(), command->m_command.c_str() + command->m_command.size()); + + return torrent::Object(); +} + +} diff --git a/src/rpc/command_function.h b/src/rpc/command_function.h new file mode 100644 index 00000000..18f65889 --- /dev/null +++ b/src/rpc/command_function.h @@ -0,0 +1,65 @@ +// 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 + +#ifndef RTORRENT_RPC_COMMAND_FUNCTION_H +#define RTORRENT_RPC_COMMAND_FUNCTION_H + +#include +#include +#include +#include + +#include "command.h" + +namespace rpc { + +class CommandFunction : public Command { +public: + CommandFunction(const std::string& cmd = std::string()) : m_command(cmd) {} + + const std::string& command() const { return m_command; } + void set_command(const std::string& cmd) { m_command = cmd; } + + static const torrent::Object call(Command* rawCommand, target_type target, const torrent::Object& args); + +private: + // TODO: Replace with a delete-me flag and const char*. + std::string m_command; +}; + +} + +#endif diff --git a/src/rpc/command_map.cc b/src/rpc/command_map.cc index dcc2b0e2..292b1fb2 100644 --- a/src/rpc/command_map.cc +++ b/src/rpc/command_map.cc @@ -46,9 +46,13 @@ namespace rpc { CommandMap::~CommandMap() { - for (iterator itr = base_type::begin(), last = base_type::end(); itr != last; itr++) + for (iterator itr = base_type::begin(), last = base_type::end(); itr != last; itr++) { if (!(itr->second.m_flags & flag_dont_delete)) delete itr->second.m_variable; + + if (itr->second.m_flags & flag_delete_key) + ; // Remove from map and then delte the key. + } } CommandMap::iterator @@ -102,14 +106,17 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe // This _should_ be optimized int just two calls. switch (itr->second.m_target) { - case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg); - case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg); - case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg); - case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg); - case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg); - case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg); - case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg); + case Command::target_any: return itr->second.m_anySlot(itr->second.m_variable, target, arg); + case Command::target_generic: + case Command::target_download: + case Command::target_peer: + case Command::target_tracker: + case Command::target_file: + case Command::target_file_itr: return itr->second.m_genericSlot(itr->second.m_variable, (target_wrapper::cleaned_type)target.second, arg); + + // This should only allow target_type to be passed or something, in + // order to optimize this away. case Command::target_download_pair: return itr->second.m_downloadPairSlot(itr->second.m_variable, (core::Download*)target.second, (core::Download*)target.third, arg); default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target."); @@ -132,13 +139,14 @@ CommandMap::call_command(const_iterator itr, const mapped_type& arg, target_type // This _should_ be optimized int just two calls. switch (itr->second.m_target) { - case Command::target_generic: return itr->second.m_genericSlot (itr->second.m_variable, arg); - case Command::target_any: return itr->second.m_anySlot (itr->second.m_variable, target, arg); - case Command::target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg); - case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg); - case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg); - case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg); - case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg); + case Command::target_any: return itr->second.m_anySlot(itr->second.m_variable, target, arg); + + case Command::target_generic: + case Command::target_download: + case Command::target_peer: + case Command::target_tracker: + case Command::target_file: + case Command::target_file_itr: return itr->second.m_genericSlot(itr->second.m_variable, (target_wrapper::cleaned_type)target.second, arg); case Command::target_download_pair: return itr->second.m_downloadPairSlot(itr->second.m_variable, (core::Download*)target.second, (core::Download*)target.third, arg); diff --git a/src/rpc/command_map.h b/src/rpc/command_map.h index 7a041b67..f67bbd45 100644 --- a/src/rpc/command_map.h +++ b/src/rpc/command_map.h @@ -65,7 +65,7 @@ struct command_map_data_type { Command* m_variable; union { - Command::generic_slot m_genericSlot; + Command::cleaned_slot m_genericSlot; Command::any_slot m_anySlot; Command::download_slot m_downloadSlot; Command::file_slot m_fileSlot; @@ -100,7 +100,9 @@ public: using base_type::find; static const int flag_dont_delete = 0x1; - static const int flag_public_xmlrpc = 0x2; + static const int flag_delete_key = 0x2; + static const int flag_public_xmlrpc = 0x4; + static const int flag_modifiable = 0x8; CommandMap() {} ~CommandMap(); @@ -116,7 +118,7 @@ public: iterator itr = insert(key, variable, flags, parm, doc); itr->second.m_target = target_type_id::value; - itr->second.m_genericSlot = (Command::generic_slot)targetSlot; + itr->second.m_genericSlot = (Command::cleaned_slot)targetSlot; } void insert(key_type key, const command_map_data_type src); diff --git a/src/rpc/command_slot.cc b/src/rpc/command_slot.cc index f17fd1a9..fe2b1966 100644 --- a/src/rpc/command_slot.cc +++ b/src/rpc/command_slot.cc @@ -44,21 +44,14 @@ namespace rpc { template const torrent::Object -CommandSlot::call_unknown(Command* rawCommand, Target target, const torrent::Object& rawArgs) { +CommandSlot::call_unknown(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandSlot* command = static_cast(rawCommand); return command->m_slot(target, rawArgs); } -const torrent::Object -CommandSlot::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - return command->m_slot(rawArgs); -} - template const torrent::Object -CommandSlot::call_list(Command* rawCommand, Target target, const torrent::Object& rawArgs) { +CommandSlot::call_list(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandSlot* command = static_cast(rawCommand); switch (rawArgs.type()) { @@ -79,30 +72,8 @@ CommandSlot::call_list(Command* rawCommand, Target target, const torrent } } -const torrent::Object -CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - switch (rawArgs.type()) { - case torrent::Object::TYPE_LIST: - return command->m_slot(rawArgs); - - case torrent::Object::TYPE_VALUE: - case torrent::Object::TYPE_STRING: - case torrent::Object::TYPE_NONE: - { - torrent::Object tmpList = torrent::Object::create_list(); - tmpList.as_list().push_back(rawArgs); - - return command->m_slot(tmpList); - } - default: - throw torrent::input_error("Not a list."); - } -} - template const torrent::Object -CommandSlot::call_value_base(Command* rawCommand, Target target, const torrent::Object& rawArgs, int base, int unit) { +CommandSlot::call_value_base(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs, int base, int unit) { CommandSlot* command = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -126,33 +97,8 @@ CommandSlot::call_value_base(Command* rawCommand, Target target, const t } } -const torrent::Object -CommandSlot::call_value_base(Command* rawCommand, const torrent::Object& rawArgs, int base, int unit) { - CommandSlot* command = static_cast(rawCommand); - - const torrent::Object& arg = convert_to_single_argument(rawArgs); - - switch (arg.type()) { - case torrent::Object::TYPE_VALUE: - // Should shift this one too, so it gives the right unit. - return command->m_slot(arg); - - case torrent::Object::TYPE_STRING: - { - torrent::Object argValue = torrent::Object::create_value(); - - 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); - } - default: - throw torrent::input_error("Not a value."); - } -} - template const torrent::Object -CommandSlot::call_string(Command* rawCommand, Target target, const torrent::Object& rawArgs) { +CommandSlot::call_string(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandSlot* command = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -170,25 +116,6 @@ CommandSlot::call_string(Command* rawCommand, Target target, const torre } } -const torrent::Object -CommandSlot::call_string(Command* rawCommand, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - const torrent::Object& arg = convert_to_single_argument(rawArgs); - - switch (arg.type()) { -// case torrent::Object::TYPE_VALUE: -// break; - - case torrent::Object::TYPE_STRING: - return command->m_slot(arg); - break; - - default: - throw torrent::input_error("Not a string."); - } -} - torrent::Object set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) { if (m_firstKey == NULL) diff --git a/src/rpc/command_slot.h b/src/rpc/command_slot.h index 44de9da3..7ae1c98b 100644 --- a/src/rpc/command_slot.h +++ b/src/rpc/command_slot.h @@ -61,56 +61,29 @@ namespace rpc { template class CommandSlot : public Command { public: - typedef rak::function2 slot_type; + typedef typename target_wrapper::target_type target_type; + typedef typename target_wrapper::cleaned_type cleaned_type; + + typedef rak::function2 slot_type; CommandSlot() {} CommandSlot(typename slot_type::base_type* s) { m_slot.set(s); } void set_slot(typename slot_type::base_type* s) { m_slot.set(s); } - static const torrent::Object call_unknown(Command* rawCommand, Target target, const torrent::Object& args); + static const torrent::Object call_unknown(Command* rawCommand, cleaned_type target, const torrent::Object& args); - static const torrent::Object call_list(Command* rawCommand, Target target, const torrent::Object& args); - static const torrent::Object call_string(Command* rawCommand, Target target, const torrent::Object& args); + static const torrent::Object call_list(Command* rawCommand, cleaned_type target, const torrent::Object& args); + static const torrent::Object call_string(Command* rawCommand, cleaned_type target, const torrent::Object& args); - static const torrent::Object call_value_base(Command* rawCommand, Target target, const torrent::Object& args, int base, int unit); + static const torrent::Object call_value_base(Command* rawCommand, cleaned_type target, const torrent::Object& args, int base, int unit); - static const torrent::Object call_value(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1); } - static const torrent::Object call_value_kb(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1 << 10); } - static const torrent::Object call_value_oct(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 8, 1); } + static const torrent::Object call_value(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1); } + static const torrent::Object call_value_kb(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1 << 10); } + static const torrent::Object call_value_oct(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 8, 1); } template - static const torrent::Object call_value_tmpl(Command* rawCommand, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); } - -// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args); - -private: - slot_type m_slot; -}; - -template <> -class CommandSlot : public Command { -public: - typedef rak::function1 slot_type; - - CommandSlot() {} - CommandSlot(slot_type::base_type* s) { m_slot.set(s); } - - void set_slot(slot_type::base_type* s) { m_slot.set(s); } - - static const torrent::Object call_unknown(Command* rawCommand, const torrent::Object& args); - - static const torrent::Object call_list(Command* rawCommand, const torrent::Object& args); - static const torrent::Object call_string(Command* rawCommand, const torrent::Object& args); - - static const torrent::Object call_value_base(Command* rawCommand, const torrent::Object& args, int base, int unit); - - static const torrent::Object call_value(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, 0, 1); } - static const torrent::Object call_value_kb(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, 0, 1 << 10); } - static const torrent::Object call_value_oct(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, 8, 1); } - - template - static const torrent::Object call_value_tmpl(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); } + static const torrent::Object call_value_tmpl(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); } // static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args); diff --git a/src/rpc/command_variable.cc b/src/rpc/command_variable.cc index 9c4b0606..ad2a6e71 100644 --- a/src/rpc/command_variable.cc +++ b/src/rpc/command_variable.cc @@ -42,7 +42,7 @@ namespace rpc { const torrent::Object -CommandVariable::set_bool(Command* rawCommand, const torrent::Object& rawArgs) { +CommandVariable::set_bool(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandVariable* variable = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -73,14 +73,14 @@ CommandVariable::set_bool(Command* rawCommand, const torrent::Object& rawArgs) { } const torrent::Object -CommandVariable::get_bool(Command* rawCommand, const torrent::Object& args) { +CommandVariable::get_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args) { CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; } const torrent::Object -CommandVariable::set_value(Command* rawCommand, const torrent::Object& rawArgs) { +CommandVariable::set_value(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandVariable* variable = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -109,14 +109,14 @@ CommandVariable::set_value(Command* rawCommand, const torrent::Object& rawArgs) } const torrent::Object -CommandVariable::get_value(Command* rawCommand, const torrent::Object& args) { +CommandVariable::get_value(Command* rawCommand, cleaned_type target, const torrent::Object& args) { CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; } const torrent::Object -CommandVariable::set_string(Command* rawCommand, const torrent::Object& rawArgs) { +CommandVariable::set_string(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { CommandVariable* variable = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -142,7 +142,7 @@ CommandVariable::set_string(Command* rawCommand, const torrent::Object& rawArgs) } const torrent::Object -CommandVariable::get_string(Command* rawCommand, const torrent::Object& args) { +CommandVariable::get_string(Command* rawCommand, cleaned_type target, const torrent::Object& args) { CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; diff --git a/src/rpc/command_variable.h b/src/rpc/command_variable.h index 217d421a..bad29c84 100644 --- a/src/rpc/command_variable.h +++ b/src/rpc/command_variable.h @@ -48,19 +48,21 @@ namespace rpc { class CommandVariable : public Command { public: + typedef target_wrapper::cleaned_type cleaned_type; + CommandVariable(const torrent::Object& v = torrent::Object()) : m_variable(v) {} const torrent::Object variable() const { return m_variable; } void set_variable(const torrent::Object& var) { m_variable = var; } - static const torrent::Object set_bool(Command* rawCommand, const torrent::Object& args); - static const torrent::Object get_bool(Command* rawCommand, const torrent::Object& args); + static const torrent::Object set_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args); + static const torrent::Object get_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args); - static const torrent::Object set_value(Command* rawCommand, const torrent::Object& args); - static const torrent::Object get_value(Command* rawCommand, const torrent::Object& args); + static const torrent::Object set_value(Command* rawCommand, cleaned_type target, const torrent::Object& args); + static const torrent::Object get_value(Command* rawCommand, cleaned_type target, const torrent::Object& args); - static const torrent::Object set_string(Command* rawCommand, const torrent::Object& args); - static const torrent::Object get_string(Command* rawCommand, const torrent::Object& args); + static const torrent::Object set_string(Command* rawCommand, cleaned_type target, const torrent::Object& args); + static const torrent::Object get_string(Command* rawCommand, cleaned_type target, const torrent::Object& args); private: torrent::Object m_variable;