Moved insight worker and introduced worker tasks
This commit is contained in:
17
src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp
Normal file
17
src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp
Normal 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()));
|
||||
}
|
||||
}
|
||||
37
src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp
Normal file
37
src/Insight/InsightWorker/Tasks/InsightWorkerTask.hpp
Normal 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();
|
||||
};
|
||||
}
|
||||
7
src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp
Normal file
7
src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "ReadTargetRegisters.hpp"
|
||||
|
||||
using namespace Bloom;
|
||||
|
||||
void ReadTargetRegisters::run(TargetControllerConsole& targetControllerConsole) {
|
||||
emit this->targetRegistersRead(targetControllerConsole.readRegisters(this->descriptors));
|
||||
}
|
||||
27
src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp
Normal file
27
src/Insight/InsightWorker/Tasks/ReadTargetRegisters.hpp
Normal 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user