diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp index b450bfa9..470eba4c 100644 --- a/bsp_hosted/GlobalConfigHandler.cpp +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -60,17 +60,93 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ //TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock //Use template functions for different data types -ReturnValue_t GlobalConfigHandler::setConfigFileValue(){ +//Trigger Event, if set/get/insert/write/Read fails +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){ ReturnValue_t result = RETURN_OK; + ReturnValue_t resultSet = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultSet=setValue(key, data); + if(resultSet!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << result << std::endl; +#endif + } + + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + + return resultSet; +} +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std::string key, T& data){ + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultGet = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultGet=getValue(key, data); + if (resultGet!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; +#endif + } + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + return result; } -ReturnValue_t GlobalConfigHandler::getConfigFileValue(){ +template ReturnValue_t GlobalConfigHandler::insertConfigFileValue(std::string key, T data){ ReturnValue_t result = RETURN_OK; - return result; -} -ReturnValue_t GlobalConfigHandler::insertConfigFileValue(){ - ReturnValue_t result = RETURN_OK; - return result; + ReturnValue_t resultInsert = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultInsert=insertValue(key, data);//Should never fail + if(resultInsert!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue insert failed with " << result << std::endl; +#endif + } + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + + return resultInsert; } ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ ReturnValue_t result = RETURN_OK; diff --git a/bsp_hosted/GlobalConfigHandler.h b/bsp_hosted/GlobalConfigHandler.h index 9db594a3..5a9d0c30 100644 --- a/bsp_hosted/GlobalConfigHandler.h +++ b/bsp_hosted/GlobalConfigHandler.h @@ -44,9 +44,9 @@ public: ReturnValue_t lockConfigFile(); ReturnValue_t unlockConfigFile(); - ReturnValue_t setConfigFileValue(); - ReturnValue_t getConfigFileValue(); - ReturnValue_t insertConfigFileValue(); + template ReturnValue_t setConfigFileValue(std::string key, T data); + template ReturnValue_t getConfigFileValue(std::string key, T& data); + template ReturnValue_t insertConfigFileValue(std::string key, T data); ReturnValue_t resetConfigFileValues(); ReturnValue_t WriteConfigFile(); ReturnValue_t ReadConfigFile();