120 lines
3.8 KiB
C
120 lines
3.8 KiB
C
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* 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 "ConfigImpl.h"
|
|
#include "ILog.h"
|
|
#include <stddef.h>
|
|
const StatusCode ConfigInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
|
const StatusCode ConfigUnInit(void) { return CreateStatusCode(STATUS_CODE_OK); }
|
|
VConfig *OpenConfigFile(const char *fileName) { return (VConfig *)NewConfig(fileName); }
|
|
const StatusCode ConfigSaveFile(VConfig *cfg)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->save(cfg);
|
|
}
|
|
void CloseConfigFile(VConfig *cfg)
|
|
{
|
|
if (NULL == cfg) {
|
|
LogError("NULL config poniter.\n");
|
|
return;
|
|
}
|
|
((Config *)cfg)->close(cfg);
|
|
}
|
|
const StatusCode ConfigGetInt(VConfig *cfg, const char *name, int *value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->get_int(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigSetInt(VConfig *cfg, const char *name, const int value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->set_int(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigGetShort(VConfig *cfg, const char *name, short *value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->get_short(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigSetShort(VConfig *cfg, const char *name, const short value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->set_short(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigGetLong(VConfig *cfg, const char *name, long *value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->get_long(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigSetLong(VConfig *cfg, const char *name, const long value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
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 ConfigGetChar(VConfig *cfg, const char *name, char *value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->get_char(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigSetChar(VConfig *cfg, const char *name, const char value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->set_char(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigGetString(VConfig *cfg, const char *name, const char **value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->get_string(cfg, name, value);
|
|
}
|
|
const StatusCode ConfigSetString(VConfig *cfg, const char *name, const char *value)
|
|
{
|
|
if (NULL == cfg) {
|
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
|
}
|
|
return cfg->set_string(cfg, name, value);
|
|
} |