Tidied TargetControllerComponent class
This commit is contained in:
@@ -20,8 +20,9 @@ namespace Bloom::TargetController
|
|||||||
using namespace Bloom::Events;
|
using namespace Bloom::Events;
|
||||||
using namespace Bloom::Exceptions;
|
using namespace Bloom::Exceptions;
|
||||||
|
|
||||||
using Commands::Command;
|
|
||||||
using Commands::CommandIdType;
|
using Commands::CommandIdType;
|
||||||
|
|
||||||
|
using Commands::Command;
|
||||||
using Commands::GetTargetDescriptor;
|
using Commands::GetTargetDescriptor;
|
||||||
using Commands::GetTargetState;
|
using Commands::GetTargetState;
|
||||||
using Commands::StopTargetExecution;
|
using Commands::StopTargetExecution;
|
||||||
@@ -699,13 +700,6 @@ namespace Bloom::TargetController
|
|||||||
EventManager::triggerEvent(std::make_shared<Events::TargetReset>());
|
EventManager::triggerEvent(std::make_shared<Events::TargetReset>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetControllerComponent::emitErrorEvent(int correlationId, const std::string& errorMessage) {
|
|
||||||
auto errorEvent = std::make_shared<Events::TargetControllerErrorOccurred>();
|
|
||||||
errorEvent->correlationId = correlationId;
|
|
||||||
errorEvent->errorMessage = errorMessage;
|
|
||||||
EventManager::triggerEvent(errorEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Targets::TargetDescriptor& TargetControllerComponent::getTargetDescriptor() {
|
Targets::TargetDescriptor& TargetControllerComponent::getTargetDescriptor() {
|
||||||
if (!this->cachedTargetDescriptor.has_value()) {
|
if (!this->cachedTargetDescriptor.has_value()) {
|
||||||
this->cachedTargetDescriptor = this->target->getDescriptor();
|
this->cachedTargetDescriptor = this->target->getDescriptor();
|
||||||
|
|||||||
@@ -151,6 +151,13 @@ namespace Bloom::TargetController
|
|||||||
*/
|
*/
|
||||||
std::map<Targets::TargetMemoryType, Targets::TargetMemoryAddressRange> registerAddressRangeByMemoryType;
|
std::map<Targets::TargetMemoryType, Targets::TargetMemoryAddressRange> 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<class CommandType>
|
template<class CommandType>
|
||||||
void registerCommandHandler(std::function<std::unique_ptr<Responses::Response>(CommandType&)> callback) {
|
void registerCommandHandler(std::function<std::unique_ptr<Responses::Response>(CommandType&)> callback) {
|
||||||
auto parentCallback = [callback] (Commands::Command& command) {
|
auto parentCallback = [callback] (Commands::Command& command) {
|
||||||
@@ -161,6 +168,13 @@ namespace Bloom::TargetController
|
|||||||
this->commandHandlersByCommandType.insert(std::pair(CommandType::type, parentCallback));
|
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);
|
void deregisterCommandHandler(Commands::CommandType commandType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,8 +212,18 @@ namespace Bloom::TargetController
|
|||||||
*/
|
*/
|
||||||
std::map<std::string, std::function<std::unique_ptr<Targets::Target>()>> getSupportedTargets();
|
std::map<std::string, std::function<std::unique_ptr<Targets::Target>()>> getSupportedTargets();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes any pending commands in the queue.
|
||||||
|
*/
|
||||||
void processQueuedCommands();
|
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<Responses::Response> response);
|
void registerCommandResponse(Commands::CommandIdType commandId, std::unique_ptr<Responses::Response> response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,14 +293,10 @@ namespace Bloom::TargetController
|
|||||||
void resetTarget();
|
void resetTarget();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the TargetController fails to handle an event, a TargetControllerErrorOccurred event is emitted, with
|
* Returns a cached instance of the target's TargetDescriptor.
|
||||||
* a correlation ID matching the ID of the event that triggered the handler.
|
|
||||||
*
|
*
|
||||||
* @param correlationId
|
* @return
|
||||||
* @param errorMessage
|
|
||||||
*/
|
*/
|
||||||
void emitErrorEvent(int correlationId, const std::string& errorMessage);
|
|
||||||
|
|
||||||
Targets::TargetDescriptor& getTargetDescriptor();
|
Targets::TargetDescriptor& getTargetDescriptor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user