mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
[zhoulongyu]: 完成配置库的 long long 数据类型
This commit is contained in:
parent
336e1863d3
commit
85ab73ddc0
|
@ -24,6 +24,7 @@ enum class IpcConfigKey
|
|||
TEST_NUM = 0,
|
||||
TEST_SHORT,
|
||||
TEST_LONG,
|
||||
TEST_LLONG,
|
||||
TEST_STRING,
|
||||
END
|
||||
};
|
||||
|
@ -43,8 +44,8 @@ public:
|
|||
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 long long GetLLong(const IpcConfigKey &key) { return -1; }
|
||||
virtual void SetLLong(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; }
|
||||
|
|
|
@ -34,6 +34,10 @@ IpcConfig::IpcConfig()
|
|||
innerMapLong.insert(std::make_pair("test_long", std::reference_wrapper<long>(mAllData.testLong)));
|
||||
mCfgMapLong.insert(std::make_pair(IpcConfigKey::TEST_LONG, innerMapLong));
|
||||
|
||||
std::map<std::string, std::reference_wrapper<long long>> innerMapLLong;
|
||||
innerMapLLong.insert(std::make_pair("test_llong", std::reference_wrapper<long long>(mAllData.testLLong)));
|
||||
mCfgMapLLong.insert(std::make_pair(IpcConfigKey::TEST_LLONG, innerMapLLong));
|
||||
|
||||
std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMapString;
|
||||
innerMapString.insert(std::make_pair("test_string", std::reference_wrapper<CHAR_STRING>(mAllData.testString)));
|
||||
mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMapString));
|
||||
|
@ -135,23 +139,25 @@ void IpcConfig::SetLong(const IpcConfigKey &key, const long &value)
|
|||
LogError("Can't find the key.\n");
|
||||
}
|
||||
}
|
||||
const long long IpcConfig::GetLongLong(const IpcConfigKey &key)
|
||||
const long long IpcConfig::GetLLong(const IpcConfigKey &key)
|
||||
{
|
||||
std::map<IpcConfigKey, std::reference_wrapper<long long>>::iterator iter;
|
||||
iter = mCfgMapLongLong.find(key);
|
||||
if (iter != mCfgMapLongLong.end()) {
|
||||
return iter->second;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long long>>>::iterator iter;
|
||||
iter = mCfgMapLLong.find(key);
|
||||
if (iter != mCfgMapLLong.end() && CHECK_MAP(iter->second)) {
|
||||
return iter->second.begin()->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)
|
||||
void IpcConfig::SetLLong(const IpcConfigKey &key, const long long &value)
|
||||
{
|
||||
std::map<IpcConfigKey, std::reference_wrapper<long long>>::iterator iter;
|
||||
iter = mCfgMapLongLong.find(key);
|
||||
if (iter != mCfgMapLongLong.end()) {
|
||||
iter->second.get() = value;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long long>>>::iterator iter;
|
||||
iter = mCfgMapLLong.find(key);
|
||||
if (iter != mCfgMapLLong.end() && CHECK_MAP(iter->second)) {
|
||||
iter->second.begin()->second.get() = value;
|
||||
const char *name = iter->second.begin()->first.c_str(); // const std::strinbg --> const char *
|
||||
ConfigSetInt(mCfg, name, iter->second.begin()->second);
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
}
|
||||
else {
|
||||
|
@ -324,11 +330,20 @@ void IpcConfig::ReadAllConfigParameters(void)
|
|||
if (StatusCodeEqual(longCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("test_long doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
constexpr short DEFAULT_TEST_LONG_NUM = 12;
|
||||
constexpr long DEFAULT_TEST_LONG_NUM = 12;
|
||||
mAllData.testLong = DEFAULT_TEST_LONG_NUM;
|
||||
ConfigSetLong(mCfg, "test_long", mAllData.testLong);
|
||||
}
|
||||
|
||||
StatusCode llongCode = ConfigGetLLong(mCfg, "test_llong", &(mAllData.testLLong));
|
||||
if (StatusCodeEqual(llongCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
LogWarning("test_llong doesn't exist, will make it as default.\n");
|
||||
mCfgChanged = CONFIG_HAS_CHANGED;
|
||||
constexpr long long DEFAULT_TEST_LLONG_NUM = 13;
|
||||
mAllData.testLLong = DEFAULT_TEST_LLONG_NUM;
|
||||
ConfigSetLLong(mCfg, "test_llong", mAllData.testLLong);
|
||||
}
|
||||
|
||||
const char *testString = NULL;
|
||||
StatusCode stringCode = ConfigGetString(mCfg, "test_string", &(testString));
|
||||
if (StatusCodeEqual(stringCode, "CONFIG_CODE_PARAM_NOT_EXIST")) {
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct Config_s
|
|||
int testNum;
|
||||
short testShort;
|
||||
long testLong;
|
||||
long long testLLong;
|
||||
CHAR_STRING testString;
|
||||
} Config_s;
|
||||
class MapInt
|
||||
|
@ -50,8 +51,8 @@ public:
|
|||
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 long long GetLLong(const IpcConfigKey &key) override;
|
||||
void SetLLong(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;
|
||||
|
@ -75,7 +76,7 @@ private:
|
|||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<int>>> mCfgMapInt;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<short>>> mCfgMapShort;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long>>> mCfgMapLong;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<long long>> mCfgMapLongLong;
|
||||
std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<long long>>> mCfgMapLLong;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<char>> mCfgMapChar;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<float>> mCfgMapFloat;
|
||||
std::map<IpcConfigKey, std::reference_wrapper<double>> mCfgMapDouble;
|
||||
|
|
|
@ -18,14 +18,19 @@ TEST(IpcConfigTest, Demo)
|
|||
|
||||
short testShort = IIpcConfig::GetInstance()->GetShort(IpcConfigKey::TEST_SHORT);
|
||||
LogInfo("Get test_short = %d\n", testShort);
|
||||
const int numShort = 888;
|
||||
const short numShort = 888;
|
||||
IIpcConfig::GetInstance()->SetShort(IpcConfigKey::TEST_SHORT, numShort);
|
||||
|
||||
long testLong = IIpcConfig::GetInstance()->GetLong(IpcConfigKey::TEST_LONG);
|
||||
LogInfo("Get test_long = %d\n", testLong);
|
||||
const int numLong = 777;
|
||||
const long numLong = 777;
|
||||
IIpcConfig::GetInstance()->SetLong(IpcConfigKey::TEST_LONG, numLong);
|
||||
|
||||
long long testLLong = IIpcConfig::GetInstance()->GetLLong(IpcConfigKey::TEST_LLONG);
|
||||
LogInfo("Get test_llong = %d\n", testLLong);
|
||||
const long long numLLong = 666;
|
||||
IIpcConfig::GetInstance()->SetLLong(IpcConfigKey::TEST_LLONG, numLLong);
|
||||
|
||||
const std::string testString = IIpcConfig::GetInstance()->GetString(IpcConfigKey::TEST_STRING);
|
||||
LogInfo("Get testString = %s\n", testString.c_str());
|
||||
const std::string string = "define";
|
||||
|
|
|
@ -32,6 +32,8 @@ typedef struct v_config
|
|||
const StatusCode (*set_short)(VConfig *, const char *, const short);
|
||||
const StatusCode (*get_long)(VConfig *, const char *, long *);
|
||||
const StatusCode (*set_long)(VConfig *, const char *, const long);
|
||||
const StatusCode (*get_llong)(VConfig *, const char *, long long *);
|
||||
const StatusCode (*set_llong)(VConfig *, const char *, const long long);
|
||||
const StatusCode (*get_string)(VConfig *, const char *, const char **);
|
||||
const StatusCode (*set_string)(VConfig *, const char *, const char *);
|
||||
const StatusCode (*save)(VConfig *);
|
||||
|
@ -47,6 +49,8 @@ const StatusCode ConfigGetShort(VConfig *cfg, const char *name, short *value);
|
|||
const StatusCode ConfigSetShort(VConfig *cfg, const char *name, const short value);
|
||||
const StatusCode ConfigGetLong(VConfig *cfg, const char *name, long *value);
|
||||
const StatusCode ConfigSetLong(VConfig *cfg, const char *name, const long value);
|
||||
const StatusCode ConfigGetLLong(VConfig *cfg, const char *name, long long *value);
|
||||
const StatusCode ConfigSetLLong(VConfig *cfg, const char *name, const long long value);
|
||||
const StatusCode ConfigGetString(VConfig *cfg, const char *name, const char **value);
|
||||
const StatusCode ConfigSetString(VConfig *cfg, const char *name, const char *value);
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -76,7 +76,20 @@ const StatusCode ConfigSetLong(VConfig *cfg, const char *name, const long value)
|
|||
}
|
||||
return cfg->set_long(cfg, name, value);
|
||||
}
|
||||
|
||||
const StatusCode ConfigGetLLong(VConfig *cfg, const char *name, long long *value)
|
||||
{
|
||||
if (NULL == cfg) {
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
return cfg->get_llong(cfg, name, value);
|
||||
}
|
||||
const StatusCode ConfigSetLLong(VConfig *cfg, const char *name, const long long value)
|
||||
{
|
||||
if (NULL == cfg) {
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
return cfg->set_llong(cfg, name, value);
|
||||
}
|
||||
const StatusCode ConfigGetString(VConfig *cfg, const char *name, const char **value)
|
||||
{
|
||||
if (NULL == cfg) {
|
||||
|
|
|
@ -112,6 +112,26 @@ static const StatusCode ConfigSetLongImpl(VConfig *cfg, const char *name, const
|
|||
config_setting_set_int64(setting, llongValue);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
static const StatusCode ConfigGetLLongImpl(VConfig *cfg, const char *name, long long *value)
|
||||
{
|
||||
int result = 0;
|
||||
result = config_lookup_int64(&(((Config *)cfg)->cfg), name, value);
|
||||
if (CONFIG_FALSE == result) {
|
||||
return CreateConfigCode(CONFIG_CODE_PARAM_NOT_EXIST);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
static const StatusCode ConfigSetLLongImpl(VConfig *cfg, const char *name, const long long value)
|
||||
{
|
||||
config_setting_t *root, *setting;
|
||||
root = config_root_setting(&(((Config *)cfg)->cfg));
|
||||
setting = config_setting_get_member(root, name);
|
||||
if (!setting) {
|
||||
setting = config_setting_add(root, name, CONFIG_TYPE_INT);
|
||||
}
|
||||
config_setting_set_int64(setting, value);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
static const StatusCode ConfigGetStringImpl(VConfig *cfg, const char *name, const char **value)
|
||||
{
|
||||
int result = 0;
|
||||
|
@ -147,6 +167,8 @@ static void ConfigImplInit(Config *cfg)
|
|||
cfg->base.set_short = ConfigSetShortImpl;
|
||||
cfg->base.get_long = ConfigGetLongImpl;
|
||||
cfg->base.set_long = ConfigSetLongImpl;
|
||||
cfg->base.get_llong = ConfigGetLLongImpl;
|
||||
cfg->base.set_llong = ConfigSetLLongImpl;
|
||||
cfg->base.get_string = ConfigGetStringImpl;
|
||||
cfg->base.set_string = ConfigSetStringImpl;
|
||||
cfg->base.save = ConfigSaveFileImpl;
|
||||
|
|
Loading…
Reference in New Issue
Block a user