package server import ( "fmt" "time" "sync" ) // implement tui specific manager to be called for each client conn type TUIManager struct { *Manager // embedded manager for access to methods and client Sys *KnownReactors ClientConnections <-chan bool Err chan error Hb time.Duration } type KnownReactors struct { Reactors map[uint32]*Reactor sync.Mutex } type Reactor struct { Devices map[string]*Device } type Device struct { Status DeviceStatus Type string Addr int } type DeviceStatus uint32 const ( READY DeviceStatus = iota ACTIVE DISABLED ) func (d DeviceStatus) String() string { return [...]string{"Ready","Active","Disabled"}[d] } func (d Device) String() string { return fmt.Sprintf("%v is %v at %x",d.Type,d.Status,d.Addr) } type DeviceManager interface{ // GetStatus() uint32 UNSUPPORTED: arguable memory benifit but until we support 100s of sensors across 10s of tui clients im not implementing it PrintSatus() string GetType() string } func NewTUIManager(c *Client,ch chan bool, err chan error) { k := new(KnownReactors) m := NewManager(c, err) hb := time.Duration(5) t := &TUIManager{Hb: hb,Sys: k,Err: err, ClientConnections: ch} t.Manager = m go t.Listen() } func (t *TUIManager) Listen() { for { c := <-t.ClientConnections if c { t.Start() } else { t.Exit() } } } func (t *TUIManager) Start() { t.Manager.Start() //conn := t.Conn() //go t.Monitor(conn) }