From 5b800932ae33e571edfdc21304c2185e17f69a38 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期二, 27 四月 2021 17:45:41 +0800
Subject: [PATCH] add api Cleanup.

---
 api/bhsgo/bhome_node_test.go |    2 +-
 api/bhsgo/bhome_node.go      |    4 ++++
 src/bh_api.h                 |    2 +-
 src/bh_api.cpp               |    5 +++++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/api/bhsgo/bhome_node.go b/api/bhsgo/bhome_node.go
index b7c1eeb..6a91f34 100644
--- a/api/bhsgo/bhome_node.go
+++ b/api/bhsgo/bhome_node.go
@@ -153,6 +153,10 @@
 
 }
 
+func Cleanup() {
+	C.BHCleanup()
+}
+
 type ServerCB func(src unsafe.Pointer, proc_id *string, req *bh.MsgRequestTopic)
 type ClientCB func(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply)
 type SubDataCB func(proc_id *string, pub *bh.MsgPublish)
diff --git a/api/bhsgo/bhome_node_test.go b/api/bhsgo/bhome_node_test.go
index cc1966e..d2720a3 100644
--- a/api/bhsgo/bhome_node_test.go
+++ b/api/bhsgo/bhome_node_test.go
@@ -27,6 +27,7 @@
 	proc := bh.ProcInfo{}
 	proc.ProcId = []byte(proc_id)
 	reply := bh.MsgCommonReply{}
+	defer Cleanup()
 
 	StartWorker(ClientCallback, ServerCallback, SubDataCallback)
 
@@ -35,7 +36,6 @@
 		fmt.Println("register ok")
 	} else {
 		fmt.Println("register failed")
-		t.Log("register error")
 		return
 	}
 	r = Unregister(&proc, &reply, 1000)
diff --git a/src/bh_api.cpp b/src/bh_api.cpp
index 7e7b2e9..efa278e 100644
--- a/src/bh_api.cpp
+++ b/src/bh_api.cpp
@@ -320,6 +320,11 @@
 	free(data);
 }
 
+int BHCleanup()
+{
+	ProcNode().Stop();
+}
+
 int BHGetLastError(void **msg, int *msg_len)
 {
 	int ec = 0;
diff --git a/src/bh_api.h b/src/bh_api.h
index 5c82049..e196aa6 100644
--- a/src/bh_api.h
+++ b/src/bh_api.h
@@ -115,7 +115,7 @@
                 const void *reply,
                 const int reply_len);
 
-// int BHCleanUp();
+int BHCleanup();
 
 void BHFree(void *buf, int size);
 

--
Gitblit v1.8.0