Replaced ResetTarget event with TC command

This commit is contained in:
Nav
2022-04-23 17:41:02 +01:00
parent 7ba997572a
commit b3694970bf
7 changed files with 40 additions and 52 deletions

View File

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