/*************************************************
File name:	subsComm.h
Author: 	He wan Dong
Version:	9:00:00 
Date:  		2003/02/14
Description:subsComm.c��ͷ�ļ�
			
			
			
												
History:               
No. 		
Author:		  
Date:		 
Version:	   
Description:
*************************************************/

#ifndef subsComm__H
	#define subsComm__H

	#include "../../../../plat/public/src/include/pub_include.h"
	#include "../../../../plat/snmp/src/include/snmp.h"
	#include "../../../omcLib/c_program/omcLib/omcLib.h"
	
	#ifndef MYSQL_H
		#include "mysql.h"
	#endif

	#ifndef subsComm_DEBUG
		#define subsComm_DEBUG 0
	#endif

	#define VMS_No			390
	/* fj added 2010-01-19, UDM��AUSFҪ֧�ַ�Ƭ */
	#define UDM_No          365
	#define AUSF_No         366
	
	#define subsComm_LogPath		"../log"
	#define subsComm_LogFile		"subsComm"
	#define subsComm_backupPath		"/usr/local/apache/htdocs/db_backup/subsData"

	#define FlagCode			1373			//snmp company code	of iwv		
	#define MaxCommNum			32				//max number of command can be execute as same time
												//The maxCommNum divides into 2 parts,The 0-15 is used for processing the commands in the subscriberComm table
												//The 16-31 is used for processing the loadData commands 
	#define loadDataCommStartNo	16
	/* fj added 2020-01-19��UDM��AUSF֧�ַ�Ƭ */
	#define MaxSysConfNum		80//30
	#define MaxParamConfNum		2048 //512 -> 1024
	#define MaxIndexNumPerSeg	100
	#define MaxOidLen			20				//max number of object ID
	#define MaxSubOidLen		10				//max number of sub object ID
	//#define MaxLenOfOneVar		1024			//max len of one var_list
	#define MaxVarNum			50				//max number of var in one pdu
	#define DefPort				4959			//define port
	#define HOSTNAME			"localhost"
	#define PUB_DB				"OMC_PUB"					//OMC's public database
	#define SysConfTable		"OMC_PUB.sysConf"			//system config table
	#define subsConfTable		"OMC_PUB.sysSubsConf"		//system config table
	#define CommTable			"OMC_PUB.subscriberComm"	//command table
	#define IpTable				"OMC_PUB.sysInfo"			//system's IP table
	#define subsDataBackupTable	"OMC_PUB.subsDataBackup"	//

	//procState flag define
	#define nIdle			0			//������״̬��nInProcʱ�����������ִ��״̬��nIdleʱ���Żᷢ��snmp���ݰ�
	#define nWaitResponse	1			//������״̬��nInProcʱ���������ݰ���ִ��״̬����ΪnWaitResponse
	#define nWaitIdleComm   2

	//commState flag define
	#define nProcFail		0			//�������ִ��״̬��nWaitResponseʱ����ȴ��ظ���Ϣ��������յ���Ϣ��������������״̬����Ϊ��״̬
	#define nWaitProc		1			//һ���µ�����������ݿ�ʱ�����õ�״̬
	#define nInProc			2			//��ʱ��ɨ�������ʱ����nWaitProc״̬������ʱ���Ѵ���������Ϊ���״̬
	#define nOutProc		3			//�������ִ��״̬��nWaitResponseʱ����ȴ��ظ���Ϣ��������յ���Ϣ��ȷ��������״̬����Ϊ��״̬

	//parameter type define
	#define nSubSysParam	0
	#define nSysParam		1

	//snmp pdu type define [define in snmp.h]
	#define nGet			0
	#define nGetNext		1
	#define nResp			2
	#define nSet			3
	
	//subscriber manage command type define
	#define nReadComm			1
	#define nChangeComm			2
	#define nCreateComm			3
	#define nDeleteComm			4
	#define nLoadIndexComm		5
	#define nReplaceIndexComm	6 //for hlr replace imsi
	#define nLoadDataComm		7 //just used in program
	
	//snmp var type code
	#define  nInteger			0x02
	#define  nOctetString		0x04
	#define  nNull				0x05
	#define  nObjectId			0x06
	#define  nNoSuchObject		0x80
	#define  nNoSuchInstance	0x81
	#define  nEndOfMibView		0x82

	typedef struct unitSysConf{
		int		isEnable;				//ʹ�ܱ�־λ
		int		sysTypeNo;				//ϵͳ�豸��
		int		dataTypeNo;				//�û��������ͣ���Щϵͳ�����ж��ֲ�ͬ���û�����
		int 	sysNo;					//ϵͳ�ţ��ó���ֻ��VSS������ϵͳ��
		DWORD	preObjId[20];			//��ȡ�û����ݵ�OID����Ҫ�ڸ�OID��������û�����OID
		int		preObjIdLen;			//����
		DWORD	indexObjId[20];			//��ȡ�û�������OID
		int		indexObjIdLen;			//����
		int		maxMsgLen;				//��Ϣ��󳤶�
		char	snmpCommunity[16];		//SNMP��֤��
		int		maxSegmentNum;			//���豸�û������Ķ���
		int		maxIndexNumPerSeg;		//���豸ÿ�ε��û���������
		char	paramTableName[128]; 	//��������ʱ�ı���
		char	tmpTableName[128]; 		//database.table
		int		paramConfArrOffset;		//��ϵͳ�Ĳ����ֶ���paramConfArr�����е���ʼλ��
		int		paramConfNum;			//�����ֶεĸ���
		char	indexFieldSubOid[16];	//�ؼ������ֶ���subsParamConf_X���е�level�����ַ���
		char	indexFieldName[64];		//�ؼ��ֶ�����
		BYTE	indexValueLen;			//�ؼ��ֶγ���
	}unitSysConf;

	typedef struct unitParamConf{	
		int		sysTypeNo;				//�ò��������ڵ�ϵͳ�豸��
		char	fieldObjIdStr[16];		//��subsParamConf_���е�level�����ַ���
		char	fieldName[64];			//��������
		int		valueType;				//��������
		int		valueLen;				//��������
		//int		initValue;
	}unitParamConf;

	typedef struct  unitComm{
		//command info
		WORD		commNo;				//ID in command table
		WORD		commType;			//0:invaild,1:read,2:change,3:create,4:delete,5:get index,6:get data in indexBuffer
		int			sysConfArrNo;		//��������Ӧ��sysConfArr��������
		int			dataTypeNo;			//�û���������
		WORD		sysTypeNo;			//ϵͳ�豸��
		WORD		sysNo;				//ϵͳ��
		WORD		subSysNo;			//��ϵͳ��
		char		dstIP[16];			//Զ���豸IP��ַ
		WORD		dstPort;			//Զ���豸�˿�
		int			requestId;			//snmp���ݰ���request ID

		MYSQL_RES	*paramSet;			//�û����ݼ�

		char		indexBuffer[MaxIndexNumPerSeg][19]; //per Segment,MaxIndexNumPerSeg=100
		BYTE		tlvTotalNum;	// ��ǰ��Ƭ���ܹ����͵�tlv����Ŀ
		BYTE		tlvFinishNum;	// ��ǰ��Ƭ���Ѿ��������tlv����Ŀ
		BYTE		tlvInvaildNum;
		char		fieldNameList[2048]; //64*32

		//command process info
		BYTE		commState;			//-1:nFailed,0:nWaitProc,1:nNoFinish,2:nFinished 
		BYTE		procState;			//command process state:0=idle,1=waitResponse 
		BYTE		waitTimeCount;		//the times number of timeout
		BYTE		timeoutCount;		//the timeCount
		WORD		totalNum;
		WORD		finishNum;
		char		desc[200];			//��������
		
		//var_list info
		BYTE	varNum;
	}unitComm;
	
//Interface Functions Declare,define in subsComm.c
int	subsCommInit();
int subsCommTimer();

#endif
