zhangmeng
2020-08-06 f87b7233a94131a5fd1b3dfb1595226e2779fffa
softbusDgram.go
@@ -3,6 +3,8 @@
/*
#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 (
@@ -263,6 +265,45 @@
   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 {
@@ -317,3 +358,30 @@
   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)
}