From 6c07fe29a5185835f28059f627a1d30e462da28b Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 29 六月 2021 14:01:19 +0800 Subject: [PATCH] add notify node change. --- api/bhsgo/bhome_node.go | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 42 insertions(+), 4 deletions(-) diff --git a/api/bhsgo/bhome_node.go b/api/bhsgo/bhome_node.go index 7e7bf17..9d66814 100644 --- a/api/bhsgo/bhome_node.go +++ b/api/bhsgo/bhome_node.go @@ -4,12 +4,13 @@ #include "bh_api_go.h" */ -// #cgo LDFLAGS: -L/home/lichao/code/shmsg/build/lib -L/usr/local/lib -lbhome_shmq -lbhome_msg -lprotobuf-lite -lstdc++ -lpthread -lrt +// #cgo LDFLAGS: -L/home/lichao/code/shmsg/build/lib -L/usr/local/lib -lbhome_shmq -lstdc++ -lpthread -lrt import "C" import ( - bh "bhshmq/proto/source/bhome_msg" "unsafe" + + bh "basic.com/valib/bhshmq.git/proto/source/bhome_msg" ) func getPtr(n *[]byte) unsafe.Pointer { @@ -46,13 +47,46 @@ return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHSubscribeTopics), data, reply, timeout_ms) } -func Heartbeat(topics *bh.ProcInfo, reply *bh.MsgCommonReply, timeout_ms int) bool { - data, _ := topics.Marshal() +func Heartbeat(proc *bh.ProcInfo, reply *bh.MsgCommonReply, timeout_ms int) bool { + data, _ := proc.Marshal() return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHHeartbeat), data, reply, timeout_ms) } func HeartbeatEasy(timeout_ms int) bool { return C.BHHeartbeatEasy(C.int(timeout_ms)) > 0 +} + +func Unregister(proc *bh.ProcInfo, reply *bh.MsgCommonReply, timeout_ms int) bool { + data, _ := proc.Marshal() + return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHUnregister), data, reply, timeout_ms) +} + +func QueryTopicAddress(dest_addr *bh.BHAddress, topic *bh.MsgQueryTopic, reply *bh.MsgQueryTopicReply, timeout_ms int) bool { + dest, _ := dest_addr.Marshal() + data, _ := topic.Marshal() + creply := unsafe.Pointer(nil) + creply_len := C.int(0) + defer C.BHFree(creply, creply_len) + r := C.BHQueryTopicAddress(getPtr(&dest), C.int(len(dest)), getPtr(&data), C.int(len(data)), &creply, &creply_len, C.int(timeout_ms)) > 0 + if r { + reply.Unmarshal(C.GoBytes(creply, creply_len)) + } + return r + +} + +func QueryProcs(dest_addr *bh.BHAddress, topic *bh.MsgQueryProc, reply *bh.MsgQueryProcReply, timeout_ms int) bool { + dest, _ := dest_addr.Marshal() + data, _ := topic.Marshal() + creply := unsafe.Pointer(nil) + creply_len := C.int(0) + defer C.BHFree(creply, creply_len) + r := C.BHQueryProcs(getPtr(&dest), C.int(len(dest)), getPtr(&data), C.int(len(data)), &creply, &creply_len, C.int(timeout_ms)) > 0 + if r { + reply.Unmarshal(C.GoBytes(creply, creply_len)) + } + return r + } func Publish(pub *bh.MsgPublish, timeout_ms int) bool { @@ -133,6 +167,10 @@ } +func Cleanup() { + C.BHCleanup() +} + type ServerCB func(src unsafe.Pointer, proc_id *string, req *bh.MsgRequestTopic) type ClientCB func(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply) type SubDataCB func(proc_id *string, pub *bh.MsgPublish) -- Gitblit v1.8.0