Allow functions and lists of functions to be passed to view.event_{added,removed}.

This commit is contained in:
rakshasa
2012-05-04 21:31:12 +09:00
parent 8d0f9b3300
commit fb75510c0f
8 changed files with 77 additions and 69 deletions
+1 -18
View File
@@ -97,24 +97,7 @@ CommandScheduler::call_item(value_type item) {
// removed.
try {
if (item->command().is_string()) {
rpc::parse_command_multiple_std(item->command().as_string());
} else if (item->command().is_dict_key()) {
// This can/should be optimized...
torrent::Object tmp_command = item->command();
// Unquote the root function object so 'parse_command_execute'
// doesn't end up calling it.
//
// TODO: Only call this if mask_function is set?
uint32_t flags = tmp_command.flags() & torrent::Object::mask_function;
tmp_command.unset_flags(torrent::Object::mask_function);
tmp_command.set_flags((flags >> 1) & torrent::Object::mask_function);
rpc::parse_command_execute(rpc::make_target(), &tmp_command);
rpc::commands.call_command(tmp_command.as_dict_key().c_str(), tmp_command.as_dict_obj());
}
rpc::call_object(item->command());
} catch (torrent::input_error& e) {
if (m_slotErrorMessage.is_valid())
+33
View File
@@ -239,6 +239,39 @@ parse_command_file(const std::string& path) {
return true;
}
void
call_object(const torrent::Object& command, target_type target) {
switch (command.type()) {
case torrent::Object::TYPE_STRING:
parse_command_multiple(target, command.as_string().c_str(), command.as_string().c_str() + command.as_string().size());
break;
case torrent::Object::TYPE_LIST:
for (torrent::Object::list_const_iterator itr = command.as_list().begin(), last = command.as_list().end(); itr != last; itr++)
call_object(*itr, target);
break;
case torrent::Object::TYPE_DICT_KEY:
{
// This can/should be optimized...
torrent::Object tmp_command = command;
// Unquote the root function object so 'parse_command_execute'
// doesn't end up calling it.
//
// TODO: Only call this if mask_function is set?
uint32_t flags = tmp_command.flags() & torrent::Object::mask_function;
tmp_command.unset_flags(torrent::Object::mask_function);
tmp_command.set_flags((flags >> 1) & torrent::Object::mask_function);
parse_command_execute(make_target(), &tmp_command);
commands.call_command(tmp_command.as_dict_key().c_str(), tmp_command.as_dict_obj(), target);
}
default:
break;
}
}
//
//
//
+12
View File
@@ -124,6 +124,18 @@ call_command_d_range(const char* key, core::Download* download, torrent::Object:
return commands.call_command_d(key, download, rawArgs);
}
void call_object(const torrent::Object& command, target_type target = make_target());
inline void
call_object_nothrow(const torrent::Object& command, target_type target = make_target()) {
try { call_object(command, target); } catch (torrent::input_error& e) {}
}
inline void
call_object_d_nothrow(const torrent::Object& command, core::Download* download) {
try { call_object(command, make_target(download)); } catch (torrent::input_error& e) {}
}
//
//
//