From f3d1415f01b6db394cb31d232662cd6db204fd5f Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 23 十二月 2019 09:31:50 +0800
Subject: [PATCH] update;

---
 .gitignore              |    1 
 app/master/master.go    |   31 +---------
 libgowrapper/humantrack |    2 
 libcomm/db.go           |  109 ++++++++++++++++++++++++++++++++++++
 libgowrapper/vehicle    |    2 
 go.mod                  |    1 
 libgowrapper/face       |    2 
 libgowrapper/yolo       |    2 
 main.go                 |    2 
 libcomm/make.sh         |    5 +
 libcomm/go.mod          |   19 ++++++
 11 files changed, 142 insertions(+), 34 deletions(-)

diff --git a/.gitignore b/.gitignore
index d761c0c..ffa5f2b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@
 data/
 runtime/
 libs/
+libcomm.so
diff --git a/app/master/master.go b/app/master/master.go
index 1180edc..fa83f15 100644
--- a/app/master/master.go
+++ b/app/master/master.go
@@ -5,7 +5,6 @@
 	"analysis/logo"
 	"analysis/util"
 	"context"
-	"io/ioutil"
 
 	"basic.com/libgowrapper/sdkstruct.git"
 )
@@ -17,36 +16,12 @@
 }
 
 // Run run
