TDengine/include/util/tconfig.h

147 lines
4.5 KiB
C
Raw Normal View History

2022-02-18 13:28:03 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_CONFIG_H_
#define _TD_CONFIG_H_
2022-02-25 02:40:53 +00:00
#include "tarray.h"
2022-02-18 13:28:03 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-02-22 05:59:51 +00:00
#define CFG_NAME_MAX_LEN 128
2022-02-18 13:37:05 +00:00
typedef enum {
2022-02-22 05:36:26 +00:00
CFG_STYPE_DEFAULT,
CFG_STYPE_CFG_FILE,
CFG_STYPE_ENV_FILE,
CFG_STYPE_ENV_VAR,
2022-04-25 05:57:55 +00:00
CFG_STYPE_ENV_CMD,
2022-02-22 05:36:26 +00:00
CFG_STYPE_APOLLO_URL,
CFG_STYPE_ARG_LIST,
2022-06-22 11:45:41 +00:00
CFG_STYPE_TAOS_OPTIONS,
CFG_STYPE_ALTER_CMD,
2022-02-21 09:33:37 +00:00
} ECfgSrcType;
2022-02-18 13:28:03 +00:00
typedef enum {
2022-02-21 07:09:10 +00:00
CFG_DTYPE_NONE,
CFG_DTYPE_BOOL,
2022-02-18 13:28:03 +00:00
CFG_DTYPE_INT32,
CFG_DTYPE_INT64,
CFG_DTYPE_FLOAT,
2023-09-15 06:30:23 +00:00
CFG_DTYPE_DOUBLE,
2022-02-18 13:28:03 +00:00
CFG_DTYPE_STRING,
CFG_DTYPE_DIR,
2022-02-22 06:22:56 +00:00
CFG_DTYPE_LOCALE,
CFG_DTYPE_CHARSET,
CFG_DTYPE_TIMEZONE
2022-02-18 13:28:03 +00:00
} ECfgDataType;
2024-04-08 02:33:02 +00:00
typedef enum { CFG_SCOPE_SERVER, CFG_SCOPE_CLIENT, CFG_SCOPE_BOTH } ECfgScopeType;
2023-07-14 06:38:35 +00:00
2023-10-23 02:46:48 +00:00
typedef enum {
CFG_DYN_NONE = 0,
CFG_DYN_SERVER = 1,
CFG_DYN_CLIENT = 2,
CFG_DYN_BOTH = 3,
#ifdef TD_ENTERPRISE
CFG_DYN_ENT_SERVER = CFG_DYN_SERVER,
CFG_DYN_ENT_CLIENT = CFG_DYN_CLIENT,
CFG_DYN_ENT_BOTH = CFG_DYN_BOTH,
#else
CFG_DYN_ENT_SERVER = CFG_DYN_NONE,
CFG_DYN_ENT_CLIENT = CFG_DYN_NONE,
CFG_DYN_ENT_BOTH = CFG_DYN_NONE,
#endif
} ECfgDynType;
2022-02-21 07:09:10 +00:00
typedef struct SConfigItem {
2022-02-22 05:36:26 +00:00
ECfgSrcType stype;
2022-02-21 07:09:10 +00:00
ECfgDataType dtype;
int8_t scope;
2023-10-23 02:46:48 +00:00
int8_t dynScope;
char *name;
2022-02-21 07:09:10 +00:00
union {
2022-02-28 05:49:38 +00:00
bool bval;
float fval;
int32_t i32;
int64_t i64;
char *str;
2022-02-21 07:09:10 +00:00
};
2022-02-22 05:36:26 +00:00
union {
2022-02-22 11:49:11 +00:00
int64_t imin;
double fmin;
2022-02-22 05:36:26 +00:00
};
union {
2022-02-22 11:49:11 +00:00
int64_t imax;
double fmax;
2022-02-22 05:36:26 +00:00
};
2024-01-03 11:57:22 +00:00
SArray *array; // SDiskCfg/SLogVar
2022-02-21 07:09:10 +00:00
} SConfigItem;
2022-02-25 02:40:53 +00:00
typedef struct {
2022-02-25 07:49:22 +00:00
const char *name;
const char *value;
2022-02-25 02:40:53 +00:00
} SConfigPair;
2024-04-25 05:58:02 +00:00
typedef struct SConfig SConfig;
typedef struct SConfigIter SConfigIter;
2022-02-23 02:58:53 +00:00
2024-07-23 07:06:14 +00:00
int32_t cfgInit(SConfig **ppCfg);
2024-04-25 05:58:02 +00:00
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg);
2022-02-23 02:58:53 +00:00
int32_t cfgGetSize(SConfig *pCfg);
2024-04-26 11:12:19 +00:00
SConfigItem *cfgGetItem(SConfig *pCfg, const char *pName);
2024-04-27 02:08:15 +00:00
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock);
2024-04-25 05:58:02 +00:00
int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer);
2024-04-26 11:12:19 +00:00
2024-07-23 07:06:14 +00:00
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter);
2024-04-25 05:58:02 +00:00
SConfigItem *cfgNextIter(SConfigIter *pIter);
void cfgDestroyIter(SConfigIter *pIter);
2024-04-26 11:12:19 +00:00
void cfgLock(SConfig *pCfg);
void cfgUnLock(SConfig *pCfg);
2022-02-23 02:58:53 +00:00
2024-04-25 05:58:02 +00:00
// clang-format off
2023-10-23 02:46:48 +00:00
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, int8_t scope, int8_t dynScope);
2024-04-25 05:58:02 +00:00
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, int8_t scope, int8_t dynScope);
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, int8_t scope, int8_t dynScope);
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, float minval, float maxval, int8_t scope, int8_t dynScope);
2023-10-23 02:46:48 +00:00
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope);
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope);
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope);
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope);
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal, int8_t scope, int8_t dynScope);
2024-04-25 05:58:02 +00:00
// clang-format on
2022-02-18 13:28:03 +00:00
2022-02-21 09:33:37 +00:00
const char *cfgStypeStr(ECfgSrcType type);
const char *cfgDtypeStr(ECfgDataType type);
2024-07-23 07:06:14 +00:00
int32_t cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
int32_t cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen);
2022-06-22 09:17:18 +00:00
2022-02-24 11:06:39 +00:00
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
2024-04-08 02:33:02 +00:00
void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump);
2022-02-23 02:58:53 +00:00
2022-10-13 03:09:43 +00:00
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl);
2022-04-25 05:57:55 +00:00
2022-02-18 13:28:03 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_CONFIG_H_*/