From dde35a0eb8847d6dd13219bae9648bf6c4d7b9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 3 Jun 2015 21:13:48 +0200 Subject: NOISSUE remove StandardTask --- logic/CMakeLists.txt | 2 - logic/tasks/StandardTask.cpp | 120 ------------------------------------------- logic/tasks/StandardTask.h | 43 ---------------- 3 files changed, 165 deletions(-) delete mode 100644 logic/tasks/StandardTask.cpp delete mode 100644 logic/tasks/StandardTask.h diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt index d91fc694..9a4ead21 100644 --- a/logic/CMakeLists.txt +++ b/logic/CMakeLists.txt @@ -203,8 +203,6 @@ set(LOGIC_SOURCES tasks/ThreadTask.cpp tasks/SequentialTask.h tasks/SequentialTask.cpp - tasks/StandardTask.h - tasks/StandardTask.cpp # Settings settings/INIFile.cpp diff --git a/logic/tasks/StandardTask.cpp b/logic/tasks/StandardTask.cpp deleted file mode 100644 index 3201d674..00000000 --- a/logic/tasks/StandardTask.cpp +++ /dev/null @@ -1,120 +0,0 @@ -// Licensed under the Apache-2.0 license. See README.md for details. - -#include "StandardTask.h" - -#include -#include - -#include "net/CacheDownload.h" -#include "net/ByteArrayDownload.h" -#include "net/NetJob.h" -#include "FileSystem.h" -#include "Exception.h" -#include "Env.h" - -StandardTask::StandardTask(QObject *parent) - : Task(parent) -{ - m_loop = new QEventLoop(this); -} - -void StandardTask::runTask(QObjectPtr other) -{ - connect(other.get(), &Task::succeeded, m_loop, &QEventLoop::quit); - connect(other.get(), &Task::failed, m_loop, &QEventLoop::quit); - connect(other.get(), &Task::progress, this, [this](qint64 current, qint64 total){setProgress(current / total);}); - connect(other.get(), &Task::status, this, &StandardTask::setStatus); - if (!other->isRunning()) - { - other->start(); - } - if (other->isRunning()) - { - m_loop->exec(); - } - disconnect(other.get(), 0, m_loop, 0); - disconnect(other.get(), 0, this, 0); - other->deleteLater(); - if (!other->successful()) - { - throw Exception(other->failReason()); - } -} -void StandardTask::runTaskNonBlocking(QObjectPtr other) -{ - if (!other) - { - return; - } - m_pendingTasks.append(other.get()); - m_pendingTaskPtrs.append(other); - other->start(); -} -QByteArray StandardTask::networkGet(const QUrl &url) -{ - ByteArrayDownloadPtr task = ByteArrayDownload::make(url); - runTask(wrapDownload("", task)); - return task->m_data; -} -QByteArray StandardTask::networkGetCached(const QString &name, const QString &base, const QString &path, const QUrl &url, const bool alwaysRefetch, - INetworkValidator *validator) -{ - MetaEntryPtr entry = ENV.metacache()->resolveEntry(base, path); - if (!alwaysRefetch && !entry->stale) - { - if (validator) { delete validator; } - return FS::read(entry->getFullPath()); - } - else if (alwaysRefetch) - { - entry->stale = true; - } - CacheDownloadPtr task = CacheDownload::make(url, entry); - task->setValidator(validator); - runTask(wrapDownload(name, task)); - return FS::read(entry->getFullPath()); -} -QByteArray StandardTask::networkGetCached(const QString &name, const QString &base, const QString &path, const QUrl &url, const QMap &headers, - INetworkValidator *validator) -{ - MetaEntryPtr entry = ENV.metacache()->resolveEntry(base, path); - if (!entry->stale) - { - if (validator) { delete validator; } - return FS::read(entry->getFullPath()); - } - CacheDownloadPtr task = CacheDownload::make(url, entry); - //task->setHeaders(headers); - task->setValidator(validator); - runTask(wrapDownload(name, task)); - return FS::read(entry->getFullPath()); -} -void StandardTask::networkGetCachedNonBlocking(const QString &name, const QString &base, const QString &path, const QUrl &url, const bool alwaysRefetch, - INetworkValidator *validator) -{ - MetaEntryPtr entry = ENV.metacache()->resolveEntry(base, path); - if (!alwaysRefetch && !entry->stale) - { - return; - } - CacheDownloadPtr dl = CacheDownload::make(url, entry); - dl->setValidator(validator); - runTaskNonBlocking(wrapDownload(name, dl)); -} -void StandardTask::waitOnPending() -{ - for (int i = 0; i < m_pendingTasks.size(); ++i) - { - if (m_pendingTasks.at(i) && m_pendingTasks.at(i)->isRunning()) - { - runTask(m_pendingTaskPtrs.at(i)); - } - } -} - -QObjectPtr StandardTask::wrapDownload(const QString &name, std::shared_ptr action) -{ - NetJobPtr task = NetJobPtr(new NetJob(name)); - task->addNetAction(action); - return task; -} diff --git a/logic/tasks/StandardTask.h b/logic/tasks/StandardTask.h deleted file mode 100644 index 6f283dcd..00000000 --- a/logic/tasks/StandardTask.h +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed under the Apache-2.0 license. See README.md for details. - -#pragma once - -#include "Task.h" - -#include -#include - -#include "QObjectPtr.h" - -class QEventLoop; -class QDir; -class NetAction; -class NetJob; -class INetworkValidator; - -class StandardTask : public Task -{ - Q_OBJECT -public: - explicit StandardTask(QObject *parent = nullptr); - -protected: - // TODO: switch to a future-based system - void runTask(QObjectPtr other); - void runTaskNonBlocking(QObjectPtr other); - QByteArray networkGet(const QUrl &url); - QByteArray networkGetCached(const QString &name, const QString &base, const QString &path, const QUrl &url, const bool alwaysRefetch = false, - INetworkValidator *validator = nullptr); - QByteArray networkGetCached(const QString &name, const QString &base, const QString &path, const QUrl &url, const QMap &headers, - INetworkValidator *validator = nullptr); - void networkGetCachedNonBlocking(const QString &name, const QString &base, const QString &path, const QUrl &url, const bool alwaysRefetch = false, - INetworkValidator *validator = nullptr); - void waitOnPending(); - -private: - QEventLoop *m_loop; - QList> m_pendingTasks; // only used to check if the object was deleted - QList> m_pendingTaskPtrs; - - QObjectPtr wrapDownload(const QString &name, std::shared_ptr action); -}; -- cgit v1.2.3