From 129a2f8b920da24c9d45c0c31ce06d69881abf34 Mon Sep 17 00:00:00 2001 From: athatheocsd <athatheo@csd.auth.gr> Date: Tue, 1 Jan 2019 20:58:36 +0200 Subject: [PATCH] updated multiple functions as per the realization that multiple actions will be added/event --- inc/Services/EventActionService.hpp | 2 ++ src/Services/EventActionService.cpp | 43 ++++++++++------------------ test/Services/EventActionService.cpp | 10 +++++-- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index c551afed..9a542fa7 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -17,6 +17,8 @@ * * @todo: check if executeAction should accept applicationID too + * @todo: Since there are multiple actions per event and in delete/enable/disable functions are + * multiple instances are accessed, should I find a more efficient way to access them? * @todo: check if eventActionFunctionStatus should be private or not * @todo: check if eventAction array of definitions should be private or not * @todo: check size of eventActionDefinitionArray diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index c2940178..6985bb25 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -44,20 +44,16 @@ void EventActionService::deleteEventActionDefinitions(Message message) { for (uint16_t i = 0; i < N; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { - if (index == 255) { // 255 should be changed depending on size of the array - flag = 1; - break; + while (index<256){ + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID== eventDefinitionID) { + eventActionDefinitionArray[index].empty = 1; + eventActionDefinitionArray[index].eventDefinitionID = 65535; + eventActionDefinitionArray[index].request = ""; + eventActionDefinitionArray[index].applicationId = 0; } index++; } - if (flag == 0) { // Found - eventActionDefinitionArray[index].empty = 1; - eventActionDefinitionArray[index].eventDefinitionID = 65535; - eventActionDefinitionArray[index].request = ""; - eventActionDefinitionArray[index].applicationId = 0; - } index = 0; } @@ -89,20 +85,15 @@ void EventActionService::enableEventActionDefinitions(Message message) { for (uint16_t i = 0; i < N; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { - if (index == 255) { // 255 should be changed depending on size of the array - flag = 1; - break; + while (index<256){ + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID== eventDefinitionID) { + stateOfEventAction[index] = 1; } index++; } - if (flag == 0) { // Found - stateOfEventAction[index] = 1; - } index = 0; } - } } @@ -116,17 +107,13 @@ void EventActionService::disableEventActionDefinitions(Message message) { for (uint16_t i = 0; i < N; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - while (eventActionDefinitionArray[index].applicationId != applicationID || - eventActionDefinitionArray[index].eventDefinitionID != eventDefinitionID) { - if (index == 255) { // 255 should be changed depending on size of the array - flag = 1; - break; + while (index<256){ + if (eventActionDefinitionArray[index].applicationId == applicationID && + eventActionDefinitionArray[index].eventDefinitionID== eventDefinitionID) { + stateOfEventAction[index] = 0; } index++; } - if (flag == 0) { // Found - stateOfEventAction[index] = 0; - } index = 0; } } diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 1fac8d65..ab10c0aa 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -104,7 +104,6 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") { EventActionService eventActionService; - char checkString[256]; Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); @@ -148,6 +147,13 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") { } TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") { + EventActionService eventActionService; + Message message0(19, 1, Message::TC, 0); + message0.appendEnum16(1); + message0.appendEnum16(0); + String<64> data = "0"; + message0.appendString(data); + eventActionService.addEventActionDefinitions(message0); } @@ -185,4 +191,4 @@ TEST_CASE("Disable event-action function TC[19,1]", "[service][st09]") { TEST_CASE("Execute a TC request", "[service][st09]"){ -} \ No newline at end of file +} -- GitLab