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-12-31 17:05:31 +00:00
|
|
|
#include "src/ProjectConfig.hpp"
|
2022-04-08 22:14:37 +01:00
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include "src/EventManager/EventManager.hpp"
|
|
|
|
|
#include "src/EventManager/EventListener.hpp"
|
2022-04-08 22:14:37 +01:00
|
|
|
#include "src/EventManager/Events/Events.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"
|
2022-04-08 22:14:37 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-10-06 21:12:31 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2022-03-20 18:01:46 +00:00
|
|
|
InsightWorker() = default;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
|
|
|
|
void queueTask(InsightWorkerTask* task);
|
|
|
|
|
|
|
|
|
|
void dispatchEvents() {
|
|
|
|
|
this->eventListener->dispatchCurrentEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startup();
|
|
|
|
|
|
|
|
|
|
signals:
|
2021-10-18 01:03:22 +01:00
|
|
|
void ready();
|
2021-10-06 21:12:31 +01:00
|
|
|
void taskQueued();
|
|
|
|
|
void targetStateUpdated(Bloom::Targets::TargetState newState);
|
|
|
|
|
void targetProgramCounterUpdated(quint32 programCounter);
|
|
|
|
|
void targetControllerSuspended();
|
|
|
|
|
void targetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
|
|
|
|
|
void targetRegistersWritten(const Bloom::Targets::TargetRegisters& targetRegisters, const QDateTime& timestamp);
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
private:
|
|
|
|
|
EventListenerPointer eventListener = std::make_shared<EventListener>("InsightWorkerEventListener");
|
|
|
|
|
|
2022-04-09 15:57:24 +01:00
|
|
|
TargetController::TargetControllerConsole targetControllerConsole = TargetController::TargetControllerConsole(
|
|
|
|
|
*(this->eventListener)
|
|
|
|
|
);
|
|
|
|
|
TargetController::TargetControllerState lastTargetControllerState =
|
|
|
|
|
TargetController::TargetControllerState::ACTIVE;
|
2021-05-30 16:53:24 +01:00
|
|
|
|
2022-04-23 17:30:14 +01:00
|
|
|
Targets::TargetState lastTargetState = Targets::TargetState::UNKNOWN;
|
|
|
|
|
|
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);
|
2022-04-08 22:14:37 +01:00
|
|
|
void onTargetResetEvent(const Events::TargetReset& 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
|
|
|
void executeTasks();
|
2021-04-04 21:04:12 +01:00
|
|
|
};
|
|
|
|
|
}
|