Renamed component (DebugServer and TargetController) state changed events to be specific to thread states

This commit is contained in:
Nav
2021-05-24 21:09:50 +01:00
parent 76e5fba383
commit 897482de1d
8 changed files with 27 additions and 54 deletions

View File

@@ -105,12 +105,12 @@ void Application::startup() {
throw InvalidConfig("Debug server configuration missing.");
}
applicationEventListener->registerCallbackForEventType<Events::TargetControllerStateChanged>(
std::bind(&Application::onTargetControllerStateChanged, this, std::placeholders::_1)
applicationEventListener->registerCallbackForEventType<Events::TargetControllerThreadStateChanged>(
std::bind(&Application::onTargetControllerThreadStateChanged, this, std::placeholders::_1)
);
applicationEventListener->registerCallbackForEventType<Events::DebugServerStateChanged>(
std::bind(&Application::onDebugServerStateChanged, this, std::placeholders::_1)
applicationEventListener->registerCallbackForEventType<Events::DebugServerThreadStateChanged>(
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<Events::TargetControllerStateChanged>();
auto tcStateChangeEvent = this->applicationEventListener->waitForEvent<Events::TargetControllerThreadStateChanged>();
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<Events::ShutdownTargetController>());
this->applicationEventListener->waitForEvent<Events::TargetControllerStateChanged>(
this->applicationEventListener->waitForEvent<Events::TargetControllerThreadStateChanged>(
std::chrono::milliseconds(10000)
);
}
@@ -287,7 +286,7 @@ void Application::startDebugServer() {
this->debugServer.get()
);
auto dsStateChangeEvent = this->applicationEventListener->waitForEvent<Events::DebugServerStateChanged>();
auto dsStateChangeEvent = this->applicationEventListener->waitForEvent<Events::DebugServerThreadStateChanged>();
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<Events::ShutdownDebugServer>());
this->applicationEventListener->waitForEvent<Events::DebugServerStateChanged>(
this->applicationEventListener->waitForEvent<Events::DebugServerThreadStateChanged>(
std::chrono::milliseconds(5000)
);
}
@@ -315,7 +314,7 @@ void Application::stopDebugServer() {
}
}
void Application::onTargetControllerStateChanged(EventPointer<Events::TargetControllerStateChanged> event) {
void Application::onTargetControllerThreadStateChanged(EventPointer<Events::TargetControllerThreadStateChanged> 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(EventPointer<Events::ShutdownAppl
this->shutdown();
}
void Application::onDebugServerStateChanged(EventPointer<Events::DebugServerStateChanged> event) {
void Application::onDebugServerThreadStateChanged(EventPointer<Events::DebugServerThreadStateChanged> event) {
if (event->getState() == ThreadState::STOPPED || event->getState() == ThreadState::SHUTDOWN_INITIATED) {
// DebugServer has unexpectedly shutdown - it must have encountered a fatal error.
this->shutdown();

View File

@@ -233,7 +233,7 @@ namespace Bloom
*
* @param event
*/
void onTargetControllerStateChanged(EventPointer<Events::TargetControllerStateChanged> event);
void onTargetControllerThreadStateChanged(Events::EventPointer<Events::TargetControllerThreadStateChanged> 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<Events::DebugServerStateChanged> event);
void onDebugServerThreadStateChanged(Events::EventPointer<Events::DebugServerThreadStateChanged> event);
/**
* Triggers a shutdown of Bloom and all of its components.
*/
void onShutdownApplicationRequest(EventPointer<Events::ShutdownApplication>);
void onShutdownApplicationRequest(Events::EventPointer<Events::ShutdownApplication>);
/**
* Returns the path to the directory in which the Bloom binary resides.

View File

@@ -50,7 +50,7 @@ namespace Bloom::DebugServers
void setStateAndEmitEvent(ThreadState state) {
Thread::setState(state);
this->eventManager.triggerEvent(
std::make_shared<Events::DebugServerStateChanged>(state)
std::make_shared<Events::DebugServerThreadStateChanged>(state)
);
};
@@ -59,7 +59,7 @@ namespace Bloom::DebugServers
*
* @param event
*/
void onShutdownDebugServerEvent(EventPointer<Events::ShutdownDebugServer> event);
void onShutdownDebugServerEvent(Events::EventPointer<Events::ShutdownDebugServer> event);
protected:
/**

View File

@@ -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 {

View File

@@ -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"

View File

@@ -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;
}
};
}

View File

@@ -43,8 +43,8 @@ void Insight::startup() {
std::bind(&Insight::onShutdownApplicationEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<TargetControllerStateChanged>(
std::bind(&Insight::onTargetControllerStateChangedEvent, this, std::placeholders::_1)
this->eventListener->registerCallbackForEventType<TargetControllerThreadStateChanged>(
std::bind(&Insight::onTargetControllerThreadStateChangedEvent, this, std::placeholders::_1)
);
auto targetDescriptor = this->targetControllerConsole.getTargetDescriptor();
@@ -123,7 +123,7 @@ void Insight::onShutdownApplicationEvent(EventPointer<ShutdownApplication>) {
this->shutdown();
}
void Insight::onTargetControllerStateChangedEvent(EventPointer<TargetControllerStateChanged> event) {
void Insight::onTargetControllerThreadStateChangedEvent(EventPointer<TargetControllerThreadStateChanged> event) {
if (event->getState() == ThreadState::STOPPED) {
// Something horrible has happened with the TargetController - Insight is useless without the TargetController
this->shutdown();

View File

@@ -88,7 +88,9 @@ namespace Bloom
*
* @param event
*/
void onTargetControllerStateChangedEvent(EventPointer<TargetControllerStateChanged> event);
void onTargetControllerThreadStateChangedEvent(
Events::EventPointer<Events::TargetControllerThreadStateChanged> event
);
/**
* Dispatches any events currently in the queue.