//---------------------------------------------------------------------------

#ifndef CDSCCamCtlrFH
#define CDSCCamCtlrFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <stdio.h>
#include <ADODB.hpp>
#include <DB.hpp>
#include "ITSLibF.h"
#include "ITSDbF.h"
#include "CDSObjectF.h"
//---------------------------------------------------------------------------
#include "CenterCommF.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

class TCCamPset
{
public:
    TCCamPset()
    {
        PSET_NMBR = 1;
        PSET_NM   = "";
        PAN       = 0;
        TILT      = 0;
        ZOOM      = 0;
        FOCS      = 0;
        ANGLE     = 0;
        DFLT_YN   = "N";
    };
    ~TCCamPset() {};

private:

public:
    String  CCAM_CTLR_NMBR;     //	N	NUMBER(10)	    N			CCTV 제어기 번호
    int     PSET_NMBR;          //	N	NUMBER(4)	    N			프리셋 번호
    String  PSET_NM;            //	N	VARCHAR2(100)	N			프리셋 명
    int     PAN;                //	N	NUMBER(4)	    Y	0		팬 값
    int     TILT;               //	N	NUMBER(4)	    Y	0		틸트 값
    int     ZOOM;               //	N	NUMBER(4)	    Y	0		줌 값
    int     FOCS;               //	N	NUMBER(4)	    Y	0		포커스 값
    int     ANGLE;              //	N	NUMBER(4)	    Y	0		각도
    String  DFLT_YN;            //	N	CHAR(1)	        Y	'N'		디폴트 여부

public:
    String  DEL_YN;

};

class TCCamCtlr : public TCDSObject
{
public:
    TCCamCtlr();
    ~TCCamCtlr();

public:
    String  STRM_SVR_IP;        //	N	VARCHAR2(20)	Y			스트리밍 서버 아이피
    String  STRM_SVR_PORT;      //	N	VARCHAR2(5)	    Y			스트리밍 서버 포트
    String  STRM_SESN_NM;       //	N	VARCHAR2(200)	Y			스트리밍 세션 명
    String  STRM_RTSP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 RTSP 주소
    String  STRM_RTMP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 RTMP 주소
    String  STRM_HTTP_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 HTTP 주소
    String  STRM_STOR_ADDR;     //	N	VARCHAR2(200)	Y			스트리밍 저장 주소
    int     CMRA_PORT;          //	N	NUMBER(5)	    Y	1852	웹카메라 제어 포트
    String  CMRA_ID;            //	N	VARCHAR2(20)	Y	'root'	웹카메라 제어 ID
    String  CMRA_PSWD;          //	N	VARCHAR2(20)	Y	'1234'	웹카메라 제어 PSWD
    int     CMRA_CHNL;          //	N	NUMBER(5)	    Y	1		웹카메라제어 CHANNEL
    String  LINK_ID;            //	N	NUMBER(10)	    Y			링크ID

    int     GROUP_NO;           //	N	NUMBER(5)	Y	0		그룹번호
    int     FAN_MODE;           //	N	NUMBER(3)	Y	2		FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     FAN_RUN_TMPR;       //	N	NUMBER(3)	Y	30		팬 동작 온도
    int     HETR_MODE;          //	N	NUMBER(3)	Y	2		히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
    int     HETR_RUN_TMPR;      //	N	NUMBER(3)	Y	0		히터 동작 온도
    int     DETECT_LANES;       //	N	NUMBER(2)	Y	0		검지 전체 차로수
    int     TRAF_CLCT_CYCL;     //	N	NUMBER(3)	Y	60		교통정보수집주기
    int     STTS_CLCT_CYCL;     //	N	NUMBER(3)	Y	0		상태정보수집주기

public:
    INT_CCAM_STATE  STATE;

    TItsMap<int, TCCamPset*> FLists;

public:
    __property String  CCAM_CTLR_NMBR     = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  CCAM_CTLR_ID       = { read = CTLR_ID,       write = CTLR_ID       };
    __property String  CCAM_NM            = { read = NAME,          write = NAME          };
    __property String  CCAM_CTLR_IP       = { read = CTLR_IP,       write = CTLR_IP       };
    __property int     CCAM_CTLR_PORT     = { read = CTLR_PORT,     write = CTLR_PORT     };
    __property int     CCAM_CTLR_LOCAL_NO = { read = CTLR_LOCAL_NO, write = CTLR_LOCAL_NO };
    __property String  CCAM_TYPE_CD       = { read = TYPE_CD,       write = TYPE_CD       };

};
//---------------------------------------------------------------------------
typedef std::map<String, TCCamCtlr*>::iterator   CCamIterator;
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
class TCCamCtlrManager
{
public:
    TCCamCtlrManager();
    ~TCCamCtlrManager();

private:
	TStream *FImgStream;

public:
    TItsMap<String, TCCamCtlr*> FLists;

public:
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool DeleteCCam(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertCCam(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateCCam(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeCCam(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeFcltInfo(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool GetNextCCamId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

    bool LoadPreSet(TADOConnection *ADbConn=NULL);
    bool SavePreSet(TCCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool DeletePreSet(TCCamCtlr *AObj, int APsetNmbr, TADOConnection *ADbConn=NULL);
    bool MergePreSet(TCCamCtlr *AObj, TCCamPset* APset, TADOConnection *ADbConn=NULL);

    bool InsCCamControlHs(String ACtlDt, String ACctvNmbr, String ACtlType, String ACtlVal, String ACtlRes, String AUserId, TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TCCamCtlrManager *CCamCtlrManager;
//---------------------------------------------------------------------------

#endif
