Taskolib
1.3.3
|
A step is the main building block of a sequence.
Each step consists of a label, a script, and various other attributes. Steps can be of different types (see Step::Type) - for instance, "action" steps hold a script that can simply be executed, "if" steps hold a script that can be evaluated to determine if a condition is fulfilled, "end" steps mark the closing of a block in a sequence.
#include <Step.h>
Public Types | |
enum | Type { type_action , type_if , type_else , type_elseif , type_end , type_while , type_try , type_catch } |
An enum for differentiating the different types of step. More... | |
Public Member Functions | |
Step (Type type=type_action) | |
Construct a Step of a certain type. More... | |
bool | execute (Context &context, CommChannel *comm_channel=nullptr, OptionalStepIndex opt_step_index=gul14::nullopt, TimeoutTrigger *sequence_timeout=nullptr) |
Execute the step script within the given context, sending status information to a message queue. More... | |
const VariableNames & | get_used_context_variable_names () const |
Retrieve the names of the variables that should be im-/exported to and from the context. More... | |
short | get_indentation_level () const noexcept |
Return the indentation level of this step. More... | |
const std::string & | get_label () const |
Return the label of the step. More... | |
const std::string & | get_script () const |
Return the script. More... | |
TimePoint | get_time_of_last_execution () const |
Return the timestamp of the last execution of this step's script. More... | |
TimePoint | get_time_of_last_modification () const |
Return the timestamp of the last modification of this step's script or label. More... | |
Timeout | get_timeout () const |
Return the timeout duration for executing the script. More... | |
Type | get_type () const noexcept |
Return the type of this step. More... | |
bool | is_running () const noexcept |
Return whether this step is currently being executed. More... | |
bool | is_disabled () const noexcept |
Return whether this step is currently disabled. More... | |
Step & | set_disabled (bool disable) |
Set whether the step should be disabled (or possibly executed). More... | |
Step & | set_indentation_level (short level) |
Set the indentation level of this step. More... | |
Step & | set_label (const std::string &label) |
Set the label. More... | |
Step & | set_running (bool is_running) |
Set whether the step should be marked as "currently running". More... | |
Step & | set_script (const std::string &script) |
Set the script that should be executed when this step is run. More... | |
Step & | set_time_of_last_execution (TimePoint t) |
Set the timestamp of the last execution of this step's script. More... | |
Step & | set_time_of_last_modification (TimePoint t) |
Set the timestamp of the last modification of this step's script or label. More... | |
Step & | set_timeout (Timeout timeout) |
Set the timeout duration for executing the script. More... | |
Step & | set_type (Type type) |
Set the type of this step. More... | |
Step & | set_used_context_variable_names (const VariableNames &used_context_variable_names) |
Set the names of the variables that should be im-/exported from/to the script. More... | |
Step & | set_used_context_variable_names (VariableNames &&used_context_variable_names) |
Static Public Attributes | |
static constexpr short | max_indentation_level { 20 } |
Maximum allowed level of indentation (or nesting of steps) More... | |
Private Member Functions | |
void | copy_used_variables_from_context_to_lua (const Context &context, sol::state &lua) |
Copy the variables listed in used_context_variable_names_ from the given Context into a Lua state. More... | |
void | copy_used_variables_from_lua_to_context (const sol::state &lua, Context &context) |
Copy the variables listed in used_context_variable_names_ from a Lua state into the given Context. More... | |
bool | execute_impl (Context &context, CommChannel *comm_channel, OptionalStepIndex index, TimeoutTrigger *sequence_timeout) |
Execute the Lua script, throwing an exception if anything goes wrong. More... | |
Private Attributes | |
std::string | label_ |
std::string | script_ |
VariableNames | used_context_variable_names_ |
TimePoint | time_of_last_modification_ { Clock::now() } |
TimePoint | time_of_last_execution_ |
Timeout | timeout_ |
Type | type_ { type_action } |
short | indentation_level_ { 0 } |
bool | is_running_ { false } |
bool | is_disabled_ { false } |
enum task::Step::Type |
|
inlineexplicit |
Construct a Step of a certain type.
|
private |
Copy the variables listed in used_context_variable_names_ from the given Context into a Lua state.
References task::Context::variables.
|
private |
Copy the variables listed in used_context_variable_names_ from a Lua state into the given Context.
References task::Context::variables.
bool task::Step::execute | ( | Context & | context, |
CommChannel * | comm_channel = nullptr , |
||
OptionalStepIndex | opt_step_index = gul14::nullopt , |
||
TimeoutTrigger * | sequence_timeout = nullptr |
||
) |
Execute the step script within the given context, sending status information to a message queue.
This function performs the following steps:
Certain step types (IF, ELSEIF, WHILE) require the script to return a boolean value. Not returning a value or returning a different type is considered an error. Conversely, the other step types (ACTION etc.) do not allow returning values from the script, with the exception of nil.
context | The context to be used for executing the step |
comm_channel | Pointer to a communication channel; If this is null, messaging is disabled and there is no way to stop the execution. Otherwise, termination requests are honored and the queue receives the following messages:
|
opt_step_index | Optional index of the step in its parent Sequence (to be used in exceptions and messages) |
sequence_timeout | Pointer to a sequence timeout to determine a timeout during executing a step. If this is null the corresponding check for timeout is omitted. |
Error | is thrown if the script cannot be started, if there is a Lua error during execution, if the script has an inappropriate return value for the step type (see above), if a timeout is encountered, or if termination has been requested via the communication channel or explicitly by the script. |
References task::remove_abort_markers(), task::requires_bool_return_value(), and task::send_message().
|
private |
Execute the Lua script, throwing an exception if anything goes wrong.
References task::execute_lua_script(), task::executes_script(), task::install_custom_commands(), task::install_timeout_and_termination_request_hook(), task::open_safe_library_subset(), task::requires_bool_return_value(), task::Context::step_setup_function, task::Context::step_setup_script, and task::to_string().
|
inlinenoexcept |
Return the indentation level of this step.
Zero indicates a top-level step and each additional level stands for one level of nesting inside a block statement such as IF, WHILE, CATCH, and so on.
References indentation_level_.
Referenced by task::Sequence::enforce_consistency_of_disabled_flags().
|
inline |
Return the label of the step.
References label_.
Referenced by task::operator<<().
|
inline |
Return the script.
References script_.
Referenced by task::operator<<().
|
inline |
Return the timestamp of the last execution of this step's script.
A default-constructed TimePoint{}
is returned to indicate that the object was never executed since its creation.
References time_of_last_execution_.
Referenced by task::operator<<().
|
inline |
Return the timestamp of the last modification of this step's script or label.
A default-constructed TimePoint{}
is returned to indicate that the object was never modified since its creation.
References time_of_last_modification_.
Referenced by task::operator<<().
|
inline |
Return the timeout duration for executing the script.
References timeout_.
Referenced by task::operator<<().
|
inlinenoexcept |
|
inline |
Retrieve the names of the variables that should be im-/exported to and from the context.
The variables with the listed names are imported from the context into the script environment before running the script and are afterwards exported back into it.
References used_context_variable_names_.
Referenced by task::operator<<().
|
inlinenoexcept |
Return whether this step is currently disabled.
References is_disabled_.
Referenced by task::operator<<().
|
inlinenoexcept |
Return whether this step is currently being executed.
This flag is normally set by an Executor.
References is_running_.
Step & task::Step::set_disabled | ( | bool | disable | ) |
Set whether the step should be disabled (or possibly executed).
Referenced by task::Sequence::enforce_consistency_of_disabled_flags().
Step & task::Step::set_indentation_level | ( | short | level | ) |
Set the indentation level of this step.
level | New indentation level; Zero indicates a top-level step and each additional level stands for one level of nesting inside a block statement such as IF, WHILE, CATCH, and so on. |
Error | is thrown if level < 0 or level > max_indentation_level. |
Step & task::Step::set_label | ( | const std::string & | label | ) |
Set the label.
This call also updates the time of last modification to the current system time.
Labels must not start or end with whitespace; existing whitespace is silently removed.
Step & task::Step::set_running | ( | bool | is_running | ) |
Set whether the step should be marked as "currently running".
This is normally done by an Executor.
Referenced by task::Executor::update().
Step & task::Step::set_script | ( | const std::string & | script | ) |
Set the script that should be executed when this step is run.
Syntax or semantics of the script are not checked.
Referenced by task::operator>>().
Set the timestamp of the last execution of this step's script.
This function should be called when an external execution engine starts the embedded script or when the Step has been restored from serialized form.
Set the timestamp of the last modification of this step's script or label.
This function is only useful to restore a step from some serialized form, e.g. from a file.
Referenced by task::operator>>().
Set the timeout duration for executing the script.
Referenced by task::operator>>().
Set the type of this step.
This call also updates the time of last modification to the current system time.
Step & task::Step::set_used_context_variable_names | ( | const VariableNames & | used_context_variable_names | ) |
Set the names of the variables that should be im-/exported from/to the script.
Step & task::Step::set_used_context_variable_names | ( | VariableNames && | used_context_variable_names | ) |
|
private |
Referenced by get_indentation_level().
|
private |
Referenced by is_disabled().
|
private |
Referenced by is_running().
|
private |
Referenced by get_label().
|
staticconstexpr |
Maximum allowed level of indentation (or nesting of steps)
Referenced by task::Sequence::indent().
|
private |
Referenced by get_script().
|
private |
Referenced by get_time_of_last_execution().
|
private |
Referenced by get_time_of_last_modification().
|
private |
Referenced by get_timeout().
|
private |
Referenced by get_type().
|
private |
Referenced by get_used_context_variable_names().