diff --git a/scripts/checks.m4 b/scripts/checks.m4 index 1efe4bab..817c114e 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -291,11 +291,11 @@ AC_DEFUN([TORRENT_WITH_ADDRESS_SPACE], [ AC_DEFUN([TORRENT_WITH_FASTCGI], [ - AC_MSG_CHECKING(for FastCGI) - AC_ARG_WITH(fastcgi, - [ --with-fastcgi=PATH Enable FastCGI RPC support.], + [ --with-fastcgi=PATH Enable FastCGI RPC support. (DO NOT USE)], [ + AC_MSG_CHECKING([for FastCGI (DO NOT USE)]) + if test "$withval" = "no"; then AC_MSG_RESULT(no) @@ -333,8 +333,6 @@ AC_DEFUN([TORRENT_WITH_FASTCGI], [ AC_DEFINE(HAVE_FASTCGI, 1, Support for FastCGI.) fi - ],[ - AC_MSG_RESULT(ignored) ]) ]) diff --git a/src/core/download.cc b/src/core/download.cc index 526600f3..c8dbbea1 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -48,7 +48,6 @@ #include #include -#include "utils/variable_generic.h" #include "utils/variable_map.h" #include "control.h" @@ -206,13 +205,14 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) { m_chunksFailed++; } -int64_t Download::get_value(const char* key) { return control->download_variables()->get_d_value(this, key); } -const std::string Download::get_string(const char* key) { return control->download_variables()->get_d_string(this, key); } -int64_t Download::get_std_value(const std::string& key) { return control->download_variables()->get_d_value(this, key.c_str()); } -const std::string Download::get_std_string(const std::string& key) { return control->download_variables()->get_d_string(this, key.c_str()); } -void Download::set(const char* key, const torrent::Object& value) { return control->download_variables()->set_d(this, key, value); } -void Download::set_value(const char* key, int64_t value) { return control->download_variables()->set_d_value(this, key, value); } -void Download::set_string(const char* key, const std::string& value) { return control->download_variables()->set_d_string(this, key, value); } +int64_t Download::get_value(const char* key) { return control->download_variables()->call_command_d_value(key, this); } +const std::string Download::get_string(const char* key) { return control->download_variables()->call_command_d_string(key, this); } +int64_t Download::get_std_value(const std::string& key) { return control->download_variables()->call_command_d_value(key.c_str(), this); } +const std::string Download::get_std_string(const std::string& key) { return control->download_variables()->call_command_d_string(key.c_str(), this); } + +void Download::set(const char* key, const torrent::Object& value) { control->download_variables()->call_command_d(key, this, value); } +void Download::set_value(const char* key, int64_t value) { control->download_variables()->call_command_d_set_value(key, this, value); } +void Download::set_string(const char* key, const std::string& value) { control->download_variables()->call_command_d_set_string(key, this, value); } // Clean up. void diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 1065ff0c..eccfee85 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -47,7 +47,6 @@ #include #include -#include "utils/variable_generic.h" #include "utils/variable_map.h" #include "curl_get.h" diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 34954d70..ec5ac1c0 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -285,8 +285,8 @@ DownloadList::receive_exit_input(Input type) { if (current_view()->focus() == current_view()->end_visible()) throw torrent::input_error("No download in focus to change root directory."); - (*current_view()->focus())->set("set_directory", rak::trim(input->str())); - control->core()->push_log("New root directory \"" + (*current_view()->focus())->get_string("set_directory") + "\" for torrent."); + control->download_variables()->call_command_d("set_directory", *current_view()->focus(), rak::trim(input->str())); + control->core()->push_log("New root directory \"" + (*current_view()->focus())->get_string("get_directory") + "\" for torrent."); break; case INPUT_COMMAND: diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index b6e4a077..0d249d59 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -18,8 +18,6 @@ libsub_utils_a_SOURCES = \ socket_fd.h \ variable.cc \ variable.h \ - variable_generic.cc \ - variable_generic.h \ variable_map.cc \ variable_map.h diff --git a/src/utils/command_download_slot.cc b/src/utils/command_download_slot.cc index b42ff9e7..ad716b4b 100644 --- a/src/utils/command_download_slot.cc +++ b/src/utils/command_download_slot.cc @@ -54,37 +54,18 @@ const torrent::Object CommandDownloadSlot::call_list(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) { CommandDownloadSlot* command = static_cast(rawVariable); -// const torrent::Object& arg = to_single_argument(rawArgs); - -// switch (arg.type()) { -// case torrent::Object::TYPE_VALUE: -// variable->m_variable = arg.as_value() ? (int64_t)1 : (int64_t)0; -// break; - -// case torrent::Object::TYPE_STRING: -// // Move the checks into some is_true, is_false think in Variable. -// if (arg.as_string() == "yes" || arg.as_string() == "true") -// variable->m_variable = (int64_t)1; - -// else if (arg.as_string() == "no" || arg.as_string() == "false") -// variable->m_variable = (int64_t)0; - -// else -// throw torrent::input_error("String does not parse as a boolean."); - -// break; - -// default: -// throw torrent::input_error("Input is not a boolean."); -// } - -// return variable->m_variable; - switch (rawArgs.type()) { -// case torrent::Object::TYPE_STRING: -// break; case torrent::Object::TYPE_LIST: return command->m_slot(download, rawArgs); + + case torrent::Object::TYPE_VALUE: + case torrent::Object::TYPE_STRING: + { + torrent::Object tmpList(torrent::Object::TYPE_LIST); + tmpList.as_list().push_back(rawArgs); + + return command->m_slot(download, tmpList); + } default: throw torrent::input_error("Not a list."); } @@ -122,25 +103,23 @@ CommandDownloadSlot::call_string(Variable* rawVariable, core::Download* download const torrent::Object& arg = to_single_argument(rawArgs); switch (arg.type()) { -// case torrent::Object::TYPE_VALUE: -// break; - case torrent::Object::TYPE_STRING: return command->m_slot(download, arg); - break; + + case torrent::Object::TYPE_NONE: + throw torrent::input_error("CDS: void."); + + case torrent::Object::TYPE_VALUE: + throw torrent::input_error("CDS: value."); + + case torrent::Object::TYPE_LIST: + throw torrent::input_error("CDS: list."); default: throw torrent::input_error("Not a string."); } } -// const torrent::Object& -// CommandDownloadSlot::get_generic(Variable* rawVariable, const torrent::Object& args) { -// CommandVariable* variable = static_cast(rawVariable); - -// return variable->m_variable; -// } - torrent::Object set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) { if (m_firstKey == NULL) diff --git a/src/utils/command_slot.cc b/src/utils/command_slot.cc index 97a0eb95..4210b2e5 100644 --- a/src/utils/command_slot.cc +++ b/src/utils/command_slot.cc @@ -53,37 +53,18 @@ const torrent::Object CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) { CommandSlot* command = static_cast(rawVariable); -// const torrent::Object& arg = to_single_argument(rawArgs); - -// switch (arg.type()) { -// case torrent::Object::TYPE_VALUE: -// variable->m_variable = arg.as_value() ? (int64_t)1 : (int64_t)0; -// break; - -// case torrent::Object::TYPE_STRING: -// // Move the checks into some is_true, is_false think in Variable. -// if (arg.as_string() == "yes" || arg.as_string() == "true") -// variable->m_variable = (int64_t)1; - -// else if (arg.as_string() == "no" || arg.as_string() == "false") -// variable->m_variable = (int64_t)0; - -// else -// throw torrent::input_error("String does not parse as a boolean."); - -// break; - -// default: -// throw torrent::input_error("Input is not a boolean."); -// } - -// return variable->m_variable; - switch (rawArgs.type()) { -// case torrent::Object::TYPE_STRING: -// break; case torrent::Object::TYPE_LIST: return command->m_slot(rawArgs); + + case torrent::Object::TYPE_VALUE: + case torrent::Object::TYPE_STRING: + { + torrent::Object tmpList(torrent::Object::TYPE_LIST); + tmpList.as_list().push_back(rawArgs); + + return command->m_slot(tmpList); + } default: throw torrent::input_error("Not a list."); } diff --git a/src/utils/variable_generic.cc b/src/utils/variable_generic.cc deleted file mode 100644 index 75abb1c3..00000000 --- a/src/utils/variable_generic.cc +++ /dev/null @@ -1,307 +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 "parse.h" -#include "variable_generic.h" - -namespace utils { - -const torrent::Object& VariableAny::get() { return m_variable; } -void VariableAny::set(const torrent::Object& arg) { m_variable = arg; } - -void -VariableValue::set(const torrent::Object& arg) { - int64_t value; - - switch (arg.type()) { - case torrent::Object::TYPE_NONE: - m_variable = (int64_t)0; - break; - - case torrent::Object::TYPE_VALUE: - m_variable = arg; - break; - - case torrent::Object::TYPE_STRING: - string_to_value_unit(arg.as_string().c_str(), &value, 0, 1); - - m_variable = value; - break; - - default: - throw torrent::input_error("VariableValue unsupported type restriction."); - } -} - -void -VariableBool::set(const torrent::Object& arg) { - switch (arg.type()) { - case torrent::Object::TYPE_VALUE: - m_variable = arg.as_value() ? (int64_t)1 : (int64_t)0; - break; - - case torrent::Object::TYPE_STRING: - // Move the checks into some is_true, is_false think in Variable. - if (arg.as_string() == "yes" || arg.as_string() == "true") - m_variable = (int64_t)1; - - else if (arg.as_string() == "no" || arg.as_string() == "false") - m_variable = (int64_t)0; - - else - throw torrent::input_error("String does not parse as a boolean."); - - break; - - default: - throw torrent::input_error("Input is not a boolean."); - } -} - -const torrent::Object& -VariableObject::get_d(core::Download* download) { - if (m_root.empty()) - return download->bencode()->get_key(m_key); - else - return download->bencode()->get_key(m_root).get_key(m_key); -} - -void -VariableObject::set_d(core::Download* download, const torrent::Object& arg) { - // Consider removing if TYPE_NONE. - torrent::Object* root; - - if (m_root.empty()) - root = download->bencode(); - else - root = &download->bencode()->get_key(m_root); - - switch (m_type) { - case torrent::Object::TYPE_NONE: - root->insert_key(m_key, arg); - break; - - case torrent::Object::TYPE_STRING: - if (arg.is_string()) - root->insert_key(m_key, arg); - else - throw torrent::input_error("VariableObject could not convert to string."); - - break; - - case torrent::Object::TYPE_VALUE: - if (arg.is_value()) - root->insert_key(m_key, arg); - else - throw torrent::input_error("VariableObject could not convert to value."); - - break; - - default: - throw torrent::input_error("VariableObject unsupported type restriction."); - } -} - -const torrent::Object& VariableDownload::get() { return m_global->get(); } -const torrent::Object& VariableDownload::get_d(core::Download* download) { return m_download->get_d(download); } -void VariableDownload::set(const torrent::Object& arg) { m_global->set(arg); } -void VariableDownload::set_d(core::Download* download, const torrent::Object& arg) { m_download->set_d(download, arg); } - -// -// New and prettified. -// - -const torrent::Object& -VariableVoidSlot::get() { - return m_cache; -} - -void -VariableVoidSlot::set(const torrent::Object& arg) { - if (!m_slotSet.is_valid()) - return; - - m_slotSet(); -} - -const torrent::Object& -VariableValueSlot::get() { - if (!m_slotGet.is_valid()) - return m_cache = torrent::Object(); - - m_cache = m_slotGet() / m_unit; - - return m_cache; -} - -void -VariableValueSlot::set(const torrent::Object& rawArg) { - if (!m_slotSet.is_valid()) - return; - - const torrent::Object* arg; - - if (rawArg.type() == torrent::Object::TYPE_LIST && rawArg.as_list().size() == 1) - arg = &rawArg.as_list().front(); - else - arg = &rawArg; - - value_type value; - - switch (arg->type()) { - case torrent::Object::TYPE_STRING: - string_to_value_unit(arg->as_string().c_str(), &value, m_base, m_unit); - - // Check if we hit the end of the input. - - m_slotSet(value); - break; - - case torrent::Object::TYPE_VALUE: - m_slotSet(arg->as_value()); - break; - - default: - throw torrent::input_error("Not a value"); - } -} - -const torrent::Object& -VariableDownloadValueSlot::get_d(core::Download* download) { - // Should clear the cache. - if (!m_slotGetDownload.is_valid()) - return m_cache = torrent::Object(); - - return m_cache = m_slotGetDownload(download) / m_unit; -} - -void -VariableDownloadValueSlot::set_d(core::Download* download, const torrent::Object& arg) { - if (!m_slotSetDownload.is_valid()) - return; - - value_type value; - - switch (arg.type()) { - case torrent::Object::TYPE_STRING: - string_to_value_unit(arg.as_string().c_str(), &value, m_base, m_unit); - - // Check if we hit the end of the input. - - m_slotSetDownload(download, value); - break; - - case torrent::Object::TYPE_VALUE: - m_slotSetDownload(download, arg.as_value()); - break; - - default: - throw torrent::input_error("Not a value"); - } -} - -const torrent::Object& -VariableStringSlot::get() { - if (!m_slotGet.is_valid()) - return m_cache = torrent::Object(); - - return m_cache = m_slotGet(); -} - -void -VariableStringSlot::set(const torrent::Object& arg) { - if (!m_slotSet.is_valid()) - return; - - switch (arg.type()) { - case torrent::Object::TYPE_STRING: - m_slotSet(arg.as_string()); - break; - case torrent::Object::TYPE_NONE: - m_slotSet(std::string()); - break; - case torrent::Object::TYPE_LIST: - m_slotSet(convert_list_to_string(arg)); - break; - default: - throw torrent::input_error("Not a string."); - } -} - -const torrent::Object& -VariableDownloadStringSlot::get_d(core::Download* download) { - // Should clear the cache. - if (!m_slotGetDownload.is_valid()) - return m_cache = torrent::Object(); - - return m_cache = m_slotGetDownload(download); -} - -void -VariableDownloadStringSlot::set_d(core::Download* download, const torrent::Object& arg) { - if (!m_slotSetDownload.is_valid()) - return; - - switch (arg.type()) { - case torrent::Object::TYPE_STRING: - m_slotSetDownload(download, arg.as_string()); - break; - case torrent::Object::TYPE_NONE: - m_slotSetDownload(download, std::string()); - break; - default: - throw torrent::input_error("Not a string."); - } -} - -void -VariableDownloadListSlot::set_d(core::Download* download, const torrent::Object& arg) { - switch (arg.type()) { -// case torrent::Object::TYPE_STRING: -// break; - case torrent::Object::TYPE_LIST: - m_slotSet(download, arg.as_list()); - break; - default: - throw torrent::input_error("Not a list."); - } -} - -} diff --git a/src/utils/variable_generic.h b/src/utils/variable_generic.h deleted file mode 100644 index a08e1e63..00000000 --- a/src/utils/variable_generic.h +++ /dev/null @@ -1,315 +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 - -// Parts of this seems ugly in an attempt to avoid copying -// data. Propably need to rewrite torrent::Object. - -#ifndef RTORRENT_UTILS_VARIABLE_GENERIC_H -#define RTORRENT_UTILS_VARIABLE_GENERIC_H - -#include -#include -#include -#include -#include -#include -#include - -#include "variable.h" -#include "core/download.h" - -namespace utils { - -class VariableAny : public Variable { -public: - VariableAny(const torrent::Object& v = torrent::Object()) : - m_variable(v) {} - - virtual const torrent::Object& get(); - virtual void set(const torrent::Object& arg); - -protected: - torrent::Object m_variable; -}; - -class VariableValue : public VariableAny { -public: - VariableValue(int64_t v) { m_variable = v; } - - virtual void set(const torrent::Object& arg); -}; - -class VariableBool : public VariableAny { -public: - VariableBool(bool state = false) { m_variable = state ? (int64_t)1 : (int64_t)0; } - - virtual void set(const torrent::Object& arg); -}; - -class VariableDownload : public Variable { -public: - VariableDownload(Variable* varGlobal, Variable* varDownload) : - m_global(varGlobal), m_download(varDownload) {} - - virtual const torrent::Object& get(); - virtual void set(const torrent::Object& arg); - - virtual const torrent::Object& get_d(core::Download* download); - virtual void set_d(core::Download* download, const torrent::Object& arg); - -protected: - Variable* m_global; - Variable* m_download; -}; - -class VariableObject : public Variable { -public: - typedef torrent::Object::type_type Type; - - VariableObject(const std::string& root, const std::string& key, Type t = torrent::Object::TYPE_NONE) : - m_root(root), m_key(key), m_type(t) {} - - virtual const torrent::Object& get_d(core::Download* download); - virtual void set_d(core::Download* download, const torrent::Object& arg); - -private: - std::string m_root; - std::string m_key; - Type m_type; -}; - -// -// New and pretty. -// - -class VariableVoidSlot : public Variable { -public: - typedef rak::function0 slot_set_type; - - VariableVoidSlot(slot_set_type::base_type* slotSet) { - m_slotSet.set(slotSet); - } - - virtual const torrent::Object& get(); - virtual void set(const torrent::Object& arg); - -private: - slot_set_type m_slotSet; - - // Store the cache here to avoid unnessesary copying and such. This - // should not result in any unresonable memory usage since few - // strings will be very large. - torrent::Object m_cache; -}; - -class VariableValueSlot : public Variable { -public: - typedef rak::function0 slot_get_type; - typedef rak::function1 slot_set_type; - - typedef std::pair range_type; - - template - VariableValueSlot(SlotGet* slotGet, SlotSet* slotSet, unsigned int base = 0, unsigned int unit = 1, - range_type range = range_type(std::numeric_limits::min(), std::numeric_limits::max())) : - m_base(base), - m_unit(unit), - m_range(range) { - - m_slotGet.set(rak::convert_fn(slotGet)); - m_slotSet.set(rak::convert_fn(slotSet)); - } - - template - VariableValueSlot(SlotGet* slotGet, void* slotSet, unsigned int base = 0, unsigned int unit = 1, - range_type range = range_type(std::numeric_limits::min(), std::numeric_limits::max())) : - m_base(base), - m_unit(unit), - m_range(range) { - - m_slotGet.set(rak::convert_fn(slotGet)); - m_slotSet.set(NULL); - } - - virtual const torrent::Object& get(); - virtual void set(const torrent::Object& arg); - -private: - slot_get_type m_slotGet; - slot_set_type m_slotSet; - - unsigned int m_base; - unsigned int m_unit; - range_type m_range; - - // Store the cache here to avoid unnessesary copying and such. This - // should not result in any unresonable memory usage since few - // strings will be very large. - torrent::Object m_cache; -}; - -class VariableDownloadValueSlot : public Variable { -public: - typedef rak::function1 slot_get_d_type; - typedef rak::function2 slot_set_d_type; - - typedef std::pair range_type; - - template - VariableDownloadValueSlot(SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload, - unsigned int base = 0, unsigned int unit = 1, - range_type range = range_type(std::numeric_limits::min(), std::numeric_limits::max())) : - m_base(base), - m_unit(unit), - m_range(range) { - - m_slotGetDownload.set(rak::convert_fn(slotGetDownload)); - m_slotSetDownload.set(rak::convert_fn(slotSetDownload)); - } - - template - VariableDownloadValueSlot(SlotGetDownload* slotGetDownload, void* slotSetDownload, - unsigned int base = 0, unsigned int unit = 1, - range_type range = range_type(std::numeric_limits::min(), std::numeric_limits::max())) : - m_base(base), - m_unit(unit), - m_range(range) { - - m_slotGetDownload.set(rak::convert_fn(slotGetDownload)); - m_slotSetDownload.set(NULL); - } - - virtual const torrent::Object& get_d(core::Download* download); - virtual void set_d(core::Download* download, const torrent::Object& arg); - -private: - slot_get_d_type m_slotGetDownload; - slot_set_d_type m_slotSetDownload; - - unsigned int m_base; - unsigned int m_unit; - range_type m_range; - - // Store the cache here to avoid unnessesary copying and such. This - // should not result in any unresonable memory usage since few - // strings will be very large. - torrent::Object m_cache; -}; - -class VariableStringSlot : public Variable { -public: - typedef rak::function0 slot_get_type; - typedef rak::function1 slot_set_type; - - template - VariableStringSlot(void* slotGet, SlotSet* slotSet) { - m_slotGet.set(NULL); - m_slotSet.set(rak::convert_fn(slotSet)); - } - - template - VariableStringSlot(SlotGet* slotGet, SlotSet* slotSet) { - m_slotGet.set(rak::convert_fn(slotGet)); - m_slotSet.set(rak::convert_fn(slotSet)); - } - - virtual const torrent::Object& get(); - virtual void set(const torrent::Object& arg); - -private: - slot_get_type m_slotGet; - slot_set_type m_slotSet; - - // Store the cache here to avoid unnessesary copying and such. This - // should not result in any unresonable memory usage since few - // strings will be very large. - torrent::Object m_cache; -}; - -class VariableDownloadStringSlot : public Variable { -public: - typedef rak::function1 slot_get_d_type; - typedef rak::function2 slot_set_d_type; - - template - VariableDownloadStringSlot(void* slotGetDownload, SlotSetDownload* slotSetDownload) { - m_slotGetDownload.set(NULL); - m_slotSetDownload.set(rak::convert_fn(slotSetDownload)); - } - - template - VariableDownloadStringSlot(SlotGetDownload* slotGetDownload, void* slotSetDownload) { - m_slotGetDownload.set(rak::convert_fn(slotGetDownload)); - m_slotSetDownload.set(NULL); - } - - template - VariableDownloadStringSlot(SlotGetDownload* slotGetDownload, SlotSetDownload* slotSetDownload) { - m_slotGetDownload.set(rak::convert_fn(slotGetDownload)); - m_slotSetDownload.set(rak::convert_fn(slotSetDownload)); - } - - virtual const torrent::Object& get_d(core::Download* download); - virtual void set_d(core::Download* download, const torrent::Object& arg); - -private: - slot_get_d_type m_slotGetDownload; - slot_set_d_type m_slotSetDownload; - - // Store the cache here to avoid unnessesary copying and such. This - // should not result in any unresonable memory usage since few - // strings will be very large. - torrent::Object m_cache; -}; - -class VariableDownloadListSlot : public Variable { -public: - typedef rak::function2 slot_set_type; - - template - VariableDownloadListSlot(SlotSet* slotSet) { - m_slotSet.set(slotSet); - } - - virtual void set_d(core::Download* download, const torrent::Object& arg); - -private: - slot_set_type m_slotSet; -}; - -} - -#endif diff --git a/src/utils/variable_map.cc b/src/utils/variable_map.cc index 2a430835..cbc116e7 100644 --- a/src/utils/variable_map.cc +++ b/src/utils/variable_map.cc @@ -83,44 +83,6 @@ VariableMap::insert(key_type key, const variable_map_data_type src) { src.m_flags | flag_dont_delete, src.m_parm, src.m_doc))); } -const VariableMap::mapped_type -VariableMap::get_d(core::Download* download, key_type key) const { - const_iterator itr = base_type::find(key); - - if (itr == base_type::end()) - throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist."); - - if (itr->second.m_downloadSlot != NULL) - return itr->second.m_downloadSlot(itr->second.m_variable, download, torrent::Object()); - - if (itr->second.m_genericSlot != NULL) - return itr->second.m_genericSlot(itr->second.m_variable, torrent::Object()); - - return itr->second.m_variable->get_d(download); -} - -void -VariableMap::set_d(core::Download* download, key_type key, const mapped_type& arg) { - iterator itr = base_type::find(key); - - // Later, allow the user to create new variables. Have a slot to - // register that thing. - if (itr == base_type::end()) - throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist."); - - if (itr->second.m_downloadSlot != NULL) { - itr->second.m_downloadSlot(itr->second.m_variable, download, arg); - return; - } - - if (itr->second.m_genericSlot != NULL) { - itr->second.m_genericSlot(itr->second.m_variable, arg); - return; - } - - itr->second.m_variable->set_d(download, arg); -} - struct variable_map_is_space : std::unary_function { bool operator () (char c) const { return std::isspace(c); @@ -191,7 +153,7 @@ VariableMap::process_d_single(core::Download* download, const char* first, const mapped_type args; first = parse_whole_list(first + 1, last, &args); - set_d(download, key.c_str(), args); + call_command_d(key.c_str(), download, args); return first; } diff --git a/src/utils/variable_map.h b/src/utils/variable_map.h index f87645e1..5ab5418c 100644 --- a/src/utils/variable_map.h +++ b/src/utils/variable_map.h @@ -118,16 +118,6 @@ public: void insert(key_type key, const variable_map_data_type src); - // Consider uninlining the helper functions. - const mapped_type get_d(core::Download* download, key_type key) const; - const std::string get_d_string(core::Download* download, key_type key) const { return get_d(download, key).as_string(); } - mapped_value_type get_d_value(core::Download* download, key_type key) const { return get_d(download, key).as_value(); } - - void set_d(core::Download* download, key_type key, const mapped_type& arg); - void set_d_string(core::Download* download, key_type key, const std::string& arg) { set_d(download, key, mapped_type(arg)); } - void set_d_std_string(core::Download* download, const std::string& key, const std::string& arg) { set_d(download, key.c_str(), mapped_type(arg)); } - void set_d_value(core::Download* download, key_type key, mapped_value_type arg) { set_d(download, key, mapped_type(arg)); } - const char* process_single(const char* first); const char* process_single(const char* first, const char* last); void process_std_single(const std::string& cmd) { process_single(cmd.c_str(), cmd.c_str() + cmd.size()); } @@ -151,6 +141,13 @@ public: void call_command_set_std_string(const std::string& key, const std::string& arg) { call_command(key.c_str(), mapped_type(arg)); } const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg); + const mapped_type call_command_d_void(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()); } + const std::string call_command_d_string(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_string(); } + mapped_value_type call_command_d_value(key_type key, core::Download* download) { return call_command_d(key, download, torrent::Object()).as_value(); } + + void call_command_d_set_value(key_type key, core::Download* download, mapped_value_type arg) { call_command_d(key, download, mapped_type(arg)); } + void call_command_d_set_string(key_type key, core::Download* download, const std::string& arg) { call_command_d(key, download, mapped_type(arg)); } + void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { call_command_d(key.c_str(), download, mapped_type(arg)); } private: VariableMap(const VariableMap&);