* 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:
rakshasa
2008-11-09 12:56:10 +00:00
parent ca9d0b1773
commit 5166253190
9 changed files with 123 additions and 0 deletions
+9
View File
@@ -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>
+46
View File
@@ -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();
}
+2
View File
@@ -55,6 +55,8 @@
namespace rpc {
torrent::Object Command::m_arguments[Command::max_arguments];
CommandMap::~CommandMap() {
std::vector<const char*> keys;
+18
View File
@@ -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;
}
}
+25
View File
@@ -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