From 0397cb9aba4d9cfef5d5e9b8c475d51e83fc4f27 Mon Sep 17 00:00:00 2001 From: Nav Date: Tue, 6 Sep 2022 00:51:48 +0100 Subject: [PATCH] Replaced targetProgramCounterUpdated signal with new ReadProgramCounter Insight worker task. Also some other bits of tidying --- src/Insight/CMakeLists.txt | 1 + src/Insight/InsightWorker/InsightWorker.cpp | 24 +---- src/Insight/InsightWorker/InsightWorker.hpp | 3 +- .../Tasks/ReadProgramCounter.cpp | 10 ++ .../Tasks/ReadProgramCounter.hpp | 20 ++++ .../InsightWindow/InsightWindow.cpp | 94 +++++++++++++------ .../InsightWindow/InsightWindow.hpp | 3 +- .../TargetRegistersPane/RegisterWidget.cpp | 4 - .../TargetRegistersPaneWidget.cpp | 37 ++------ .../TargetRegistersPaneWidget.hpp | 4 +- .../TargetWidgets/TargetPackageWidget.cpp | 11 --- 11 files changed, 110 insertions(+), 101 deletions(-) create mode 100644 src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp create mode 100644 src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp diff --git a/src/Insight/CMakeLists.txt b/src/Insight/CMakeLists.txt index 3e918ad5..dc929717 100755 --- a/src/Insight/CMakeLists.txt +++ b/src/Insight/CMakeLists.txt @@ -27,6 +27,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadTargetMemory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadStackPointer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/QueryLatestVersionNumber.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/InsightWorker/Tasks/ReadProgramCounter.cpp # Error dialogue window ${CMAKE_CURRENT_SOURCE_DIR}/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp diff --git a/src/Insight/InsightWorker/InsightWorker.cpp b/src/Insight/InsightWorker/InsightWorker.cpp index d2a4957b..5a705b58 100644 --- a/src/Insight/InsightWorker/InsightWorker.cpp +++ b/src/Insight/InsightWorker/InsightWorker.cpp @@ -41,10 +41,6 @@ namespace Bloom std::bind(&InsightWorker::onTargetResetEvent, this, std::placeholders::_1) ); - this->eventListener->registerCallbackForEventType( - std::bind(&InsightWorker::onTargetRegistersWrittenEvent, this, std::placeholders::_1) - ); - this->eventListener->registerCallbackForEventType( std::bind(&InsightWorker::onProgrammingModeEnabledEvent, this, std::placeholders::_1) ); @@ -92,7 +88,6 @@ namespace Bloom this->lastTargetState = TargetState::STOPPED; emit this->targetStateUpdated(TargetState::STOPPED); - emit this->targetProgramCounterUpdated(event.programCounter); } void InsightWorker::onTargetResumedEvent(const Events::TargetExecutionResumed& event) { @@ -113,30 +108,13 @@ namespace Bloom emit this->targetStateUpdated(TargetState::STOPPED); } - emit this->targetProgramCounterUpdated(this->targetControllerConsole.getProgramCounter()); + emit this->targetReset(); } catch (const Exceptions::Exception& exception) { Logger::debug("Error handling TargetReset event - " + exception.getMessage()); } } - void InsightWorker::onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event) { - emit this->targetRegistersWritten(event.registers, event.createdTimestamp); - - for (const auto& reg : event.registers) { - if (reg.descriptor.type == Targets::TargetRegisterType::PROGRAM_COUNTER) { - try { - emit this->targetProgramCounterUpdated(this->targetControllerConsole.getProgramCounter()); - - } catch (const Exceptions::Exception& exception) { - Logger::debug("Error reading program counter - " + exception.getMessage()); - } - - break; - } - } - } - void InsightWorker::onTargetControllerStateChangedEvent(const Events::TargetControllerStateChanged& event) { using TargetController::TargetControllerState; diff --git a/src/Insight/InsightWorker/InsightWorker.hpp b/src/Insight/InsightWorker/InsightWorker.hpp index 3b088524..ca6ae86c 100644 --- a/src/Insight/InsightWorker/InsightWorker.hpp +++ b/src/Insight/InsightWorker/InsightWorker.hpp @@ -38,7 +38,7 @@ namespace Bloom void ready(); void taskQueued(); void targetStateUpdated(Bloom::Targets::TargetState newState); - void targetProgramCounterUpdated(quint32 programCounter); + void targetReset(); void targetControllerSuspended(); void targetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor); void targetRegistersWritten(const Bloom::Targets::TargetRegisters& targetRegisters, const QDateTime& timestamp); @@ -65,7 +65,6 @@ namespace Bloom void onTargetStoppedEvent(const Events::TargetExecutionStopped& event); void onTargetResumedEvent(const Events::TargetExecutionResumed& event); void onTargetResetEvent(const Events::TargetReset& event); - void onTargetRegistersWrittenEvent(const Events::RegistersWrittenToTarget& event); void onTargetControllerStateChangedEvent(const Events::TargetControllerStateChanged& event); void onProgrammingModeEnabledEvent(const Events::ProgrammingModeEnabled& event); void onProgrammingModeDisabledEvent(const Events::ProgrammingModeDisabled& event); diff --git a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp new file mode 100644 index 00000000..f476d4c6 --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.cpp @@ -0,0 +1,10 @@ +#include "ReadProgramCounter.hpp" + +namespace Bloom +{ + using TargetController::TargetControllerConsole; + + void ReadProgramCounter::run(TargetControllerConsole& targetControllerConsole) { + emit this->programCounterRead(targetControllerConsole.getProgramCounter()); + } +} diff --git a/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp new file mode 100644 index 00000000..01509a75 --- /dev/null +++ b/src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "InsightWorkerTask.hpp" + +namespace Bloom +{ + class ReadProgramCounter: public InsightWorkerTask + { + Q_OBJECT + + public: + ReadProgramCounter() = default; + + signals: + void programCounterRead(std::uint32_t programCounter); + + protected: + void run(TargetController::TargetControllerConsole& targetControllerConsole) override; + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index bd78a3c7..c172de76 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -15,6 +15,8 @@ #include "src/Helpers/Paths.hpp" #include "src/Targets/TargetDescriptor.hpp" +#include "src/Insight/InsightWorker/Tasks/ReadProgramCounter.hpp" + namespace Bloom { using namespace Bloom::Exceptions; @@ -262,9 +264,11 @@ namespace Bloom ); QObject::connect( &(this->insightWorker), - &InsightWorker::targetProgramCounterUpdated, + &InsightWorker::targetReset, this, - &InsightWindow::onTargetProgramCounterUpdate + [this] { + this->refreshProgramCounter(); + } ); QObject::connect( @@ -533,11 +537,7 @@ namespace Bloom this->targetPackageWidget->setTargetState(this->targetState); if (this->targetState == TargetState::STOPPED) { - this->targetPackageWidget->refreshPinStates([this] { - if (this->targetState == TargetState::STOPPED) { - this->targetPackageWidget->setDisabled(false); - } - }); + this->refreshPinStates(); } this->adjustPanels(); @@ -840,49 +840,79 @@ namespace Bloom this->programCounterValueLabel->setText("-"); this->setUiDisabled(true); + if (this->targetPackageWidget != nullptr) { + this->targetPackageWidget->setDisabled(true); + } + } else if (newState == TargetState::STOPPED) { this->targetStatusLabel->setText("Stopped"); - this->setUiDisabled(false); + this->refresh(); } else { this->targetStatusLabel->setText("Unknown"); } } - void InsightWindow::onTargetProgramCounterUpdate(quint32 programCounter) { - this->programCounterValueLabel->setText( - "0x" + QString::number(programCounter, 16).toUpper() + " (" + QString::number(programCounter) + ")" - ); - } void InsightWindow::refresh() { if (this->targetState != TargetState::STOPPED || this->selectedVariant == nullptr) { return; } - this->setUiDisabled(true); this->refreshIoInspectionButton->startSpin(); + this->refreshIoInspectionButton->setDisabled(true); if (this->targetPackageWidget != nullptr) { - this->targetPackageWidget->setDisabled(true); - this->targetPackageWidget->refreshPinStates([this] { - if (this->targetState == TargetState::STOPPED) { - this->targetPackageWidget->setDisabled(false); - - if (this->targetRegistersSidePane == nullptr || !this->targetRegistersSidePane->state.activated) { - this->refreshIoInspectionButton->stopSpin(); - this->setUiDisabled(false); - } - } - }); + this->refreshPinStates(); } - if (this->targetRegistersSidePane != nullptr && this->targetRegistersSidePane->state.activated) { - this->targetRegistersSidePane->refreshRegisterValues([this] { - this->refreshIoInspectionButton->stopSpin(); - this->setUiDisabled(false); - }); + if (this->targetRegistersSidePane != nullptr) { + this->targetRegistersSidePane->refreshRegisterValues(); } + + this->refreshProgramCounter([this] { + this->refreshIoInspectionButton->stopSpin(); + + if (this->targetState == TargetState::STOPPED) { + this->refreshIoInspectionButton->setDisabled(false); + } + }); + } + + void InsightWindow::refreshPinStates() { + this->targetPackageWidget->setDisabled(true); + + this->targetPackageWidget->refreshPinStates([this] { + if (this->targetState == TargetState::STOPPED) { + this->targetPackageWidget->setDisabled(false); + } + }); + } + + void InsightWindow::refreshProgramCounter(std::optional> callback) { + auto* readProgramCounterTask = new ReadProgramCounter(); + + QObject::connect( + readProgramCounterTask, + &ReadProgramCounter::programCounterRead, + this, + [this] (std::uint32_t programCounter) { + this->programCounterValueLabel->setText( + "0x" + QString::number(programCounter, 16).toUpper() + " (" + QString::number(programCounter) + ")" + ); + } + ); + + if (callback.has_value()) { + QObject::connect( + readProgramCounterTask, + &ReadProgramCounter::finished, + this, + callback.value() + ); + } + + this->insightWorker.queueTask(readProgramCounterTask); } void InsightWindow::openReportIssuesUrl() { @@ -985,6 +1015,10 @@ namespace Bloom void InsightWindow::onRegistersPaneStateChanged() { this->targetRegistersButton->setChecked(this->targetRegistersSidePane->state.activated); + + if (this->targetState == Targets::TargetState::STOPPED && this->targetRegistersSidePane->state.activated) { + this->targetRegistersSidePane->refreshRegisterValues(); + } } void InsightWindow::onRamInspectionPaneStateChanged() { diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index f94d0929..c28424e0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -131,8 +131,9 @@ namespace Bloom void onTargetControllerSuspended(); void onTargetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor); void onTargetStateUpdate(Targets::TargetState newState); - void onTargetProgramCounterUpdate(quint32 programCounter); void refresh(); + void refreshPinStates(); + void refreshProgramCounter(std::optional> callback = std::nullopt); void openReportIssuesUrl(); void openGettingStartedUrl(); void openAboutWindow(); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterWidget.cpp index 65449b72..a481fef0 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/RegisterWidget.cpp @@ -229,9 +229,5 @@ namespace Bloom::Widgets void RegisterWidget::onTargetStateChange(Targets::TargetState newState) { this->targetState = newState; - - if (this->targetState == Targets::TargetState::RUNNING) { - this->clearInlineValue(); - } } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp index f262c031..01c46e49 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.cpp @@ -115,20 +115,6 @@ namespace Bloom::Widgets itemLayout->addStretch(1); - QObject::connect( - this, - &PaneWidget::paneActivated, - this, - &TargetRegistersPaneWidget::postActivate - ); - - QObject::connect( - this, - &PaneWidget::paneDeactivated, - this, - &TargetRegistersPaneWidget::postDeactivate - ); - QObject::connect( &insightWorker, &InsightWorker::targetStateUpdated, @@ -240,26 +226,15 @@ namespace Bloom::Widgets PaneWidget::resizeEvent(event); } - void TargetRegistersPaneWidget::postActivate() { - if (this->targetState == Targets::TargetState::STOPPED) { - this->refreshRegisterValues(); - } - } - - void TargetRegistersPaneWidget::postDeactivate() { - - } - void TargetRegistersPaneWidget::onTargetStateChanged(Targets::TargetState newState) { if (this->targetState == newState) { return; } - using Targets::TargetState; this->targetState = newState; - if (newState == TargetState::STOPPED && this->state.activated) { - this->refreshRegisterValues(); + if (this->targetState == Targets::TargetState::RUNNING) { + this->clearInlineRegisterValues(); } } @@ -277,4 +252,12 @@ namespace Bloom::Widgets } } } + + void TargetRegistersPaneWidget::clearInlineRegisterValues() { + for (const auto& registerGroupWidget : this->registerGroupWidgets) { + for (auto* registerWidget : registerGroupWidget->registerWidgets) { + registerWidget->clearInlineValue(); + } + } + } } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp index 1ddf2059..aadd2082 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/TargetRegistersPaneWidget.hpp @@ -44,9 +44,6 @@ namespace Bloom::Widgets protected: void resizeEvent(QResizeEvent* event) override; - void postActivate(); - void postDeactivate(); - private: const Targets::TargetDescriptor& targetDescriptor; InsightWorker& insightWorker; @@ -70,5 +67,6 @@ namespace Bloom::Widgets void onTargetStateChanged(Targets::TargetState newState); void onRegistersRead(const Targets::TargetRegisters& registers); + void clearInlineRegisterValues(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp index f39547d2..6009d2e8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp @@ -86,17 +86,6 @@ namespace Bloom::Widgets::InsightTargetWidgets } this->targetState = newState; - - if (newState == TargetState::RUNNING) { - this->setDisabled(true); - - } else if (newState == TargetState::STOPPED) { - this->refreshPinStates([this] { - if (this->targetState == TargetState::STOPPED) { - this->setDisabled(false); - } - }); - } } void TargetPackageWidget::onProgrammingModeEnabled() {