diff --git a/middleware/IpcConfig/include/IIpcConfig.h b/middleware/IpcConfig/include/IIpcConfig.h index 6904321b..e7451274 100644 --- a/middleware/IpcConfig/include/IIpcConfig.h +++ b/middleware/IpcConfig/include/IIpcConfig.h @@ -16,6 +16,9 @@ #define IIPCCONFIG_H #include "StatusCode.h" #include +#include +#include + enum class IpcConfigKey { TEST_NUM = 0, @@ -31,6 +34,27 @@ public: virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } virtual const int GetInt(const IpcConfigKey &key) { return -1; } virtual void SetInt(const IpcConfigKey &key, const int &value) {} + virtual const short GetShort(const IpcConfigKey &key) { return -1; } + virtual void SetShort(const IpcConfigKey &key, const short &value) {} + virtual const long GetLong(const IpcConfigKey &key) { return -1; } + virtual void SetLong(const IpcConfigKey &key, const long &value) {} + virtual const long long GetLongLong(const IpcConfigKey &key) { return -1; } + virtual void SetLongLong(const IpcConfigKey &key, const long long &value) {} + virtual const char GetChar(const IpcConfigKey &key) { return '\0'; } + virtual void SetChar(const IpcConfigKey &key, const char &value) {} + virtual const float GetFloat(const IpcConfigKey &key) { return -1.0; } + virtual void SetFloat(const IpcConfigKey &key, const float &value) {} + virtual const double GetDouble(const IpcConfigKey &key) { return -1.0; } + virtual void SetDouble(const IpcConfigKey &key, const double &value) {} + virtual const long double GetLongDouble(const IpcConfigKey &key) { return -1.0; } + virtual void SetLongDouble(const IpcConfigKey &key, const long double &value) {} + virtual const bool GetBool(const IpcConfigKey &key) { return true; } + virtual void SetBool(const IpcConfigKey &key, const bool &value) {} + virtual const std::string_view GetString(const IpcConfigKey &key) { return "undefine"; } + virtual void SetString(const IpcConfigKey &key, const std::string string) {} + + + }; bool CreateIpcConfig(void); #endif \ No newline at end of file diff --git a/middleware/IpcConfig/src/IpcConfig.cpp b/middleware/IpcConfig/src/IpcConfig.cpp index bfed7d60..0013de93 100644 --- a/middleware/IpcConfig/src/IpcConfig.cpp +++ b/middleware/IpcConfig/src/IpcConfig.cpp @@ -15,6 +15,7 @@ #include "IpcConfig.h" #include "ILog.h" #include + IpcConfig::IpcConfig() { mCfgChanged = CONFIG_HAS_NOT_CHANGED; @@ -73,6 +74,246 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value) LogError("Can't find the key.\n"); } } +const short IpcConfig::GetShort(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapShort.find(key); + if (iter != mCfgMapShort.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr short UNKNOWN_CONFIG = -1; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetShort(const IpcConfigKey &key, const short &value) +{ + std::map>::iterator iter; + iter = mCfgMapShort.find(key); + if (iter != mCfgMapShort.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const long IpcConfig::GetLong(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapLong.find(key); + if (iter != mCfgMaplong.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr long UNKNOWN_CONFIG = -1; + return UNKNOWN_CONFIG; +} + +void IpcConfig::SetLong(const IpcConfigKey &key, const long &value) +{ + std::map>::iterator iter; + iter = mCfgMaLlong.find(key); + if (iter != mCfgMapLong.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const long long IpcConfig::GetLongLong(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapLongLong.find(key); + if (iter != mCfgMapLongLong.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr long long UNKNOWN_CONFIG = -1; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetLongLong(const IpcConfigKey &key, const long long &value) +{ + std::map>::iterator iter; + iter = mCfgMapLongLong.find(key); + if (iter != mCfgMapLongLong.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const char IpcConfig::GetChar(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapChar.find(key); + if (iter != mCfgMapChar.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr char UNKNOWN_CONFIG = '\0'; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetChar(const IpcConfigKey &key, const char &character) +{ + std::map>::iterator iter; + iter = mCfgMapChar.find(key); + if (iter != mCfgMapChar.end()) + { + iter->second.get() = character; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const float IpcConfig::GetFloat(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapFloat.find(key); + if (iter != mCfgMapFloat.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr float UNKNOWN_CONFIG = -1.0; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetFloat(const IpcConfigKey &key, const float &value) +{ + std::map>::iterator iter; + iter = mCfgMapFloat.find(key); + if (iter != mCfgMapFloat.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const double IpcConfig::GetDouble(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapDouble.find(key); + if (iter != mCfgMapDouble.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr double UNKNOWN_CONFIG = -1.0; + return UNKNOWN_CONFIG; +} + +void IpcConfig::SetDouble(const IpcConfigKey &key, const double &value) +{ + std::map>::iterator iter; + iter = mCfgMapDouble.find(key); + if (iter != mCfgMapDouble.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const long double IpcConfig::GetLongDouble(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapLongDouble.find(key); + if (iter != mCfgMapLongDouble.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr long double UNKNOWN_CONFIG = -1.0; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetLongDouble(const IpcConfigKey &key, const long double &value) +{ + std::map>::iterator iter; + iter = mCfgMapLongDouble.find(key); + if (iter != mCfgMapLongDouble.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const bool IpcConfig::GetBool(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapBool.find(key); + if (iter != mCfgMapBool.end()) + { + return iter->second; + } + LogError("Can't find the key.\n"); + constexpr bool UNKNOWN_CONFIG = false; + return UNKNOWN_CONFIG; +} +void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value) +{ + std::map>::iterator iter; + iter = mCfgMapBool.find(key); + if (iter != mCfgMapBool.end()) + { + iter->second.get() = value; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} +const std::string_view IpcConfig::GetString(const IpcConfigKey &key) +{ + std::map>::iterator iter; + iter = mCfgMapString.find(key); + if (iter != mCfgMapString.end()) + { + std::string s = iter->second; + std::string_view sv(s); + return sv; + } + LogError("Can't find the key.\n"); + constexpr std::string_view UNKNOWN_CONFIG = "undefine"; + return UNKNOWN_CONFIG; +} + +void IpcConfig::SetString(const IpcConfigKey &key, const std::string string) +{ + std::map>::iterator iter; + iter = mCfgMapString.find(key); + if (iter != mCfgMapString.end()) + { + iter->second.get() = string; + mCfgChanged = CONFIG_HAS_CHANGED; + } + else + { + LogError("Can't find the key.\n"); + } +} + void IpcConfig::ReadAllConfigParameters(void) { StatusCode code = ConfigGetInt(mCfg, "test_num", &(mAllData.testNum)); diff --git a/middleware/IpcConfig/src/IpcConfig.h b/middleware/IpcConfig/src/IpcConfig.h index ee37af02..1a2ba777 100644 --- a/middleware/IpcConfig/src/IpcConfig.h +++ b/middleware/IpcConfig/src/IpcConfig.h @@ -40,6 +40,25 @@ public: const StatusCode UnInit(void) override; const int GetInt(const IpcConfigKey &key) override; void SetInt(const IpcConfigKey &key, const int &value) override; + const short GetShort(const IpcConfigKey &key) override; + void SetShort(const IpcConfigKey &key, const short &value) override; + const long GetLong(const IpcConfigKey &key) override; + void SetLong(const IpcConfigKey &key, const long &value) override; + const long long GetLongLong(const IpcConfigKey &key) override; + void SetLongLong(const IpcConfigKey &key, const long long &value) override; + const char GetChar(const IpcConfigKey &key) override; + void SetChar(const IpcConfigKey &key, const char &character) override; + const float GetFloat(const IpcConfigKey &key) override; + void SetFloat(const IpcConfigKey &key, const float &value) override; + const double GetDouble(const IpcConfigKey &key) override; + void SetDouble(const IpcConfigKey &key, const double &value) override; + const long double GetLongDouble(const IpcConfigKey &key) override; + void SetLongDouble(const IpcConfigKey &key, const long double &value) override; + const bool GetBool(const IpcConfigKey &key) override; + void SetBool(const IpcConfigKey &key, const bool &value) override; + const std::string_view GetString(const IpcConfigKey &key) override; + void SetString(const IpcConfigKey &key, const std::string string) override; + private: void ReadAllConfigParameters(void); @@ -49,7 +68,14 @@ private: VConfig *mCfg; Config_s mAllData; std::map> mCfgMapInt; - std::map> mCfgMapUInt; + std::map> mCfgMapShort; + std::map> mCfgMapLong; + std::map> mCfgMapLongLong; + std::map> mCfgMapChar; + std::map> mCfgMapFloat; + std::map> mCfgMapDouble; + std::map> mCfgMapLongDouble; + std::map> mCfgMapBool; std::map> mCfgMapString; }; #endif \ No newline at end of file