forked from iflytek/aiges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback_c_linux.go
61 lines (57 loc) · 1.47 KB
/
callback_c_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build linux && cgo
// +build linux,cgo
package widget
/*
#include "./widget/wrapper.h"
#include <stdlib.h>
*/
import "C"
import (
"errors"
"github.com/xfyun/aiges/instance"
"unsafe"
)
//export engineCreateCallBack
func engineCreateCallBack(hdl unsafe.Pointer, output C.pDataList, ret C.int) (Code C.int) {
// 异步回调接口,回调结果数据写缓冲区;
var resp instance.ActMsg
last := false
if ret != 0 {
resp.AsyncErr = errors.New(engineError(int(ret)))
resp.AsyncCode = int(ret)
} else {
resp.DeliverData = make([]instance.DataMeta, 0, 1)
for output != nil {
var ele instance.DataMeta
ele.DataDesc = make(map[string]string)
ele.DataId = C.GoString((*output).key)
ele.DataType = int((*output)._type)
ele.DataStatus = int((*output).status)
pDesc := (*output).desc
for pDesc != nil {
ele.DataDesc[C.GoString((*pDesc).key)] = C.GoString((*pDesc).value)
pDesc = (*pDesc).next
}
ele.Data = C.GoBytes(unsafe.Pointer((*output).data), C.int((*output).len))
resp.DeliverData = append(resp.DeliverData, ele)
output = (*output).next
if ele.DataStatus == int(C.DataEnd) || ele.DataStatus == int(C.DataOnce) {
// TODO 适配多数据流结果状态规则
last = true
}
}
}
var usrTag string
usrTag = C.GoString((*C.char)(hdl))
cbchan, err := instance.QueryChan(usrTag)
if err == nil {
cbchan <- resp
if last || ret != 0 {
_ = instance.FreeChan(usrTag)
}
} else {
Code = C.int(-1)
}
// C.free(hdl)
return
}