mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 20:52:30 +00:00
* Allow inlining functions in commands with parantheses, e.g:
print = (convert.time,(system.time)) schedule2 = test_print_2,2,2,((print,"current ",((convert.time,((system.time)))))) Multiple parantheses need to be used in schedule to ensure the command doesn't get evaluated at the time of calling schedule. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1191 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -97,7 +97,22 @@ CommandScheduler::call_item(value_type item) {
|
||||
// removed.
|
||||
|
||||
try {
|
||||
rpc::parse_command_multiple_std(item->command());
|
||||
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.
|
||||
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());
|
||||
}
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
if (m_slotErrorMessage.is_valid())
|
||||
@@ -119,13 +134,19 @@ CommandScheduler::call_item(value_type item) {
|
||||
}
|
||||
|
||||
void
|
||||
CommandScheduler::parse(const std::string& key, const std::string& bufAbsolute, const std::string& bufInterval, const std::string& command) {
|
||||
CommandScheduler::parse(const std::string& key,
|
||||
const std::string& bufAbsolute,
|
||||
const std::string& bufInterval,
|
||||
const torrent::Object& command) {
|
||||
if (!command.is_string() && !command.is_dict_key())
|
||||
throw torrent::bencode_error("Invalid type passed to command scheduler.");
|
||||
|
||||
uint32_t absolute = parse_absolute(bufAbsolute.c_str());
|
||||
uint32_t interval = parse_interval(bufInterval.c_str());
|
||||
|
||||
CommandSchedulerItem* item = *insert(key);
|
||||
|
||||
item->set_command(command);
|
||||
item->command() = command;
|
||||
item->set_interval(interval);
|
||||
|
||||
item->enable((cachedTime + rak::timer::from_seconds(absolute)).round_seconds());
|
||||
|
||||
Reference in New Issue
Block a user