/**----------------------------------------------------------------------
** Copyright	: Video Surveillance(China) Co. Ltd 2006-20007
** File Name	: vs_conf.h
** Description  : 
**				common config lib
** Created On   : 06/13/07
** Created by   : 
**				  Double Yang
** Modification : 
** 
**---------------------------------------------------------------------*/
#ifndef __VS_SYSTEM_CONFIG__
#define __VS_SYSTEM_CONFIG__

/*-----------------------Included Files-------------------------*/
#include "ssi.h"
#include "tinyxml.h"

/*---------------------------Defines----------------------------*/
#define VS_MAX_IP_LEN		32
#define VS_MAX_FILEPATH_LEN  128
#define VS_MAX_USERID_LEN	32
#define VS_MAX_WWW_LEN 64

enum VS_NE_TYPE
{
	VS_NE_VMS=1,
	VS_NE_DBS=2,
	VS_NE_VSS=3,
	VS_NE_MAX,
};



typedef struct VsConfCommon_s
{
	S8	szLocalIp[VS_MAX_IP_LEN+1];
	S8	szNtpIp[VS_MAX_IP_LEN+1];
	
	U32	nDbsVisitOPtion;	
	S8	szDbsIp[VS_MAX_IP_LEN+1];
	U32	nDbsPort;
	S8	szDbsWWWName[VS_MAX_WWW_LEN];
	U32	nDbsWWWPort;
	
	U32	nVmsVisitOPtion;	
	S8	szVmsIp[VS_MAX_IP_LEN+1];
	U32	nVmsPort;
	S8	szVmsWWWName[VS_MAX_WWW_LEN];
	U32	nVmsWWWPort;
}VsConfCommon_t;

typedef struct VsConfSsi_s
{
	U32  nCacheSize;
	U32  nHeapSize;
	U32  nTelnetPort;
}VsConfSsi_t;

typedef struct VsConfSlog_s
{
	S8   szServerIp[VS_MAX_IP_LEN+1];
	S8   szFilePath[VS_MAX_FILEPATH_LEN+1];
	U32  nLogMask;
	U32  nPrintSwitch;
}VsConfSlog_t;

typedef struct VsConfVss_s
{
	U32	nNeId;
	U32	nDbCache;
	U32	nSdrSwitch;
	U32	nLimitIpcNum;
	U32	nLimitUserNum;
	S32	nLimitBand;

	S8	szDomainId[VS_MAX_USERID_LEN];
	S8	szFtpRoot[VS_MAX_FILEPATH_LEN+1];
	
	U32 nLogMaskMc;
	U32 nLogMaskAd;
	U32 nLogMaskMt;
	U32 nLogMaskVr;
	U32 nLogMaskPlayback;
	U32 nLogMaskBsdDb;
	U32	nLogMaskCtm;
	U32	nLogMaskCtmCom;
	U32	nLogMaskCtmDmn;

	U32 nTcpStreamPort;
	U32 nTcpAudioPort;	
	U32 nAudioForceUdp;
	U32 nVmxFakePort;
	U32 nMfsOption;	//大于0表示是MFS
	U32 nFsBasket;	//大于0表示使用basket文件系统
}VsConfVss_t;

typedef struct VsConfVms_s
{
	U32  nNeId;
	U32  nListenPort;
	U32  nAdaptorPort;
	U32  nSdrSwitch;
	U32  nEmsClientPort;
	U32  nEmsAgentSlogMask;
	U32	 nLimitIpcNum;
	U32  nLimitUserNum;
	U32  nWriteAllDevStatus;

	S8   szDbName[VS_MAX_FILEPATH_LEN+1];
	S8   szDbIp[VS_MAX_IP_LEN+1];
	S8	szFtpRoot[VS_MAX_FILEPATH_LEN+1];
}VsConfVms_t;


typedef struct VsConfDbs_s
{
	U32  nNeId;
	U32  nConcurMax;	
	U32  nSdrSwitch;
	U32  nEmsClientPort;
	U32  nEmsAgentSlogMask;
	S8   szDbName[VS_MAX_FILEPATH_LEN+1];
	S8   szDbIp[VS_MAX_IP_LEN+1];
}VsConfDbs_t;


class CVsConfig
{
public:
	CVsConfig();
	virtual ~CVsConfig();

	static S32 LoadConfig();
	static S32 CloseConfig();
	static S32 ShowConfig(U32 nNeType);
	static void ManualConfig(U32 nNeType);

	// common config
	static S8* GetLocaIp();
	static void SetLocaIp(S8 * szIpAddr);

	static S8* GetNtpIp();
	
	static U32 GetDbsVisitOption();
	static S8* GetDbsIp();
	static U32 GetDbsPort();
	static S8* GetDbsWWWName();
	static U32 GetDbsWWWPort();

