From fa037a81b1c7b3dc9071c117d1bf55ab1cf94bc0 Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 28 Apr 2022 21:06:57 +0100 Subject: [PATCH] Replaced nasty onInsightStateChangedEvent event handler in TargetController with new GetTargetState command --- src/Insight/Insight.cpp | 11 +++++++++-- src/Insight/InsightWorker/InsightWorker.cpp | 5 +++++ src/Insight/InsightWorker/InsightWorker.hpp | 10 ++++++---- .../UserInterfaces/InsightWindow/InsightWindow.cpp | 1 + .../UserInterfaces/InsightWindow/InsightWindow.hpp | 3 +++ .../TargetMemoryInspectionPane.cpp | 4 ++++ .../TargetRegisterInspectorWindow.cpp | 4 ++++ .../TargetRegistersPaneWidget.cpp | 4 ++++ .../Widgets/TargetWidgets/TargetPackageWidget.cpp | 4 ++++ src/TargetController/TargetControllerComponent.cpp | 13 ------------- src/TargetController/TargetControllerComponent.hpp | 8 -------- 11 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index e6aa3d19..e9fee9a7 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -139,11 +139,16 @@ namespace Bloom QObject::connect(eventDispatchTimer, &QTimer::timeout, this, &Insight::dispatchEvents); eventDispatchTimer->start(100); + QObject::connect( + this->mainWindow, + &InsightWindow::activatedSignal, + this->insightWorker, + &InsightWorker::onInsightWindowActivated + ); + this->mainWindow->setInsightConfig(this->insightConfig); this->mainWindow->setEnvironmentConfig(this->environmentConfig); - this->mainWindow->init(targetDescriptor); - // Prepare worker thread this->workerThread = new QThread(); this->workerThread->setObjectName("IW"); @@ -152,6 +157,8 @@ namespace Bloom QObject::connect(this->workerThread, &QThread::finished, this->insightWorker, &QObject::deleteLater); QObject::connect(this->workerThread, &QThread::finished, this->workerThread, &QThread::deleteLater); + this->mainWindow->init(targetDescriptor); + QObject::connect(this->insightWorker, &InsightWorker::ready, this, [this] { this->checkBloomVersion(); }); diff --git a/src/Insight/InsightWorker/InsightWorker.cpp b/src/Insight/InsightWorker/InsightWorker.cpp index c862f6c2..abe593e6 100644 --- a/src/Insight/InsightWorker/InsightWorker.cpp +++ b/src/Insight/InsightWorker/InsightWorker.cpp @@ -58,6 +58,11 @@ namespace Bloom emit this->ready(); } + void InsightWorker::onInsightWindowActivated() { + this->lastTargetState = this->targetControllerConsole.getTargetState(); + emit this->targetStateUpdated(this->lastTargetState); + } + std::optional InsightWorker::getQueuedTask() { auto task = std::optional(); diff --git a/src/Insight/InsightWorker/InsightWorker.hpp b/src/Insight/InsightWorker/InsightWorker.hpp index 2d0f99ce..ca736df8 100644 --- a/src/Insight/InsightWorker/InsightWorker.hpp +++ b/src/Insight/InsightWorker/InsightWorker.hpp @@ -30,12 +30,10 @@ namespace Bloom void queueTask(InsightWorkerTask* task); - void dispatchEvents() { - this->eventListener->dispatchCurrentEvents(); - } - void startup(); + void onInsightWindowActivated(); + signals: void ready(); void taskQueued(); @@ -58,6 +56,10 @@ namespace Bloom SyncSafe> queuedTasks; + void dispatchEvents() { + this->eventListener->dispatchCurrentEvents(); + } + std::optional getQueuedTask(); void onTargetStoppedEvent(const Events::TargetExecutionStopped& event); diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index 1bdaf8da..45751c87 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -347,6 +347,7 @@ namespace Bloom this->setUiDisabled(this->targetState != TargetState::STOPPED); this->activated = true; + emit this->activatedSignal(); } void InsightWindow::populateVariantMenu() { diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index d980f7a6..69b9f737 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -50,6 +50,9 @@ namespace Bloom void init(Targets::TargetDescriptor targetDescriptor); + signals: + void activatedSignal(); + protected: void resizeEvent(QResizeEvent* event) override; void showEvent(QShowEvent* event) override; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp index 9fff783b..e1f73d68 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/TargetMemoryInspectionPane.cpp @@ -243,6 +243,10 @@ void TargetMemoryInspectionPane::sanitiseSettings() { } void TargetMemoryInspectionPane::onTargetStateChanged(Targets::TargetState newState) { + if (this->targetState == newState) { + return; + } + using Targets::TargetState; this->targetState = newState; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp index 1f583acb..8d41df51 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp @@ -261,6 +261,10 @@ namespace Bloom::Widgets } void TargetRegisterInspectorWindow::onTargetStateChanged(TargetState newState) { + if (this->targetState == newState) { + return; + } + if (newState != TargetState::STOPPED) { this->registerValueTextInput->setDisabled(true); this->registerValueBitsetWidgetContainer->setDisabled(true); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index 32e53fdb..1424cff3 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -231,6 +231,10 @@ namespace Bloom::Widgets } void TargetRegistersPaneWidget::onTargetStateChanged(Targets::TargetState newState) { + if (this->targetState == newState) { + return; + } + using Targets::TargetState; this->targetState = newState; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp index 66f74950..32f77597 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp @@ -63,6 +63,10 @@ namespace Bloom::Widgets::InsightTargetWidgets } void TargetPackageWidget::onTargetStateChanged(TargetState newState) { + if (this->targetState == newState) { + return; + } + this->targetState = newState; if (newState == TargetState::RUNNING) { diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index 6342b0d1..015e9821 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -922,19 +922,6 @@ namespace Bloom::TargetController } } - // TODO: remove this - void TargetControllerComponent::onInsightStateChangedEvent(const Events::InsightThreadStateChanged& event) { - if (event.getState() == ThreadState::READY) { - /* - * Insight has just started up. - * - * Refresh the target state and kick off a target stop/resume execution event. Setting the lastTargetState - * to UNKNOWN will be enough to do this. See TargetControllerComponent::fireTargetEvents(). - */ - this->lastTargetState = TargetState::UNKNOWN; - } - } - void TargetControllerComponent::onRetrieveTargetPinStatesEvent(const Events::RetrieveTargetPinStates& event) { try { if (this->target->getState() != TargetState::STOPPED) { diff --git a/src/TargetController/TargetControllerComponent.hpp b/src/TargetController/TargetControllerComponent.hpp index d3f4a7c9..294576d4 100644 --- a/src/TargetController/TargetControllerComponent.hpp +++ b/src/TargetController/TargetControllerComponent.hpp @@ -341,14 +341,6 @@ namespace Bloom::TargetController */ void onSetProgramCounterEvent(const Events::SetProgramCounterOnTarget& event); - /** - * Will automatically fire a target state update event. - * @TODO: get rid of this - Insight should request this itself. - * - * @param event - */ - void onInsightStateChangedEvent(const Events::InsightThreadStateChanged& event); - /** * Will attempt to obtain the pin states from the target. Will emit a TargetPinStatesRetrieved event on success. *