/********************************************************************************************
*** Copyright (c) 2010, Topsee,Inc.
*** File name  : CFunctionInf.h
*** Module     : IPVS client 
*** Author     : LionelLiao
*** Version    : 1.0
*** Created On : 2010.05.06
*** Description:
***            
*** Modification histroy:
*********************************************************************************************/
#ifndef _DEVICE_INFO_H_
#define _DEVICE_INFO_H_

#include <list>
#include "ProjHeader.h"

/*
 *	alarm type
 */
#define ALARM_TYPE_VIDEO_LOSS             2
#define ALARM_TYPE_MOTION_DETECT          3
#define ALARM_TYPE_COVERAGE               4
#define ALARM_TYPE_FIRE                   5
#define ALARM_TYPE_SMOKE                  6
#define ALARM_TYPE_INFRARED               7
#define ALARM_TYPE_GAS                    8
#define ALARM_TYPE_TEMPERATURE            9
#define ALARM_TYPE_JANITOR                10
#define ALARM_TYPE_TEST                   10000
#define ALARM_MODE_STOP                   0 /*停止*/
#define ALARM_MODE_START                  1 /*开始*/
#define ALARM_MODE_CONTINUE               2 /*持续*/

/*
* device type
*/
#define DEVICE_TYPE_NONE            0x00
#define DEVICE_TYPE_CAMERA          0x01
#define DEVICE_TYPE_ENCODER         0x02
#define DEVICE_TYPE_IPCAM           0x03
#define DEVICE_TYPE_DVR             0x04
#define DEVICE_TYPE_DECODER         0x05
#define DEVICE_TYPE_SERIAL          0x06
#define DEVICE_TYPE_PTZ             0x07
#define DEVICE_TYPE_ALARM_IN        0x08
#define DEVICE_TYPE_ALARM_OUT       0x09
#define DEVICE_TYPE_AUDIO_LINE_IN   0x0A
#define DEVICE_TYPE_AUDIO_MIC_IN    0x0B
#define DEVICE_TYPE_AUDIO_OUT       0x0C
#define DEVICE_TYPE_MONITOR         0x0D
#define DEVICE_TYPE_SOFT_DECODER    0x0E
#define DEVICE_TYPE_MAX             DEVICE_TYPE_SOFT_DECODER+1

#define STREAM_TYPE_YUNLIAN  1  // Yunlian standard format
#define STREAM_TYPE_HIK      2  // Hikvision standard format
#define STREAM_TYPE_TS		 3	
#define STREAM_TYPE_DH		 4

/*
* video res
*/
#define RES_VIDEO_SIZE_NONE          0x00
#define RES_VIDEO_SIZE_QCIF          0x01
#define RES_VIDEO_SIZE_CIF           0x02
#define RES_VIDEO_SIZE_HD1           0x03
#define RES_VIDEO_SIZE_D1            0x04


#define MAX_TRACK_DESC_LEN          128
#define MAX_TRACK_SEQ_LEN           256
#define MAX_PRESET_DESC_LEN			128
bool IsMaster(U32 type);

class CMasterDevice;
class CDeviceBaseInfo
{
public:
	CDeviceBaseInfo();
	CDeviceBaseInfo(CDeviceBaseInfo& oDevice);
	virtual ~CDeviceBaseInfo() {};
	//Must
	S8  szDevId[VS_DEV_ID_LEN];
	S8  szDevName[VS_DEV_NAME_LEN];
	U32 nVendor;                   
	U32 nType;

	S8   szDomainId[VS_DOMAINID_LEN+1];
	S8   szDomainName[AUTH_MAX_DOMAIN_LEN];
	S8   szVssDomainId[VS_DOMAINID_LEN+1];
	U32  nVssSvrId;
	U32  nVssSvrIp;
	U32  nVssSvrPort;
	U32  nVisiteOption;//visit by ip or domain
	S8   szWWWVssSvrDomain[AUTH_MAX_DOMAIN_LEN];
	U32  nWWWVssSvrPort;
	
	U32  nAudioSvrPort;

