| | |
| | | |
| | | import ( |
| | | bh "bhshmq/proto/source/bhome_msg" |
| | | "fmt" |
| | | "unsafe" |
| | | ) |
| | | |
| | | func BHApiIn1Out1(bhfunc C.FBHApiIn1Out1, data []byte, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | 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) |
| | |
| | | |
| | | func Register(proc *bh.ProcInfo, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | data, _ := proc.Marshal() |
| | | return BHApiIn1Out1(C.FBHApiIn1Out1(C.BHRegister), data, reply, timeout_ms) |
| | | return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHRegister), data, reply, timeout_ms) |
| | | } |
| | | |
| | | func RegisterTopics(topics *bh.MsgTopicList, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | data, _ := topics.Marshal() |
| | | return BHApiIn1Out1(C.FBHApiIn1Out1(C.BHRegisterTopics), data, reply, timeout_ms) |
| | | return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHRegisterTopics), data, reply, timeout_ms) |
| | | } |
| | | |
| | | func Subscribe(topics *bh.MsgTopicList, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | data, _ := topics.Marshal() |
| | | return BHApiIn1Out1(C.FBHApiIn1Out1(C.BHSubscribeTopics), data, reply, timeout_ms) |
| | | return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHSubscribeTopics), data, reply, timeout_ms) |
| | | } |
| | | |
| | | func Heartbeat(topics *bh.MsgTopicList, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | func Heartbeat(topics *bh.ProcInfo, reply *bh.MsgCommonReply, timeout_ms int) bool { |
| | | data, _ := topics.Marshal() |
| | | return BHApiIn1Out1(C.FBHApiIn1Out1(C.BHHeartbeat), data, reply, timeout_ms) |
| | | return bhApiIn1Out1(C.FBHApiIn1Out1(C.BHHeartbeat), data, reply, timeout_ms) |
| | | } |
| | | |
| | | func HeartbeatEasy(timeout_ms int) bool { |
| | |
| | | var cgoClientCB ClientCB |
| | | var cgoSubDataCB SubDataCB |
| | | |
| | | //export CGoSubDataCallback |
| | | func CGoSubDataCallback(cpid C.PCVoid, pid_len C.int, data C.PCVoid, data_len C.int) { |
| | | //export cgoSubDataCallback |
| | | func cgoSubDataCallback(cpid C.PCVoid, pid_len C.int, data C.PCVoid, data_len C.int) { |
| | | proc_id := string(C.GoBytes(unsafe.Pointer(cpid), pid_len)) |
| | | msg := bh.MsgPublish{} |
| | | msg.Unmarshal(C.GoBytes(unsafe.Pointer(data), data_len)) |
| | | cgoSubDataCB(&proc_id, &msg) |
| | | } |
| | | |
| | | //export CGoServerCallback |
| | | func CGoServerCallback(cpid C.PCVoid, pid_len C.int, data C.PCVoid, data_len C.int, src unsafe.Pointer) { |
| | | //export cgoServerCallback |
| | | func cgoServerCallback(cpid C.PCVoid, pid_len C.int, data C.PCVoid, data_len C.int, src unsafe.Pointer) { |
| | | proc_id := string(C.GoBytes(unsafe.Pointer(cpid), pid_len)) |
| | | msg := bh.MsgRequestTopic{} |
| | | msg.Unmarshal(C.GoBytes(unsafe.Pointer(data), data_len)) |
| | | cgoServerCB(src, &proc_id, &msg) |
| | | } |
| | | |
| | | //export CGoClientCallback |
| | | func CGoClientCallback(cpid C.PCVoid, pid_len C.int, msgid C.PCVoid, msgid_len C.int, data C.PCVoid, data_len C.int) { |
| | | //export cgoClientCallback |
| | | func cgoClientCallback(cpid C.PCVoid, pid_len C.int, msgid C.PCVoid, msgid_len C.int, data C.PCVoid, data_len C.int) { |
| | | proc_id := string(C.GoBytes(unsafe.Pointer(cpid), pid_len)) |
| | | msg_id := C.GoBytes(unsafe.Pointer(msgid), msgid_len) |
| | | var msg bh.MsgRequestTopicReply |
| | |
| | | cgoSubDataCB = sub |
| | | C.CGoStartWorker() |
| | | } |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| | | // user code: |
| | | |
| | | func ServerCallback(src unsafe.Pointer, proc_id *string, req *bh.MsgRequestTopic) { |
| | | fmt.Println("user server cb called, request topic: " + string(req.Topic) + ", data:" + string(req.Data)) |
| | | reply := bh.MsgRequestTopicReply{} |
| | | reply.Data = []byte("reply 1234") |
| | | SendReply(src, &reply) |
| | | } |
| | | |
| | | func SubDataCallback(proc_id *string, pub *bh.MsgPublish) { |
| | | fmt.Println("user sub data cb called") |
| | | } |
| | | func ClientCallback(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply) { |
| | | fmt.Println("user client cb reply: " + string(reply.Data)) |
| | | } |