diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index 03492b00770fb951484ecb899c17e8c2151cd21e..4d62938f761363c6f90379a2ae17523ba2de7c84 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -111,10 +111,11 @@ public: enum ExecutionStartErrorType { UnknownExecutionStartError = 0, /** + * EventAction refers to the service, EventActionIDefinitionID refers to the variable * In the Event Action Service, in the addEventActionDefinition function an attempt was * made to add an event Action Definition with an eventActionDefinitionID that exists */ - EventActionIDExists = 1, + EventActionEventActionDefinitionIDExistsError = 1, /** * In the Event Action Service, in the deleteEventActionDefinition function, an attempt * was made to delete an event action definition that was enabled @@ -124,9 +125,14 @@ public: * In the Event Action Service, an access attempt was made to an unknown event * action definition */ - EventActionUnknownDefinitionError = 3, + EventActionUnknownEventDefinitionError = 3, SubServiceExecutionStartError = 4, InstructionExecutionStartError = 5, + /** + * EventAction refers to the service, EventActionIDefinitionID refers to the variable + * In the Event Action Service, an access attempt was made to an unknown eventActionDefinitionID + */ + EventActionUnknownEventActionDefinitionIDError = 6, }; /** diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index e1cfa395b4e4355ca122e7a5140e4b3a9ef2d84b..668189a5585076759f936cd3f524c45614670f82 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -13,10 +13,10 @@ void EventActionService::addEventActionDefinitions(Message& message) { bool flag = true; // This variable checks if the message can be added or not. Couldn't think of a better name if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto element = range.first; element != range.second; ++element) { + for (auto& element = range.first; element != range.second; ++element) { if (element->second.eventActionDefinitionID == eventActionDefinitionID) { flag = false; - ErrorHandler::reportError(message, ErrorHandler::EventActionIDExists); + ErrorHandler::reportError(message, ErrorHandler::EventActionEventActionDefinitionIDExistsError); } } } @@ -41,23 +41,28 @@ void EventActionService::deleteEventActionDefinitions(Message& message) { message.assertTC(19, 2); message.resetRead(); uint16_t numberOfEventActionDefinitions = message.readUint16(); + bool eventActionDefinitionIDexists = false; for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { message.skipBytes(2); uint16_t eventDefinitionID = message.readEnum16(); uint16_t eventActionDefinitionID = message.readEnum16(); if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); - for (auto element = range.first; element != range.second; ++element) { + for (auto& element = range.first; element != range.second; ++element) { if (element->second.eventActionDefinitionID == eventActionDefinitionID){ if (element->second.enabled == true){ ErrorHandler::reportError(message, ErrorHandler::EventActionDeleteEnabledDefinitionError); } else { + eventActionDefinitionIDexists = true; eventActionDefinitionMap.erase(element); } } } + if (eventActionDefinitionIDexists == false){ + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); + } } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownDefinitionError); + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); } } } @@ -75,17 +80,25 @@ void EventActionService::enableEventActionDefinitions(Message& message) { message.assertTC(19, 4); message.resetRead(); uint16_t numberOfEventActionDefinitions = message.readUint16(); + bool eventActionDefinitionIDexists = false; if (numberOfEventActionDefinitions != 0) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - uint16_t applicationID = message.readEnum16(); + message.skipBytes(2); uint16_t eventDefinitionID = message.readEnum16(); + uint16_t eventActionDefinitionID = message.readEnum16(); if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { - // This is need to pass the cpp check. The applicationId should be used - // somewhere - eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; - eventActionDefinitionMap[eventDefinitionID].enabled = true; + auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); + for (auto& element = range.first; element != range.second; ++element) { + if (element->second.eventActionDefinitionID == eventActionDefinitionID){ + element->second.enabled = true; + eventActionDefinitionIDexists = true; + } + } + if (eventActionDefinitionIDexists == false){ + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); + } } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownDefinitionError); + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); } } } else { @@ -101,18 +114,25 @@ void EventActionService::disableEventActionDefinitions(Message& message) { message.resetRead(); uint16_t numberOfEventActionDefinitions = message.readUint16(); + bool eventActionDefinitionIDexists = false; if (numberOfEventActionDefinitions != 0) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - uint16_t applicationID = message.readEnum16(); + message.skipBytes(2); uint16_t eventDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap - .end()) { - // This is need to pass the cpp check. The applicationId should be used - // somewhere - eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; - eventActionDefinitionMap[eventDefinitionID].enabled = false; + uint16_t eventActionDefinitionID = message.readEnum16(); + if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { + auto range = eventActionDefinitionMap.equal_range(eventDefinitionID); + for (auto& element = range.first; element != range.second; ++element) { + if (element->second.eventActionDefinitionID == eventActionDefinitionID){ + element->second.enabled = false; + eventActionDefinitionIDexists = true; + } + } + if (eventActionDefinitionIDexists == false){ + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventActionDefinitionIDError); + } } else { - ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownDefinitionError); + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownEventDefinitionError); } } } else { @@ -137,6 +157,7 @@ void EventActionService::eventActionStatusReport() { for (const auto& element : eventActionDefinitionMap) { report.appendEnum16(element.second.applicationId); report.appendEnum16(element.second.eventDefinitionID); + report.appendEnum16(element.second.eventActionDefinitionID); report.appendBoolean(element.second.enabled); } storeMessage(report);