package tui import ( _ "fmt" "sync" ) type LocalView struct { sync.Mutex Reactors map[uint32]*Reactor *TUIClient // embedding for easy grpc calls } type Reactor struct { Status bool Devices map[int]*Device } type Device struct { Type string Status string Data string } func (l *LocalView) UpdateReactors(id uint32, r *Reactor) { l.Lock() defer l.Unlock() l.Reactors[id] = r } func (l *LocalView) UpdateReactorDevices(id uint32, addr int, d *Device) { l.Lock() defer l.Unlock() if _, exists := l.Reactors[id]; !exists { m := make(map[int]*Device) l.Reactors[id] = &Reactor{Devices:m} l.Reactors[id].Devices[addr] = d } l.Reactors[id].Devices[addr] = d } func (l *LocalView) GetReactors() map[uint32]bool { l.Lock() defer l.Unlock() r := make(map[uint32]bool) for a,s := range l.Reactors { r[a] = s.Status } return r } func (l *LocalView) GetReactorDevices(id uint32) map[int]*Device { l.Lock() defer l.Unlock() return l.Reactors[id].Devices }