	static U32 GetVmsVisitOption();
	static S8* GetVmsIp();
	static U32 GetVmsPort();
	static S8* GetVmsWWWName();
	static U32 GetVmsWWWPort();
	static S8* GetVmsFtpRoot();



	// surveillance server related config
	static U32 GetVssSsiCacheSize();
	static U32 GetVssSsiHeapSize();
	static U32 GetVssSsiTelnetPort();
	static S8* GetVssSlogServer();
	static S8* GetVssSlogFile();
	static U32 GetVssSlogMask();
	static U32 GetVssSlogPrintSwitch();

	static U32 GetVssNeId();
	static U32 GetVssDbCache();
	static U32 GetVssSdrSwitch();
	
	static U32 GetVssLimitIpcNum();
	static U32 GetVssLimitUsrNum();
	static U32 GetVssLimitBand();
	
	static S8* GetVssDomainId();

	
	static S8* GetFtpRoot();

	static U32 GetLogMaskMc() ;
	static U32 GetLogMaskAd() ;
	static U32 GetLogMaskMt() ;
	static U32 GetLogMaskVr() ;
	static U32 GetLogMaskPlayback() ;
	static U32 GetLogMaskBsdDb() ;

	static U32 GetLogMaskCtm();
	static U32 GetLogMaskCtmCom();
	static U32 GetLogMaskCtmDmn();
	
	static U32 GetTcpStreamPort();
	static U32 GetTcpAudioPort();
	static U32 GetAudioForceUDP();
	static U32 GetVmxFakePort();
	static U32 GetMfsOption();
	static U32 GetFsBasket();

	// auth server related config
	static U32 GetVmsSsiCacheSize();
	static U32 GetVmsSsiHeapSize();
	static U32 GetVmsSsiTelnetPort();
	static S8* GetVmsSlogServer();
	static S8* GetVmsSlogFile();
	static U32 GetVmsSlogMask();
	static U32 GetVmsSlogPrintSwitch();

	static U32 GetVmsNeId();
	static U32 GetVmsListenPort();
	static U32 GetVmsAdaptorPort();
	static U32 GetVmsSdrSwitch();

	static S8* GetVmsDbName();
	static S8* GetVmsDbIp();

	static U32 GetVmsLimitIpcNum();
	static U32 GetVmsLimitUsrNum();
	static U32 GetVmsDevStatusSwitch();

	// DBS related config
	static U32 GetDbsSsiCacheSize();
	static U32 GetDbsSsiHeapSize();
	static U32 GetDbsSsiTelnetPort();
	static S8* GetDbsSlogServer();
	static S8* GetDbsSlogFile();
	static U32 GetDbsSlogMask();
	static U32 GetDbsSlogPrintSwitch();

	static U32 GetDbsNeId();
	static U32 GetConcurMax();
	
	static U32 GetDbsSdrSwitch();
	static U32 GetDbsEmsCliPort();
	static U32 GetDbsEmsAgentSlogMask();
	static S8* GetDbsDbName();
	static S8* GetDbsDbIp();


protected:

	
private:
	static CVsConfig	  m_ConfVs;
	static VsConfCommon_t m_ConfCom;
	static TiXmlElement*	m_pXmlCom;
	static TiXmlDocument*   m_pXmlDoc;

	static void Init();
	static S32 LoadConfComm(TiXmlElement* pRootElement);
	static S32 LoadConfBasic(TiXmlElement* pRootElement, U32 nNeType);

	static S32 SetNeId(U32 nNeType, U32 nNeId);

	// Surveillance Server related config
	static VsConfSsi_t	m_ConfVssSsi;
	static VsConfSlog_t   m_ConfVssSlog;
	static VsConfVss_t	 m_ConfVss;
	static TiXmlElement*	m_pXmlVss;
	static S32 LoadConfVss(TiXmlElement* pRootElement);

	// Auth server related config
	static VsConfSsi_t	m_ConfVmsSsi;
	static VsConfSlog_t   m_ConfVmsSlog;
	static VsConfVms_t	 m_ConfVms;
	static TiXmlElement*	m_pXmlVms;
	static S32 LoadConfVms(TiXmlElement* pRootElement);

	// Metadata server related config
	static VsConfSsi_t	m_ConfDbsSsi;
	static VsConfSlog_t   m_ConfDbsSlog;
	static VsConfDbs_t	m_ConfDbs;
	static TiXmlElement*	m_pXmlDbs;
	static S32 LoadConfDbs(TiXmlElement* pRootElement);
};

#ifdef LINUX
#define WS_SNPRINTF snprintf
#define WS_STRCMPI  strcasecmp
#else
#define WS_SNPRINTF _snprintf
#define WS_STRCMPI  _strcmpi
#endif

#endif

