mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 14:12: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:
@@ -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,141 +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 "core/download.h"
|
||||
#include "utils/parse.h"
|
||||
|
||||
#include "command_download_slot.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_unknown(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
|
||||
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);
|
||||
|
||||
switch (rawArgs.type()) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
// Should shift this one too, so it gives the right unit.
|
||||
return command->m_slot(download, arg);
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
torrent::Object argValue(torrent::Object::TYPE_VALUE);
|
||||
|
||||
if (!utils::parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
|
||||
throw torrent::input_error("Not a value.");
|
||||
|
||||
return command->m_slot(download, argValue);
|
||||
}
|
||||
default:
|
||||
throw torrent::input_error("Not a value.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandDownloadSlot::call_string(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
return command->m_slot(download, arg);
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
if (m_firstKey == NULL)
|
||||
download->bencode()->get_key(m_secondKey) = arg1;
|
||||
else
|
||||
download->bencode()->get_key(m_firstKey).get_key(m_secondKey) = arg1;
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
get_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
if (m_firstKey == NULL)
|
||||
return download->bencode()->get_key(m_secondKey);
|
||||
else
|
||||
return download->bencode()->get_key(m_firstKey).get_key(m_secondKey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,204 +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
|
||||
|
||||
#ifndef RTORRENT_UTILS_COMMAND_DOWNLOAD_SLOT_H
|
||||
#define RTORRENT_UTILS_COMMAND_DOWNLOAD_SLOT_H
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
#include "variable.h"
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandDownloadSlot : public Variable {
|
||||
public:
|
||||
typedef rak::function2<torrent::Object, core::Download*, const torrent::Object&> slot_type;
|
||||
|
||||
CommandDownloadSlot() {}
|
||||
|
||||
CommandDownloadSlot(slot_type::base_type* s) {
|
||||
m_slot.set(s);
|
||||
}
|
||||
|
||||
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
|
||||
|
||||
static const torrent::Object call_unknown(Variable* rawVariable, 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_value_base(Variable* rawVariable, 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); }
|
||||
|
||||
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& get_list(Variable* rawVariable, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
slot_type m_slot;
|
||||
};
|
||||
|
||||
// Some slots that convert torrent::Object arguments to proper
|
||||
// function calls.
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_void_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_void_d_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download)); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_void_d_fn_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_void_d_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
m_func(download);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_value_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_value_d_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
return torrent::Object((int64_t)m_func(download, arg1.as_value()));
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_value_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_value_d_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
m_func(download, arg1.as_value());
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_string_d_fn1_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_string_d_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) { return torrent::Object(m_func(download, arg1.as_string())); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_string_d_fn1_t<Func, void> : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
object_string_d_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1) {
|
||||
m_func(download, arg1.as_string());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
class set_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
set_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
|
||||
|
||||
private:
|
||||
const char* m_firstKey;
|
||||
const char* m_secondKey;
|
||||
};
|
||||
|
||||
class get_variable_d_fn_t : public rak::function_base2<torrent::Object, core::Download*, const torrent::Object&> {
|
||||
public:
|
||||
get_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {}
|
||||
|
||||
virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1);
|
||||
|
||||
private:
|
||||
const char* m_firstKey;
|
||||
const char* m_secondKey;
|
||||
};
|
||||
|
||||
template <typename Return> object_void_d_fn_t<Return (*)(core::Download*), Return>*
|
||||
object_d_fn(Return (*func)(core::Download*)) {
|
||||
return new object_void_d_fn_t<Return (*)(core::Download*), Return>(func);
|
||||
}
|
||||
|
||||
template <typename Func> object_void_d_fn_t<Func>* object_void_d_fn(Func func) { return new object_void_d_fn_t<Func>(func); }
|
||||
template <typename Func> object_value_d_fn1_t<Func>* object_value_d_fn(Func func) { return new object_value_d_fn1_t<Func>(func); }
|
||||
template <typename Func> object_string_d_fn1_t<Func>* object_string_d_fn(Func func) { return new object_string_d_fn1_t<Func>(func); }
|
||||
|
||||
inline set_variable_d_fn_t*
|
||||
set_variable_d_fn(const char* firstKey, const char* secondKey) { return new set_variable_d_fn_t(firstKey, secondKey); }
|
||||
inline get_variable_d_fn_t*
|
||||
get_variable_d_fn(const char* firstKey, const char* secondKey) { return new get_variable_d_fn_t(firstKey, secondKey); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,124 +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 "utils/parse.h"
|
||||
|
||||
#include "command_slot.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_unknown(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
return command->m_slot(rawArgs);
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_list(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
switch (rawArgs.type()) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
// Should shift this one too, so it gives the right unit.
|
||||
return command->m_slot(arg);
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
torrent::Object argValue(torrent::Object::TYPE_VALUE);
|
||||
|
||||
if (!utils::parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
|
||||
throw torrent::input_error("Not a value.");
|
||||
|
||||
return command->m_slot(argValue);
|
||||
}
|
||||
default:
|
||||
throw torrent::input_error("Not a value.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandSlot::call_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
// case torrent::Object::TYPE_VALUE:
|
||||
// break;
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
return command->m_slot(arg);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("Not a string.");
|
||||
}
|
||||
}
|
||||
|
||||
// const torrent::Object&
|
||||
// CommandSlot::get_generic(Variable* rawVariable, const torrent::Object& args) {
|
||||
// CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
// return variable->m_variable;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,174 +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
|
||||
|
||||
#ifndef RTORRENT_UTILS_COMMAND_SLOT_H
|
||||
#define RTORRENT_UTILS_COMMAND_SLOT_H
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
#include "variable.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandSlot : public Variable {
|
||||
public:
|
||||
typedef rak::function1<torrent::Object, const torrent::Object&> slot_type;
|
||||
|
||||
// template <typename SlotSet>
|
||||
// CommandSlot(SlotSet* slotSet) {
|
||||
// m_slotSet.set(slotSet);
|
||||
// }
|
||||
|
||||
CommandSlot() {}
|
||||
|
||||
CommandSlot(slot_type::base_type* s) {
|
||||
m_slot.set(s);
|
||||
}
|
||||
|
||||
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
|
||||
|
||||
static const torrent::Object call_unknown(Variable* rawVariable, 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_value_base(Variable* rawVariable, 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); }
|
||||
|
||||
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& get_list(Variable* rawVariable, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
slot_type m_slot;
|
||||
};
|
||||
|
||||
// Some slots that convert torrent::Object arguments to proper
|
||||
// function calls.
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_void_fn_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_void_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func()); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_void_fn_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_void_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) {
|
||||
m_func();
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_value_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_value_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(arg1.as_value())); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_value_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_value_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) {
|
||||
m_func(arg1.as_value());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_string_fn1_t : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_string_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func(arg1.as_string())); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_string_fn1_t<Func, void> : public rak::function_base1<torrent::Object, const torrent::Object&> {
|
||||
public:
|
||||
object_string_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (const torrent::Object& arg1) {
|
||||
m_func(arg1.as_string());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
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); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,151 +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 "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);
|
||||
|
||||
const torrent::Object& arg = convert_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;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::get_bool(Variable* rawVariable, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_NONE:
|
||||
variable->m_variable = (int64_t)0;
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
variable->m_variable = arg;
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
int64_t value;
|
||||
parse_whole_value(arg.as_string().c_str(), &value, 0, 1);
|
||||
|
||||
variable->m_variable = value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("VariableValue 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);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::set_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_NONE:
|
||||
variable->m_variable = std::string("");
|
||||
break;
|
||||
|
||||
// case torrent::Object::TYPE_VALUE:
|
||||
// variable->m_variable = arg;
|
||||
// break;
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
variable->m_variable = arg;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("Not a string.");
|
||||
}
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandVariable::get_string(Variable* rawVariable, const torrent::Object& args) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +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
|
||||
|
||||
#ifndef RTORRENT_UTILS_COMMAND_VARIABLES_H
|
||||
#define RTORRENT_UTILS_COMMAND_VARIABLES_H
|
||||
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "variable.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
class CommandVariable : public Variable {
|
||||
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_value(Variable* rawVariable, const torrent::Object& args);
|
||||
static const torrent::Object get_value(Variable* rawVariable, 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);
|
||||
|
||||
private:
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+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;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,66 +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
|
||||
|
||||
#ifndef RTORRENT_UTILS_VARIABLE_H
|
||||
#define RTORRENT_UTILS_VARIABLE_H
|
||||
|
||||
#include <torrent/object.h>
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
|
||||
class Variable {
|
||||
public:
|
||||
typedef torrent::Object::value_type value_type;
|
||||
typedef torrent::Object::string_type string_type;
|
||||
typedef torrent::Object::list_type list_type;
|
||||
typedef torrent::Object::map_type map_type;
|
||||
typedef torrent::Object::key_type key_type;
|
||||
|
||||
Variable() {}
|
||||
virtual ~Variable() {}
|
||||
|
||||
protected:
|
||||
Variable(const Variable&);
|
||||
void operator = (const Variable&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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