From e3d8ac1ce502e5a5f9dc762da301b0060b641811 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期一, 07 十二月 2020 15:56:42 +0800
Subject: [PATCH] 修改适配新的版本接口

---
 bhomebus.go         |   68 ++++++++++++-----
 libcbhomebus.c      |   64 +++++++++++-----
 libcbhomebus_func.h |   30 +++++-
 libcbhomebus.h      |   33 ++++++--
 4 files changed, 139 insertions(+), 56 deletions(-)

diff --git a/bhomebus.go b/bhomebus.go
index 89b4645..97563cd 100644
--- a/bhomebus.go
+++ b/bhomebus.go
@@ -360,14 +360,14 @@
 	return int(ret)
 }
 
-// StartBus socket
-func (s *Socket) StartBus() int {
-	if libbhomebus == nil || s.socket == nil {
-		return -1
-	}
-
-	return int(C.wrap_fn_socket_start_bus(libbhomebus, s.socket))
-}
+//// StartBus socket
+//func (s *Socket) StartBus() int {
+//	if libbhomebus == nil || s.socket == nil {
+//		return -1
+//	}
+//
+//	return int(C.wrap_fn_socket_start_bus(libbhomebus, s.socket))
+//}
 
 // Pub socket
 func (s *Socket) Pub(nodes []NetNode, topic string, data []byte) int {
@@ -455,7 +455,7 @@
 }
 
 // Sub socket
-func (s *Socket) Sub(topic string, key int) int {
+func (s *Socket) Sub(topic string) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
@@ -463,46 +463,46 @@
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_sub(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key)))
+	return int(C.wrap_fn_socket_sub(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic))))
 }
 
 // SubTimeout socket
-func (s *Socket) SubTimeout(topic string, key int, milliseconds int) int {
+func (s *Socket) SubTimeout(topic string, milliseconds int) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_sub_timeout(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key), 0, C.int(milliseconds*1000000)))
+	return int(C.wrap_fn_socket_sub_timeout(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), 0, C.int(milliseconds*1000000)))
 
 }
 
 // SubNowait socket
-func (s *Socket) SubNowait(topic string, key int) int {
+func (s *Socket) SubNowait(topic string) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_sub_nowait(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key)))
+	return int(C.wrap_fn_socket_sub_nowait(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic))))
 
 }
 
 // Desub socket
-func (s *Socket) Desub(topic string, key int) int {
+func (s *Socket) Desub(topic string) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_desub(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key)))
+	return int(C.wrap_fn_socket_desub(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic))))
 }
 
 // DesubTimeout socket
-func (s *Socket) DesubTimeout(topic string, key int, milliseconds int) int {
+func (s *Socket) DesubTimeout(topic string, milliseconds int) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
@@ -510,18 +510,18 @@
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_desub_timeout(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key), 0, C.int(milliseconds*1000000)))
+	return int(C.wrap_fn_socket_desub_timeout(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), 0, C.int(milliseconds*1000000)))
 }
 
 // DesubNowait socket
-func (s *Socket) DesubNowait(topic string, key int) int {
+func (s *Socket) DesubNowait(topic string) int {
 	if libbhomebus == nil || s.socket == nil {
 		return -1
 	}
 	ctopic := C.CString(topic)
 	defer C.free(unsafe.Pointer(ctopic))
 
-	return int(C.wrap_fn_socket_desub_nowait(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key)))
+	return int(C.wrap_fn_socket_desub_nowait(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic))))
 }
 
 // Getkey socket
@@ -610,3 +610,31 @@
 
 	return int(C.wrap_fn_server_socket_start(libbhomebus, s.socket))
 }
+
+// ServerOpen bus server
+func BusServerOpen() *Socket {
+	if libbhomebus == nil {
+		return nil
+	}
+
+	sock := C.wrap_fn_bus_server_socket_open(libbhomebus)
+	return &Socket{sock}
+}
+
+// Close close
+func (s *Socket) BusClose() {
+	if libbhomebus == nil {
+		return
+	}
+
+	C.wrap_fn_bus_server_socket_close(libbhomebus, s.socket)
+}
+
+// Start start
+func (s *Socket) BusStart() int {
+	if libbhomebus == nil {
+		return -1
+	}
+
+	return int(C.wrap_fn_bus_server_socket_start(libbhomebus, s.socket))
+}
diff --git a/libcbhomebus.c b/libcbhomebus.c
index 9046a11..da3750b 100644
--- a/libcbhomebus.c
+++ b/libcbhomebus.c
@@ -197,14 +197,14 @@
     return fn_socket_sendandrecv_nowait(_socket, (net_node_t*)node_arr, arrlen, send_buf, send_size, (net_mod_recv_msg_t**)recv_arr, recv_arr_size);
 }
 
