diff --git a/src/EventManager/Events/Event.hpp b/src/EventManager/Events/Event.hpp index 0eabfb97..c2c137d7 100644 --- a/src/EventManager/Events/Event.hpp +++ b/src/EventManager/Events/Event.hpp @@ -29,8 +29,6 @@ namespace Bloom::Events TARGET_EXECUTION_RESUMED, TARGET_EXECUTION_STOPPED, MEMORY_WRITTEN_TO_TARGET, - EXTRACT_TARGET_DESCRIPTOR, - TARGET_DESCRIPTOR_EXTRACTED, INSIGHT_THREAD_STATE_CHANGED, TARGET_RESET, }; diff --git a/src/EventManager/Events/Events.hpp b/src/EventManager/Events/Events.hpp index c4f73637..9605c5cf 100644 --- a/src/EventManager/Events/Events.hpp +++ b/src/EventManager/Events/Events.hpp @@ -16,8 +16,6 @@ #include "TargetExecutionResumed.hpp" #include "TargetExecutionStopped.hpp" #include "MemoryWrittenToTarget.hpp" -#include "ExtractTargetDescriptor.hpp" -#include "TargetDescriptorExtracted.hpp" #include "InsightThreadStateChanged.hpp" #include "TargetReset.hpp" diff --git a/src/EventManager/Events/ExtractTargetDescriptor.hpp b/src/EventManager/Events/ExtractTargetDescriptor.hpp deleted file mode 100644 index 9555b60d..00000000 --- a/src/EventManager/Events/ExtractTargetDescriptor.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include "Event.hpp" - -#include "TargetDescriptorExtracted.hpp" - -namespace Bloom::Events -{ - class ExtractTargetDescriptor: public Event - { - public: - using TargetControllerResponseType = TargetDescriptorExtracted; - - static constexpr EventType type = EventType::EXTRACT_TARGET_DESCRIPTOR; - static inline const std::string name = "ExtractTargetDescriptor"; - - [[nodiscard]] EventType getType() const override { - return ExtractTargetDescriptor::type; - } - - [[nodiscard]] std::string getName() const override { - return ExtractTargetDescriptor::name; - } - }; -} diff --git a/src/EventManager/Events/TargetDescriptorExtracted.hpp b/src/EventManager/Events/TargetDescriptorExtracted.hpp deleted file mode 100644 index 00226d2a..00000000 --- a/src/EventManager/Events/TargetDescriptorExtracted.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -#include "Event.hpp" -#include "src/Targets/TargetDescriptor.hpp" - -namespace Bloom::Events -{ - class TargetDescriptorExtracted: public Event - { - public: - static constexpr EventType type = EventType::TARGET_DESCRIPTOR_EXTRACTED; - static inline const std::string name = "TargetDescriptorExtracted"; - Targets::TargetDescriptor targetDescriptor; - - [[nodiscard]] EventType getType() const override { - return TargetDescriptorExtracted::type; - } - - [[nodiscard]] std::string getName() const override { - return TargetDescriptorExtracted::name; - } - }; -} diff --git a/src/TargetController/Commands/CommandTypes.hpp b/src/TargetController/Commands/CommandTypes.hpp index 9ad7fdbc..1ebe8cbb 100644 --- a/src/TargetController/Commands/CommandTypes.hpp +++ b/src/TargetController/Commands/CommandTypes.hpp @@ -23,5 +23,6 @@ namespace Bloom::TargetController::Commands GET_TARGET_PIN_STATES, SET_TARGET_PIN_STATE, GET_TARGET_STACK_POINTER, + GET_TARGET_DESCRIPTOR, }; } diff --git a/src/TargetController/Commands/GetTargetDescriptor.hpp b/src/TargetController/Commands/GetTargetDescriptor.hpp new file mode 100644 index 00000000..411a54c2 --- /dev/null +++ b/src/TargetController/Commands/GetTargetDescriptor.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "Command.hpp" + +#include "src/TargetController/Responses/TargetDescriptor.hpp" + +namespace Bloom::TargetController::Commands +{ + class GetTargetDescriptor: public Command + { + public: + using SuccessResponseType = Responses::TargetDescriptor; + + static constexpr CommandType type = CommandType::GET_TARGET_DESCRIPTOR; + static inline const std::string name = "GetTargetDescriptor"; + + [[nodiscard]] CommandType getType() const override { + return GetTargetDescriptor::type; + } + }; +} diff --git a/src/TargetController/Responses/ResponseTypes.hpp b/src/TargetController/Responses/ResponseTypes.hpp index ea088694..af717ed5 100644 --- a/src/TargetController/Responses/ResponseTypes.hpp +++ b/src/TargetController/Responses/ResponseTypes.hpp @@ -13,5 +13,6 @@ namespace Bloom::TargetController::Responses TARGET_STATE, TARGET_PIN_STATES, TARGET_STACK_POINTER, + TARGET_DESCRIPTOR, }; } diff --git a/src/TargetController/Responses/TargetDescriptor.hpp b/src/TargetController/Responses/TargetDescriptor.hpp new file mode 100644 index 00000000..54f79b54 --- /dev/null +++ b/src/TargetController/Responses/TargetDescriptor.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include "Response.hpp" + +#include "src/Targets/TargetDescriptor.hpp" + +namespace Bloom::TargetController::Responses +{ + class TargetDescriptor: public Response + { + public: + static constexpr ResponseType type = ResponseType::TARGET_DESCRIPTOR; + + Targets::TargetDescriptor targetDescriptor; + + explicit TargetDescriptor(const Targets::TargetDescriptor& targetDescriptor) + : targetDescriptor(targetDescriptor) + {} + + [[nodiscard]] ResponseType getType() const override { + return TargetDescriptor::type; + } + }; +} diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index a609ea1e..6afcd0bc 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -22,6 +22,7 @@ namespace Bloom::TargetController using Commands::Command; using Commands::CommandIdType; + using Commands::GetTargetDescriptor; using Commands::GetTargetState; using Commands::StopTargetExecution; using Commands::ResumeTargetExecution; @@ -393,6 +394,7 @@ namespace Bloom::TargetController + std::string(exception.what())); } + this->deregisterCommandHandler(GetTargetDescriptor::type); this->deregisterCommandHandler(GetTargetState::type); this->deregisterCommandHandler(StopTargetExecution::type); this->deregisterCommandHandler(ResumeTargetExecution::type); @@ -410,7 +412,6 @@ namespace Bloom::TargetController this->deregisterCommandHandler(GetTargetStackPointer::type); this->eventListener->deregisterCallbacksForEventType(); - this->eventListener->deregisterCallbacksForEventType(); this->lastTargetState = TargetState::UNKNOWN; this->cachedTargetDescriptor = std::nullopt; @@ -427,6 +428,10 @@ namespace Bloom::TargetController this->acquireHardware(); this->loadRegisterDescriptors(); + this->registerCommandHandler( + std::bind(&TargetControllerComponent::handleGetTargetDescriptor, this, std::placeholders::_1) + ); + this->registerCommandHandler( std::bind(&TargetControllerComponent::handleGetTargetState, this, std::placeholders::_1) ); @@ -491,10 +496,6 @@ namespace Bloom::TargetController std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1) ); - this->eventListener->registerCallbackForEventType( - std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1) - ); - TargetControllerComponent::state = TargetControllerState::ACTIVE; EventManager::triggerEvent( std::make_shared(TargetControllerComponent::state) @@ -710,14 +711,6 @@ namespace Bloom::TargetController this->shutdown(); } - void TargetControllerComponent::onExtractTargetDescriptor(const Events::ExtractTargetDescriptor& event) { - auto targetDescriptorExtracted = std::make_shared(); - targetDescriptorExtracted->targetDescriptor = this->getTargetDescriptor(); - - targetDescriptorExtracted->correlationId = event.id; - EventManager::triggerEvent(targetDescriptorExtracted); - } - void TargetControllerComponent::onDebugSessionStartedEvent(const Events::DebugSessionStarted&) { if (TargetControllerComponent::state == TargetControllerState::SUSPENDED) { Logger::debug("Waking TargetController"); @@ -738,6 +731,12 @@ namespace Bloom::TargetController } } + std::unique_ptr TargetControllerComponent::handleGetTargetDescriptor( + GetTargetDescriptor& command + ) { + return std::make_unique(this->getTargetDescriptor()); + } + std::unique_ptr TargetControllerComponent::handleGetTargetState(GetTargetState& command) { return std::make_unique(this->target->getState()); } diff --git a/src/TargetController/TargetControllerComponent.hpp b/src/TargetController/TargetControllerComponent.hpp index 027d40de..4d8038c8 100644 --- a/src/TargetController/TargetControllerComponent.hpp +++ b/src/TargetController/TargetControllerComponent.hpp @@ -18,6 +18,7 @@ // Commands #include "Commands/Command.hpp" +#include "Commands/GetTargetDescriptor.hpp" #include "Commands/GetTargetState.hpp" #include "Commands/StopTargetExecution.hpp" #include "Commands/ResumeTargetExecution.hpp" @@ -36,6 +37,7 @@ // Responses #include "Responses/Response.hpp" +#include "Responses/TargetDescriptor.hpp" #include "Responses/TargetState.hpp" #include "Responses/TargetRegistersRead.hpp" #include "Responses/TargetMemoryRead.hpp" @@ -282,13 +284,6 @@ namespace Bloom::TargetController */ void onShutdownTargetControllerEvent(const Events::ShutdownTargetController& event); - /** - * Obtains a TargetDescriptor from the target and includes it in a TargetDescriptorExtracted event. - * - * @param event - */ - void onExtractTargetDescriptor(const Events::ExtractTargetDescriptor& event); - /** * Will hold the target stopped at it's current state. * @@ -303,6 +298,7 @@ namespace Bloom::TargetController */ void onDebugSessionFinishedEvent(const Events::DebugSessionFinished& event); + std::unique_ptr handleGetTargetDescriptor(Commands::GetTargetDescriptor& command); std::unique_ptr handleGetTargetState(Commands::GetTargetState& command); std::unique_ptr handleStopTargetExecution(Commands::StopTargetExecution& command); std::unique_ptr handleResumeTargetExecution(Commands::ResumeTargetExecution& command); diff --git a/src/TargetController/TargetControllerConsole.cpp b/src/TargetController/TargetControllerConsole.cpp index 61b0ec63..43c40c5e 100644 --- a/src/TargetController/TargetControllerConsole.cpp +++ b/src/TargetController/TargetControllerConsole.cpp @@ -5,6 +5,7 @@ #include "TargetControllerComponent.hpp" // Commands +#include "Commands/GetTargetDescriptor.hpp" #include "Commands/GetTargetState.hpp" #include "Commands/StopTargetExecution.hpp" #include "Commands/ResumeTargetExecution.hpp" @@ -29,6 +30,7 @@ namespace Bloom::TargetController using namespace Bloom::Events; using namespace Bloom::Exceptions; + using Commands::GetTargetDescriptor; using Commands::GetTargetState; using Commands::StopTargetExecution; using Commands::ResumeTargetExecution; @@ -63,8 +65,9 @@ namespace Bloom::TargetController } Targets::TargetDescriptor TargetControllerConsole::getTargetDescriptor() { - return this->triggerTargetControllerEventAndWaitForResponse( - std::make_shared() + return this->commandManager.sendCommandAndWaitForResponse( + std::make_unique(), + this->defaultTimeout )->targetDescriptor; }