liuxiaolong
2020-12-29 a7f35d9126fa7803284038f8e69a22199cd35e64
micronode.go
File was renamed from mc/micronode.go
@@ -2,7 +2,6 @@
import (
   "basic.com/valib/bhomebus.git"
   "bhomeclient"
   "context"
   "encoding/json"
   "errors"
@@ -13,19 +12,19 @@
type MicroNode struct {
   ctx       context.Context
   handle       *bhomeclient.BHBus
   reg       *bhomeclient.RegisterInfo
   procInfo    *bhomeclient.ProcInfo
   handle       *BHBus
   reg       *RegisterInfo
   procInfo    *ProcInfo
   handlers    map[string]MicroFunc
   serverId    string
   fnLog       func(...interface{})
   SubChM       map[string]chan *bhomeclient.MsgInfo //以订阅的主题为key
   SubChM       map[string]chan *MsgInfo //以订阅的主题为key
}
func NewMicroNode(ctx context.Context,q chan os.Signal, serverId string, reg *bhomeclient.RegisterInfo, procInfo *bhomeclient.ProcInfo,fnLog func(v ...interface{})) (*MicroNode, error){
   conf := bhomeclient.NewConfig(bhomeclient.KEY_REGISTER,512,5,10,10,100, fnLog)
   handle, err := bhomeclient.Register(ctx, q, conf, reg)
func NewMicroNode(ctx context.Context,q chan os.Signal, serverId string, reg *RegisterInfo, procInfo *ProcInfo,fnLog func(v ...interface{})) (*MicroNode, error){
   conf := NewConfig(KEY_REGISTER,512,5,10,10,100, fnLog)
   handle, err := Register(ctx, q, conf, reg)
   if err != nil {
      return nil, err
   }
@@ -35,10 +34,10 @@
      reg:      reg,
      procInfo: procInfo,
      fnLog: fnLog,
      SubChM:   make(map[string]chan *bhomeclient.MsgInfo),
      SubChM:   make(map[string]chan *MsgInfo),
   }
   for _,subTopic := range reg.SubTopic {
      mn.SubChM[subTopic] = make(chan *bhomeclient.MsgInfo, 512)
      mn.SubChM[subTopic] = make(chan *MsgInfo, 512)
   }
   return mn, nil
@@ -52,7 +51,7 @@
   }
}
func (ms *MicroNode) UpdateNodeTopics(ts []bhomeclient.NodeInfo) {
func (ms *MicroNode) UpdateNodeTopics(ts []NodeInfo) {
   ms.handle.UpdateNodeTopics(ts)
}
@@ -64,7 +63,7 @@
}
func (ms *MicroNode) startHeartbeat() {
   hbi := &bhomeclient.HeartBeatInfo{
   hbi := &HeartBeatInfo{
      HealthLevel: "health",
      Fps:         12,
      WarnInfo:    "warn",
@@ -125,7 +124,7 @@
   ms.printLog("1:", time.Since(t))
   t = time.Now()
   rb, _ := json.Marshal(request)
   msgR := &bhomeclient.MsgInfo {
   msgR := &MsgInfo {
      Topic: request.Path,
      Body: rb,
   }
@@ -153,7 +152,7 @@
func (ms *MicroNode) RequestTopic(serverId string, request Request) (*Reply,error) {
   rb, _ := json.Marshal(request)
   msgR := &bhomeclient.MsgInfo{
   msgR := &MsgInfo{
      Topic: request.Path,
      Body: rb,
   }
@@ -192,7 +191,7 @@
   return netNodes
}
func (ms *MicroNode) serve(msgR *bhomeclient.MsgInfo, p int) {
func (ms *MicroNode) serve(msgR *MsgInfo, p int) {
   var reqBody Request
   err := json.Unmarshal(msgR.Body, &reqBody)
   if err != nil {
@@ -216,7 +215,7 @@
   if err != nil {
      ms.printLog("marshal *ri err:", err)
   }
   rMsg := bhomeclient.MsgInfo{
   rMsg := MsgInfo{
      Body: rd,
   }
   ms.handle.Reply(p, rMsg)
@@ -229,7 +228,7 @@
}
func (ms *MicroNode) PublishNet(nodes []bhomebus.NetNode, topic string,msg []byte) error {
   pi := &bhomeclient.MsgInfo{
   pi := &MsgInfo{
      Topic: topic,
      Body: msg,
   }