5#ifndef TASKING_CONCURRENTCALL_H
6#define TASKING_CONCURRENTCALL_H
21#include <QtConcurrent/QtConcurrent>
32template <
typename ResultType>
39 template <
typename Function,
typename ...Args>
42 wrapConcurrent(
std::forward<Function>(function),
std::forward<Args>(args)...);
47 return m_future.resultCount() ? m_future.result() : ResultType();
51 return m_future.results();
56 template <
typename Function,
typename ...Args>
57 void wrapConcurrent(Function &&function, Args &&...args)
59 m_startHandler = [
this, function = std::forward<Function>(function), args...] {
60 QThreadPool *threadPool = m_threadPool ? m_threadPool : QThreadPool::globalInstance();
61 return QtConcurrent::run(threadPool, function, args...);
65 template <
typename Function,
typename ...Args>
66 void wrapConcurrent(
std::reference_wrapper<
const Function> &&wrapper, Args &&...args)
68 m_startHandler = [
this, wrapper = std::forward<std::reference_wrapper<
const Function>>(wrapper), args...] {
69 QThreadPool *threadPool = m_threadPool ? m_threadPool : QThreadPool::globalInstance();
70 return QtConcurrent::run(threadPool, std::forward<
const Function>(wrapper.get()),
78 std::function<QFuture<ResultType>()> m_startHandler;
79 QThreadPool *m_threadPool =
nullptr;
80 QFuture<ResultType> m_future;
83template <
typename ResultType>
90 m_watcher->waitForFinished();
95 if (!
this->task()->m_startHandler) {
96 emit
this->done(DoneResult::Error);
99 m_watcher.reset(
new QFutureWatcher<ResultType>);
100 this->connect(m_watcher.get(), &QFutureWatcherBase::finished,
this, [
this] {
101 emit
this->done(toDoneResult(!m_watcher->isCanceled()));
102 m_watcher.release()->deleteLater();
104 this->task()->m_future =
this->task()->m_startHandler();
105 m_watcher->setFuture(
this->task()->m_future);
109 std::unique_ptr<QFutureWatcher<ResultType>> m_watcher;
void setupDownload(NetworkQuery *query, const QString &progressText)
QDir m_preferredLocalDownloadDir
void setLocalDownloadDir(const QDir &dir)
void setProgress(int progressValue, int progressMaximum, const QString &progressText)
QUrl m_offlineAssetsFilePath
AssetDownloaderPrivate(AssetDownloader *q)
void clearProgress(const QString &progressText)
QStringList m_networkErrors
TaskTreeRunner m_taskTreeRunner
QString m_lastProgressText
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)
QUrl preferredLocalDownloadDir() const
QUrl downloadBase() const
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 &)
QString jsonFileName() const
QUrl offlineAssetsFilePath() const
void setDownloadBase(const QUrl &downloadBase)
QString zipFileName() const
void setZipFileName(const QString &zipFileName)
void finished(bool success)
QUrl localDownloadDir() const
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.
~ConcurrentCallTaskAdapter()
void setThreadPool(QThreadPool *pool)
QFuture< ResultType > future() const
QList< ResultType > results() const
ResultType result() const
void setConcurrentCallData(Function &&function, Args &&...args)
std::function< SetupResult(Task &)> TaskSetupHandler
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
CustomTask< ConcurrentCallTaskAdapter< T > > ConcurrentCallTask