

#ifndef __CDR_HEAD_FILE
#define __CDR_HEAD_FILE

#include "mysql.h"
#include "errmsg.h"
#include <dirent.h>
#include "../../../../plat/public/src/include/asn1.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"

#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif

/* Added for show version by Simon
 * --Begin
 */
#define CDRCOLLECTOR_VERSION		"1.2311.15"
/* --End
 *
 */

#define CDR_DEBUG 0

#define MAX_CDR_PTR 0x7FFFFFFF
#define CDR_PORT 4968
#define MAX_TAG_VALUE 32
#define MAX_FLD_NUM 128
#define MAX_PROCESS_CDR_NUM 256
#define MAX_SNMP_MSG_NUM 64
#define MAX_BIND_VAR_NUM 16
#define MAX_SRC_NUM 32
#define MAX_SYS_NUM 128
#define MAX_SQL_COMM_NUM 256
#define MAX_RETRY 300
#define MAX_MSG_TIMEOUT 20
#define MAX_IDLE_TIMEOUT 5
#define INSTANT_TIMEOUT -1
#define HOST_NAME		"localhost"
#define CDRDB_NAME		"CDR_DB"
#define CSV_PATH		"/usr/local/cdr"
#define CDR_LOG_PATH	"../log"
#define CDR_LOG_FILE	"cdrlog"


#define OMC_SINGLE	7
#define OMC_MASTER	5

#define STATE_IDLE 0
#define STATE_INFO_GET 1
#define STATE_INFO_RESPONSE 2
#define STATE_CDR_GET 3
#define STATE_CDR_RESPONSE 4
#define STATE_TAIL_SET 5
#define STATE_TAIL_RESPONSE 6
#define STATE_RESET_SET 7
#define STATE_RESET_RESPONSE 8

void cdr_timer();
void cdr_init();

typedef struct field_def
{
	char fieldName[64];
	char type;
	char optional;
	int width;
	char tags[MAX_TAG_VALUE][24];
	char tagFlag[MAX_TAG_VALUE];
}field_def;

typedef struct cdr_def
{
	char tags[MAX_TAG_VALUE];
	char allFieldList[8192];
	char outFieldList[8192];
	int fieldCount;
	field_def fields[MAX_FLD_NUM];
}cdr_def;

typedef struct cdr_src
{
	char dataPotOid[128];
	char headPotOid[128];
	char tailPotOid[128];
	DWORD dataOid[32];
	DWORD headOid[32];
	DWORD tailOid[32];
	BYTE dataOidLen;
	BYTE headOidLen;
	BYTE tailOidLen;
	int bufferSize;
	int sysTypeNo;
	int port;
	char recordTable[64];
	char defineTable[64];
	char csvPath[128];
	int version;
	
	cdr_def define;
}cdr_src;

typedef struct cdr_sys
{
	int cdrSrcNo;
	int sysTypeNo;
	int sysNo;
	int subSysNo;
	
	char ip[24];
	snmp_addr addr;
	DWORD requestId;
	int timeout;
	int retry;
	
	DWORD head;
	DWORD tail;
	DWORD tmptail;
	int prepareSetTail;
	int isVarTooBig;
	int maxVarNum;
	int state;
	int processNum;
	int error;
	
}cdr_sys;

typedef struct msg
{
	snmp_pdu pdu;
	unsigned char use;
	int timeout;
}msg;

typedef struct sql_comm_buf
{
	char sqlstr[MAX_SQL_COMM_NUM][8192];
	int commNum;
}sql_comm_buf;

#endif
