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

#ifndef CDSWCamCtlrFH
#define CDSWCamCtlrFH
//---------------------------------------------------------------------------
#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 TWCamPset
{
public:
    TWCamPset()
    {
        PSET_NMBR = 1;
        PSET_NM   = "";
        PAN       = 0;
        TILT      = 0;
        ZOOM      = 0;
        FOCS      = 0;
        ANGLE     = 0;
        DFLT_YN   = "N";
    };
    ~TWCamPset() {};

private:

public:
    String  WCAM_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 TWCamCtlr : public TCDSObject
{
public:
    TWCamCtlr();
    ~TWCamCtlr();

public:
    String  WCAM_MODL;          //  N   VARCHAR2(20)    Y           웹카메라 모델
    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
    String  FULL_STRM_ADDR;

public:
    INT_WCAM_STATE  STATE;

    TItsMap<int, TWCamPset*> FLists;

public:
    __property String  WCAM_CTLR_NMBR     = { read = CTLR_NMBR,     write = CTLR_NMBR     };
    __property String  WCAM_CTLR_ID       = { read = CTLR_ID,       write = CTLR_ID       };
    __property String  WCAM_NM            = { read = NAME,          write = NAME          };
    __property String  WCAM_CTLR_IP       = { read = CTLR_IP,       write = CTLR_IP       };
    __property int     WCAM_CTLR_PORT     = { read = CTLR_PORT,     write = CTLR_PORT     };
    __property int     WCAM_CTLR_LOCAL_NO = { read = CTLR_LOCAL_NO, write = CTLR_LOCAL_NO };
    __property String  WCAM_TYPE_CD       = { read = TYPE_CD,       write = TYPE_CD       };

};
//---------------------------------------------------------------------------
typedef std::map<String, TWCamCtlr*>::iterator   WCamIterator;
//---------------------------------------------------------------------------

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

private:
	TStream *FImgStream;

public:
    TItsMap<String, TWCamCtlr*> FLists;

public:
    bool LoadFromDb(TADOConnection *ADbConn=NULL);
    bool LoadStatusFromDb(TADOConnection *ADbConn=NULL);
    bool DeleteWCam(TWCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool InsertWCam(TWCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool UpdateWCam(TWCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeWCam(TWCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool MergeFcltInfo(TWCamCtlr *AObj, TADOConnection *ADbConn=NULL);
    bool GetNextWCamId(int &ANmbr, int &AId, TADOConnection *ADbConn=NULL);

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

    bool InsWCamControlHs(String ACtlDt, String ACctvNmbr, String ACtlType, String ACtlVal, String ACtlRes, String AUserId, TADOConnection *ADbConn=NULL);
};
//---------------------------------------------------------------------------
extern TWCamCtlrManager *WCamCtlrManager;
//---------------------------------------------------------------------------

#endif
