]> code.octet-stream.net Git - broadcaster/blob - server/status.go
Initial commit, basic functionality working
[broadcaster] / server / status.go
1 package main
2
3 import (
4 "code.octet-stream.net/broadcaster/protocol"
5 )
6
7 type ServerStatus struct {
8 statuses map[int]protocol.StatusMessage
9 changeWait chan bool
10 }
11
12 var status ServerStatus
13
14 func InitServerStatus() {
15 status = ServerStatus{
16 statuses: make(map[int]protocol.StatusMessage),
17 changeWait: make(chan bool),
18 }
19 }
20
21 func (s *ServerStatus) MergeStatus(radioId int, status protocol.StatusMessage) {
22 s.statuses[radioId] = status
23 s.TriggerChange()
24 }
25
26 func (s *ServerStatus) RadioDisconnected(radioId int) {
27 delete(s.statuses, radioId)
28 s.TriggerChange()
29 }
30
31 func (s *ServerStatus) TriggerChange() {
32 close(s.changeWait)
33 s.changeWait = make(chan bool)
34 }
35
36 func (s *ServerStatus) Statuses() map[int]protocol.StatusMessage {
37 return s.statuses
38 }
39
40 func (s *ServerStatus) ChangeChannel() chan bool {
41 return s.changeWait
42 }