zhangmeng
2020-01-21 9d9cd1d3b93613071d1dffc1c82c4515d2a65af6
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
package slave
 
import (
    "analysis/app"
    "analysis/logo"
    "context"
    "plugin"
)
 
// func Create(config string, typ, id string, gpu int, shm bool, ipc2Rule string, ruleMaxSize int, fn func(...interface{}), reserved map[string]string) interface{}
// func Run(ctx context.Context, i interface{}) {
 
// SDK plugin Func
type SDK struct {
    fnCreate func(string, string, string, int, bool, string, int, func(...interface{}), map[string]interface{}) interface{}
    fnRun    func(context.Context, interface{})
}
 
// LoadSDK from plugin
func LoadSDK(soFile string) *SDK {
    plug, err := plugin.Open(soFile)
    if err != nil {
        logo.Errorln("Slave Open so File: ", soFile, " Error: ", err)
        return nil
    }
 
    fnC, err := app.LoadFunc(plug, soFile, "Create")
    if err != nil {
        logo.Errorln("Load Func Create From: ", soFile, " Error: ", err)
        return nil
    }
 
    fnR, err := app.LoadFunc(plug, soFile, "Run")
    if err != nil {
        logo.Errorln("Load Func Run From: ", soFile, " Error: ", err)
        return nil
    }
    return &SDK{
        fnCreate: fnC.(func(string, string, string, int, bool, string, int, func(...interface{}), map[string]interface{}) interface{}),
        fnRun:    fnR.(func(context.Context, interface{})),
    }
}