Replaced ExtractTargetDescriptor event with TC command

This commit is contained in:
Nav
2022-05-01 18:30:58 +01:00
parent d8af8fe1ee
commit 96cae9d1e4
11 changed files with 69 additions and 78 deletions

View File

@@ -29,8 +29,6 @@ namespace Bloom::Events
TARGET_EXECUTION_RESUMED, TARGET_EXECUTION_RESUMED,
TARGET_EXECUTION_STOPPED, TARGET_EXECUTION_STOPPED,
MEMORY_WRITTEN_TO_TARGET, MEMORY_WRITTEN_TO_TARGET,
EXTRACT_TARGET_DESCRIPTOR,
TARGET_DESCRIPTOR_EXTRACTED,
INSIGHT_THREAD_STATE_CHANGED, INSIGHT_THREAD_STATE_CHANGED,
TARGET_RESET, TARGET_RESET,
}; };

View File

@@ -16,8 +16,6 @@
#include "TargetExecutionResumed.hpp" #include "TargetExecutionResumed.hpp"
#include "TargetExecutionStopped.hpp" #include "TargetExecutionStopped.hpp"
#include "MemoryWrittenToTarget.hpp" #include "MemoryWrittenToTarget.hpp"
#include "ExtractTargetDescriptor.hpp"
#include "TargetDescriptorExtracted.hpp"
#include "InsightThreadStateChanged.hpp" #include "InsightThreadStateChanged.hpp"
#include "TargetReset.hpp" #include "TargetReset.hpp"

View File

@@ -1,27 +0,0 @@
#pragma once
#include <string>
#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;
}
};
}

View File

@@ -1,25 +0,0 @@
#pragma once
#include <string>
#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;
}
};
}

View File

@@ -23,5 +23,6 @@ namespace Bloom::TargetController::Commands
GET_TARGET_PIN_STATES, GET_TARGET_PIN_STATES,
SET_TARGET_PIN_STATE, SET_TARGET_PIN_STATE,
GET_TARGET_STACK_POINTER, GET_TARGET_STACK_POINTER,
GET_TARGET_DESCRIPTOR,
}; };
} }

View File

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

View File

@@ -13,5 +13,6 @@ namespace Bloom::TargetController::Responses
TARGET_STATE, TARGET_STATE,
TARGET_PIN_STATES, TARGET_PIN_STATES,
TARGET_STACK_POINTER, TARGET_STACK_POINTER,
TARGET_DESCRIPTOR,
}; };
} }

View File

@@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
#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;
}
};
}

View File

@@ -22,6 +22,7 @@ namespace Bloom::TargetController
using Commands::Command; using Commands::Command;
using Commands::CommandIdType; using Commands::CommandIdType;
using Commands::GetTargetDescriptor;
using Commands::GetTargetState; using Commands::GetTargetState;
using Commands::StopTargetExecution; using Commands::StopTargetExecution;
using Commands::ResumeTargetExecution; using Commands::ResumeTargetExecution;
@@ -393,6 +394,7 @@ namespace Bloom::TargetController
+ std::string(exception.what())); + std::string(exception.what()));
} }
this->deregisterCommandHandler(GetTargetDescriptor::type);
this->deregisterCommandHandler(GetTargetState::type); this->deregisterCommandHandler(GetTargetState::type);
this->deregisterCommandHandler(StopTargetExecution::type); this->deregisterCommandHandler(StopTargetExecution::type);
this->deregisterCommandHandler(ResumeTargetExecution::type); this->deregisterCommandHandler(ResumeTargetExecution::type);
@@ -410,7 +412,6 @@ namespace Bloom::TargetController
this->deregisterCommandHandler(GetTargetStackPointer::type); this->deregisterCommandHandler(GetTargetStackPointer::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>(); this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->lastTargetState = TargetState::UNKNOWN; this->lastTargetState = TargetState::UNKNOWN;
this->cachedTargetDescriptor = std::nullopt; this->cachedTargetDescriptor = std::nullopt;
@@ -427,6 +428,10 @@ namespace Bloom::TargetController
this->acquireHardware(); this->acquireHardware();
this->loadRegisterDescriptors(); this->loadRegisterDescriptors();
this->registerCommandHandler<GetTargetDescriptor>(
std::bind(&TargetControllerComponent::handleGetTargetDescriptor, this, std::placeholders::_1)
);
this->registerCommandHandler<GetTargetState>( this->registerCommandHandler<GetTargetState>(
std::bind(&TargetControllerComponent::handleGetTargetState, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleGetTargetState, this, std::placeholders::_1)
); );
@@ -491,10 +496,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
); );
this->eventListener->registerCallbackForEventType<Events::ExtractTargetDescriptor>(
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
);
TargetControllerComponent::state = TargetControllerState::ACTIVE; TargetControllerComponent::state = TargetControllerState::ACTIVE;
EventManager::triggerEvent( EventManager::triggerEvent(
std::make_shared<TargetControllerStateChanged>(TargetControllerComponent::state) std::make_shared<TargetControllerStateChanged>(TargetControllerComponent::state)
@@ -710,14 +711,6 @@ namespace Bloom::TargetController
this->shutdown(); this->shutdown();
} }
void TargetControllerComponent::onExtractTargetDescriptor(const Events::ExtractTargetDescriptor& event) {
auto targetDescriptorExtracted = std::make_shared<TargetDescriptorExtracted>();
targetDescriptorExtracted->targetDescriptor = this->getTargetDescriptor();
targetDescriptorExtracted->correlationId = event.id;
EventManager::triggerEvent(targetDescriptorExtracted);
}
void TargetControllerComponent::onDebugSessionStartedEvent(const Events::DebugSessionStarted&) { void TargetControllerComponent::onDebugSessionStartedEvent(const Events::DebugSessionStarted&) {
if (TargetControllerComponent::state == TargetControllerState::SUSPENDED) { if (TargetControllerComponent::state == TargetControllerState::SUSPENDED) {
Logger::debug("Waking TargetController"); Logger::debug("Waking TargetController");
@@ -738,6 +731,12 @@ namespace Bloom::TargetController
} }
} }
std::unique_ptr<Responses::TargetDescriptor> TargetControllerComponent::handleGetTargetDescriptor(
GetTargetDescriptor& command
) {
return std::make_unique<Responses::TargetDescriptor>(this->getTargetDescriptor());
}
std::unique_ptr<Responses::TargetState> TargetControllerComponent::handleGetTargetState(GetTargetState& command) { std::unique_ptr<Responses::TargetState> TargetControllerComponent::handleGetTargetState(GetTargetState& command) {
return std::make_unique<Responses::TargetState>(this->target->getState()); return std::make_unique<Responses::TargetState>(this->target->getState());
} }

