diff --git a/developpment/interfacer/commandManager.cpp b/developpment/interfacer/commandManager.cpp index b4f7dec..4c89a55 100644 --- a/developpment/interfacer/commandManager.cpp +++ b/developpment/interfacer/commandManager.cpp @@ -8,3 +8,90 @@ * TODO : Comment the code wiht odxygen * */ + +#include "commandManager.h" + + +CommandManager:: CommandManager():emptyIndex(0) +{ +} + +void CommandManager::addNewCommand( const std::string& commmand, + const std::string& description, + commanCallback_t callBack) +{ + if(emptyIndex >= MAX_MUNBER_OF_COMMANDS) // Check if the command list is full + { + std::cout << "Error | Intern | Command list is full!" << std::endl; + exit(1); + } + if(getLookUpIndex(commmand) >= 0) // Chek for command duplicats + { + std::cout << "Error | Intern | Command already exitst!" << std::endl; + exit(1); + } + + + commandLookup[emptyIndex].commmand = commmand; + commandLookup[emptyIndex].description = description; + commandLookup[emptyIndex].callBack = callBack; + emptyIndex++; +} + +void CommandManager::operator()(const std::string cmdName) +{ + int index = 0; + + if(cmdName == "help" || cmdName == "Help") + { + printHelp(); + exit(1); + } + + if(cmdName == "-h" || cmdName == "-H") + { + printCommads(); + exit(1); + } + + index = getLookUpIndex(cmdName); + + if(index < 0) + { + std::cout << "Error | Intern | Invalid Command!" << std::endl; + exit(1); + } + + commandLookup[index].callBack(); + exit(1); +} + + +// +// Privat memeber functions +// + + +int CommandManager::getLookUpIndex(const std::string& cmd) +{ + int index = 0; + for (index = 0; index < emptyIndex; index++) + { + if(commandLookup[index].commmand == cmd) + { + return index; + } + } + return -1; +} + +void CommandManager::printHelp() +{ + std::cout << "Function : printHelp is under construction" << std::endl; +} + +void CommandManager::printCommads() +{ + std::cout << "Function : printCommads is under construction" << std::endl; +} + diff --git a/developpment/interfacer/commandManager.h b/developpment/interfacer/commandManager.h new file mode 100644 index 0000000..5d7eff2 --- /dev/null +++ b/developpment/interfacer/commandManager.h @@ -0,0 +1,53 @@ +/* + * Authors : Kerem Yollu & Edwin Koch + * Date : 07.03.2021 + * + * Description : + * TODO : Inplement singleton pattern + * TODO : Write description + * TODO : Comment the code wiht odxygen + * + */ + + +#ifndef _COMMMANDMANAGER_H_ +#define _COMMMANDMANAGER_H_ + +#include +#include +#include +#include + +#define MAX_MUNBER_OF_COMMANDS 4 + +class CommandManager +{ + public: + typedef std::function commanCallback_t; + CommandManager(); + void addNewCommand( const std::string& commmand, + const std::string& description, + commanCallback_t callBack); + + void operator()(const std::string cmdName); + + + private: + unsigned int emptyIndex; + + struct commant_t{ + std::string commmand; + std::string description; + commanCallback_t callBack; // The Callback function could only be a void returning a void. + }; + + std::array commandLookup; + int getLookUpIndex(const std::string& cmd); // If command exists retunrs the index otherwise -1 + void printHelp(); // Prints all awailbale commands and their description. + void printCommads(); // Prints all awailable commnads without description. +}; + + + + +#endif // _COMMMANDMANAGER_H_ diff --git a/developpment/interfacer/commandManager.o b/developpment/interfacer/commandManager.o new file mode 100644 index 0000000..c9eefcf Binary files /dev/null and b/developpment/interfacer/commandManager.o differ diff --git a/developpment/interfacer/errorHandling.cpp b/developpment/interfacer/errorHandling.cpp index 4e72b7c..9e30a38 100644 --- a/developpment/interfacer/errorHandling.cpp +++ b/developpment/interfacer/errorHandling.cpp @@ -4,18 +4,6 @@ ErrorHandler::ErrorHandler(): emptyIndex(0) { } -int ErrorHandler::getLookUpIndex(int errNo) -{ - int i = 0; - for(i = 0; i < emptyIndex; i++) - { - if(errNo == errorLookup[i].errNo) - { - return i; - } - } - return -1; -} void ErrorHandler::handleError(int errNo) { @@ -51,3 +39,20 @@ void ErrorHandler::addNewError(const int& no, const std::string& message) errorLookup[emptyIndex].errMessage = message; emptyIndex++; } + +// +// Privat memeber functions +// + +int ErrorHandler::getLookUpIndex(int errNo) +{ + int i = 0; + for(i = 0; i < emptyIndex; i++) + { + if(errNo == errorLookup[i].errNo) + { + return i; + } + } + return -1; +} diff --git a/developpment/interfacer/errorHandling.o b/developpment/interfacer/errorHandling.o new file mode 100644 index 0000000..5826368 Binary files /dev/null and b/developpment/interfacer/errorHandling.o differ diff --git a/developpment/interfacer/interfacer.cpp b/developpment/interfacer/interfacer.cpp index fb667af..500ffab 100644 --- a/developpment/interfacer/interfacer.cpp +++ b/developpment/interfacer/interfacer.cpp @@ -7,11 +7,13 @@ * */ -#include "errorHandling.h" #include - +#include "errorHandling.h" +#include "commandManager.h" ErrorHandler errorHandle; +CommandManager commander; + int initPlatform() { @@ -20,17 +22,23 @@ int initPlatform() return 0; } - +void dummy() +{ + std::cout << "HElllooo from the the other side signed adele" << std::endl; +} int main(int argc, char *argv[]) { - errorHandle.addNewError(-34,"Test eroor 1"); -// errorHandle.handleError(-34); - - errorHandle.addNewError(-34,"Test eroor"); - // Init std::cout << "Main" << std::endl; + //errorHandle.addNewError(-34,"Test eroor 1"); + //errorHandle.handleError(-34); + + commander.addNewCommand("test", "The test command for testing the test", dummy); + + commander(argv[1]); + + return 1; } diff --git a/developpment/interfacer/interfacer.o b/developpment/interfacer/interfacer.o new file mode 100644 index 0000000..7f2055e Binary files /dev/null and b/developpment/interfacer/interfacer.o differ diff --git a/developpment/interfacer/runtest b/developpment/interfacer/runtest new file mode 100755 index 0000000..6b6d4e2 Binary files /dev/null and b/developpment/interfacer/runtest differ