Replaced ResetTarget event with TC command
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "ResetTarget.hpp"
|
||||
#include "DebugSessionStarted.hpp"
|
||||
#include "DebugSessionFinished.hpp"
|
||||
#include "TargetControllerThreadStateChanged.hpp"
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "TargetReset.hpp"
|
||||
|
||||
namespace Bloom::Events
|
||||
{
|
||||
class ResetTarget: public Event
|
||||
{
|
||||
public:
|
||||
using TargetControllerResponseType = TargetReset;
|
||||
|
||||
static constexpr EventType type = EventType::RESET_TARGET;
|
||||
static inline const std::string name = "ResetTargetEvent";
|
||||
|
||||
[[nodiscard]] EventType getType() const override {
|
||||
return ResetTarget::type;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string getName() const override {
|
||||
return ResetTarget::name;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -9,5 +9,6 @@ namespace Bloom::TargetController::Commands
|
||||
GENERIC,
|
||||
STOP_TARGET_EXECUTION,
|
||||
RESUME_TARGET_EXECUTION,
|
||||
RESET_TARGET,
|
||||
};
|
||||
}
|
||||
|
||||
17
src/TargetController/Commands/ResetTarget.hpp
Normal file
17
src/TargetController/Commands/ResetTarget.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
|
||||
namespace Bloom::TargetController::Commands
|
||||
{
|
||||
class ResetTarget: public Command
|
||||
{
|
||||
public:
|
||||
static constexpr CommandType type = CommandType::RESET_TARGET;
|
||||
static inline const std::string name = "ResetTarget";
|
||||
|
||||
[[nodiscard]] CommandType getType() const override {
|
||||
return ResetTarget::type;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -24,6 +24,7 @@ namespace Bloom::TargetController
|
||||
using Commands::CommandIdType;
|
||||
using Commands::StopTargetExecution;
|
||||
using Commands::ResumeTargetExecution;
|
||||
using Commands::ResetTarget;
|
||||
|
||||
using Responses::Response;
|
||||
|
||||
@@ -372,6 +373,7 @@ namespace Bloom::TargetController
|
||||
|
||||
this->deregisterCommandHandler(StopTargetExecution::type);
|
||||
this->deregisterCommandHandler(ResumeTargetExecution::type);
|
||||
this->deregisterCommandHandler(ResetTarget::type);
|
||||
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
|
||||
@@ -411,6 +413,10 @@ namespace Bloom::TargetController
|
||||
std::bind(&TargetControllerComponent::handleResumeTargetExecution, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->registerCommandHandler<ResetTarget>(
|
||||
std::bind(&TargetControllerComponent::handleResetTarget, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
|
||||
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
|
||||
);
|
||||
@@ -467,10 +473,6 @@ namespace Bloom::TargetController
|
||||
std::bind(&TargetControllerComponent::onRetrieveStackPointerEvent, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->eventListener->registerCallbackForEventType<Events::ResetTarget>(
|
||||
std::bind(&TargetControllerComponent::onResetTarget, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->state = TargetControllerState::ACTIVE;
|
||||
EventManager::triggerEvent(
|
||||
std::make_shared<TargetControllerStateReported>(this->state)
|
||||
@@ -660,13 +662,10 @@ namespace Bloom::TargetController
|
||||
}
|
||||
}
|
||||
|
||||
void TargetControllerComponent::resetTarget(const std::optional<int>& resetEventCorrelationId) {
|
||||
void TargetControllerComponent::resetTarget() {
|
||||
this->target->reset();
|
||||
|
||||
auto targetResetEvent = std::make_shared<Events::TargetReset>();
|
||||
targetResetEvent->correlationId = resetEventCorrelationId;
|
||||
|
||||
EventManager::triggerEvent(targetResetEvent);
|
||||
EventManager::triggerEvent(std::make_shared<Events::TargetReset>());
|
||||
}
|
||||
|
||||
void TargetControllerComponent::emitErrorEvent(int correlationId, const std::string& errorMessage) {
|
||||
@@ -759,6 +758,11 @@ namespace Bloom::TargetController
|
||||
return std::make_unique<Response>();
|
||||
}
|
||||
|
||||
std::unique_ptr<Responses::Response> TargetControllerComponent::handleResetTarget(ResetTarget& command) {
|
||||
this->resetTarget();
|
||||
return std::make_unique<Response>();
|
||||
}
|
||||
|
||||
void TargetControllerComponent::onStepTargetExecutionEvent(const Events::StepTargetExecution& event) {
|
||||
try {
|
||||
if (this->target->getState() != TargetState::STOPPED) {
|
||||
@@ -1018,14 +1022,4 @@ namespace Bloom::TargetController
|
||||
this->emitErrorEvent(event.id, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
void TargetControllerComponent::onResetTarget(const Events::ResetTarget& event) {
|
||||
try {
|
||||
this->resetTarget(event.id);
|
||||
|
||||
} catch (const TargetOperationFailure& exception) {
|
||||
Logger::error("Failed to reset target - " + exception.getMessage());
|
||||
this->emitErrorEvent(event.id, exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Commands/Command.hpp"
|
||||
#include "Commands/StopTargetExecution.hpp"
|
||||
#include "Commands/ResumeTargetExecution.hpp"
|
||||
#include "Commands/ResetTarget.hpp"
|
||||
|
||||
// Responses
|
||||
#include "Responses/Response.hpp"
|
||||
@@ -238,10 +239,8 @@ namespace Bloom::TargetController
|
||||
|
||||
/**
|
||||
* Triggers a target reset and emits a TargetReset event.
|
||||
*
|
||||
* @param resetEventCorrelationId
|
||||
*/
|
||||
void resetTarget(const std::optional<int>& resetEventCorrelationId = std::nullopt);
|
||||
void resetTarget();
|
||||
|
||||
/**
|
||||
* When the TargetController fails to handle an event, a TargetControllerErrorOccurred event is emitted, with
|
||||
@@ -291,6 +290,7 @@ namespace Bloom::TargetController
|
||||
|
||||
std::unique_ptr<Responses::Response> handleStopTargetExecution(Commands::StopTargetExecution& command);
|
||||
std::unique_ptr<Responses::Response> handleResumeTargetExecution(Commands::ResumeTargetExecution& command);
|
||||
std::unique_ptr<Responses::Response> handleResetTarget(Commands::ResetTarget& command);
|
||||
|
||||
/**
|
||||
* Will attempt to step execution on the target and emit a TargetExecutionResumed event.
|
||||
@@ -381,7 +381,5 @@ namespace Bloom::TargetController
|
||||
* @param event
|
||||
*/
|
||||
void onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event);
|
||||
|
||||
void onResetTarget(const Events::ResetTarget& event);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// Commands
|
||||
#include "Commands/StopTargetExecution.hpp"
|
||||
#include "Commands/ResumeTargetExecution.hpp"
|
||||
#include "Commands/ResetTarget.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
@@ -16,6 +17,7 @@ namespace Bloom::TargetController
|
||||
|
||||
using Commands::StopTargetExecution;
|
||||
using Commands::ResumeTargetExecution;
|
||||
using Commands::ResetTarget;
|
||||
|
||||
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
|
||||
: eventListener(eventListener)
|
||||
@@ -157,6 +159,9 @@ namespace Bloom::TargetController
|
||||
}
|
||||
|
||||
void TargetControllerConsole::resetTarget() {
|
||||
this->triggerTargetControllerEventAndWaitForResponse(std::make_shared<ResetTarget>());
|
||||
this->commandManager.sendCommandAndWaitForResponse(
|
||||
std::make_unique<ResetTarget>(),
|
||||
this->defaultTimeout
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user