mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-13 12:46:18 +00:00
* Cleaned up commands.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1068 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+1
-1
@@ -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_INIT_AUTOMAKE
|
||||||
AM_CONFIG_HEADER(config.h)
|
AM_CONFIG_HEADER(config.h)
|
||||||
|
|||||||
@@ -139,6 +139,26 @@ private:
|
|||||||
std::auto_ptr<base_type> m_base;
|
std::auto_ptr<base_type> m_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Result, typename Arg2>
|
||||||
|
class function2<Result, void, Arg2> {
|
||||||
|
public:
|
||||||
|
typedef Result result_type;
|
||||||
|
typedef function_base1<Result, Arg2> base_type;
|
||||||
|
|
||||||
|
bool is_valid() const { return m_base.get() != NULL; }
|
||||||
|
|
||||||
|
void set(base_type* base) { m_base = std::auto_ptr<base_type>(base); }
|
||||||
|
base_type* release() { return m_base.release(); }
|
||||||
|
|
||||||
|
Result operator () (Arg2 arg2) { return (*m_base)(arg2); }
|
||||||
|
|
||||||
|
template <typename Discard>
|
||||||
|
Result operator () (Discard discard, Arg2 arg2) { return (*m_base)(arg2); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::auto_ptr<base_type> m_base;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Result, typename Arg1, typename Arg2, typename Arg3>
|
template <typename Result, typename Arg1, typename Arg2, typename Arg3>
|
||||||
class function3 {
|
class function3 {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -434,11 +434,11 @@ initialize_command_download() {
|
|||||||
ADD_CD_LIST("delete_link", rak::bind_ptr_fn(&apply_d_change_link, 1));
|
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_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"));
|
CMD_FUNC_SINGLE("d.start", "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"));
|
CMD_FUNC_SINGLE("d.stop", "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}"));
|
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}");
|
||||||
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}"));
|
CMD_FUNC_SINGLE("d.try_stop", "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.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("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));
|
ADD_CD_F_VOID("pause", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::pause_default));
|
||||||
|
|||||||
@@ -339,14 +339,6 @@ d_multicall(const torrent::Object& rawArgs) {
|
|||||||
return resultRaw;
|
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
|
void
|
||||||
initialize_command_events() {
|
initialize_command_events() {
|
||||||
core::DownloadList* downloadList = control->core()->download_list();
|
core::DownloadList* downloadList = control->core()->download_list();
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ initialize_commands() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
|
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) {
|
const torrent::Object& defaultObject) {
|
||||||
rpc::CommandVariable* variable = commandVariablesItr++;
|
rpc::CommandVariable* variable = commandVariablesItr++;
|
||||||
variable->set_variable(defaultObject);
|
variable->set_variable(defaultObject);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#define RTORRENT_UTILS_COMMAND_HELPERS_H
|
#define RTORRENT_UTILS_COMMAND_HELPERS_H
|
||||||
|
|
||||||
#include "rpc/command_slot.h"
|
#include "rpc/command_slot.h"
|
||||||
|
#include "rpc/command_function.h"
|
||||||
#include "rpc/parse_commands.h"
|
#include "rpc/parse_commands.h"
|
||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
@@ -78,11 +79,9 @@ void initialize_commands();
|
|||||||
|
|
||||||
void
|
void
|
||||||
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
|
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);
|
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) \
|
#define ADD_VARIABLE_BOOL(key, defaultValue) \
|
||||||
add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_bool, &rpc::CommandVariable::set_bool, (int64_t)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) \
|
#define CMD_D_VOID(key, slot) \
|
||||||
CMD_D_SLOT(key, call_unknown, rpc::object_fn(slot), "i:", "")
|
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
|
#endif
|
||||||
|
|||||||
@@ -393,6 +393,9 @@ DownloadList::pause(Download* download, int flags) {
|
|||||||
download->download()->stop(flags);
|
download->download()->stop(flags);
|
||||||
torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
|
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));
|
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));
|
rpc::call_command("d.set_state_changed", cachedTime.seconds(), rpc::make_target(download));
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ noinst_LIBRARIES = libsub_rpc.a
|
|||||||
|
|
||||||
libsub_rpc_a_SOURCES = \
|
libsub_rpc_a_SOURCES = \
|
||||||
command.h \
|
command.h \
|
||||||
|
command_function.cc \
|
||||||
|
command_function.h \
|
||||||
command_map.cc \
|
command_map.cc \
|
||||||
command_map.h \
|
command_map.h \
|
||||||
command_scheduler.cc \
|
command_scheduler.cc \
|
||||||
|
|||||||
+17
-1
@@ -52,6 +52,20 @@ namespace torrent {
|
|||||||
|
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
|
template <typename Target>
|
||||||
|
struct target_wrapper {
|
||||||
|
typedef Target target_type;
|
||||||
|
typedef Target cleaned_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct target_wrapper<void> {
|
||||||
|
struct no_type {};
|
||||||
|
|
||||||
|
typedef void target_type;
|
||||||
|
typedef no_type* cleaned_type;
|
||||||
|
};
|
||||||
|
|
||||||
// Since c++0x isn't out yet...
|
// Since c++0x isn't out yet...
|
||||||
template <typename T1, typename T2, typename T3>
|
template <typename T1, typename T2, typename T3>
|
||||||
struct rt_triple : private std::pair<T1, T2> {
|
struct rt_triple : private std::pair<T1, T2> {
|
||||||
@@ -95,6 +109,7 @@ public:
|
|||||||
typedef torrent::Object::key_type key_type;
|
typedef torrent::Object::key_type key_type;
|
||||||
|
|
||||||
typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);
|
typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);
|
||||||
|
typedef const torrent::Object (*cleaned_slot) (Command*, target_wrapper<void>::cleaned_type, const torrent::Object&);
|
||||||
typedef const torrent::Object (*any_slot) (Command*, target_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 (*download_slot) (Command*, core::Download*, const torrent::Object&);
|
||||||
typedef const torrent::Object (*file_slot) (Command*, torrent::File*, 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.
|
// Nothing here, so we cause an error.
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; };
|
//template <> struct target_type_id<Command::generic_slot> { static const int value = Command::target_generic; };
|
||||||
|
template <> struct target_type_id<Command::cleaned_slot> { static const int value = Command::target_generic; };
|
||||||
template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; };
|
template <> struct target_type_id<Command::any_slot> { static const int value = Command::target_any; };
|
||||||
template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; };
|
template <> struct target_type_id<Command::download_slot> { static const int value = Command::target_download; };
|
||||||
template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; };
|
template <> struct target_type_id<Command::peer_slot> { static const int value = Command::target_peer; };
|
||||||
|
|||||||
@@ -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 <jaris@ifi.uio.no>
|
||||||
|
//
|
||||||
|
// 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<CommandFunction*>(rawCommand);
|
||||||
|
|
||||||
|
parse_command_multiple(target, command->m_command.c_str(), command->m_command.c_str() + command->m_command.size());
|
||||||
|
|
||||||
|
return torrent::Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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 <jaris@ifi.uio.no>
|
||||||
|
//
|
||||||
|
// Skomakerveien 33
|
||||||
|
// 3185 Skoppum, NORWAY
|
||||||
|
|
||||||
|
#ifndef RTORRENT_RPC_COMMAND_FUNCTION_H
|
||||||
|
#define RTORRENT_RPC_COMMAND_FUNCTION_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <limits>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <torrent/object.h>
|
||||||
|
|
||||||
|
#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
|
||||||
+23
-15
@@ -46,9 +46,13 @@
|
|||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
CommandMap::~CommandMap() {
|
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))
|
if (!(itr->second.m_flags & flag_dont_delete))
|
||||||
delete itr->second.m_variable;
|
delete itr->second.m_variable;
|
||||||
|
|
||||||
|
if (itr->second.m_flags & flag_delete_key)
|
||||||
|
; // Remove from map and then delte the key.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandMap::iterator
|
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.
|
// This _should_ be optimized int just two calls.
|
||||||
switch (itr->second.m_target) {
|
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_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_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<void>::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);
|
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.");
|
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.
|
// This _should_ be optimized int just two calls.
|
||||||
switch (itr->second.m_target) {
|
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_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_generic:
|
||||||
case Command::target_peer: return itr->second.m_peerSlot (itr->second.m_variable, (torrent::Peer*)target.second, arg);
|
case Command::target_download:
|
||||||
case Command::target_tracker: return itr->second.m_trackerSlot (itr->second.m_variable, (torrent::Tracker*)target.second, arg);
|
case Command::target_peer:
|
||||||
case Command::target_file: return itr->second.m_fileSlot (itr->second.m_variable, (torrent::File*)target.second, arg);
|
case Command::target_tracker:
|
||||||
case Command::target_file_itr: return itr->second.m_fileItrSlot (itr->second.m_variable, (torrent::FileListIterator*)target.second, arg);
|
case Command::target_file:
|
||||||
|
case Command::target_file_itr: return itr->second.m_genericSlot(itr->second.m_variable, (target_wrapper<void>::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);
|
case Command::target_download_pair: return itr->second.m_downloadPairSlot(itr->second.m_variable, (core::Download*)target.second, (core::Download*)target.third, arg);
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ struct command_map_data_type {
|
|||||||
Command* m_variable;
|
Command* m_variable;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
Command::generic_slot m_genericSlot;
|
Command::cleaned_slot m_genericSlot;
|
||||||
Command::any_slot m_anySlot;
|
Command::any_slot m_anySlot;
|
||||||
Command::download_slot m_downloadSlot;
|
Command::download_slot m_downloadSlot;
|
||||||
Command::file_slot m_fileSlot;
|
Command::file_slot m_fileSlot;
|
||||||
@@ -100,7 +100,9 @@ public:
|
|||||||
using base_type::find;
|
using base_type::find;
|
||||||
|
|
||||||
static const int flag_dont_delete = 0x1;
|
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() {}
|
||||||
~CommandMap();
|
~CommandMap();
|
||||||
@@ -116,7 +118,7 @@ public:
|
|||||||
iterator itr = insert(key, variable, flags, parm, doc);
|
iterator itr = insert(key, variable, flags, parm, doc);
|
||||||
|
|
||||||
itr->second.m_target = target_type_id<T>::value;
|
itr->second.m_target = target_type_id<T>::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);
|
void insert(key_type key, const command_map_data_type src);
|
||||||
|
|||||||
+4
-77
@@ -44,21 +44,14 @@
|
|||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
template <typename Target> const torrent::Object
|
template <typename Target> const torrent::Object
|
||||||
CommandSlot<Target>::call_unknown(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
|
CommandSlot<Target>::call_unknown(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) {
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||||
|
|
||||||
return command->m_slot(target, rawArgs);
|
return command->m_slot(target, rawArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
|
||||||
CommandSlot<void>::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) {
|
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
|
||||||
|
|
||||||
return command->m_slot(rawArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Target> const torrent::Object
|
template <typename Target> const torrent::Object
|
||||||
CommandSlot<Target>::call_list(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
|
CommandSlot<Target>::call_list(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) {
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||||
|
|
||||||
switch (rawArgs.type()) {
|
switch (rawArgs.type()) {
|
||||||
@@ -79,30 +72,8 @@ CommandSlot<Target>::call_list(Command* rawCommand, Target target, const torrent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
|
||||||
CommandSlot<void>::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
|
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(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 <typename Target> const torrent::Object
|
template <typename Target> const torrent::Object
|
||||||
CommandSlot<Target>::call_value_base(Command* rawCommand, Target target, const torrent::Object& rawArgs, int base, int unit) {
|
CommandSlot<Target>::call_value_base(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs, int base, int unit) {
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||||
|
|
||||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||||
@@ -126,33 +97,8 @@ CommandSlot<Target>::call_value_base(Command* rawCommand, Target target, const t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
|
||||||
CommandSlot<void>::call_value_base(Command* rawCommand, const torrent::Object& rawArgs, int base, int unit) {
|
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(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 <typename Target> const torrent::Object
|
template <typename Target> const torrent::Object
|
||||||
CommandSlot<Target>::call_string(Command* rawCommand, Target target, const torrent::Object& rawArgs) {
|
CommandSlot<Target>::call_string(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) {
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||||
|
|
||||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||||
@@ -170,25 +116,6 @@ CommandSlot<Target>::call_string(Command* rawCommand, Target target, const torre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
|
||||||
CommandSlot<void>::call_string(Command* rawCommand, const torrent::Object& rawArgs) {
|
|
||||||
CommandSlot* command = static_cast<CommandSlot*>(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
|
torrent::Object
|
||||||
set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
|
set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
|
||||||
if (m_firstKey == NULL)
|
if (m_firstKey == NULL)
|
||||||
|
|||||||
+12
-39
@@ -61,56 +61,29 @@ namespace rpc {
|
|||||||
template <typename Target>
|
template <typename Target>
|
||||||
class CommandSlot : public Command {
|
class CommandSlot : public Command {
|
||||||
public:
|
public:
|
||||||
typedef rak::function2<torrent::Object, Target, const torrent::Object&> slot_type;
|
typedef typename target_wrapper<Target>::target_type target_type;
|
||||||
|
typedef typename target_wrapper<Target>::cleaned_type cleaned_type;
|
||||||
|
|
||||||
|
typedef rak::function2<torrent::Object, target_type, const torrent::Object&> slot_type;
|
||||||
|
|
||||||
CommandSlot() {}
|
CommandSlot() {}
|
||||||
CommandSlot(typename slot_type::base_type* s) { m_slot.set(s); }
|
CommandSlot(typename slot_type::base_type* s) { m_slot.set(s); }
|
||||||
|
|
||||||
void set_slot(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_list(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||||
static const torrent::Object call_string(Command* rawCommand, Target 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(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, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1 << 10); }
|
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, Target target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 8, 1); }
|
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 <int base, int unit>
|
template <int base, int unit>
|
||||||
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 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);
|
|
||||||
|
|
||||||
private:
|
|
||||||
slot_type m_slot;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class CommandSlot<void> : public Command {
|
|
||||||
public:
|
|
||||||
typedef rak::function1<torrent::Object, const torrent::Object&> 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 <int base, int unit>
|
|
||||||
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& get_list(Command* rawCommand, const torrent::Object& args);
|
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
const torrent::Object
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
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
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
return variable->m_variable;
|
return variable->m_variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
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
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
return variable->m_variable;
|
return variable->m_variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
const torrent::Object
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
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
|
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<CommandVariable*>(rawCommand);
|
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||||
|
|
||||||
return variable->m_variable;
|
return variable->m_variable;
|
||||||
|
|||||||
@@ -48,19 +48,21 @@ namespace rpc {
|
|||||||
|
|
||||||
class CommandVariable : public Command {
|
class CommandVariable : public Command {
|
||||||
public:
|
public:
|
||||||
|
typedef target_wrapper<void>::cleaned_type cleaned_type;
|
||||||
|
|
||||||
CommandVariable(const torrent::Object& v = torrent::Object()) : m_variable(v) {}
|
CommandVariable(const torrent::Object& v = torrent::Object()) : m_variable(v) {}
|
||||||
|
|
||||||
const torrent::Object variable() const { return m_variable; }
|
const torrent::Object variable() const { return m_variable; }
|
||||||
void set_variable(const torrent::Object& var) { m_variable = var; }
|
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 set_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||||
static const torrent::Object get_bool(Command* rawCommand, 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 set_value(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||||
static const torrent::Object get_value(Command* rawCommand, 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 set_string(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||||
static const torrent::Object get_string(Command* rawCommand, const torrent::Object& args);
|
static const torrent::Object get_string(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
torrent::Object m_variable;
|
torrent::Object m_variable;
|
||||||
|
|||||||
Reference in New Issue
Block a user