summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-03-26 22:50:49 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-03-26 22:50:49 (GMT)
commit53d0b44c0e1e51ab70dfa75cc94087359fc90b49 (patch)
tree7ab79e0b94e20d9b848169717243fc73cdc18375 /src
parent51d11296928da674b38df14697ba849d106b7cce (diff)
parsing server channel command works
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/main.go5
-rw-r--r--src/rhctl/playout_server.go49
2 files changed, 47 insertions, 7 deletions
diff --git a/src/rhctl/main.go b/src/rhctl/main.go
index 23a7f13..4638293 100644
--- a/src/rhctl/main.go
+++ b/src/rhctl/main.go
@@ -116,6 +116,11 @@ func main() {
}(server)
}
+ // TODO: remove this after testing server interface
+ for {
+ rhl.Printf("new server state: %+v", <-servers[0].Updates)
+ }
+
<-stop
rhl.Printf("at least one essential part has stopped - bringing down the whole process")
}
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)