Replaced StopTargetExecution event with TC command

This commit is contained in:
Nav
2022-04-18 18:50:23 +01:00
parent 5efffc6605
commit fa4f5e3427
8 changed files with 43 additions and 45 deletions

View File

@@ -15,7 +15,6 @@ namespace Bloom::Events
enum class EventType: std::uint8_t
{
GENERIC,
STOP_TARGET_EXECUTION,
RESUME_TARGET_EXECUTION,
RESET_TARGET,
DEBUG_SESSION_STARTED,

View File

@@ -3,7 +3,6 @@
#include <memory>
#include "Event.hpp"
#include "StopTargetExecution.hpp"
#include "ResumeTargetExecution.hpp"
#include "ResetTarget.hpp"
#include "DebugSessionStarted.hpp"

View File

@@ -1,26 +0,0 @@
#pragma once
#include <string>
#include "Event.hpp"
#include "TargetExecutionStopped.hpp"
namespace Bloom::Events
{
class StopTargetExecution: public Event
{
public:
using TargetControllerResponseType = TargetExecutionStopped;
static constexpr EventType type = EventType::STOP_TARGET_EXECUTION;
static inline const std::string name = "StopTargetExecution";
[[nodiscard]] EventType getType() const override {
return StopTargetExecution::type;
}
[[nodiscard]] std::string getName() const override {
return StopTargetExecution::name;
}
};
}

View File

@@ -7,5 +7,6 @@ namespace Bloom::TargetController::Commands
enum class CommandType: std::uint8_t
{
GENERIC,
STOP_TARGET_EXECUTION,
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "Command.hpp"
namespace Bloom::TargetController::Commands
{
class StopTargetExecution: public Command
{
public:
static constexpr CommandType type = CommandType::STOP_TARGET_EXECUTION;
static inline const std::string name = "StopTargetExecution";
[[nodiscard]] CommandType getType() const override {
return StopTargetExecution::type;
}
};
}

View File

@@ -22,7 +22,10 @@ namespace Bloom::TargetController
using Commands::Command;
using Commands::CommandIdType;
using Commands::StopTargetExecution;
using Responses::Response;
TargetControllerComponent::TargetControllerComponent(
const ProjectConfig& projectConfig,
const EnvironmentConfig& environmentConfig
@@ -366,9 +369,10 @@ namespace Bloom::TargetController
+ std::string(exception.what()));
}
this->deregisterCommandHandler(StopTargetExecution::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->eventListener->deregisterCallbacksForEventType<Events::StopTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::StepTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::ResumeTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveRegistersFromTarget>();
@@ -398,6 +402,10 @@ namespace Bloom::TargetController
this->acquireHardware();
this->loadRegisterDescriptors();
this->registerCommandHandler<StopTargetExecution>(
std::bind(&TargetControllerComponent::handleStopTargetExecution, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
);
@@ -406,10 +414,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::StopTargetExecution>(
std::bind(&TargetControllerComponent::onStopTargetExecutionEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::StepTargetExecution>(
std::bind(&TargetControllerComponent::onStepTargetExecutionEvent, this, std::placeholders::_1)
);
@@ -723,19 +727,18 @@ namespace Bloom::TargetController
}
}
void TargetControllerComponent::onStopTargetExecutionEvent(const Events::StopTargetExecution& event) {
std::unique_ptr<Response> TargetControllerComponent::handleStopTargetExecution(StopTargetExecution& command) {
if (this->target->getState() != TargetState::STOPPED) {
this->target->stop();
this->lastTargetState = TargetState::STOPPED;
}
auto executionStoppedEvent = std::make_shared<Events::TargetExecutionStopped>(
EventManager::triggerEvent(std::make_shared<Events::TargetExecutionStopped>(
this->target->getProgramCounter(),
TargetBreakCause::UNKNOWN
);
));
executionStoppedEvent->correlationId = event.id;
EventManager::triggerEvent(executionStoppedEvent);
return std::make_unique<Response>();
}
void TargetControllerComponent::onStepTargetExecutionEvent(const Events::StepTargetExecution& event) {

View File

@@ -17,6 +17,7 @@
// Commands
#include "Commands/Command.hpp"
#include "Commands/StopTargetExecution.hpp"
// Responses
#include "Responses/Response.hpp"
@@ -287,12 +288,7 @@ namespace Bloom::TargetController
*/
void onDebugSessionFinishedEvent(const Events::DebugSessionFinished& event);
/**
* Will attempt to stop execution on the target and emit a TargetExecutionStopped event.
*
* @param event
*/
void onStopTargetExecutionEvent(const Events::StopTargetExecution& event);
std::unique_ptr<Responses::Response> handleStopTargetExecution(Commands::StopTargetExecution& command);
/**
* Will attempt to step execution on the target and emit a TargetExecutionResumed event.

View File

@@ -1,6 +1,10 @@
#include "TargetControllerConsole.hpp"
#include "src/EventManager/Events/Events.hpp"
// Commands
#include "Commands/StopTargetExecution.hpp"
#include "src/Logger/Logger.hpp"
namespace Bloom::TargetController
@@ -9,6 +13,8 @@ namespace Bloom::TargetController
using namespace Bloom::Events;
using namespace Bloom::Exceptions;
using Commands::StopTargetExecution;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener)
{}
@@ -35,7 +41,10 @@ namespace Bloom::TargetController
}
void TargetControllerConsole::stopTargetExecution() {
this->triggerTargetControllerEventAndWaitForResponse(std::make_shared<StopTargetExecution>());
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<StopTargetExecution>(),
this->defaultTimeout
);
}
void TargetControllerConsole::continueTargetExecution(std::optional<std::uint32_t> fromAddress) {