* Modified the fallocate configure check so it will fail if 'fallocate' can't be found.

* Changed more commands to the new format.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1153 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2010-03-24 20:23:48 +00:00
parent db2b813fc4
commit bc96dbfa2d
18 changed files with 316 additions and 345 deletions
+18 -6
View File
@@ -161,18 +161,30 @@ template <> struct target_type_id<Command::file_itr_slot> { static const in
template <> struct target_type_id<Command::download_pair_slot> { static const int value = Command::target_download_pair; };
template <> struct target_type_id<> { static const int value = Command::target_generic; };
template <> struct target_type_id<target_type> { static const int value = Command::target_any; };
template <> struct target_type_id<core::Download*> { static const int value = Command::target_download; };
template <> struct target_type_id<torrent::Peer*> { static const int value = Command::target_peer; };
template <> struct target_type_id<torrent::Tracker*> { static const int value = Command::target_tracker; };
template <> struct target_type_id<torrent::File*> { static const int value = Command::target_file; };
template <> struct target_type_id<torrent::FileListIterator*> { static const int value = Command::target_file_itr; };
template <> struct target_type_id<target_type> { static const int value = Command::target_any; static const int proper_type = 1; };
template <> struct target_type_id<core::Download*> { static const int value = Command::target_download; static const int proper_type = 1; };
template <> struct target_type_id<torrent::Peer*> { static const int value = Command::target_peer; static const int proper_type = 1; };
template <> struct target_type_id<torrent::Tracker*> { static const int value = Command::target_tracker; static const int proper_type = 1; };
template <> struct target_type_id<torrent::File*> { static const int value = Command::target_file; static const int proper_type = 1; };
template <> struct target_type_id<torrent::FileListIterator*> { static const int value = Command::target_file_itr; static const int proper_type = 1; };
template <> struct target_type_id<core::Download*, core::Download*> { static const int value = Command::target_download_pair; };
template <typename T> inline bool
is_target_compatible(const target_type& target) { return target.first == target_type_id<T>::value; }
template <> inline bool
is_target_compatible<target_type>(const target_type& target) { return true; }
// Splitting pairs into separate targets.
inline bool is_target_pair(const target_type& target) { return target.first >= Command::target_download_pair; }
template <typename T> inline T
get_target_cast(target_type target, int type = target_type_id<T>::value) { return (T)target.second; }
template <> inline target_type
get_target_cast<target_type>(target_type target, int type) { return target; }
inline target_type get_target_left(const target_type& target) { return target_type(target.first - 5, target.second); }
inline target_type get_target_right(const target_type& target) { return target_type(target.first - 5, target.third); }
+45 -18
View File
@@ -41,15 +41,31 @@
#include "command_new_slot.h"
#define COMMAND_BASE_TEMPLATE_DEFINE(func_name) \
template const torrent::Object func_name<target_type>(Command* rawCommand, target_type target, const torrent::Object& args); \
template const torrent::Object func_name<core::Download*>(Command* rawCommand, target_type target, const torrent::Object& args); \
template const torrent::Object func_name<torrent::Peer*>(Command* rawCommand, target_type target, const torrent::Object& args); \
template const torrent::Object func_name<torrent::Tracker*>(Command* rawCommand, target_type target, const torrent::Object& args); \
template const torrent::Object func_name<torrent::File*>(Command* rawCommand, target_type target, const torrent::Object& args); \
template const torrent::Object func_name<torrent::FileListIterator*>(Command* rawCommand, target_type target, const torrent::Object& args);
namespace rpc {
const torrent::Object
command_base_call_any(Command* rawCommand, target_type target, const torrent::Object& args) {
return static_cast<command_base*>(rawCommand)->_pod<any_function>()(target, args);
template <typename T> const torrent::Object
command_base_call(Command* rawCommand, target_type target, const torrent::Object& args) {
if (!is_target_compatible<T>(target))
throw torrent::input_error("Target of wrong type.");
return command_base::_call<typename command_function<T>::type, T>(rawCommand, target, args);
}
const torrent::Object
command_base_call_any_value_base(Command* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) {
COMMAND_BASE_TEMPLATE_DEFINE(command_base_call);
template <typename T> const torrent::Object
command_base_call_value_base(Command* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) {
if (!is_target_compatible<T>(target))
throw torrent::input_error("Target of wrong type.");
const torrent::Object& arg = convert_to_single_argument(rawArgs);
if (arg.type() == torrent::Object::TYPE_STRING) {
@@ -58,40 +74,51 @@ command_base_call_any_value_base(Command* rawCommand, target_type target, const
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &val, base, unit))
throw torrent::input_error("Not a value.");
return static_cast<command_base*>(rawCommand)->_pod<any_value_function>()(target, val);
return command_base::_call<typename command_value_function<T>::type, T>(rawCommand, target, val);
}
return static_cast<command_base*>(rawCommand)->_pod<any_value_function>()(target, arg.as_value());
return command_base::_call<typename command_value_function<T>::type, T>(rawCommand, target, arg.as_value());
}
const torrent::Object
command_base_call_any_value(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
return command_base_call_any_value_base(rawCommand, target, rawArgs, 0, 1);
template <typename T> const torrent::Object
command_base_call_value(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
return command_base_call_value_base<T>(rawCommand, target, rawArgs, 0, 1);
}
COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_value);
template <typename T> const torrent::Object
command_base_call_string(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
if (!is_target_compatible<T>(target))
throw torrent::input_error("Target of wrong type.");
const torrent::Object
command_base_call_any_string(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
const torrent::Object& arg = convert_to_single_argument(rawArgs);
if (arg.type() == torrent::Object::TYPE_RAW_STRING)
return static_cast<command_base*>(rawCommand)->_pod<any_string_function>()(target, arg.as_raw_string().as_string());
return command_base::_call<typename command_string_function<T>::type, T>(rawCommand, target, arg.as_raw_string().as_string());
return static_cast<command_base*>(rawCommand)->_pod<any_string_function>()(target, arg.as_string());
return command_base::_call<typename command_string_function<T>::type, T>(rawCommand, target, arg.as_string());
}
const torrent::Object
command_base_call_any_list(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_string);
template <typename T> const torrent::Object
command_base_call_list(Command* rawCommand, target_type target, const torrent::Object& rawArgs) {
if (!is_target_compatible<T>(target))
throw torrent::input_error("Target of wrong type.");
if (rawArgs.type() != torrent::Object::TYPE_LIST) {
torrent::Object::list_type arg;
if (!rawArgs.is_empty())
arg.push_back(rawArgs);
return static_cast<command_base*>(rawCommand)->_pod<any_list_function>()(target, arg);
return command_base::_call<typename command_list_function<T>::type, T>(rawCommand, target, arg);
}
return static_cast<command_base*>(rawCommand)->_pod<any_list_function>()(target, rawArgs.as_list());
return command_base::_call<typename command_list_function<T>::type, T>(rawCommand, target, rawArgs.as_list());
}
COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_list);
}
+33 -26
View File
@@ -59,7 +59,7 @@ typedef const torrent::Object (*command_base_call_type)(Command*, target_type, c
typedef std::tr1::function<torrent::Object (target_type, const torrent::Object&)> base_function;
template <typename tmpl> struct command_base_is_valid {};
template <typename tmpl_type, command_base_call_type tmpl_func> struct command_base_is_type {};
template <command_base_call_type tmpl_func> struct command_base_is_type {};
class command_base : public Command {
public:
@@ -76,6 +76,11 @@ public:
// have no idea atm.
template <typename tmpl> tmpl& _pod() { return reinterpret_cast<tmpl&>(t_pod); }
template <typename Func, typename T, typename Args>
static const torrent::Object _call(Command* cmd, target_type target, Args args) {
return static_cast<command_base*>(cmd)->_pod<Func>()(get_target_cast<T>(target), args);
}
protected:
union {
@@ -83,35 +88,37 @@ protected:
};
};
#define COMMAND_BASE_TYPE(func_type, func_parm) \
typedef std::tr1::function<func_parm> func_type; \
template <> struct command_base_is_valid<func_type> { static const int value = 1; };
#define COMMAND_BASE_TEMPLATE_TYPE(func_type, func_parm) \
template <typename T, int proper = target_type_id<T>::proper_type> struct func_type { typedef std::tr1::function<func_parm> type; }; \
\
template <> struct command_base_is_valid<func_type<target_type>::type> { static const int value = 1; }; \
template <> struct command_base_is_valid<func_type<core::Download*>::type> { static const int value = 1; }; \
template <> struct command_base_is_valid<func_type<torrent::Peer*>::type> { static const int value = 1; }; \
template <> struct command_base_is_valid<func_type<torrent::Tracker*>::type> { static const int value = 1; }; \
template <> struct command_base_is_valid<func_type<torrent::File*>::type> { static const int value = 1; }; \
template <> struct command_base_is_valid<func_type<torrent::FileListIterator*>::type> { static const int value = 1; };
#define COMMAND_BASE_CALL(func_name, func_type) \
const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \
template <> struct command_base_is_type<func_type, func_name> { static const int value = 1; };
// template <typename Q> struct command_base_is_valid<typename func_type<Q>::type > { static const int value = 1; };
// template <> struct command_base_is_valid<base_function> { static const int value = 1; };
COMMAND_BASE_TEMPLATE_TYPE(command_function, torrent::Object (T, const torrent::Object&));
COMMAND_BASE_TEMPLATE_TYPE(command_value_function, torrent::Object (T, const torrent::Object::value_type&));
COMMAND_BASE_TEMPLATE_TYPE(command_string_function, torrent::Object (T, const std::string&));
COMMAND_BASE_TEMPLATE_TYPE(command_list_function, torrent::Object (T, const torrent::Object::list_type&));
// const torrent::Object command_base_call_any(Command* rawCommand, target_type target, const torrent::Object& args);
// template <> struct command_base_is_type<any_function, command_base_call_any> { static const int value = 1; };
#define COMMAND_BASE_TEMPLATE_CALL(func_name, func_type) \
template <typename T> const torrent::Object func_name(Command* rawCommand, target_type target, const torrent::Object& args); \
\
template <> struct command_base_is_type<func_name<target_type> > { static const int value = 1; typedef func_type<target_type>::type type; }; \
template <> struct command_base_is_type<func_name<core::Download*> > { static const int value = 1; typedef func_type<core::Download*>::type type; }; \
template <> struct command_base_is_type<func_name<torrent::Peer*> > { static const int value = 1; typedef func_type<torrent::Peer*>::type type; }; \
template <> struct command_base_is_type<func_name<torrent::Tracker*> > { static const int value = 1; typedef func_type<torrent::Tracker*>::type type; }; \
template <> struct command_base_is_type<func_name<torrent::File*> > { static const int value = 1; typedef func_type<torrent::File*>::type type; }; \
template <> struct command_base_is_type<func_name<torrent::FileListIterator*> > { static const int value = 1; typedef func_type<torrent::FileListIterator*>::type type; };
//
// Declare valid parameters and functions:
//
// typedef std::tr1::function<torrent::Object (target_type, const torrent::Object&)> any_function;
// typedef std::tr1::function<torrent::Object (target_type, const std::string&)> any_string_function;
COMMAND_BASE_TYPE(any_function, torrent::Object (target_type, const torrent::Object&));
COMMAND_BASE_TYPE(any_value_function, torrent::Object (target_type, const torrent::Object::value_type&));
COMMAND_BASE_TYPE(any_string_function, torrent::Object (target_type, const std::string&));
COMMAND_BASE_TYPE(any_list_function, torrent::Object (target_type, const torrent::Object::list_type&));
COMMAND_BASE_CALL(command_base_call_any, any_function);
COMMAND_BASE_CALL(command_base_call_any_value, any_value_function);
COMMAND_BASE_CALL(command_base_call_any_string, any_string_function);
COMMAND_BASE_CALL(command_base_call_any_list, any_list_function);
COMMAND_BASE_TEMPLATE_CALL(command_base_call, command_function);
COMMAND_BASE_TEMPLATE_CALL(command_base_call_value, command_value_function);
COMMAND_BASE_TEMPLATE_CALL(command_base_call_string, command_string_function);
COMMAND_BASE_TEMPLATE_CALL(command_base_call_list, command_list_function);
}