|
|
@@ -1,6 +1,7 @@ |
|
|
|
package com.iformall.haikang.alarm; |
|
|
|
|
|
|
|
|
|
|
|
import com.iformall.file.haikang.HaiKangNetSdkConfig; |
|
|
|
import com.iformall.haikang.alarm.common.HCNetSDK; |
|
|
|
import com.iformall.haikang.alarm.common.osSelect; |
|
|
|
import com.sun.jna.Native; |
|
|
@@ -13,12 +14,16 @@ import javax.annotation.PreDestroy; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class Alarm { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
HaiKangNetSdkConfig hkConfig; |
|
|
|
|
|
|
|
private HCNetSDK hCNetSDK = null; |
|
|
|
private int lUserID = -1;//用户句柄 实现对设备登录 |
|
|
@@ -35,14 +40,17 @@ public class Alarm { |
|
|
|
private boolean createSDKInstance() { |
|
|
|
if (hCNetSDK == null) { |
|
|
|
synchronized (HCNetSDK.class) { |
|
|
|
String strDllPath = ""; |
|
|
|
String strDllPath = hkConfig.getLibdir(); |
|
|
|
try { |
|
|
|
if (osSelect.isWindows()) |
|
|
|
if (osSelect.isWindows()) { |
|
|
|
//win系统加载库路径 |
|
|
|
strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll"; |
|
|
|
else if (osSelect.isLinux()) |
|
|
|
//strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll"; |
|
|
|
strDllPath = strDllPath + "\\lib\\HCNetSDK.dll"; |
|
|
|
}else if (osSelect.isLinux()) { |
|
|
|
//Linux系统加载库路径 |
|
|
|
strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so"; |
|
|
|
//strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so"; |
|
|
|
strDllPath = strDllPath + "/lib/libhcnetsdk.so"; |
|
|
|
} |
|
|
|
hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class); |
|
|
|
} catch (Exception ex) { |
|
|
|
logger.error("createSDKInstance loadLibrary: " + strDllPath + " Error: " + ex.getMessage(),ex); |
|
|
@@ -110,7 +118,7 @@ public class Alarm { |
|
|
|
public void onDestory() { |
|
|
|
//释放SDK |
|
|
|
if (hCNetSDK != null) { |
|
|
|
stopListen(); |
|
|
|
//stopListen(); |
|
|
|
hCNetSDK.NET_DVR_Cleanup(); |
|
|
|
} |
|
|
|
} |
|
|
@@ -119,7 +127,7 @@ public class Alarm { |
|
|
|
* 开启监听 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public void listen() { |
|
|
|
public int listen() { |
|
|
|
if (hCNetSDK == null) { |
|
|
|
initSdk(); |
|
|
|
} |
|
|
@@ -127,6 +135,8 @@ public class Alarm { |
|
|
|
//lUserID=loginDevice( "192.168.2.200", (short) 8000, "admin", "wushikeji001"); //登录设备 |
|
|
|
|
|
|
|
lListenHandle = startListen("192.168.2.103",(short) 7201); |
|
|
|
return lListenHandle; |
|
|
|
|
|
|
|
//设备注销 |
|
|
|
//logoutDev(lUserID); |
|
|
|
} |
|
|
@@ -135,9 +145,8 @@ public class Alarm { |
|
|
|
* 停止监听 |
|
|
|
* @param Handle 监听句柄 |
|
|
|
*/ |
|
|
|
public void stopListen() |
|
|
|
public void stopListen(int Handle) |
|
|
|
{ |
|
|
|
int Handle = lListenHandle; |
|
|
|
if (Handle <= -1) |
|
|
|
{ |
|
|
|
logger.info("监听未开启"); |
|
|
|