Files
BloomPatched/src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp

84 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include <cstdint>
#include <atomic>
#include <QObject>
#include <QString>
#include "TaskGroup.hpp"
#include "src/Services/TargetControllerService.hpp"
namespace Bloom
{
enum class InsightWorkerTaskState: std::uint8_t
{
CREATED,
STARTED,
FAILED,
COMPLETED,
};
class InsightWorkerTask: public QObject
{
Q_OBJECT
public:
using IdType = std::uint64_t;
const InsightWorkerTask::IdType id = ++(InsightWorkerTask::lastId);
2021-12-25 21:01:58 +00:00
InsightWorkerTaskState state = InsightWorkerTaskState::CREATED;
InsightWorkerTask();
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 {
return TaskGroups();
};
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(int 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;
private:
static inline std::atomic<InsightWorkerTask::IdType> lastId = 0;
};
}