/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jpsoft.ehome.sdk;

import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.win32.StdCallLibrary;

import java.util.Arrays;
import java.util.List;

//SDK接口说明,HCNetSDK.dll

//windows gdi接口,gdi32.dll in system32 folder, 在设置遮挡区域,移动侦测区域等情况下使用
public interface HCISUPAlarm extends StdCallLibrary {
    /***宏定义***/
    //常量
    public static final int MAX_DEVICE_ID_LEN = 256;    //设备ID长度
    public static final int NET_EHOME_SERIAL_LEN = 12;  //设备序列号长度

    public static class NET_EHOME_IPADDRESS extends Structure {
        public byte[] szIP = new byte[128];
        public short wPort;     //端口
        public byte[] byRes = new byte[2];

        @Override
        protected List<String> getFieldOrder() {
            // TODO Auto-generated method stub
            return Arrays.asList(
                    "szIP", 
                    "wPort", 
                    "byRes"
            );
        }
    }
    
    public static class BYTE_ARRAY extends Structure
    {
	public byte[] byValue;

	public BYTE_ARRAY(int iLen) {
		byValue = new byte[iLen];
	}

        @Override
        protected List<String> getFieldOrder() {
            // TODO Auto-generated method stub
            return Arrays.asList(
                    "byValue"
            );
        }
    }

    public static class NET_EHOME_ALARM_ISAPI_INFO extends Structure{
		public Pointer pAlarmData;
		public int dwAlarmDataLen;
		public byte byDataType;
		public byte byPicturesNumber;
		public byte[] byRes = new byte[2];
		public Pointer pPicPackData;
		public byte[] byRes1 = new byte[32];
		
		@Override
		protected List<String> getFieldOrder() {
			return Arrays.asList("pAlarmData", "dwAlarmDataLen", "byDataType", "byPicturesNumber",
					"byRes", "pPicPackData", "byRes1");
		}
    }
    
    public static class NET_EHOME_ALARM_MSG extends Structure {
        public int dwAlarmType;      //报警类型，见EN_ALARM_TYPE
        public Pointer pAlarmInfo;       //报警内容（结构体）
        public int dwAlarmInfoLen;   //结构体报警内容长度
        public Pointer pXmlBuf;          //报警内容（XML）
        public int dwXmlBufLen;      //xml报警内容长度
        public byte[] sSerialNumber = new byte[NET_EHOME_SERIAL_LEN]; //设备序列号，用于进行Token认证
        public Pointer pHttpUrl;
	public int dwHttpUrlLen;
	public byte[] byRes = new byte[12];

        @Override
        protected List<String> getFieldOrder() {
            // TODO Auto-generated method stub
            return Arrays.asList(
                    "dwAlarmType", 
                    "pAlarmInfo", 
                    "dwAlarmInfoLen",
                    "pXmlBuf", 
                    "dwXmlBufLen", 
                    "sSerialNumber",
                    "pHttpUrl",
                    "dwHttpUrlLen",
                    "byRes"
            );
        }
    }

    public static interface EHomeMsgCallBack extends StdCallCallback {
        public boolean invoke(int iHandle, NET_EHOME_ALARM_MSG pAlarmMsg, Pointer pUser);
    }

    public static class NET_EHOME_ALARM_LISTEN_PARAM extends Structure {
        public NET_EHOME_IPADDRESS struAddress;
        public EHomeMsgCallBack fnMsgCb; //报警信息回调函数
        public Pointer pUserData;   //用户数据
        public byte  byProtocolType;    //协议类型，0-TCP,1-UDP
        public byte   byUseCmsPort; //是否复用CMS端口,0-不复用，非0-复用，如果复用cms端口，协议类型字段无效（此时本地监听信息struAddress填本地回环地址）
        public byte   byUseThreadPool;  //0-回调报警时，使用线程池，1-回调报警时，不使用线程池，默认情况下，报警回调的时候，使用线程池
        public byte  byRes[]= new byte[29];;

        @Override
        protected List<String> getFieldOrder() {
            // TODO Auto-generated method stub
            return Arrays.asList(
                    "struAddress", 
                    "fnMsgCb", 
                    "pUserData",
                    "byProtocolType", 
                    "byUseCmsPort", 
                    "byUseThreadPool",
                    "byRes"
            );
        }
    }

    //初始化，反初始化
    boolean  NET_EALARM_Init();
    boolean  NET_EALARM_Fini();

    boolean NET_EALARM_SetLogToFile(int iLogLevel, String strLogDir, boolean bAutoDel);
    int  NET_EALARM_StartListen(NET_EHOME_ALARM_LISTEN_PARAM pAlarmListenParam);
    boolean NET_EALARM_StopListen(int iListenHandle);

    boolean NET_EALARM_SetSDKLocalCfg(int enumType, Pointer lpInBuff);
    boolean NET_EALARM_SetSDKInitCfg(int enumType, Pointer lpInBuff);
    
    boolean NET_EALARM_SetDeviceSessionKey(Pointer pDeviceKey);
}
