Files
ldb/common/config.h
2026-01-19 10:37:32 +00:00

53 lines
1.0 KiB
C

#ifndef __CONFIG_H__
#define __CONFIG_H__
#include <stddef.h>
typedef enum {
LOG_LEVEL_DEBUG,
LOG_LEVEL_INFO,
LOG_LEVEL_ERROR
} LogLevel;
typedef enum {
MODE_MASTER,
MODE_SLAVE
} ServerMode;
typedef enum {
PERSIST_INCREMENTAL,
PERSIST_NONE
} PersistenceType;
typedef enum {
ALLOC_JEMALLOC,
ALLOC_MALLOC,
ALLOC_OTHER
} AllocatorType;
typedef struct {
char ip[64];
int port;
ServerMode mode;
char master_ip[64]; // slave 才需要
int master_port; // slave 才需要
LogLevel log_level;
PersistenceType persistence;
AllocatorType allocator;
} AppConfig;
/**
* 从 XML 文件加载配置
* 返回 0 表示成功;非 0 表示失败
*/
int config_load(const char *filename, AppConfig *out_cfg);
const char *log_level_to_string(LogLevel lvl);
const char *server_mode_to_string(ServerMode mode);
const char *persistence_to_string(PersistenceType p);
const char *allocator_to_string(AllocatorType a);
#endif /* CONFIG_H */