mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Ipc config backup.
This commit is contained in:
parent
0e8ecc75d4
commit
a60d476935
|
@ -16,6 +16,7 @@ public:
|
|||
virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
||||
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) {}
|
||||
};
|
||||
bool CreateIpcConfig(void);
|
||||
#endif
|
|
@ -1,6 +1,17 @@
|
|||
#include "IpcConfig.h"
|
||||
#include "ILog.h"
|
||||
#include <string.h>
|
||||
// #include <utility>
|
||||
IpcConfig::IpcConfig()
|
||||
{
|
||||
mCfgChanged = CONFIG_HAS_NOT_CHANGED;
|
||||
mCfgMapInt.insert(
|
||||
std::make_pair<
|
||||
IpcConfigKey,
|
||||
std::reference_wrapper<int>>(
|
||||
IpcConfigKey::TEST_NUM,
|
||||
std::reference_wrapper<int>(mAllData.testNum)));
|
||||
}
|
||||
const StatusCode IpcConfig::Init(void)
|
||||
{
|
||||
memset(&mAllData, 0, sizeof(Config_s));
|
||||
|
@ -15,12 +26,38 @@ const StatusCode IpcConfig::Init(void)
|
|||
}
|
||||
const StatusCode IpcConfig::UnInit(void)
|
||||
{
|
||||
if (CONFIG_HAS_CHANGED == mCfgChanged)
|
||||
{
|
||||
LogInfo("Save config files.\n");
|
||||
ConfigSaveFile(mCfg);
|
||||
}
|
||||
CloseConfigFile(mCfg);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const int IpcConfig::GetInt(const IpcConfigKey &key)
|
||||
{
|
||||
return 0;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<int>>::iterator iter;
|
||||
iter = mCfgMapInt.find(key);
|
||||
if (iter != mCfgMapInt.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
LogError("Can't find the key.\n");
|
||||
constexpr int UNKNOWN_CONFIG = -1;
|
||||
return UNKNOWN_CONFIG;
|
||||
}
|
||||
void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
|
||||
{
|
||||
std::map<IpcConfigKey, std::reference_wrapper<int>>::iterator iter;
|
||||
iter = mCfgMapInt.find(key);
|
||||
if (iter != mCfgMapInt.end())
|
||||
{
|
||||
iter->second.get() = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError("Can't find the key.\n");
|
||||
}
|
||||
}
|
||||
void IpcConfig::ReadAllConfigParameters(void)
|
||||
{
|
||||
|
@ -30,7 +67,7 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
{
|
||||
LogWarning("test_num doesn't exist, will make it as default.\n");
|
||||
configChanging = true;
|
||||
constexpr int DEFAULT_TEST_NUM = 0;
|
||||
constexpr int DEFAULT_TEST_NUM = 10;
|
||||
mAllData.testNum = DEFAULT_TEST_NUM;
|
||||
ConfigSetInt(mCfg, "test_num", mAllData.testNum);
|
||||
}
|
||||
|
|
|
@ -4,24 +4,38 @@
|
|||
#include "IIpcConfig.h"
|
||||
#include "Config.h"
|
||||
#include <memory>
|
||||
#include <map>
|
||||
constexpr bool CONFIG_HAS_CHANGED = true;
|
||||
constexpr bool CONFIG_HAS_NOT_CHANGED = false;
|
||||
typedef struct Config_s
|
||||
{
|
||||
int testNum;
|
||||
} Config_s;
|
||||
class MapInt
|
||||
{
|
||||
public:
|
||||
MapInt() = default;
|
||||
~MapInt() = default;
|
||||
};
|
||||
class IpcConfig : public IIpcConfig
|
||||
{
|
||||
public:
|
||||
IpcConfig() = default;
|
||||
IpcConfig();
|
||||
virtual ~IpcConfig() = default;
|
||||
const StatusCode Init(void) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
const int GetInt(const IpcConfigKey &key) override;
|
||||
void SetInt(const IpcConfigKey &key, const int &value) override;
|
||||
|
||||
private:
|
||||
void ReadAllConfigParameters(void);
|
||||
|
||||
private:
|
||||
bool mCfgChanged;
|
||||
VConfig *mCfg;
|
||||
Config_s mAllData;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<int>> mCfgMapInt;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<long int>> mCfgMapUInt;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<std::string>> mCfgMapString;
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user