2021-08-30 22:17:59 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-03-12 23:31:19 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <atomic>
|
2021-08-30 22:17:59 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
|
2022-09-08 19:54:37 +01:00
|
|
|
#include "TaskGroup.hpp"
|
2022-12-26 21:27:19 +00:00
|
|
|
#include "src/Services/TargetControllerService.hpp"
|
2021-08-30 22:17:59 +01:00
|
|
|
|
|
|
|
|
namespace Bloom
|
|
|
|
|
{
|
|
|
|
|
enum class InsightWorkerTaskState: std::uint8_t
|
|
|
|
|
{
|
|
|
|
|
CREATED,
|
|
|
|
|
STARTED,
|
|
|
|
|
FAILED,
|
|
|
|
|
COMPLETED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class InsightWorkerTask: public QObject
|
|
|
|
|
{
|
2021-10-06 21:12:31 +01:00
|
|
|
Q_OBJECT
|
2021-08-30 22:17:59 +01:00
|
|
|
|
|
|
|
|
public:
|
2023-03-12 23:31:19 +00:00
|
|
|
using IdType = std::uint64_t;
|
|
|
|
|
const InsightWorkerTask::IdType id = ++(InsightWorkerTask::lastId);
|
2021-12-25 21:01:58 +00:00
|
|
|
InsightWorkerTaskState state = InsightWorkerTaskState::CREATED;
|
2021-08-30 22:17:59 +01:00
|
|
|
|
2023-03-12 23:31:19 +00:00
|
|
|
InsightWorkerTask();
|
2021-08-30 22:17:59 +01:00
|
|
|
|
2023-03-15 20:16:07 +00:00
|
|
|
virtual QString brief() const = 0;
|
|
|
|
|
|
2023-03-15 20:15:05 +00:00
|
|
|
virtual TaskGroups taskGroups() const {
|
2022-09-08 19:54:37 +01:00
|
|
|
return TaskGroups();
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
void execute(Services::TargetControllerService& targetControllerService);
|
2021-08-30 22:17:59 +01:00
|
|
|
|
|
|
|
|
signals:
|
2022-04-24 15:31:38 +01:00
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::started() signal will be emitted once the task has started (InsightWorker::run() is
|
|
|
|
|
* called)
|
|
|
|
|
*/
|
2021-08-30 22:17:59 +01:00
|
|
|
void started();
|
2022-04-24 15:31:38 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::completed() signal will be emitted once the task has successfully completed.
|
|
|
|
|
*/
|
2021-08-30 22:17:59 +01:00
|
|
|
void completed();
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2022-04-24 15:31:38 +01:00
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::failed() signal will be emitted when the task fails (InsightWorkerTask::run() throws
|
|
|
|
|
* an exception).
|
|
|
|
|
*/
|
|
|
|
|
void failed(QString errorMessage);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::finished() signal will be emitted at the end of the task, regardless to whether it
|
|
|
|
|
* completed successfully or failed.
|
|
|
|
|
*/
|
|
|
|
|
void finished();
|
|
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
protected:
|
2022-12-26 21:27:19 +00:00
|
|
|
virtual void run(Services::TargetControllerService& targetControllerService) = 0;
|
2023-03-12 23:31:19 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static inline std::atomic<InsightWorkerTask::IdType> lastId = 0;
|
2021-08-30 22:17:59 +01:00
|
|
|
};
|
|
|
|
|
}
|