Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
tasktreerunner.h
Go to the documentation of this file.
1// Copyright (C) 2024 Jarek Kobus
2// Copyright (C) 2024 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef TASKING_TASKTREERUNNER_H
6#define TASKING_TASKTREERUNNER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "tasking_global.h"
20#include "tasktree.h"
21
22#include <QtCore/QObject>
23
25
26namespace Tasking {
27
29{
31
32public:
33 using SetupHandler = std::function<void(TaskTree *)>;
35
37
38 bool isRunning() const { return bool(m_taskTree); }
39
40 // When task tree is running it resets the old task tree.
41 void start(const Group &recipe,
42 const SetupHandler &setupHandler = {},
43 const DoneHandler &doneHandler = {});
44
45 // When task tree is running it emits done(DoneWith::Cancel) synchronously.
46 void cancel();
47
48 // No done() signal is emitted.
49 void reset();
50
53 void done(DoneWith result);
54
55private:
56 std::unique_ptr<TaskTree> m_taskTree;
57};
58
59} // namespace Tasking
60
61QT_END_NAMESPACE
62
63#endif // TASKING_TASKTREERUNNER_H
void setupDownload(NetworkQuery *query, const QString &progressText)
void setProgress(int progressValue, int progressMaximum, const QString &progressText)
void clearProgress(const QString &progressText)
void updateProgress(int progressValue, int progressMaximum)
std::unique_ptr< QNetworkAccessManager > m_manager
std::unique_ptr< QTemporaryDir > m_temporaryDir
void progressChanged(int progressValue, int progressMaximum, const QString &progressText)
void localDownloadDirChanged(const QUrl &url)
void setOfflineAssetsFilePath(const QUrl &offlineAssetsFilePath)
virtual QUrl resolvedUrl(const QUrl &url) const
void setJsonFileName(const QString &jsonFileName)
void jsonFileNameChanged(const QString &)
void downloadBaseChanged(const QUrl &)
void setPreferredLocalDownloadDir(const QUrl &localDir)
void offlineAssetsFilePathChanged(const QUrl &)
void setDownloadBase(const QUrl &downloadBase)
void setZipFileName(const QString &zipFileName)
void zipFileNameChanged(const QString &)
void preferredLocalDownloadDirChanged(const QUrl &url)
void start() final
This method is called by the running TaskTree for starting the Task instance.
void setThreadPool(QThreadPool *pool)
QFuture< ResultType > future() const
QList< ResultType > results() const
ResultType result() const
void setConcurrentCallData(Function &&function, Args &&...args)
typename Adapter::TaskType Task
Definition tasktree.h:551
typename Adapter::DeleterType Deleter
Definition tasktree.h:552
std::function< SetupResult(Task &)> TaskSetupHandler
Definition tasktree.h:556
CustomTask(SetupHandler &&setup=TaskSetupHandler(), DoneHandler &&done=TaskDoneHandler(), CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
\typealias Tasking::CustomTask::Task
Definition tasktree.h:560
Do(std::initializer_list< GroupItem > children)
Definition tasktree.h:491
Do(const GroupItems &children)
Definition tasktree.h:490
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:317
Group withCancel(SenderSignalPairGetter &&getter, std::initializer_list< GroupItem > postCancelRecipe={}) const
Definition tasktree.h:416
ExecutableItem(const TaskHandler &handler)
Definition tasktree.h:329
Group withLog(const QString &logName) const
Attaches a custom debug printout to a copy of this ExecutableItem, issued on task startup and after t...
Group withTimeout(std::chrono::milliseconds timeout, const std::function< void()> &handler={}) const
Attaches TimeoutTask to a copy of this ExecutableItem, elapsing after timeout in milliseconds,...
Group withAccept(SenderSignalPairGetter &&getter) const
Definition tasktree.h:429
For(const Loop &loop)
Definition tasktree.h:477
Forever(const GroupItems &children)
Definition tasktree.h:503
Forever(std::initializer_list< GroupItem > children)
Definition tasktree.h:505
\typealias Tasking::GroupItems
Definition tasktree.h:226
GroupItem(const Loop &loop)
Definition tasktree.h:243
GroupItem(std::initializer_list< GroupItem > children)
Definition tasktree.h:240
GroupItem(const TaskHandler &handler)
Definition tasktree.h:284
GroupItem(const GroupData &data)
Definition tasktree.h:281
GroupItem(Type type)
Definition tasktree.h:280
GroupItem(const GroupItems &children)
Constructs a GroupItem element with a given list of items.
Definition tasktree.h:239
GroupItem(const Storage< StorageStruct > &storage)
Constructs a GroupItem element holding the storage object.
Definition tasktree.h:234
static GroupItem groupHandler(const GroupHandler &handler)
Definition tasktree.h:289
void addChildren(const GroupItems &children)
static constexpr bool isInvocable()
Definition tasktree.h:294
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:348
static GroupItem onGroupSetup(Handler &&handler)
Definition tasktree.h:355
static GroupItem onGroupDone(Handler &&handler, CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
Definition tasktree.h:359
Group(const GroupItems &children)
Constructs a group with a given list of children.
Definition tasktree.h:350
Group(std::initializer_list< GroupItem > children)
Constructs a group from std::initializer_list given by children.
Definition tasktree.h:351
const T & operator*() const
Definition tasktree.h:163
LoopList(const QList< T > &list)
Definition tasktree.h:161
const T * operator->() const
Definition tasktree.h:162
LoopRepeat(int count)
Definition tasktree.h:148
LoopUntil(const Condition &condition)
Definition tasktree.h:154
Loop(int count, const ValueGetter &valueGetter={})
Loop(const Condition &condition)
int iteration() const
const void * valuePtr() const
QNetworkReply * reply() const
void setNetworkAccessManager(QNetworkAccessManager *manager)
void setOperation(NetworkOperation operation)
void done(DoneResult result)
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void setRequest(const QNetworkRequest &request)
void setWriteData(const QByteArray &data)
void start() final
This method is called by the running TaskTree for starting the Task instance.
Definition tasktree.h:651
friend bool operator==(const StorageBase &first, const StorageBase &second)
Definition tasktree.h:177
friend size_t qHash(const StorageBase &storage, uint seed=0)
Definition tasktree.h:183
friend class Storage
Definition tasktree.h:188
friend bool operator!=(const StorageBase &first, const StorageBase &second)
Definition tasktree.h:180
StorageStruct * operator->() const noexcept
Returns a pointer to the active StorageStruct object, created by the running task tree.
Definition tasktree.h:213
StorageStruct & operator*() const noexcept
Returns a reference to the active StorageStruct object, created by the running task tree.
Definition tasktree.h:212
Storage()
Creates a storage for the given StorageStruct type.
Definition tasktree.h:200
StorageStruct * activeStorage() const
Returns a pointer to the active StorageStruct object, created by the running task tree.
Definition tasktree.h:214
Storage(const Args &...args)
Definition tasktree.h:207
Sync(Handler &&handler)
Constructs an element that executes a passed handler synchronously.
Definition tasktree.h:514
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:534
const Task * task() const
Definition tasktree.h:538
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Definition tasktree.h:102
virtual void start()=0
This method is called by the running TaskTree for starting the Task instance.
void done(DoneWith result)
void start(const Group &recipe, const SetupHandler &setupHandler={}, const DoneHandler &doneHandler={})
void start() final
This method is called by the running TaskTree for starting the Task instance.
void done(DoneWith result)
This signal is emitted when the task tree finished, passing the final result of the execution.
DoneWith runBlocking(const QFuture< void > &future)
int progressMaximum() const
Returns the maximum progressValue().
Definition tasktree.h:686
TaskTree()
Constructs an empty task tree.
int taskCount() const
Returns the number of asynchronous tasks contained in the stored recipe.
void cancel()
Cancels the execution of the running task tree.
void start()
Starts the task tree.
void onStorageSetup(const Storage< StorageStruct > &storage, Handler &&handler)
Installs a storage setup handler for the storage to pass the initial data dynamically to the running ...
Definition tasktree.h:690
~TaskTree()
Destroys the task tree.
bool isRunning() const
Returns true if the task tree is currently running; otherwise returns false.
void onStorageDone(const Storage< StorageStruct > &storage, Handler &&handler)
Installs a storage done handler for the storage to retrieve the final data dynamically from the runni...
Definition tasktree.h:698
void setRecipe(const Group &recipe)
Sets a given recipe for the task tree.
void asyncCountChanged(int count)
This signal is emitted when the running task tree is about to return control to the caller's event lo...
TaskTree(const Group &recipe)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int progressValue() const
Returns the current progress value, which is between the 0 and progressMaximum().
DoneWith runBlocking()
Executes a local event loop with QEventLoop::ExcludeUserInputEvents and starts the task tree.
static DoneWith runBlocking(const Group &recipe)
Constructs a temporary task tree using the passed recipe and runs it blocking.
void progressValueChanged(int value)
This signal is emitted when the running task tree finished, canceled, or skipped some tasks.
int asyncCount() const
Returns the current real count of asynchronous chains of invocations.
static DoneWith runBlocking(const Group &recipe, const QFuture< void > &future)
void start() final
This method is called by the running TaskTree for starting the Task instance.
TASKING_EXPORT friend Group operator>>(const When &whenItem, const Do &doItem)
static void unzip(QPromise< void > &promise, const QByteArray &content, const QDir &directory, const QString &fileName)
static bool sameFileContent(const QFileInfo &first, const QFileInfo &second)
static void writeAsset(QPromise< void > &promise, const QByteArray &content, const QString &filePath)
static void precheckLocalFile(const QUrl &url)
static QDir baseLocalDir(const QDir &preferredLocalDir)
static QString pathFromUrl(const QUrl &url)
static bool allAssetsPresent(const QList< QUrl > &assetFiles, const QDir &expectedDir)
static void copyAndCheck(QPromise< void > &promise, const QString &sourcePath, const QString &destPath)
static bool canBeALocalBaseDir(const QDir &dir)
static QList< QUrl > filterDownloadableAssets(const QList< QUrl > &assetFiles, const QDir &expectedDir)
static void readAssetsFileContent(QPromise< DownloadableAssets > &promise, const QByteArray &content)
static bool createDirectory(const QDir &dir)
static bool isWritableDir(const QDir &dir)
\inmodule TaskingSolution
const ExecutableItem successItem
SetupResult
Definition tasktree.h:65
WorkflowPolicy
Definition tasktree.h:53
const GroupItem sequential
GroupItem parallelLimit(int limit)
Constructs a group's element describing the \l{Execution Mode}{execution mode}.
Group operator||(const ExecutableItem &first, const ExecutableItem &second)
CustomTask< ConcurrentCallTaskAdapter< T > > ConcurrentCallTask
const GroupItem continueOnSuccess
const GroupItem stopOnError
const GroupItem finishAllAndError
const ExecutableItem errorItem
CustomTask< SimpleTaskAdapter< Task > > SimpleCustomTask
Definition tasktree.h:659
CustomTask< TimeoutTaskAdapter > TimeoutTask
Definition tasktree.h:748
const GroupItem finishAllAndSuccess
Group operator||(const ExecutableItem &item, DoneResult result)
DoneResult toDoneResult(bool success)
const GroupItem parallelIdealThreadCountLimit
ExecutableItem timeoutTask(const std::chrono::milliseconds &timeout, DoneResult result)
CustomTask< TaskTreeTaskAdapter > TaskTreeTask
Definition tasktree.h:747
const GroupItem stopOnSuccessOrError
const GroupItem nullItem
Group operator&&(const ExecutableItem &item, DoneResult result)
const GroupItem parallel
Group operator&&(const ExecutableItem &first, const ExecutableItem &second)
static GroupItem onGroupSetup(Handler &&handler)
\typealias Tasking::GroupItem::GroupSetupHandler
Definition tasktree.h:441
Group operator>>(const For &forItem, const Do &doItem)
Group operator!(const ExecutableItem &item)
const GroupItem continueOnError
GroupItem workflowPolicy(WorkflowPolicy policy)
Constructs a group's \l {Workflow Policy} {workflow policy} element for a given policy.
const GroupItem stopOnSuccess
static GroupItem onGroupDone(Handler &&handler, CallDoneIf callDoneIf=CallDoneIf::SuccessOrError)
Constructs a group's element holding the group done handler.
Definition tasktree.h:447
std::optional< WorkflowPolicy > m_workflowPolicy
Definition tasktree.h:267
std::optional< int > m_parallelLimit
Definition tasktree.h:266
std::optional< Loop > m_loop
Definition tasktree.h:268
GroupDoneHandler m_doneHandler
Definition tasktree.h:260
GroupSetupHandler m_setupHandler
Definition tasktree.h:259
InterfaceSetupHandler m_setupHandler
Definition tasktree.h:253
InterfaceCreateHandler m_createHandler
Definition tasktree.h:252
InterfaceDoneHandler m_doneHandler
Definition tasktree.h:254
#define TASKING_EXPORT