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
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
enum class InsightWorkerTaskState: std::uint8_t
|
2021-08-30 22:17:59 +01:00
|
|
|
{
|
2023-08-13 15:47:51 +01:00
|
|
|
CREATED,
|
|
|
|
|
STARTED,
|
|
|
|
|
FAILED,
|
|
|
|
|
COMPLETED,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static_assert(std::atomic<InsightWorkerTaskState>::is_always_lock_free);
|
|
|
|
|
static_assert(std::atomic<std::uint8_t>::is_always_lock_free);
|
|
|
|
|
|
|
|
|
|
class InsightWorkerTask: public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2021-08-30 22:17:59 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
public:
|
|
|
|
|
using IdType = std::uint64_t;
|
|
|
|
|
const InsightWorkerTask::IdType id = ++(InsightWorkerTask::lastId);
|
|
|
|
|
std::atomic<InsightWorkerTaskState> state = InsightWorkerTaskState::CREATED;
|
|
|
|
|
std::atomic<std::uint8_t> progressPercentage = 0;
|
|
|
|
|
|
|
|
|
|
InsightWorkerTask();
|
|
|
|
|
|
|
|
|
|
virtual QString brief() const = 0;
|
|
|
|
|
|
|
|
|
|
virtual TaskGroups taskGroups() const {
|
|
|
|
|
return TaskGroups();
|
2021-08-30 22:17:59 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
|
|
|
|
|
void execute(Services::TargetControllerService& targetControllerService);
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::started() signal will be emitted once the task has started (InsightWorker::run() is
|
|
|
|
|
* called)
|
|
|
|
|
*/
|
|
|
|
|
void started();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Some tasks will emit an InsightWorkerTask::progressUpdate() signal to provide an update on their progress.
|
|
|
|
|
*
|
|
|
|
|
* This is used for progress bar widgets.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: A task doesn't have to emit this signal. Currently, the time-expensive tasks (like ReadTargetMemory)
|
|
|
|
|
* emit this signal.
|
|
|
|
|
*
|
|
|
|
|
* @param progressPercentage
|
|
|
|
|
* The task's current progress.
|
|
|
|
|
*/
|
|
|
|
|
void progressUpdate(std::uint8_t progressPercentage);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The InsightWorkerTask::completed() signal will be emitted once the task has successfully completed.
|
|
|
|
|
*/
|
|
|
|
|
void completed();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void run(Services::TargetControllerService& targetControllerService) = 0;
|
|
|
|
|
void setProgressPercentage(std::uint8_t percentage);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static inline std::atomic<InsightWorkerTask::IdType> lastId = 0;
|
|
|
|
|
};
|