|
DynExp
Highly flexible laboratory automation for dynamically changing experiments.
|
Default task which does not do anything. Though, calling it ensures that TaskBase::CallbackFunc gets called. This is required to avoid InstrumentBase::AsSyncTask() getting stuck in an infinite loop. All functions overridden from meta instruments, which are expected to enqueue a task, must at least enqueue a DefaultTask (by calling MakeAndEnqueueTask< DynExp::DefaultTask >(std::move(CallbackFunc));). Moreover, this task can be used to defer the task queue execution by setting the DeferUntil parameter.
More...
#include <Instrument.h>
Inheritance diagram for DynExp::DefaultTask:Public Member Functions | |
| DefaultTask (CallbackType CallbackFunc, std::chrono::system_clock::time_point DeferUntil={}) noexcept | |
| Constructs an instrument task. | |
Public Member Functions inherited from DynExp::TaskBase | |
| TaskBase (CallbackType CallbackFunc=nullptr, std::chrono::system_clock::time_point DeferUntil={}) noexcept | |
| Constructs an instrument task. | |
| TaskBase (TaskBase &Other, std::chrono::system_clock::time_point DeferUntil={}) noexcept | |
| Constructs an instrument task, moving CallbackFunc from another task to this task. The other task is left with a CallbackFunc that will not be executed anymore after this operation. Using this constructor is useful, if a running task enqueues (an)other task(s). In this case, the callback function should not be called by the original task but by the last task in this chain of tasks. | |
| virtual | ~TaskBase ()=0 |
The destructor aborts a waiting task setting State to TaskState::Aborted. Then, it calls CallbackFunc with a default-constructed ExceptionContainer instance. | |
| auto | GetDeferUntil () const noexcept |
| Getter for the instrument task's earliest execution time point. | |
| TaskState | GetState () const noexcept |
| Getter for the instrument task's current state. | |
| bool | IsLocked () const noexcept |
| Determines whether the task is locked. | |
| bool | IsAborting () const noexcept |
| Determines whether the task should abort. A derived task is encouraged to call this method before performing any action or in between the individual steps of a more complex action. | |
| int | GetErrorCode () const noexcept |
| Getter for the error code related to an error possibly occurred while the task was executed. | |
| void | Abort () |
Requests the task to abort. There is no guarantee that the derived task does call IsAborting() to check whether it should abort. The task could have finished already or the implementation of RunChild() in the derived class does not allow for aborting. | |
Private Member Functions | |
| virtual TaskResultType | RunChild (InstrumentInstance &Instance) override |
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChild() will terminate the instrument thread. In this case, the instrument has to be reset in order to restart it. For minor errors occurring in RunChild(), return a TaskResultType instance with TaskResultType::ErrorCode set to an appropriate (non-zero) value. This sets State to TaskState::Failed. Note that in this case there might be no way to retrieve the error if finished tasks are not kept (i.e. KeepFinishedTask() returns false) and if no CallbackFunc has been set. RunChild() is supposed to check the return value of IsAborting(). | |
Additional Inherited Members | |
Public Types inherited from DynExp::TaskBase | |
| enum class | TaskState { Waiting , Locked , Running , Finished , Failed , Aborted } |
| Defines states an instrument's task can undergo. Possible state transitions are: More... | |
Public Attributes inherited from DynExp::TaskBase | |
| InstrumentBaseOnlyType | InstrumentBaseOnly |
Allow exclusive access to some of TaskBase's private methods to InstrumentBase. | |
| InstrumentDataBaseOnlyType | InstrumentDataBaseOnly |
Allow exclusive access to some of TaskBase's private methods to InstrumentDataBase. | |
Default task which does not do anything. Though, calling it ensures that TaskBase::CallbackFunc gets called. This is required to avoid InstrumentBase::AsSyncTask() getting stuck in an infinite loop. All functions overridden from meta instruments, which are expected to enqueue a task, must at least enqueue a DefaultTask (by calling MakeAndEnqueueTask< DynExp::DefaultTask >(std::move(CallbackFunc));). Moreover, this task can be used to defer the task queue execution by setting the DeferUntil parameter.
Definition at line 1248 of file Instrument.h.
|
inlinenoexcept |
Constructs an instrument task.
| CallbackFunc | This callback function is called after the task has finished (either successfully or not) with a pointer to the current task and with a reference to the exception which occurred during the task execution (if an exception has occurred). |
| DeferUntil | The execution of this task is deferred until the specified point in time is reached if time_since_epoch() of DeferUntil is non-zero. Tasks being deferred block the task queue of the instrument they are assigned to, i.e., other enqueued tasks do not run before this task to maintain the task order. If the task does not support being deferred, the DeferUntil parameter is not available in the task's constructor. |
Definition at line 1254 of file Instrument.h.
|
inlineoverrideprivatevirtual |
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChild() will terminate the instrument thread. In this case, the instrument has to be reset in order to restart it. For minor errors occurring in RunChild(), return a TaskResultType instance with TaskResultType::ErrorCode set to an appropriate (non-zero) value. This sets State to TaskState::Failed. Note that in this case there might be no way to retrieve the error if finished tasks are not kept (i.e. KeepFinishedTask() returns false) and if no CallbackFunc has been set. RunChild() is supposed to check the return value of IsAborting().
| Instance | Handle to the instrument thread's data |
| Util::InvalidStateException | is thrown if the task is not in the TaskState::Waiting or TaskState::Locked state. |
Implements DynExp::TaskBase.
Definition at line 1258 of file Instrument.h.