tconfig.h 3.1 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

/*
 * 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_

S
Shengliang Guan 已提交
20
#include "tarray.h"
S
Shengliang Guan 已提交
21 22 23 24 25

#ifdef __cplusplus
extern "C" {
#endif

S
config  
Shengliang Guan 已提交
26 27
#define CFG_NAME_MAX_LEN 128

S
Shengliang Guan 已提交
28
typedef enum {
S
config  
Shengliang Guan 已提交
29 30 31 32 33 34
  CFG_STYPE_DEFAULT,
  CFG_STYPE_CFG_FILE,
  CFG_STYPE_ENV_FILE,
  CFG_STYPE_ENV_VAR,
  CFG_STYPE_APOLLO_URL,
  CFG_STYPE_ARG_LIST,
S
Shengliang Guan 已提交
35
  CFG_STYPE_TAOS_OPTIONS
S
Shengliang Guan 已提交
36
} ECfgSrcType;
S
Shengliang Guan 已提交
37 38

typedef enum {
S
Shengliang Guan 已提交
39 40
  CFG_DTYPE_NONE,
  CFG_DTYPE_BOOL,
S
Shengliang Guan 已提交
41 42 43 44 45
  CFG_DTYPE_INT32,
  CFG_DTYPE_INT64,
  CFG_DTYPE_FLOAT,
  CFG_DTYPE_STRING,
  CFG_DTYPE_DIR,
S
config  
Shengliang Guan 已提交
46 47 48
  CFG_DTYPE_LOCALE,
  CFG_DTYPE_CHARSET,
  CFG_DTYPE_TIMEZONE
S
Shengliang Guan 已提交
49 50
} ECfgDataType;

S
Shengliang Guan 已提交
51
typedef struct SConfigItem {
S
config  
Shengliang Guan 已提交
52
  ECfgSrcType  stype;
S
Shengliang Guan 已提交
53
  ECfgDataType dtype;
S
Shengliang Guan 已提交
54
  bool         tsc;
S
cfgtest  
Shengliang Guan 已提交
55
  char        *name;
S
Shengliang Guan 已提交
56
  union {
S
Shengliang Guan 已提交
57 58 59 60 61
    bool    bval;
    float   fval;
    int32_t i32;
    int64_t i64;
    char   *str;
S
Shengliang Guan 已提交
62
  };
S
config  
Shengliang Guan 已提交
63
  union {
S
Shengliang Guan 已提交
64 65
    int64_t imin;
    double  fmin;
S
config  
Shengliang Guan 已提交
66 67
  };
  union {
S
Shengliang Guan 已提交
68 69
    int64_t imax;
    double  fmax;
S
config  
Shengliang Guan 已提交
70
  };
S
tfs cfg  
Shengliang Guan 已提交
71
  SArray *array;  // SDiskCfg
S
Shengliang Guan 已提交
72 73
} SConfigItem;

S
Shengliang Guan 已提交
74
typedef struct {
S
Shengliang Guan 已提交
75 76
  const char *name;
  const char *value;
S
Shengliang Guan 已提交
77 78
} SConfigPair;

S
Shengliang Guan 已提交
79 80 81 82
typedef struct SConfig {
  ECfgSrcType stype;
  SArray     *array;
} SConfig;
S
Shengliang Guan 已提交
83 84

SConfig *cfgInit();
S
Shengliang Guan 已提交
85
int32_t  cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
86
int32_t  cfgLoadFromArray(SConfig *pCfg, SArray *pArgs);  // SConfigPair
S
Shengliang Guan 已提交
87 88 89 90
void     cfgCleanup(SConfig *pCfg);

int32_t      cfgGetSize(SConfig *pCfg);
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
S
Shengliang Guan 已提交
91
int32_t      cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
S
Shengliang Guan 已提交
92

S
Shengliang Guan 已提交
93 94 95 96 97 98
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, bool tsc);
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval, bool tsc);
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
S
Shengliang Guan 已提交
99 100 101
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal);
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal);
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal);
S
Shengliang Guan 已提交
102

S
Shengliang Guan 已提交
103 104 105
const char *cfgStypeStr(ECfgSrcType type);
const char *cfgDtypeStr(ECfgDataType type);

S
Shengliang Guan 已提交
106
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
S
Shengliang Guan 已提交
107

S
Shengliang Guan 已提交
108 109 110 111 112
#ifdef __cplusplus
}
#endif

#endif /*_TD_CONFIG_H_*/