#ifndef _GY_MSG_H
#define _GY_MSG_H

#define MAX_GY_PORT	16384// 8192
#define INVALID_GY_PORT	0xFFFF

#define  NUMBER_LEN        32
#define  GY_APN_LEN        	64
//#define  ADDRESS_LEN      64
#define CONTEXT_ID_LEN	128

typedef enum GY_MSG_TYPE
{
	GY_MSG_CCR,
	GY_MSG_CCA,
}_GY_MSG_TYPE;

typedef enum SERVICE_TYPE
{
	ST_CS_VOICE,
	ST_CS_SMS,
	ST_CS_VEDIO,
	ST_PS_DATA,
	ST_PS_VEDIO,
}_SERVICE_TYPE;

typedef enum REQUEST_TYPE
{
	RT_INITIAL_REQUEST=1,
	RT_UPDATE_REQUEST,
	RT_TERMINATE_REQUEST,
	RT_EVENT_REQUEST,
}_REQUEST_TYPE;

typedef enum REQUEST_ACTION
{
	RA_DIRECT_DEBITING = 0,
	RA_REFUND_ACCOUNT = 1,
	RA_CHECK_BALANCE = 2,
	RA_PRICE_ENQUIRY = 3,
}_REQUEST_ACTION;

typedef enum CHECK_BALANCE_RESULT
{
	CBR_ENOUGH_CREDIT = 0,
	CBR_NO_CREDIT = 1,
}_CHECK_BALANCE_RESULT;

typedef enum REPORTING_REASON
{
	RR_THRESHOLD = 0,
	RR_QHT = 1,
	RR_FINAL = 2,
	RR_QUOTA_EXHAUSTED = 3,
	RR_VALIDITY_TIME = 4,
	RR_OTHER_QUOTA_TYPE = 5,
	RR_RATING_CONDITION_CHANGE = 6,
	RR_FORCED_REAUTHORISATION = 7,
	RR_POOL_EXHAUSTED = 8,
}_REPORTING_REASON;

typedef struct gy_ccr
{

	char	caller[NUMBER_LEN];
	char	called[NUMBER_LEN];
	char smsc[NUMBER_LEN];
	char origin_caller[NUMBER_LEN];
	char msc_addr[NUMBER_LEN];
	char vlr_number[NUMBER_LEN];
	char imsi[NUMBER_LEN];
	char	apn[GY_APN_LEN];
	char cellid[16];	
	int    sgsn_ip;
	int    ggsn_ip;
	char	request_action;
	char cellid_presented;	
	//char mscc_presented;
	char role_of_node;
	//long	balance_to_check;
	float	req_service_unit;
	int service_key;
	int reporting_reason;
	int sent_msg_num;
	long used_unit;
}_gy_ccr;

typedef struct gy_cca
{

	int   result;
	int   check_balance_result;
	long  grant_value;
	long  volume_threshold;	
	long  time_threshold;		
	int  is_final;
}_gy_cca;

typedef struct gy_msg
{
	int	fd_port;
	int	app_port;
	enum GY_MSG_TYPE	msg_type;
	enum SERVICE_TYPE	service_type;  
	enum REQUEST_TYPE   request_type;	
	int	   request_number;
	int   service_identifier;
	int   rating_group;
	char	cxt_id[CONTEXT_ID_LEN];
	struct msg_body
	{
		_gy_ccr ccr;
		_gy_cca cca;
	}msg_body;
	
}_gy_msg;

typedef struct gy_port
{
	int	used_flag;
	int	index;
	long updated_ts;
	int	app_port;
	char	context_id[CONTEXT_ID_LEN];
	enum SERVICE_TYPE	service_type;  
	int	request_number;
	int   as_client;
}_gy_port;

typedef struct gy_space
{
	int	cur_index;
	int	used_ports;
	_gy_port gy_port[MAX_GY_PORT];
}_gy_space;

typedef struct gy_msg_stat
{
	int	ccr;
	int	ccr_init;
	int	ccr_update;
	int	ccr_terminate;
	int	ccr_event;
	int	cca;
	int	cca_init;
	int	cca_update;
	int	cca_terminate;
	int	cca_event;
}_gy_msg_stat;

typedef struct gy_stat
{

	_gy_msg_stat	send_stat;
	_gy_msg_stat recv_stat;
}_gy_stat;


#endif