-int  wrap_fn_socket_start_bus(hbhomebus lib, void * _socket)
-{
-    if(!fn_socket_start_bus){
-        fn_socket_start_bus = (tfn_net_mod_socket_start_bus)dlsym(lib,l_net_mod_socket_start_bus);
-        check_with_ret(fn_socket_start_bus, lib, -1);
-    }
-    return fn_socket_start_bus(_socket);
-}
+//int  wrap_fn_socket_start_bus(hbhomebus lib, void * _socket)
+//{
+//    if(!fn_socket_start_bus){
+//        fn_socket_start_bus = (tfn_net_mod_socket_start_bus)dlsym(lib,l_net_mod_socket_start_bus);
+//        check_with_ret(fn_socket_start_bus, lib, -1);
+//    }
+//    return fn_socket_start_bus(_socket);
+//}
 
 int wrap_fn_socket_pub(hbhomebus lib, void *_socket, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size)
 {
@@ -233,58 +233,58 @@
     return fn_socket_pub_nowait(_socket, (net_node_t*)node_arr, node_arr_len, topic, topic_size, content, content_size);
 }
 
-int  wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size, int key)
+int  wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size)
 {
     if(!fn_socket_sub){
         fn_socket_sub = (tfn_net_mod_socket_sub)dlsym(lib,l_net_mod_socket_sub);
         check_with_ret(fn_socket_sub, lib, -1);
     }
-    return fn_socket_sub(_socket, topic, size, key);
+    return fn_socket_sub(_socket, topic, size);
 }
 
-int  wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec)
+int  wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec)
 {
     if(!fn_socket_sub_timeout){
         fn_socket_sub_timeout = (tfn_net_mod_socket_sub_timeout)dlsym(lib,l_net_mod_socket_sub_timeout);
         check_with_ret(fn_socket_sub_timeout, lib, -1);
     }
-    return fn_socket_sub_timeout(_socket, topic, size, key, sec, nsec);
+    return fn_socket_sub_timeout(_socket, topic, size, sec, nsec);
 }
 
-int  wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key)
+int  wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size)
 {
     if(!fn_socket_sub_nowait){
         fn_socket_sub_nowait = (tfn_net_mod_socket_sub_nowait)dlsym(lib,l_net_mod_socket_sub_nowait);
         check_with_ret(fn_socket_sub_nowait, lib, -1);
     }
-    return fn_socket_sub_nowait(_socket, topic, size, key);
+    return fn_socket_sub_nowait(_socket, topic, size);
 }
 
-int  wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size, int key)
+int  wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size)
 {
     if(!fn_socket_desub){
         fn_socket_desub = (tfn_net_mod_socket_desub)dlsym(lib,l_net_mod_socket_desub);
         check_with_ret(fn_socket_desub, lib, -1);
     }
-    return fn_socket_desub(_socket, topic, size, key);
+    return fn_socket_desub(_socket, topic, size);
 }
 
-int  wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec)
+int  wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec)
 {
     if(!fn_socket_desub_timeout){
         fn_socket_desub_timeout = (tfn_net_mod_socket_desub_timeout)dlsym(lib,l_net_mod_socket_desub_timeout);
         check_with_ret(fn_socket_desub_timeout, lib, -1);
     }
-    return fn_socket_desub_timeout(_socket, topic, size, key, sec, nsec);
+    return fn_socket_desub_timeout(_socket, topic, size, sec, nsec);
 }
 
-int  wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key)
+int  wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size)
 {
     if(!fn_socket_desub_nowait){
         fn_socket_desub_nowait = (tfn_net_mod_socket_sub_nowait)dlsym(lib,l_net_mod_socket_sub_nowait);
         check_with_ret(fn_socket_desub_nowait, lib, -1);
     }
-    return fn_socket_desub_nowait(_socket, topic, size, key);
+    return fn_socket_desub_nowait(_socket, topic, size);
 }
 
 int wrap_fn_socket_get_key(hbhomebus lib, void * _socket)
@@ -353,3 +353,27 @@
     }
     return fn_server_socket_start(_socket);
 }
