|
|
@ -3,6 +3,7 @@ package server
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
_ "fmt"
|
|
|
|
_ "fmt"
|
|
|
|
|
|
|
|
"FRMS/internal/pkg/logging"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// package will create and maintain a concurrent system structure
|
|
|
|
// package will create and maintain a concurrent system structure
|
|
|
@ -23,8 +24,9 @@ func NewStatusMonitor(ch chan *DeviceInfo) *StatusMonitor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type InfoStream struct {
|
|
|
|
type InfoStream struct {
|
|
|
|
// used for reactor and device status streams
|
|
|
|
// base stream for any reactor/device
|
|
|
|
sync.Mutex
|
|
|
|
// NewSender embedds the channel to send updates on
|
|
|
|
|
|
|
|
// NewListener will add the statusmon to the list of devs to echo to
|
|
|
|
Stream chan *DeviceInfo
|
|
|
|
Stream chan *DeviceInfo
|
|
|
|
Layout *syslayout
|
|
|
|
Layout *syslayout
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -32,7 +34,7 @@ type InfoStream struct {
|
|
|
|
type syslayout struct {
|
|
|
|
type syslayout struct {
|
|
|
|
Devs map[uint32]*DeviceInfo
|
|
|
|
Devs map[uint32]*DeviceInfo
|
|
|
|
uint32 //index
|
|
|
|
uint32 //index
|
|
|
|
sync.Mutex
|
|
|
|
sync.RWMutex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewInfoStream() *InfoStream {
|
|
|
|
func NewInfoStream() *InfoStream {
|
|
|
@ -56,32 +58,48 @@ func (s *InfoStream) AddSender() *StatusMonitor {
|
|
|
|
func (s *InfoStream) Listener() {
|
|
|
|
func (s *InfoStream) Listener() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
deviceInfo := <-s.Stream
|
|
|
|
deviceInfo := <-s.Stream
|
|
|
|
go s.Layout.Update(deviceInfo)
|
|
|
|
go s.Update(deviceInfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *syslayout) Update(d *DeviceInfo) {
|
|
|
|
func (s *InfoStream) Update(d *DeviceInfo) {
|
|
|
|
s.Lock()
|
|
|
|
s.Layout.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
if dev, ok := s.Layout.Devs[d.Id]; !ok {
|
|
|
|
// set index to be kept for the entire time the dev exists
|
|
|
|
d.Index = s.Layout.uint32
|
|
|
|
if dev, ok := s.Devs[d.Id]; !ok {
|
|
|
|
s.Layout.uint32 += 1
|
|
|
|
d.Index = s.uint32
|
|
|
|
|
|
|
|
s.uint32 += 1
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
d.Index = dev.Index
|
|
|
|
d.Index = dev.Index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Devs[d.Id] = d
|
|
|
|
s.Layout.Devs[d.Id] = d
|
|
|
|
|
|
|
|
go s.Echo(d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *InfoStream) GetLayout() map[uint32]*DeviceInfo {
|
|
|
|
func (s *InfoStream) Echo(d *DeviceInfo) {
|
|
|
|
s.Layout.Lock()
|
|
|
|
s.Listeners.RLock()
|
|
|
|
defer s.Layout.Unlock()
|
|
|
|
defer s.Listeners.RUnlock()
|
|
|
|
return s.Layout.Devs
|
|
|
|
// read only lock
|
|
|
|
|
|
|
|
for _, lis := range s.Listeners {
|
|
|
|
|
|
|
|
go func(){
|
|
|
|
|
|
|
|
lis <-d
|
|
|
|
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *InfoStream) AddListner(ch chan *DeviceInfo) {
|
|
|
|
|
|
|
|
s.Listeners.Lock()
|
|
|
|
|
|
|
|
defer s.Listeners.Unlock()
|
|
|
|
|
|
|
|
s.Listeners = append(s.Listeners, ch)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//func (s *InfoStream) GetLayout() map[uint32]*DeviceInfo {
|
|
|
|
|
|
|
|
//s.Layout.RLock()
|
|
|
|
|
|
|
|
//defer s.Layout.RUnlock()
|
|
|
|
|
|
|
|
//return s.Layout.Devs
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// status buffer maintaince
|
|
|
|
// status buffer maintaince
|
|
|
|
type StatusMonitor struct {
|
|
|
|
type StatusMonitor struct {
|
|
|
|
// serve as base to embed in managers to send/receive reactor info
|
|
|
|
// serve as base to embed in managers to send/receive device info
|
|
|
|
TransactionId chan uint32 // monotonically increases to track outdated reqs
|
|
|
|
TransactionId chan uint32 // monotonically increases to track outdated reqs
|
|
|
|
StatusChan chan *DeviceInfo // sending reactor info in same fmt
|
|
|
|
StatusChan chan *DeviceInfo // sending reactor info in same fmt
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,6 +119,7 @@ func (s *StatusMonitor) GenerateIds() {
|
|
|
|
|
|
|
|
|
|
|
|
func (s *StatusMonitor) Send(d *DeviceInfo) {
|
|
|
|
func (s *StatusMonitor) Send(d *DeviceInfo) {
|
|
|
|
d.TransactionId = <-s.TransactionId
|
|
|
|
d.TransactionId = <-s.TransactionId
|
|
|
|
|
|
|
|
logging.Debug(logging.DClient,"SYS 01 Updating %s Info (%s, %s)", d.Type, d.Status, d.Data)
|
|
|
|
s.StatusChan <-d
|
|
|
|
s.StatusChan <-d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|