| | |
| | | return int(ret) |
| | | } |
| | | |
| | | // StartBus socket |
| | | func (s *Socket) StartBus() int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | | |
| | | return int(C.wrap_fn_socket_start_bus(libbhomebus, s.socket)) |
| | | } |
| | | //// StartBus socket |
| | | //func (s *Socket) StartBus() int { |
| | | // if libbhomebus == nil || s.socket == nil { |
| | | // return -1 |
| | | // } |
| | | // |
| | | // return int(C.wrap_fn_socket_start_bus(libbhomebus, s.socket)) |
| | | //} |
| | | |
| | | // Pub socket |
| | | func (s *Socket) Pub(nodes []NetNode, topic string, data []byte) int { |
| | |
| | | } |
| | | |
| | | // Sub socket |
| | | func (s *Socket) Sub(topic string, key int) int { |
| | | func (s *Socket) Sub(topic string) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_sub(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key))) |
| | | return int(C.wrap_fn_socket_sub(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)))) |
| | | } |
| | | |
| | | // SubTimeout socket |
| | | func (s *Socket) SubTimeout(topic string, key int, milliseconds int) int { |
| | | func (s *Socket) SubTimeout(topic string, milliseconds int) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_sub_timeout(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key), 0, C.int(milliseconds*1000000))) |
| | | return int(C.wrap_fn_socket_sub_timeout(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), 0, C.int(milliseconds*1000000))) |
| | | |
| | | } |
| | | |
| | | // SubNowait socket |
| | | func (s *Socket) SubNowait(topic string, key int) int { |
| | | func (s *Socket) SubNowait(topic string) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_sub_nowait(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)), C.int(key))) |
| | | return int(C.wrap_fn_socket_sub_nowait(libbhomebus, s.socket, unsafe.Pointer(ctopic), C.int(len(topic)))) |
| | | |
| | | } |
| | | |
| | | // Desub socket |
| | | func (s *Socket) Desub(topic string, key int) int { |
| | | func (s *Socket) Desub(topic string) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_desub(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key))) |
| | | return int(C.wrap_fn_socket_desub(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)))) |
| | | } |
| | | |
| | | // DesubTimeout socket |
| | | func (s *Socket) DesubTimeout(topic string, key int, milliseconds int) int { |
| | | func (s *Socket) DesubTimeout(topic string, milliseconds int) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_desub_timeout(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key), 0, C.int(milliseconds*1000000))) |
| | | return int(C.wrap_fn_socket_desub_timeout(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), 0, C.int(milliseconds*1000000))) |
| | | } |
| | | |
| | | // DesubNowait socket |
| | | func (s *Socket) DesubNowait(topic string, key int) int { |
| | | func (s *Socket) DesubNowait(topic string) int { |
| | | if libbhomebus == nil || s.socket == nil { |
| | | return -1 |
| | | } |
| | | ctopic := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ctopic)) |
| | | |
| | | return int(C.wrap_fn_socket_desub_nowait(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)), C.int(key))) |
| | | return int(C.wrap_fn_socket_desub_nowait(libbhomebus, s.socket, unsafe.Pointer(&ctopic), C.int(len(topic)))) |
| | | } |
| | | |
| | | // Getkey socket |
| | |
| | | |
| | | return int(C.wrap_fn_server_socket_start(libbhomebus, s.socket)) |
| | | } |
| | | |
| | | // ServerOpen bus server |
| | | func BusServerOpen() *Socket { |
| | | if libbhomebus == nil { |
| | | return nil |
| | | } |
| | | |
| | | sock := C.wrap_fn_bus_server_socket_open(libbhomebus) |
| | | return &Socket{sock} |
| | | } |
| | | |
| | | // Close close |
| | | func (s *Socket) BusClose() { |
| | | if libbhomebus == nil { |
| | | return |
| | | } |
| | | |
| | | C.wrap_fn_bus_server_socket_close(libbhomebus, s.socket) |
| | | } |
| | | |
| | | // Start start |
| | | func (s *Socket) BusStart() int { |
| | | if libbhomebus == nil { |
| | | return -1 |
| | | } |
| | | |
| | | return int(C.wrap_fn_bus_server_socket_start(libbhomebus, s.socket)) |
| | | } |
| | |
| | | return fn_socket_sendandrecv_nowait(_socket, (net_node_t*)node_arr, arrlen, send_buf, send_size, (net_mod_recv_msg_t**)recv_arr, recv_arr_size); |
| | | } |
| | | |
| | | int wrap_fn_socket_start_bus(hbhomebus lib, void * _socket) |
| | | { |
| | | if(!fn_socket_start_bus){ |
| | | fn_socket_start_bus = (tfn_net_mod_socket_start_bus)dlsym(lib,l_net_mod_socket_start_bus); |
| | | check_with_ret(fn_socket_start_bus, lib, -1); |
| | | } |
| | | return fn_socket_start_bus(_socket); |
| | | } |
| | | //int wrap_fn_socket_start_bus(hbhomebus lib, void * _socket) |
| | | //{ |
| | | // if(!fn_socket_start_bus){ |
| | | // fn_socket_start_bus = (tfn_net_mod_socket_start_bus)dlsym(lib,l_net_mod_socket_start_bus); |
| | | // check_with_ret(fn_socket_start_bus, lib, -1); |
| | | // } |
| | | // return fn_socket_start_bus(_socket); |
| | | //} |
| | | |
| | | int wrap_fn_socket_pub(hbhomebus lib, void *_socket, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size) |
| | | { |
| | |
| | | return fn_socket_pub_nowait(_socket, (net_node_t*)node_arr, node_arr_len, topic, topic_size, content, content_size); |
| | | } |
| | | |
| | | int wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size, int key) |
| | | int wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size) |
| | | { |
| | | if(!fn_socket_sub){ |
| | | fn_socket_sub = (tfn_net_mod_socket_sub)dlsym(lib,l_net_mod_socket_sub); |
| | | check_with_ret(fn_socket_sub, lib, -1); |
| | | } |
| | | return fn_socket_sub(_socket, topic, size, key); |
| | | return fn_socket_sub(_socket, topic, size); |
| | | } |
| | | |
| | | int wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec) |
| | | int wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec) |
| | | { |
| | | if(!fn_socket_sub_timeout){ |
| | | fn_socket_sub_timeout = (tfn_net_mod_socket_sub_timeout)dlsym(lib,l_net_mod_socket_sub_timeout); |
| | | check_with_ret(fn_socket_sub_timeout, lib, -1); |
| | | } |
| | | return fn_socket_sub_timeout(_socket, topic, size, key, sec, nsec); |
| | | return fn_socket_sub_timeout(_socket, topic, size, sec, nsec); |
| | | } |
| | | |
| | | int wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key) |
| | | int wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size) |
| | | { |
| | | if(!fn_socket_sub_nowait){ |
| | | fn_socket_sub_nowait = (tfn_net_mod_socket_sub_nowait)dlsym(lib,l_net_mod_socket_sub_nowait); |
| | | check_with_ret(fn_socket_sub_nowait, lib, -1); |
| | | } |
| | | return fn_socket_sub_nowait(_socket, topic, size, key); |
| | | return fn_socket_sub_nowait(_socket, topic, size); |
| | | } |
| | | |
| | | int wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size, int key) |
| | | int wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size) |
| | | { |
| | | if(!fn_socket_desub){ |
| | | fn_socket_desub = (tfn_net_mod_socket_desub)dlsym(lib,l_net_mod_socket_desub); |
| | | check_with_ret(fn_socket_desub, lib, -1); |
| | | } |
| | | return fn_socket_desub(_socket, topic, size, key); |
| | | return fn_socket_desub(_socket, topic, size); |
| | | } |
| | | |
| | | int wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec) |
| | | int wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec) |
| | | { |
| | | if(!fn_socket_desub_timeout){ |
| | | fn_socket_desub_timeout = (tfn_net_mod_socket_desub_timeout)dlsym(lib,l_net_mod_socket_desub_timeout); |
| | | check_with_ret(fn_socket_desub_timeout, lib, -1); |
| | | } |
| | | return fn_socket_desub_timeout(_socket, topic, size, key, sec, nsec); |
| | | return fn_socket_desub_timeout(_socket, topic, size, sec, nsec); |
| | | } |
| | | |
| | | int wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key) |
| | | int wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size) |
| | | { |
| | | if(!fn_socket_desub_nowait){ |
| | | fn_socket_desub_nowait = (tfn_net_mod_socket_sub_nowait)dlsym(lib,l_net_mod_socket_sub_nowait); |
| | | check_with_ret(fn_socket_desub_nowait, lib, -1); |
| | | } |
| | | return fn_socket_desub_nowait(_socket, topic, size, key); |
| | | return fn_socket_desub_nowait(_socket, topic, size); |
| | | } |
| | | |
| | | int wrap_fn_socket_get_key(hbhomebus lib, void * _socket) |
| | |
| | | } |
| | | return fn_server_socket_start(_socket); |
| | | } |
| | | |
| | | void *wrap_fn_bus_server_socket_open(hbhomebus lib){ |
| | | if (!fn_bus_server_socket_open){ |
| | | fn_bus_server_socket_open = (tfn_bus_server_socket_wrapper_open)dlsym(lib, l_bus_server_socket_wrapper_open); |
| | | check_with_ret(fn_bus_server_socket_open, lib, NULL); |
| | | } |
| | | return fn_bus_server_socket_open(); |
| | | } |
| | | |
| | | void wrap_fn_bus_server_socket_close(hbhomebus lib, void* _socket){ |
| | | if (!fn_bus_server_socket_close){ |
| | | fn_bus_server_socket_close = (tfn_bus_server_socket_wrapper_close)dlsym(lib, l_bus_server_socket_wrapper_close); |
| | | check_only(fn_bus_server_socket_close, lib); |
| | | } |
| | | fn_bus_server_socket_close(_socket); |
| | | } |
| | | |
| | | int wrap_fn_bus_server_socket_start(hbhomebus lib, void* _socket){ |
| | | if (!fn_bus_server_socket_start){ |
| | | fn_bus_server_socket_start = (tfn_bus_server_socket_wrapper_start_bus)dlsym(lib, l_bus_server_socket_wrapper_start_bus); |
| | | check_with_ret(fn_bus_server_socket_start, lib, -1); |
| | | } |
| | | return fn_bus_server_socket_start(_socket); |
| | | } |
| | |
| | | static tfn_net_mod_socket_sendandrecv fn_socket_sendandrecv = NULL; |
| | | static tfn_net_mod_socket_sendandrecv_timeout fn_socket_sendandrecv_timeout = NULL; |
| | | static tfn_net_mod_socket_sendandrecv_nowait fn_socket_sendandrecv_nowait = NULL; |
| | | static tfn_net_mod_socket_start_bus fn_socket_start_bus = NULL; |
| | | //static tfn_net_mod_socket_start_bus fn_socket_start_bus = NULL; |
| | | static tfn_net_mod_socket_pub fn_socket_pub = NULL; |
| | | static tfn_net_mod_socket_pub_timeout fn_socket_pub_timeout = NULL; |
| | | static tfn_net_mod_socket_pub_nowait fn_socket_pub_nowait = NULL; |
| | |
| | | static tfn_net_mod_server_socket_open fn_server_socket_open = NULL; |
| | | static tfn_net_mod_server_socket_close fn_server_socket_close = NULL; |
| | | static tfn_net_mod_server_socket_start fn_server_socket_start = NULL; |
| | | |
| | | // bus |
| | | static tfn_bus_server_socket_wrapper_open fn_bus_server_socket_open = NULL; |
| | | static tfn_bus_server_socket_wrapper_close fn_bus_server_socket_close = NULL; |
| | | static tfn_bus_server_socket_wrapper_start_bus fn_bus_server_socket_start = NULL; |
| | | ////////////////////////////////////////////////////////////////////// |
| | | |
| | | // labels |
| | |
| | | const static char l_net_mod_socket_sendandrecv[] = "net_mod_socket_sendandrecv"; |
| | | const static char l_net_mod_socket_sendandrecv_timeout[] = "net_mod_socket_sendandrecv_timeout"; |
| | | const static char l_net_mod_socket_sendandrecv_nowait[] = "net_mod_socket_sendandrecv_nowait"; |
| | | const static char l_net_mod_socket_start_bus[] = "net_mod_socket_start_bus"; |
| | | //const static char l_net_mod_socket_start_bus[] = "net_mod_socket_start_bus"; |
| | | const static char l_net_mod_socket_pub[] = "net_mod_socket_pub"; |
| | | const static char l_net_mod_socket_pub_timeout[] = "net_mod_socket_pub_timeout"; |
| | | const static char l_net_mod_socket_pub_nowait[] = "net_mod_socket_pub_nowait"; |
| | |
| | | const static char l_net_mod_server_socket_open[] = "net_mod_server_socket_open"; |
| | | const static char l_net_mod_server_socket_close[] = "net_mod_server_socket_close"; |
| | | const static char l_net_mod_server_socket_start[] = "net_mod_server_socket_start"; |
| | | |
| | | // bus |
| | | const static char l_bus_server_socket_wrapper_open[] = "bus_server_socket_wrapper_open"; |
| | | const static char l_bus_server_socket_wrapper_close[] = "bus_server_socket_wrapper_close"; |
| | | const static char l_bus_server_socket_wrapper_start_bus[] = "bus_server_socket_wrapper_start_bus"; |
| | | ////////////////////////////////////////////////////////////////////// |
| | | |
| | | // dlopen dynamic library |
| | |
| | | void ** recv_arr, int *recv_arr_size, int timeout); |
| | | int wrap_fn_socket_sendandrecv_nowait(hbhomebus lib, void *_sockt, void *node_arr, int arrlen, void *send_buf, int send_size, |
| | | void ** recv_arr, int *recv_arr_size) ; |
| | | int wrap_fn_socket_start_bus(hbhomebus lib, void * _socket); |
| | | //int wrap_fn_socket_start_bus(hbhomebus lib, void * _socket); |
| | | int wrap_fn_socket_pub(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); |
| | | int wrap_fn_socket_pub_timeout(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout); |
| | | int wrap_fn_socket_pub_nowait(hbhomebus lib, void *_sockt, void *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); |
| | | int wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size, int key); |
| | | int wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec); |
| | | int wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key); |
| | | int wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size, int key); |
| | | int wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int key, int sec, int nsec); |
| | | int wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size, int key); |
| | | int wrap_fn_socket_sub(hbhomebus lib, void * _socket, void *topic, int size); |
| | | int wrap_fn_socket_sub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec); |
| | | int wrap_fn_socket_sub_nowait(hbhomebus lib, void * _socket, void *topic, int size); |
| | | int wrap_fn_socket_desub(hbhomebus lib, void * _socket, void *topic, int size); |
| | | int wrap_fn_socket_desub_timeout(hbhomebus lib, void * _socket, void *topic, int size, int sec, int nsec); |
| | | int wrap_fn_socket_desub_nowait(hbhomebus lib, void * _socket, void *topic, int size); |
| | | int wrap_fn_socket_get_key(hbhomebus lib, void * _socket) ; |
| | | void wrap_fn_socket_free_recv_msg_arr(hbhomebus lib, void * arr, int size); |
| | | void wrap_fn_socket_free(hbhomebus lib, void *buf) ; |
| | |
| | | void wrap_fn_server_socket_close(hbhomebus lib, void* _socket); |
| | | int wrap_fn_server_socket_start(hbhomebus lib, void* _socket); |
| | | |
| | | //bus |
| | | void *wrap_fn_bus_server_socket_open(hbhomebus lib); |
| | | void wrap_fn_bus_server_socket_close(hbhomebus lib, void* _socket); |
| | | int wrap_fn_bus_server_socket_start(hbhomebus lib, void* _socket); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | |
| | | * |
| | | * @return 0 成功, 其他值 失败的错误码 |
| | | */ |
| | | typedef int (*tfn_net_mod_socket_start_bus)(void * _socket); |
| | | //typedef int (*tfn_net_mod_socket_start_bus)(void * _socket); |
| | | |
| | | |
| | | /** |
| | |
| | | * @size 主题长度 |
| | | * @key 总线端口 |
| | | */ |
| | | typedef int (*tfn_net_mod_socket_sub)(void * _socket, void *topic, int size, int key); |
| | | typedef int (*tfn_net_mod_socket_sub)(void * _socket, void *topic, int size); |
| | | // 超时返回。 @sec 秒 , @nsec 纳秒 |
| | | typedef int (*tfn_net_mod_socket_sub_timeout)(void * _socket, void *topic, int size, int key, int sec, int nsec); |
| | | typedef int (*tfn_net_mod_socket_sub_nowait)(void * _socket, void *topic, int size, int key); |
| | | typedef int (*tfn_net_mod_socket_sub_timeout)(void * _socket, void *topic, int size, int sec, int nsec); |
| | | typedef int (*tfn_net_mod_socket_sub_nowait)(void * _socket, void *topic, int size); |
| | | |
| | | |
| | | /** |
| | |
| | | * @size 主题长度 |
| | | * @key 总线端口 |
| | | */ |
| | | typedef int (*tfn_net_mod_socket_desub)(void * _socket, void *topic, int size, int key); |
| | | typedef int (*tfn_net_mod_socket_desub)(void * _socket, void *topic, int size); |
| | | // 超时返回。 @sec 秒 , @nsec 纳秒 |
| | | typedef int (*tfn_net_mod_socket_desub_timeout)(void * _socket, void *topic, int size, int key, int sec, int nsec); |
| | | typedef int (*tfn_net_mod_socket_desub_nowait)(void * _socket, void *topic, int size, int key); |
| | | typedef int (*tfn_net_mod_socket_desub_timeout)(void * _socket, void *topic, int size, int sec, int nsec); |
| | | typedef int (*tfn_net_mod_socket_desub_nowait)(void * _socket, void *topic, int size); |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | typedef int(*tfn_shm_mod_socket_remove_keys) (int*, int); |
| | | |
| | | |
| | | /** |
| | | * 创建 |
| | | */ |
| | |
| | | */ |
| | | typedef int (*tfn_net_mod_server_socket_start)(void *_sockt); |
| | | |
| | | /** |
| | | * bus创建 |
| | | */ |
| | | typedef void *(*tfn_bus_server_socket_wrapper_open)() ; |
| | | |
| | | /** |
| | | * bus关闭 |
| | | */ |
| | | typedef void (*tfn_bus_server_socket_wrapper_close)(void *_sockt) ; |
| | | |
| | | /** |
| | | * bus启动 |
| | | */ |
| | | typedef int (*tfn_bus_server_socket_wrapper_start_bus)(void *_sockt); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |