package sdk
|
|
import (
|
"fmt"
|
"reflect"
|
"videoServer/util/gosdk"
|
)
|
|
type fnParamInfo struct {
|
typ reflect.Type
|
typKind reflect.Kind
|
|
typElem reflect.Type
|
typElemKind reflect.Kind
|
}
|
|
type fnInfo struct {
|
fn interface{}
|
params []fnParamInfo
|
}
|
|
var (
|
mapSDK = make(map[string]fnInfo)
|
|
FaceDetect = "face_detect"
|
FaceProperty = "face_property"
|
FaceExtract = "face_extract"
|
FaceCompare = "face_compare"
|
FaceTrack = "face_track"
|
FaceTrackOnly = "face_track_only"
|
FaceTrackDetect = "face_track_detect"
|
YoloDetect = "yolo_detect"
|
)
|
|
func typeInfo(t reflect.Type) fnParamInfo {
|
var pInfo fnParamInfo
|
|
pInfo.typ = t
|
pInfo.typKind = t.Kind()
|
if t.Kind() == reflect.Ptr || t.Kind() == reflect.Slice || t.Kind() == reflect.Map {
|
te := t.Elem()
|
pInfo.typElem = te
|
pInfo.typElemKind = te.Kind()
|
}
|
return pInfo
|
}
|
|
func valueTypeInfo(p interface{}) fnParamInfo {
|
t := reflect.TypeOf(p)
|
return typeInfo(t)
|
}
|
|
func makeFnInfo(fnName string, i interface{}) {
|
|
f := reflect.ValueOf(i)
|
fmt.Println()
|
fmt.Println("function :", fnName)
|
numIn := f.Type().NumIn()
|
|
var paramsInfo []fnParamInfo
|
for i := 0; i < numIn; i++ {
|
t := f.Type().In(i)
|
|
pInfo := typeInfo(t)
|
|
paramsInfo = append(paramsInfo, pInfo)
|
fmt.Printf("[param %d type %s, kind %s] ", i, pInfo.typ.Name(), pInfo.typKind.String())
|
if pInfo.typElem != nil {
|
fmt.Printf("[Elem type %s, kind %s]", pInfo.typElem.Name(), pInfo.typElemKind.String())
|
}
|
fmt.Println()
|
|
}
|
|
mapSDK[fnName] = fnInfo{i, paramsInfo}
|
}
|
|
func init() {
|
makeFnInfo(FaceDetect, gosdk.FaceDetect)
|
makeFnInfo(FaceProperty, gosdk.FaceProperty)
|
makeFnInfo(FaceExtract, gosdk.FaceExtract)
|
makeFnInfo(FaceCompare, gosdk.FaceCompare)
|
makeFnInfo(FaceTrack, gosdk.FaceTrack)
|
makeFnInfo(FaceTrackOnly, gosdk.FaceTrackOnly)
|
makeFnInfo(FaceTrackDetect, gosdk.FaceTrackDetect)
|
makeFnInfo(YoloDetect, gosdk.YoloDetect)
|
}
|
|
// Run sdks...
|
func Run(sdks ...string) {
|
fmt.Println("hello")
|
fmt.Println("world")
|
}
|
|
func RunSDK(sdk string) {
|
if v, ok := mapSDK[sdk]; ok {
|
DoFiledAndMethod(v.fn)
|
}
|
}
|
|
// DoFiledAndMethod 通过接口来获取任意参数,然后一一揭晓
|
func DoFiledAndMethod(input interface{}) {
|
f := reflect.ValueOf(input)
|
numIn := f.Type().NumIn()
|
|
fmt.Println("func number in param :", numIn)
|
|
for i := 0; i < numIn; i++ {
|
t := f.Type().In(i)
|
if t.Kind() == reflect.Ptr {
|
te := t.Elem()
|
fmt.Printf("t type %s, t elem type %s\n", t.Name(), te.Name())
|
}
|
fmt.Printf("param %d type %s\n", i, t.Name())
|
}
|
|
var b []gosdk.CObjInfo
|
var a []gosdk.CObjInfo
|
|
bInfo := valueTypeInfo(b)
|
aInfo := valueTypeInfo(a)
|
fmt.Printf("a type %+v is b type %+v :%t\n", aInfo, bInfo, bInfo == aInfo)
|
fmt.Println("b type:", valueTypeInfo(b).typ.Name(), valueTypeInfo(b).typKind.String())
|
}
|