diff --git a/src/command_download.cc b/src/command_download.cc index f8bcbe2b..8c67d1a1 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -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" diff --git a/src/command_events.cc b/src/command_events.cc index df1e378d..7160b697 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -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" diff --git a/src/command_helpers.cc b/src/command_helpers.cc index ac134066..dd7a22c3 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -38,9 +38,9 @@ #include -#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" diff --git a/src/command_helpers.h b/src/command_helpers.h index 3fd17e95..0670e5ea 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -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:", "") diff --git a/src/command_local.cc b/src/command_local.cc index 52965ce0..12c26bdb 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -42,9 +42,10 @@ //#include #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)); } diff --git a/src/command_network.cc b/src/command_network.cc index acacc681..00035e25 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -46,15 +46,13 @@ #include #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)); } diff --git a/src/command_ui.cc b/src/command_ui.cc index 1c109a61..4bdab1c7 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -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" diff --git a/src/rpc/Makefile.am b/src/rpc/Makefile.am index b7219749..7ea589a6 100644 --- a/src/rpc/Makefile.am +++ b/src/rpc/Makefile.am @@ -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 \ diff --git a/src/utils/variable.h b/src/rpc/command.h similarity index 92% rename from src/utils/variable.h rename to src/rpc/command.h index 417bf633..387b30de 100644 --- a/src/utils/variable.h +++ b/src/rpc/command.h @@ -39,13 +39,9 @@ #include -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&); }; } diff --git a/src/utils/command_download_slot.cc b/src/rpc/command_download_slot.cc similarity index 89% rename from src/utils/command_download_slot.cc rename to src/rpc/command_download_slot.cc index 696571a1..0c68b4f4 100644 --- a/src/utils/command_download_slot.cc +++ b/src/rpc/command_download_slot.cc @@ -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(rawVariable); +CommandDownloadSlot::call_unknown(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) { + CommandDownloadSlot* command = static_cast(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(rawVariable); +CommandDownloadSlot::call_list(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) { + CommandDownloadSlot* command = static_cast(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(rawVariable); +CommandDownloadSlot::call_value_base(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs, int base, int unit) { + CommandDownloadSlot* command = static_cast(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(rawVariable); +CommandDownloadSlot::call_string(Command* rawCommand, core::Download* download, const torrent::Object& rawArgs) { + CommandDownloadSlot* command = static_cast(rawCommand); const torrent::Object& arg = convert_to_single_argument(rawArgs); diff --git a/src/utils/command_download_slot.h b/src/rpc/command_download_slot.h similarity index 84% rename from src/utils/command_download_slot.h rename to src/rpc/command_download_slot.h index 4eabe65f..886c1d98 100644 --- a/src/utils/command_download_slot.h +++ b/src/rpc/command_download_slot.h @@ -43,7 +43,7 @@ #include #include -#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 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 - 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; diff --git a/src/utils/command_slot.cc b/src/rpc/command_slot.cc similarity index 82% rename from src/utils/command_slot.cc rename to src/rpc/command_slot.cc index 77f0158f..fe06b7b9 100644 --- a/src/utils/command_slot.cc +++ b/src/rpc/command_slot.cc @@ -43,15 +43,15 @@ namespace utils { const torrent::Object -CommandSlot::call_unknown(Variable* rawVariable, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawVariable); +CommandSlot::call_unknown(Command* rawCommand, const torrent::Object& rawArgs) { + CommandSlot* command = static_cast(rawCommand); return command->m_slot(rawArgs); } const torrent::Object -CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawVariable); +CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) { + CommandSlot* command = static_cast(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(rawVariable); +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); @@ -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(rawVariable); +CommandSlot::call_string(Command* rawCommand, const torrent::Object& rawArgs) { + CommandSlot* command = static_cast(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(rawVariable); +// CommandSlot::get_generic(Command* rawCommand, const torrent::Object& args) { +// CommandVariable* variable = static_cast(rawCommand); // return variable->m_variable; // } diff --git a/src/utils/command_slot.h b/src/rpc/command_slot.h similarity index 77% rename from src/utils/command_slot.h rename to src/rpc/command_slot.h index d0e59b51..01d8b542 100644 --- a/src/utils/command_slot.h +++ b/src/rpc/command_slot.h @@ -43,11 +43,11 @@ #include #include -#include "variable.h" +#include "rpc/command.h" namespace utils { -class CommandSlot : public Variable { +class CommandSlot : public Command { public: typedef rak::function1 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 - 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 object_void_fn_t* object_fn(Return (*func)(void)) { return new object_void_fn_t(func); } -template object_void_fn_t* object_void_fn(Func func) { return new object_void_fn_t(func); } -template object_value_fn1_t* object_value_fn(Func func) { return new object_value_fn1_t(func); } -template object_string_fn1_t* object_string_fn(Func func) { return new object_string_fn1_t(func); } +template object_void_fn_t* object_void_fn(Func func) { return new object_void_fn_t(func); } + //template object_void_fn_t* object_void_value_fn(Func func) { return new object_void_fn_t(func); } +template object_value_fn1_t* object_value_fn(Func func) { return new object_value_fn1_t(func); } +template object_string_fn1_t* object_string_fn(Func func) { return new object_string_fn1_t(func); } } diff --git a/src/utils/command_variable.cc b/src/rpc/command_variable.cc similarity index 76% rename from src/utils/command_variable.cc rename to src/rpc/command_variable.cc index 1a1e70ab..88bd5c84 100644 --- a/src/utils/command_variable.cc +++ b/src/rpc/command_variable.cc @@ -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(rawVariable); +CommandVariable::set_bool(Command* rawCommand, const torrent::Object& rawArgs) { + CommandVariable* variable = static_cast(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(rawVariable); +CommandVariable::get_bool(Command* rawCommand, const torrent::Object& args) { + CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; } const torrent::Object -CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs) { - CommandVariable* variable = static_cast(rawVariable); +CommandVariable::set_value(Command* rawCommand, const torrent::Object& rawArgs) { + CommandVariable* variable = static_cast(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(rawVariable); +CommandVariable::get_value(Command* rawCommand, const torrent::Object& args) { + CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; } const torrent::Object -CommandVariable::set_string(Variable* rawVariable, const torrent::Object& rawArgs) { - CommandVariable* variable = static_cast(rawVariable); +CommandVariable::set_string(Command* rawCommand, const torrent::Object& rawArgs) { + CommandVariable* variable = static_cast(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(rawVariable); +CommandVariable::get_string(Command* rawCommand, const torrent::Object& args) { + CommandVariable* variable = static_cast(rawCommand); return variable->m_variable; } diff --git a/src/utils/command_variable.h b/src/rpc/command_variable.h similarity index 79% rename from src/utils/command_variable.h rename to src/rpc/command_variable.h index 052b21ac..0fd7f411 100644 --- a/src/utils/command_variable.h +++ b/src/rpc/command_variable.h @@ -42,25 +42,25 @@ #include #include -#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; diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 0d249d59..77fad1f8 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -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 diff --git a/src/utils/parse.cc b/src/utils/parse.cc index 1e39f388..c4021129 100644 --- a/src/utils/parse.cc +++ b/src/utils/parse.cc @@ -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); diff --git a/src/utils/variable.cc b/src/utils/variable.cc deleted file mode 100644 index 94b37f8c..00000000 --- a/src/utils/variable.cc +++ /dev/null @@ -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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include - -#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; -// } -// } - -} diff --git a/src/utils/variable_map.cc b/src/utils/variable_map.cc index e1493126..f1b622b1 100644 --- a/src/utils/variable_map.cc +++ b/src/utils/variable_map.cc @@ -46,13 +46,13 @@ #include #include "parse.h" -#include "variable.h" +#include "rpc/command.h" #include "variable_map.h" namespace utils { -struct variable_map_get_ptr : std::unary_function { - Variable* operator () (VariableMap::value_type& value) { return value.second.m_variable; } +struct variable_map_get_ptr : std::unary_function { + 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); } diff --git a/src/utils/variable_map.h b/src/utils/variable_map.h index 5ab5418c..fad4ed35 100644 --- a/src/utils/variable_map.h +++ b/src/utils/variable_map.h @@ -57,20 +57,20 @@ struct variable_map_comp : public std::binary_function