You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
633 B
Go
30 lines
633 B
Go
3 years ago
|
package reactor
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
// implements grpc handler and device update handler
|
||
|
type SystemUpdates struct {
|
||
|
sync.Mutex
|
||
|
pending map[int]*Dev
|
||
|
}
|
||
|
|
||
|
type Dev struct {
|
||
|
Status string
|
||
|
Type string
|
||
|
}
|
||
|
|
||
|
func (s *SystemUpdates) DeviceUpdateHandler(a int, st, t string) {
|
||
|
s.Lock()
|
||
|
defer s.Unlock()
|
||
|
s.pending[a] = &Dev{Status:st,Type:t}
|
||
|
}
|
||
|
|
||
|
func (s *SystemUpdates) GetPendingChanges() (map[int]*Dev, chan bool) {
|
||
|
// calls chld routine to block and return w/ buffer contents
|
||
|
// chan is used to send grpc res
|
||
|
// true = empty buffer
|
||
|
// false = release lock unchanged
|
||
|
res := s.LockAndWait()
|