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::Group Class Reference

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

#include <tasktree.h>

+ Inheritance diagram for Tasking::Group:
+ Collaboration diagram for Tasking::Group:

Public Member Functions

 Group (const QList< GroupItem > &children)
 Constructs a group with a given list of children.
 
 Group (std::initializer_list< GroupItem > children)
 Constructs a group from std::initializer_list given by children.
 
- 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.
 

Static Public Member Functions

template<typename Handler >
static GroupItem onGroupSetup (Handler &&handler)
 
template<typename Handler >
static GroupItem onGroupDone (Handler &&handler, CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
 
static GroupItem parallelLimit (int limit)
 
static GroupItem workflowPolicy (WorkflowPolicy policy)
 

Additional Inherited Members

- Public Types inherited from Tasking::GroupItem
using GroupSetupHandler = std::function<SetupResult()>
 
using GroupDoneHandler = std::function<DoneResult(DoneWith)>
 
- 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

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

Group represents the basic element for composing declarative recipes describing how to execute and handle a nested tree of asynchronous tasks. \reentrant

Group is a container for other group items. It encloses child tasks into one unit, which is seen by the group's parent as a single, asynchronous task. Since Group is of the GroupItem type, it may also be a child of Group.

Insert child tasks into the group by using aliased custom task names, such as, ConcurrentCallTask<ResultType> or NetworkQueryTask:

const Group group {
ConcurrentCallTask<int>(...)
};
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:327
CustomTask< NetworkQueryTaskAdapter > NetworkQueryTask
GLboolean GLuint group

The group's behavior may be customized by inserting the items returned by \l {Tasking::parallelLimit()} {parallelLimit()} or \l {Tasking::workflowPolicy()} {workflowPolicy()} functions:

const Group group {
};
const GroupItem continueOnError
const GroupItem parallel

The group may contain nested groups:

const Group group {
}
ConcurrentCallTask<QString>(...)
}
};
const GroupItem finishAllAndSuccess

The group may dynamically instantiate a custom storage structure, which may be used for inter-task data exchange:

struct MyCustomStruct { QByteArray data; };
Storage<MyCustomStruct> storage;
const auto onFirstSetup = [](NetworkQuery &task) { ... };
const auto onFirstDone = [storage](const NetworkQuery &task) {
// storage-> gives a pointer to MyCustomStruct instance,
// created dynamically by the running task tree.
storage->data = task.reply()->readAll();
};
const auto onSecondSetup = [storage](ConcurrentCall<QImage> &task) {
// storage-> gives a pointer to MyCustomStruct. Since the group is sequential,
// the stored MyCustomStruct was already updated inside the onFirstDone handler.
const QByteArray storedData = storage->data;
};
const Group group {
// When the group is entered by a running task tree, it creates MyCustomStruct
// instance dynamically. It is later accessible from all handlers via
// the *storage or storage-> operators.
NetworkQueryTask(onFirstSetup, onFirstDone, CallDoneIf::Success),
ConcurrentCallTask<QImage>(onSecondSetup)
};
\inmodule QtCore
Definition qbytearray.h:57
const GroupItem sequential
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QStorageInfo storage
[1]

Definition at line 326 of file tasktree.h.

Constructor & Destructor Documentation

◆ Group() [1/2]

Tasking::Group::Group ( const QList< GroupItem > & children)
inline

Constructs a group with a given list of children.

This constructor is useful when the child items of the group are not known at compile time, but later, at runtime:

const QStringList sourceList = ...;
QList<GroupItem> groupItems { parallel };
for (const QString &source : sourceList) {
const NetworkQueryTask task(...); // use source for setup handler
groupItems << task;
}
const Group group(groupItems);
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
GLsizei GLsizei GLchar * source

Definition at line 329 of file tasktree.h.

◆ Group() [2/2]

Tasking::Group::Group ( std::initializer_list< GroupItem > children)
inline

Constructs a group from std::initializer_list given by children.

This constructor is useful when all child items of the group are known at compile time:

const Group group {
}
ConcurrentCallTask<QString>(...)
}
};

Definition at line 330 of file tasktree.h.

Member Function Documentation

◆ onGroupDone()

template<typename Handler >
static GroupItem Tasking::Group::onGroupDone ( Handler && handler,
CallDoneIf callDoneIf = CallDoneIf::SuccessOrError )
inlinestatic

Definition at line 338 of file tasktree.h.

◆ onGroupSetup()

template<typename Handler >
static GroupItem Tasking::Group::onGroupSetup ( Handler && handler)
inlinestatic

Definition at line 334 of file tasktree.h.

◆ parallelLimit()

static GroupItem Tasking::GroupItem::parallelLimit ( int limit)
inlinestatic

Definition at line 274 of file tasktree.h.

Referenced by Tasking::parallelLimit().

+ Here is the caller graph for this function:

◆ workflowPolicy()

static GroupItem Tasking::GroupItem::workflowPolicy ( WorkflowPolicy policy)
inlinestatic

Definition at line 275 of file tasktree.h.

Referenced by Tasking::workflowPolicy().

+ Here is the caller graph for this function:

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