-func Run(ctx context.Context, configPath string) bool {
+func Run(ctx context.Context, configPath, soFile string) bool {
 	reaper(ctx)
 
-	rPath := configPath
-	configFile := configPath
-	var fetcher *Fetcher
-
-	fs, _ := ioutil.ReadDir(rPath)
-	for _, file := range fs {
-		if !file.IsDir() {
-			if rPath[len(rPath)-1] != '/' {
-				configFile = rPath + "/" + file.Name()
-			} else {
-				configFile = rPath + file.Name()
-			}
-
-			cfg, err := app.ReadConfig(configFile)
-			if err != nil {
-				logo.Errorln("Run Fetcher Master Read From File: ", configFile, " Config Error: ", err)
-				continue
-			}
-			fetcher = NewFetcher(cfg.SoFile)
-			if fetcher == nil {
-				logo.Errorln("New Fetcher Load so File Funcs Error From File: ", cfg.SoFile)
-				continue
-			}
-		}
-	}
+	fetcher := NewFetcher(soFile)
 	if fetcher == nil {
-		logo.Errorln("!!!!!!Read All So File, But Can't Init DB Fetcher")
+		logo.Errorln("New Fetcher Load so File Funcs Error From File: ", soFile)
 		return false
 	}
 
diff --git a/go.mod b/go.mod
index 9cca7cb..f83e480 100644
--- a/go.mod
+++ b/go.mod
@@ -8,5 +8,4 @@
 	github.com/amoghe/distillog v0.0.0-20180726233512-ae382b35b717
 	github.com/natefinch/lumberjack v2.0.0+incompatible
 	github.com/spf13/viper v1.6.1
-	golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
 )
diff --git a/libcomm/db.go b/libcomm/db.go
new file mode 100644
index 0000000..3b3e278
--- /dev/null
+++ b/libcomm/db.go
@@ -0,0 +1,109 @@
+package main
+
+import (
+	"fmt"
+	"strconv"
+
+	"basic.com/dbapi.git"
+	"basic.com/libgowrapper/sdkstruct.git"
+	"basic.com/pubsub/cache.git/shardmap"
+	"basic.com/pubsub/protomsg.git"
+	"basic.com/valib/gopherdiscovery.git"
+	"github.com/gogo/protobuf/proto"
+)
+
+const (
+	prefixTASKSDKRULE = "TASKSDKRULE_"
+)
+
+var cMap *shardmap.ShardMap
+
+// InitDBAPI init dbapi
+func InitDBAPI(ip string, httpPort, heartBeatPort, dataPort int, log func(...interface{})) {
+	dbapi.Init(ip, httpPort)
+	var initchan = make(chan bool)
+	go InitCache(initchan, ip, heartBeatPort, dataPort)
+	log("db init done!", <-initchan)
+}
+
+// TaskInfos get camera infos from sqlite db
+func TaskInfos() []protomsg.TaskSdkInfo {
+	tAPI := dbapi.TaskApi{}
+	tasks := tAPI.FindAll()
+
+	return tasks
+}
+
+// SDKInfo get sdk
+func SDKInfo() []sdkstruct.SDKInfo {
+	sAPI := dbapi.SdkApi{}
+
+	s := sAPI.FindAllSdkRun()
+	var sdks []sdkstruct.SDKInfo
+	for _, v := range s {
+		sdks = append(sdks, sdkstruct.SDKInfo{
+			IpcID:   v.IpcId,
+			SdkType: v.SdkType,
+		})
+	}
+	return sdks
+}
+
+// InitCache cache
+func InitCache(initChan chan bool, dbIP string, surveyPort int, pubSubPort int) {
+	cMap = shardmap.New(uint8(32))
+	urlSurvey := "tcp://" + dbIP + ":" + strconv.Itoa(surveyPort)
+	urlPubSub := "tcp://" + dbIP + ":" + strconv.Itoa(pubSubPort)
+	client, _ := gopherdiscovery.ClientWithSub(urlSurvey, urlPubSub, "analysisProc")
+	recvMsg := client.HeartBeatMsg()
+	fmt.Println(<-recvMsg)
+
+	initCacheData(initChan)
+
+	peers, _ := client.Peers()
+	for b := range peers {
+		fmt.Println("peerMsg:", b)
+		updateData(b)
+	}
+}
+
+func initCacheData(initChan chan bool) {
+	initTaskSdkRule()
+	initChan <- true
+}
+
+func initTaskSdkRule() {
+	var api dbapi.TaskSdkRuleApi
+
+	b, rules := api.FindAllTaskSdkRules()
+	if b {
+		if rules != nil {
+			for _, tRule := range rules {
+				cMap.Set(prefixTASKSDKRULE+tRule.TaskId, tRule.SdkRules)
+			}
+		}
+	}
+}
+
+func updateData(b []byte) {
+	newUpdateMsg := &protomsg.DbChangeMessage{}
+	if err := proto.Unmarshal(b, newUpdateMsg); err != nil {
+		fmt.Println("dbChangeMsg unmarshal err:", err)
+		return
+	}
+	switch newUpdateMsg.Table {
+	case protomsg.TableChanged_T_TaskSdkRule:
+		initTaskSdkRule()
+	default:
+
+	}
+}
+
+// GetTaskSdkRules rules
+func GetTaskSdkRules(taskID string) []*protomsg.SdkRuleSet {
+	r, b := cMap.Get(prefixTASKSDKRULE + taskID)
+	if b {
+		return r.([]*protomsg.SdkRuleSet)
+	}
+	return nil
+}
diff --git a/libcomm/go.mod b/libcomm/go.mod
new file mode 100644
index 0000000..7f7f9a4
--- /dev/null
+++ b/libcomm/go.mod
@@ -0,0 +1,19 @@
+module comm
+
+go 1.12
+
+require (
+	basic.com/dbapi.git v0.0.0-20191216030028-03153c1f1f30
+	basic.com/libgowrapper/sdkstruct.git v0.0.0-20191220011601-e0b3d1f0183c
+	basic.com/pubsub/cache.git v0.0.0-20190718093725-6a413e1d7d48
+	basic.com/pubsub/protomsg.git v0.0.0-20191219033725-b95da65535d0
+	basic.com/valib/gopherdiscovery.git v0.0.0-20190605034340-15d89d8b4e28
+	github.com/ajg/form v1.5.1 // indirect
+	github.com/gogo/protobuf v1.3.1
+	golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
+	golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
+	golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
+	google.golang.org/grpc v1.26.0 // indirect
+	honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
+	nanomsg.org/go-mangos v1.4.0 // indirect
+)
diff --git a/libcomm/make.sh b/libcomm/make.sh
new file mode 100755
index 0000000..eb6ee18
--- /dev/null
+++ b/libcomm/make.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+go build -buildmode=plugin -o libcomm.so -a
+mv libcomm.so ..
+
diff --git a/libgowrapper/face b/libgowrapper/face
index a79283f..d30dfa5 160000
--- a/libgowrapper/face
+++ b/libgowrapper/face
@@ -1 +1 @@
-Subproject commit a79283f652e78fb8591a8af69f973055f9730c9d
+Subproject commit d30dfa5952c21e88210004a6341a16eb0ee68e2e
diff --git a/libgowrapper/humantrack b/libgowrapper/humantrack
index eb177ba..4c0bbb8 160000
--- a/libgowrapper/humantrack
+++ b/libgowrapper/humantrack
@@ -1 +1 @@
-Subproject commit eb177ba4a1f61e268dacb77d065d88cb70441d1a
+Subproject commit 4c0bbb853bef9103167f4d7d4a08b9b2ce30bd6b
diff --git a/libgowrapper/vehicle b/libgowrapper/vehicle
index c4ec8a5..e28bf7d 160000
--- a/libgowrapper/vehicle
+++ b/libgowrapper/vehicle
@@ -1 +1 @@
-Subproject commit c4ec8a5f30cb29dc407472d244a537973b7d3567
+Subproject commit e28bf7df5c319218e5633e0ebd9bdcc9ec84b97a
diff --git a/libgowrapper/yolo b/libgowrapper/yolo
index 2e1584a..578175f 160000
--- a/libgowrapper/yolo
+++ b/libgowrapper/yolo
@@ -1 +1 @@
-Subproject commit 2e1584a6d6d185d8ed950a60f97532c3eb14aa6a
+Subproject commit 578175fa42aece999fc70143535d3ebb6dfbca3f
diff --git a/main.go b/main.go
index 8702d5e..777cf7c 100644
--- a/main.go
+++ b/main.go
@@ -114,7 +114,7 @@
 	ret := false
 	if role == roleMaster {
 		setParamters()
-		ret = master.Run(ctx, configPath)
+		ret = master.Run(ctx, configPath, "./libcomm.so")
 
 	} else if role == roleSlave {
 		ret = slave.Run(ctx, configPath, runType, id, gpu, shm)

--
Gitblit v1.8.0