From e25f3e440ed00d597a9802df68adedadb629d814 Mon Sep 17 00:00:00 2001
From: cheliequan <liequanche@126.com>
Date: 星期五, 13 一月 2023 12:10:06 +0800
Subject: [PATCH] 1.增加获取系统授权接口 2.完善相机相关函数实现 3.优化内存释放

---
 versionctrlapi.cpp |   33 +++++++++++
 dbapi.h            |    2 
 main.cpp           |    4 +
 util.cpp           |   55 +++++++++++++++++-
 util.h             |    2 
 camera.cpp         |   61 +++++++++++++++++++-
 CMakeLists.txt     |    1 
 7 files changed, 148 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5194eb2..7b6f393 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,7 @@
     )
 
 set(src
+    ${CMAKE_SOURCE_DIR}/versionctrlapi.cpp
     ${CMAKE_SOURCE_DIR}/camera.cpp
     ${CMAKE_SOURCE_DIR}/polygon.cpp
     ${CMAKE_SOURCE_DIR}/rule.cpp
diff --git a/camera.cpp b/camera.cpp
index 127ed6e..771ebbb 100644
--- a/camera.cpp
+++ b/camera.cpp
@@ -1,19 +1,72 @@
+/******************************************************************************
+
+                  鐗堟潈鎵�鏈� (C), 2001-2011, 鍖椾含璐濇�濈鎶�鏈湁闄愬叕鍙�
+
+ ******************************************************************************
+  鏂� 浠� 鍚�   : camera.cpp
+  鐗� 鏈� 鍙�   : 鍒濈
+  浣�    鑰�   : cheliequan
+  鐢熸垚鏃ユ湡   : 2023骞�1鏈�13鏃�
+  鏈�杩戜慨鏀�   :
+  鍔熻兘鎻忚堪   : 鑾峰彇鐩告満鐩稿叧淇℃伅
+  鍑芥暟鍒楄〃   :
+              dbapi_get_cameras_by_runtype
+              dbapi_get_gb28181_cameras_by_runtype
+  淇敼鍘嗗彶   :
+  1.鏃�    鏈�   : 2023骞�1鏈�13鏃�
+    浣�    鑰�   : cheliequan
+    淇敼鍐呭   : 鍒涘缓鏂囦欢
+
+******************************************************************************/
+
+/*----------------------------------------------*
+ * 鍖呭惈澶存枃浠�                                   *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 澶栭儴鍙橀噺璇存槑                                 *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 澶栭儴鍑芥暟鍘熷瀷璇存槑                             *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 鍐呴儴鍑芥暟鍘熷瀷璇存槑                             *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 鍏ㄥ眬鍙橀噺                                     *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 妯″潡绾у彉閲�                                   *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 甯搁噺瀹氫箟                                     *
+ *----------------------------------------------*/
+
+/*----------------------------------------------*
+ * 瀹忓畾涔�                                       *
+ *----------------------------------------------*/
+
 #include "dbapi.h"
 #include "util.h"
-
 using namespace protomsg;
-
 // 鍔爂et鍙傛暟 runType 1: 瀹炴椂 0 杞
 bool dbapi_get_cameras_by_runtype(void *handle, std::vector<protomsg::Camera> & list) {
     const char *topic = DATA_URL_PREFIX("/camera/getCamerasByRunType");
 
-    return true;
+	bool ret = bus_dbapi_get_list(handle, topic, list);
+    return ret;
 }
 
 // 鍔爂et鍙傛暟 runType 1: 瀹炴椂 0 杞
 bool dbapi_get_gb28181_cameras_by_runtype(void *handle, std::vector<protomsg::Camera> & list) {
     const char *topic = DATA_URL_PREFIX("/gb28181/camera/getCamerasByRunType");
 
-    return true;
+	bool ret = bus_dbapi_get_list(handle, topic, list);
+    return ret;
 }
 
diff --git a/dbapi.h b/dbapi.h
index 00378d7..adcdbc4 100644
--- a/dbapi.h
+++ b/dbapi.h
@@ -23,5 +23,5 @@
 bool dbapi_get_doing_stacks(void *handle, std::vector<protomsg::FileStack> & list);
 bool dbapi_get_polygons(void *handle, std::vector<protomsg::CameraPolygon> & list);
 bool dbapi_get_polygon_relations(void *handle, std::vector<protomsg::CameraPolygonRelation> & list);
-
+bool dbapi_get_server_get_is_sys_expired(void *handle);
 #endif
\ No newline at end of file
diff --git a/main.cpp b/main.cpp
index e63170f..58e57bc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -52,5 +52,9 @@
         printf("CameraTimerule:\n");
     }
 
+	//绯荤粺鎺堟潈淇℃伅
+	
+	 printf("isExpired:%d\n", dbapi_get_server_get_is_sys_expired(handle));
+
     return 0;
 }
diff --git a/util.cpp b/util.cpp
index 9eedab4..d7f1e5f 100644
--- a/util.cpp
+++ b/util.cpp
@@ -145,12 +145,14 @@
 	if (bus_client_request(handle, reqmsg, pptr_repmsg)) {
 		printf("======>> bus_client_reqest [%s] get [%s]\n", topic, (*pptr_repmsg)->data);
 	} else {
+        free(reqData);		
 		return false;
 	}
 
 	len = strlen((*pptr_repmsg)->data) + 1;
 	
