-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
dev_tracker.go
139 lines (120 loc) · 2.75 KB
/
dev_tracker.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
ws "github.com/gorilla/websocket"
"sync"
)
type VidConn struct {
socket *ws.Conn
stopChan chan bool
offset int64
}
type DevStatus struct {
wda bool
cfa bool
video bool
}
type DevTracker struct {
provConns map[int64]*ProviderConnection
devToProv map[string]int64
DevStatus map[string]*DevStatus
vidConns map[string]*VidConn
clients map[string]chan ClientMsg
lock *sync.Mutex
config *Config
}
func NewDevTracker(config *Config) *DevTracker {
self := &DevTracker{
provConns: make(map[int64]*ProviderConnection),
devToProv: make(map[string]int64),
lock: &sync.Mutex{},
vidConns: make(map[string]*VidConn),
DevStatus: make(map[string]*DevStatus),
clients: make(map[string]chan ClientMsg),
config: config,
}
return self
}
func (self *DevTracker) setVidStreamOutput(udid string, vidConn *VidConn) {
self.lock.Lock()
self.vidConns[udid] = vidConn
self.lock.Unlock()
}
func (self *DevTracker) getVidStreamOutput(udid string) *VidConn {
return self.vidConns[udid]
}
func (self *DevTracker) setDevProv(udid string, provId int64) {
self.lock.Lock()
self.devToProv[udid] = provId
self.DevStatus[udid] = &DevStatus{}
self.lock.Unlock()
}
func (self *DevTracker) clearDevProv(udid string) {
self.lock.Lock()
delete(self.devToProv, udid)
delete(self.DevStatus, udid)
self.lock.Unlock()
}
func (self *DevTracker) addClient(udid string, msgChan chan ClientMsg) {
self.lock.Lock()
self.clients[udid] = msgChan
self.lock.Unlock()
}
func (self *DevTracker) deleteClient(udid string) {
self.lock.Lock()
delete(self.clients, udid)
self.lock.Unlock()
}
func (self *DevTracker) msgClient(udid string, msg ClientMsg) {
msgChan, chanOk := self.clients[udid]
if !chanOk {
return
}
msgChan <- msg
}
func (self *DevTracker) setDevStatus(udid string, service string, status bool) {
stat, statOk := self.DevStatus[udid]
if !statOk {
return
}
if service == "wda" {
stat.wda = status
return
}
if service == "cfa" {
stat.cfa = status
return
}
if service == "video" {
stat.video = status
return
}
}
func (self *DevTracker) getDevStatus(udid string) *DevStatus {
devStatus, devOk := self.DevStatus[udid]
if devOk {
return devStatus
} else {
return nil
}
}
func (self *DevTracker) getDevProvId(udid string) int64 {
provId, provOk := self.devToProv[udid]
if provOk {
return provId
} else {
return 0
}
}
func (self *DevTracker) setProvConn(provId int64, provConn *ProviderConnection) {
self.lock.Lock()
self.provConns[provId] = provConn
self.lock.Unlock()
}
func (self *DevTracker) getProvConn(provId int64) *ProviderConnection {
return self.provConns[provId]
}
func (self *DevTracker) clearProvConn(provId int64) {
self.lock.Lock()
delete(self.provConns, provId)
self.lock.Unlock()
}