// // rhctl // // Copyright (C) 2009-2016 Christian Pointner // // This file is part of rhctl. // // rhctl is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // rhctl is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with rhctl. If not, see . // package main type SwitchControl struct { sw *AudioSwitch servers []*PlayoutServer } 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 { 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 } } func SwitchControlInit(conf *Config, sw *AudioSwitch, servers []*PlayoutServer) (ctrl *SwitchControl) { ctrl = &SwitchControl{} ctrl.sw = sw ctrl.servers = servers return }