    S8  szLongitude[32];
    S8  szLatitude[32];

	S8  szAlmTypeAct1[VS_STRING_LENG_64];
	S8  szAlmTypeAct2[VS_STRING_LENG_64];
	S8  szAlmTypeAct3[VS_STRING_LENG_64];

	//static bool IsMaster(U32 type);
	CMasterDevice* getMaster() {return m_pMaster;};
	void setMasterDevice(CMasterDevice* pMaster) { m_pMaster = pMaster; };
protected:

	CMasterDevice* m_pMaster;
};


class CCameraDevice;
class CAudioOutDevice;
typedef struct
{
	U32 puManagerRight:1;// 1）   能否对其进行设备管理
	U32 videoSuvRight:1;//  2）   能否对其进行视频浏览
	U32 audioTwowayRight:1;// 3）   能否对其进行语音对讲
	U32 ptzSetRight:1; //  4）   能否对其进行PTZ控制
	U32 videoPlaybackRight:1;// 5）   能否对其进行录像回放
	U32 videoMangerRight:1;// 6）   能否对其进行录像管理   
	
	U32 reserved:26; 
}DeviceRights;

typedef struct
{
	S8   szDevOrGrpId[VS_DEV_ID_LEN];
	U32  nIsDevGrpId;
	U32  nPriority;
	S8   szRights[64];
	S8   szDevDomainId[VS_DOMAINID_LEN];
}RelatedInfo_t;

typedef struct
{
	S8 szGroupId[VS_DEVGROUP_ID_LEN];
	S8 szGroupName[VS_DEV_NAME_LEN];
}GroupInfo_t;

typedef  struct
{
	S8  szDevId[VS_DEV_ID_LEN];	   // alarm input devId or camera id
	U32 nAlmActType;				// 1,2,3
	S8 szAlmType[VS_STRING_LENG_64];	// VS_ALARM_TYPE_XXX 取值组合，以逗号分开
}AlmActTypeInfo_t;

typedef struct
{
	U32  nVssSvrId;
	U32  nVssSvrIp;
	U32  nVssSvrPort;
	U32  nVisiteOption;//visit by ip or domain
	S8   szWWWVssSvrDomain[AUTH_MAX_DOMAIN_LEN];
	S8   szVssDomainId[VS_DOMAINID_LEN+1];
	U32  nWWWVssSvrPort;
}VssSvrInfo_t;

typedef struct
{
	S8  szMasterDevId[VS_DEV_ID_LEN];
	S8  szSlaveDevId[VS_DEV_ID_LEN];
	U32 nSlaveType;
	U32 nChannel;
}DevRelationInfo_t;

typedef struct
{
	S8   szDevId[VS_DEV_ID_LEN];
	S8   szDevName[VS_DEV_NAME_LEN];
	S8   szDomainId[VS_DOMAINID_LEN+1];
	U32  nVendor;
	U32  nVersion;
	U32  nType;
	U32  nVssSvrId;
}DevBaseInfo_t;

typedef struct
{
    S8    szDevId[VS_DEV_ID_LEN];
	U32   nVisitStreamOption;
	U32   nRecStatus;
}CameraSettingInfo_t;

typedef struct
{
	S8    szDevId[VS_DEV_ID_LEN];
	U32   bDoubleStream;
	U32   bWithPTZ;
	U32   bWithAudioIn;
	U32   bWithAudioOut;
}CameraRegInfo_t;

typedef struct
{
	//Must
	S8  szDevId[VS_DEV_ID_LEN];
	S8  szDevName[VS_DEV_NAME_LEN];
	U32 nVendor;                   
	U32 nType;

	S8   szDomainId[VS_DOMAINID_LEN+1];
	S8   szDomainName[AUTH_MAX_DOMAIN_LEN];
	S8   szVssDomainId[VS_DOMAINID_LEN+1];
	U32  nVssSvrId;
	U32  nVssSvrIp;
	U32  nVssSvrPort;
	U32  nVisiteOption;//visit by ip or domain
	S8   szWWWVssSvrDomain[AUTH_MAX_DOMAIN_LEN];
	U32  nWWWVssSvrPort;

	U32  nAudioSvrPort;

	S8  szLongitude[32];
	S8  szLatitude[32];

	TabDevLoc_t  oDevLoc;
	TabMasterBaseInfo_t oMasterBaseInfo;
	S8	szDevGroupName[VS_DEV_NAME_LEN];

	DeviceRights Rights;
	U32   nPriority;
}MasterDevInfo_t;

