#ifndef nrtrde__H
#define nrtrde__H

#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "./conv_prefix.h"
#include <sys/types.h>
#include <dirent.h>

#ifndef MYSQL_H
	#include "mysql.h"
#endif
	
#ifndef NRTRDE_DEBUG
	#define NRTRDE_DEBUG 0
#endif

/********************************************************/
/******             Constant Define                ******/
/********************************************************/
/* The hpmn servers info update timeslot (Second) */
#define HPMN_INFO_UPDATE_TIME 60	
/* The hpmn servers count which this version to support */
#define HPMN_SERVER_COUNT 100
/* The max time of the file backup (day) */
#define MAX_BAK_DAY 7

#define SEQ_NUM_CONF "./conf/nrtrde_seq.conf"

/* The return value of the function */
#define SUCCESSFUL 1
#define FAIL 0
#define NO_FIND 0x7FFFFFFF

/********************************************************/
/******              Struct Define                 ******/
/********************************************************/
/* The information of the hpmn servers */
typedef struct HpmnServer
{
	char mcc[8];					//The mcc of the HPMN server
	char mnc[8];					//The mnc of the HPMN server
	char tadig[8];					//The tadig of the HPMN server, length=5
	char serverIP[16];				//The remote IP address of the HPMN server, xxx.xxx.xxx.xxx
	char loginName[64];				//The user name to login the remote HPMN server
	char loginPass[64];				//The user password to login the remote HPMN server
	int timeSlot;					//The timeslot to send the nrtrde to the remote HPMN server
	char reportDir[256];			//The directory to send the report files to the HPMN server
	char nrtrdeDir[256];			//The directory to send the nrtrde files to the HPMN server

	int sendFileTimeout;			//When the value<0, then send the nrtrde file to remote HPMN server
}HpmnServer;

/* The config of the tag */
typedef struct TagNode
{
	char fieldName[32];				//The field name of the tag
	int tagValue;					//The value of the tag, the tag is application
	int isStructed;					//Whether the tag is structed or not
	int code;						//How to code the field, 0-no code; 1-Integer; 2-Ascii; 3-HexString; 4-NumberString; 5-BCDString;
	int minSize;					//The min size of the field
	int maxSize;					//The max size of the field
}TagNode;

/* Use for link struct */
typedef struct DataNode
{
	struct DataNode* next;			//The next data link to the data
	unsigned char data;				//The data in the node
}DataNode;
	
/* Use for store the record of the NRTRDE Delivery report */	
typedef struct NDRepNode
{
	char tadig[8];					//The tadig of this record
	char fileName[32];				//The fileName of this record
	char recvTime[32];				//The time when to receive the file
	struct NDRepNode* next;			//The next node in the link
}NDRepNode;

/* Use for store the record of the NRTRDE Error report */
typedef struct NERepNode
{
	char tadig[8];					//The tadig of this record
	char fileName[32];				//The fileName of the received NRTRDE file which is parsed
	int type;						//The type of this record, 1-NRTRDE file error, 2-MOC error, 3-MTC error
	int recordNumber;				//The number of this record in the NRTRDE file
	char errorCode[8];				//The error code of this record
	struct NERepNode* next;			//The next node in the link
}NERepNode;

/* Use for store the information of every CallEvents */
typedef struct CallEvent
{
	int type;						//1-MOC, 2-MTC, 3-GPRS
	char imsi[32];					//Imsi
	char imei[32];					//Imei
	char startTime[32];				//CallEventStartTime
	char utcTimeOff[32];			//utcTimeOffsef
	long callDuration;				//CallEventDuration
	int causeForTerm;				//CauseForTermination
	char teleServCode[32];			//TeleServiceCode
	char bearerServCode[32];		//BearerServCode
	char supplServCode[32];			//SupplementaryServiceCode
	char dialledDigits[32];			//DialledDigits
	char connectedNumber[32];		//ConnectedNumber
	char thirdPartyNumber[32];		//ThirdPartyNumber
	char callingNumber[32];			//CallingNumber
	char recEntityId[32];			//RecEntityId
	long callReference;				//CallReference
	long chargeAmount;				//ChargeAmount
}CallEvent;

typedef struct seq_object
{
	char tadig[8];
	unsigned long nr_seq_num;
	unsigned long nd_seq_num;
	unsigned long ne_seq_num;
}seq_object;

typedef struct seq_buffer
{
	int count;
	seq_object seq_obj[HPMN_SERVER_COUNT];
}seq_buffer;

#endif	

