mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 22:22:31 +00:00
* Re-enabled the umask option.
* Moved around command related classes. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@911 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -46,9 +46,9 @@
|
||||
|
||||
#include "core/download.h"
|
||||
#include "core/manager.h"
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "utils/command_download_slot.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "rpc/command_download_slot.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "control.h"
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
#include "core/download.h"
|
||||
#include "core/download_list.h"
|
||||
#include "core/manager.h"
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "utils/command_download_slot.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "rpc/command_download_slot.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "control.h"
|
||||
|
||||
+14
-9
@@ -91,19 +91,24 @@ add_variable("get_" key, "set_" key, key, &utils::CommandVariable::get_string, &
|
||||
variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::VariableMap::flag_dont_delete, NULL, NULL);
|
||||
|
||||
#define ADD_COMMAND_VALUE_TRI(key, set, get) \
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value, utils::object_value_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "")
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value, utils::object_value_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "")
|
||||
|
||||
#define ADD_COMMAND_VALUE_TRI_KB(key, set, get) \
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value_kb, utils::object_value_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "")
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value_kb, utils::object_value_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "")
|
||||
|
||||
#define ADD_COMMAND_VALUE_TRI_OCT(key, set, get) \
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, utils::object_value_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "i:", "")
|
||||
|
||||
#define ADD_COMMAND_STRING_TRI(key, set, get) \
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_string, utils::object_string_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_string, "i:s", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "s:", "")
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_string, utils::object_string_fn(set)) \
|
||||
ADD_COMMAND_COPY("set_" key, call_string, "i:s", "") \
|
||||
ADD_COMMAND_SLOT("get_" key, call_unknown, utils::object_void_fn(get), "s:", "")
|
||||
|
||||
#define ADD_COMMAND_VOID(key, slot) \
|
||||
ADD_COMMAND_SLOT(key, call_unknown, utils::object_void_fn(slot), "i:", "")
|
||||
|
||||
+14
-3
@@ -42,9 +42,10 @@
|
||||
//#include <torrent/connection_manager.h>
|
||||
|
||||
#include "core/download_list.h"
|
||||
#include "core/download_store.h"
|
||||
#include "core/manager.h"
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
#include "globals.h"
|
||||
@@ -55,9 +56,11 @@ typedef torrent::ChunkManager CM_t;
|
||||
|
||||
void
|
||||
initialize_command_local() {
|
||||
utils::VariableMap* variables = control->variable();
|
||||
utils::VariableMap* variables = control->variable();
|
||||
// core::DownloadList* downloadList = control->core()->download_list();
|
||||
torrent::ChunkManager* chunkManager = torrent::chunk_manager();
|
||||
core::DownloadList* dList = control->core()->download_list();
|
||||
core::DownloadStore* dStore = control->core()->download_store();
|
||||
|
||||
ADD_VARIABLE_VALUE("max_file_size", -1);
|
||||
ADD_VARIABLE_VALUE("split_file_size", -1);
|
||||
@@ -71,4 +74,12 @@ initialize_command_local() {
|
||||
ADD_COMMAND_VALUE_TRI("preload_type", rak::make_mem_fun(chunkManager, &CM_t::set_preload_type), rak::make_mem_fun(chunkManager, &CM_t::preload_type));
|
||||
ADD_COMMAND_VALUE_TRI("preload_min_size", rak::make_mem_fun(chunkManager, &CM_t::set_preload_min_size), rak::make_mem_fun(chunkManager, &CM_t::preload_min_size));
|
||||
ADD_COMMAND_VALUE_TRI_KB("preload_required_rate", rak::make_mem_fun(chunkManager, &CM_t::set_preload_required_rate), rak::make_mem_fun(chunkManager, &CM_t::preload_required_rate));
|
||||
|
||||
ADD_VARIABLE_STRING("directory", "./");
|
||||
|
||||
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));
|
||||
|
||||
ADD_COMMAND_VALUE_TRI_OCT("umask", rak::make_mem_fun(control, &Control::set_umask), rak::make_mem_fun(control, &Control::umask));
|
||||
ADD_COMMAND_STRING_TRI("working_directory", rak::make_mem_fun(control, &Control::set_working_directory), rak::make_mem_fun(control, &Control::working_directory));
|
||||
}
|
||||
|
||||
+3
-15
@@ -46,15 +46,13 @@
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "core/download.h"
|
||||
#include "core/download_list.h"
|
||||
#include "core/download_store.h"
|
||||
#include "core/manager.h"
|
||||
#include "rpc/fast_cgi.h"
|
||||
#include "rpc/scgi.h"
|
||||
#include "rpc/xmlrpc.h"
|
||||
#include "ui/root.h"
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "utils/parse.h"
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
@@ -96,7 +94,7 @@ apply_encryption(const torrent::Object& rawArgs) {
|
||||
|
||||
torrent::Object
|
||||
apply_tos(const torrent::Object& rawArg) {
|
||||
utils::Variable::value_type value;
|
||||
utils::Command::value_type value;
|
||||
torrent::ConnectionManager* cm = torrent::connection_manager();
|
||||
|
||||
const std::string& arg = rawArg.as_string();
|
||||
@@ -244,8 +242,6 @@ initialize_command_network() {
|
||||
// core::DownloadList* downloadList = control->core()->download_list();
|
||||
torrent::ConnectionManager* cm = torrent::connection_manager();
|
||||
core::CurlStack* httpStack = control->core()->get_poll_manager()->get_http_stack();
|
||||
core::DownloadList* dList = control->core()->download_list();
|
||||
core::DownloadStore* dStore = control->core()->download_store();
|
||||
|
||||
ADD_VARIABLE_BOOL("use_udp_trackers", true);
|
||||
|
||||
@@ -307,12 +303,4 @@ initialize_command_network() {
|
||||
// Not really network stuff:
|
||||
ADD_VARIABLE_BOOL("handshake_log", false);
|
||||
ADD_VARIABLE_STRING("tracker_dump", "");
|
||||
|
||||
ADD_VARIABLE_STRING("directory", "./");
|
||||
|
||||
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));
|
||||
|
||||
// ADD_VARIABLE_VALUE_TRI_OCT("umask", rak::mem_fn(control, &Control::set_umask), rak::mem_fn(control, &Control::umask));
|
||||
ADD_COMMAND_STRING_TRI("working_directory", rak::make_mem_fun(control, &Control::set_working_directory), rak::make_mem_fun(control, &Control::working_directory));
|
||||
}
|
||||
|
||||
+2
-2
@@ -43,8 +43,8 @@
|
||||
// #include "core/download_list.h"
|
||||
#include "core/manager.h"
|
||||
#include "core/view_manager.h"
|
||||
#include "utils/command_slot.h"
|
||||
#include "utils/command_variable.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
noinst_LIBRARIES = libsub_rpc.a
|
||||
|
||||
libsub_rpc_a_SOURCES = \
|
||||
command.h \
|
||||
command_slot.cc \
|
||||
command_slot.h \
|
||||
command_variable.cc \
|
||||
command_variable.h \
|
||||
command_download_slot.cc \
|
||||
command_download_slot.h \
|
||||
fast_cgi.cc \
|
||||
fast_cgi.h \
|
||||
scgi.cc \
|
||||
|
||||
@@ -39,13 +39,9 @@
|
||||
|
||||
#include <torrent/object.h>
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
|
||||
class Variable {
|
||||
class Command {
|
||||
public:
|
||||
typedef torrent::Object::value_type value_type;
|
||||
typedef torrent::Object::string_type string_type;
|
||||
@@ -53,12 +49,12 @@ public:
|
||||
typedef torrent::Object::map_type map_type;
|
||||
typedef torrent::Object::key_type key_type;
|
||||
|
||||
Variable() {}
|
||||
virtual ~Variable() {}
|
||||
Command() {}
|
||||
virtual ~Command() {}
|
||||
|
||||
protected:
|
||||
Variable(const Variable&);
|
||||
void operator = (const Variable&);
|
||||
Command(const Command&);
|
||||
void operator = (const Command&);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -44,15 +44,15 @@
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_unknown(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
CommandDownloadSlot::call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
|
||||
|
||||
return command->m_slot(download, rawArgs);
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_list(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
CommandDownloadSlot::call_list(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
|
||||
|
||||
switch (rawArgs.type()) {
|
||||
case torrent::Object::TYPE_LIST:
|
||||
@@ -72,8 +72,8 @@ CommandDownloadSlot::call_list(Variable* rawVariable, core::Download* download,
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_value_base(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
CommandDownloadSlot::call_value_base(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -97,8 +97,8 @@ CommandDownloadSlot::call_value_base(Variable* rawVariable, core::Download* down
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_string(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
CommandDownloadSlot::call_string(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include <torrent/object.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
#include "variable.h"
|
||||
#include "rpc/command.h"
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
@@ -51,7 +51,7 @@ namespace core {
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandDownloadSlot : public Variable {
|
||||
class CommandDownloadSlot : public Command {
|
||||
public:
|
||||
typedef rak::function2<torrent::Object, core::Download*, const torrent::Object&> slot_type;
|
||||
|
||||
@@ -63,20 +63,20 @@ public:
|
||||
|
||||
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
|
||||
|
||||
static const torrent::Object call_unknown(Variable* rawVariable, core::Download* download, const torrent::Object& args);
|
||||
static const torrent::Object call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_list(Variable* rawVariable, core::Download* download, const torrent::Object& args);
|
||||
static const torrent::Object call_string(Variable* rawVariable, core::Download* download, const torrent::Object& args);
|
||||
static const torrent::Object call_list(Command* rawCommand, core::Download* download, const torrent::Object& args);
|
||||
static const torrent::Object call_string(Command* rawCommand, core::Download* download, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_value_base(Variable* rawVariable, core::Download* download, const torrent::Object& args, int base, int unit);
|
||||
static const torrent::Object call_value_base(Command* rawCommand, core::Download* download, const torrent::Object& args, int base, int unit);
|
||||
|
||||
static const torrent::Object call_value(Variable* rawVariable, core::Download* download, const torrent::Object& args) { return call_value_base(rawVariable, download, args, 0, 1); }
|
||||
static const torrent::Object call_value_kb(Variable* rawVariable, core::Download* download, const torrent::Object& args) { return call_value_base(rawVariable, download, args, 0, 1 << 10); }
|
||||
static const torrent::Object call_value(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, 0, 1); }
|
||||
static const torrent::Object call_value_kb(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, 0, 1 << 10); }
|
||||
|
||||
template <int base, int unit>
|
||||
static const torrent::Object call_value(Variable* rawVariable, core::Download* download, const torrent::Object& args) { return call_value_base(rawVariable, download, args, base, unit); }
|
||||
static const torrent::Object call_value(Command* rawCommand, core::Download* download, const torrent::Object& args) { return call_value_base(rawCommand, download, args, base, unit); }
|
||||
|
||||
// static const torrent::Object& get_list(Variable* rawVariable, const torrent::Object& args);
|
||||
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
slot_type m_slot;
|
||||
@@ -43,15 +43,15 @@
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_unknown(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
CommandSlot::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||
|
||||
return command->m_slot(rawArgs);
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||
|
||||
switch (rawArgs.type()) {
|
||||
case torrent::Object::TYPE_LIST:
|
||||
@@ -71,8 +71,8 @@ CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
CommandSlot::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);
|
||||
|
||||
@@ -96,8 +96,8 @@ CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawAr
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
CommandSlot::call_string(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -115,8 +115,8 @@ CommandSlot::call_string(Variable* rawVariable, const torrent::Object& rawArgs)
|
||||
}
|
||||
|
||||
// const torrent::Object&
|
||||
// CommandSlot::get_generic(Variable* rawVariable, const torrent::Object& args) {
|
||||
// CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
// CommandSlot::get_generic(Command* rawCommand, const torrent::Object& args) {
|
||||
// CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
// return variable->m_variable;
|
||||
// }
|
||||
@@ -43,11 +43,11 @@
|
||||
#include <torrent/object.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
#include "variable.h"
|
||||
#include "rpc/command.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandSlot : public Variable {
|
||||
class CommandSlot : public Command {
|
||||
public:
|
||||
typedef rak::function1<torrent::Object, const torrent::Object&> slot_type;
|
||||
|
||||
@@ -64,20 +64,21 @@ public:
|
||||
|
||||
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
|
||||
|
||||
static const torrent::Object call_unknown(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object call_unknown(Command* rawCommand, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_list(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object call_string(Variable* rawVariable, 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(Variable* rawVariable, const torrent::Object& args, int base, int unit);
|
||||
static const torrent::Object call_value_base(Command* rawCommand, const torrent::Object& args, int base, int unit);
|
||||
|
||||
static const torrent::Object call_value(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, 0, 1); }
|
||||
static const torrent::Object call_value_kb(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, 0, 1 << 10); }
|
||||
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(Variable* rawVariable, const torrent::Object& args) { return call_value_base(rawVariable, args, base, unit); }
|
||||
static const torrent::Object call_value(Command* rawCommand, const torrent::Object& args) { return call_value_base(rawCommand, args, base, unit); }
|
||||
|
||||
// static const torrent::Object& get_list(Variable* rawVariable, const torrent::Object& args);
|
||||
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
slot_type m_slot;
|
||||
@@ -165,9 +166,10 @@ private:
|
||||
|
||||
template <typename Return> object_void_fn_t<Return (*)(void), Return>* object_fn(Return (*func)(void)) { return new object_void_fn_t<Return (*)(void), Return>(func); }
|
||||
|
||||
template <typename Func> object_void_fn_t<Func>* object_void_fn(Func func) { return new object_void_fn_t<Func>(func); }
|
||||
template <typename Func> object_value_fn1_t<Func>* object_value_fn(Func func) { return new object_value_fn1_t<Func>(func); }
|
||||
template <typename Func> object_string_fn1_t<Func>* object_string_fn(Func func) { return new object_string_fn1_t<Func>(func); }
|
||||
template <typename Func> object_void_fn_t<Func>* object_void_fn(Func func) { return new object_void_fn_t<Func>(func); }
|
||||
//template <typename Func> object_void_fn_t<Func>* object_void_value_fn(Func func) { return new object_void_fn_t<Func, int64_t>(func); }
|
||||
template <typename Func> object_value_fn1_t<Func>* object_value_fn(Func func) { return new object_value_fn1_t<Func>(func); }
|
||||
template <typename Func> object_string_fn1_t<Func>* object_string_fn(Func func) { return new object_string_fn1_t<Func>(func); }
|
||||
|
||||
}
|
||||
|
||||
@@ -36,14 +36,15 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "command_variable.h"
|
||||
#include "parse.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::set_bool(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::set_bool(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -53,7 +54,7 @@ CommandVariable::set_bool(Variable* rawVariable, const torrent::Object& rawArgs)
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
// Move the checks into some is_true, is_false think in Variable.
|
||||
// Move the checks into some is_true, is_false think in Command.
|
||||
if (arg.as_string() == "yes" || arg.as_string() == "true")
|
||||
variable->m_variable = (int64_t)1;
|
||||
|
||||
@@ -73,15 +74,15 @@ CommandVariable::set_bool(Variable* rawVariable, const torrent::Object& rawArgs)
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::get_bool(Variable* rawVariable, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::get_bool(Command* rawCommand, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::set_value(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -102,22 +103,22 @@ CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("VariableValue unsupported type restriction.");
|
||||
throw torrent::input_error("CommandValue unsupported type restriction.");
|
||||
}
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::get_value(Variable* rawVariable, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::get_value(Command* rawCommand, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::set_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::set_string(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
@@ -142,8 +143,8 @@ CommandVariable::set_string(Variable* rawVariable, const torrent::Object& rawArg
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::get_string(Variable* rawVariable, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
CommandVariable::get_string(Command* rawCommand, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawCommand);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
@@ -42,25 +42,25 @@
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "variable.h"
|
||||
#include "rpc/command.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandVariable : public Variable {
|
||||
class CommandVariable : public Command {
|
||||
public:
|
||||
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(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object get_bool(Variable* rawVariable, const torrent::Object& args);
|
||||
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_value(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object get_value(Variable* rawVariable, 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_string(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object get_string(Variable* rawVariable, 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);
|
||||
|
||||
private:
|
||||
torrent::Object m_variable;
|
||||
@@ -1,12 +1,6 @@
|
||||
noinst_LIBRARIES = libsub_utils.a
|
||||
|
||||
libsub_utils_a_SOURCES = \
|
||||
command_slot.cc \
|
||||
command_slot.h \
|
||||
command_variable.cc \
|
||||
command_variable.h \
|
||||
command_download_slot.cc \
|
||||
command_download_slot.h \
|
||||
directory.cc \
|
||||
directory.h \
|
||||
list_focus.h \
|
||||
@@ -16,8 +10,6 @@ libsub_utils_a_SOURCES = \
|
||||
parse.h \
|
||||
socket_fd.cc \
|
||||
socket_fd.h \
|
||||
variable.cc \
|
||||
variable.h \
|
||||
variable_map.cc \
|
||||
variable_map.h
|
||||
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ parse_whole_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
const char*
|
||||
parse_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
if (unit <= 0)
|
||||
throw torrent::input_error("Variable::string_to_value_unit(...) received unit <= 0.");
|
||||
throw torrent::input_error("Command::string_to_value_unit(...) received unit <= 0.");
|
||||
|
||||
char* last;
|
||||
*value = strtoll(src, &last, base);
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2006, 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 <torrent/exceptions.h>
|
||||
|
||||
#include "variable.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
// const char*
|
||||
// Variable::string_to_value_unit(const char* pos, value_type* value, int base, int unit) {
|
||||
// if (unit <= 0)
|
||||
// throw torrent::input_error("Variable::string_to_value_unit(...) received unit <= 0.");
|
||||
|
||||
// char* last;
|
||||
// *value = strtoll(pos, &last, base);
|
||||
|
||||
// if (last == pos) {
|
||||
// if (strcasecmp(pos, "no") == 0) { *value = 0; return pos + strlen("no"); }
|
||||
// if (strcasecmp(pos, "yes") == 0) { *value = 1; return pos + strlen("yes"); }
|
||||
// if (strcasecmp(pos, "true") == 0) { *value = 1; return pos + strlen("true"); }
|
||||
// if (strcasecmp(pos, "false") == 0) { *value = 0; return pos + strlen("false"); }
|
||||
|
||||
// throw torrent::input_error("Could not convert string to value.");
|
||||
// }
|
||||
|
||||
// switch (*last) {
|
||||
// case 'b':
|
||||
// case 'B':
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
// case 'k':
|
||||
// case 'K':
|
||||
// *value = *value << 10;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
// case 'm':
|
||||
// case 'M':
|
||||
// *value = *value << 20;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
// case 'g':
|
||||
// case 'G':
|
||||
// *value = *value << 30;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
// case ' ':
|
||||
// case '\0':
|
||||
// *value = *value * unit;
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// throw torrent::input_error("Could not parse value.");
|
||||
// }
|
||||
|
||||
// return last;
|
||||
// }
|
||||
|
||||
// bool
|
||||
// Variable::string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit) {
|
||||
// try {
|
||||
// string_to_value_unit(pos, value, base, unit);
|
||||
|
||||
// return true;
|
||||
// } catch (const torrent::input_error& e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -46,13 +46,13 @@
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "parse.h"
|
||||
#include "variable.h"
|
||||
#include "rpc/command.h"
|
||||
#include "variable_map.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct variable_map_get_ptr : std::unary_function<VariableMap::value_type&, Variable*> {
|
||||
Variable* operator () (VariableMap::value_type& value) { return value.second.m_variable; }
|
||||
struct variable_map_get_ptr : std::unary_function<VariableMap::value_type&, Command*> {
|
||||
Command* operator () (VariableMap::value_type& value) { return value.second.m_variable; }
|
||||
};
|
||||
|
||||
VariableMap::~VariableMap() {
|
||||
@@ -62,7 +62,7 @@ VariableMap::~VariableMap() {
|
||||
}
|
||||
|
||||
void
|
||||
VariableMap::insert(key_type key, Variable* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
VariableMap::insert(key_type key, Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc) {
|
||||
iterator itr = base_type::find(key);
|
||||
|
||||
@@ -215,10 +215,10 @@ VariableMap::call_command(key_type key, const mapped_type& arg) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist.");
|
||||
throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist.");
|
||||
|
||||
if (itr->second.m_genericSlot == NULL)
|
||||
throw torrent::input_error("Variable does not have a generic slot.");
|
||||
throw torrent::input_error("Command does not have a generic slot.");
|
||||
|
||||
return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
}
|
||||
@@ -228,11 +228,11 @@ VariableMap::call_command_d(key_type key, core::Download* download, const mapped
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist.");
|
||||
throw torrent::input_error("Command \"" + std::string(key) + "\" does not exist.");
|
||||
|
||||
if (itr->second.m_downloadSlot == NULL) {
|
||||
if (itr->second.m_genericSlot == NULL)
|
||||
throw torrent::input_error("Variable does not have a generic slot.");
|
||||
throw torrent::input_error("Command does not have a generic slot.");
|
||||
|
||||
return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
}
|
||||
|
||||
@@ -57,20 +57,20 @@ struct variable_map_comp : public std::binary_function<const char*, const char*,
|
||||
bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; }
|
||||
};
|
||||
|
||||
class Variable;
|
||||
class Command;
|
||||
|
||||
struct variable_map_data_type {
|
||||
// Some commands will need to share data, like get/set a variable. So
|
||||
// instead of using a single virtual member function, each command
|
||||
// will register a member function pointer to be used instead.
|
||||
typedef const torrent::Object (*generic_slot)(Variable*, const torrent::Object&);
|
||||
typedef const torrent::Object (*download_slot)(Variable*, core::Download*, const torrent::Object&);
|
||||
typedef const torrent::Object (*generic_slot)(Command*, const torrent::Object&);
|
||||
typedef const torrent::Object (*download_slot)(Command*, core::Download*, const torrent::Object&);
|
||||
|
||||
variable_map_data_type(Variable* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
variable_map_data_type(Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc) :
|
||||
m_variable(variable), m_genericSlot(genericSlot), m_downloadSlot(downloadSlot), m_flags(flags), m_parm(parm), m_doc(doc) {}
|
||||
|
||||
Variable* m_variable;
|
||||
Command* m_variable;
|
||||
generic_slot m_genericSlot;
|
||||
download_slot m_downloadSlot;
|
||||
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
// Allow NULL slot as a temporary compatibility hack.
|
||||
|
||||
void insert(key_type key, Variable* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
void insert(key_type key, Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc);
|
||||
|
||||
void insert(key_type key, const variable_map_data_type src);
|
||||
|
||||
Reference in New Issue
Block a user