From 3540228f6d47bde0d9c5e4461576e69807c7a82d Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 25 May 2023 00:29:46 +0100 Subject: [PATCH] Shut down on device failure (instead of suspending) --- .../TargetControllerComponent.cpp | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index 8b799ef0..e6366c21 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -67,31 +67,14 @@ namespace Bloom::TargetController Logger::debug("TargetController ready and waiting for events."); while (this->getThreadState() == ThreadState::READY) { - try { - if (this->state == TargetControllerState::ACTIVE) { - this->fireTargetEvents(); - } - - TargetControllerComponent::notifier.waitForNotification(std::chrono::milliseconds(60)); - - this->processQueuedCommands(); - this->eventListener->dispatchCurrentEvents(); - - } catch (const DeviceFailure& exception) { - /* - * Upon a device failure, we assume Bloom has lost control of the debug tool. This could be the - * result of the user disconnecting the debug tool, or issuing a soft reset. The soft reset could - * have been issued via another application, without the user's knowledge. - * See https://github.com/navnavnav/Bloom/issues/3 for more on that. - * - * The TC will go into a suspended state and the DebugServer should terminate any active debug - * session. When the user attempts to start another debug session, we will try to re-connect to the - * debug tool. - */ - Logger::error("Device failure detected - " + exception.getMessage()); - Logger::error("Suspending TargetController"); - this->suspend(); + if (this->state == TargetControllerState::ACTIVE) { + this->fireTargetEvents(); } + + TargetControllerComponent::notifier.waitForNotification(std::chrono::milliseconds(60)); + + this->processQueuedCommands(); + this->eventListener->dispatchCurrentEvents(); } } catch (const std::exception& exception) { @@ -392,6 +375,14 @@ namespace Bloom::TargetController this->registerCommandResponse(commandId, commandHandlerIt->second(*(command.get()))); + } catch (const DeviceFailure& exception) { + this->registerCommandResponse( + commandId, + std::make_unique(exception.getMessage()) + ); + + throw exception; + } catch (const Exception& exception) { this->registerCommandResponse( commandId,