From f48e2e378bacffb96cb5575876a7b2f0081de0be Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期一, 08 六月 2020 15:19:01 +0800
Subject: [PATCH] update

---
 netdisk/hcnetdisk.c |  183 ++++++++++++++++++++++++++-------------------
 1 files changed, 105 insertions(+), 78 deletions(-)

diff --git a/netdisk/hcnetdisk.c b/netdisk/hcnetdisk.c
index 155ee7a..5bac513 100644
--- a/netdisk/hcnetdisk.c
+++ b/netdisk/hcnetdisk.c
@@ -1,12 +1,18 @@
 #include "netdisk.h"
 #include "hcnetdisk.h"
  
+bool HCNetdisk::envInited = false;
 
-void HCNetdisk::netdisk_init(HCNetdisk_EnvConfig &config){
-
-	if (&config != NULL && config.libpath.length() != 0) {
+/**
+ * 璁惧鍒濆鍖�
+ */
+void HCNetdisk::netdisk_init(Netdisk_EnvConfig *config){
+	if (envInited) {
+		return;
+	}
+	if (config != NULL && config->libpath.length() != 0) {
 	  NET_DVR_LOCAL_SDK_PATH struComPath = {0};
-	  sprintf(struComPath.sPath, "%s", config.libpath.c_str()); //HCNetSDKCom鏂囦欢澶规墍鍦ㄧ殑璺緞
+	  sprintf(struComPath.sPath, "%s", config->libpath.c_str()); //HCNetSDKCom鏂囦欢澶规墍鍦ㄧ殑璺緞
 	  NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_SDK_PATH, &struComPath);
 	}
 
@@ -16,7 +22,102 @@
 	//璁剧疆杩炴帴鏃堕棿涓庨噸杩炴椂闂�
 	NET_DVR_SetConnectTime(2000, 1);
 	NET_DVR_SetReconnect(10000, true);
+	envInited = true;
 }
+
+void HCNetdisk::netdisk_deinit() {
+	if (!envInited) {
+		return;
+	}
+	NET_DVR_Cleanup();
+	envInited = false;
+}
+
+
+
+
+
+
+int HCNetdisk::login(Netdisk_LoginInfo &loginInfo) {
+
+  //鐧诲綍鍙傛暟锛屽寘鎷澶囧湴鍧�銆佺櫥褰曠敤鎴枫�佸瘑鐮佺瓑
+  NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
+  struLoginInfo.bUseAsynLogin = 0; //鍚屾鐧诲綍鏂瑰紡
+  strcpy(struLoginInfo.sDeviceAddress, loginInfo.host.c_str()); //璁惧IP鍦板潃
+  struLoginInfo.wPort = loginInfo.port; //璁惧鏈嶅姟绔彛
+  strcpy(struLoginInfo.sUserName, loginInfo.username.c_str()); //璁惧鐧诲綍鐢ㄦ埛鍚�
+  strcpy(struLoginInfo.sPassword, loginInfo.password.c_str()); //璁惧鐧诲綍瀵嗙爜
+
+// 娉ㄥ唽璁惧
+  LONG lUserID;
+  NET_DVR_DEVICEINFO_V40 struDeviceInfo = {0};
+  //lUserID = 0;
+  lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfo);
+  if (lUserID < 0)
+  {
+    printf("Login error, %d\n", NET_DVR_GetLastError());
+    NET_DVR_Cleanup();
+    return -1;
+  }
+
+  printf("lUserID = %ld\n", lUserID);
+  userid = lUserID;
+  username = loginInfo.username;
+  password = loginInfo.password;
+  host = loginInfo.host;
+  port = loginInfo.port;
+
+
+  startChannel = struDeviceInfo.struDeviceV30.byStartDChan;
+  maxChannels = struDeviceInfo.struDeviceV30.byIPChanNum + struDeviceInfo.struDeviceV30.byHighDChanNum * 256;
+ 
+
+  return 0;
+}
+
+int HCNetdisk::logout() {
+	//娉ㄩ攢鐢ㄦ埛
+	NET_DVR_Logout(userid);
+	userid = -1;
+	return 0;
+}
+
+int HCNetdisk::downloadByTime(Netdisk_DownloadRequest &request, std::vector<std::string> *files) {
+	struct tm start, end;
+	char destfile[1024];
+	int i = 0;
+	start = request.start;
+
+	while(mktime(&start) < mktime(&(request.end))) {
+		if (difftime(mktime(&(request.end)), mktime(&start)) > 10 * 60) {
+			end = start;
+			end.tm_min += 10;
+			mktime(&end);
+		} else {
+			end = request.end;
+		}
+		
+		// printf("start = %s", asctime(&start));
+		// printf("end   = %s", asctime(&end));
+		sprintf(destfile, "%s/%s-%d-%ld-%d", 
+		 	request.destpath.c_str(), 
+			devicename.c_str(), 
+		 	request.channel, 
+		 	mktime(&start), 
+		 	i);
+		// printf("%s\n", destfile);
+		downloadByTime_wrapper(userid, request.channel, &start, &end, destfile);
+		if(files != NULL) {
+			files->push_back(destfile);
+		}
+		start = end;
+		i++;
+	}
+	
+	return 0;
+}
+
+HCNetdisk::~HCNetdisk() { }
 
 /**
  * @return success: 0, failture : -1
@@ -150,77 +251,3 @@
   }
 }
 
-
-
-
-int HCNetdisk::login(Netdisk_LoginInfo &loginInfo) {
-
-  //鐧诲綍鍙傛暟锛屽寘鎷澶囧湴鍧�銆佺櫥褰曠敤鎴枫�佸瘑鐮佺瓑
-  NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
-  struLoginInfo.bUseAsynLogin = 0; //鍚屾鐧诲綍鏂瑰紡
-  strcpy(struLoginInfo.sDeviceAddress, loginInfo.host.c_str()); //璁惧IP鍦板潃
-  struLoginInfo.wPort = loginInfo.port; //璁惧鏈嶅姟绔彛
-  strcpy(struLoginInfo.sUserName, loginInfo.username.c_str()); //璁惧鐧诲綍鐢ㄦ埛鍚�
-  strcpy(struLoginInfo.sPassword, loginInfo.password.c_str()); //璁惧鐧诲綍瀵嗙爜
-
-// 娉ㄥ唽璁惧
-  LONG lUserID;
-  NET_DVR_DEVICEINFO_V40 struDeviceInfo = {0};
-  //lUserID = 0;
-  lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfo);
-  if (lUserID < 0)
-  {
-    printf("Login error, %d\n", NET_DVR_GetLastError());
-    NET_DVR_Cleanup();
-    return -1;
-  }
-  // printf("lUserID = %ld\n", lUserID);
-  userid = lUserID;
-  username = loginInfo.username;
-  password = loginInfo.password;
-  host = loginInfo.host;
-  port = loginInfo.port;
-  return 0;
-
-}
-
-int HCNetdisk::logout() {
-	//娉ㄩ攢鐢ㄦ埛
-	NET_DVR_Logout(userid);
-	//閲婃斁 SDK 璧勬簮
-	NET_DVR_Cleanup();
-	userid = -1;
-	return 0;
-}
-
-int HCNetdisk::downloadByTime(Netdisk_DownloadRequest &request) {
-	struct tm start, end;
-	char destfile[1024];
-	int i = 0;
-	start = request.start;
-
-	while(mktime(&start) < mktime(&(request.end))) {
-		if (difftime(mktime(&(request.end)), mktime(&start)) > 10 * 60) {
-			end = start;
-			end.tm_min += 10;
-			mktime(&end);
-		} else {
-			end = request.end;
-		}
-		
-		// printf("start = %s", asctime(&start));
-		// printf("end   = %s", asctime(&end));
-		 sprintf(destfile, "%s/%s-%d-%ld-%d", 
-		 	request.destpath.c_str(), 
-			devicename.c_str(), 
-		 	request.channel, 
-		 	mktime(&start), 
-		 	i);
-		// printf("%s\n", destfile);
-		downloadByTime_wrapper(userid, request.channel, &start, &end, destfile);
-		start = end;
-		i++;
-	}
-	
-	return 0;
-}

--
Gitblit v1.8.0