From 58d904a328c0d849769b483e901a0be9426b8209 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 20 七月 2021 20:20:44 +0800 Subject: [PATCH] 调整Request C.BHFree的位置 --- api/bhsgo/bhome_node.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 11 deletions(-) diff --git a/api/bhsgo/bhome_node.go b/api/bhsgo/bhome_node.go index b7c1eeb..3fbb294 100644 --- a/api/bhsgo/bhome_node.go +++ b/api/bhsgo/bhome_node.go @@ -4,7 +4,7 @@ #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 ( @@ -24,8 +24,9 @@ func bhApiIn1Out1(bhfunc C.FBHApiIn1Out1, data []byte, reply *bh.MsgCommonReply, timeout_ms int) bool { creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) + r := C.BHApiIn1Out1Proxy(bhfunc, getPtr(&data), C.int(len(data)), &creply, &creply_len, C.int(timeout_ms)) > 0 + defer C.BHFree(creply, creply_len) if r { reply.Unmarshal(C.GoBytes(creply, creply_len)) } @@ -47,6 +48,11 @@ return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHSubscribeTopics), data, reply, timeout_ms) } +func SubscribeNet(topics *bh.MsgTopicList, reply *bh.MsgCommonReply, timeout_ms int) bool { + data, _ := topics.Marshal() + return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHSubscribeNetTopics), data, reply, timeout_ms) +} + 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) @@ -66,8 +72,22 @@ 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 + defer C.BHFree(creply, creply_len) + 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) + r := C.BHQueryProcs(getPtr(&dest), C.int(len(dest)), getPtr(&data), C.int(len(data)), &creply, &creply_len, C.int(timeout_ms)) > 0 + defer C.BHFree(creply, creply_len) if r { reply.Unmarshal(C.GoBytes(creply, creply_len)) } @@ -83,12 +103,14 @@ func ReadSub(proc_id *string, pub *bh.MsgPublish, timeout_ms int) bool { cpid := unsafe.Pointer(nil) cpid_len := C.int(0) - defer C.BHFree(cpid, cpid_len) + creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) r := C.BHReadSub(&cpid, &cpid_len, &creply, &creply_len, C.int(timeout_ms)) > 0 + defer C.BHFree(cpid, cpid_len) + defer C.BHFree(creply, creply_len) + *proc_id = string(C.GoBytes(cpid, cpid_len)) pub.Unmarshal(C.GoBytes(creply, creply_len)) return r @@ -99,8 +121,10 @@ data, _ := req.Marshal() creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) + r := C.BHAsyncRequest(getPtr(&dest), C.int(len(dest)), getPtr(&data), C.int(len(data)), &creply, &creply_len) > 0 + defer C.BHFree(creply, creply_len) + if r { *msg_id = C.GoBytes(creply, creply_len) } @@ -112,11 +136,14 @@ data, _ := req.Marshal() cpid := unsafe.Pointer(nil) cpid_len := C.int(0) - defer C.BHFree(cpid, cpid_len) + creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) + r := C.BHRequest(getPtr(&dest), C.int(len(dest)), getPtr(&data), C.int(len(data)), &cpid, &cpid_len, &creply, &creply_len, C.int(timeout_ms)) > 0 + + defer C.BHFree(cpid, cpid_len) + defer C.BHFree(creply, creply_len) if r { *proc_id = string(C.GoBytes(cpid, cpid_len)) reply.Unmarshal(C.GoBytes(creply, creply_len)) @@ -127,11 +154,15 @@ func ReadRequest(proc_id *string, req *bh.MsgRequestTopic, psrc *unsafe.Pointer, timeout_ms int) bool { cpid := unsafe.Pointer(nil) cpid_len := C.int(0) - defer C.BHFree(cpid, cpid_len) + creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) + r := C.BHReadRequest(&cpid, &cpid_len, &creply, &creply_len, psrc, C.int(timeout_ms)) > 0 + + defer C.BHFree(cpid, cpid_len) + defer C.BHFree(creply, creply_len) + if r { *proc_id = string(C.GoBytes(cpid, cpid_len)) req.Unmarshal(C.GoBytes(creply, creply_len)) @@ -147,12 +178,18 @@ func GetLastError() (int, string) { creply := unsafe.Pointer(nil) creply_len := C.int(0) - defer C.BHFree(creply, creply_len) + r := C.BHGetLastError(&creply, &creply_len) + defer C.BHFree(creply, creply_len) + return int(r), string(C.GoBytes(creply, creply_len)) } +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