From 61f48b85e0c0301b1c5384c09c822bc5e2265a4f Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@spreadspace.org>
Date: Sun, 27 Mar 2016 22:14:59 +0200
Subject: receiving of updates from switch as well from servers works now


diff --git a/src/rhctl/playout_server.go b/src/rhctl/playout_server.go
index 1f38f42..9f8b9d1 100644
--- a/src/rhctl/playout_server.go
+++ b/src/rhctl/playout_server.go
@@ -45,6 +45,7 @@ func (s ServerHealth) String() string {
 }
 
 type ServerStatus struct {
+	Name    string
 	Health  ServerHealth
 	Channel string
 }
@@ -145,6 +146,7 @@ func ServerInit(name string, conf *Config) (srv *PlayoutServer, err error) {
 	if conf.Servers[name].HeartbeatThreshold > 0 {
 		srv.hbthreshold = conf.Servers[name].HeartbeatThreshold
 	}
+	srv.status.Name = srv.name
 	srv.status.Health = ServerDead
 	srv.status.Channel = ""
 	srv.Updates = make(chan ServerStatus, 8)
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index de5bf6d..40dd788 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -21,20 +21,39 @@
 
 package main
 
-import (
-	"time"
-)
-
 type SwitchControl struct {
 	sw      *AudioSwitch
 	servers []*PlayoutServer
 }
 
-func (sw *SwitchControl) Run() {
+func handleServer(in <-chan ServerStatus, out chan<- ServerStatus) {
+	for {
+		update := <-in
+		out <- update
+	}
+}
+
+func (ctrl *SwitchControl) Run() {
 	rhdl.Printf("SwitchCTRL: handler running...")
 
+	serverUpdates := make(chan ServerStatus, 8)
+	for _, srv := range ctrl.servers {
+		go handleServer(srv.Updates, serverUpdates)
+	}
+
 	for {
-		time.Sleep(time.Second)
+		select {
+		case update := <-ctrl.sw.Updates:
+			rhdl.Printf("got update from switch: %+v", update)
+			for _, srv := range ctrl.servers {
+				srv.SwitchUpdates <- update
+			}
+			// TODO: send out to all clients who are interested in this
+		case status := <-serverUpdates:
+			rhdl.Printf("got server status update: %+v", status)
+			// TODO: recalculate overall status and send out commands to switch
+		}
+		// TODO: add handler for requests from control clients
 	}
 }
 
-- 
cgit v0.10.2