-    free(reqData);	
+    free(reqData);
+	return true;
 }
 	
 
@@ -158,6 +160,7 @@
 	yyjson_type type = YYJSON_TYPE_OBJ;
 	crepmsg *repmsg = NULL;
     size_t len = 0;
+	bool bRet = false;
 	
 	bus_dbapi_get_topic_data(handle, topic, &repmsg, len);
 
@@ -171,19 +174,63 @@
     }
 
 	std::string jsonString = msgdata;
-	if (json_to_proto(jsonString, message)) 
+	bRet = json_to_proto(jsonString, message);
+	if (bRet) 
 	{
 		printf("======>> json_to_proto done\n");
 	} 
 	else
 	{
 		printf("======>> json_to_proto fail\n");
-		return false;
 	}  
 
     free(msgdata);
 	free_reply_msg(repmsg);
 
-    return true;
+    return bRet;
 }
 
+/*****************************************************************************
+ 鍑� 鏁� 鍚�  : bus_dbapi_get_str
+ 鍔熻兘鎻忚堪  : 鑾峰彇璁㈤槄涓婚娑堟伅瀛楃涓诧紝杩斿洖鐨勫唴瀛樿皟鐢ㄨ�呴渶瑕佹墜宸ヨ皟鐢╢ree鍑芥暟閲婃斁
+ 杈撳叆鍙傛暟  : void *handle       
+             const char* topic  
+             char **pptr_str    
+ 杈撳嚭鍙傛暟  : 鏃�
+ 杩� 鍥� 鍊�  : 
+ 璋冪敤鍑芥暟  : 
+ 琚皟鍑芥暟  : 
+ 
+ 淇敼鍘嗗彶      :
+  1.鏃�    鏈�   : 2023骞�1鏈�13鏃�
+    浣�    鑰�   : cheliequan
+    淇敼鍐呭   : 鏂扮敓鎴愬嚱鏁�
+
+*****************************************************************************/
+bool bus_dbapi_get_str(void *handle, const char* topic, char **pptr_str) {
+	yyjson_type type = YYJSON_TYPE_OBJ;
+	crepmsg *repmsg = NULL;
+    size_t len = 0;
+	int iRet = 0;
+	bool bRet = false;
+	
+	bus_dbapi_get_topic_data(handle, topic, &repmsg, len);
+
+    int msglen = strlen(repmsg->data);
+    char* msgdata = (char *)malloc(msglen);
+    memset(msgdata, 0 , msglen);
+
+    iRet = bus_dbapi_get_json_data((const char *)repmsg->data, &msgdata, &type);
+    if(0 == iRet)
+    {
+        printf("======>> protomsg: %s\n", msgdata); 
+		bRet = true;
+    }	
+
+    *pptr_str = msgdata; 
+
+    free(msgdata);
+	free_reply_msg(repmsg);
+
+    return bRet;
+}
diff --git a/util.h b/util.h
index 4521fb7..8e38043 100644
--- a/util.h
+++ b/util.h
@@ -24,13 +24,13 @@
 using namespace std;
 using google::protobuf::util::JsonStringToMessage;
 
-
 bool json_to_proto(const std::string &json, google::protobuf::Message& message);
 bool proto_to_json(const google::protobuf::Message& message, std::string& json);
 char *make_get_request(const char *topic);
 bool bus_dbapi_get(void *handle, const char* topic, google::protobuf::Message& message);
 bool bus_dbapi_get_topic_data(void *handle, const char* topic, crepmsg **pptr_repmsg, size_t len);
 extern "C" int bus_dbapi_get_json_data(const char * json, char ** pptr_data, uint8_t *ptr_type);
+bool bus_dbapi_get_str(void *handle, const char* topic, char **pptr_str);
 template <class T>  bool bus_dbapi_get_list (void *handle, const char* topic, T & list)
 
 {
diff --git a/versionctrlapi.cpp b/versionctrlapi.cpp
new file mode 100644
index 0000000..1bc6fd7
--- /dev/null
+++ b/versionctrlapi.cpp
@@ -0,0 +1,33 @@
+#include "dbapi.h"
+#include "util.h"
+
+using namespace protomsg;
+
+//鑾峰彇鏈嶅姟鍣ㄦ湰鏈洪厤缃俊鎭�
+bool dbapi_get_server_get_sn(void *handle, char * reply_msg){
+	const char *topic = DATA_URL_PREFIX("/version/snBus");
+	return bus_dbapi_get_str(handle, topic, &reply_msg);
+}
+
+bool dbapi_get_server_get_is_sys_expired(void *handle)  {
+	char * reply_msg = NULL;
+    bool is_expired = false;
+	bool ret = false;
+    bool  expire_val = false;	
+
+	ret = dbapi_get_server_get_sn(handle, reply_msg);
+	if(ret && reply_msg != NULL)
+	{
+		// Read JSON and get root
+		yyjson_doc *doc = yyjson_read(reply_msg, strlen(reply_msg), 0);
+		yyjson_val *root = yyjson_doc_get_root(doc);
+
+        yyjson_val *data = yyjson_obj_get(root, "expire");
+        expire_val = yyjson_get_bool(data);
+        printf("expire: %d\n", expire_val);	
+		yyjson_doc_free(doc);
+	}
+
+    free(reply_msg);
+	return expire_val;
+}

--
Gitblit v1.8.0