class CMasterDevice : public CDeviceBaseInfo
{
public:
	TabDevLoc_t  oDevLoc;
	TabMasterBaseInfo_t oMasterBaseInfo;
	S8	szDevGroupName[VS_DEV_NAME_LEN];

 	DeviceRights Rights;
	U32   nPriority;
	BOOL  bAlmAct;
	U32   nAlmActSec;
	U32   nAlmActStatus;
	std::list<CDeviceBaseInfo *> m_lstDevice;
	
	CCameraDevice* getCameraDev(U32 nChl);
	CAudioOutDevice* getAODev(U32 nChl);

	bool HaveManagerRight();
	bool HaveSuvRight();
	bool HaveAudioTalkRight();
	bool HavePtzRight();
	bool HaveVideoPBRight();
	bool HaveVideoMngRight();

	CMasterDevice();
	virtual ~CMasterDevice();

};

class CCameraDevice : public CDeviceBaseInfo
{
public:
	CCameraDevice(CMasterDevice* pMaster);
	CCameraDevice(CCameraDevice& oDevice);
	virtual ~CCameraDevice();
	
	TabDevLoc_t  oDevLoc;
	
	CAudioOutDevice* getAODev()
	{
		if(m_pMaster==NULL)
			return NULL;
		return m_pMaster->getAODev(nChannel);
	};

	U32   nChannel;
	U32   StreamType;
	U32   bDoubleStream;
	U32   bWithPTZ;
	U32   bWithAudioIn;
	U32   bWithAudioOut;
	U32   nRecStatus;
	U32   nVisitStreamOption;
	BOOL  bAlmAct;
	U32   nAlmActSec;
	U32   nAlmActStatus;
};

class CMonitorDevice : public CDeviceBaseInfo
{
public:
	CMonitorDevice(CMasterDevice* pMaster);
	CMonitorDevice(CMonitorDevice& oDevice);
	virtual ~CMonitorDevice() {};
	U32 nStreamType;
	U32 nStreamIP;
    U32 nStreamPort;  
	U32 m_Bind;
	U32 nChannel;

};

class CAudioInDevice : public CDeviceBaseInfo
{
public:
	CAudioInDevice(CMasterDevice* pMaster);
	CAudioInDevice(CAudioInDevice& oDevice);
	virtual ~CAudioInDevice() {};

	U32 nChannel;

};

class CAudioOutDevice : public CDeviceBaseInfo
{
public:
	CAudioOutDevice(CMasterDevice* pMaster);
	CAudioOutDevice(CAudioOutDevice& oDevice);
	virtual ~CAudioOutDevice() {};
	
	U32 StreamType;
	U32 nChannel;
};

class CAlarmInDevice : public CDeviceBaseInfo
{
public:
	CAlarmInDevice(CMasterDevice* pMaster);
	CAlarmInDevice(CAlarmInDevice& oDevice);
	virtual ~CAlarmInDevice() {};

	TabDevAlmin_t oAlmin;
	TabDevLoc_t  oDevLoc;
	U32 nChannel;
    U32 nAlarmType;                              /* IPVS_ALARM_IN_XXX */
    U32 nVideoChannel;

};

class CAlarmOutDevice : public CDeviceBaseInfo
{
public:
	 CAlarmOutDevice(CMasterDevice* pMaster);
	 CAlarmOutDevice(CAlarmOutDevice& oDevice);
	 virtual ~CAlarmOutDevice() {};
	 
	 TabDevAlmout_t oAlmout;
	 U32 nChannel;
	 U32 nAlarmType; 
};

#endif