2021-04-04 21:04:12 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
#include "src/Helpers/Thread.hpp"
|
2021-08-30 22:17:59 +01:00
|
|
|
#include "src/Helpers/SyncSafe.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "src/ApplicationConfig.hpp"
|
|
|
|
|
#include "src/EventManager/EventManager.hpp"
|
|
|
|
|
#include "src/EventManager/EventListener.hpp"
|
2021-04-24 20:23:17 +01:00
|
|
|
#include "src/TargetController/TargetControllerConsole.hpp"
|
2021-05-30 16:53:24 +01:00
|
|
|
#include "src/TargetController/TargetControllerState.hpp"
|
2021-08-30 22:17:59 +01:00
|
|
|
#include "Tasks/InsightWorkerTask.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
namespace Bloom
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The InsightWorker runs on a separate thread to the main GUI thread. Its purpose is to handle any
|
|
|
|
|
* blocking/time-expensive operations.
|
|
|
|
|
*/
|
|
|
|
|
class InsightWorker: public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
private:
|
|
|
|
|
EventManager& eventManager;
|
|
|
|
|
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightWorkerEventListener");
|
|
|
|
|
|
2021-04-24 20:23:17 +01:00
|
|
|
TargetControllerConsole targetControllerConsole = TargetControllerConsole(
|
|
|
|
|
this->eventManager,
|
|
|
|
|
*(this->eventListener)
|
|
|
|
|
);
|
2021-05-30 16:53:24 +01:00
|
|
|
TargetControllerState lastTargetControllerState = TargetControllerState::ACTIVE;
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
QTimer* eventDispatchTimer = nullptr;
|
|
|
|
|
|
2021-08-30 22:17:59 +01:00
|
|
|
SyncSafe<std::queue<InsightWorkerTask*>> queuedTasks;
|
|
|
|
|
|
|
|
|
|
std::optional<InsightWorkerTask*> getQueuedTask();
|
|
|
|
|
|
2021-06-22 14:44:00 +01:00
|
|
|
void onTargetStoppedEvent(const Events::TargetExecutionStopped& event);
|
|
|
|
|
void onTargetResumedEvent(const Events::TargetExecutionResumed& event);
|
2021-09-11 20:45:06 +01:00
|
|
|
void onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event);
|
2021-09-11 20:45:26 +01:00
|
|
|
void onTargetControllerStateReportedEvent(const Events::TargetControllerStateReported& event);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-08-30 22:17:59 +01:00
|
|
|
private slots:
|
|
|
|
|
void executeTasks();
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
public:
|
2021-06-21 00:14:31 +01:00
|
|
|
explicit InsightWorker(EventManager& eventManager): eventManager(eventManager) {};
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
void dispatchEvents() {
|
|
|
|
|
this->eventListener->dispatchCurrentEvents();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 22:17:59 +01:00
|
|
|
void queueTask(InsightWorkerTask* task);
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
public slots:
|
|
|
|
|
void startup();
|
|
|
|
|
void requestPinStates(int variantId);
|
|
|
|
|
|
|
|
|
|
signals:
|
2021-08-30 22:17:59 +01:00
|
|
|
void taskQueued();
|
2021-04-04 21:04:12 +01:00
|
|
|
void targetStateUpdated(Bloom::Targets::TargetState newState);
|
|
|
|
|
void targetProgramCounterUpdated(quint32 programCounter);
|
2021-05-30 16:53:24 +01:00
|
|
|
void targetControllerSuspended();
|
|
|
|
|
void targetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
|
2021-09-18 22:35:30 +01:00
|
|
|
void targetRegistersWritten(const Bloom::Targets::TargetRegisters& targetRegisters, const QDateTime& timestamp);
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|