2022-06-12 21:37:11 +05:30
|
|
|
#pragma once
|
|
|
|
|
2023-03-30 23:52:55 +05:30
|
|
|
#include <QUuid>
|
|
|
|
#include <QHash>
|
2022-06-12 21:37:11 +05:30
|
|
|
#include <QQueue>
|
|
|
|
#include <QSet>
|
2023-03-30 23:52:55 +05:30
|
|
|
#include <memory>
|
2022-06-12 21:37:11 +05:30
|
|
|
|
|
|
|
#include "tasks/Task.h"
|
|
|
|
|
|
|
|
class ConcurrentTask : public Task {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-01-25 01:22:09 +05:30
|
|
|
using Ptr = shared_qobject_ptr<ConcurrentTask>;
|
|
|
|
|
2022-06-12 21:37:11 +05:30
|
|
|
explicit ConcurrentTask(QObject* parent = nullptr, QString task_name = "", int max_concurrent = 6);
|
2022-07-25 01:46:14 +05:30
|
|
|
~ConcurrentTask() override;
|
|
|
|
|
|
|
|
bool canAbort() const override { return true; }
|
2022-06-12 21:37:11 +05:30
|
|
|
|
2023-03-31 12:20:29 +05:30
|
|
|
inline auto isMultiStep() const -> bool override { return totalSize() > 1; };
|
|
|
|
auto getStepProgress() const -> TaskStepProgressList override;
|
2022-06-12 21:37:11 +05:30
|
|
|
|
|
|
|
void addTask(Task::Ptr task);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
bool abort() override;
|
|
|
|
|
2022-12-15 22:15:50 +05:30
|
|
|
/** Resets the internal state of the task.
|
|
|
|
* This allows the same task to be re-used.
|
|
|
|
*/
|
|
|
|
void clear();
|
|
|
|
|
2022-06-12 21:37:11 +05:30
|
|
|
protected
|
|
|
|
slots:
|
|
|
|
void executeTask() override;
|
|
|
|
|
|
|
|
virtual void startNext();
|
|
|
|
|
|
|
|
void subTaskSucceeded(Task::Ptr);
|
|
|
|
void subTaskFailed(Task::Ptr, const QString &msg);
|
2023-03-30 23:52:55 +05:30
|
|
|
void subTaskStatus(Task::Ptr task, const QString &msg);
|
|
|
|
void subTaskProgress(Task::Ptr task, qint64 current, qint64 total);
|
2023-03-31 12:20:29 +05:30
|
|
|
void subTaskStepProgress(Task::Ptr task, TaskStepProgressList task_step_progress);
|
2022-06-12 21:37:11 +05:30
|
|
|
|
|
|
|
protected:
|
2022-12-17 21:25:03 +05:30
|
|
|
// NOTE: This is not thread-safe.
|
|
|
|
[[nodiscard]] unsigned int totalSize() const { return m_queue.size() + m_doing.size() + m_done.size(); }
|
|
|
|
|
2023-03-30 23:52:55 +05:30
|
|
|
void updateStepProgress();
|
2022-06-12 21:37:11 +05:30
|
|
|
|
|
|
|
virtual void updateState();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QString m_name;
|
|
|
|
QString m_step_status;
|
|
|
|
|
|
|
|
QQueue<Task::Ptr> m_queue;
|
|
|
|
|
2023-03-30 23:52:55 +05:30
|
|
|
QHash<Task*, Task::Ptr> m_doing;
|
2022-06-12 21:37:11 +05:30
|
|
|
QHash<Task*, Task::Ptr> m_done;
|
|
|
|
QHash<Task*, Task::Ptr> m_failed;
|
2023-03-30 23:52:55 +05:30
|
|
|
QHash<Task*, Task::Ptr> m_succeeded;
|
|
|
|
|
|
|
|
QHash<QUuid, std::shared_ptr<TaskStepProgress>> m_task_progress;
|
2022-06-12 21:37:11 +05:30
|
|
|
|
|
|
|
int m_total_max_size;
|
|
|
|
|
|
|
|
qint64 m_stepProgress = 0;
|
|
|
|
qint64 m_stepTotalProgress = 100;
|
|
|
|
|
|
|
|
bool m_aborted = false;
|
|
|
|
};
|