| | |
| | | /* |
| | | #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 ( |
| | |
| | | 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 { |
| | |
| | | r := C.wrap_fn_dgram_socket_port(libsoftbus, d.dgram) |
| | | return int(r) |
| | | } |
| | | |
| | | // RemoveKey rm key |
| | | func (d *DgramSocket) 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 (d *DgramSocket) 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) |
| | | } |