mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 23:29:21 +00:00
* Added 'argument.?' commands that passing of arguments to commands
created with 'system.method.insert'. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1077 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -132,9 +132,18 @@ public:
|
||||
Command() {}
|
||||
virtual ~Command() {}
|
||||
|
||||
static torrent::Object* argument(unsigned int index) { return m_arguments + index; }
|
||||
|
||||
protected:
|
||||
Command(const Command&);
|
||||
void operator = (const Command&);
|
||||
|
||||
// For use by functions that need to use placeholders to arguments
|
||||
// within commands. E.d. callable command strings where one of the
|
||||
// arguments within the command needs to be supplied by the caller.
|
||||
static const unsigned int max_arguments = 10;
|
||||
|
||||
static torrent::Object m_arguments[max_arguments];
|
||||
};
|
||||
|
||||
template <typename T1 = void, typename T2 = void>
|
||||
|
||||
@@ -48,20 +48,66 @@ namespace rpc {
|
||||
|
||||
const torrent::Object
|
||||
CommandFunction::call(Command* rawCommand, target_type target, const torrent::Object& args) {
|
||||
char* buffer[sizeof(torrent::Object) * Command::max_arguments];
|
||||
torrent::Object* stack = (torrent::Object*)buffer;
|
||||
torrent::Object* first = (torrent::Object*)buffer;
|
||||
|
||||
if (args.is_list()) {
|
||||
// Do nothing for now.
|
||||
for (torrent::Object::list_const_iterator itr = args.as_list().begin(), last = args.as_list().end();
|
||||
itr != last && first != stack + Command::max_arguments;
|
||||
itr++, first++) {
|
||||
new (first) torrent::Object(*itr);
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
}
|
||||
|
||||
} else if (args.type() != torrent::Object::TYPE_NONE) {
|
||||
new (first) torrent::Object(args);
|
||||
(first++)->swap(*argument(0));
|
||||
}
|
||||
|
||||
CommandFunction* command = reinterpret_cast<CommandFunction*>(rawCommand);
|
||||
|
||||
parse_command_multiple(target, command->m_command.c_str(), command->m_command.c_str() + command->m_command.size());
|
||||
|
||||
while (first-- != stack) {
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandFunctionList::call(Command* rawCommand, target_type target, const torrent::Object& args) {
|
||||
char* buffer[sizeof(torrent::Object) * Command::max_arguments];
|
||||
torrent::Object* stack = (torrent::Object*)buffer;
|
||||
torrent::Object* first = (torrent::Object*)buffer;
|
||||
|
||||
if (args.is_list()) {
|
||||
// Do nothing for now.
|
||||
for (torrent::Object::list_const_iterator itr = args.as_list().begin(), last = args.as_list().end();
|
||||
itr != last && first != stack + Command::max_arguments;
|
||||
itr++, first++) {
|
||||
new (first) torrent::Object(*itr);
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
}
|
||||
|
||||
} else if (args.type() != torrent::Object::TYPE_NONE) {
|
||||
new (first) torrent::Object(args);
|
||||
(first++)->swap(*argument(0));
|
||||
}
|
||||
|
||||
CommandFunctionList* command = reinterpret_cast<CommandFunctionList*>(rawCommand);
|
||||
|
||||
for (base_type::const_iterator itr = command->begin(), last = command->end(); itr != last; itr++)
|
||||
parse_command_multiple(target, itr->second.c_str(), itr->second.c_str() + itr->second.size());
|
||||
|
||||
while (first-- != stack) {
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
torrent::Object Command::m_arguments[Command::max_arguments];
|
||||
|
||||
CommandMap::~CommandMap() {
|
||||
std::vector<const char*> keys;
|
||||
|
||||
|
||||
@@ -148,4 +148,22 @@ CommandVariable::get_string(Command* rawCommand, cleaned_type target, const torr
|
||||
return variable->m_variable;
|
||||
}
|
||||
|
||||
//
|
||||
// ObjectPtr
|
||||
//
|
||||
|
||||
const torrent::Object
|
||||
CommandObjectPtr::set_generic(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) {
|
||||
CommandObjectPtr* command = static_cast<CommandObjectPtr*>(rawCommand);
|
||||
|
||||
return (*command->m_object = rawArgs);
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandObjectPtr::get_generic(Command* rawCommand, cleaned_type target, const torrent::Object& args) {
|
||||
CommandObjectPtr* command = static_cast<CommandObjectPtr*>(rawCommand);
|
||||
|
||||
return *command->m_object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,6 +68,31 @@ private:
|
||||
torrent::Object m_variable;
|
||||
};
|
||||
|
||||
class CommandObjectPtr : public Command {
|
||||
public:
|
||||
typedef target_wrapper<void>::cleaned_type cleaned_type;
|
||||
|
||||
CommandObjectPtr(torrent::Object* obj = NULL) : m_object(obj) {}
|
||||
|
||||
const torrent::Object* object() const { return m_object; }
|
||||
void set_object(torrent::Object* obj) { m_object = obj; }
|
||||
|
||||
static const torrent::Object set_generic(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
static const torrent::Object get_generic(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
|
||||
// static const torrent::Object set_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
// static const torrent::Object get_bool(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
|
||||
// static const torrent::Object set_value(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
// static const torrent::Object get_value(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
|
||||
// static const torrent::Object set_string(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
// static const torrent::Object get_string(Command* rawCommand, cleaned_type target, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
torrent::Object* m_object;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user