Implemented set/get/insert functions for config file handler

This commit is contained in:
petriVM18 2022-06-08 08:27:45 +02:00
parent 74b38a6d06
commit 0fb620b290
2 changed files with 86 additions and 10 deletions

View File

@ -60,18 +60,94 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){
//TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock //TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock
//Use template functions for different data types //Use template functions for different data types
ReturnValue_t GlobalConfigHandler::setConfigFileValue(){ //Trigger Event, if set/get/insert/write/Read fails
template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){
ReturnValue_t result = RETURN_OK; 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; return result;
} }
ReturnValue_t GlobalConfigHandler::getConfigFileValue(){
ReturnValue_t result = RETURN_OK; 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 result;
} }
ReturnValue_t GlobalConfigHandler::insertConfigFileValue(){
return resultSet;
}
template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(std::string key, T& data){
ReturnValue_t result = RETURN_OK; 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; 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;
}
template <typename T> ReturnValue_t GlobalConfigHandler::insertConfigFileValue(std::string key, T data){
ReturnValue_t result = RETURN_OK;
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 GlobalConfigHandler::resetConfigFileValues(){
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result=lockConfigFile(); result=lockConfigFile();

View File

@ -44,9 +44,9 @@ public:
ReturnValue_t lockConfigFile(); ReturnValue_t lockConfigFile();
ReturnValue_t unlockConfigFile(); ReturnValue_t unlockConfigFile();
ReturnValue_t setConfigFileValue(); template <typename T> ReturnValue_t setConfigFileValue(std::string key, T data);
ReturnValue_t getConfigFileValue(); template <typename T> ReturnValue_t getConfigFileValue(std::string key, T& data);
ReturnValue_t insertConfigFileValue(); template <typename T> ReturnValue_t insertConfigFileValue(std::string key, T data);
ReturnValue_t resetConfigFileValues(); ReturnValue_t resetConfigFileValues();
ReturnValue_t WriteConfigFile(); ReturnValue_t WriteConfigFile();
ReturnValue_t ReadConfigFile(); ReturnValue_t ReadConfigFile();