+
+void *wrap_fn_bus_server_socket_open(hbhomebus lib){
+    if (!fn_bus_server_socket_open){
+        fn_bus_server_socket_open = (tfn_bus_server_socket_wrapper_open)dlsym(lib, l_bus_server_socket_wrapper_open);
+        check_with_ret(fn_bus_server_socket_open, lib, NULL);
+    }
+    return fn_bus_server_socket_open();
+}
+
+void wrap_fn_bus_server_socket_close(hbhomebus lib, void* _socket){
+    if (!fn_bus_server_socket_close){
+        fn_bus_server_socket_close = (tfn_bus_server_socket_wrapper_close)dlsym(lib, l_bus_server_socket_wrapper_close);
+        check_only(fn_bus_server_socket_close, lib);
+    }
+    fn_bus_server_socket_close(_socket);
+}
+
+int wrap_fn_bus_server_socket_start(hbhomebus lib, void* _socket){
+    if (!fn_bus_server_socket_start){
+        fn_bus_server_socket_start = (tfn_bus_server_socket_wrapper_start_bus)dlsym(lib, l_bus_server_socket_wrapper_start_bus);
+        check_with_ret(fn_bus_server_socket_start, lib, -1);
+    }
+    return fn_bus_server_socket_start(_socket);
+}
diff --git a/libcbhomebus.h b/libcbhomebus.h
index d637d63..0ffdf89 100644
--- a/libcbhomebus.h
+++ b/libcbhomebus.h
@@ -28,7 +28,7 @@
 static tfn_net_mod_socket_sendandrecv           fn_socket_sendandrecv = NULL;
 static tfn_net_mod_socket_sendandrecv_timeout   fn_socket_sendandrecv_timeout = NULL;
 static tfn_net_mod_socket_sendandrecv_nowait    fn_socket_sendandrecv_nowait = NULL;
-static tfn_net_mod_socket_start_bus             fn_socket_start_bus = NULL;
+//static tfn_net_mod_socket_start_bus             fn_socket_start_bus = NULL;
 static tfn_net_mod_socket_pub                   fn_socket_pub = NULL;
 static tfn_net_mod_socket_pub_timeout           fn_socket_pub_timeout = NULL;
 static tfn_net_mod_socket_pub_nowait            fn_socket_pub_nowait = NULL;
@@ -47,6 +47,11 @@
 static tfn_net_mod_server_socket_open           fn_server_socket_open = NULL;
 static tfn_net_mod_server_socket_close          fn_server_socket_close = NULL;
 static tfn_net_mod_server_socket_start          fn_server_socket_start = NULL;
+
+// bus
+static tfn_bus_server_socket_wrapper_open           fn_bus_server_socket_open = NULL;
+static tfn_bus_server_socket_wrapper_close          fn_bus_server_socket_close = NULL;
+static tfn_bus_server_socket_wrapper_start_bus      fn_bus_server_socket_start = NULL;
 //////////////////////////////////////////////////////////////////////
 
 // labels
@@ -70,7 +75,7 @@
 const static char l_net_mod_socket_sendandrecv[] = "net_mod_socket_sendandrecv";
 const static char l_net_mod_socket_sendandrecv_timeout[] = "net_mod_socket_sendandrecv_timeout";
 const static char l_net_mod_socket_sendandrecv_nowait[] = "net_mod_socket_sendandrecv_nowait";
-const static char l_net_mod_socket_start_bus[] = "net_mod_socket_start_bus";
+//const static char l_net_mod_socket_start_bus[] = "net_mod_socket_start_bus";
 const static char l_net_mod_socket_pub[] = "net_mod_socket_pub";
 const static char l_net_mod_socket_pub_timeout[] = "net_mod_socket_pub_timeout";
 const static char l_net_mod_socket_pub_nowait[] = "net_mod_socket_pub_nowait";
@@ -89,6 +94,11 @@
 const static char l_net_mod_server_socket_open[] = "net_mod_server_socket_open";
 const static char l_net_mod_server_socket_close[] = "net_mod_server_socket_close";
 const static char l_net_mod_server_socket_start[] = "net_mod_server_socket_start";
+
+// bus
+const static char l_bus_server_socket_wrapper_open[] = "bus_server_socket_wrapper_open";
+const static char l_bus_server_socket_wrapper_close[] = "bus_server_socket_wrapper_close";
+const static char l_bus_server_socket_wrapper_start_bus[] = "bus_server_socket_wrapper_start_bus";
 //////////////////////////////////////////////////////////////////////
 
 // dlopen dynamic library
