diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-26 22:50:49 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-26 22:50:49 (GMT) |
commit | 53d0b44c0e1e51ab70dfa75cc94087359fc90b49 (patch) | |
tree | 7ab79e0b94e20d9b848169717243fc73cdc18375 /src/rhctl/playout_server.go | |
parent | 51d11296928da674b38df14697ba849d106b7cce (diff) |
parsing server channel command works
Diffstat (limited to 'src/rhctl/playout_server.go')
-rw-r--r-- | src/rhctl/playout_server.go | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go index 276c462..506279b 100644 --- a/src/rhctl/playout_server.go +++ b/src/rhctl/playout_server.go @@ -23,7 +23,7 @@ package main import ( "fmt" - "time" + "strings" ) type ServerHealth bool @@ -33,27 +33,62 @@ const ( Alive = true ) +type ServerStatus struct { + health ServerHealth + channel string +} + type PlayoutServer struct { name string control *SerialPort heartbeat *SerialPort - health ServerHealth - channel string + status ServerStatus + Updates chan ServerStatus +} + +func (srv *PlayoutServer) handleControl(data string) { + rhdl.Printf("Server(%s): got control message: %q", srv.name, data) + + if strings.HasPrefix(data, "channel ") { + if len(data) <= 8 { + rhl.Printf("Server(%s) sent empty channel name", srv.name) + return + } + srv.status.channel = data[8:] + srv.Updates <- srv.status + return + } + rhl.Printf("Warning: ignoring unknown control message from '%s': %q", srv.name, data) +} + +func (srv *PlayoutServer) handleHeartbeat(data string) { + rhdl.Printf("Server(%s): got heartbeat message: %q", srv.name, data) } func (srv *PlayoutServer) Run() { - rhdl.Printf("running playout server: %s", srv.name) + stop := make(chan bool) + srv.control.Run(stop) + srv.heartbeat.Run(stop) + rhdl.Printf("Server(%s) handler running...", srv.name) for { - time.Sleep(time.Second) + select { + case <-stop: + return + case data := <-srv.control.rx: + srv.handleControl(data) + case data := <-srv.heartbeat.rx: + srv.handleHeartbeat(data) + } } } func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) { srv = &PlayoutServer{} srv.name = name - srv.health = Dead - srv.channel = "music" + srv.status.health = Dead + srv.status.channel = "" + srv.Updates = make(chan ServerStatus, 8) if srv.control, err = SerialOpen(conf.Servers[name].ControlDevice, conf.Servers[name].ControlBaudrate, "\r\n"); err != nil { err = fmt.Errorf("Error opening control port(%s): %s", srv.name, err) |