New resume & suspend TargetController commands
This commit is contained in:
@@ -157,23 +157,15 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
* service it.
|
* service it.
|
||||||
*/
|
*/
|
||||||
if (!this->targetControllerConsole.isTargetControllerInService()) {
|
if (!this->targetControllerConsole.isTargetControllerInService()) {
|
||||||
// The TargetController is suspended - allow it some time to wake up
|
// The TargetController is suspended - attempt to wake it up
|
||||||
|
try {
|
||||||
|
this->targetControllerConsole.resumeTargetController();
|
||||||
|
|
||||||
/*
|
} catch (Bloom::Exceptions::Exception& exception) {
|
||||||
* At first, it may seem like there is a possibility that we may miss the
|
Logger::error("Failed to wake up TargetController - " + exception.getMessage());
|
||||||
* TargetControllerStateChanged event here. But this is nothing to worry about because
|
}
|
||||||
* this->eventListener is already listening for TargetControllerStateChanged events, so if an event
|
|
||||||
* does fire in between the call to isTargetControllerInService() (above) and waitForEvent() (below),
|
|
||||||
* then waitForEvent() will return immediately with the event.
|
|
||||||
*/
|
|
||||||
const auto targetControllerStateChangedEvent = this->eventListener.waitForEvent<
|
|
||||||
Events::TargetControllerStateChanged
|
|
||||||
>(std::chrono::milliseconds(10000));
|
|
||||||
|
|
||||||
if (
|
if (!this->targetControllerConsole.isTargetControllerInService()) {
|
||||||
!targetControllerStateChangedEvent.has_value()
|
|
||||||
|| targetControllerStateChangedEvent->get()->state != TargetControllerState::ACTIVE
|
|
||||||
) {
|
|
||||||
this->activeDebugSession.reset();
|
this->activeDebugSession.reset();
|
||||||
throw DebugSessionAborted("TargetController not in service");
|
throw DebugSessionAborted("TargetController not in service");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ namespace Bloom::TargetController::Commands
|
|||||||
{
|
{
|
||||||
GENERIC,
|
GENERIC,
|
||||||
GET_STATE,
|
GET_STATE,
|
||||||
|
RESUME,
|
||||||
|
SUSPEND,
|
||||||
GET_TARGET_DESCRIPTOR,
|
GET_TARGET_DESCRIPTOR,
|
||||||
STOP_TARGET_EXECUTION,
|
STOP_TARGET_EXECUTION,
|
||||||
RESUME_TARGET_EXECUTION,
|
RESUME_TARGET_EXECUTION,
|
||||||
|
|||||||
21
src/TargetController/Commands/Resume.hpp
Normal file
21
src/TargetController/Commands/Resume.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Command.hpp"
|
||||||
|
|
||||||
|
namespace Bloom::TargetController::Commands
|
||||||
|
{
|
||||||
|
class Resume: public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr CommandType type = CommandType::RESUME;
|
||||||
|
static inline const std::string name = "Resume";
|
||||||
|
|
||||||
|
[[nodiscard]] CommandType getType() const override {
|
||||||
|
return Resume::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool requiresDebugMode() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
21
src/TargetController/Commands/Suspend.hpp
Normal file
21
src/TargetController/Commands/Suspend.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Command.hpp"
|
||||||
|
|
||||||
|
namespace Bloom::TargetController::Commands
|
||||||
|
{
|
||||||
|
class Suspend: public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr CommandType type = CommandType::SUSPEND;
|
||||||
|
static inline const std::string name = "Suspend";
|
||||||
|
|
||||||
|
[[nodiscard]] CommandType getType() const override {
|
||||||
|
return Suspend::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool requiresDebugMode() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@ namespace Bloom::TargetController
|
|||||||
|
|
||||||
using Commands::Command;
|
using Commands::Command;
|
||||||
using Commands::GetState;
|
using Commands::GetState;
|
||||||
|
using Commands::Resume;
|
||||||
|
using Commands::Suspend;
|
||||||
using Commands::GetTargetDescriptor;
|
using Commands::GetTargetDescriptor;
|
||||||
using Commands::GetTargetState;
|
using Commands::GetTargetState;
|
||||||
using Commands::StopTargetExecution;
|
using Commands::StopTargetExecution;
|
||||||
@@ -172,6 +174,14 @@ namespace Bloom::TargetController
|
|||||||
std::bind(&TargetControllerComponent::handleGetState, this, std::placeholders::_1)
|
std::bind(&TargetControllerComponent::handleGetState, this, std::placeholders::_1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this->registerCommandHandler<Resume>(
|
||||||
|
std::bind(&TargetControllerComponent::handleResume, this, std::placeholders::_1)
|
||||||
|
);
|
||||||
|
|
||||||
|
this->registerCommandHandler<Suspend>(
|
||||||
|
std::bind(&TargetControllerComponent::handleSuspend, this, std::placeholders::_1)
|
||||||
|
);
|
||||||
|
|
||||||
this->registerCommandHandler<GetTargetDescriptor>(
|
this->registerCommandHandler<GetTargetDescriptor>(
|
||||||
std::bind(&TargetControllerComponent::handleGetTargetDescriptor, this, std::placeholders::_1)
|
std::bind(&TargetControllerComponent::handleGetTargetDescriptor, this, std::placeholders::_1)
|
||||||
);
|
);
|
||||||
@@ -765,6 +775,22 @@ namespace Bloom::TargetController
|
|||||||
return std::make_unique<Responses::State>(this->state);
|
return std::make_unique<Responses::State>(this->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Responses::Response> TargetControllerComponent::handleResume(Resume& command) {
|
||||||
|
if (this->state != TargetControllerState::ACTIVE) {
|
||||||
|
this->resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_unique<Response>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Responses::Response> TargetControllerComponent::handleSuspend(Suspend& command) {
|
||||||
|
if (this->state != TargetControllerState::SUSPENDED) {
|
||||||
|
this->suspend();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_unique<Response>();
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Responses::TargetDescriptor> TargetControllerComponent::handleGetTargetDescriptor(
|
std::unique_ptr<Responses::TargetDescriptor> TargetControllerComponent::handleGetTargetDescriptor(
|
||||||
GetTargetDescriptor& command
|
GetTargetDescriptor& command
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
// Commands
|
// Commands
|
||||||
#include "Commands/Command.hpp"
|
#include "Commands/Command.hpp"
|
||||||
#include "Commands/GetState.hpp"
|
#include "Commands/GetState.hpp"
|
||||||
|
#include "Commands/Resume.hpp"
|
||||||
|
#include "Commands/Suspend.hpp"
|
||||||
#include "Commands/GetTargetDescriptor.hpp"
|
#include "Commands/GetTargetDescriptor.hpp"
|
||||||
#include "Commands/GetTargetState.hpp"
|
#include "Commands/GetTargetState.hpp"
|
||||||
#include "Commands/StopTargetExecution.hpp"
|
#include "Commands/StopTargetExecution.hpp"
|
||||||
@@ -335,6 +337,8 @@ namespace Bloom::TargetController
|
|||||||
|
|
||||||
// Command handlers
|
// Command handlers
|
||||||
std::unique_ptr<Responses::State> handleGetState(Commands::GetState& command);
|
std::unique_ptr<Responses::State> handleGetState(Commands::GetState& command);
|
||||||
|
std::unique_ptr<Responses::Response> handleSuspend(Commands::Suspend& command);
|
||||||
|
std::unique_ptr<Responses::Response> handleResume(Commands::Resume& command);
|
||||||
std::unique_ptr<Responses::TargetDescriptor> handleGetTargetDescriptor(Commands::GetTargetDescriptor& command);
|
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);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
#include "Commands/GetState.hpp"
|
#include "Commands/GetState.hpp"
|
||||||
|
#include "Commands/Suspend.hpp"
|
||||||
|
#include "Commands/Resume.hpp"
|
||||||
#include "Commands/GetTargetDescriptor.hpp"
|
#include "Commands/GetTargetDescriptor.hpp"
|
||||||
#include "Commands/GetTargetState.hpp"
|
#include "Commands/GetTargetState.hpp"
|
||||||
#include "Commands/StopTargetExecution.hpp"
|
#include "Commands/StopTargetExecution.hpp"
|
||||||
@@ -25,6 +27,8 @@
|
|||||||
namespace Bloom::TargetController
|
namespace Bloom::TargetController
|
||||||
{
|
{
|
||||||
using Commands::GetState;
|
using Commands::GetState;
|
||||||
|
using Commands::Suspend;
|
||||||
|
using Commands::Resume;
|
||||||
using Commands::GetTargetDescriptor;
|
using Commands::GetTargetDescriptor;
|
||||||
using Commands::GetTargetState;
|
using Commands::GetTargetState;
|
||||||
using Commands::StopTargetExecution;
|
using Commands::StopTargetExecution;
|
||||||
@@ -81,6 +85,22 @@ namespace Bloom::TargetController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetControllerConsole::resumeTargetController() {
|
||||||
|
this->commandManager.sendCommandAndWaitForResponse(
|
||||||
|
std::make_unique<Resume>(),
|
||||||
|
this->defaultTimeout
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TargetControllerConsole::suspendTargetController() {
|
||||||
|
this->commandManager.sendCommandAndWaitForResponse(
|
||||||
|
std::make_unique<Suspend>(),
|
||||||
|
this->defaultTimeout
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TargetDescriptor TargetControllerConsole::getTargetDescriptor() {
|
TargetDescriptor TargetControllerConsole::getTargetDescriptor() {
|
||||||
return this->commandManager.sendCommandAndWaitForResponse(
|
return this->commandManager.sendCommandAndWaitForResponse(
|
||||||
std::make_unique<GetTargetDescriptor>(),
|
std::make_unique<GetTargetDescriptor>(),
|
||||||
|
|||||||
@@ -49,6 +49,16 @@ namespace Bloom::TargetController
|
|||||||
*/
|
*/
|
||||||
bool isTargetControllerInService() noexcept;
|
bool isTargetControllerInService() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resumes the TargetController if it's suspended. Otherwise, this function does nothing.
|
||||||
|
*/
|
||||||
|
void resumeTargetController();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspends the TargetController if it's active. Otherwise, this function does nothing.
|
||||||
|
*/
|
||||||
|
void suspendTargetController();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests the TargetDescriptor from the TargetController
|
* Requests the TargetDescriptor from the TargetController
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user