mirror of
				https://gitee.com/jiuyilian/embedded-framework.git
				synced 2025-10-24 18:20:15 -04:00 
			
		
		
		
	[zhoulongyu]: 使用格式化工具编译后的代码
This commit is contained in:
		
							parent
							
								
									b94f6ac956
								
							
						
					
					
						commit
						c5691b1b95
					
				| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			@ -15,9 +15,9 @@
 | 
			
		|||
#ifndef IIPCCONFIG_H
 | 
			
		||||
#define IIPCCONFIG_H
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <string_view>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
enum class IpcConfigKey
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ class IIpcConfig
 | 
			
		|||
public:
 | 
			
		||||
    IIpcConfig() = default;
 | 
			
		||||
    virtual ~IIpcConfig() = default;
 | 
			
		||||
    virtual const StatusCode ConfigFileSave(void) {return CreateStatusCode(STATUS_CODE_OK); }
 | 
			
		||||
    virtual const StatusCode ConfigFileSave(void) { return CreateStatusCode(STATUS_CODE_OK); }
 | 
			
		||||
    static std::shared_ptr<IIpcConfig> &GetInstance(std::shared_ptr<IIpcConfig> *impl = nullptr);
 | 
			
		||||
    virtual const StatusCode Init(void) { return CreateStatusCode(STATUS_CODE_OK); }
 | 
			
		||||
    virtual const StatusCode UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			@ -17,15 +17,12 @@
 | 
			
		|||
