/*************************************************
File name:	paraComm.h
Author: 	Cui Ticun
Version:	9.00.00 
Date:  		2007-7-1
Description:
						
History:               
No. 
Author  
Date    
Version   
Description
*************************************************/

#ifndef paraComm__H
#define paraComm__H

#ifndef SNMP__H
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../../plat/snmp/src/mib_parser/snmp_mib_api.h"
#include "../../../../plat/snmp/src/mib_parser/snmp_mib.h"
#endif

#include "../../../omcLib/c_program/omcLib/omcLib.h"

#ifndef MYSQL__H
#include "mysql.h"
#endif

#ifndef paraComm_DEBUG
#define paraComm_DEBUG 0
#endif

#define paraComm_LogPath		"../log"
#define paraComm_LogFile		"paraComm"

#define MaxCommNum			32						//max number of command can be execute at the same time
#define MaxOidLen			20						//max number of object ID
#define MaxColumnNum		4096					//max number of columns in one table
#define MaxInstanceNoLevel	4						//max level of instanceNo
#define MaxVarNum			50						//max number of var in one pdu
#define MaxLenOfParaValue	512						//max len of One parameter value
#define DefPort				4958					//define port
#define HOSTNAME			"localhost"				//DB's adress
#define PUB_DB				"OMC_PUB"				//OMC's public database
#define ConfTable			"OMC_PUB.sysConf"		//system config table
#define CommTable			"OMC_PUB.parameterComm"	//command table
#define IpTable				"OMC_PUB.sysInfo"		//system's IP table
#define nPubFlag			99						//if sysNo == nPubFlag this parameter is system param

//commState flag define
#define nProcFail			0
#define nWaitProc			1
#define nInProc				2
#define nOutProc			3

//procState flag define
#define nIdle				0
#define nWaitResponse		1

//parameter type define
#define nSubSysParam		0
#define nGlobalSubSysParam	1
#define nGlobalSysParam		2

//snmp pdu type define [define in snmp.h]
/*
#define PDU_GET         	0
#define PDU_GETNEXT     	1
#define PDU_RSP         	2
#define PDU_SET         	3
#define PDU_GETBULK     	5
#define PDU_INFORM      	6
#define PDU_TRAP        	7
#define PDU_REPORT      	8
*/

//snmp var type code
#define  nInteger			0x02
#define  nOctetString		0x04
#define  nNull				0x05
#define  nObjectId			0x06
#define  nIPAddress			0x40
#define  nNoSuchObject		0x80
#define  nNoSuchInstance	0x81
#define  nEndOfMibView		0x82

//Operation_type
#define DO_NOT_DISPLAY		0
#define PULLDOWN_MENU		1
#define TEXTBOX				2
#define LABEL				3

//command type define
#define nGetComm		0
#define	nSetComm		3
#define nGetBulkComm	5
#define nNewEntryComm	9

/***********************Error display define***************************/
#define CONF_COMMAND_ERR_0000	"0000:Command successful"

//ERR_001*:should prompt the operator "Check the device's status"
#define CONF_COMMAND_ERR_0101	"0101:OMC cannot get the device IP"
#define CONF_COMMAND_ERR_0102	"0102:The device IP is error"

//ERR_002*:should prompt the operator "Check the software version of OMC and device"
#define CONF_COMMAND_ERR_0201	"0201:OMC cannot get the object value"
#define CONF_COMMAND_ERR_0202	"0202:OMC cannot get the instance value"

//ERR_003*:should prompt the operator "Check the OMC's status or send command again"
#define CONF_COMMAND_ERR_0301	"0301:OMC send snmp message failed"

//ERR_004*:should prompt the operator "Check the device's status or send command again"
#define CONF_COMMAND_ERR_0401	"0401:Invailed response message"
#define CONF_COMMAND_ERR_0402	"0402:Error Response message"
#define CONF_COMMAND_ERR_0403	"0403:Response timeout"


#define CONF_COMMAND_ERR_9999	"9999:Unknown error"
/******************Error display define End*******************************/


typedef struct snmpInfoDef{
	/*General Info*/
	char	dstIP[16];
	int		needMuliObj;		//can send or get more one objid in one packet
	WORD	dstPort;
	WORD	maxMsgLen;
	char 	snmpCommunity[16];
	
	BYTE	preOidLen;			//The total OID of one system,it's defined in sysConf
	BYTE	oidLen;				//The oid len of the command's parameters
	int		oid[MaxOidLen];		//The oid of this command's parameters
	BOOL	isTablePara;		//If or Not this command's parameters are table parameters
	int		columnNum;			//The column number of this table parameters
	int		column[MaxColumnNum];//The columns of this table parameters
	BYTE	instanceNoLevel;	//The instanceNo level of this command's parameters
	int		instanceNo[MaxInstanceNoLevel];//The instanceNo of this command's parameters
}snmpInfoDef;

typedef struct unitComm {
	/*General Info*/
	WORD commId;				//ID in command table,which is also SNMP's request_id
	WORD commType;				//Command type get,set,get bulk,newEntry
	BYTE paramType;				//0:subsys param/1:global subsys param/2:global sys param
	WORD sysTypeNo;
	WORD sysNo;
	WORD subSysNo;
	
	MYSQL_RES *paramSet;		//Store the infor,which is need when packeting SNMP message
	WORD totalNum;
	WORD finishNum;
	char desc[256];
	char paramTable[64];
	
	snmpInfoDef snmpInfo;
		
	/*command process info*/
	BYTE commState;				//this command's state:0= nFailed, 1=nWaitProc, 2=nNoFinish, 3=nFinished 
	BYTE procState;				//command process state:0=idle,1=waitResponse 
	BYTE waitTimeCount;			//the times number of timeout
	BYTE timeoutCount;			//the timeCount

	//var_list info
	BYTE varNum;
	
	BYTE levelWidth[MaxVarNum];	//The level(!=0) number of the parameter
	
	char readValue[MaxVarNum][512];
} unitComm;

/*************************************************
Function:        // initDbFromMib
Description:     // Get oid info from MIB file and init the paramConf tables.
Calls:           // extern int init_mib();extern struct tree *getLGCroot();extern struct get_tree;extern void close_mib();
Called By:       // paraCommInit();
Table Accessed:  // 
Table Updated:   // paramConf
Input:           // 
Output:          // 
Return:          // 1:OK,0:error
Others:          // 
*************************************************/
int initDbFromMib();

/*************************************************
Function:        // paraCommInit
Description:     // 1.Init OMC_PUB.parameterComm
				 // 2.Init Commands Array
				 // 3.Init Every module's paramConf
Calls:           // omcLogInit();initUnitComm();initDbFromMib();
Called By:       // 
Table Accessed:  // 
Table Updated:   // OMC_PUB.parameterComm;OBJ_xxx.paramConf
Input:           // 
Output:          // 
Return:          // 1:OK,0:error
Others:          // 
*************************************************/
int paraCommInit();

/*************************************************
Function:        // paraCommTimer
Description:     // �豸������ʱ������������
				 // ɨ�����������������������顣
				 // �������������е����

Calls:           // paraCommScan();paraCommProc();omcLogInit();
Called By:       // 
Table Accessed:  // 
Table Updated:   // 
Input:           // 
Output:          // 
Return:          // 1:OK,0:error
Others:          // 
*************************************************/
int paraCommTimer();
#endif
