summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rhctl/switch_control.go21
-rw-r--r--src/rhctl/telnet.go18
2 files changed, 29 insertions, 10 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index a73d465..463c97e 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -96,9 +96,14 @@ func (ctrl *SwitchControl) handleCommand(cmd *Command) {
case CmdState:
cmd.Response <- ctrl.state
case CmdServer:
+ if len(cmd.Args) == 0 {
+ cmd.Response <- fmt.Errorf("no server specified")
+ return
+ }
+ cmd.Response <- ctrl.reconcile(cmd.Args[0])
case CmdSwitch:
if len(cmd.Args) == 0 {
- rhl.Printf("SwitchCTRL: ignoring empty raw switch command")
+ cmd.Response <- fmt.Errorf("no command specified")
return
}
c, err := NewSwitchCommandFromStrings(cmd.Args[0], cmd.Args[1:]...)
@@ -118,15 +123,17 @@ func handleServer(in <-chan ServerState, out chan<- ServerState) {
}
}
-func (ctrl *SwitchControl) reconcile() {
- rhdl.Printf("SwitchCTRL: reconciling state...")
+func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
+ rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
// TODO: set mood dependent on overall-state
// TODO: send out commands to switch, server to get missing infos
- // TODO: change active server it fails
+ // TODO: change active server it fails or on request
+ // return true if requested server got selected
// TODO: change switch output mappings if servers change channels or fail
+ return
}
func (ctrl *SwitchControl) Run() {
@@ -137,7 +144,7 @@ func (ctrl *SwitchControl) Run() {
go handleServer(srv.StateChanges, serverStateChanges)
}
- ctrl.reconcile()
+ ctrl.reconcile("")
for {
select {
case update := <-ctrl.sw.Updates:
@@ -150,13 +157,13 @@ func (ctrl *SwitchControl) Run() {
rhdl.Printf("got switch state update: %+v", state)
ctrl.Updates.Pub(state, "switch:state")
ctrl.state.Switch = state
- ctrl.reconcile()
+ ctrl.reconcile("")
ctrl.Updates.Pub(ctrl.state, "state")
case state := <-serverStateChanges:
rhdl.Printf("got server state update: %+v", state)
ctrl.Updates.Pub(state, "server:state")
ctrl.state.Server[state.Name] = state
- ctrl.reconcile()
+ ctrl.reconcile("")
ctrl.Updates.Pub(ctrl.state, "state")
case cmd := <-ctrl.Commands:
ctrl.handleCommand(cmd)
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index e4044ef..a6a53fe 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -139,8 +139,19 @@ func telnetCmdListen(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
}
func telnetCmdServer(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
- ctrl.Commands <- &Command{Type: CmdServer}
- // TODO: implement this
+ resp := make(chan interface{})
+ ctrl.Commands <- &Command{Type: CmdServer, Args: args[1:], Response: resp}
+
+ r := <-resp
+ switch r.(type) {
+ case error:
+ c.Sayln("%v", r)
+ case bool:
+ if !r.(bool) {
+ c.Sayln("the switch-over was denied - is the requested server alive?")
+ }
+ }
+
return false
}
@@ -200,7 +211,8 @@ func telnetHelp(c *telgo.Client, args []string) bool {
return false
case "switch":
c.Sayln("usage: switch <cmd> [ [ <arg1> ] ... ]")
- c.Sayln(" send commands to tha audio switch directley.")
+ c.Sayln(" send commands to tha audio switch directly.")
+ // TODO: print help text for raw switch commands
return false
}
fallthrough