-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.go
95 lines (68 loc) · 1.42 KB
/
global.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package global
import (
"errors"
"sync"
"github.com/dekoch/gouniversal/module/monmotion/core"
"github.com/dekoch/gouniversal/module/monmotion/moduleconfig"
"github.com/dekoch/gouniversal/module/monmotion/ui/pageviewer/uirequest"
"github.com/dekoch/gouniversal/shared/language"
)
var (
Config moduleconfig.ModuleConfig
Lang language.Language
Cores []core.Core
UIRequest uirequest.UIRequest
mut sync.Mutex
)
func AddCores(n int) {
for i := 0; i < n; i++ {
var nc core.Core
Cores = append(Cores, nc)
}
}
func IsCoreAvailable(uid string) bool {
mut.Lock()
defer mut.Unlock()
for i := range Cores {
if Cores[i].GetUUID() == uid {
return true
}
}
return false
}
func GetCore(uid string) (*core.Core, error) {
mut.Lock()
defer mut.Unlock()
for i := range Cores {
if Cores[i].GetUUID() == uid {
return &Cores[i], nil
}
}
var n core.Core
return &n, errors.New("device uuid not found")
}
func GetFreeCore() (*core.Core, error) {
mut.Lock()
defer mut.Unlock()
for i := range Cores {
if Cores[i].GetUUID() == "" {
return &Cores[i], nil
}
}
var n core.Core
return &n, errors.New("no free core found")
}
func ExitCore(uid string) error {
mut.Lock()
defer mut.Unlock()
for i := range Cores {
if Cores[i].GetUUID() == uid {
err := Cores[i].Stop()
if err != nil {
return err
}
return Cores[i].Exit()
}
}
return errors.New("device uuid not found")
}