View File

@@ -18,6 +18,7 @@
// Commands // Commands
#include "Commands/Command.hpp" #include "Commands/Command.hpp"
#include "Commands/GetTargetDescriptor.hpp"
#include "Commands/GetTargetState.hpp" #include "Commands/GetTargetState.hpp"
#include "Commands/StopTargetExecution.hpp" #include "Commands/StopTargetExecution.hpp"
#include "Commands/ResumeTargetExecution.hpp" #include "Commands/ResumeTargetExecution.hpp"
@@ -36,6 +37,7 @@
// Responses // Responses
#include "Responses/Response.hpp" #include "Responses/Response.hpp"
#include "Responses/TargetDescriptor.hpp"
#include "Responses/TargetState.hpp" #include "Responses/TargetState.hpp"
#include "Responses/TargetRegistersRead.hpp" #include "Responses/TargetRegistersRead.hpp"
#include "Responses/TargetMemoryRead.hpp" #include "Responses/TargetMemoryRead.hpp"
@@ -282,13 +284,6 @@ namespace Bloom::TargetController
*/ */
void onShutdownTargetControllerEvent(const Events::ShutdownTargetController& event); 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. * Will hold the target stopped at it's current state.
* *
@@ -303,6 +298,7 @@ namespace Bloom::TargetController
*/ */
void onDebugSessionFinishedEvent(const Events::DebugSessionFinished& event); void onDebugSessionFinishedEvent(const Events::DebugSessionFinished& event);
std::unique_ptr<Responses::TargetDescriptor> handleGetTargetDescriptor(Commands::GetTargetDescriptor& command);
std::unique_ptr<Responses::TargetState> handleGetTargetState(Commands::GetTargetState& command); std::unique_ptr<Responses::TargetState> handleGetTargetState(Commands::GetTargetState& command);
std::unique_ptr<Responses::Response> handleStopTargetExecution(Commands::StopTargetExecution& command); std::unique_ptr<Responses::Response> handleStopTargetExecution(Commands::StopTargetExecution& command);
std::unique_ptr<Responses::Response> handleResumeTargetExecution(Commands::ResumeTargetExecution& command); std::unique_ptr<Responses::Response> handleResumeTargetExecution(Commands::ResumeTargetExecution& command);

View File

@@ -5,6 +5,7 @@
#include "TargetControllerComponent.hpp" #include "TargetControllerComponent.hpp"
// Commands // Commands
#include "Commands/GetTargetDescriptor.hpp"
#include "Commands/GetTargetState.hpp" #include "Commands/GetTargetState.hpp"
#include "Commands/StopTargetExecution.hpp" #include "Commands/StopTargetExecution.hpp"
#include "Commands/ResumeTargetExecution.hpp" #include "Commands/ResumeTargetExecution.hpp"
@@ -29,6 +30,7 @@ namespace Bloom::TargetController
using namespace Bloom::Events; using namespace Bloom::Events;
using namespace Bloom::Exceptions; using namespace Bloom::Exceptions;
using Commands::GetTargetDescriptor;
using Commands::GetTargetState; using Commands::GetTargetState;
using Commands::StopTargetExecution; using Commands::StopTargetExecution;
using Commands::ResumeTargetExecution; using Commands::ResumeTargetExecution;
@@ -63,8 +65,9 @@ namespace Bloom::TargetController
} }
Targets::TargetDescriptor TargetControllerConsole::getTargetDescriptor() { Targets::TargetDescriptor TargetControllerConsole::getTargetDescriptor() {
return this->triggerTargetControllerEventAndWaitForResponse( return this->commandManager.sendCommandAndWaitForResponse(
std::make_shared<ExtractTargetDescriptor>() std::make_unique<GetTargetDescriptor>(),
this->defaultTimeout
)->targetDescriptor; )->targetDescriptor;
} }