Moved insight worker and introduced worker tasks

This commit is contained in:
Nav
2021-08-30 22:17:59 +01:00
parent a52d2271b3
commit 3be8d90e09
7 changed files with 141 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
#include "InsightWorkerTask.hpp"
using namespace Bloom;
void InsightWorkerTask::execute(TargetControllerConsole& targetControllerConsole) {
try {
this->state = InsightWorkerTaskState::STARTED;
emit this->started();
this->run(targetControllerConsole);
this->state = InsightWorkerTaskState::COMPLETED;
emit this->completed();
} catch (std::exception& exception) {
this->state = InsightWorkerTaskState::FAILED;
emit this->failed(QString::fromStdString(exception.what()));
}
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <QObject>
#include <QString>
#include "src/TargetController/TargetControllerConsole.hpp"
namespace Bloom
{
enum class InsightWorkerTaskState: std::uint8_t
{
CREATED,
STARTED,
FAILED,
COMPLETED,
};
class InsightWorkerTask: public QObject
{
Q_OBJECT
protected:
virtual void run(TargetControllerConsole& targetControllerConsole) = 0;
public:
InsightWorkerTaskState state;
InsightWorkerTask() = default;
InsightWorkerTask(QObject* parent): QObject(parent) {};
void execute(TargetControllerConsole& targetControllerConsole);
signals:
void started();
void failed(QString errorMessage);
void completed();
};
}

View File

@@ -0,0 +1,7 @@
#include "ReadTargetRegisters.hpp"
using namespace Bloom;
void ReadTargetRegisters::run(TargetControllerConsole& targetControllerConsole) {
emit this->targetRegistersRead(targetControllerConsole.readRegisters(this->descriptors));
}

View File

@@ -0,0 +1,27 @@
#pragma once
#include <QObject>
#include <QString>
#include "InsightWorkerTask.hpp"
#include "src/Targets/TargetRegister.hpp"
namespace Bloom
{
class ReadTargetRegisters: public InsightWorkerTask
{
Q_OBJECT
private:
Targets::TargetRegisterDescriptors descriptors;
protected:
void run(TargetControllerConsole& targetControllerConsole) override;
public:
ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors, QObject* parent):
InsightWorkerTask(nullptr), descriptors(descriptors) {}
signals:
void targetRegistersRead(Targets::TargetRegisters registers);
};
}