From e3c307aa858f8f81d4cb0a5cfe4271cdc5d984be Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期一, 08 二月 2021 10:40:58 +0800 Subject: [PATCH] add remove keys and remove keys exclude --- bhomebus.go | 66 ++++++++++++--------- libcbhomebus.c | 32 +++++----- libcbhomebus_func.h | 12 +-- libcbhomebus.h | 13 ++-- 4 files changed, 65 insertions(+), 58 deletions(-) diff --git a/bhomebus.go b/bhomebus.go index 98f334e..1e3aec3 100644 --- a/bhomebus.go +++ b/bhomebus.go @@ -185,6 +185,44 @@ } } +// Removekeys socket +func (s *Socket) Removekeys(keys []int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + ckey := C.create_int_array(C.int(len(keys))) + defer C.release_int_array(ckey) + if ckey == nil { + return -2 + } + + for i, v := range keys { + C.set_1_int(ckey, C.int(i), C.int(v)) + } + + return int(C.wrap_fn_shm_remove_keys(libbhomebus, ckey, C.int(len(keys)))) +} + +// RemoveOtherkeys socket +func (s *Socket) RemoveOtherkeys(keys []int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + ckey := C.create_int_array(C.int(len(keys))) + defer C.release_int_array(ckey) + if ckey == nil { + return -2 + } + + for i, v := range keys { + C.set_1_int(ckey, C.int(i), C.int(v)) + } + + return int(C.wrap_fn_shm_remove_keys_exclude(libbhomebus, ckey, C.int(len(keys)))) +} + // Socket of bhomebus type Socket struct { socket unsafe.Pointer @@ -630,34 +668,6 @@ return -1 } return 0 -} - -// Removekey socket -func (s *Socket) Removekey(key int) int { - if libbhomebus == nil || s.socket == nil { - return -1 - } - - return int(C.wrap_fn_socket_remove_key(libbhomebus, C.int(key))) -} - -// Removekeys socket -func (s *Socket) Removekeys(keys []int) int { - if libbhomebus == nil || s.socket == nil { - return -1 - } - - ckey := C.create_int_array(C.int(len(keys))) - defer C.release_int_array(ckey) - if ckey == nil { - return -2 - } - - for i, v := range keys { - C.set_1_int(ckey, C.int(i), C.int(v)) - } - - return int(C.wrap_fn_socket_remove_keys(libbhomebus, ckey, C.int(len(keys)))) } // ServerSocket tcp diff --git a/libcbhomebus.c b/libcbhomebus.c index 3831923..7d3796f 100644 --- a/libcbhomebus.c +++ b/libcbhomebus.c @@ -73,6 +73,22 @@ fn_shm_destroy(); } +int wrap_fn_shm_remove_keys(hbhomebus lib, void *keys, int length){ + if (!fn_shm_remove_keys){ + fn_shm_remove_keys = (tfn_shm_remove_keys)dlsym(lib, l_shm_remove_keys); + check_with_ret(fn_shm_remove_keys, lib, -1); + } + return fn_shm_remove_keys((int*)keys, length); +} + +int wrap_fn_shm_remove_keys_exclude(hbhomebus lib, void *keys, int length){ + if (!fn_shm_remove_keys_exclude){ + fn_shm_remove_keys_exclude = (tfn_shm_remove_keys_exclude)dlsym(lib, l_shm_remove_keys_exclude); + check_with_ret(fn_shm_remove_keys_exclude, lib, -1); + } + return fn_shm_remove_keys_exclude((int*)keys, length); +} + //////////////////////////////////////////// // dgram socket mode //////////////////////////////////////////// @@ -337,22 +353,6 @@ check_only(fn_socket_free, lib); } return fn_socket_free(buf); -} - -int wrap_fn_socket_remove_key(hbhomebus lib, int key){ - if (!fn_socket_remove_key){ - fn_socket_remove_key = (tfn_shm_mod_socket_remove_key)dlsym(lib, l_shm_mod_socket_remove_key); - check_with_ret(fn_socket_remove_key, lib, -1); - } - return fn_socket_remove_key(key); -} - -int wrap_fn_socket_remove_keys(hbhomebus lib, void *keys, int length){ - if (!fn_socket_remove_keys){ - fn_socket_remove_keys = (tfn_shm_mod_socket_remove_keys)dlsym(lib, l_shm_mod_socket_remove_keys); - check_with_ret(fn_socket_remove_keys, lib, -1); - } - return fn_socket_remove_keys((int*)keys, length); } void *wrap_fn_server_socket_open(hbhomebus lib, int port){ diff --git a/libcbhomebus.h b/libcbhomebus.h index 44f8bb2..da0fd2c 100644 --- a/libcbhomebus.h +++ b/libcbhomebus.h @@ -13,6 +13,8 @@ static tfn_shm_init fn_shm_init = NULL; static tfn_shm_alloc_key fn_shm_alloc_key = NULL; static tfn_shm_destroy fn_shm_destroy = NULL; +static tfn_shm_remove_keys fn_shm_remove_keys = NULL; +static tfn_shm_remove_keys_exclude fn_shm_remove_keys_exclude = NULL; // net mode socket static tfn_net_mod_socket_open fn_socket_open = NULL; @@ -46,8 +48,6 @@ static tfn_net_mod_socket_get_key fn_socket_get_key = NULL; static tfn_net_mod_socket_free_recv_msg_arr fn_socket_free_recv_msg_arr = NULL; static tfn_net_mod_socket_free fn_socket_free = NULL; -static tfn_shm_mod_socket_remove_key fn_socket_remove_key = NULL; -static tfn_shm_mod_socket_remove_keys fn_socket_remove_keys = NULL; static tfn_net_mod_server_socket_open fn_server_socket_open = NULL; static tfn_net_mod_server_socket_close fn_server_socket_close = NULL; @@ -64,6 +64,8 @@ const static char l_shm_init[] = "shm_mm_wrapper_init"; const static char l_shm_destroy[] = "shm_mm_wrapper_destroy"; const static char l_shm_alloc_key[] = "shm_mm_wrapper_alloc_key"; +const static char l_shm_remove_keys[] = "shm_mm_wrapper_remove_keys"; +const static char l_shm_remove_keys_exclude[] = "shm_mm_wrapper_remove_keys_exclude"; // net mode socket const static char l_socket_open[] = "net_mod_socket_open"; @@ -98,8 +100,6 @@ const static char l_net_mod_socket_get_key[] = "net_mod_socket_get_key"; const static char l_net_mod_socket_free_recv_msg_arr[] = "net_mod_socket_free_recv_msg_arr"; const static char l_net_mod_socket_free[] = "net_mod_socket_free"; -const static char l_shm_mod_socket_remove_key[] = "shm_mod_socket_remove_key"; -const static char l_shm_mod_socket_remove_keys[] = "shm_mod_socket_remove_keys"; 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"; @@ -120,6 +120,8 @@ void wrap_fn_shm_init(hbhomebus lib, int size); int wrap_fn_shm_alloc_key(hbhomebus lib); void wrap_fn_shm_destroy(hbhomebus lib); +int wrap_fn_shm_remove_keys(hbhomebus lib, void *keys, int length); +int wrap_fn_shm_remove_keys_exclude(hbhomebus lib, void *keys, int length); ///////////////////////////////////////////////////////// // net mode socket @@ -157,9 +159,6 @@ 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) ; - -int wrap_fn_socket_remove_key(hbhomebus lib, int key); -int wrap_fn_socket_remove_keys(hbhomebus lib, void *keys, int length); void *wrap_fn_server_socket_open(hbhomebus lib, int port); void wrap_fn_server_socket_close(hbhomebus lib, void* _socket); diff --git a/libcbhomebus_func.h b/libcbhomebus_func.h index a986a0c..a104766 100644 --- a/libcbhomebus_func.h +++ b/libcbhomebus_func.h @@ -46,6 +46,11 @@ */ typedef int(*tfn_shm_alloc_key) (); +/** + * 鎵归噺鍒犻櫎key瀵瑰簲鐨勫叡浜槦鍒楋紝骞跺湪bus閲屽垹闄よkey鐨勮闃� + */ +typedef int(*tfn_shm_remove_keys) (int*, int); +typedef int(*tfn_shm_remove_keys_exclude) (int*, int); ///////////////////////////////////////////// // net_mod_socket @@ -227,13 +232,6 @@ * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf */ typedef void (*tfn_net_mod_socket_free)(void *buf) ; - -typedef int(*tfn_shm_mod_socket_remove_key) (int); -/** - * 鎵归噺鍒犻櫎key瀵瑰簲鐨勫叡浜槦鍒楋紝骞跺湪bus閲屽垹闄よkey鐨勮闃� - */ -typedef int(*tfn_shm_mod_socket_remove_keys) (int*, int); - /** * 鍒涘缓 -- Gitblit v1.8.0