liuxiaolong
2021-04-21 d1f89c1eb52a08b97d5be5dd991c5991b6f0bf93
api/bhsgo/bhome_node.go
File was renamed from api/go/bhome_node.go
@@ -1,4 +1,4 @@
package main
package bhsgo
/*
#include "bh_api_go.h"
@@ -8,9 +8,8 @@
import "C"
import (
   bh "bhome_node/bhome_msg"
   bh "bhshmq/proto/source/bhome_msg"
   "fmt"
   "time"
   "unsafe"
)
@@ -181,57 +180,4 @@
}
func ClientCallback(proc_id *string, msg_id *[]byte, reply *bh.MsgRequestTopicReply) {
   fmt.Println("user client cb reply: " + string(reply.Data))
}
func main() {
   proc_id := "test_proc"
   proc := bh.ProcInfo{}
   proc.ProcId = []byte(proc_id)
   reply := bh.MsgCommonReply{}
   StartWorker(ClientCallback, ServerCallback, SubDataCallback)
   r := Register(&proc, &reply, 1000)
   if r {
      fmt.Println("register ok")
   } else {
      fmt.Println("register failed")
      return
   }
   r = HeartbeatEasy(1000)
   if r {
      fmt.Println("heartbeat ok")
   } else {
      fmt.Println("heartbeat failed")
   }
   topics := bh.MsgTopicList{}
   topics.TopicList = append(topics.TopicList, []byte("topic0"), []byte("topic1"))
   RegisterTopics(&topics, &reply, 0)
   if r {
      fmt.Println("reg topics ok")
   } else {
      fmt.Println("reg topics failed")
   }
   req := bh.MsgRequestTopic{}
   time.Sleep(time.Second * 1)
   req.Topic = []byte("topic0")
   req.Data = []byte("data0")
   // var msg_id []byte
   // AsyncRequest(&req, &msg_id)
   // fmt.Println(msg_id)
   // time.Sleep(time.Second * 5)
   pid := ""
   rr := bh.MsgRequestTopicReply{}
   for i := 0; i < 10000; i++ {
      if Request(&req, &pid, &rr, 3000) {
         fmt.Println("server:" + pid + ", reply:" + string(rr.Data))
      } else {
         e, s := GetLastError()
         fmt.Println("ec:", e, ", msg:"+s)
      }
   }
}
}