Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
Tasking::CustomTask< Adapter > Class Template Referencefinal

\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution More...

#include <tasktree.h>

+ Inheritance diagram for Tasking::CustomTask< Adapter >:
+ Collaboration diagram for Tasking::CustomTask< Adapter >:

Public Types

using Task = typename Adapter::TaskType
 
using Deleter = typename Adapter::DeleterType
 
using TaskSetupHandler = std::function<SetupResult(Task &)>
 
using TaskDoneHandler = std::function<DoneResult(const Task &, DoneWith)>
 
- Public Types inherited from Tasking::GroupItem
using GroupSetupHandler = std::function<SetupResult()>
 
using GroupDoneHandler = std::function<DoneResult(DoneWith)>
 

Public Member Functions

template<typename SetupHandler = TaskSetupHandler, typename DoneHandler = TaskDoneHandler>
 CustomTask (SetupHandler &&setup=TaskSetupHandler(), DoneHandler &&done=TaskDoneHandler(), CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
 \typealias CustomTask::Task
 
- Public Member Functions inherited from Tasking::ExecutableItem
ExecutableItem withTimeout (std::chrono::milliseconds timeout, const std::function< void()> &handler={}) const
 Attaches TimeoutTask to a copy of this ExecutableItem, elapsing after timeout in milliseconds, with an optionally provided timeout handler, and returns the coupled item.
 
ExecutableItem withLog (const QString &logName) const
 Attaches a custom debug printout to a copy of this ExecutableItem, issued on task startup and after the task is finished, and returns the coupled item.
 
template<typename SenderSignalPairGetter >
ExecutableItem withCancel (SenderSignalPairGetter &&getter) const
 
- Public Member Functions inherited from Tasking::GroupItem
template<typename StorageStruct >
 GroupItem (const Storage< StorageStruct > &storage)
 Constructs a GroupItem element holding the storage object.
 
 GroupItem (const Loop &loop)
 
 GroupItem (const QList< GroupItem > &children)
 Constructs a GroupItem element with a given list of items.
 
 GroupItem (std::initializer_list< GroupItem > children)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Additional Inherited Members

- Protected Types inherited from Tasking::GroupItem
enum class  Type {
  List , Group , GroupData , Storage ,
  TaskHandler
}
 
using InterfaceCreateHandler = std::function<TaskInterface *(void)>
 
using InterfaceSetupHandler = std::function<SetupResult(TaskInterface &)>
 
using InterfaceDoneHandler = std::function<DoneResult(const TaskInterface &, DoneWith)>
 
- Protected Member Functions inherited from Tasking::ExecutableItem
 ExecutableItem ()=default
 
 ExecutableItem (const TaskHandler &handler)
 
- Protected Member Functions inherited from Tasking::GroupItem
 GroupItem ()=default
 
 GroupItem (Type type)
 
 GroupItem (const GroupData &data)
 
 GroupItem (const TaskHandler &handler)
 
void addChildren (const QList< GroupItem > &children)
 
- Static Protected Member Functions inherited from Tasking::GroupItem
static GroupItem groupHandler (const GroupHandler &handler)
 
static GroupItem parallelLimit (int limit)
 
static GroupItem workflowPolicy (WorkflowPolicy policy)
 
template<typename Result , typename Function , typename ... Args, typename DecayedFunction = std::decay_t<Function>>
static constexpr bool isInvocable ()
 

Detailed Description

template<typename Adapter>
class Tasking::CustomTask< Adapter >

\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution

A class template used for declaring custom task items and defining their setup and done handlers. \reentrant

Describes custom task items within task tree recipes.

Custom task names are aliased with unique names using the CustomTask template with a given TaskAdapter subclass as a template parameter. For example, ConcurrentCallTask<T> is an alias to the CustomTask that is defined to work with ConcurrentCall<T> as an associated task class. The following table contains example custom tasks and their associated task classes:

\table \header

  • Aliased Task Name (Tasking Namespace)
  • Associated Task Class
  • Brief Description \row
  • ConcurrentCallTask<ReturnType>
  • ConcurrentCall<ReturnType>
  • Starts an asynchronous task. Runs in a separate thread. \row
  • NetworkQueryTask
  • NetworkQuery
  • Sends a network query. \row
  • TaskTreeTask
  • TaskTree
  • Starts a nested task tree. \row
  • TimeoutTask
  • std::chrono::milliseconds
  • Starts a timer. \row
  • WaitForBarrierTask
  • MultiBarrier<Limit>
  • Starts an asynchronous task waiting for the barrier to pass. \endtable

Definition at line 467 of file tasktree.h.

Member Typedef Documentation

◆ Deleter

template<typename Adapter >
using Tasking::CustomTask< Adapter >::Deleter = typename Adapter::DeleterType

Definition at line 471 of file tasktree.h.

◆ Task

template<typename Adapter >
using Tasking::CustomTask< Adapter >::Task = typename Adapter::TaskType

Definition at line 470 of file tasktree.h.

◆ TaskDoneHandler

template<typename Adapter >
using Tasking::CustomTask< Adapter >::TaskDoneHandler = std::function<DoneResult(const Task &, DoneWith)>

Definition at line 476 of file tasktree.h.

◆ TaskSetupHandler

template<typename Adapter >
using Tasking::CustomTask< Adapter >::TaskSetupHandler = std::function<SetupResult(Task &)>

Definition at line 475 of file tasktree.h.

Constructor & Destructor Documentation

◆ CustomTask()

template<typename Adapter >
template<typename SetupHandler = TaskSetupHandler, typename DoneHandler = TaskDoneHandler>
template< typename Adapter > template< typename SetupHandler=TaskSetupHandler, typename DoneHandler=TaskDoneHandler > Tasking::CustomTask< Adapter >::CustomTask ( SetupHandler && setup = TaskSetupHandler(),
DoneHandler && done = TaskDoneHandler(),
CallDoneIf callDoneIf = CallDoneIf::SuccessOrError )
inline

\typealias CustomTask::Task

Type alias for the task type associated with the custom task's Adapter.

\typealias CustomTask::Deleter

Type alias for the task's type deleter associated with the custom task's Adapter.

\typealias CustomTask::TaskSetupHandler

Type alias for std::function<SetupResult(Task &)>.

The TaskSetupHandler is an optional argument of a custom task element's constructor. Any function with the above signature, when passed as a task setup handler, will be called by the running task tree after the task is created and before it is started.

Inside the body of the handler, you may configure the task according to your needs. The additional parameters, including storages, may be passed to the handler via the lambda capture. You can decide dynamically whether the task should be started or skipped with success or an error.

Note
Do not start the task inside the start handler by yourself. Leave it for TaskTree, otherwise the behavior is undefined.

The return value of the handler instructs the running task tree on how to proceed after the handler's invocation is finished. The return value of SetupResult::Continue instructs the task tree to continue running, that is, to execute the associated Task. The return value of SetupResult::StopWithSuccess or SetupResult::StopWithError instructs the task tree to skip the task's execution and finish it immediately with success or an error, respectively.

When the return type is either SetupResult::StopWithSuccess or SetupResult::StopWithError, the task's done handler (if provided) isn't called afterwards.

The constructor of a custom task accepts also functions in the shortened form of std::function<void(Task &)>, that is, the return value is void. In this case, it's assumed that the return value is SetupResult::Continue.

See also
CustomTask(), TaskDoneHandler, GroupSetupHandler

\typealias CustomTask::TaskDoneHandler

Type alias for std::function<DoneResult(const Task &, DoneWith)>.

The TaskDoneHandler is an optional argument of a custom task element's constructor. Any function with the above signature, when passed as a task done handler, will be called by the running task tree after the task execution finished and before the final result of the execution is reported back to the parent group.

Inside the body of the handler you may retrieve the final data from the finished task. The additional parameters, including storages, may be passed to the handler via the lambda capture. It is also possible to decide dynamically whether the task should finish with its return value, or the final result should be tweaked.

The DoneWith argument is optional and your done handler may omit it. When provided, it holds the info about the final result of a task that will be reported to its parent.

If you do not plan to read any data from the finished task, you may omit the {const Task &} argument.

The returned DoneResult value is optional and your handler may return void instead. In this case, the final result of the task will be equal to the value indicated by the DoneWith argument. When the handler returns the DoneResult value, the task's final result may be tweaked inside the done handler's body by the returned value.

See also
CustomTask(), TaskSetupHandler, GroupDoneHandler

Constructs a CustomTask instance and attaches the setup and done handlers to the task. When the running task tree is about to start the task, it instantiates the associated \l Task object, invokes setup handler with a reference to the created task, and starts it. When the running task finishes, the task tree invokes a done handler, with a const reference to the created task.

The passed setup handler is of the \l TaskSetupHandler type. For example:

static void parseAndLog(const QString &input);
...
const QString input = ...;
const auto onFirstSetup = [input](ConcurrentCall<void> &task) {
if (input == "Skip")
return SetupResult::StopWithSuccess; // This task won't start, the next one will
if (input == "Error")
return SetupResult::StopWithError; // This task and the next one won't start
task.setConcurrentCallData(parseAndLog, input);
// This task will start, and the next one will start after this one finished with success
};
const auto onSecondSetup = [input](ConcurrentCall<void> &task) {
task.setConcurrentCallData(parseAndLog, input);
};
const Group group {
ConcurrentCallTask<void>(onFirstSetup),
ConcurrentCallTask<void>(onSecondSetup)
};
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
GLboolean GLuint group
GLenum GLenum GLenum input

The done handler is of the \l TaskDoneHandler type. By default, the done handler is invoked whenever the task finishes. Pass a non-default value for the callDoneIf argument when you want the handler to be called only on a successful or failed execution.

See also
TaskSetupHandler, TaskDoneHandler

Definition at line 479 of file tasktree.h.

References done.


The documentation for this class was generated from the following files: