| | |
| | | "strconv" |
| | | "time" |
| | | |
| | | "basic.com/libgowrapper/sdkstruct.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/deliver.git" |
| | | "github.com/gogo/protobuf/proto" |
| | | ) |
| | | |
| | | const mode = deliver.PushPull |
| | | |
| | | // GetIpcAddress get ipc |
| | | func GetIpcAddress(shm bool, id string) string { |
| | |
| | | time.Sleep(10 * time.Millisecond) |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Msg2MsgSDK msg->msgsdk |
| | | func Msg2MsgSDK(msg protomsg.SdkMessage) *sdkstruct.MsgSDK { |
| | | |
| | | d, err := proto.Marshal(&msg) |
| | | if err != nil { |
| | | return nil |
| | | } |
| | | |
| | | index, count := int(msg.Tasklab.Index), len(msg.Tasklab.Sdkinfos) |
| | | if index >= count { |
| | | return &sdkstruct.MsgSDK{ |
| | | MsgData: d, |
| | | SdkCount: count, |
| | | SdkIndex: index, |
| | | SdkDataLen: 0, |
| | | } |
| | | } |
| | | |
| | | return &sdkstruct.MsgSDK{ |
| | | MsgData: d, |
| | | SdkCount: count, |
| | | SdkIndex: index, |
| | | SdkDataLen: len(d), |
| | | } |
| | | } |
| | | |
| | | // EjectResult eject |
| | | func EjectResult(res []byte, msg protomsg.SdkMessage, out chan<- sdkstruct.MsgSDK) { |
| | | |
| | | if res == nil { |
| | | s := Msg2MsgSDK(msg) |
| | | if s == nil { |
| | | return |
| | | } |
| | | out <- *s |
| | | return |
| | | } |
| | | |
| | | msg.Tasklab.Sdkinfos[int(msg.Tasklab.Index)].Sdkdata = res |
| | | |
| | | s := Msg2MsgSDK(msg) |
| | | if s == nil { |
| | | return |
| | | } |
| | | out <- *s |
| | | } |
| | | |
| | | ///////////////////////////////////////////////////////////// |
| | | |
| | | // ValidRemoteMessage valid or not |
| | | func ValidRemoteMessage(msg protomsg.SdkMessage, fnName string, fn func(...interface{})) bool { |
| | | if msg.Tasklab == nil { |
| | | fn(fnName, " recieve msg nil") |
| | | return false |
| | | } |
| | | |
| | | sdkLen := len(msg.Tasklab.Sdkinfos) |
| | | if sdkLen == 0 { |
| | | fn(fnName, " has no sdk info") |
| | | return false |
| | | } |
| | | |
| | | curIndex := int(msg.Tasklab.Index) |
| | | if curIndex < 0 || curIndex >= sdkLen { |
| | | fn(fnName, " tasklab index ", curIndex, " error") |
| | | return false |
| | | } |
| | | if msg.Tasklab.Sdkinfos[curIndex].Sdktype != fnName { |
| | | fn(fnName, " is different from ", msg.Tasklab.Sdkinfos[curIndex].Sdktype) |
| | | return false |
| | | } |
| | | return true |
| | | } |
| | | |
| | | // UnpackImage unpack |