Taskolib  1.3.3
Executor.h
Go to the documentation of this file.
1 
23 // SPDX-License-Identifier: LGPL-2.1-or-later
24 
25 #ifndef TASKOLIB_EXECUTOR_H_
26 #define TASKOLIB_EXECUTOR_H_
27 
28 #include <future>
29 #include <memory>
30 
31 #include "taskolib/CommChannel.h"
32 #include "taskolib/Context.h"
33 #include "taskolib/Sequence.h"
34 #include "taskolib/StepIndex.h"
35 
36 namespace task {
37 
69 class Executor
70 {
71 public:
73  Executor();
74 
75  // Not copyable but movable (you can't copy a future)
76  Executor(Executor const&) = delete;
77  Executor& operator=(Executor const&) = delete;
78  Executor(Executor&&) = default;
79  Executor& operator=(Executor&&) = default;
80 
81  ~Executor() { cancel(); };
82 
92  void cancel();
93 
102  void cancel(Sequence& sequence);
103 
115  void run_asynchronously(Sequence& sequence, Context context);
116 
130  void run_single_step_asynchronously(Sequence& sequence, Context context,
131  StepIndex step_index);
132 
143  bool update(Sequence& sequence);
144 
156 
157 private:
165  std::shared_ptr<CommChannel> comm_channel_;
166 
172  std::future<VariableTable> future_;
173 
180 
194  void launch_async_execution(Sequence& sequence, Context context,
195  OptionalStepIndex step_index);
196 
206  bool is_busy();
207 };
208 
209 } // namespace task
210 
211 #endif
Declaration of the CommChannel struct.
Declaration of the Context and VariableValue types.
A sequence of Steps.
Declaration of the StepIndex type.
An executor runs a copy of a given Sequence (or just a single step within it) in a separate thread,...
Definition: Executor.h:70
Executor & operator=(Executor const &)=delete
std::future< VariableTable > future_
A future for the result of the execution thread.
Definition: Executor.h:172
Context context_
A local copy of the context that was used to start the last sequence.
Definition: Executor.h:179
bool is_busy()
Determine if the executor is currently running a sequence in a separate thread.
Definition: Executor.cc:88
~Executor()
Definition: Executor.h:81
Executor(Executor &&)=default
void cancel()
Terminate a running sequence.
Definition: Executor.cc:67
void run_single_step_asynchronously(Sequence &sequence, Context context, StepIndex step_index)
Start a single step of the given sequence in a separate thread.
Definition: Executor.cc:126
Executor(Executor const &)=delete
void run_asynchronously(Sequence &sequence, Context context)
Start a copy of the given sequence in a separate thread.
Definition: Executor.cc:121
Executor & operator=(Executor &&)=default
void launch_async_execution(Sequence &sequence, Context context, OptionalStepIndex step_index)
Start a sequence- or single-step-execution function in a separate thread.
Definition: Executor.cc:102
bool update(Sequence &sequence)
Update the local copy of the sequence from messages that have arrived from the execution thread.
Definition: Executor.cc:135
Executor()
Construct an Executor.
Definition: Executor.cc:62
VariableTable get_context_variables()
Retrieve the variables stored in the context.
Definition: Executor.h:155
std::shared_ptr< CommChannel > comm_channel_
Communications channel between the main thread and the executing thread.
Definition: Executor.h:165
A sequence of steps that can be modified and executed.
Definition: Sequence.h:160
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
std::uint16_t StepIndex
A type for storing the index of a Step in a Sequence.
Definition: StepIndex.h:34
gul14::optional< StepIndex > OptionalStepIndex
An optional step index (gul14::optional<StepIndex>).
Definition: StepIndex.h:37
std::unordered_map< VariableName, VariableValue > VariableTable
Associative table that holds Lua variable names and their value.
Definition: Context.h:80
A context stores information that influences the execution of steps and sequences,...
Definition: Context.h:128
VariableTable variables
A map of variables (names and values) that can be im-/exported into steps.
Definition: Context.h:130