@@ -119,16 +129,16 @@
     void ** recv_arr, int *recv_arr_size, int timeout);
 int wrap_fn_socket_sendandrecv_nowait(hbhomebus lib, void *_sockt, void *node_arr, int arrlen, void *send_buf, int send_size,
     void ** recv_arr, int *recv_arr_size) ;
-int  wrap_fn_socket_start_bus(hbhomebus lib, void * _socket);
+//int  wrap_fn_socket_start_bus(hbhomebus lib, void * _socket);
 int wrap_fn_socket_pub(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size);
 int wrap_fn_socket_pub_timeout(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout);
 int wrap_fn_socket_pub_nowait(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size);
-int  wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size, int key);
-int  wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec);
-int  wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key);
-int  wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size, int key);
-int  wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec);
-int  wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key);
+int  wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size);
+int  wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec);
+int  wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size);
+int  wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size);
+int  wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec);
+int  wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size);
 int wrap_fn_socket_get_key(hbhomebus lib, void * _socket) ;
 void  wrap_fn_socket_free_recv_msg_arr(hbhomebus lib, void * arr, int size);
 void wrap_fn_socket_free(hbhomebus lib, void *buf) ;
@@ -140,6 +150,11 @@
 void wrap_fn_server_socket_close(hbhomebus lib, void* _socket);
 int wrap_fn_server_socket_start(hbhomebus lib, void* _socket);
 
+//bus
+void *wrap_fn_bus_server_socket_open(hbhomebus lib);
+void wrap_fn_bus_server_socket_close(hbhomebus lib, void* _socket);
+int wrap_fn_bus_server_socket_start(hbhomebus lib, void* _socket);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libcbhomebus_func.h b/libcbhomebus_func.h
index 83d663d..0479a28 100644
--- a/libcbhomebus_func.h
+++ b/libcbhomebus_func.h
@@ -127,7 +127,7 @@
  *
  * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
 */
-typedef int  (*tfn_net_mod_socket_start_bus)(void * _socket);
+//typedef int  (*tfn_net_mod_socket_start_bus)(void * _socket);
 
 
  /**
@@ -147,10 +147,10 @@
  * @size 涓婚闀垮害
  * @key 鎬荤嚎绔彛
  */
-typedef int  (*tfn_net_mod_socket_sub)(void * _socket, void *topic, int size, int key);
+typedef int  (*tfn_net_mod_socket_sub)(void * _socket, void *topic, int size);
 // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
-typedef int  (*tfn_net_mod_socket_sub_timeout)(void * _socket, void *topic, int size, int key, int sec, int nsec);
-typedef int  (*tfn_net_mod_socket_sub_nowait)(void * _socket, void *topic, int size, int key);
+typedef int  (*tfn_net_mod_socket_sub_timeout)(void * _socket, void *topic, int size, int sec, int nsec);
+typedef int  (*tfn_net_mod_socket_sub_nowait)(void * _socket, void *topic, int size);
 
 
 /**
@@ -159,10 +159,10 @@
  * @size 涓婚闀垮害
  * @key 鎬荤嚎绔彛
  */
-typedef int  (*tfn_net_mod_socket_desub)(void * _socket, void *topic, int size, int key);
+typedef int  (*tfn_net_mod_socket_desub)(void * _socket, void *topic, int size);
 // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
-typedef int  (*tfn_net_mod_socket_desub_timeout)(void * _socket, void *topic, int size, int key, int sec, int nsec);
-typedef int  (*tfn_net_mod_socket_desub_nowait)(void * _socket, void *topic, int size, int key);
+typedef int  (*tfn_net_mod_socket_desub_timeout)(void * _socket, void *topic, int size, int sec, int nsec);
+typedef int  (*tfn_net_mod_socket_desub_nowait)(void * _socket, void *topic, int size);
 
 
 /**
@@ -190,6 +190,7 @@
  */
 typedef int(*tfn_shm_mod_socket_remove_keys) (int*, int);
 
+
 /**
  * 鍒涘缓
  */
@@ -205,6 +206,21 @@
  */
 typedef int (*tfn_net_mod_server_socket_start)(void *_sockt);
 
+/**
+ * bus鍒涘缓
+ */
+typedef void *(*tfn_bus_server_socket_wrapper_open)() ;
+
+/**
+ * bus鍏抽棴
+ */
+typedef void (*tfn_bus_server_socket_wrapper_close)(void *_sockt) ;
+
+/**
+ * bus鍚姩
+ */
+typedef int (*tfn_bus_server_socket_wrapper_start_bus)(void *_sockt);
+
 #ifdef __cplusplus
 }
 #endif

--
Gitblit v1.8.0