Added events for failure of config file handler functions

This commit is contained in:
petriVM18 2022-06-08 09:18:17 +02:00
parent 0fb620b290
commit 7cd048b03f
3 changed files with 30 additions and 4 deletions

View File

@ -58,9 +58,6 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){
return result;
}
//TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock
//Use template functions for different data types
//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 resultSet = RETURN_OK;
@ -75,6 +72,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(std:
resultSet=setValue(key, data);
if(resultSet!=RETURN_OK){
triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << result << std::endl;
#endif
@ -105,6 +103,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(std:
resultGet=getValue(key, data);
if (resultGet!= RETURN_OK){
triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl;
#endif
@ -133,6 +132,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::insertConfigFileValue(s
resultInsert=insertValue(key, data);//Should never fail
if(resultInsert!=RETURN_OK){
triggerEvent(INSERT_CONFIGFILEVALUE_FAILED, 0, 0);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::insertConfigFileValue insert failed with " << result << std::endl;
#endif
@ -181,6 +181,7 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile(){
resultWrite =writeJsonFile();
if(resultWrite!=RETURN_OK){
triggerEvent(WRITE_CONFIGFILE_FAILED, 0, 0);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << result << std::endl;
#endif
@ -209,6 +210,7 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile(){
resultRead=readJsonFile();
if(resultRead!=RETURN_OK){
triggerEvent(READ_CONFIGFILE_FAILED, 0, 0);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << result << std::endl;
#endif
@ -230,3 +232,15 @@ ReturnValue_t GlobalConfigHandler::ResetConfigFile(){
result =writeJsonFile();
return result;
}
ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName){
ReturnValue_t result = RETURN_OK;
setFullName(configFileName);
result=ResetConfigFile();
return result;
}
std::string GlobalConfigHandler::getConfigFileName(){
return getFullName();
}

View File

@ -39,6 +39,15 @@ class GlobalConfigHandler: public SystemObject, public ExecutableObjectIF, publi
public:
GlobalConfigHandler(object_id_t objectId, std::string configFilePath);
virtual ~GlobalConfigHandler();
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CONFIGHANDLER;
static constexpr Event SET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(1, severity::MEDIUM);
static constexpr Event GET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(2, severity::MEDIUM);
static constexpr Event INSERT_CONFIGFILEVALUE_FAILED = MAKE_EVENT(3, severity::MEDIUM);
static constexpr Event WRITE_CONFIGFILE_FAILED = MAKE_EVENT(4, severity::MEDIUM);
static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM);
ReturnValue_t performOperation(uint8_t operationCode);
ReturnValue_t initialize();
@ -52,8 +61,10 @@ public:
ReturnValue_t ReadConfigFile();
ReturnValue_t ResetConfigFile();
ReturnValue_t setConfigFileName(std::string configFileName);
std::string getConfigFileName();
private:
std::string configFilePath;
static MutexIF* configLock ;

View File

@ -31,6 +31,7 @@ enum: uint8_t {
PDU2_HANDLER = 134,
ACU_HANDLER = 135,
SYRLINKS = 136,
CONFIGHANDLER=137,
COMMON_SUBSYSTEM_ID_END
};
}