#ifndef __DORIS_CLIENT_H__
#define __DORIS_CLIENT_H__

#include <event.h>
#include <cjson/cJSON.h>

enum FSSTAT_DORIS_FILED_ITEMS
{
	DRS_FS_FILED_REQ_FAIL=0,
	DRS_FS_FILED_REQ_META,
	DRS_FS_FILED_RES_META,
	DRS_FS_FILED_RES_NOMETA,
	DRS_FS_FILED_REQ_FILES,
	DRS_FS_FILED_RES_FILES,
	DRS_FS_FILED_RES_FRAGS,
	DRS_FS_FILED_RES_FRAGERR,
	DRS_FS_FILED_RES_BYTES,
	DRS_FS_FILED_RES_VERERR,

	DRS_FS_FILED_BACKUP1_REQ,
	DRS_FS_FILED_BACKUP2_REQ,
	
	FSSTAT_DORIS_FILED_NUM,
};

enum FSSTAT_DORIS_STATUS_ITEMS
{
	DRS_FS_STAT_MST_CNN_SRV=0,
	DRS_FS_STAT_MST_FAIL_SRV,
	DRS_FS_STAT_BCK1_CNN_SRV,
	DRS_FS_STAT_BCK1_FAIL_SRV,
	DRS_FS_STAT_BCK2_CNN_SRV,
	DRS_FS_STAT_BCK2_FAIL_SRV,
	DRS_FS_STAT_MEMORY_USED,
	DRS_FS_STAT_HTTP_SESSIONS,

	FSSTAT_DORIS_STATUS_NUM,
};

struct doris_statistics
{
	long long field[FSSTAT_DORIS_FILED_NUM];
	long long status[FSSTAT_DORIS_STATUS_NUM];
};

struct doris_arguments
{
	char bizname[32];
	int64_t current_version; //当前已获取完毕的最新版本号，将从它下一个版本取配置
	int32_t judian_id;
};

struct doris_instance;
struct doris_callbacks
{
	void *userdata;
	void (*version_start)(struct doris_instance *instance, cJSON *meta, void *userdata); //meta在整个版本声明周期内都有效
	void (*cfgfile_start)(struct doris_instance *instance, const char *tablename, size_t size, u_int32_t cfgnum, const char *userregion, void *userdata);
	void (*cfgfile_update)(struct doris_instance *instance, const char *data, size_t len, void *userdata);
	void (*cfgfile_finish)(struct doris_instance *instance, const char *md5, void *userdata);
	void (*version_error)(struct doris_instance *instance, void *userdata); //下载文件失败，该版本需要回滚
	void (*version_finish)(struct doris_instance *instance, void *userdata);
};

struct doris_parameter *doris_parameter_new(const char *confile, struct event_base *manage_evbase, void *runtimelog);
struct doris_instance *doris_instance_new(struct doris_parameter *param, struct event_base *worker_evbase,
	struct doris_callbacks *cbs, struct doris_arguments *args, void *runtimelog);

#endif

