From 897482de1d6e6620695b715de56a7bc46e7fec51 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 24 May 2021 21:09:50 +0100 Subject: [PATCH] Renamed component (DebugServer and TargetController) state changed events to be specific to thread states --- src/Application.cpp | 21 +++++++------- src/Application.hpp | 6 ++-- src/DebugServers/DebugServer.hpp | 4 +-- ....hpp => DebugServerThreadStateChanged.hpp} | 8 +++--- src/EventManager/Events/Events.hpp | 4 +-- .../Events/TargetControllerStateChanged.hpp | 28 ------------------- src/Insight/Insight.cpp | 6 ++-- src/Insight/Insight.hpp | 4 ++- 8 files changed, 27 insertions(+), 54 deletions(-) rename src/EventManager/Events/{DebugServerStateChanged.hpp => DebugServerThreadStateChanged.hpp} (53%) delete mode 100644 src/EventManager/Events/TargetControllerStateChanged.hpp diff --git a/src/Application.cpp b/src/Application.cpp index 2f0e1fcb..ebb7bb38 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -105,12 +105,12 @@ void Application::startup() { throw InvalidConfig("Debug server configuration missing."); } - applicationEventListener->registerCallbackForEventType( - std::bind(&Application::onTargetControllerStateChanged, this, std::placeholders::_1) + applicationEventListener->registerCallbackForEventType( + std::bind(&Application::onTargetControllerThreadStateChanged, this, std::placeholders::_1) ); - applicationEventListener->registerCallbackForEventType( - std::bind(&Application::onDebugServerStateChanged, this, std::placeholders::_1) + applicationEventListener->registerCallbackForEventType( + std::bind(&Application::onDebugServerThreadStateChanged, this, std::placeholders::_1) ); this->startTargetController(); @@ -245,7 +245,7 @@ void Application::startTargetController() { std::ref(this->targetController) ); - auto tcStateChangeEvent = this->applicationEventListener->waitForEvent(); + auto tcStateChangeEvent = this->applicationEventListener->waitForEvent(); if (!tcStateChangeEvent.has_value() || tcStateChangeEvent->get()->getState() != ThreadState::READY) { throw Exception("TargetController failed to startup."); @@ -255,9 +255,8 @@ void Application::startTargetController() { void Application::stopTargetController() { auto targetControllerState = this->targetController.getState(); if (targetControllerState == ThreadState::STARTING || targetControllerState == ThreadState::READY) { - // this->applicationEventListener->clearEventsOfType(Events::TargetControllerStateChanged::name); this->eventManager.triggerEvent(std::make_shared()); - this->applicationEventListener->waitForEvent( + this->applicationEventListener->waitForEvent( std::chrono::milliseconds(10000) ); } @@ -287,7 +286,7 @@ void Application::startDebugServer() { this->debugServer.get() ); - auto dsStateChangeEvent = this->applicationEventListener->waitForEvent(); + auto dsStateChangeEvent = this->applicationEventListener->waitForEvent(); if (!dsStateChangeEvent.has_value() || dsStateChangeEvent->get()->getState() != ThreadState::READY) { throw Exception("DebugServer failed to startup."); @@ -303,7 +302,7 @@ void Application::stopDebugServer() { auto debugServerState = this->debugServer->getState(); if (debugServerState == ThreadState::STARTING || debugServerState == ThreadState::READY) { this->eventManager.triggerEvent(std::make_shared()); - this->applicationEventListener->waitForEvent( + this->applicationEventListener->waitForEvent( std::chrono::milliseconds(5000) ); } @@ -315,7 +314,7 @@ void Application::stopDebugServer() { } } -void Application::onTargetControllerStateChanged(EventPointer event) { +void Application::onTargetControllerThreadStateChanged(EventPointer event) { if (event->getState() == ThreadState::STOPPED || event->getState() == ThreadState::SHUTDOWN_INITIATED) { // TargetController has unexpectedly shutdown - it must have encountered a fatal error. this->shutdown(); @@ -327,7 +326,7 @@ void Application::onShutdownApplicationRequest(EventPointershutdown(); } -void Application::onDebugServerStateChanged(EventPointer event) { +void Application::onDebugServerThreadStateChanged(EventPointer event) { if (event->getState() == ThreadState::STOPPED || event->getState() == ThreadState::SHUTDOWN_INITIATED) { // DebugServer has unexpectedly shutdown - it must have encountered a fatal error. this->shutdown(); diff --git a/src/Application.hpp b/src/Application.hpp index 2231cd63..61bcaf72 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -233,7 +233,7 @@ namespace Bloom * * @param event */ - void onTargetControllerStateChanged(EventPointer event); + void onTargetControllerThreadStateChanged(Events::EventPointer event); /** * Same goes for the DebugServer - it should never shutdown unless a shutdown request was issued. If it does, @@ -241,12 +241,12 @@ namespace Bloom * * @param event */ - void onDebugServerStateChanged(EventPointer event); + void onDebugServerThreadStateChanged(Events::EventPointer event); /** * Triggers a shutdown of Bloom and all of its components. */ - void onShutdownApplicationRequest(EventPointer); + void onShutdownApplicationRequest(Events::EventPointer); /** * Returns the path to the directory in which the Bloom binary resides. diff --git a/src/DebugServers/DebugServer.hpp b/src/DebugServers/DebugServer.hpp index 0796a5dc..12bb3fbc 100644 --- a/src/DebugServers/DebugServer.hpp +++ b/src/DebugServers/DebugServer.hpp @@ -50,7 +50,7 @@ namespace Bloom::DebugServers void setStateAndEmitEvent(ThreadState state) { Thread::setState(state); this->eventManager.triggerEvent( - std::make_shared(state) + std::make_shared(state) ); }; @@ -59,7 +59,7 @@ namespace Bloom::DebugServers * * @param event */ - void onShutdownDebugServerEvent(EventPointer event); + void onShutdownDebugServerEvent(Events::EventPointer event); protected: /** diff --git a/src/EventManager/Events/DebugServerStateChanged.hpp b/src/EventManager/Events/DebugServerThreadStateChanged.hpp similarity index 53% rename from src/EventManager/Events/DebugServerStateChanged.hpp rename to src/EventManager/Events/DebugServerThreadStateChanged.hpp index 171f53ed..2b65a15f 100644 --- a/src/EventManager/Events/DebugServerStateChanged.hpp +++ b/src/EventManager/Events/DebugServerThreadStateChanged.hpp @@ -5,17 +5,17 @@ namespace Bloom::Events { - class DebugServerStateChanged: public Event + class DebugServerThreadStateChanged: public Event { private: ThreadState state; public: - DebugServerStateChanged(ThreadState state): state(state) {}; + DebugServerThreadStateChanged(ThreadState state): state(state) {}; - static inline const std::string name = "DebugServerStateChanged"; + static inline const std::string name = "DebugServerThreadStateChanged"; std::string getName() const override { - return DebugServerStateChanged::name; + return DebugServerThreadStateChanged::name; } ThreadState getState() const { diff --git a/src/EventManager/Events/Events.hpp b/src/EventManager/Events/Events.hpp index 1d6cd1fe..c9a476b6 100644 --- a/src/EventManager/Events/Events.hpp +++ b/src/EventManager/Events/Events.hpp @@ -8,12 +8,12 @@ #include "ResetTarget.hpp" #include "DebugSessionStarted.hpp" #include "DebugSessionFinished.hpp" -#include "TargetControllerStateChanged.hpp" +#include "TargetControllerThreadStateChanged.hpp" #include "TargetControllerStopped.hpp" #include "ShutdownTargetController.hpp" #include "TargetControllerErrorOccurred.hpp" #include "ShutdownApplication.hpp" -#include "DebugServerStateChanged.hpp" +#include "DebugServerThreadStateChanged.hpp" #include "ShutdownDebugServer.hpp" #include "RetrieveRegistersFromTarget.hpp" #include "RegistersRetrievedFromTarget.hpp" diff --git a/src/EventManager/Events/TargetControllerStateChanged.hpp b/src/EventManager/Events/TargetControllerStateChanged.hpp deleted file mode 100644 index 23188f83..00000000 --- a/src/EventManager/Events/TargetControllerStateChanged.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "Event.hpp" -#include "src/Helpers/Thread.hpp" - -namespace Bloom::Events -{ - - class TargetControllerStateChanged: public Event - { - private: - ThreadState state; - public: - TargetControllerStateChanged(ThreadState state): state(state) { - - }; - - static inline const std::string name = "TargetControllerStateChanged"; - - std::string getName() const override { - return TargetControllerStateChanged::name; - } - - ThreadState getState() const { - return this->state; - } - }; -} diff --git a/src/Insight/Insight.cpp b/src/Insight/Insight.cpp index 5143e863..8e23add8 100644 --- a/src/Insight/Insight.cpp +++ b/src/Insight/Insight.cpp @@ -43,8 +43,8 @@ void Insight::startup() { std::bind(&Insight::onShutdownApplicationEvent, this, std::placeholders::_1) ); - this->eventListener->registerCallbackForEventType( - std::bind(&Insight::onTargetControllerStateChangedEvent, this, std::placeholders::_1) + this->eventListener->registerCallbackForEventType( + std::bind(&Insight::onTargetControllerThreadStateChangedEvent, this, std::placeholders::_1) ); auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor(); @@ -123,7 +123,7 @@ void Insight::onShutdownApplicationEvent(EventPointer) { this->shutdown(); } -void Insight::onTargetControllerStateChangedEvent(EventPointer event) { +void Insight::onTargetControllerThreadStateChangedEvent(EventPointer event) { if (event->getState() == ThreadState::STOPPED) { // Something horrible has happened with the TargetController - Insight is useless without the TargetController this->shutdown(); diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index daaf130f..522a155f 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -88,7 +88,9 @@ namespace Bloom * * @param event */ - void onTargetControllerStateChangedEvent(EventPointer event); + void onTargetControllerThreadStateChangedEvent( + Events::EventPointer event + ); /** * Dispatches any events currently in the queue.