package com.netsdk.demo.customize.queryFaceDetection;
|
|
import com.netsdk.demo.customize.analyseTaskDemo.AnalyseTaskUtils;
|
import com.netsdk.lib.NetSDKLib;
|
import com.netsdk.lib.callback.impl.DefaultDisconnectCallback;
|
import com.netsdk.lib.callback.impl.DefaultHaveReconnectCallBack;
|
|
import java.io.File;
|
|
/**
|
* @author : 47040
|
* @since : Created in 2020/9/8 16:30
|
*/
|
public class QueryFaceDetectionUtils {
|
|
////////////////// SDK 初始化/清理资源 /////////////////////
|
//////////////////////////////////////////////////////////
|
|
// The constant net sdk
|
public static final NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
|
|
// The constant config sdk.
|
public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE;
|
|
private static boolean bInit = false; // 判断是否初始化
|
private static boolean bLogOpen = false; // 判断log是否打开
|
|
// 回调函数需要是静态的,防止被系统回收
|
private static NetSDKLib.fDisConnect disConnectCB = DefaultDisconnectCallback.getINSTANCE(); // 断线回调
|
private static NetSDKLib.fHaveReConnect haveReConnectCB = DefaultHaveReconnectCallBack.getINSTANCE(); // 重连回调
|
|
/**
|
* Init boolean. sdk 初始化
|
*
|
* @return the boolean
|
*/
|
public static boolean Init() {
|
bInit = netsdk.CLIENT_Init(disConnectCB, null);
|
if (!bInit) {
|
System.out.println("Initialize SDK failed");
|
return false;
|
}
|
|
QueryFaceDetectionUtils.enableLog(); // 配置日志
|
|
// 设置断线重连回调接口, 此操作为可选操作,但建议用户进行设置
|
netsdk.CLIENT_SetAutoReconnect(haveReConnectCB, null);
|
|
//设置登录超时时间和尝试次数,可选
|
int waitTime = 3000; //登录请求响应超时时间设置为3S
|
int tryTimes = 1; //登录时尝试建立链接 1 次
|
netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
|
// 设置更多网络参数, NET_PARAM 的nWaittime , nConnectTryNum 成员与 CLIENT_SetConnectTime
|
// 接口设置的登录设备超时时间和尝试次数意义相同,可选
|
NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
|
netParam.nConnectTime = 10000; // 登录时尝试建立链接的超时时间
|
netParam.nGetConnInfoTime = 3000; // 设置子连接的超时时间
|
netsdk.CLIENT_SetNetworkParam(netParam);
|
return true;
|
}
|
|
/**
|
* 打开 sdk log
|
*/
|
private static void enableLog() {
|
NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO();
|
File path = new File("sdklog/");
|
if (!path.exists()) path.mkdir();
|
|
// 这里的log保存地址依据实际情况自己调整
|
String logPath = path.getAbsoluteFile().getParent() + "\\sdklog\\" + "sdklog" + AnalyseTaskUtils.getDate() + ".log";
|
setLog.nPrintStrategy = 0;
|
setLog.bSetFilePath = 1;
|
System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length);
|
System.out.println(logPath);
|
setLog.bSetPrintStrategy = 1;
|
bLogOpen = netsdk.CLIENT_LogOpen(setLog);
|
if (!bLogOpen) System.err.println("Failed to open NetSDK log");
|
}
|
|
/**
|
* Cleanup. 清除 sdk 环境
|
*/
|
public static void cleanup() {
|
if (bLogOpen) {
|
netsdk.CLIENT_LogClose();
|
}
|
if (bInit) {
|
netsdk.CLIENT_Cleanup();
|
}
|
}
|
|
/**
|
* 清理并退出
|
*/
|
public static void cleanAndExit() {
|
netsdk.CLIENT_Cleanup();
|
System.exit(0);
|
}
|
|
}
|