This commit is contained in:
fancy 2023-09-16 09:30:13 -07:00
parent a60d476935
commit 2eca81afe6
14 changed files with 201 additions and 6 deletions

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IIPCCONFIG_H #ifndef IIPCCONFIG_H
#define IIPCCONFIG_H #define IIPCCONFIG_H
#include "StatusCode.h" #include "StatusCode.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "IIpcConfig.h" #include "IIpcConfig.h"
#include "ILog.h" #include "ILog.h"
std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig> *impl) std::shared_ptr<IIpcConfig> &IIpcConfig::GetInstance(std::shared_ptr<IIpcConfig> *impl)

View File

@ -1,7 +1,20 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "IpcConfig.h" #include "IpcConfig.h"
#include "ILog.h" #include "ILog.h"
#include <string.h> #include <string.h>
// #include <utility>
IpcConfig::IpcConfig() IpcConfig::IpcConfig()
{ {
mCfgChanged = CONFIG_HAS_NOT_CHANGED; mCfgChanged = CONFIG_HAS_NOT_CHANGED;
@ -53,6 +66,7 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
if (iter != mCfgMapInt.end()) if (iter != mCfgMapInt.end())
{ {
iter->second.get() = value; iter->second.get() = value;
mCfgChanged = CONFIG_HAS_CHANGED;
} }
else else
{ {
@ -61,19 +75,19 @@ void IpcConfig::SetInt(const IpcConfigKey &key, const int &value)
} }
void IpcConfig::ReadAllConfigParameters(void) void IpcConfig::ReadAllConfigParameters(void)
{ {
bool configChanging = false;
StatusCode code = ConfigGetInt(mCfg, "test_num", &(mAllData.testNum)); 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"); LogWarning("test_num doesn't exist, will make it as default.\n");
configChanging = true; mCfgChanged = CONFIG_HAS_CHANGED;
constexpr int DEFAULT_TEST_NUM = 10; constexpr int DEFAULT_TEST_NUM = 10;
mAllData.testNum = DEFAULT_TEST_NUM; mAllData.testNum = DEFAULT_TEST_NUM;
ConfigSetInt(mCfg, "test_num", mAllData.testNum); ConfigSetInt(mCfg, "test_num", mAllData.testNum);
} }
if (true == configChanging) if (CONFIG_HAS_CHANGED == mCfgChanged)
{ {
LogInfo("Save the config file.\n"); LogInfo("Save the config file.\n");
mCfgChanged = CONFIG_HAS_NOT_CHANGED;
ConfigSaveFile(mCfg); ConfigSaveFile(mCfg);
} }
} }

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IPCCONFIG_H #ifndef IPCCONFIG_H
#define IPCCONFIG_H #define IPCCONFIG_H
#include "StatusCode.h" #include "StatusCode.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "IpcConfigMakePtr.h" #include "IpcConfigMakePtr.h"
#include "ILog.h" #include "ILog.h"
#include "IpcConfig.h" #include "IpcConfig.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IPC_CONFIG_MAKE_PTR_H #ifndef IPC_CONFIG_MAKE_PTR_H
#define IPC_CONFIG_MAKE_PTR_H #define IPC_CONFIG_MAKE_PTR_H
#include "IIpcConfig.h" #include "IIpcConfig.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include "StatusCode.h" #include "StatusCode.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Config.h" #include "Config.h"
#include "ConfigImpl.h" #include "ConfigImpl.h"
#include "ILog.h" #include "ILog.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ConfigCode.h" #include "ConfigCode.h"
#include "ILog.h" #include "ILog.h"
#include <string.h> #include <string.h>

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONFIGCODE_H #ifndef CONFIGCODE_H
#define CONFIGCODE_H #define CONFIGCODE_H
#include "Config.h" #include "Config.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ConfigImpl.h" #include "ConfigImpl.h"
#include "ILog.h" #include "ILog.h"
#include "ConfigCode.h" #include "ConfigCode.h"
@ -42,8 +56,7 @@ static const StatusCode ConfigGetIntImpl(VConfig *cfg, const char *name, int *va
} }
static const StatusCode ConfigSetIntImpl(VConfig *cfg, const char *name, const int value) static const StatusCode ConfigSetIntImpl(VConfig *cfg, const char *name, const int value)
{ {
int result = 0; config_setting_t *root, *setting;
config_setting_t *root, *setting, *movie;
root = config_root_setting(&(((Config *)cfg)->cfg)); root = config_root_setting(&(((Config *)cfg)->cfg));
setting = config_setting_add(root, name, CONFIG_TYPE_INT); setting = config_setting_add(root, name, CONFIG_TYPE_INT);
config_setting_set_int(setting, value); config_setting_set_int(setting, value);

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONFIGIMPL_H #ifndef CONFIGIMPL_H
#define CONFIGIMPL_H #define CONFIGIMPL_H
#include "Config.h" #include "Config.h"

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef STATUSCODE_H #ifndef STATUSCODE_H
#define STATUSCODE_H #define STATUSCODE_H
#include <stdbool.h> #include <stdbool.h>

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2023 JIUYILIAN Co., Ltd.
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "StatusCode.h" #include "StatusCode.h"
#include "ILog.h" #include "ILog.h"
#include <stdio.h> #include <stdio.h>