std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig> *impl)
 | 
			
		||||
{
 | 
			
		||||
    static auto instance = std::make_shared<IIpcConfig>();
 | 
			
		||||
    if (impl)
 | 
			
		||||
    {
 | 
			
		||||
        if (instance.use_count() == 1)
 | 
			
		||||
        {
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        if (instance.use_count() == 1) {
 | 
			
		||||
            LogInfo("Instance changed succeed.\n");
 | 
			
		||||
            instance = *impl;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
        else {
 | 
			
		||||
            LogError("Can't changing the instance becase of using by some one.\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			@ -16,32 +16,23 @@
 | 
			
		|||
#include "ILog.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#define CHECK_MAP(map) (map.size()==1? true:false)
 | 
			
		||||
#define CHECK_MAP(map) (map.size() == 1 ? true : false)
 | 
			
		||||
 | 
			
		||||
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)));
 | 
			
		||||
    mCfgMapInt.insert(std::make_pair<IpcConfigKey, std::reference_wrapper<int>>(
 | 
			
		||||
        IpcConfigKey::TEST_NUM, std::reference_wrapper<int>(mAllData.testNum)));
 | 
			
		||||
 | 
			
		||||
    std::map<std::string, std::reference_wrapper<CHAR_STRING>> innerMap;
 | 
			
		||||
    innerMap.insert(
 | 
			
		||||
        std::make_pair(
 | 
			
		||||
            "test_string",
 | 
			
		||||
            std::reference_wrapper<CHAR_STRING>(mAllData.testString)));
 | 
			
		||||
    innerMap.insert(std::make_pair("test_string", std::reference_wrapper<CHAR_STRING>(mAllData.testString)));
 | 
			
		||||
    mCfgMapString.insert(std::make_pair(IpcConfigKey::TEST_STRING, innerMap));
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
const StatusCode IpcConfig::Init(void)
 | 
			
		||||
{
 | 
			
		||||
    memset(&mAllData, 0, sizeof(Config_s));
 | 
			
		||||
    mCfg = OpenConfigFile(IPC_CONFIG_FILE_PATH);
 | 
			
		||||
    if (nullptr == mCfg)
 | 
			
		||||
    {
 | 
			
		||||
    if (nullptr == mCfg) {
 | 
			
		||||
        LogError("Open config file failed.\n");
 | 
			
		||||
        return CreateStatusCode(STATUS_CODE_NOT_OK);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -50,25 +41,20 @@ const StatusCode IpcConfig::Init(void)
 | 
			
		|||
}
 | 
			
		||||
const StatusCode IpcConfig::UnInit(void)
 | 
			
		||||
{
 | 
			
		||||
    if (CONFIG_HAS_CHANGED == mCfgChanged)
 | 
			
		||||
    {
 | 
			
		||||
    if (CONFIG_HAS_CHANGED == mCfgChanged) {
 | 
			
		||||
        LogInfo("Save config files.\n");
 | 
			
		||||
        ConfigSaveFile(mCfg);
 | 
			
		||||
    }
 | 
			
		||||
    CloseConfigFile(mCfg);
 | 
			
		||||
    return CreateStatusCode(STATUS_CODE_OK);
 | 
			
		||||
}
 | 
			
		||||
const StatusCode IpcConfig::ConfigFileSave(void)
 | 
			
		||||
{
 | 
			
		||||
    return ConfigSaveFile(mCfg);
 | 
			
		||||
}
 | 
			
		||||
const StatusCode IpcConfig::ConfigFileSave(void) { return ConfigSaveFile(mCfg); }
 | 
			
		||||
 | 
			
		||||
const int IpcConfig::GetInt(const IpcConfigKey &key)
 | 
			
		||||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<int>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapInt.find(key);
 | 
			
		||||
    if (iter != mCfgMapInt.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapInt.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -79,13 +65,11 @@ 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())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapInt.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -93,8 +77,7 @@ const short IpcConfig::GetShort(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<short>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapShort.find(key);
 | 
			
		||||
    if (iter != mCfgMapShort.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapShort.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -105,13 +88,11 @@ void IpcConfig::SetShort(const IpcConfigKey &key, const short &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<short>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapShort.find(key);
 | 
			
		||||
    if (iter != mCfgMapShort.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapShort.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -119,8 +100,7 @@ const long IpcConfig::GetLong(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<long>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapLong.find(key);
 | 
			
		||||
    if (iter != mCfgMapLong.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLong.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -131,13 +111,11 @@ void IpcConfig::SetLong(const IpcConfigKey &key, const long &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<long>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapLong.find(key);
 | 
			
		||||
    if (iter != mCfgMapLong.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLong.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -145,8 +123,7 @@ const long long IpcConfig::GetLongLong(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<long long>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapLongLong.find(key);
 | 
			
		||||
    if (iter != mCfgMapLongLong.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLongLong.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -157,13 +134,11 @@ void IpcConfig::SetLongLong(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())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLongLong.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -171,8 +146,7 @@ const char IpcConfig::GetChar(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<char>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapChar.find(key);
 | 
			
		||||
    if (iter != mCfgMapChar.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapChar.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -183,13 +157,11 @@ void IpcConfig::SetChar(const IpcConfigKey &key, const char &character)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<char>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapChar.find(key);
 | 
			
		||||
    if (iter != mCfgMapChar.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapChar.end()) {
 | 
			
		||||
        iter->second.get() = character;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -197,8 +169,7 @@ const float IpcConfig::GetFloat(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<float>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapFloat.find(key);
 | 
			
		||||
    if (iter != mCfgMapFloat.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapFloat.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -209,13 +180,11 @@ void IpcConfig::SetFloat(const IpcConfigKey &key, const float &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<float>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapFloat.find(key);
 | 
			
		||||
    if (iter != mCfgMapFloat.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapFloat.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -223,8 +192,7 @@ const double IpcConfig::GetDouble(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<double>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapDouble.find(key);
 | 
			
		||||
    if (iter != mCfgMapDouble.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapDouble.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -235,13 +203,11 @@ void IpcConfig::SetDouble(const IpcConfigKey &key, const double &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<double>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapDouble.find(key);
 | 
			
		||||
    if (iter != mCfgMapDouble.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapDouble.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -249,8 +215,7 @@ const long double IpcConfig::GetLongDouble(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<long double>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapLongDouble.find(key);
 | 
			
		||||
    if (iter != mCfgMapLongDouble.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLongDouble.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -261,13 +226,11 @@ void IpcConfig::SetLongDouble(const IpcConfigKey &key, const long double &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<long double>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapLongDouble.find(key);
 | 
			
		||||
    if (iter != mCfgMapLongDouble.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapLongDouble.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -275,8 +238,7 @@ const bool IpcConfig::GetBool(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<bool>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapBool.find(key);
 | 
			
		||||
    if (iter != mCfgMapBool.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapBool.end()) {
 | 
			
		||||
        return iter->second;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -287,13 +249,11 @@ void IpcConfig::SetBool(const IpcConfigKey &key, const bool &value)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::reference_wrapper<bool>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapBool.find(key);
 | 
			
		||||
    if (iter != mCfgMapBool.end())
 | 
			
		||||
    {
 | 
			
		||||
    if (iter != mCfgMapBool.end()) {
 | 
			
		||||
        iter->second.get() = value;
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -301,9 +261,8 @@ const std::string IpcConfig::GetString(const IpcConfigKey &key)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<CHAR_STRING>>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapString.find(key);
 | 
			
		||||
    if (iter != mCfgMapString.end() && CHECK_MAP(iter->second))
 | 
			
		||||
    {
 | 
			
		||||
        const std::string sv(iter->second.begin()->second);     // char[] --> const std::strinbg
 | 
			
		||||
    if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) {
 | 
			
		||||
        const std::string sv(iter->second.begin()->second); // char[] --> const std::strinbg
 | 
			
		||||
        return sv;
 | 
			
		||||
    }
 | 
			
		||||
    LogError("Can't find the key.\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -314,15 +273,13 @@ void IpcConfig::SetString(const IpcConfigKey &key, const std::string string)
 | 
			
		|||
{
 | 
			
		||||
    std::map<IpcConfigKey, std::map<std::string, std::reference_wrapper<CHAR_STRING>>>::iterator iter;
 | 
			
		||||
    iter = mCfgMapString.find(key);
 | 
			
		||||
    if (iter != mCfgMapString.end() && CHECK_MAP(iter->second))
 | 
			
		||||
    {
 | 
			
		||||
        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 *
 | 
			
		||||
    if (iter != mCfgMapString.end() && CHECK_MAP(iter->second)) {
 | 
			
		||||
        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
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        LogError("Can't find the key.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -330,8 +287,7 @@ void IpcConfig::SetString(const IpcConfigKey &key, const std::string string)
 | 
			
		|||
void IpcConfig::ReadAllConfigParameters(void)
 | 
			
		||||
{
 | 
			
		||||
    StatusCode code = ConfigGetInt(mCfg, "test_num", &(mAllData.testNum));
 | 
			
		||||
    if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST"))
 | 
			
		||||
    {
 | 
			
		||||
    if (StatusCodeEqual(code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
 | 
			
		||||
        LogWarning("test_num doesn't exist, will make it as default.\n");
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
        constexpr int DEFAULT_TEST_NUM = 10;
 | 
			
		||||
| 
						 | 
				
			
			@ -340,21 +296,18 @@ void IpcConfig::ReadAllConfigParameters(void)
 | 
			
		|||
    }
 | 
			
		||||
    const char *testString = NULL;
 | 
			
		||||
    StatusCode string_code = ConfigGetString(mCfg, "test_string", &(testString));
 | 
			
		||||
    if (StatusCodeEqual(string_code, "CONFIG_CODE_PARAM_NOT_EXIST"))
 | 
			
		||||
    {
 | 
			
		||||
    if (StatusCodeEqual(string_code, "CONFIG_CODE_PARAM_NOT_EXIST")) {
 | 
			
		||||
        LogWarning("test_string doesn't exist, will make it as default.\n");
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_CHANGED;
 | 
			
		||||
        char  DEFAULT_TEST_STRING[] = "undefine";
 | 
			
		||||
        char DEFAULT_TEST_STRING[] = "undefine";
 | 
			
		||||
        strncpy(mAllData.testString, DEFAULT_TEST_STRING, sizeof(mAllData.testString));
 | 
			
		||||
        ConfigSetString(mCfg, "test_string", mAllData.testString);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
    else {
 | 
			
		||||
        strncpy(mAllData.testString, testString, sizeof(mAllData.testString));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (CONFIG_HAS_CHANGED == mCfgChanged)
 | 
			
		||||
    {
 | 
			
		||||
    if (CONFIG_HAS_CHANGED == mCfgChanged) {
 | 
			
		||||
        LogInfo("Save the config file.\n");
 | 
			
		||||
        mCfgChanged = CONFIG_HAS_NOT_CHANGED;
 | 
			
		||||
        ConfigSaveFile(mCfg);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			@ -14,11 +14,11 @@
 | 
			
		|||
 */
 | 
			
		||||
#ifndef IPCCONFIG_H
 | 
			
		||||
#define IPCCONFIG_H
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include "IIpcConfig.h"
 | 
			
		||||
#include "Config.h"
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include "IIpcConfig.h"
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <memory>
 | 
			
		||||
constexpr bool CONFIG_HAS_CHANGED = true;
 | 
			
		||||
constexpr bool CONFIG_HAS_NOT_CHANGED = false;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +63,6 @@ public:
 | 
			
		|||
    const std::string GetString(const IpcConfigKey &key) override;
 | 
			
		||||
    void SetString(const IpcConfigKey &key, const std::string string) override;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void ReadAllConfigParameters(void);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			@ -19,8 +19,7 @@ bool CreateIpcConfig(void)
 | 
			
		|||
{
 | 
			
		||||
    auto instance = std::make_shared<IIpcConfig>();
 | 
			
		||||
    StatusCode code = IpcConfigMakePtr::GetInstance()->CreateIpcConfig(instance);
 | 
			
		||||
    if (IsCodeOK(code))
 | 
			
		||||
    {
 | 
			
		||||
    if (IsCodeOK(code)) {
 | 
			
		||||
        LogInfo("CreateIpcConfig is ok.\n");
 | 
			
		||||
        IIpcConfig::GetInstance(&instance);
 | 
			
		||||
        return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -30,8 +29,7 @@ bool CreateIpcConfig(void)
 | 
			
		|||
std::shared_ptr<IpcConfigMakePtr> &IpcConfigMakePtr::GetInstance(std::shared_ptr<IpcConfigMakePtr> *impl)
 | 
			
		||||
{
 | 
			
		||||
    static auto instance = std::make_shared<IpcConfigMakePtr>();
 | 
			
		||||
    if (impl)
 | 
			
		||||
    {
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        instance = *impl;
 | 
			
		||||
    }
 | 
			
		||||
    return instance;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@
 | 
			
		|||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,29 +1,29 @@
 | 
			
		|||
#include "ILog.h"
 | 
			
		||||
#include "IIpcConfig.h"
 | 
			
		||||
#include "ILog.h"
 | 
			
		||||
// #include <gmock/gmock.h>
 | 
			
		||||
#include <gtest/gtest.h>
 | 
			
		||||
namespace IpcConfigTest
 | 
			
		||||
{
 | 
			
		||||
    // ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.Demo
 | 
			
		||||
    TEST(IpcConfigTest, Demo)
 | 
			
		||||
    {
 | 
			
		||||
        CreateLogModule();
 | 
			
		||||
        CreateIpcConfig();
 | 
			
		||||
        ILogInit(LOG_INSTANCE_TYPE_END);
 | 
			
		||||
        IIpcConfig::GetInstance()->Init();
 | 
			
		||||
        int testNum = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::TEST_NUM);
 | 
			
		||||
        LogInfo("Get testNum = %d\n", testNum);
 | 
			
		||||
        const int num999 = 999;
 | 
			
		||||
        IIpcConfig::GetInstance()->SetInt(IpcConfigKey::TEST_NUM, num999);
 | 
			
		||||
// ../output_files/test/bin/IpcConfigTest --gtest_filter=IpcConfigTest.Demo
 | 
			
		||||
TEST(IpcConfigTest, Demo)
 | 
			
		||||
{
 | 
			
		||||
    CreateLogModule();
 | 
			
		||||
    CreateIpcConfig();
 | 
			
		||||
    ILogInit(LOG_INSTANCE_TYPE_END);
 | 
			
		||||
    IIpcConfig::GetInstance()->Init();
 | 
			
		||||
    int testNum = IIpcConfig::GetInstance()->GetInt(IpcConfigKey::TEST_NUM);
 | 
			
		||||
    LogInfo("Get testNum = %d\n", testNum);
 | 
			
		||||
    const int num999 = 999;
 | 
			
		||||
    IIpcConfig::GetInstance()->SetInt(IpcConfigKey::TEST_NUM, num999);
 | 
			
		||||
 | 
			
		||||
        const std::string testString = IIpcConfig::GetInstance()->GetString(IpcConfigKey::TEST_STRING);
 | 
			
		||||
        LogInfo("Get testString = %s\n", testString.c_str());
 | 
			
		||||
        const std::string string = "define";
 | 
			
		||||
        IIpcConfig::GetInstance()->SetString(IpcConfigKey::TEST_STRING, string);
 | 
			
		||||
        IIpcConfig::GetInstance()->ConfigFileSave();
 | 
			
		||||
    const std::string testString = IIpcConfig::GetInstance()->GetString(IpcConfigKey::TEST_STRING);
 | 
			
		||||
    LogInfo("Get testString = %s\n", testString.c_str());
 | 
			
		||||
    const std::string string = "define";
 | 
			
		||||
    IIpcConfig::GetInstance()->SetString(IpcConfigKey::TEST_STRING, string);
 | 
			
		||||
    IIpcConfig::GetInstance()->ConfigFileSave();
 | 
			
		||||
 | 
			
		||||
        IIpcConfig::GetInstance()->UnInit();
 | 
			
		||||
        ILogUnInit();
 | 
			
		||||
        DestroyLogModule();
 | 
			
		||||
    }
 | 
			
		||||
    IIpcConfig::GetInstance()->UnInit();
 | 
			
		||||
    ILogUnInit();
 | 
			
		||||
    DestroyLogModule();
 | 
			
		||||
}
 | 
			
		||||
} // namespace IpcConfigTest
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user