#ifndef __DORIS_SERVER_MAIN_H__
#define __DORIS_SERVER_MAIN_H__

#include <openssl/ssl.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <pthread.h>

#include <event.h>
#include <evhttp.h>

#include <MESA/field_stat2.h>
#include <MESA/MESA_htable.h>
#include <MESA/MESA_handle_logger.h>

#include "MESA_Monitor.h"

#include "doris_client.h"
#include "doris_server_receive.h"

#include <map>
#include <string>

using namespace std;

#ifndef __FILENAME__
#define __FILENAME__ __FILE__
#endif
#define MESA_RUNTIME_LOGV3(handle, lv, fmt, args...)   \
    MESA_handle_runtime_log((handle), (lv), "DorisServer", "%s:%d, " fmt, __FILENAME__, __LINE__, ##args)

#define NIRVANA_CONFIG_FILE "./conf/doris_main.conf"
#define MAX_BUSINESS_NUM 64

#define RECV_WAY_DRS_CLIENT 1
#define RECV_WAY_IDX_FILE   2
#define RECV_WAY_HTTP_POST  3

struct doris_business
{
	char bizname[32];
	u_int32_t recv_way;
	u_int32_t write_file_sw;
	char recv_path_full[256];
	char recv_path_inc[256];
	char store_path_root[256];
	struct version_list_handle *cfgver_head;
	struct doris_parameter *param;

	int64_t total_cfgnum;
	int32_t mm_latest_ver;
	int32_t mm_total_cfgnum;
	u_int32_t mm_status_codeid; //MMÄÚ²¿Òì³£×´Ì¬id
	u_int32_t fs_lineid;
	pthread_rwlock_t rwlock;
};

struct doris_global_info
{
	u_int32_t iothreads;
	int32_t server_port;
	int32_t manager_port;
	int32_t sock_recv_bufsize;
	u_int32_t ssl_conn_on;
	u_int32_t scan_idx_interval;
	u_int32_t cache_frag_size;
	u_int32_t server_role_sw;

	char ssl_CA_path[256];
	char ssl_cert_file[256];
	char ssl_key_file[256];
	char ssl_key_passwd[64];
	pthread_mutex_t *lock_cs;
	SSL_CTX *ssl_instance;

	evutil_socket_t listener;
	evutil_socket_t manager;

	struct doris_business business[MAX_BUSINESS_NUM];
	u_int32_t business_num;
	u_int32_t idx_file_maat;
	map<string, struct doris_business*> *name2business;
	map<string, struct doris_parameter *> *confile2param;

	struct MESA_MonitorHandler *monitor;

	/*logs*/
	u_int32_t log_level;
	u_int32_t statistic_period;
	char root_log_dir[256];
	void *log_runtime;

	screen_stat_handle_t fsstat_handle;
	char fsstat_dst_ip[64];
	char fsstat_appname[16];
	char fsstat_filepath[256];
	u_int32_t fsstat_period;
	int32_t fsstat_print_mode;
	int32_t fsstat_dst_port;
	int32_t fsstat_field[DRS_FSSTAT_FIELD_NUM];
	int32_t fsstat_status[DRS_FSSTAT_STATUS_NUM];
	int32_t fsstat_column[DRS_FSSTAT_CLUMN_NUM];
};

int doris_mkdir_according_path(const char * path);

#endif

