From 03192056ece95e0e9c30a3b906cb4080c2e75bca Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 01 十二月 2020 14:21:59 +0800 Subject: [PATCH] new bhomebus --- /dev/null | 127 ----- bhomebus.go | 579 +++++++++++++++++++++++++ libcbhomebus.c | 331 ++++++++++++++ libcbhomebus_func.h | 197 ++++++++ libcbhomebus.h | 137 +++++ 5 files changed, 1,244 insertions(+), 127 deletions(-) diff --git a/bhomebus.go b/bhomebus.go new file mode 100644 index 0000000..50f2259 --- /dev/null +++ b/bhomebus.go @@ -0,0 +1,579 @@ +package bhomebus + +/* +#cgo LDFLAGS: -ldl +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include "libcbhomebus.h" + +void* create_net_node_t(const int size){ + net_node_t* nodes = (net_node_t*)malloc(sizeof(net_node_t) * size); + return nodes; +} +void release_net_node_t(void* arr){ + net_node_t* nodes = (net_node_t*)arr; + free(nodes); +} +void set_1_net_node(void* arr, const int index, char* host, const int port, const int key){ + net_node_t* nodes = (net_node_t*)arr; + nodes[index].host = strlen(host) > 0 ? host : NULL; + nodes[index].port = port; + nodes[index].key = key; +} +int get_1_net_mod_recv_msg(void* arr, const int index, + char** host, int* port, int* key, void** content, int* content_length){ + + if (!arr) return -1; + + net_mod_recv_msg_t* msg = (net_mod_recv_msg_t*)arr; + *host = msg[index].host; + *port = msg[index].port; + *key = msg[index].key; + *content = msg[index].content; + *content_length = msg[index].content_length; + return 0; +} +void* create_int_array(const int size){ + int* arr = (int*)malloc(sizeof(int) * size); + return arr; +} +void release_int_array(void* arr){ + int* carr = (int*)arr; + free(carr); +} +int set_1_int(void* arr, const int index, const int key){ + if (!arr) return -1; + int* carr = (int*)arr; + carr[index] = key; + return 0; +} +*/ +import "C" +import ( + "errors" + "unsafe" +) + +var libbhomebus C.hbhomebus + +// Init Dynamic library +func Init(so string) error { + cso := C.CString(so) + defer C.free(unsafe.Pointer(cso)) + + handle := C.c_bhomebus_handle(cso) + if handle == nil { + return errors.New("Init BHomeBus Error") + } + + libbhomebus = handle + return nil +} + +// Release handle of c softbus +func Release() { + if libbhomebus != nil { + C.c_bhomebus_release(libbhomebus) + } +} + +// ShmInit block size +func ShmInit(size int) error { + if libbhomebus == nil { + return errors.New("C BHomeBus Handle Is Nil") + } + C.wrap_fn_shm_init(libbhomebus, C.int(size)) + return nil +} + +// ShmAllocKey alloc key +func ShmAllocKey() int { + if libbhomebus == nil { + return -1 + } + r := C.wrap_fn_shm_alloc_key(libbhomebus) + return int(r) +} + +// ShmDestroy destroy shm block, every softbus proc MUST call it +func ShmDestroy() { + if libbhomebus != nil { + C.wrap_fn_shm_destroy(libbhomebus) + } +} + +// Socket of bhomebus +type Socket struct { + socket unsafe.Pointer +} + +// OpenSocket open socket +func OpenSocket() *Socket { + if libbhomebus == nil { + return nil + } + + sock := C.wrap_fn_socket_open(libbhomebus) + return &Socket{sock} +} + +// Close socket +func (s *Socket) Close() { + if libbhomebus == nil { + return + } + C.wrap_fn_socket_close(libbhomebus, s.socket) +} + +// Bind socket +func (s *Socket) Bind(key int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_bind(libbhomebus, s.socket, C.int(key))) +} + +// ForceBind socket +func (s *Socket) ForceBind(key int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_force_bind(libbhomebus, s.socket, C.int(key))) +} + +// Sendto socket +func (s *Socket) Sendto(data []byte, key int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_sendto(libbhomebus, s.socket, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(key))) +} + +// SendtoTimeout socket +func (s *Socket) SendtoTimeout(data []byte, key int, milliseconds int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_sendto_timeout(libbhomebus, s.socket, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(key), 0, C.int(milliseconds*1000000))) +} + +// SendtoNowait socket +func (s *Socket) SendtoNowait(data []byte, key int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_sendto_nowait(libbhomebus, s.socket, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(key))) +} + +// Recvfrom socket +func (s *Socket) Recvfrom(data *[]byte, key *int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + var buf unsafe.Pointer + var size, ckey C.int + ret := C.wrap_fn_socket_recvfrom(libbhomebus, s.socket, &buf, &size, &ckey) + defer C.wrap_fn_socket_free(libbhomebus, buf) + if ret == 0 && buf != nil { + *data = C.GoBytes(buf, size) + *key = int(ckey) + } + + return int(ret) +} + +// RecvfromTimeout socket +func (s *Socket) RecvfromTimeout(data *[]byte, key *int, milliseconds int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + var buf unsafe.Pointer + var size, ckey C.int + + ret := C.wrap_fn_socket_recvfrom_timeout(libbhomebus, s.socket, &buf, &size, &ckey, 0, C.int(milliseconds*1000000)) + defer C.wrap_fn_socket_free(libbhomebus, buf) + if ret == 0 && buf != nil { + *data = C.GoBytes(buf, size) + *key = int(ckey) + } + return int(ret) + +} + +// RecvfromNowait socket +func (s *Socket) RecvfromNowait(data *[]byte, key *int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + var buf unsafe.Pointer + var size, ckey C.int + ret := C.wrap_fn_socket_recvfrom_nowait(libbhomebus, s.socket, &buf, &size, &ckey) + defer C.wrap_fn_socket_free(libbhomebus, buf) + if ret == 0 && buf != nil { + *data = C.GoBytes(buf, size) + *key = int(ckey) + } + + return int(ret) +} + +// NetNode peer info +type NetNode struct { + IPHost string + Port int + Key int +} + +// Mesg msg from peer +type Mesg struct { + PeerNode NetNode + Data []byte +} + +func transferMesg(recvMsg unsafe.Pointer, recvMsgSize C.int) []Mesg { + var msgs []Mesg + + var host *C.char + var content unsafe.Pointer + var port, key, contentLength C.int + for i := 0; i < int(recvMsgSize); i++ { + if 0 == C.get_1_net_mod_recv_msg(recvMsg, C.int(i), &host, &port, &key, &content, &contentLength) { + msgs = append(msgs, + Mesg{ + PeerNode: NetNode{ + IPHost: C.GoString(host), + Port: int(port), + Key: int(key), + }, + Data: C.GoBytes(content, contentLength), + }) + } + + } + return msgs +} + +// Sendandrecv socket +func (s *Socket) Sendandrecv(nodes []NetNode, data []byte, msgs *[]Mesg) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + if cnodes == nil { + return -2 + } + + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + var recvMsg unsafe.Pointer + var recvMsgSize C.int + ret := C.wrap_fn_socket_sendandrecv(libbhomebus, s.socket, cnodes, C.int(len(nodes)), unsafe.Pointer(&data[0]), C.int(len(data)), &recvMsg, &recvMsgSize) + defer C.wrap_fn_socket_free_recv_msg_arr(libbhomebus, recvMsg, recvMsgSize) + if ret > 0 && recvMsg != nil && recvMsgSize > 0 { + *msgs = transferMesg(recvMsg, recvMsgSize) + } + + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + return int(ret) +} + +// SendandrecvTimeout socket +func (s *Socket) SendandrecvTimeout(nodes []NetNode, data []byte, msgs *[]Mesg, milliseconds int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + + if cnodes == nil { + return -2 + } + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + var recvMsg unsafe.Pointer + var recvMsgSize C.int + ret := C.wrap_fn_socket_sendandrecv_timeout(libbhomebus, s.socket, cnodes, C.int(len(nodes)), unsafe.Pointer(&data[0]), C.int(len(data)), &recvMsg, &recvMsgSize, C.int(milliseconds)) + defer C.wrap_fn_socket_free_recv_msg_arr(libbhomebus, recvMsg, recvMsgSize) + if ret > 0 && recvMsg != nil && recvMsgSize > 0 { + *msgs = transferMesg(recvMsg, recvMsgSize) + } + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + + return int(ret) +} + +// SendandrecvNowait socket +func (s *Socket) SendandrecvNowait(nodes []NetNode, data []byte, msgs *[]Mesg) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + + if cnodes == nil { + return -2 + } + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + var recvMsg unsafe.Pointer + var recvMsgSize C.int + ret := C.wrap_fn_socket_sendandrecv_nowait(libbhomebus, s.socket, cnodes, C.int(len(nodes)), unsafe.Pointer(&data[0]), C.int(len(data)), &recvMsg, &recvMsgSize) + defer C.wrap_fn_socket_free_recv_msg_arr(libbhomebus, recvMsg, recvMsgSize) + if ret > 0 && recvMsg != nil && recvMsgSize > 0 { + *msgs = transferMesg(recvMsg, recvMsgSize) + } + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + + 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)) +} + +// Pub socket +func (s *Socket) Pub(nodes []NetNode, topic string, data []byte) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + + if cnodes == nil { + return -2 + } + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + ctopic := C.CString(topic) + defer C.free(unsafe.Pointer(ctopic)) + ret := C.wrap_fn_socket_pub(libbhomebus, s.socket, cnodes, C.int(len(nodes)), ctopic, C.int(len(topic)), unsafe.Pointer(&data[0]), C.int(len(data))) + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + + return int(ret) +} + +// PubTimeout socket +func (s *Socket) PubTimeout(nodes []NetNode, topic string, data []byte, milliseconds int) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + + if cnodes == nil { + return -2 + } + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + ctopic := C.CString(topic) + defer C.free(unsafe.Pointer(ctopic)) + + ret := C.wrap_fn_socket_pub_timeout(libbhomebus, s.socket, cnodes, C.int(len(nodes)), ctopic, C.int(len(topic)), unsafe.Pointer(&data[0]), C.int(len(data)), C.int(milliseconds)) + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + + return int(ret) +} + +// PubNowait socket +func (s *Socket) PubNowait(nodes []NetNode, topic string, data []byte) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + cnodes := C.create_net_node_t(C.int(len(nodes))) + defer C.release_net_node_t(cnodes) + + if cnodes == nil { + return -2 + } + var ciphosts []*C.char + for i, v := range nodes { + chost := C.CString(v.IPHost) + ciphosts = append(ciphosts, chost) + C.set_1_net_node(cnodes, C.int(i), chost, C.int(v.Port), C.int(v.Key)) + } + + ctopic := C.CString(topic) + defer C.free(unsafe.Pointer(ctopic)) + ret := C.wrap_fn_socket_pub_nowait(libbhomebus, s.socket, cnodes, C.int(len(nodes)), ctopic, C.int(len(topic)), unsafe.Pointer(&data[0]), C.int(len(data))) + for _, v := range ciphosts { + C.free(unsafe.Pointer(v)) + } + + return int(ret) +} + +// Sub socket +func (s *Socket) Sub(topic string, key 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(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key))) +} + +// SubTimeout socket +func (s *Socket) SubTimeout(topic string, key int, 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))) + +} + +// SubNowait socket +func (s *Socket) SubNowait(topic string, key 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_nowait(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key))) + +} + +// Desub socket +func (s *Socket) Desub(topic string, key 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_desub(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key))) +} + +// DesubTimeout socket +func (s *Socket) DesubTimeout(topic string, key int, 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_desub_timeout(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key), 0, C.int(milliseconds*1000000))) +} + +// DesubNowait socket +func (s *Socket) DesubNowait(topic string, key 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_desub_nowait(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key))) +} + +// Getkey socket +func (s *Socket) Getkey() int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return int(C.wrap_fn_socket_get_key(libbhomebus, s.socket)) +} + +// FreeRecvMsgArr socket +func (s *Socket) FreeRecvMsgArr(data []Mesg) int { + if libbhomebus == nil || s.socket == nil { + return -1 + } + + return 0 +} + +// FreeBuf socket +func (s *Socket) FreeBuf(buf unsafe.Pointer) int { + if libbhomebus == nil || s.socket == nil { + 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)))) +} diff --git a/libcbhomebus.c b/libcbhomebus.c new file mode 100644 index 0000000..9aa0240 --- /dev/null +++ b/libcbhomebus.c @@ -0,0 +1,331 @@ +#ifdef __cplusplus +extern "C"{ +#endif + +#ifdef __cplusplus +} +#endif + +#include <dlfcn.h> +#include <stdlib.h> +#include <stdio.h> + +#include "libcbhomebus.h" + +#define check_only(fn, lib) \ +do{ \ + if(!fn){ \ + dlclose(lib); \ + printf("run func %s error\n", #fn); \ + return; \ + } \ +}while(0) + +#define check_with_ret(fn, lib, flag) \ +do{ \ + if(!fn){ \ + dlclose(lib); \ + printf("run func %s error\n", #fn); \ + return flag; \ + } \ +}while(0) + + +hbhomebus c_bhomebus_handle(const char *so){ + hbhomebus lib = dlopen(so, RTLD_LAZY); + if(lib){ + + fn_shm_destroy = (tfn_shm_destroy)dlsym(lib, l_shm_destroy); + check_with_ret(fn_shm_destroy, lib, NULL); + }else{ + printf("softbus dlopen - %s\n", dlerror()); + } + return lib; +} + +void c_bhomebus_release(hbhomebus lib){ + if(lib) { + dlclose(lib); + } +} + +void wrap_fn_shm_init(hbhomebus lib, int size){ + if (!fn_shm_init){ + fn_shm_init = (tfn_shm_init)dlsym(lib, l_shm_init); + check_only(fn_shm_init, lib); + } + fn_shm_init(size); +} + +int wrap_fn_shm_alloc_key(hbhomebus lib){ + if (!fn_shm_alloc_key){ + fn_shm_alloc_key = (tfn_shm_alloc_key)dlsym(lib, l_shm_alloc_key); + check_with_ret(fn_shm_alloc_key, lib, -1); + } + return fn_shm_alloc_key(); +} + +void wrap_fn_shm_destroy(hbhomebus lib){ + if (!fn_shm_destroy){ + printf("shm destroy failed\n"); + return; + } + fn_shm_destroy(); +} + +//////////////////////////////////////////// +// dgram socket mode +//////////////////////////////////////////// + +void * wrap_fn_socket_open(hbhomebus lib) +{ + if(!fn_socket_open){ + fn_socket_open = (tfn_net_mod_socket_open)dlsym(lib,l_net_mod_socket_open); + check_with_ret(fn_socket_open, lib, NULL); + } + return fn_socket_open(); +} + +void wrap_fn_socket_close(hbhomebus lib, void *_socket) +{ + if(!fn_socket_close){ + fn_socket_close = (tfn_net_mod_socket_close)dlsym(lib,l_net_mod_socket_close); + check_only(fn_socket_close, lib); + } + return fn_socket_close(_socket); +} + +int wrap_fn_socket_bind(hbhomebus lib, void * _socket, int key) +{ + if(!fn_socket_bind){ + fn_socket_bind = (tfn_net_mod_socket_bind)dlsym(lib,l_net_mod_socket_bind); + check_with_ret(fn_socket_bind, lib, -1); + } + return fn_socket_bind(_socket, key); +} + +int wrap_fn_socket_force_bind(hbhomebus lib, void * _socket, int key) +{ + if(!fn_socket_force_bind){ + fn_socket_force_bind = (tfn_net_mod_socket_force_bind)dlsym(lib,l_net_mod_socket_force_bind); + check_with_ret(fn_socket_force_bind, lib, -1); + } + return fn_socket_force_bind(_socket, key); +} + +int wrap_fn_socket_sendto(hbhomebus lib, void *_socket, const void *buf, const int size, const int key) +{ + if(!fn_socket_sendto){ + fn_socket_sendto = (tfn_net_mod_socket_sendto)dlsym(lib,l_net_mod_socket_sendto); + check_with_ret(fn_socket_sendto, lib, -1); + } + return fn_socket_sendto(_socket, buf, size, key); +} + +int wrap_fn_socket_sendto_timeout(hbhomebus lib, void *_socket, const void *buf, const int size, const int key, int sec, int nsec) +{ + if(!fn_socket_sendto_timeout){ + fn_socket_sendto_timeout = (tfn_net_mod_socket_sendto_timeout)dlsym(lib,l_net_mod_socket_sendto_timeout); + check_with_ret(fn_socket_sendto_timeout, lib, -1); + } + return fn_socket_sendto_timeout(_socket, buf, size, key, sec, nsec); +} + +int wrap_fn_socket_sendto_nowait(hbhomebus lib, void *_socket, const void *buf, const int size, const int key) +{ + if(!fn_socket_sendto_nowait){ + fn_socket_sendto_nowait = (tfn_net_mod_socket_sendto_nowait)dlsym(lib,l_net_mod_socket_sendto_nowait); + check_with_ret(fn_socket_sendto_nowait, lib, -1); + } + return fn_socket_sendto_nowait(_socket, buf, size, key); +} + +int wrap_fn_socket_recvfrom(hbhomebus lib, void *_socket, void **buf, int *size, int *key) +{ + if(!fn_socket_recvfrom){ + fn_socket_recvfrom = (tfn_net_mod_socket_recvfrom)dlsym(lib,l_net_mod_socket_recvfrom); + check_with_ret(fn_socket_recvfrom, lib, -1); + } + return fn_socket_recvfrom(_socket, buf, size, key); +} + +int wrap_fn_socket_recvfrom_timeout(hbhomebus lib, void *_socket, void **buf, int *size, int *key, int sec, int nsec) +{ + if(!fn_socket_recvfrom_timeout){ + fn_socket_recvfrom_timeout = (tfn_net_mod_socket_recvfrom_timeout)dlsym(lib,l_net_mod_socket_recvfrom_timeout); + check_with_ret(fn_socket_recvfrom_timeout, lib, -1); + } + return fn_socket_recvfrom_timeout(_socket, buf, size, key, sec, nsec); +} + +int wrap_fn_socket_recvfrom_nowait(hbhomebus lib, void *_socket, void **buf, int *size, int *key) +{ + if(!fn_socket_recvfrom_nowait){ + fn_socket_recvfrom_nowait = (tfn_net_mod_socket_recvfrom_nowait)dlsym(lib,l_net_mod_socket_recvfrom_nowait); + check_with_ret(fn_socket_recvfrom_nowait, lib, -1); + } + return fn_socket_recvfrom_nowait(_socket, buf, size, key); +} + +int wrap_fn_socket_sendandrecv(hbhomebus lib, void *_sockt, void *node_arr, int arrlen, void *send_buf, int send_size, + void ** recv_arr, int *recv_arr_size) +{ + if(!fn_socket_sendandrecv){ + fn_socket_sendandrecv = (tfn_net_mod_socket_sendandrecv)dlsym(lib,l_net_mod_socket_sendandrecv); + check_with_ret(fn_socket_sendandrecv, lib, -1); + } + return fn_socket_sendandrecv(_sockt, (net_node_t*) node_arr, arrlen, send_buf, send_size, (net_mod_recv_msg_t**)recv_arr, recv_arr_size); +} + +int wrap_fn_socket_sendandrecv_timeout(hbhomebus lib, void *_socket, void *node_arr, int arrlen, void *send_buf, int send_size, + void ** recv_arr, int *recv_arr_size, int timeout) +{ + if(!fn_socket_sendandrecv_timeout){ + fn_socket_sendandrecv_timeout = (tfn_net_mod_socket_sendandrecv_timeout)dlsym(lib,l_net_mod_socket_sendandrecv_timeout); + check_with_ret(fn_socket_sendandrecv_timeout, lib, -1); + } + return fn_socket_sendandrecv_timeout(_socket, (net_node_t*)node_arr, arrlen, send_buf, send_size, (net_mod_recv_msg_t**)recv_arr, recv_arr_size, timeout); +} + +int wrap_fn_socket_sendandrecv_nowait(hbhomebus lib, void *_socket, void *node_arr, int arrlen, void *send_buf, int send_size, + void ** recv_arr, int *recv_arr_size) +{ + if(!fn_socket_sendandrecv_nowait){ + fn_socket_sendandrecv_nowait = (tfn_net_mod_socket_sendandrecv_nowait)dlsym(lib,l_net_mod_socket_sendandrecv_nowait); + check_with_ret(fn_socket_sendandrecv_nowait, lib, -1); + } + 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_pub(hbhomebus lib, void *_socket, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size) +{ + if(!fn_socket_pub){ + fn_socket_pub = (tfn_net_mod_socket_pub)dlsym(lib,l_net_mod_socket_pub); + check_with_ret(fn_socket_pub, lib, -1); + } + return fn_socket_pub(_socket, (net_node_t*)node_arr, node_arr_len, topic, topic_size, content, content_size); +} + +int wrap_fn_socket_pub_timeout(hbhomebus lib, void *_socket, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout) +{ + if(!fn_socket_pub_timeout){ + fn_socket_pub_timeout = (tfn_net_mod_socket_pub_timeout)dlsym(lib,l_net_mod_socket_pub_timeout); + check_with_ret(fn_socket_pub_timeout, lib, -1); + } + return fn_socket_pub_timeout(_socket, (net_node_t*)node_arr, node_arr_len, topic, topic_size, content, content_size, timeout); +} + +int wrap_fn_socket_pub_nowait(hbhomebus lib, void *_socket, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size) +{ + if(!fn_socket_pub_nowait){ + fn_socket_pub_nowait = (tfn_net_mod_socket_pub_nowait)dlsym(lib,l_net_mod_socket_pub_nowait); + check_with_ret(fn_socket_pub_nowait, lib, -1); + } + 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) +{ + 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); +} + +int wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, 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); +} + +int wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key) +{ + 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); +} + +int wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size, int key) +{ + 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); +} + +int wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, 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); +} + +int wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key) +{ + 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); +} + +int wrap_fn_socket_get_key(hbhomebus lib, void * _socket) +{ + if(!fn_socket_get_key){ + fn_socket_get_key = (tfn_net_mod_socket_get_key)dlsym(lib,l_net_mod_socket_get_key); + check_with_ret(fn_socket_get_key, lib, -1); + } + return fn_socket_get_key(_socket); +} + +void wrap_fn_socket_free_recv_msg_arr(hbhomebus lib, void * arr, int size) +{ + if(!fn_socket_free_recv_msg_arr){ + fn_socket_free_recv_msg_arr = (tfn_net_mod_socket_free_recv_msg_arr)dlsym(lib,l_net_mod_socket_free_recv_msg_arr); + check_only(fn_socket_free_recv_msg_arr, lib); + } + return fn_socket_free_recv_msg_arr((net_mod_recv_msg_t*)arr, size); +} + +void wrap_fn_socket_free(hbhomebus lib, void *buf) +{ + if(!fn_socket_free){ + fn_socket_free = (tfn_net_mod_socket_free)dlsym(lib,l_net_mod_socket_free); + 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); +} \ No newline at end of file diff --git a/libcbhomebus.h b/libcbhomebus.h new file mode 100644 index 0000000..c43abc3 --- /dev/null +++ b/libcbhomebus.h @@ -0,0 +1,137 @@ +#ifndef _c_libshm_queue_so_go_wrapper_h_ +#define _c_libshm_queue_so_go_wrapper_h_ + + +#ifdef __cplusplus +extern "C"{ +#endif + +#include "libcbhomebus_func.h" +#include <stddef.h> + +// shm manipulate +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; + +// net mode socket +static tfn_net_mod_socket_open fn_socket_open = NULL; +static tfn_net_mod_socket_close fn_socket_close = NULL; +static tfn_net_mod_socket_bind fn_socket_bind = NULL; +static tfn_net_mod_socket_force_bind fn_socket_force_bind = NULL; +static tfn_net_mod_socket_sendto fn_socket_sendto = NULL; +static tfn_net_mod_socket_sendto_timeout fn_socket_sendto_timeout = NULL; +static tfn_net_mod_socket_sendto_nowait fn_socket_sendto_nowait = NULL; +static tfn_net_mod_socket_recvfrom fn_socket_recvfrom = NULL; +static tfn_net_mod_socket_recvfrom_timeout fn_socket_recvfrom_timeout = NULL; +static tfn_net_mod_socket_recvfrom_nowait fn_socket_recvfrom_nowait = NULL; +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_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; +static tfn_net_mod_socket_sub fn_socket_sub = NULL; +static tfn_net_mod_socket_sub_timeout fn_socket_sub_timeout = NULL; +static tfn_net_mod_socket_sub_nowait fn_socket_sub_nowait = NULL; +static tfn_net_mod_socket_desub fn_socket_desub = NULL; +static tfn_net_mod_socket_desub_timeout fn_socket_desub_timeout = NULL; +static tfn_net_mod_socket_desub_nowait fn_socket_desub_nowait = NULL; +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; + +////////////////////////////////////////////////////////////////////// + +// labels +// shm +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"; + +// net mode socket +const static char l_socket_open[] = "net_mod_socket_open"; +const static char l_net_mod_socket_open[] = "net_mod_socket_open"; +const static char l_net_mod_socket_close[] = "net_mod_socket_close"; +const static char l_net_mod_socket_bind[] = "net_mod_socket_bind"; +const static char l_net_mod_socket_force_bind[] = "net_mod_socket_force_bind"; +const static char l_net_mod_socket_sendto[] = "net_mod_socket_sendto"; +const static char l_net_mod_socket_sendto_timeout[] = "net_mod_socket_sendto_timeout"; +const static char l_net_mod_socket_sendto_nowait[] = "net_mod_socket_sendto_nowait"; +const static char l_net_mod_socket_recvfrom[] = "net_mod_socket_recvfrom"; +const static char l_net_mod_socket_recvfrom_timeout[] = "net_mod_socket_recvfrom_timeout"; +const static char l_net_mod_socket_recvfrom_nowait[] = "net_mod_socket_recvfrom_nowait"; +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_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"; +const static char l_net_mod_socket_sub[] = "net_mod_socket_sub"; +const static char l_net_mod_socket_sub_timeout[] = "net_mod_socket_sub_timeout"; +const static char l_net_mod_socket_sub_nowait[] = "net_mod_socket_sub_nowait"; +const static char l_net_mod_socket_desub[] = "net_mod_socket_desub"; +const static char l_net_mod_socket_desub_timeout[] = "net_mod_socket_desub_timeout"; +const static char l_net_mod_socket_desub_nowait[] = "net_mod_socket_desub_nowait"; +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"; +////////////////////////////////////////////////////////////////////// + +// dlopen dynamic library +typedef void* hbhomebus; +hbhomebus c_bhomebus_handle(const char *so); +void c_bhomebus_release(hbhomebus lib); + +// shm manipulate +void wrap_fn_shm_init(hbhomebus lib, int size); +int wrap_fn_shm_alloc_key(hbhomebus lib); +void wrap_fn_shm_destroy(hbhomebus lib); + +///////////////////////////////////////////////////////// +// net mode socket +void * wrap_fn_socket_open(hbhomebus lib); +void wrap_fn_socket_close(hbhomebus lib, void *_sockt); +int wrap_fn_socket_bind(hbhomebus lib, void * _socket, int key); +int wrap_fn_socket_force_bind(hbhomebus lib, void * _socket, int key); +int wrap_fn_socket_sendto(hbhomebus lib, void *_socket, const void *buf, const int size, const int key); +int wrap_fn_socket_sendto_timeout(hbhomebus lib, void *_socket, const void *buf, const int size, const int key, int sec, int nsec); +int wrap_fn_socket_sendto_nowait(hbhomebus lib, void *_socket, const void *buf, const int size, const int key); +int wrap_fn_socket_recvfrom(hbhomebus lib, void *_socket, void **buf, int *size, int *key); +int wrap_fn_socket_recvfrom_timeout(hbhomebus lib, void *_socket, void **buf, int *size, int *key, int sec, int nsec); +int wrap_fn_socket_recvfrom_nowait(hbhomebus lib, void *_socket, void **buf, int *size, int *key); +int wrap_fn_socket_sendandrecv(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_sendandrecv_timeout(hbhomebus lib, void *_sockt, void *node_arr, int arrlen, void *send_buf, int send_size, + 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_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_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); + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/libcbhomebus_func.h b/libcbhomebus_func.h new file mode 100644 index 0000000..f2cbbb7 --- /dev/null +++ b/libcbhomebus_func.h @@ -0,0 +1,197 @@ +#ifndef _c_libshm_queue_so_func_h_ +#define _c_libshm_queue_so_func_h_ + + +#ifdef __cplusplus +extern "C"{ +#endif + +#ifndef net_node_t +typedef struct _net_node_t{ + const char *host; + int port; + int key; +} net_node_t; +#endif + +#ifndef net_mod_recv_msg_t + #ifndef NI_MAXHOST + #define _BSD_SOURCE /* To get definitions of NI_MAXHOST and + NI_MAXSERV from <netdb.h> */ + #include <netdb.h> + // #define NI_MAXHOST 1025 + #endif +typedef struct _net_mod_recv_msg_t{ + char host[NI_MAXHOST]; + int port; + int key; + void *content; + int content_length; +} net_mod_recv_msg_t; +#endif + +/** + * 鍒濆鍖栧叡浜唴瀛� + * @size 鍏变韩鍐呭瓨澶у皬 + * + */ +typedef void(*tfn_shm_init)(int); +/** + * 閿�姣佸叡浜唴瀛� + * 鏁翠釜杩涚▼閫�鍑烘椂闇�瑕佹墽琛岃繖涓柟娉曪紝璇ユ柟娉曢鍏堜細妫�鏌ユ槸鍚﹁繕鏈夊叾浠栬繘绋嬪湪浣跨敤璇ュ叡浜唴瀛橈紝濡傛灉杩樻湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ氨鍙槸detach,濡傛灉娌℃湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ垯閿�姣佹暣鍧楀唴瀛樸�� + */ +typedef void(*tfn_shm_destroy)(); +/** + * 鑾峰彇key + */ +typedef int(*tfn_shm_alloc_key) (); + + +///////////////////////////////////////////// +// net_mod_socket +/** + * 鍒涘缓 + */ +typedef void * (*tfn_net_mod_socket_open)(); + +/** + * 鍏抽棴 + */ +typedef void (*tfn_net_mod_socket_close)(void *_sockt); + + + +/** + * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +typedef int (*tfn_net_mod_socket_bind)(void * _socket, int key); + +/** + * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +typedef int (*tfn_net_mod_socket_force_bind)(void * _socket, int key); + +/** + * 鍙戦�佷俊鎭� + * @key 鍙戦�佺粰璋� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 + */ +typedef int (*tfn_net_mod_socket_sendto)(void *_socket, const void *buf, const int size, const int key); +// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇 +typedef int (*tfn_net_mod_socket_sendto_timeout)(void *_socket, const void *buf, const int size, const int key, int sec, int nsec); +// 鍙戦�佷俊鎭珛鍒昏繑鍥炪�� +typedef int (*tfn_net_mod_socket_sendto_nowait)(void *_socket, const void *buf, const int size, const int key); + +/** + * 鎺ユ敹淇℃伅 + * @key 浠庤皝鍝噷鏀跺埌鐨勪俊鎭� + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +typedef int (*tfn_net_mod_socket_recvfrom)(void *_socket, void **buf, int *size, int *key); +// 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇 +typedef int (*tfn_net_mod_socket_recvfrom_timeout)(void *_socket, void **buf, int *size, int *key, int sec, int nsec); +typedef int (*tfn_net_mod_socket_recvfrom_nowait)(void *_socket, void **buf, int *size, int *key); + + + +/** + * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅浼氫竴鐩寸瓑寰� + * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂閫佽姹傛秷鎭紝鑺傜偣鐨勮繑鍥炰俊鎭眹鎬诲苟瀛樺偍鍦╮ecv_arr涓� + * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴� + * @send_buf 鍙戦�佺殑娑堟伅锛孈send_size 璇ユ秷鎭綋鐨勯暱搴� + * @recv_arr 杩斿洖鐨勫簲绛旀秷鎭粍锛孈recv_arr_size 璇ユ暟缁勯暱搴� + * @return 鎴愬姛鍙戦�佺殑鑺傜偣鐨勪釜鏁� + * 浼樼偣锛�1鏌愪釜鑺傜偣鐨勬晠闅滀笉浼氶樆濉炲叾浠栬妭鐐广��2鎬ц兘濂� + * 缂虹偣锛氫笉鏄嚎绋嬪畨鍏ㄧ殑, 鍗充笉鑳芥湁涓や釜浠ヤ笂鐨勭嚎绋嬪悓鏃朵娇鐢ㄨ繖涓璞$殑鏂规硶 + */ +typedef int (*tfn_net_mod_socket_sendandrecv)(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ; +/** + * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅绛夊緟timeout鐨勬椂闂村悗杩斿洖 + * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉� +*/ +typedef int (*tfn_net_mod_socket_sendandrecv_timeout)(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout); + +/** + * 涓嶇瓑寰呯珛鍗宠繑鍥� +*/ +typedef int (*tfn_net_mod_socket_sendandrecv_nowait)(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ; + + +/** + * 鍚姩bus + * + * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 +*/ +typedef int (*tfn_net_mod_socket_start_bus)(void * _socket); + + + /** + * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭� + * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴� + * @topic 涓婚锛孈topic_size 璇ヤ富棰樼殑闀垮害 + * @content 鍐呭锛孈content_size 鍐呭闀垮害 + * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟 + */ +typedef int (*tfn_net_mod_socket_pub)(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); +typedef int (*tfn_net_mod_socket_pub_timeout)(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout); +typedef int (*tfn_net_mod_socket_pub_nowait)(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); + +/** + * 璁㈤槄鎸囧畾涓婚 + * @topic 涓婚 + * @size 涓婚闀垮害 + * @key 鎬荤嚎绔彛 + */ +typedef int (*tfn_net_mod_socket_sub)(void * _socket, void *topic, int size, int key); +// 瓒呮椂杩斿洖銆� @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); + + +/** + * 鍙栨秷璁㈤槄鎸囧畾涓婚 + * @topic 涓婚,涓婚涓虹┖鏃跺彇娑堝叏閮ㄨ闃� + * @size 涓婚闀垮害 + * @key 鎬荤嚎绔彛 + */ +typedef int (*tfn_net_mod_socket_desub)(void * _socket, void *topic, int size, int key); +// 瓒呮椂杩斿洖銆� @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); + + +/** + * 鑾峰彇soket绔彛鍙� + */ +typedef int (*tfn_net_mod_socket_get_key)(void * _socket) ; + + +/** + * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 + * @arr 娑堟伅缁� + * @size 娑堟伅缁勭殑闀垮害 + */ +typedef void (*tfn_net_mod_socket_free_recv_msg_arr)(net_mod_recv_msg_t * arr, int size); + + +/** + * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡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); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/libcsoftbus.c b/libcsoftbus.c deleted file mode 100644 index 01c9f9a..0000000 --- a/libcsoftbus.c +++ /dev/null @@ -1,489 +0,0 @@ -#ifdef __cplusplus -extern "C"{ -#endif - -#include <dlfcn.h> -#include <stdlib.h> -#include <stdio.h> - -#include "libcsoftbus.h" - -#ifdef __cplusplus -} -#endif - -#define check_only(fn, lib) \ -do{ \ - if(!fn){ \ - dlclose(lib); \ - printf("run func %s error\n", #fn); \ - return; \ - } \ -}while(0) - -#define check_with_ret(fn, lib, flag) \ -do{ \ - if(!fn){ \ - dlclose(lib); \ - printf("run func %s error\n", #fn); \ - return flag; \ - } \ -}while(0) - - -hcsoftbus c_softbus_handle(const char *so){ - hcsoftbus lib = dlopen(so, RTLD_LAZY); - if(lib){ - - fn_shm_destroy = (tfn_shm_destroy)dlsym(lib, l_shm_destroy); - check_with_ret(fn_shm_destroy, lib, NULL); - }else{ - printf("softbus dlopen - %s\n", dlerror()); - } - return lib; -} - -void c_softbus_release(hcsoftbus lib){ - if(lib) { - dlclose(lib); - } -} - -void wrap_fn_shm_init(hcsoftbus lib, int size){ - if (!fn_shm_init){ - fn_shm_init = (tfn_shm_init)dlsym(lib, l_shm_init); - check_only(fn_shm_init, lib); - } - fn_shm_init(size); -} - -int wrap_fn_shm_alloc_key(hcsoftbus lib){ - if (!fn_shm_alloc_key){ - fn_shm_alloc_key = (tfn_shm_alloc_key)dlsym(lib, l_shm_alloc_key); - check_with_ret(fn_shm_alloc_key, lib, -1); - } - return fn_shm_alloc_key(); -} - -void wrap_fn_shm_destroy(hcsoftbus lib){ - if (!fn_shm_destroy){ - printf("shm destroy failed\n"); - return; - } - fn_shm_destroy(); -} - -void wrap_fn_shm_rm_dead_queue(hcsoftbus lib, void *array, int len){ - if (!fn_shm_rm_dead_queue){ - fn_shm_rm_dead_queue = (tfn_shm_rm_dead_queue)dlsym(lib, l_shm_rm_dead_queue); - check_only(fn_shm_rm_dead_queue, lib); - } - fn_shm_rm_dead_queue(array, len); -} - -void* wrap_fn_queue_create(hcsoftbus lib, int *key, int queue_size){ - if (!fn_queue_create){ - fn_queue_create = (tfn_queue_create)dlsym(lib, l_queue_create); - check_with_ret(fn_queue_create, lib, NULL); - } - return fn_queue_create(key, queue_size); -} - -void* wrap_fn_queue_attach(hcsoftbus lib, int key){ - if (!fn_queue_attach){ - fn_queue_attach = (tfn_queue_attach)dlsym(lib, l_queue_attach); - check_with_ret(fn_queue_attach, lib, NULL); - } - return fn_queue_attach(key); -} - -void wrap_fn_queue_drop(hcsoftbus lib, void* shmq){ - if (!fn_queue_drop){ - fn_queue_drop = (tfn_queue_drop)dlsym(lib, l_queue_drop); - check_only(fn_queue_drop, lib); - } - fn_queue_drop(shmq); -} - -int wrap_fn_queue_size(hcsoftbus lib, void *shmq){ - if (!fn_queue_size){ - fn_queue_size = (tfn_queue_size)dlsym(lib, l_queue_size); - check_with_ret(fn_queue_size, lib, 0); - } - return fn_queue_size(shmq); -} - -int wrap_fn_queue_full(hcsoftbus lib, void *shmq){ - if (!fn_queue_full){ - fn_queue_full = (tfn_queue_full)dlsym(lib, l_queue_full); - check_with_ret(fn_queue_full, lib, 1); - } - return fn_queue_full(shmq); -} - -int wrap_fn_queue_empty(hcsoftbus lib, void *shmq){ - if (!fn_queue_empty){ - fn_queue_empty = (tfn_queue_empty)dlsym(lib, l_queue_empty); - check_with_ret(fn_queue_empty, lib, 0); - } - return fn_queue_empty(shmq); -} - -int wrap_fn_queue_push(hcsoftbus lib, void *shmq, void *ele, int ele_size){ - if (!fn_queue_push){ - fn_queue_push = (tfn_queue_push)dlsym(lib, l_queue_push); - check_with_ret(fn_queue_push, lib, 0); - } - - return fn_queue_push(shmq, ele, ele_size); -} - -int wrap_fn_queue_push_nowait(hcsoftbus lib, void *shmq, void *ele, int ele_size){ - if (!fn_queue_push_nowait){ - fn_queue_push_nowait = (tfn_queue_push_nowait)dlsym(lib, l_queue_push_nowait); - check_with_ret(fn_queue_push_nowait, lib, 0); - } - return fn_queue_push_nowait(shmq, ele, ele_size); -} - -int wrap_fn_queue_push_timeout(hcsoftbus lib, void *shmq, void *ele, int ele_size, int sec, int nsec){ - if (!fn_queue_push_timeout){ - fn_queue_push_timeout = (tfn_queue_push_timeout)dlsym(lib, l_queue_push_timeout); - check_with_ret(fn_queue_push_timeout, lib, 0); - } - return fn_queue_push_timeout(shmq, ele, ele_size, sec, nsec); -} - -int wrap_fn_queue_pop(hcsoftbus lib, void *shmq, void **ele, int *ele_size){ - if (!fn_queue_pop){ - fn_queue_pop = (tfn_queue_pop)dlsym(lib, l_queue_pop); - check_with_ret(fn_queue_pop, lib, 0); - } - return fn_queue_pop(shmq, ele, ele_size); -} - -int wrap_fn_queue_pop_nowait(hcsoftbus lib, void *shmq, void **ele, int *ele_size){ - if (!fn_queue_pop_nowait){ - fn_queue_pop_nowait = (tfn_queue_pop_nowait)dlsym(lib, l_queue_pop_nowait); - check_with_ret(fn_queue_pop_nowait, lib, 0); - } - return fn_queue_pop_nowait(shmq, ele, ele_size); -} - -int wrap_fn_queue_pop_timeout(hcsoftbus lib, void *shmq, void **ele, int *ele_size, int sec, int nsec){ - if (!fn_queue_pop_timeout){ - fn_queue_pop_timeout = (tfn_queue_pop_timeout)dlsym(lib, l_queue_pop_timeout); - check_with_ret(fn_queue_pop_timeout, lib, 0); - } - - return fn_queue_pop_timeout(shmq, ele, ele_size, sec, nsec); -} - -void wrap_fn_queue_free_poped(hcsoftbus lib, void *ptr){ - if (!fn_queue_free_poped){ - fn_queue_free_poped = (tfn_queue_free_poped)dlsym(lib, l_queue_free_poped); - check_only(fn_queue_free_poped, lib); - } - fn_queue_free_poped(ptr); -} - -//////////////////////////////////////////// -// socket mode -//////////////////////////////////////////// -void *wrap_fn_socket_open(hcsoftbus lib, int mod){ - if (!fn_socket_open) { - fn_socket_open = (tfn_socket_open)dlsym(lib, l_socket_open); - check_with_ret(fn_socket_open, lib, NULL); - } - return fn_socket_open(mod); -} - -int wrap_fn_socket_close(hcsoftbus lib, void* s){ - if(!fn_socket_close){ - fn_socket_close = (tfn_socket_close)dlsym(lib, l_socket_close); - check_with_ret(fn_socket_close, lib, -1); - } - return fn_socket_listen(s); -} - -int wrap_fn_socket_bind(hcsoftbus lib, void *s, int port){ - if (!fn_socket_bind){ - fn_socket_bind = (tfn_socket_bind)dlsym(lib, l_socket_bind); - check_with_ret(fn_socket_bind, lib, -1); - } - - return fn_socket_bind(s, port); -} - -int wrap_fn_socket_listen(hcsoftbus lib, void *s){ - if (!fn_socket_listen){ - fn_socket_listen = (tfn_socket_listen)dlsym(lib, l_socket_listen); - check_with_ret(fn_socket_listen, lib, -1); - } - return fn_socket_listen(s); -} - -int wrap_fn_socket_connect(hcsoftbus lib, void *s, int port){ - if (!fn_socket_connect){ - fn_socket_connect = (tfn_socket_connect)dlsym(lib, l_socket_connect); - check_with_ret(fn_socket_connect, lib, -1); - } - return fn_socket_connect(s, port); -} - -int wrap_fn_socket_send(hcsoftbus lib, void *s, const void *buf, const int size){ - if (!fn_socket_send){ - fn_socket_send = (tfn_socket_send)dlsym(lib, l_socket_send); - check_with_ret(fn_socket_send, lib, -1); - } - - return fn_socket_send(s, buf, size); -} - -int wrap_fn_socket_recv(hcsoftbus lib, void *s, void **buf, int *size){ - if (!fn_socket_recv){ - fn_socket_recv = (tfn_socket_recv)dlsym(lib, l_socket_recv); - check_with_ret(fn_socket_recv, lib, -1); - } - return fn_socket_recv(s, buf, size); -} - -void wrap_fn_socket_buf_free(hcsoftbus lib, void *buf){ - if (!fn_socket_buf_free){ - fn_socket_buf_free = (tfn_socket_buf_free)dlsym(lib, l_socket_free); - } - if (fn_socket_buf_free){ - fn_socket_buf_free(buf); - } -} - -int wrap_fn_socket_port(hcsoftbus lib, void *s){ - if (!fn_socket_port){ - fn_socket_port = (tfn_socket_port)dlsym(lib, l_socket_port); - check_with_ret(fn_socket_port, lib, -1); - } - - return fn_socket_port(s); -} -//////////////////////////////////////////// -// dgram socket mode -//////////////////////////////////////////// -void *wrap_fn_dgram_socket_open(hcsoftbus lib){ - if (!fn_dgram_socket_open){ - fn_dgram_socket_open = (tfn_dgram_socket_open)dlsym(lib , l_dgram_socket_open); - check_with_ret(fn_dgram_socket_open, lib, NULL); - } - return fn_dgram_socket_open(); -} - -int wrap_fn_dgram_socket_close(hcsoftbus lib, void *s){ - if (!fn_dgram_socket_close){ - fn_dgram_socket_close = (tfn_dgram_socket_close)dlsym(lib, l_dgram_socket_close); - check_with_ret(fn_dgram_socket_close, lib, -1); - } - return fn_dgram_socket_close(s); -} - -int wrap_fn_dgram_socket_bind(hcsoftbus lib, void *s, int port){ - if (!fn_dgram_socket_bind){ - fn_dgram_socket_bind = (tfn_dgram_socket_bind)dlsym(lib, l_dgram_socket_bind); - check_with_ret(fn_dgram_socket_bind, lib, -1); - } - return fn_dgram_socket_bind(s, port); -} - -int wrap_fn_dgram_socket_force_bind(hcsoftbus lib, void *s, int port){ - if (!fn_dgram_socket_force_bind){ - fn_dgram_socket_force_bind = (tfn_dgram_socket_force_bind)dlsym(lib, l_dgram_socket_force_bind); - check_with_ret(fn_dgram_socket_force_bind, lib, -1); - } - return fn_dgram_socket_force_bind(s, port); -} - -int wrap_fn_dgram_socket_sendto(hcsoftbus lib, void *s, const void *buf, const int size, const int port){ - if (!fn_dgram_socket_sendto){ - fn_dgram_socket_sendto = (tfn_dgram_socket_sendto)dlsym(lib, l_dgram_socket_sendto); - check_with_ret(fn_dgram_socket_sendto, lib, -1); - } - return fn_dgram_socket_sendto(s, buf, size, port); -} - -int wrap_fn_dgram_socket_sendto_timeout(hcsoftbus lib, void *s, const void *buf, const int size, const int port, int sec, int usec){ - if (!fn_dgram_socket_sendto_timeout){ - fn_dgram_socket_sendto_timeout = (tfn_dgram_socket_sendto_timeout)dlsym(lib, l_dgram_socket_sendto_timeout); - check_with_ret(fn_dgram_socket_sendto_timeout, lib, -1); - } - return fn_dgram_socket_sendto_timeout(s, buf, size, port, sec, usec); -} - -int wrap_fn_dgram_socket_sendto_nowait(hcsoftbus lib, void *s, const void *buf, const int size, const int port){ - if (!fn_dgram_socket_sendto_nowait){ - fn_dgram_socket_sendto_nowait = (tfn_dgram_socket_sendto_nowait)dlsym(lib, l_dgram_socket_sendto_nowait); - check_with_ret(fn_dgram_socket_sendto_nowait, lib, -1); - } - return fn_dgram_socket_sendto_nowait(s, buf, size, port); -} - -int wrap_fn_dgram_socket_recvfrom(hcsoftbus lib, void *s, void **buf, int *size, int *port){ - if (!fn_dgram_socket_recvfrom){ - fn_dgram_socket_recvfrom = (tfn_dgram_socket_recvfrom)dlsym(lib, l_dgram_socket_recvfrom); - check_with_ret(fn_dgram_socket_recvfrom, lib, -1); - } - return fn_dgram_socket_recvfrom(s, buf, size, port); -} - -int wrap_fn_dgram_socket_recvfrom_timeout(hcsoftbus lib, void *s, void **buf, int *size, int *port, int sec, int usec){ - if (!fn_dgram_socket_recvfrom_timeout){ - fn_dgram_socket_recvfrom_timeout = (tfn_dgram_socket_recvfrom_timeout)dlsym(lib, l_dgram_socket_recvfrom_timeout); - check_with_ret(fn_dgram_socket_recvfrom_timeout, lib, -1); - } - return fn_dgram_socket_recvfrom_timeout(s, buf, size, port, sec, usec); -} - -int wrap_fn_dgram_socket_recvfrom_nowait(hcsoftbus lib, void *s, void **buf, int *size, int *port){ - if (!fn_dgram_socket_recvfrom_nowait){ - fn_dgram_socket_recvfrom_nowait = (tfn_dgram_socket_recvfrom_nowait)dlsym(lib, l_dgram_socket_recvfrom_nowait); - check_with_ret(fn_dgram_socket_recvfrom_nowait, lib, -1); - } - return fn_dgram_socket_recvfrom_nowait(s, buf, size, port); -} - -int wrap_fn_dgram_socket_sendandrecv(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize){ - if (!fn_dgram_socket_sendandrecv){ - fn_dgram_socket_sendandrecv = (tfn_dgram_socket_sendandrecv)dlsym(lib, l_dgram_socket_sendandrecv); - check_with_ret(fn_dgram_socket_sendandrecv, lib, -1); - } - return fn_dgram_socket_sendandrecv(s, sbuf, ssize, port, rbuf, rsize); -} - -int wrap_fn_dgram_socket_sendandrecv_timeout(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize, int sec, int usec){ - if (!fn_dgram_socket_sendandrecv_timeout){ - fn_dgram_socket_sendandrecv_timeout = (tfn_dgram_socket_sendandrecv_timeout)dlsym(lib, l_dgram_socket_sendandrecv_timeout); - check_with_ret(fn_dgram_socket_sendandrecv_timeout, lib, -1); - } - - return fn_dgram_socket_sendandrecv_timeout(s, sbuf, ssize, port, rbuf, rsize, sec, usec); -} - -int wrap_fn_dgram_socket_sendandrecv_nowait(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize){ - if (!fn_dgram_socket_sendandrecv_nowait){ - fn_dgram_socket_sendandrecv_nowait = (tfn_dgram_socket_sendandrecv_nowait)dlsym(lib, l_dgram_socket_sendandrecv_nowait); - check_with_ret(fn_dgram_socket_sendandrecv_nowait, lib, -1); - } - return fn_dgram_socket_sendandrecv_nowait(s, sbuf, ssize, port, rbuf, rsize); -} - -int wrap_fn_dgram_socket_start_bus(hcsoftbus lib, void *s){ - if (!fn_dgram_socket_start_bus){ - fn_dgram_socket_start_bus = (tfn_dgram_socket_start_bus)dlsym(lib, l_dgram_socket_start_bus); - check_with_ret(fn_dgram_socket_start_bus, lib, -1); - } - return fn_dgram_socket_start_bus(s); -} - -int wrap_fn_dgram_socket_sub(hcsoftbus lib, void *s, void *topic, int size, int port){ - if (!fn_dgram_socket_sub){ - fn_dgram_socket_sub = (tfn_dgram_socket_sub)dlsym(lib, l_dgram_socket_sub); - check_with_ret(fn_dgram_socket_sub, lib, -1); - } - return fn_dgram_socket_sub(s, topic, size, port); -} - -int wrap_fn_dgram_socket_sub_timeout(hcsoftbus lib, void *s, void *topic, int size, int port, int sec, int usec){ - if (!fn_dgram_socket_sub_timeout){ - fn_dgram_socket_sub_timeout = (tfn_dgram_socket_sub_timeout)dlsym(lib, l_dgram_socket_sub_timeout); - check_with_ret(fn_dgram_socket_sub_timeout, lib, -1); - } - return fn_dgram_socket_sub_timeout(s, topic, size, port, sec, usec); -} - -int wrap_fn_dgram_socket_sub_nowait(hcsoftbus lib, void *s, void *topic, int size, int port){ - if (!fn_dgram_socket_sub_nowait){ - fn_dgram_socket_sub_nowait = (tfn_dgram_socket_sub_nowait)dlsym(lib, l_dgram_socket_sub_nowait); - check_with_ret(fn_dgram_socket_sub_nowait, lib, -1); - } - return fn_dgram_socket_sub_nowait(s, topic, size, port); -} - -int wrap_fn_dgram_socket_desub(hcsoftbus lib, void *s, void *topic, int size, int port){ - if (!fn_dgram_socket_desub){ - fn_dgram_socket_desub = (tfn_dgram_socket_desub)dlsym(lib, l_dgram_socket_desub); - check_with_ret(fn_dgram_socket_desub, lib, -1); - } - return fn_dgram_socket_desub(s, topic, size, port); -} - -int wrap_fn_dgram_socket_desub_timeout(hcsoftbus lib, void *s, void *topic, int size, int port, int sec, int usec){ - if (!fn_dgram_socket_desub_timeout){ - fn_dgram_socket_desub_timeout = (tfn_dgram_socket_desub_timeout)dlsym(lib, l_dgram_socket_desub_timeout); - check_with_ret(fn_dgram_socket_desub_timeout, lib, -1); - } - return fn_dgram_socket_desub_timeout(s, topic, size, port, sec, usec); -} - -int wrap_fn_dgram_socket_desub_nowait(hcsoftbus lib, void *s, void *topic, int size, int port){ - if (!fn_dgram_socket_desub_nowait){ - fn_dgram_socket_desub_nowait = (tfn_dgram_socket_desub_nowait)dlsym(lib, l_dgram_socket_desub_nowait); - check_with_ret(fn_dgram_socket_desub_nowait, lib, -1); - } - return fn_dgram_socket_desub_nowait(s, topic, size, port); -} - -int wrap_fn_dgram_socket_pub(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port){ - if (!fn_dgram_socket_pub){ - fn_dgram_socket_pub = (tfn_dgram_socket_pub)dlsym(lib, l_dgram_socket_pub); - check_with_ret(fn_dgram_socket_pub, lib, -1); - } - return fn_dgram_socket_pub(s, topic, tsize, content, csize, port); -} - -int wrap_fn_dgram_socket_pub_timeout(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port, int sec, int usec){ - if (!fn_dgram_socket_pub_timeout){ - fn_dgram_socket_pub_timeout = (tfn_dgram_socket_pub_timeout)dlsym(lib, l_dgram_socket_pub_timeout); - check_with_ret(fn_dgram_socket_pub_timeout, lib, -1); - } - return fn_dgram_socket_pub_timeout(s, topic, tsize, content, csize, port, sec, usec); -} - -int wrap_fn_dgram_socket_pub_nowait(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port){ - if (!fn_dgram_socket_pub_nowait){ - fn_dgram_socket_pub_nowait = (tfn_dgram_socket_pub_nowait)dlsym(lib, l_dgram_socket_pub_nowait); - check_with_ret(fn_dgram_socket_pub_nowait, lib, -1); - } - return fn_dgram_socket_pub_nowait(s, topic, tsize, content, csize, port); -} - -int wrap_fn_dgram_socket_port(hcsoftbus lib, void *s){ - if (!fn_dgram_socket_port){ - fn_dgram_socket_port = (tfn_dgram_socket_port)dlsym(lib, l_dgram_socket_port); - check_with_ret(fn_dgram_socket_port, lib, -1); - } - return fn_dgram_socket_port(s); -} - -void wrap_fn_dgram_socket_free(hcsoftbus lib, void *buf){ - if (!fn_dgram_socket_free){ - fn_dgram_socket_free = (tfn_dgram_socket_free)dlsym(lib, l_dgram_socket_free); - } - if (fn_dgram_socket_free){ - fn_dgram_socket_free(buf); - }else{ - free(buf); - } -} - -int wrap_fn_dgram_remove_key(hcsoftbus lib, int key){ - if (!fn_dgram_remove_key){ - fn_dgram_remove_key = (tfn_dgram_remove_key)dlsym(lib, l_dgram_remove_key); - check_with_ret(fn_dgram_remove_key, lib, -1); - } - return fn_dgram_remove_key(key); -} - -int wrap_fn_dgram_remove_keys(hcsoftbus lib, void *keys, int length){ - if (!fn_dgram_remove_keys){ - fn_dgram_remove_keys = (tfn_dgram_remove_keys)dlsym(lib, l_dgram_remove_keys); - check_with_ret(fn_dgram_remove_keys, lib, -1); - } - return fn_dgram_remove_keys((int*)keys, length); -} \ No newline at end of file diff --git a/libcsoftbus.h b/libcsoftbus.h deleted file mode 100644 index 2597108..0000000 --- a/libcsoftbus.h +++ /dev/null @@ -1,226 +0,0 @@ -#ifndef _c_libshm_queue_so_go_wrapper_h_ -#define _c_libshm_queue_so_go_wrapper_h_ - -#include "libcsoftbus_func.h" -#include <stddef.h> - -#ifdef __cplusplus -extern "C"{ -#endif - -// shm manipulate -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_rm_dead_queue fn_shm_rm_dead_queue = NULL; - -// shm queue create drop -static tfn_queue_create fn_queue_create = NULL; -static tfn_queue_attach fn_queue_attach = NULL; -static tfn_queue_drop fn_queue_drop = NULL; - -// shm queue size -static tfn_queue_size fn_queue_size = NULL; -static tfn_queue_full fn_queue_full = NULL; -static tfn_queue_empty fn_queue_empty = NULL; - -// shm queue push -static tfn_queue_push fn_queue_push = NULL; -static tfn_queue_push_nowait fn_queue_push_nowait = NULL; -static tfn_queue_push_timeout fn_queue_push_timeout = NULL; - -// shm queue pop -static tfn_queue_pop fn_queue_pop = NULL; -static tfn_queue_pop_nowait fn_queue_pop_nowait = NULL; -static tfn_queue_pop_timeout fn_queue_pop_timeout = NULL; -static tfn_queue_free_poped fn_queue_free_poped = NULL; - -// socket mode -static tfn_socket_open fn_socket_open = NULL; -static tfn_socket_close fn_socket_close = NULL; -static tfn_socket_bind fn_socket_bind = NULL; -static tfn_socket_listen fn_socket_listen = NULL; -static tfn_socket_connect fn_socket_connect = NULL; -static tfn_socket_send fn_socket_send = NULL; -static tfn_socket_recv fn_socket_recv = NULL; -static tfn_socket_buf_free fn_socket_buf_free = NULL; -static tfn_socket_port fn_socket_port = NULL; - -// dgram mode socket -static tfn_dgram_socket_open fn_dgram_socket_open = NULL; -static tfn_dgram_socket_close fn_dgram_socket_close = NULL; -static tfn_dgram_socket_bind fn_dgram_socket_bind = NULL; -static tfn_dgram_socket_force_bind fn_dgram_socket_force_bind = NULL; -static tfn_dgram_socket_sendto fn_dgram_socket_sendto = NULL; -static tfn_dgram_socket_sendto_timeout fn_dgram_socket_sendto_timeout = NULL; -static tfn_dgram_socket_sendto_nowait fn_dgram_socket_sendto_nowait = NULL; -static tfn_dgram_socket_recvfrom fn_dgram_socket_recvfrom = NULL; -static tfn_dgram_socket_recvfrom_timeout fn_dgram_socket_recvfrom_timeout = NULL; -static tfn_dgram_socket_recvfrom_nowait fn_dgram_socket_recvfrom_nowait = NULL; -static tfn_dgram_socket_sendandrecv fn_dgram_socket_sendandrecv = NULL; -static tfn_dgram_socket_sendandrecv_timeout fn_dgram_socket_sendandrecv_timeout = NULL; -static tfn_dgram_socket_sendandrecv_nowait fn_dgram_socket_sendandrecv_nowait = NULL; -static tfn_dgram_socket_start_bus fn_dgram_socket_start_bus = NULL; -static tfn_dgram_socket_sub fn_dgram_socket_sub = NULL; -static tfn_dgram_socket_sub_timeout fn_dgram_socket_sub_timeout = NULL; -static tfn_dgram_socket_sub_nowait fn_dgram_socket_sub_nowait = NULL; -static tfn_dgram_socket_desub fn_dgram_socket_desub = NULL; -static tfn_dgram_socket_desub_timeout fn_dgram_socket_desub_timeout = NULL; -static tfn_dgram_socket_desub_nowait fn_dgram_socket_desub_nowait = NULL; -static tfn_dgram_socket_pub fn_dgram_socket_pub = NULL; -static tfn_dgram_socket_pub_timeout fn_dgram_socket_pub_timeout = NULL; -static tfn_dgram_socket_pub_nowait fn_dgram_socket_pub_nowait = NULL; -static tfn_dgram_socket_port fn_dgram_socket_port = NULL; -static tfn_dgram_socket_free fn_dgram_socket_free = NULL; -static tfn_dgram_remove_key fn_dgram_remove_key = NULL; -static tfn_dgram_remove_keys fn_dgram_remove_keys = NULL; -////////////////////////////////////////////////////////////////////// - -// labels -// shm -const static char l_shm_init[] = "shm_init"; -const static char l_shm_alloc_key[] = "shm_alloc_key"; -const static char l_shm_destroy[] = "shm_destroy"; -const static char l_shm_rm_dead_queue[] = "shm_remove_queues_exclude"; - -// queue -const static char l_queue_create[] = "shmqueue_create"; -const static char l_queue_attach[] = "shmqueue_attach"; -const static char l_queue_drop[] = "shmqueue_drop"; - -// queue size -const static char l_queue_size[] = "shmqueue_size"; -const static char l_queue_full[] = "shmqueue_full"; -const static char l_queue_empty[] = "shmqueue_empty"; - -// queue push -const static char l_queue_push[] = "shmqueue_push"; -const static char l_queue_push_nowait[] = "shmqueue_push_nowait"; -const static char l_queue_push_timeout[] = "shmqueue_push_timeout"; - -// queue pop -const static char l_queue_pop[] = "shmqueue_pop"; -const static char l_queue_pop_nowait[] = "shmqueue_pop_nowait"; -const static char l_queue_pop_timeout[] = "shmqueue_pop_timeout"; -const static char l_queue_free_poped[] = "shmqueue_free"; - -// mode socket -const static char l_socket_open[] = "mod_open_socket"; -const static char l_socket_close[] = "mod_close_socket"; -const static char l_socket_bind[] = "mod_socket_bind"; -const static char l_socket_listen[] = "mod_listen"; -const static char l_socket_connect[] = "mod_connect"; -const static char l_socket_send[] = "mod_send"; -const static char l_socket_recv[] = "mod_recv"; -const static char l_socket_free[] = "mod_free"; -const static char l_socket_port[] = "mod_get_socket_port"; - -// dgram mode socket -const static char l_dgram_socket_open[] = "dgram_mod_open_socket"; -const static char l_dgram_socket_close[] = "dgram_mod_close_socket"; -const static char l_dgram_socket_bind[] = "dgram_mod_bind"; -const static char l_dgram_socket_force_bind[] = "dgram_mod_force_bind"; -const static char l_dgram_socket_sendto[] = "dgram_mod_sendto"; -const static char l_dgram_socket_sendto_timeout[] = "dgram_mod_sendto_timeout"; -const static char l_dgram_socket_sendto_nowait[] = "dgram_mod_sendto_nowait"; -const static char l_dgram_socket_recvfrom[] = "dgram_mod_recvfrom"; -const static char l_dgram_socket_recvfrom_timeout[] = "dgram_mod_recvfrom_timeout"; -const static char l_dgram_socket_recvfrom_nowait[] = "dgram_mod_recvfrom_nowait"; -const static char l_dgram_socket_sendandrecv[] = "dgram_mod_sendandrecv"; -const static char l_dgram_socket_sendandrecv_timeout[] = "dgram_mod_sendandrecv_timeout"; -const static char l_dgram_socket_sendandrecv_nowait[] = "dgram_mod_sendandrecv_nowait"; -const static char l_dgram_socket_start_bus[] = "dgram_mod_start_bus"; -const static char l_dgram_socket_sub[] = "dgram_mod_sub"; -const static char l_dgram_socket_sub_timeout[] = "dgram_mod_sub_timeout"; -const static char l_dgram_socket_sub_nowait[] = "dgram_mod_sub_nowait"; -const static char l_dgram_socket_desub[] = "dgram_mod_desub"; -const static char l_dgram_socket_desub_timeout[] = "dgram_mod_desub_timeout"; -const static char l_dgram_socket_desub_nowait[] = "dgram_mod_desub_nowait"; -const static char l_dgram_socket_pub[] = "dgram_mod_pub"; -const static char l_dgram_socket_pub_timeout[] = "dgram_mod_pub_timeout"; -const static char l_dgram_socket_pub_nowait[] = "dgram_mod_pub_nowait"; -const static char l_dgram_socket_port[] = "dgram_mod_get_port"; -const static char l_dgram_socket_free[] = "dgram_mod_free"; -const static char l_dgram_remove_key[] = "dgram_mod_remove_key"; -const static char l_dgram_remove_keys[] = "dgram_mod_remove_keys"; -////////////////////////////////////////////////////////////////////// - -// dlopen dynamic library -typedef void* hcsoftbus; -hcsoftbus c_softbus_handle(const char *so); -void c_softbus_release(hcsoftbus lib); - -// shm manipulate -void wrap_fn_shm_init(hcsoftbus lib, int size); -int wrap_fn_shm_alloc_key(hcsoftbus lib); -void wrap_fn_shm_destroy(hcsoftbus lib); -void wrap_fn_shm_rm_dead_queue(hcsoftbus lib, void *array, int len); - -// queue create/drop -void* wrap_fn_queue_create(hcsoftbus lib, int *key, int queue_size); -void* wrap_fn_queue_attach(hcsoftbus lib, int key); -void wrap_fn_queue_drop(hcsoftbus lib, void* shmq); - -// queue size -int wrap_fn_queue_size(hcsoftbus lib, void *shmq); -int wrap_fn_queue_full(hcsoftbus lib, void *shmq); -int wrap_fn_queue_empty(hcsoftbus lib, void *shmq); - -// queue push -int wrap_fn_queue_push(hcsoftbus lib, void *shmq, void *ele, int ele_size); -int wrap_fn_queue_push_nowait(hcsoftbus lib, void *shmq, void *ele, int ele_size); -int wrap_fn_queue_push_timeout(hcsoftbus lib, void *shmq, void *ele, int ele_size, int sec, int nsec); - -// queue pop -int wrap_fn_queue_pop(hcsoftbus lib, void *shmq, void **ele, int *ele_size); -int wrap_fn_queue_pop_nowait(hcsoftbus lib, void *shmq, void **ele, int *ele_size); -int wrap_fn_queue_pop_timeout(hcsoftbus lib, void *shmq, void **ele, int *ele_size, int sec, int nsec); -void wrap_fn_queue_free_poped(hcsoftbus lib, void *ptr); - -///////////////////////////////////////////////////////// -// socket mode -void *wrap_fn_socket_open(hcsoftbus lib, int mod); -int wrap_fn_socket_close(hcsoftbus lib, void* s); -int wrap_fn_socket_bind(hcsoftbus lib, void *s, int port); -int wrap_fn_socket_listen(hcsoftbus lib, void *s); -int wrap_fn_socket_connect(hcsoftbus lib, void *s, int port); -int wrap_fn_socket_send(hcsoftbus lib, void *s, const void *buf, const int size); -int wrap_fn_socket_recv(hcsoftbus lib, void *s, void **buf, int *size); -void wrap_fn_socket_buf_free(hcsoftbus lib, void *buf); -int wrap_fn_socket_port(hcsoftbus lib, void *s); - -///////////////////////////////////////////////////////// -// dgram socket mode -void *wrap_fn_dgram_socket_open(hcsoftbus lib); -int wrap_fn_dgram_socket_close(hcsoftbus lib, void *s); -int wrap_fn_dgram_socket_bind(hcsoftbus lib, void *s, int port); -int wrap_fn_dgram_socket_force_bind(hcsoftbus lib, void *s, int port); -int wrap_fn_dgram_socket_sendto(hcsoftbus lib, void *s, const void *buf, const int size, const int port); -int wrap_fn_dgram_socket_sendto_timeout(hcsoftbus lib, void *s, const void *buf, const int size, const int port, int sec, int usec); -int wrap_fn_dgram_socket_sendto_nowait(hcsoftbus lib, void *s, const void *buf, const int size, const int port); -int wrap_fn_dgram_socket_recvfrom(hcsoftbus lib, void *s, void **buf, int *size, int *port); -int wrap_fn_dgram_socket_recvfrom_timeout(hcsoftbus lib, void *s, void **buf, int *size, int *port, int sec, int usec); -int wrap_fn_dgram_socket_recvfrom_nowait(hcsoftbus lib, void *s, void **buf, int *size, int *port); -int wrap_fn_dgram_socket_sendandrecv(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize); -int wrap_fn_dgram_socket_sendandrecv_timeout(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize, int sec, int usec); -int wrap_fn_dgram_socket_sendandrecv_nowait(hcsoftbus lib, void *s, const void *sbuf, const int ssize, const int port, void **rbuf, int *rsize); -int wrap_fn_dgram_socket_start_bus(hcsoftbus lib, void *s); -int wrap_fn_dgram_socket_sub(hcsoftbus lib, void *s, void *topic, int size, int port); -int wrap_fn_dgram_socket_sub_timeout(hcsoftbus lib, void *s, void *topic, int size, int port, int sec, int usec); -int wrap_fn_dgram_socket_sub_nowait(hcsoftbus lib, void *s, void *topic, int size, int port); -int wrap_fn_dgram_socket_desub(hcsoftbus lib, void *s, void *topic, int size, int port); -int wrap_fn_dgram_socket_desub_timeout(hcsoftbus lib, void *s, void *topic, int size, int port, int sec, int usec); -int wrap_fn_dgram_socket_desub_nowait(hcsoftbus lib, void *s, void *topic, int size, int port); -int wrap_fn_dgram_socket_pub(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port); -int wrap_fn_dgram_socket_pub_timeout(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port, int sec, int usec); -int wrap_fn_dgram_socket_pub_nowait(hcsoftbus lib, void *s, void *topic, int tsize, void *content, int csize, int port); -int wrap_fn_dgram_socket_port(hcsoftbus lib, void *s); -void wrap_fn_dgram_socket_free(hcsoftbus lib, void *buf); -int wrap_fn_dgram_remove_key(hcsoftbus lib, int key); -int wrap_fn_dgram_remove_keys(hcsoftbus lib, void *keys, int length); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/libcsoftbus_func.h b/libcsoftbus_func.h deleted file mode 100644 index f73826a..0000000 --- a/libcsoftbus_func.h +++ /dev/null @@ -1,255 +0,0 @@ -#ifndef _c_libshm_queue_so_func_h_ -#define _c_libshm_queue_so_func_h_ - - -#ifdef __cplusplus -extern "C"{ -#endif - -/** - * 鍒濆鍖栧叡浜唴瀛� - * @size 鍏变韩鍐呭瓨澶у皬 - * - */ -typedef void(*tfn_shm_init)(int); -/** - * 閿�姣佸叡浜唴瀛� - * 鏁翠釜杩涚▼閫�鍑烘椂闇�瑕佹墽琛岃繖涓柟娉曪紝璇ユ柟娉曢鍏堜細妫�鏌ユ槸鍚﹁繕鏈夊叾浠栬繘绋嬪湪浣跨敤璇ュ叡浜唴瀛橈紝濡傛灉杩樻湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ氨鍙槸detach,濡傛灉娌℃湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ垯閿�姣佹暣鍧楀唴瀛樸�� - */ -typedef void(*tfn_shm_destroy)(); -/** - * 鑾峰彇key - */ -typedef int(*tfn_shm_alloc_key) (); - -//绉婚櫎涓嶅寘鍚湪keys涓殑闃熷垪 -typedef void (*tfn_shm_rm_dead_queue)(void *keys, int length); - -/** - * 鍒涘缓闃熷垪 - * @ shmqueue - * @ key 鏍囪瘑鍏变韩闃熷垪鐨勫敮涓�鏍囪瘑, key鏄竴涓寚閽堥噷闈㈠瓨鍌ㄤ簡key鐨勫�硷紝 濡傛灉key鐨勫�间负-1绯荤粺浼氳嚜鍔ㄥ垎閰嶄竴涓猭ey鍊煎苟鎶婅key鐨勫�艰祴缁檏ey鎸囬拡銆傚鏋渒ey鐨勫�间笉浼氱┖浼氭鏌ユ槸鍚︽湁閲嶅缁戝畾鐨勬儏鍐�, 鏈夐噸澶嶅氨鎶ラ敊娌℃湁灏卞垱寤洪槦鍒楀苟缁戝畾key. - * @ queue_size 闃熷垪澶у皬 - */ -typedef void*(*tfn_queue_create) (int*, int); -/** - * 缁戝畾key鍒伴槦鍒楋紝浣嗘槸骞朵笉浼氬垱寤洪槦鍒椼�傚鏋滄病鏈夊搴旀寚瀹歬ey鐨勯槦鍒楁彁绀洪敊璇苟杩斿洖绌哄�� - */ -typedef void*(*tfn_queue_attach) (int); -/** - * 閿�姣� -*/ -typedef void(*tfn_queue_drop) (void*); -/** - * 闃熷垪鍏冪礌鐨勪釜鏁� - */ -typedef int(*tfn_queue_size) (void*); -/** - * 鏄惁宸叉弧 - * * @return 1鏄紝 0鍚� - */ -typedef int(*tfn_queue_full) (void*); -/** - * 鏄惁涓虹┖ - * @return 1鏄紝 0鍚� - */ -typedef int(*tfn_queue_empty) (void*); -/** - * 鍏ラ槦, 闃熷垪婊℃椂绛夊緟. - * @return 1 鍏ラ槦鎴愬姛, 0 鍏ラ槦澶辫触 - */ -typedef int(*tfn_queue_push) (void*, void*, int); -/** - * 鍏ラ槦, 闃熷垪婊℃椂绔嬪嵆杩斿洖. - * @return 1 鍏ラ槦鎴愬姛, 0 鍏ラ槦澶辫触 - */ -typedef tfn_queue_push tfn_queue_push_nowait; -/** - * 鍏ラ槦, 鎸囧畾鏃堕棿鍐呭叆闃熶笉鎴愬姛灏辫繑鍥� - * @sec 绉� - * @nsec 绾崇 - * @return 1 鍏ラ槦鎴愬姛, 0 鍏ラ槦澶辫触 - */ -typedef int(*tfn_queue_push_timeout) (void*, void*, int, int, int); -/** - * 鍑洪槦, 闃熷垪绌烘椂绛夊緟 - * @return 1 鍑洪槦鎴愬姛锛� 0鍑洪槦澶辫触 - */ -typedef int(*tfn_queue_pop) (void*, void**, int *); -/** - * 鍑洪槦, 闃熷垪绌烘椂绔嬪嵆杩斿洖 - * @return 1 鍑洪槦鎴愬姛锛� 0鍑洪槦澶辫触 - */ -typedef tfn_queue_pop tfn_queue_pop_nowait; -/** - * 鍑洪槦, 鎸囧畾鏃堕棿鍐呭嚭闃熶笉鎴愬姛灏辫繑鍥� - * @sec绉� - * @nsec绾崇 - * @return 1 鍑洪槦鎴愬姛锛� 0鍑洪槦澶辫触 - */ -typedef int(*tfn_queue_pop_timeout) (void*, void**, int *, int, int); -/** - * 閲婃斁鍑洪槦鍒嗛厤鐨勫唴瀛� - */ -typedef void (*tfn_queue_free_poped)(void *ptr); - -//////////////////////////// -// socket mode -//////////////////////////// -enum socket_mod_t -{ - PULL_PUSH = 1, - REQ_REP = 2, - PAIR = 3, - PUB_SUB = 4, - SURVEY = 5, - BUS = 6 - -}; - -/** - * 鍒涘缓socket - * @return socket鍦板潃 -*/ -typedef void*(*tfn_socket_open) (int); -/** - * 鍏抽棴socket -*/ -typedef int(*tfn_socket_close) (void*); -/** - * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_socket_bind) (void*, int); -/** - * 鏈嶅姟绔紑鍚繛鎺ョ洃鍚� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 - */ -typedef int(*tfn_socket_listen) (void*); -/** - * 瀹㈡埛绔彂璧疯繛鎺ヨ姹� - */ -typedef int(*tfn_socket_connect) (void*, int); -/** - * 鍙戦�佷俊鎭� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 - */ -typedef int(*tfn_socket_send) (void*, const void*, const int); -/** - * 鎺ユ敹淇℃伅 - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_socket_recv) (void*, void**, int*); - -/** - * 閲婃斁鎺ユ敹淇℃伅鐨刡uf - */ -typedef void(*tfn_socket_buf_free) (void*); - -/** - * 鑾峰彇soket绔彛鍙� - */ -typedef int(*tfn_socket_port) (void*); - -////////////////////////////////////////////// -// dgram socket -/** - * 鍒涘缓socket - * @return socket鍦板潃 -*/ -typedef void*(*tfn_dgram_socket_open) (); -/** - * 鍏抽棴socket - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_dgram_socket_close) (void*); -/** - * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_dgram_socket_bind) (void*, int); -typedef tfn_dgram_socket_bind tfn_dgram_socket_force_bind; -/** - * 鍙戦�佷俊鎭� - * @port 鍙戦�佺粰璋� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 - */ -typedef int(*tfn_dgram_socket_sendto) (void*, const void*, const int, const int); -// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇 -typedef int(*tfn_dgram_socket_sendto_timeout) (void*, const void*, const int, const int, int, int); -// 鍙戦�佷俊鎭珛鍒昏繑鍥炪�� -typedef tfn_dgram_socket_sendto tfn_dgram_socket_sendto_nowait; -/** - * 鎺ユ敹淇℃伅 - * @port 浠庤皝鍝噷鏀跺埌鐨勪俊鎭� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_dgram_socket_recvfrom) (void*, void**, int*, int*); -typedef int(*tfn_dgram_socket_recvfrom_timeout) (void*, void**, int*, int*, int, int); -typedef tfn_dgram_socket_recvfrom tfn_dgram_socket_recvfrom_nowait; -/** - * 鍙戦�佽姹備俊鎭苟绛夊緟鎺ユ敹搴旂瓟 - * @port 鍙戦�佺粰璋� - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_dgram_socket_sendandrecv) (void*, const void*, const int, const int, void**, int*); -typedef int(*tfn_dgram_socket_sendandrecv_timeout) (void*, const void*, const int, const int, void**, int*, int, int); -typedef tfn_dgram_socket_sendandrecv tfn_dgram_socket_sendandrecv_nowait; -/** - * 鍚姩bus - * - * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜 -*/ -typedef int(*tfn_dgram_socket_start_bus) (void*); -/** - * 璁㈤槄鎸囧畾涓婚 - * @topic 涓婚 - * @size 涓婚闀垮害 - * @port 鎬荤嚎绔彛 - */ -typedef int(*tfn_dgram_socket_sub) (void*, void*, int, int); -typedef int(*tfn_dgram_socket_sub_timeout) (void*, void*, int, int, int, int); -typedef tfn_dgram_socket_sub tfn_dgram_socket_sub_nowait; -/** - * 鍙栨秷璁㈤槄鎸囧畾涓婚 - * @topic 涓婚 - * @size 涓婚闀垮害 - * @port 鎬荤嚎绔彛 - */ -typedef tfn_dgram_socket_sub tfn_dgram_socket_desub; -typedef tfn_dgram_socket_sub_timeout tfn_dgram_socket_desub_timeout; -typedef tfn_dgram_socket_sub_nowait tfn_dgram_socket_desub_nowait; -/** - * 鍙戝竷涓婚 - * @topic 涓婚 - * @content 涓婚鍐呭 - * @port 鎬荤嚎绔彛 - */ -typedef int(*tfn_dgram_socket_pub) (void*, void*, int, void*, int, int); -typedef int(*tfn_dgram_socket_pub_timeout) (void*, void*, int, void*, int, int, int, int); -typedef tfn_dgram_socket_pub tfn_dgram_socket_pub_nowait; -/** - * 鑾峰彇soket绔彛鍙� - */ -typedef int(*tfn_dgram_socket_port) (void*); -/** - * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf - */ -typedef void(*tfn_dgram_socket_free) (void*); - -/** - * 鍒犻櫎key瀵瑰簲鐨勫叡浜槦鍒楋紝骞跺湪bus閲屽垹闄よkey鐨勮闃� - */ - -typedef int(*tfn_dgram_remove_key) (int); -/** - * 鎵归噺鍒犻櫎key瀵瑰簲鐨勫叡浜槦鍒楋紝骞跺湪bus閲屽垹闄よkey鐨勮闃� - */ -typedef int(*tfn_dgram_remove_keys) (int*, int); - - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/library.go b/library.go deleted file mode 100644 index 489d2e9..0000000 --- a/library.go +++ /dev/null @@ -1,415 +0,0 @@ -package softbus - -import ( - "context" - "fmt" - "sync" - "time" - - "github.com/golang/protobuf/proto" -) - -const ( - // RegKey fixed key for hb to servermanager - RegKey = 12 - // GetTopicInfoTypeTopic topic - GetTopicInfoTypeTopic = "gettopic" - // GetTopicInfoTypeChannel channel - GetTopicInfoTypeChannel = "getchannel" -) - -type sockServer struct { - sock *DgramSocket - info *ProcInfo -} - -type sockClient struct { - sock *DgramSocket - peer int -} - -// TransInfo 浼犺緭鐨勬暟鎹拰蹇呰鐨勮褰� -type TransInfo struct { - info *MsgInfo - port int -} - -// Handle handler -/* -sockHB/sockPub/sockWorker鍙互浣跨敤涓�涓猻ocket -浣嗘槸鐢变簬闇�瑕佹敮鎸佸绾跨▼涓斿績璺�/鍙戝竷閮芥槸寰堥噸瑕佺殑淇℃伅,鍗曠嫭涓�涓猻ocket澶勭悊 -worker澶勭悊鐭椂鐨勫彂閫� -*/ -type Handle struct { - ctx context.Context - wg *sync.WaitGroup - // 鍒涘缓channel瀵瑰簲鐨剅eply,绛夊緟璇诲彇鍏朵腑鐨勫唴瀹�,server - m map[string]*sockServer - // 鍒涘缓reply鏈嶅姟Request鍑芥暟 - sockRep *sockServer - // 鍒涘缓蹇冭烦杩炴帴,client,浠呭彂閫佸績璺充俊鎭� - // 蹇冭烦闇�瑕佷繚璇佸崟鐙殑socket鍙戦��,濡傛灉璺熷叾浠栧叡鐢╯ocket,濡傛灉闃诲灏辨棤娉曞彂閫� - sockHB *sockClient - // 鍒涘缓鏇存柊涓婚杩炴帴,client,浠呭彂閫佷富棰樻洿鏂颁俊鎭� - // 鍙戦�佹湰韬殑pub淇℃伅,寰堝彲鑳藉叾浠栬繘绋嬩緷璧�,闇�瑕佸崟鐙瑂ocket澶勭悊 - sockPub *sockClient - // 鍒涘缓璁㈤槄鐨剆ocket - // 璁㈤槄鐨勪富棰榩eer鍙戦�佺殑娑堟伅 - sockSub *sockClient - // 鍒涘缓涓�涓竾鑳絪ocket鍙戦�佺粰浠绘剰server - sockWorker *sockClient - // 澶氱嚎绋� - mtxWorker sync.Mutex - - // GetMessge瀹炵幇闇�瑕佺殑缂撳瓨 - chSub chan TransInfo - chReply chan TransInfo -} - -const ( - routineSub = "sub" - routineReply = "reply" -) - -// 璁㈤槄娑堟伅鎴杛eply鎺ユ敹鐨凴equest璇锋眰娑堟伅,閫氳繃缂撳瓨鐢ㄤ簬GetMessage鑾峰彇 -func recvRoutine(ctx context.Context, sock *DgramSocket, wg *sync.WaitGroup, ch chan<- TransInfo, id string) { - for { - select { - case <-ctx.Done(): - wg.Done() - return - default: - if data, peer, err := sock.RecvFromTimeout(0, 10*1000); err == nil { - var info MsgInfo - if err := proto.Unmarshal(data, &info); err == nil { - ch <- TransInfo{ - info: &info, - port: peer, - } - - // if id == routineReply { - // fmt.Println("repley server recv:", info) - // } - } - } else { - // time.Sleep(10 * time.Millisecond) - } - } - } -} - -// Register firstly register to manager -func Register(ctx context.Context, info *RegisterInfo) *Handle { - m := make(map[string]*sockServer) - - // 棣栧厛璇锋眰涓�鍫唊ey, 鍖呮嫭reply/sub/pub/topic/heartbeat - sockReg := OpenDgramSocket() - if sockReg == nil { - return nil - } - defer sockReg.Close() - - var msg, rdata []byte - var err error -loop: - for { - select { - case <-ctx.Done(): - return nil - default: - - if msg == nil { - if msg, err = proto.Marshal(info); err != nil { - time.Sleep(100 * time.Millisecond) - continue - } - } - if rdata, err = sockReg.SendAndRecv(msg, RegKey); err == nil { - break loop - } else { - time.Sleep(100 * time.Millisecond) - } - } - } - - // 寰楀埌key - var regReply RegisterInfoReply - if err := proto.Unmarshal(rdata, ®Reply); err != nil { - return nil - } - - // 鏀跺彂req/rep channel, server - // channels瀵瑰簲鐨剆erver,閮芥槸reply - for _, v := range info.Channel { - if k, ok := regReply.ChannelKey[v]; ok { - s := OpenDgramSocket() - s.Bind(int(k)) - m[v] = &sockServer{ - sock: s, - info: info.ProcInfo, - } - } - } - - wg := &sync.WaitGroup{} - - // 鍒涘缓sub/reply鏈嶅姟缂撳瓨 - chSize := 5 - chSub := make(chan TransInfo, chSize) - chReply := make(chan TransInfo, chSize) - - // reply server, 鏈嶅姟Request - sockReply := OpenDgramSocket() - sockReply.Bind(int(regReply.ReplyKey)) - // 鍚姩鎺ユ敹绾跨▼ - wg.Add(1) - go recvRoutine(ctx, sockReply, wg, chReply, routineReply) - repS := &sockServer{ - sock: sockReply, - info: info.ProcInfo, - } - - // heartbeat client, 鍗曠嫭浣跨敤涓�涓猻ocket鍙戦�佸績璺� - sockHB := OpenDgramSocket() - hbC := &sockClient{ - sock: sockHB, - peer: int(regReply.HeartbeatKey), - } - - // pub client, 鍗曠嫭浣跨敤涓�涓彂甯冧富棰� - sockPub := OpenDgramSocket() - pubC := &sockClient{ - sock: sockPub, - peer: int(regReply.UpdateTopicKey), - } - - // sub client, 鍏辩敤涓�涓猻ocket - sockSub := OpenDgramSocket() - // sockSub.Bind(int(regReply.SubTopicKey)) - // 璁㈤槄鎵�鏈変富棰� - for _, v := range info.SubTopic { - sockSub.Sub(v, int(regReply.SubTopicKey)) - } - // 鍚姩鎺ユ敹绾跨▼ - wg.Add(1) - go recvRoutine(ctx, sockSub, wg, chSub, routineSub) - subC := &sockClient{ - sock: sockSub, - peer: -1, - } - - // 涓囪兘socket,浠呬綔涓哄鎴风浣跨敤, 鎴栬�呰幏鍙杢opic key, 淇濆瓨topic鏈嶅姟鍣ㄧ殑key - sockW := OpenDgramSocket() - uniC := &sockClient{ - sock: sockW, - peer: int(regReply.GetTopicKey), - } - handle := &Handle{ - ctx: ctx, - wg: wg, - m: m, - sockHB: hbC, - sockPub: pubC, - sockSub: subC, - sockRep: repS, - sockWorker: uniC, - chSub: chSub, - chReply: chReply, - } - - return handle -} - -// Free free -func (h *Handle) Free() { - h.wg.Wait() - - for _, v := range h.m { - v.sock.Close() - } - h.sockHB.sock.Close() - h.sockHB = nil - h.sockPub.sock.Close() - h.sockPub = nil - h.sockSub.sock.Close() - h.sockSub = nil - h.sockRep.sock.Close() - h.sockRep = nil - h.sockWorker.sock.Close() - h.sockWorker = nil - - fmt.Println("Handle Safe Free") -} - -const ( - timeoutSec = 1 - timeoutUsec = 0 -) - -// GetTopicInfo get topic info -func (h *Handle) GetTopicInfo(topic, typ string) int { - // 鎹涓嶆洿鏂�,鍏堢敤缂撳瓨,鍚﹀垯浠巑anager璇锋眰key - // ***k - if v, ok := h.m[topic]; ok { - return v.sock.Port() - } - // 杩滅▼鑾峰彇 - msg := &TopicInfo{ - Topic: topic, - TopicType: typ, - } - if data, err := proto.Marshal(msg); err == nil { - h.mtxWorker.Lock() - if rdata, err := h.sockWorker.sock.SendAndRecvTimeout(data, h.sockWorker.peer, timeoutSec, timeoutUsec); err == nil { - h.mtxWorker.Unlock() - var rmsg TopicInfoReply - if err := proto.Unmarshal(rdata, &rmsg); err == nil { - return int(rmsg.Key) - } - } - h.mtxWorker.Unlock() - } - return -1 -} - -func (h *Handle) send2(sc *sockClient, data []byte, logID string) error { - if r := sc.sock.SendToTimeout(data, sc.peer, timeoutSec, timeoutUsec); r != 0 { - return fmt.Errorf("%s SendTo Failed: %d", logID, r) - } - return nil -} - -// HeartBeat hb -func (h *Handle) HeartBeat(info *HeartbeatInfo) error { - msg, err := proto.Marshal(info) - if err == nil { - return h.send2(h.sockHB, msg, "HeartBeat") - } - return err -} - -// SendOnly no recv -func (h *Handle) SendOnly(key int, info *MsgInfo) error { - h.mtxWorker.Lock() - defer h.mtxWorker.Unlock() - msg, err := proto.Marshal(info) - if err == nil { - if r := h.sockWorker.sock.SendToTimeout(msg, key, timeoutSec, timeoutUsec); r != 0 { - return fmt.Errorf("SendOnly Failed: %d", r) - } - } - return err -} - -// Pub func -func (h *Handle) Pub(info *MsgInfo) error { - msg, err := proto.Marshal(info) - if err == nil { - return h.send2(h.sockPub, msg, "Pub") - } - return err -} - -// Request req sync -func (h *Handle) Request(key int, info *MsgInfo) *MsgInfo { - h.mtxWorker.Lock() - defer h.mtxWorker.Unlock() - - msg, err := proto.Marshal(info) - if err != nil { - return nil - } - - // 鍚屾鎺ュ彛,闇�瑕佺瓑寰呰繑鍥炲�� - var ret MsgInfo -loop: - for { - select { - case <-h.ctx.Done(): - return nil - default: - if data, err := h.sockWorker.sock.SendAndRecvTimeout(msg, key, timeoutSec, timeoutUsec); err == nil { - if err := proto.Unmarshal(data, &ret); err == nil { - break loop - } - } - } - } - return &ret -} - -// RequestWithTimeout req sync -func (h *Handle) RequestWithTimeout(key int, info *MsgInfo, timeout int) *MsgInfo { - h.mtxWorker.Lock() - defer h.mtxWorker.Unlock() - - msg, err := proto.Marshal(info) - if err != nil { - return nil - } - - until := (float32)(timeout) - one := (float32)(timeoutSec) + ((float32)(timeoutUsec) / 1000000) - fc := until / one - - count := (int)(fc) - - try := 0 - - // 鍚屾鎺ュ彛,闇�瑕佺瓑寰呰繑鍥炲�� - var ret MsgInfo -loop: - for { - select { - case <-h.ctx.Done(): - return nil - default: - if data, err := h.sockWorker.sock.SendAndRecvTimeout(msg, key, timeoutSec, timeoutUsec); err == nil { - if err := proto.Unmarshal(data, &ret); err == nil { - break loop - } else { - try++ - if try > count { - return nil - } - } - } else { - try++ - if try > count { - return nil - } - } - } - } - return &ret -} - -// Reply request -func (h *Handle) Reply(key int, info *MsgInfo) error { - msg, err := proto.Marshal(info) - if err == nil { - if r := h.sockRep.sock.SendToTimeout(msg, key, timeoutSec, timeoutUsec); r != 0 { - return fmt.Errorf("Reply Failed: %d", r) - } - } - return err -} - -// GetMesg get mesg for sub or reply -func (h *Handle) GetMesg() (subMsg *MsgInfo, replyMsg *MsgInfo, replyKey int) { - if h.sockHB == nil && h.sockRep == nil && h.sockPub == nil && h.sockSub == nil && h.sockWorker == nil { - return nil, nil, -1 - } - - if len(h.chSub) > 1 { - m := <-h.chSub - subMsg = m.info - } - - if len(h.chReply) > 1 { - m := <-h.chReply - replyMsg = m.info - replyKey = m.port - } - return -} diff --git a/softbus.go b/softbus.go deleted file mode 100644 index 5ae50df..0000000 --- a/softbus.go +++ /dev/null @@ -1,269 +0,0 @@ -package softbus - -/* -#cgo LDFLAGS: -ldl -#include <stdlib.h> -#include "libcsoftbus.h" - -void *get_array(const int size){ - int *arr = (int*)malloc(sizeof(int)*size); - return arr; -} - -void set_array(void *arr, const int index, const int value){ - int *iarr = (int*)arr; - iarr[index] = value; -} -*/ -import "C" -import ( - "errors" - "unsafe" -) - -var libsoftbus C.hcsoftbus - -// Init Dynamic library -func Init(so string) error { - cso := C.CString(so) - defer C.free(unsafe.Pointer(cso)) - - handle := C.c_softbus_handle(cso) - if handle == nil { - // fmt.Errorf("Go SoftBus Init From %s Error\n", so) - return errors.New("Init SoftBus Error") - } - - libsoftbus = handle - return nil -} - -// Release handle of c softbus -func Release() { - if libsoftbus != nil { - C.c_softbus_release(libsoftbus) - } -} - -// ShmInit block size -func ShmInit(size int) error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - C.wrap_fn_shm_init(libsoftbus, C.int(size)) - return nil -} - -// ShmAllocKey alloc key -func ShmAllocKey() int { - if libsoftbus == nil { - return -1 - } - r := C.wrap_fn_shm_alloc_key(libsoftbus) - return int(r) -} - -// ShmDestroy destroy shm block, every softbus proc MUST call it -func ShmDestroy() { - if libsoftbus != nil { - C.wrap_fn_shm_destroy(libsoftbus) - } -} - -// ShmRmDeadQueue remove dead queue but pass live queue keys -func ShmRmDeadQueue(keys []int) error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - if len(keys) == 0 { - C.wrap_fn_shm_rm_dead_queue(libsoftbus, nil, 0) - return nil - } - - l := len(keys) - ca := C.get_array(C.int(l)) - defer C.free(ca) - for k, v := range keys { - C.set_array(ca, C.int(k), C.int(v)) - } - - C.wrap_fn_shm_rm_dead_queue(libsoftbus, ca, C.int(l)) - return nil -} - -// Queue struct wrap shmqueue pointer -type Queue struct { - shmqueue unsafe.Pointer - key int -} - -// Create shm queue -func Create(qSize int) *Queue { - if libsoftbus == nil { - return nil - } - - var key C.int - csb := C.wrap_fn_queue_create(libsoftbus, &key, C.int(qSize)) - if csb != nil { - return &Queue{ - shmqueue: csb, - key: int(key), - } - } - return nil -} - -// Attach shm queue with key -func Attach(key int) *Queue { - if libsoftbus == nil { - return nil - } - - csb := C.wrap_fn_queue_attach(libsoftbus, C.int(key)) - if csb != nil { - return &Queue{ - shmqueue: csb, - key: key, - } - } - - return nil -} - -// Drop shm queue -func (q *Queue) Drop() error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - - C.wrap_fn_queue_drop(libsoftbus, q.shmqueue) - return nil -} - -// Size shm queue -func (q *Queue) Size() int { - if libsoftbus == nil { - return 0 - } - - cs := C.wrap_fn_queue_size(libsoftbus, q.shmqueue) - return int(cs) -} - -// Full shm queue -func (q *Queue) Full() bool { - if libsoftbus == nil { - return true - } - - f := C.wrap_fn_queue_full(libsoftbus, q.shmqueue) - if f != 0 { - return true - } - return false -} - -// Empty shm queue -func (q *Queue) Empty() bool { - if libsoftbus == nil { - return false - } - - f := C.wrap_fn_queue_full(libsoftbus, q.shmqueue) - if f != 0 { - return true - } - return false - -} - -// Push shm queue -func (q *Queue) Push(data []byte) error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - - r := C.wrap_fn_queue_push(libsoftbus, q.shmqueue, unsafe.Pointer(&data[0]), C.int(len(data))) - if r == 0 { - return nil - } - return errors.New("Queue Push Data Error") -} - -// PushNoWait shm queue -func (q *Queue) PushNoWait(data []byte) error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - - r := C.wrap_fn_queue_push_nowait(libsoftbus, q.shmqueue, unsafe.Pointer(&data[0]), C.int(len(data))) - if r == 0 { - return nil - } - return errors.New("Queue PushNoWait Data Error") -} - -// PushTimeout shm queue push with timeout -func (q *Queue) PushTimeout(data []byte, sec, nsec int) error { - if libsoftbus == nil { - return errors.New("C SoftBus Handle Is Nil") - } - - r := C.wrap_fn_queue_push_timeout(libsoftbus, q.shmqueue, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(sec), C.int(nsec)) - if r == 0 { - return nil - } - return errors.New("Queue PushTimeout Data Error") -} - -// Pop from shm queue -func (q *Queue) Pop() ([]byte, error) { - if libsoftbus == nil { - return nil, errors.New("C SoftBus Handle Is Nil") - } - - var data unsafe.Pointer - var size C.int - r := C.wrap_fn_queue_pop(libsoftbus, q.shmqueue, &data, &size) - if r == 0 { - gd := C.GoBytes(data, size) - C.wrap_fn_queue_free_poped(libsoftbus, data) - return gd, nil - } - return nil, errors.New("Queue Pop Data Error") -} - -// PopNoWait from shm queue -func (q *Queue) PopNoWait() ([]byte, error) { - if libsoftbus == nil { - return nil, errors.New("C SoftBus Handle Is Nil") - } - - var data unsafe.Pointer - var size C.int - r := C.wrap_fn_queue_pop_nowait(libsoftbus, q.shmqueue, &data, &size) - if r == 0 { - gd := C.GoBytes(data, size) - C.wrap_fn_queue_free_poped(libsoftbus, data) - return gd, nil - } - return nil, errors.New("Queue Pop Data Error") -} - -// PopTimeout from shm queue -func (q *Queue) PopTimeout(sec, nsec int) ([]byte, error) { - if libsoftbus == nil { - return nil, errors.New("C SoftBus Handle Is Nil") - } - - var data unsafe.Pointer - var size C.int - r := C.wrap_fn_queue_pop_timeout(libsoftbus, q.shmqueue, &data, &size, C.int(sec), C.int(nsec)) - if r == 0 { - gd := C.GoBytes(data, size) - C.wrap_fn_queue_free_poped(libsoftbus, data) - return gd, nil - } - return nil, errors.New("Queue Pop Data Error") -} diff --git a/softbus.pb.go b/softbus.pb.go deleted file mode 100644 index 4f63e7d..0000000 --- a/softbus.pb.go +++ /dev/null @@ -1,2815 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: softbus.proto - -package softbus - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - io "io" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -// 杩涚▼鍩烘湰淇℃伅 -type ProcInfo struct { - ServerID string `protobuf:"bytes,1,opt,name=serverID,proto3" json:"serverID,omitempty"` - BoardID string `protobuf:"bytes,2,opt,name=boardID,proto3" json:"boardID,omitempty"` - ServerIP string `protobuf:"bytes,3,opt,name=serverIP,proto3" json:"serverIP,omitempty"` - ProcName string `protobuf:"bytes,4,opt,name=procName,proto3" json:"procName,omitempty"` - ProcID string `protobuf:"bytes,5,opt,name=procID,proto3" json:"procID,omitempty"` - ProcLabel string `protobuf:"bytes,6,opt,name=procLabel,proto3" json:"procLabel,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ProcInfo) Reset() { *m = ProcInfo{} } -func (m *ProcInfo) String() string { return proto.CompactTextString(m) } -func (*ProcInfo) ProtoMessage() {} -func (*ProcInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{0} -} -func (m *ProcInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ProcInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ProcInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ProcInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_ProcInfo.Merge(m, src) -} -func (m *ProcInfo) XXX_Size() int { - return m.Size() -} -func (m *ProcInfo) XXX_DiscardUnknown() { - xxx_messageInfo_ProcInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_ProcInfo proto.InternalMessageInfo - -func (m *ProcInfo) GetServerID() string { - if m != nil { - return m.ServerID - } - return "" -} - -func (m *ProcInfo) GetBoardID() string { - if m != nil { - return m.BoardID - } - return "" -} - -func (m *ProcInfo) GetServerIP() string { - if m != nil { - return m.ServerIP - } - return "" -} - -func (m *ProcInfo) GetProcName() string { - if m != nil { - return m.ProcName - } - return "" -} - -func (m *ProcInfo) GetProcID() string { - if m != nil { - return m.ProcID - } - return "" -} - -func (m *ProcInfo) GetProcLabel() string { - if m != nil { - return m.ProcLabel - } - return "" -} - -type RegisterInfo struct { - ProcInfo *ProcInfo `protobuf:"bytes,1,opt,name=procInfo,proto3" json:"procInfo,omitempty"` - Channel []string `protobuf:"bytes,2,rep,name=channel,proto3" json:"channel,omitempty"` - PubTopic []string `protobuf:"bytes,3,rep,name=pubTopic,proto3" json:"pubTopic,omitempty"` - SubTopic []string `protobuf:"bytes,4,rep,name=subTopic,proto3" json:"subTopic,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RegisterInfo) Reset() { *m = RegisterInfo{} } -func (m *RegisterInfo) String() string { return proto.CompactTextString(m) } -func (*RegisterInfo) ProtoMessage() {} -func (*RegisterInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{1} -} -func (m *RegisterInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RegisterInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RegisterInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RegisterInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_RegisterInfo.Merge(m, src) -} -func (m *RegisterInfo) XXX_Size() int { - return m.Size() -} -func (m *RegisterInfo) XXX_DiscardUnknown() { - xxx_messageInfo_RegisterInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_RegisterInfo proto.InternalMessageInfo - -func (m *RegisterInfo) GetProcInfo() *ProcInfo { - if m != nil { - return m.ProcInfo - } - return nil -} - -func (m *RegisterInfo) GetChannel() []string { - if m != nil { - return m.Channel - } - return nil -} - -func (m *RegisterInfo) GetPubTopic() []string { - if m != nil { - return m.PubTopic - } - return nil -} - -func (m *RegisterInfo) GetSubTopic() []string { - if m != nil { - return m.SubTopic - } - return nil -} - -type RegisterInfoReply struct { - ProcInfo *ProcInfo `protobuf:"bytes,1,opt,name=procInfo,proto3" json:"procInfo,omitempty"` - ChannelKey map[string]int32 `protobuf:"bytes,2,rep,name=channelKey,proto3" json:"channelKey,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - HeartbeatKey int32 `protobuf:"varint,3,opt,name=heartbeatKey,proto3" json:"heartbeatKey,omitempty"` - SubTopicKey int32 `protobuf:"varint,4,opt,name=subTopicKey,proto3" json:"subTopicKey,omitempty"` - UpdateTopicKey int32 `protobuf:"varint,5,opt,name=updateTopicKey,proto3" json:"updateTopicKey,omitempty"` - ReplyKey int32 `protobuf:"varint,6,opt,name=replyKey,proto3" json:"replyKey,omitempty"` - GetTopicKey int32 `protobuf:"varint,7,opt,name=getTopicKey,proto3" json:"getTopicKey,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RegisterInfoReply) Reset() { *m = RegisterInfoReply{} } -func (m *RegisterInfoReply) String() string { return proto.CompactTextString(m) } -func (*RegisterInfoReply) ProtoMessage() {} -func (*RegisterInfoReply) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{2} -} -func (m *RegisterInfoReply) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *RegisterInfoReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_RegisterInfoReply.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *RegisterInfoReply) XXX_Merge(src proto.Message) { - xxx_messageInfo_RegisterInfoReply.Merge(m, src) -} -func (m *RegisterInfoReply) XXX_Size() int { - return m.Size() -} -func (m *RegisterInfoReply) XXX_DiscardUnknown() { - xxx_messageInfo_RegisterInfoReply.DiscardUnknown(m) -} - -var xxx_messageInfo_RegisterInfoReply proto.InternalMessageInfo - -func (m *RegisterInfoReply) GetProcInfo() *ProcInfo { - if m != nil { - return m.ProcInfo - } - return nil -} - -func (m *RegisterInfoReply) GetChannelKey() map[string]int32 { - if m != nil { - return m.ChannelKey - } - return nil -} - -func (m *RegisterInfoReply) GetHeartbeatKey() int32 { - if m != nil { - return m.HeartbeatKey - } - return 0 -} - -func (m *RegisterInfoReply) GetSubTopicKey() int32 { - if m != nil { - return m.SubTopicKey - } - return 0 -} - -func (m *RegisterInfoReply) GetUpdateTopicKey() int32 { - if m != nil { - return m.UpdateTopicKey - } - return 0 -} - -func (m *RegisterInfoReply) GetReplyKey() int32 { - if m != nil { - return m.ReplyKey - } - return 0 -} - -func (m *RegisterInfoReply) GetGetTopicKey() int32 { - if m != nil { - return m.GetTopicKey - } - return 0 -} - -type TopicInfo struct { - Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"` - TopicType string `protobuf:"bytes,2,opt,name=topicType,proto3" json:"topicType,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *TopicInfo) Reset() { *m = TopicInfo{} } -func (m *TopicInfo) String() string { return proto.CompactTextString(m) } -func (*TopicInfo) ProtoMessage() {} -func (*TopicInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{3} -} -func (m *TopicInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *TopicInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_TopicInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *TopicInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_TopicInfo.Merge(m, src) -} -func (m *TopicInfo) XXX_Size() int { - return m.Size() -} -func (m *TopicInfo) XXX_DiscardUnknown() { - xxx_messageInfo_TopicInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_TopicInfo proto.InternalMessageInfo - -func (m *TopicInfo) GetTopic() string { - if m != nil { - return m.Topic - } - return "" -} - -func (m *TopicInfo) GetTopicType() string { - if m != nil { - return m.TopicType - } - return "" -} - -type TopicInfoReply struct { - Info *TopicInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"` - Key int32 `protobuf:"varint,2,opt,name=key,proto3" json:"key,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *TopicInfoReply) Reset() { *m = TopicInfoReply{} } -func (m *TopicInfoReply) String() string { return proto.CompactTextString(m) } -func (*TopicInfoReply) ProtoMessage() {} -func (*TopicInfoReply) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{4} -} -func (m *TopicInfoReply) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *TopicInfoReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_TopicInfoReply.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *TopicInfoReply) XXX_Merge(src proto.Message) { - xxx_messageInfo_TopicInfoReply.Merge(m, src) -} -func (m *TopicInfoReply) XXX_Size() int { - return m.Size() -} -func (m *TopicInfoReply) XXX_DiscardUnknown() { - xxx_messageInfo_TopicInfoReply.DiscardUnknown(m) -} - -var xxx_messageInfo_TopicInfoReply proto.InternalMessageInfo - -func (m *TopicInfoReply) GetInfo() *TopicInfo { - if m != nil { - return m.Info - } - return nil -} - -func (m *TopicInfoReply) GetKey() int32 { - if m != nil { - return m.Key - } - return 0 -} - -type HeartbeatInfo struct { - HealthLevel string `protobuf:"bytes,1,opt,name=healthLevel,proto3" json:"healthLevel,omitempty"` - Fps int32 `protobuf:"varint,2,opt,name=fps,proto3" json:"fps,omitempty"` - WarnInfo string `protobuf:"bytes,3,opt,name=warnInfo,proto3" json:"warnInfo,omitempty"` - ErrorInfo string `protobuf:"bytes,4,opt,name=errorInfo,proto3" json:"errorInfo,omitempty"` - OtherInfo []byte `protobuf:"bytes,5,opt,name=otherInfo,proto3" json:"otherInfo,omitempty"` - OtherInfoSize int32 `protobuf:"varint,6,opt,name=otherInfoSize,proto3" json:"otherInfoSize,omitempty"` - ProcInfo *ProcInfo `protobuf:"bytes,7,opt,name=procInfo,proto3" json:"procInfo,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *HeartbeatInfo) Reset() { *m = HeartbeatInfo{} } -func (m *HeartbeatInfo) String() string { return proto.CompactTextString(m) } -func (*HeartbeatInfo) ProtoMessage() {} -func (*HeartbeatInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{5} -} -func (m *HeartbeatInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeartbeatInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HeartbeatInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HeartbeatInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeartbeatInfo.Merge(m, src) -} -func (m *HeartbeatInfo) XXX_Size() int { - return m.Size() -} -func (m *HeartbeatInfo) XXX_DiscardUnknown() { - xxx_messageInfo_HeartbeatInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_HeartbeatInfo proto.InternalMessageInfo - -func (m *HeartbeatInfo) GetHealthLevel() string { - if m != nil { - return m.HealthLevel - } - return "" -} - -func (m *HeartbeatInfo) GetFps() int32 { - if m != nil { - return m.Fps - } - return 0 -} - -func (m *HeartbeatInfo) GetWarnInfo() string { - if m != nil { - return m.WarnInfo - } - return "" -} - -func (m *HeartbeatInfo) GetErrorInfo() string { - if m != nil { - return m.ErrorInfo - } - return "" -} - -func (m *HeartbeatInfo) GetOtherInfo() []byte { - if m != nil { - return m.OtherInfo - } - return nil -} - -func (m *HeartbeatInfo) GetOtherInfoSize() int32 { - if m != nil { - return m.OtherInfoSize - } - return 0 -} - -func (m *HeartbeatInfo) GetProcInfo() *ProcInfo { - if m != nil { - return m.ProcInfo - } - return nil -} - -type MsgInfo struct { - SrcProc *ProcInfo `protobuf:"bytes,1,opt,name=srcProc,proto3" json:"srcProc,omitempty"` - MsgType string `protobuf:"bytes,2,opt,name=msgType,proto3" json:"msgType,omitempty"` - Topic string `protobuf:"bytes,3,opt,name=topic,proto3" json:"topic,omitempty"` - ShmKey int32 `protobuf:"varint,4,opt,name=shmKey,proto3" json:"shmKey,omitempty"` - Body []byte `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` - BodyLen int32 `protobuf:"varint,6,opt,name=bodyLen,proto3" json:"bodyLen,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *MsgInfo) Reset() { *m = MsgInfo{} } -func (m *MsgInfo) String() string { return proto.CompactTextString(m) } -func (*MsgInfo) ProtoMessage() {} -func (*MsgInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_61abf516b68179fd, []int{6} -} -func (m *MsgInfo) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgInfo.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgInfo.Merge(m, src) -} -func (m *MsgInfo) XXX_Size() int { - return m.Size() -} -func (m *MsgInfo) XXX_DiscardUnknown() { - xxx_messageInfo_MsgInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgInfo proto.InternalMessageInfo - -func (m *MsgInfo) GetSrcProc() *ProcInfo { - if m != nil { - return m.SrcProc - } - return nil -} - -func (m *MsgInfo) GetMsgType() string { - if m != nil { - return m.MsgType - } - return "" -} - -func (m *MsgInfo) GetTopic() string { - if m != nil { - return m.Topic - } - return "" -} - -func (m *MsgInfo) GetShmKey() int32 { - if m != nil { - return m.ShmKey - } - return 0 -} - -func (m *MsgInfo) GetBody() []byte { - if m != nil { - return m.Body - } - return nil -} - -func (m *MsgInfo) GetBodyLen() int32 { - if m != nil { - return m.BodyLen - } - return 0 -} - -func init() { - proto.RegisterType((*ProcInfo)(nil), "softbus.ProcInfo") - proto.RegisterType((*RegisterInfo)(nil), "softbus.RegisterInfo") - proto.RegisterType((*RegisterInfoReply)(nil), "softbus.RegisterInfoReply") - proto.RegisterMapType((map[string]int32)(nil), "softbus.RegisterInfoReply.ChannelKeyEntry") - proto.RegisterType((*TopicInfo)(nil), "softbus.TopicInfo") - proto.RegisterType((*TopicInfoReply)(nil), "softbus.TopicInfoReply") - proto.RegisterType((*HeartbeatInfo)(nil), "softbus.HeartbeatInfo") - proto.RegisterType((*MsgInfo)(nil), "softbus.MsgInfo") -} - -func init() { proto.RegisterFile("softbus.proto", fileDescriptor_61abf516b68179fd) } - -var fileDescriptor_61abf516b68179fd = []byte{ - // 593 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xd1, 0x8a, 0xd3, 0x5c, - 0x10, 0xfe, 0xd3, 0x36, 0xcd, 0xee, 0xb4, 0xdd, 0x7f, 0xf7, 0xb0, 0x2c, 0x61, 0x91, 0x52, 0x82, - 0x2c, 0xa2, 0xd8, 0x8b, 0xf5, 0x46, 0x04, 0x11, 0xb4, 0x82, 0x5d, 0xab, 0x94, 0xb8, 0x2f, 0x90, - 0xb4, 0xd3, 0xa6, 0x98, 0x26, 0xe1, 0x24, 0xad, 0xc4, 0x97, 0xf0, 0xd6, 0x87, 0x10, 0x9f, 0xc3, - 0x4b, 0x1f, 0x41, 0xea, 0x0b, 0x78, 0xeb, 0x9d, 0xcc, 0xe4, 0x9c, 0x24, 0x5d, 0x11, 0xf1, 0x6e, - 0xbe, 0x99, 0xef, 0xcc, 0xf9, 0xe6, 0xcc, 0x97, 0x40, 0x2f, 0x8d, 0x17, 0x99, 0xbf, 0x49, 0x87, - 0x89, 0x8c, 0xb3, 0x58, 0x58, 0x0a, 0x3a, 0x9f, 0x0d, 0x38, 0x98, 0xca, 0x78, 0x36, 0x8e, 0x16, - 0xb1, 0x38, 0x87, 0x83, 0x14, 0xe5, 0x16, 0xe5, 0x78, 0x64, 0x1b, 0x03, 0xe3, 0xce, 0xa1, 0x5b, - 0x62, 0x61, 0x83, 0xe5, 0xc7, 0x9e, 0x9c, 0x8f, 0x47, 0x76, 0x83, 0x4b, 0x1a, 0xd6, 0x4e, 0x4d, - 0xed, 0xe6, 0xde, 0xa9, 0x29, 0xd5, 0x12, 0x19, 0xcf, 0x5e, 0x7b, 0x6b, 0xb4, 0x5b, 0x45, 0x4d, - 0x63, 0x71, 0x06, 0x6d, 0x8a, 0xc7, 0x23, 0xdb, 0xe4, 0x8a, 0x42, 0xe2, 0x16, 0x1c, 0x52, 0x34, - 0xf1, 0x7c, 0x0c, 0xed, 0x36, 0x97, 0xaa, 0x84, 0xf3, 0xc1, 0x80, 0xae, 0x8b, 0xcb, 0x55, 0x9a, - 0xa1, 0x64, 0xd1, 0xf7, 0x8b, 0x2b, 0x28, 0x66, 0xd1, 0x9d, 0xcb, 0x93, 0xa1, 0x1e, 0x56, 0x4f, - 0xe6, 0x96, 0x14, 0x9a, 0x63, 0x16, 0x78, 0x51, 0x84, 0xa1, 0xdd, 0x18, 0x34, 0x69, 0x0e, 0x05, - 0x59, 0xeb, 0xc6, 0xbf, 0x8e, 0x93, 0xd5, 0xcc, 0x6e, 0x72, 0xa9, 0xc4, 0x3c, 0xa3, 0xae, 0xb5, - 0x8a, 0x9a, 0xc6, 0xce, 0xcf, 0x06, 0x9c, 0xd4, 0x15, 0xb9, 0x98, 0x84, 0xf9, 0xbf, 0xca, 0xba, - 0x02, 0x50, 0x3a, 0x5e, 0x62, 0xce, 0xca, 0x3a, 0x97, 0x77, 0xcb, 0x03, 0xbf, 0xb5, 0x1f, 0x3e, - 0x2b, 0xc9, 0xcf, 0xa3, 0x4c, 0xe6, 0x6e, 0xed, 0xb4, 0x70, 0xa0, 0x1b, 0xa0, 0x27, 0x33, 0x1f, - 0xbd, 0x8c, 0xba, 0xd1, 0x52, 0x4c, 0x77, 0x2f, 0x27, 0x06, 0xd0, 0xd1, 0x03, 0x10, 0xa5, 0xc5, - 0x94, 0x7a, 0x4a, 0x5c, 0xc0, 0xd1, 0x26, 0x99, 0x7b, 0x19, 0x96, 0x24, 0x93, 0x49, 0x37, 0xb2, - 0xf4, 0x34, 0x92, 0x24, 0x11, 0xa3, 0xcd, 0x8c, 0x12, 0xd3, 0x2d, 0x4b, 0xcc, 0xca, 0x06, 0x56, - 0x71, 0x4b, 0x2d, 0x75, 0xfe, 0x18, 0xfe, 0xbf, 0x31, 0x8a, 0x38, 0x86, 0xe6, 0x5b, 0xcc, 0x95, - 0x01, 0x29, 0x14, 0xa7, 0x60, 0x6e, 0xbd, 0x70, 0x83, 0xec, 0x3c, 0xd3, 0x2d, 0xc0, 0xa3, 0xc6, - 0x43, 0xc3, 0x79, 0x02, 0x87, 0xdc, 0x8a, 0xdf, 0xf0, 0x14, 0xcc, 0x8c, 0x37, 0x54, 0x1c, 0x2d, - 0x00, 0xd9, 0x89, 0x83, 0xeb, 0x3c, 0x41, 0x65, 0xdd, 0x2a, 0xe1, 0x5c, 0xc1, 0x51, 0xd9, 0xa0, - 0x58, 0xdc, 0x05, 0xb4, 0x56, 0xd5, 0xd2, 0x44, 0xb9, 0x83, 0x8a, 0xc6, 0x75, 0x2d, 0xb3, 0x90, - 0x44, 0xa1, 0xf3, 0xc3, 0x80, 0xde, 0x0b, 0xfd, 0xc8, 0xac, 0x68, 0x00, 0x9d, 0x00, 0xbd, 0x30, - 0x0b, 0x26, 0xb8, 0xc5, 0x50, 0xe9, 0xaa, 0xa7, 0xa8, 0xcb, 0x22, 0x49, 0x75, 0x97, 0x45, 0x92, - 0xd2, 0x7b, 0xbe, 0xf3, 0x64, 0xc4, 0xc6, 0x51, 0x9f, 0x93, 0xc6, 0x34, 0x0b, 0x4a, 0x19, 0xb3, - 0x0f, 0xd4, 0xf7, 0x54, 0x25, 0xa8, 0x1a, 0x67, 0x41, 0xe1, 0x12, 0x5e, 0x56, 0xd7, 0xad, 0x12, - 0xe2, 0x36, 0xf4, 0x4a, 0xf0, 0x66, 0xf5, 0x1e, 0xd5, 0xb2, 0xf6, 0x93, 0x7b, 0xb6, 0xb5, 0xfe, - 0x6a, 0x5b, 0xe7, 0x93, 0x01, 0xd6, 0xab, 0x74, 0xc9, 0x17, 0xdc, 0x03, 0x2b, 0x95, 0x33, 0x22, - 0xfd, 0xd9, 0xf0, 0x9a, 0x41, 0x9f, 0xe1, 0x3a, 0x5d, 0xd6, 0x76, 0xa2, 0x61, 0xb5, 0xc5, 0x66, - 0x7d, 0x8b, 0x67, 0xd0, 0x4e, 0x83, 0x75, 0x65, 0x55, 0x85, 0x84, 0x80, 0x96, 0x1f, 0xcf, 0x73, - 0x35, 0x2e, 0xc7, 0xc5, 0xaf, 0x6a, 0x9e, 0x4f, 0x30, 0x52, 0x33, 0x6a, 0xf8, 0xf4, 0xf8, 0xcb, - 0xae, 0x6f, 0x7c, 0xdd, 0xf5, 0x8d, 0x6f, 0xbb, 0xbe, 0xf1, 0xf1, 0x7b, 0xff, 0x3f, 0xbf, 0xcd, - 0xff, 0xc3, 0x07, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x65, 0x52, 0xb8, 0x9f, 0x20, 0x05, 0x00, - 0x00, -} - -func (m *ProcInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProcInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.ServerID) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ServerID))) - i += copy(dAtA[i:], m.ServerID) - } - if len(m.BoardID) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.BoardID))) - i += copy(dAtA[i:], m.BoardID) - } - if len(m.ServerIP) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ServerIP))) - i += copy(dAtA[i:], m.ServerIP) - } - if len(m.ProcName) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ProcName))) - i += copy(dAtA[i:], m.ProcName) - } - if len(m.ProcID) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ProcID))) - i += copy(dAtA[i:], m.ProcID) - } - if len(m.ProcLabel) > 0 { - dAtA[i] = 0x32 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ProcLabel))) - i += copy(dAtA[i:], m.ProcLabel) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *RegisterInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RegisterInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ProcInfo != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.ProcInfo.Size())) - n1, err1 := m.ProcInfo.MarshalTo(dAtA[i:]) - if err1 != nil { - return 0, err1 - } - i += n1 - } - if len(m.Channel) > 0 { - for _, s := range m.Channel { - dAtA[i] = 0x12 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.PubTopic) > 0 { - for _, s := range m.PubTopic { - dAtA[i] = 0x1a - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if len(m.SubTopic) > 0 { - for _, s := range m.SubTopic { - dAtA[i] = 0x22 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *RegisterInfoReply) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *RegisterInfoReply) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.ProcInfo != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.ProcInfo.Size())) - n2, err2 := m.ProcInfo.MarshalTo(dAtA[i:]) - if err2 != nil { - return 0, err2 - } - i += n2 - } - if len(m.ChannelKey) > 0 { - for k, _ := range m.ChannelKey { - dAtA[i] = 0x12 - i++ - v := m.ChannelKey[k] - mapSize := 1 + len(k) + sovSoftbus(uint64(len(k))) + 1 + sovSoftbus(uint64(v)) - i = encodeVarintSoftbus(dAtA, i, uint64(mapSize)) - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(k))) - i += copy(dAtA[i:], k) - dAtA[i] = 0x10 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(v)) - } - } - if m.HeartbeatKey != 0 { - dAtA[i] = 0x18 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.HeartbeatKey)) - } - if m.SubTopicKey != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.SubTopicKey)) - } - if m.UpdateTopicKey != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.UpdateTopicKey)) - } - if m.ReplyKey != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.ReplyKey)) - } - if m.GetTopicKey != 0 { - dAtA[i] = 0x38 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.GetTopicKey)) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *TopicInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TopicInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.Topic) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.Topic))) - i += copy(dAtA[i:], m.Topic) - } - if len(m.TopicType) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.TopicType))) - i += copy(dAtA[i:], m.TopicType) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *TopicInfoReply) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *TopicInfoReply) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.Info != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.Info.Size())) - n3, err3 := m.Info.MarshalTo(dAtA[i:]) - if err3 != nil { - return 0, err3 - } - i += n3 - } - if m.Key != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.Key)) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *HeartbeatInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HeartbeatInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.HealthLevel) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.HealthLevel))) - i += copy(dAtA[i:], m.HealthLevel) - } - if m.Fps != 0 { - dAtA[i] = 0x10 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.Fps)) - } - if len(m.WarnInfo) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.WarnInfo))) - i += copy(dAtA[i:], m.WarnInfo) - } - if len(m.ErrorInfo) > 0 { - dAtA[i] = 0x22 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.ErrorInfo))) - i += copy(dAtA[i:], m.ErrorInfo) - } - if len(m.OtherInfo) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.OtherInfo))) - i += copy(dAtA[i:], m.OtherInfo) - } - if m.OtherInfoSize != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.OtherInfoSize)) - } - if m.ProcInfo != nil { - dAtA[i] = 0x3a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.ProcInfo.Size())) - n4, err4 := m.ProcInfo.MarshalTo(dAtA[i:]) - if err4 != nil { - return 0, err4 - } - i += n4 - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func (m *MsgInfo) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgInfo) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.SrcProc != nil { - dAtA[i] = 0xa - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.SrcProc.Size())) - n5, err5 := m.SrcProc.MarshalTo(dAtA[i:]) - if err5 != nil { - return 0, err5 - } - i += n5 - } - if len(m.MsgType) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.MsgType))) - i += copy(dAtA[i:], m.MsgType) - } - if len(m.Topic) > 0 { - dAtA[i] = 0x1a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.Topic))) - i += copy(dAtA[i:], m.Topic) - } - if m.ShmKey != 0 { - dAtA[i] = 0x20 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.ShmKey)) - } - if len(m.Body) > 0 { - dAtA[i] = 0x2a - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(len(m.Body))) - i += copy(dAtA[i:], m.Body) - } - if m.BodyLen != 0 { - dAtA[i] = 0x30 - i++ - i = encodeVarintSoftbus(dAtA, i, uint64(m.BodyLen)) - } - if m.XXX_unrecognized != nil { - i += copy(dAtA[i:], m.XXX_unrecognized) - } - return i, nil -} - -func encodeVarintSoftbus(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func (m *ProcInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ServerID) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.BoardID) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.ServerIP) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.ProcName) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.ProcID) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.ProcLabel) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *RegisterInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ProcInfo != nil { - l = m.ProcInfo.Size() - n += 1 + l + sovSoftbus(uint64(l)) - } - if len(m.Channel) > 0 { - for _, s := range m.Channel { - l = len(s) - n += 1 + l + sovSoftbus(uint64(l)) - } - } - if len(m.PubTopic) > 0 { - for _, s := range m.PubTopic { - l = len(s) - n += 1 + l + sovSoftbus(uint64(l)) - } - } - if len(m.SubTopic) > 0 { - for _, s := range m.SubTopic { - l = len(s) - n += 1 + l + sovSoftbus(uint64(l)) - } - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *RegisterInfoReply) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ProcInfo != nil { - l = m.ProcInfo.Size() - n += 1 + l + sovSoftbus(uint64(l)) - } - if len(m.ChannelKey) > 0 { - for k, v := range m.ChannelKey { - _ = k - _ = v - mapEntrySize := 1 + len(k) + sovSoftbus(uint64(len(k))) + 1 + sovSoftbus(uint64(v)) - n += mapEntrySize + 1 + sovSoftbus(uint64(mapEntrySize)) - } - } - if m.HeartbeatKey != 0 { - n += 1 + sovSoftbus(uint64(m.HeartbeatKey)) - } - if m.SubTopicKey != 0 { - n += 1 + sovSoftbus(uint64(m.SubTopicKey)) - } - if m.UpdateTopicKey != 0 { - n += 1 + sovSoftbus(uint64(m.UpdateTopicKey)) - } - if m.ReplyKey != 0 { - n += 1 + sovSoftbus(uint64(m.ReplyKey)) - } - if m.GetTopicKey != 0 { - n += 1 + sovSoftbus(uint64(m.GetTopicKey)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *TopicInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Topic) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.TopicType) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *TopicInfoReply) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Info != nil { - l = m.Info.Size() - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.Key != 0 { - n += 1 + sovSoftbus(uint64(m.Key)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *HeartbeatInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.HealthLevel) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.Fps != 0 { - n += 1 + sovSoftbus(uint64(m.Fps)) - } - l = len(m.WarnInfo) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.ErrorInfo) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.OtherInfo) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.OtherInfoSize != 0 { - n += 1 + sovSoftbus(uint64(m.OtherInfoSize)) - } - if m.ProcInfo != nil { - l = m.ProcInfo.Size() - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *MsgInfo) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.SrcProc != nil { - l = m.SrcProc.Size() - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.MsgType) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - l = len(m.Topic) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.ShmKey != 0 { - n += 1 + sovSoftbus(uint64(m.ShmKey)) - } - l = len(m.Body) - if l > 0 { - n += 1 + l + sovSoftbus(uint64(l)) - } - if m.BodyLen != 0 { - n += 1 + sovSoftbus(uint64(m.BodyLen)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovSoftbus(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozSoftbus(x uint64) (n int) { - return sovSoftbus(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *ProcInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProcInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProcInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ServerID", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ServerID = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BoardID", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BoardID = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ServerIP", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ServerIP = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcName", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ProcName = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcID", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ProcID = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcLabel", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ProcLabel = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RegisterInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RegisterInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RegisterInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ProcInfo == nil { - m.ProcInfo = &ProcInfo{} - } - if err := m.ProcInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Channel = append(m.Channel, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PubTopic", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PubTopic = append(m.PubTopic, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SubTopic", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SubTopic = append(m.SubTopic, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *RegisterInfoReply) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: RegisterInfoReply: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: RegisterInfoReply: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ProcInfo == nil { - m.ProcInfo = &ProcInfo{} - } - if err := m.ProcInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChannelKey", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ChannelKey == nil { - m.ChannelKey = make(map[string]int32) - } - var mapkey string - var mapvalue int32 - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthSoftbus - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthSoftbus - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else { - iNdEx = entryPreIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - m.ChannelKey[mapkey] = mapvalue - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field HeartbeatKey", wireType) - } - m.HeartbeatKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.HeartbeatKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SubTopicKey", wireType) - } - m.SubTopicKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SubTopicKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdateTopicKey", wireType) - } - m.UpdateTopicKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.UpdateTopicKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ReplyKey", wireType) - } - m.ReplyKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ReplyKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GetTopicKey", wireType) - } - m.GetTopicKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GetTopicKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TopicInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TopicInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TopicInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Topic", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Topic = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TopicType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TopicType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *TopicInfoReply) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: TopicInfoReply: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: TopicInfoReply: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Info", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Info == nil { - m.Info = &TopicInfo{} - } - if err := m.Info.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - m.Key = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Key |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HeartbeatInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HeartbeatInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeartbeatInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HealthLevel", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.HealthLevel = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Fps", wireType) - } - m.Fps = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Fps |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field WarnInfo", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.WarnInfo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ErrorInfo", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ErrorInfo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field OtherInfo", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.OtherInfo = append(m.OtherInfo[:0], dAtA[iNdEx:postIndex]...) - if m.OtherInfo == nil { - m.OtherInfo = []byte{} - } - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field OtherInfoSize", wireType) - } - m.OtherInfoSize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.OtherInfoSize |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProcInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ProcInfo == nil { - m.ProcInfo = &ProcInfo{} - } - if err := m.ProcInfo.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgInfo) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgInfo: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgInfo: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SrcProc", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.SrcProc == nil { - m.SrcProc = &ProcInfo{} - } - if err := m.SrcProc.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.MsgType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Topic", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Topic = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ShmKey", wireType) - } - m.ShmKey = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ShmKey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSoftbus - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSoftbus - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Body = append(m.Body[:0], dAtA[iNdEx:postIndex]...) - if m.Body == nil { - m.Body = []byte{} - } - iNdEx = postIndex - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BodyLen", wireType) - } - m.BodyLen = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSoftbus - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.BodyLen |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipSoftbus(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthSoftbus - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSoftbus(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSoftbus - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSoftbus - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSoftbus - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthSoftbus - } - iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthSoftbus - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSoftbus - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipSoftbus(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthSoftbus - } - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthSoftbus = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSoftbus = fmt.Errorf("proto: integer overflow") -) diff --git a/softbus.proto b/softbus.proto deleted file mode 100644 index ce076f8..0000000 --- a/softbus.proto +++ /dev/null @@ -1,59 +0,0 @@ -syntax = "proto3"; - -package softbus; - -// 杩涚▼鍩烘湰淇℃伅 -message ProcInfo{ - string serverID = 1;// 鏈哄櫒ID - string boardID = 2;// 鏉垮崱ID - string serverIP = 3;// 鏈哄櫒IP - string procName = 4;// 杩涚▼鍚嶇О - string procID = 5;// 杩涚▼鍞竴鏍囪瘑 - string procLabel = 6;// 杩涚▼鐨勬弿杩颁俊鎭紝鐢ㄤ簬鍖哄垎鍚屼竴杩涚▼鍚嶇О涓嬪涓繘绋� -} - -message RegisterInfo{ - ProcInfo procInfo = 1;// 杩涚▼鐨勪俊鎭� - repeated string channel = 2;// 鏂板棰戦亾锛屽搴斾竴涓柊鐨勫叡浜唴瀛橀槦鍒� - repeated string pubTopic = 3;// 杩涚▼瀵瑰鍙戝竷鐨勬湇鍔′富棰� - repeated string subTopic = 4;// 杩涚▼璁㈤槄鐨勬湇鍔′富棰� -} - -message RegisterInfoReply{ - ProcInfo procInfo = 1;//杩涚▼淇℃伅 - map<string, int32> channelKey = 2; - int32 heartbeatKey = 3; - int32 subTopicKey = 4; - int32 updateTopicKey = 5; - int32 replyKey = 6; - int32 getTopicKey = 7; -} - -message TopicInfo{ - string topic = 1; - string topicType = 2; -} - -message TopicInfoReply{ - TopicInfo info = 1; - int32 key = 2; -} - -message HeartbeatInfo { - string healthLevel = 1;// 鍋ュ悍绛夌骇 - int32 fps = 2;// 澶勭悊甯х巼(dec瑙g爜甯х巼銆乻dk澶勭悊甯х巼) - string warnInfo = 3;// 鎶ヨ淇℃伅 - string errorInfo = 4;// 閿欒淇℃伅 - bytes otherInfo = 5;// 鍏朵粬鐗规湁淇℃伅锛屽鏈夐渶瑕佸氨鐢ㄨ繖涓� - int32 otherInfoSize = 6;// 鍏朵粬鐗规湁淇℃伅闀垮害 - ProcInfo procInfo = 7; //杩涚▼淇℃伅 -} - -message MsgInfo{ - ProcInfo srcProc = 1;// 婧愯繘绋嬪熀鏈俊鎭� - string msgType = 2;// 鏁版嵁绫诲瀷锛屽彲涓鸿姹傘�佸彂甯冦�佽闃呫�佸簲绛旂瓑 - string topic = 3;// 鏈嶅姟涓婚 - int32 shmKey = 4;// 璇锋眰搴旂瓟鏁版嵁浣跨敤鐨刱ey锛屽叾浠栨暟鎹笉鐢紝寰呯‘璁� - bytes body = 5;// 鏁版嵁鍐呭锛屼簩杩涘埗缂栫爜鍚庣殑锛岄渶瑕佺‘瀹氱紪鐮佺被鍨嬪苟瑙g爜 - int32 bodyLen = 6;// 鏁版嵁闀垮害 -} \ No newline at end of file diff --git a/softbusDgram.go b/softbusDgram.go deleted file mode 100644 index ec71b5a..0000000 --- a/softbusDgram.go +++ /dev/null @@ -1,387 +0,0 @@ -package softbus - -/* -#include <stdlib.h> -#include "libcsoftbus.h" -extern void *get_array(const int size); -extern void set_array(void *arr, const int index, const int value); -*/ -import "C" -import ( - "fmt" - "unsafe" -) - -// DgramSocket dgram -type DgramSocket struct { - dgram unsafe.Pointer -} - -// OpenDgramSocket dgram -func OpenDgramSocket() *DgramSocket { - if libsoftbus == nil { - return nil - } - - d := C.wrap_fn_dgram_socket_open(libsoftbus) - if d == nil { - return nil - } - - return &DgramSocket{ - dgram: d, - } -} - -// Close close dgram socket -func (d *DgramSocket) Close() int { - if libsoftbus != nil && d.dgram != nil { - r := C.wrap_fn_dgram_socket_close(libsoftbus, d.dgram) - return int(r) - } - - return RETVAL -} - -// Bind bind -func (d *DgramSocket) Bind(port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_bind(libsoftbus, d.dgram, C.int(port)) - return int(r) -} - -// ForceBind bind -func (d *DgramSocket) ForceBind(port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_force_bind(libsoftbus, d.dgram, C.int(port)) - return int(r) -} - -// SendTo port -func (d *DgramSocket) SendTo(data []byte, port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_sendto(libsoftbus, d.dgram, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(port)) - return int(r) -} - -// SendToTimeout port -func (d *DgramSocket) SendToTimeout(data []byte, port int, sec, usec int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_sendto_timeout(libsoftbus, d.dgram, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(port), C.int(sec), C.int(usec)) - return int(r) -} - -// SendToNoWait port -func (d *DgramSocket) SendToNoWait(data []byte, port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_sendto_nowait(libsoftbus, d.dgram, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(port)) - return int(r) -} - -// RecvFrom data and port -func (d *DgramSocket) RecvFrom() ([]byte, int, error) { - if libsoftbus == nil { - return nil, -1, fmt.Errorf("RecvFrom Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - var rp C.int - - r := C.wrap_fn_dgram_socket_recvfrom(libsoftbus, d.dgram, &rb, &rs, &rp) - if r != 0 { - return nil, int(rp), fmt.Errorf("RecvFrom Func Failed %d", int(r)) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, int(rp), nil -} - -// RecvFromTimeout data and port -func (d *DgramSocket) RecvFromTimeout(sec, usec int) ([]byte, int, error) { - if libsoftbus == nil { - return nil, -1, fmt.Errorf("RecvFromTimeout Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - var rp C.int - - r := C.wrap_fn_dgram_socket_recvfrom_timeout(libsoftbus, d.dgram, &rb, &rs, &rp, C.int(sec), C.int(usec)) - if r != 0 { - return nil, int(rp), fmt.Errorf("RecvFromTimeout Func Failed %d", int(r)) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, int(rp), nil -} - -// RecvFromNoWait data and port -func (d *DgramSocket) RecvFromNoWait() ([]byte, int, error) { - if libsoftbus == nil { - return nil, -1, fmt.Errorf("RecvFromNoWait Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - var rp C.int - - r := C.wrap_fn_dgram_socket_recvfrom_nowait(libsoftbus, d.dgram, &rb, &rs, &rp) - if r != 0 { - return nil, int(rp), fmt.Errorf("RecvFromNoWait Func Failed %d", int(r)) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, int(rp), nil -} - -// SendAndRecv sync -func (d *DgramSocket) SendAndRecv(sdata []byte, port int) ([]byte, error) { - if libsoftbus == nil { - return nil, fmt.Errorf("SendAndRecv Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - - r := C.wrap_fn_dgram_socket_sendandrecv(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs) - if r != 0 { - return nil, fmt.Errorf("SendAndRecv Send To %d And Recv From It Failed", port) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, nil -} - -// SendAndRecvTimeout sync -func (d *DgramSocket) SendAndRecvTimeout(sdata []byte, port int, sec, usec int) ([]byte, error) { - if libsoftbus == nil { - return nil, fmt.Errorf("SendAndRecvTimeout Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - - r := C.wrap_fn_dgram_socket_sendandrecv_timeout(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs, C.int(sec), C.int(usec)) - if r != 0 { - return nil, fmt.Errorf("SendAndRecvTimeout Send To %d And Recv From It Failed", port) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, nil -} - -// SendAndRecvNoWait sync -func (d *DgramSocket) SendAndRecvNoWait(sdata []byte, port int) ([]byte, error) { - if libsoftbus == nil { - return nil, fmt.Errorf("SendAndRecvNoWait Func Test libsoftbus Is Nil") - } - - var rb unsafe.Pointer - var rs C.int - - r := C.wrap_fn_dgram_socket_sendandrecv_nowait(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs) - if r != 0 { - return nil, fmt.Errorf("SendAndRecvNoWait Send To %d And Recv From It Failed", port) - } - - data := C.GoBytes(rb, rs) - C.wrap_fn_dgram_socket_free(libsoftbus, rb) - - return data, nil -} - -// StartBus bus -func (d *DgramSocket) StartBus() int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_socket_start_bus(libsoftbus, d.dgram) - return int(r) -} - -// Sub sub bus -func (d *DgramSocket) Sub(topic string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_sub(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) - return int(r) -} - -// SubTimeout sub bus -func (d *DgramSocket) SubTimeout(topic string, port int, sec, usec int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_sub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port), C.int(sec), C.int(usec)) - return int(r) -} - -// SubNoWait sub bus -func (d *DgramSocket) SubNoWait(topic string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_sub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) - return int(r) -} - -// Desub remove sub -func (d *DgramSocket) Desub(topic string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_desub(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) - return int(r) -} - -// DesubTimeout timeout -func (d *DgramSocket) DesubTimeout(topic string, port int, sec, usec int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_desub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port), C.int(sec), C.int(usec)) - return int(r) -} - -// DesubNoWait remove sub -func (d *DgramSocket) DesubNoWait(topic string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - - r := C.wrap_fn_dgram_socket_desub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) - return int(r) -} - -// Pub bus -func (d *DgramSocket) Pub(topic, msg string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - cm := C.CString(msg) - defer C.free(unsafe.Pointer(cm)) - - r := C.wrap_fn_dgram_socket_pub(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), unsafe.Pointer(cm), C.int(len(msg)), C.int(port)) - return int(r) -} - -// PubTimeout bus -func (d *DgramSocket) PubTimeout(topic, msg string, port int, sec, usec int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - cm := C.CString(msg) - defer C.free(unsafe.Pointer(cm)) - - r := C.wrap_fn_dgram_socket_pub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), unsafe.Pointer(cm), C.int(len(msg)), C.int(port), C.int(sec), C.int(usec)) - return int(r) -} - -// PubNoWait bus -func (d *DgramSocket) PubNoWait(topic, msg string, port int) int { - if libsoftbus == nil { - return RETVAL - } - - ct := C.CString(topic) - defer C.free(unsafe.Pointer(ct)) - cm := C.CString(msg) - defer C.free(unsafe.Pointer(cm)) - - r := C.wrap_fn_dgram_socket_pub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), unsafe.Pointer(cm), C.int(len(msg)), C.int(port)) - return int(r) -} - -// Port socket -func (d *DgramSocket) Port() int { - if libsoftbus == nil { - return -1 - } - - r := C.wrap_fn_dgram_socket_port(libsoftbus, d.dgram) - return int(r) -} - -// RemoveKey rm key -func RemoveKey(key int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_dgram_remove_key(libsoftbus, C.int(key)) - return int(r) -} - -// RemoveKeys rm key -func RemoveKeys(keys []int) int { - if libsoftbus == nil { - return RETVAL - } - - l := len(keys) - ca := C.get_array(C.int(l)) - defer C.free(ca) - for k, v := range keys { - C.set_array(ca, C.int(k), C.int(v)) - } - - r := C.wrap_fn_dgram_remove_keys(libsoftbus, ca, C.int(l)) - return int(r) -} diff --git a/softbusSocket.go b/softbusSocket.go deleted file mode 100644 index ac49a29..0000000 --- a/softbusSocket.go +++ /dev/null @@ -1,127 +0,0 @@ -package softbus - -/* -#include <stdlib.h> -#include "libcsoftbus.h" -*/ -import "C" -import ( - "errors" - "fmt" - "unsafe" -) - -const ( - - // RETVAL retual val - RETVAL = 0x7fff - // PullPush mode - PullPush = 1 - // ReqRep mode - ReqRep = 2 - // Pair mode - Pair = 3 - // PubSub mode - PubSub = 4 - // Survey mode - Survey = 5 - // Bus mode - Bus = 6 -) - -// Socket struct -type Socket struct { - csocket unsafe.Pointer -} - -// OpenSocket open -func OpenSocket(mod int) *Socket { - if libsoftbus == nil { - return nil - } - - s := C.wrap_fn_socket_open(libsoftbus, C.int(mod)) - if s == nil { - return nil - } - - return &Socket{ - csocket: s, - } -} - -// Close socket -func (s *Socket) Close() int { - if libsoftbus != nil || s.csocket != nil { - r := C.wrap_fn_socket_close(libsoftbus, s.csocket) - return int(r) - } - return RETVAL -} - -// Bind socket -func (s *Socket) Bind(port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_socket_bind(libsoftbus, s.csocket, C.int(port)) - return int(r) -} - -// Listen socket -func (s *Socket) Listen() int { - if libsoftbus == nil { - return RETVAL - } - r := C.wrap_fn_socket_listen(libsoftbus, s.csocket) - return int(r) -} - -// Connect socket -func (s *Socket) Connect(port int) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_socket_connect(libsoftbus, s.csocket, C.int(port)) - return int(r) -} - -// Send data -func (s *Socket) Send(data []byte) int { - if libsoftbus == nil { - return RETVAL - } - - r := C.wrap_fn_socket_send(libsoftbus, s.csocket, unsafe.Pointer(&data[0]), C.int(len(data))) - return int(r) -} - -// Recv data -func (s *Socket) Recv() ([]byte, error) { - if libsoftbus == nil { - return nil, errors.New("libsoftbus is nil") - } - - var rd unsafe.Pointer - var rl C.int - r := C.wrap_fn_socket_recv(libsoftbus, s.csocket, &rd, &rl) - if r != 0 { - return nil, fmt.Errorf("Recv Data Failed errCode: %d", int(r)) - } - data := C.GoBytes(rd, rl) - C.wrap_fn_socket_buf_free(libsoftbus, rd) - return data, nil -} - -// Port get port/key -func (s *Socket) Port() int { - if libsoftbus == nil { - return -1 - } - - r := C.wrap_fn_socket_port(libsoftbus, s.csocket) - - return int(r) -} -- Gitblit v1.8.0