From 674a529dc84bc9ee1f5480f6a80530d699eca6b4 Mon Sep 17 00:00:00 2001 From: Grigoris Pavlakis <grigpavl@ece.auth.gr> Date: Mon, 7 Jan 2019 16:34:59 +0200 Subject: [PATCH] Fix unnecessary code duplication at call() --- inc/Services/FunctionManagementService.hpp | 20 +++---- src/Services/FunctionManagementService.cpp | 63 +--------------------- 2 files changed, 8 insertions(+), 75 deletions(-) diff --git a/inc/Services/FunctionManagementService.hpp b/inc/Services/FunctionManagementService.hpp index 012f1df1..4ab4bb27 100644 --- a/inc/Services/FunctionManagementService.hpp +++ b/inc/Services/FunctionManagementService.hpp @@ -39,16 +39,16 @@ typedef String<MAXFUNCNAMELENGTH> functionName; typedef etl::map<functionName, void(*)(String<MAXARGLENGTH>), FUNCMAPSIZE> -PointerMap; +FunctionMap; class FunctionManagementService : public Service { /** * Map of the function names to their respective pointers. Size controlled by FUNCMAPSIZE */ #ifdef TESTMODE -public: PointerMap funcPtrIndex; +public: FunctionMap funcPtrIndex; #else - PointerMap funcPtrIndex; + FunctionMap funcPtrIndex; #endif public: @@ -62,28 +62,22 @@ public: /** * Calls the function described in the TC[8,1] message *msg*, passing the arguments contained - * and, if non-existent, generates a failed start of execution notification. + * and, if non-existent, generates a failed start of execution notification. Returns an unneeded + * int, for testing purposes. * @param msg A TC[8,1] message */ - #ifdef TESTMODE int call(Message msg); - #else - void call(Message msg); - #endif /** * Includes a new function in the pointer map. This enables it to be called by way of a valid - * TC [8,1] message. + * TC [8,1] message. After inclusion it returns an unneeded int signalling insertion success + * (0) or failure (2). These returns are there for testing purposes only. * * @param funcName the function's name. Max. length is MAXFUNCNAMELENGTH bytes. * @param ptr pointer to a function of void return type and a MAXARGLENGTH-lengthed byte * string as argument (which contains the actual arguments of the function) */ -#ifdef TESTMODE int include(String<MAXFUNCNAMELENGTH> funcName, void(*ptr)(String<MAXARGLENGTH>)); -#else - void include(String<MAXFUNCNAMELENGTH> funcName, void(*ptr)(String<MAXARGLENGTH>)); -#endif }; #endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP diff --git a/src/Services/FunctionManagementService.cpp b/src/Services/FunctionManagementService.cpp index 0ec37aaf..d4d51d8d 100644 --- a/src/Services/FunctionManagementService.cpp +++ b/src/Services/FunctionManagementService.cpp @@ -31,7 +31,6 @@ FunctionManagementService::FunctionManagementService() { } #endif -#ifdef TESTMODE int FunctionManagementService::call(Message msg){ assert(msg.messageType == 1); assert(msg.serviceType == 8); @@ -51,7 +50,7 @@ int FunctionManagementService::call(Message msg){ // locate the appropriate function pointer String<MAXFUNCNAMELENGTH> name(funcName); - PointerMap::iterator iter = funcPtrIndex.find(name); + FunctionMap::iterator iter = funcPtrIndex.find(name); void(*selected)(String<MAXARGLENGTH>); if (iter != funcPtrIndex.end()) { @@ -69,7 +68,6 @@ int FunctionManagementService::call(Message msg){ return 0; } -// TEST VERSION OF include()! int FunctionManagementService::include(String<MAXFUNCNAMELENGTH> funcName, void(*ptr) (String<MAXARGLENGTH>)) { @@ -85,62 +83,3 @@ int FunctionManagementService::include(String<MAXFUNCNAMELENGTH> funcName, void( return 0; } - -#else -void FunctionManagementService::call(Message msg){ - assert(msg.messageType == 1); - assert(msg.serviceType == 8); - - uint8_t funcName[MAXFUNCNAMELENGTH]; // the function's name - uint8_t funcArgs[MAXARGLENGTH]; // arguments for the function - - msg.readString(funcName, MAXFUNCNAMELENGTH); - msg.readString(funcArgs, MAXARGLENGTH); - - if (msg.readPosition < MAXFUNCNAMELENGTH + MAXARGLENGTH) { - /** - * @todo Send failed start of execution (too long message) - */ - return; - } - - // locate the appropriate function pointer - String<MAXFUNCNAMELENGTH> name(funcName); - PointerMap::iterator iter = funcPtrIndex.find(name); - void(*selected)(String<MAXARGLENGTH>); - - if (iter != funcPtrIndex.end()) { - selected = *iter->second; - } - else { - /** - * @todo Send failed start of execution (function not found) - */ - return; - } - - // execute the function if there are no obvious flaws (defined in the standard, pg.158) - selected(funcArgs); -} - -void FunctionManagementService::include(String<MAXFUNCNAMELENGTH> funcName, - void (*ptr)(String<MAXARGLENGTH>)) { - - if (funcName.length() > MAXFUNCNAMELENGTH) { - /** - * @todo Generate suitable notification (function name exceeds maximum allowed length) - */ - return; - } - else if (funcPtrIndex.full()) { - /** - * @todo Generate suitable notification (index is full) - */ - return; - } - else { - funcName.append(MAXFUNCNAMELENGTH - funcName.length(), '\0'); - funcPtrIndex.insert(std::make_pair(funcName, ptr)); - } -} -#endif -- GitLab