From 17daa5fbb911f77189fe5a74ed9d9ac7f8a574a0 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 1 May 2022 19:23:58 +0100 Subject: [PATCH] Tidied TargetControllerComponent class --- .../TargetControllerComponent.cpp | 10 ++---- .../TargetControllerComponent.hpp | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/TargetController/TargetControllerComponent.cpp b/src/TargetController/TargetControllerComponent.cpp index e2b0f18f..ad0af754 100644 --- a/src/TargetController/TargetControllerComponent.cpp +++ b/src/TargetController/TargetControllerComponent.cpp @@ -20,8 +20,9 @@ namespace Bloom::TargetController using namespace Bloom::Events; using namespace Bloom::Exceptions; - using Commands::Command; using Commands::CommandIdType; + + using Commands::Command; using Commands::GetTargetDescriptor; using Commands::GetTargetState; using Commands::StopTargetExecution; @@ -699,13 +700,6 @@ namespace Bloom::TargetController EventManager::triggerEvent(std::make_shared()); } - void TargetControllerComponent::emitErrorEvent(int correlationId, const std::string& errorMessage) { - auto errorEvent = std::make_shared(); - errorEvent->correlationId = correlationId; - errorEvent->errorMessage = errorMessage; - EventManager::triggerEvent(errorEvent); - } - Targets::TargetDescriptor& TargetControllerComponent::getTargetDescriptor() { if (!this->cachedTargetDescriptor.has_value()) { this->cachedTargetDescriptor = this->target->getDescriptor(); diff --git a/src/TargetController/TargetControllerComponent.hpp b/src/TargetController/TargetControllerComponent.hpp index d666c5d3..1becd9cb 100644 --- a/src/TargetController/TargetControllerComponent.hpp +++ b/src/TargetController/TargetControllerComponent.hpp @@ -151,6 +151,13 @@ namespace Bloom::TargetController */ std::map registerAddressRangeByMemoryType; + /** + * Registers a handler function for a particular command type. + * Only one handler function can be registered per command type. + * + * @tparam CommandType + * @param callback + */ template void registerCommandHandler(std::function(CommandType&)> callback) { auto parentCallback = [callback] (Commands::Command& command) { @@ -161,6 +168,13 @@ namespace Bloom::TargetController this->commandHandlersByCommandType.insert(std::pair(CommandType::type, parentCallback)); } + /** + * Removes any registered handler for a given command type. After calling this function, any commands issued + * for the given command type will be rejected with a "No handler registered for this command." error, until a + * handler is registered again. + * + * @param commandType + */ void deregisterCommandHandler(Commands::CommandType commandType); /** @@ -198,8 +212,18 @@ namespace Bloom::TargetController */ std::map()>> getSupportedTargets(); + /** + * Processes any pending commands in the queue. + */ void processQueuedCommands(); + /** + * Records a response for a given command ID. Notifies the TargetControllerComponent::responsesByCommandIdCv + * condition variable of the new response. + * + * @param commandId + * @param response + */ void registerCommandResponse(Commands::CommandIdType commandId, std::unique_ptr response); /** @@ -269,14 +293,10 @@ namespace Bloom::TargetController void resetTarget(); /** - * When the TargetController fails to handle an event, a TargetControllerErrorOccurred event is emitted, with - * a correlation ID matching the ID of the event that triggered the handler. + * Returns a cached instance of the target's TargetDescriptor. * - * @param correlationId - * @param errorMessage + * @return */ - void emitErrorEvent(int correlationId, const std::string& errorMessage); - Targets::TargetDescriptor& getTargetDescriptor(); /**