diff --git a/middleware/IpcConfig/src/IpcConfig.cpp b/middleware/IpcConfig/src/IpcConfig.cpp index d7451417..1e28df9f 100644 --- a/middleware/IpcConfig/src/IpcConfig.cpp +++ b/middleware/IpcConfig/src/IpcConfig.cpp @@ -16,6 +16,8 @@ #include "ILog.h" #include +#define CHECK_MAP(map) (map.size()==1? true:false) + IpcConfig::IpcConfig() { mCfgChanged = CONFIG_HAS_NOT_CHANGED; @@ -26,12 +28,13 @@ IpcConfig::IpcConfig() IpcConfigKey::TEST_NUM, std::reference_wrapper(mAllData.testNum))); - mCfgMapString.insert( - std::make_pair< - IpcConfigKey, - std::reference_wrapper>( - IpcConfigKey::TEST_STRING, + std::map> innerMap; + innerMap.insert( + std::make_pair( + "test_string", std::reference_wrapper(mAllData.testString))); + mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMap)); + } const StatusCode IpcConfig::Init(void) { @@ -296,26 +299,26 @@ void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value) } const std::string IpcConfig::GetString(const IpcConfigKey &key) { - std::map>::iterator iter; + std::map>>::iterator iter; iter = mCfgMapString.find(key); - if (iter != mCfgMapString.end()) + if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) { - std::reference_wrapper s = iter->second; - const std::string sv(s); + const std::string sv(iter->second.begin()->second); // char[] --> const std::strinbg return sv; } LogError("Can't find the key.\n"); const std::string UNKNOWN_CONFIG = "undefine"; return UNKNOWN_CONFIG; } - void IpcConfig::SetString(const IpcConfigKey &key, const std::string string) { - std::map>::iterator iter; + std::map>>::iterator iter; iter = mCfgMapString.find(key); - if (iter != mCfgMapString.end()) + if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) { - strncpy(iter->second, string.c_str(), sizeof(CHAR_STRING)); + strncpy(iter->second.begin()->second, string.c_str(), sizeof(CHAR_STRING)); // const std::strinbg --> char[] + const char * name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char * + ConfigSetString(mCfg, name, iter->second.begin()->second); mCfgChanged = CONFIG_HAS_CHANGED; } else @@ -335,7 +338,6 @@ void IpcConfig::ReadAllConfigParameters(void) mAllData.testNum = DEFAULT_TEST_NUM; ConfigSetInt(mCfg, "test_num", mAllData.testNum); } - const char *testString = NULL; StatusCode string_code = ConfigGetString(mCfg, "test_string", &(testString)); if (StatusCodeEqual(string_code, "CONFIG_CODE_PARAM_NOT_EXIST")) diff --git a/middleware/IpcConfig/src/IpcConfig.h b/middleware/IpcConfig/src/IpcConfig.h index d21517c5..6bad3232 100644 --- a/middleware/IpcConfig/src/IpcConfig.h +++ b/middleware/IpcConfig/src/IpcConfig.h @@ -80,6 +80,6 @@ private: std::map> mCfgMapDouble; std::map> mCfgMapLongDouble; std::map> mCfgMapBool; - std::map> mCfgMapString; + std::map>> mCfgMapString; }; #endif \ No newline at end of file