summaryrefslogtreecommitdiff
path: root/src/rhctl/switch_control.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl/switch_control.go')
-rw-r--r--src/rhctl/switch_control.go105
1 files changed, 39 insertions, 66 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index a7b5a58..ec77b2e 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -165,17 +165,12 @@ func (ctrl *SwitchControl) getSwitchServerAssignment() (swsrv, swch string, err
return "", "", errors.New("no or more than one input is active")
}
- for _, in := range ctrl.sw.Inputs {
- if in.Number == activeInput {
- return in.Server, in.Channel, nil
- }
- }
- return "", "", errors.New("unknown input")
+ return ctrl.sw.Inputs.GetServerAndChannel(activeInput)
}
func (ctrl *SwitchControl) selectServer(server string) bool {
- newIn := ctrl.sw.Inputs.Get(server, ctrl.state.Server[server].Channel)
- if newIn == SwitchInputNum(0) {
+ newIn, err := ctrl.sw.Inputs.GetNumber(server, ctrl.state.Server[server].Channel)
+ if err != nil {
rhdl.Printf("SwitchCTRL: no audio input configured for server/channel: '%s/%s'", server, ctrl.state.Server[server].Channel)
return false
}
@@ -207,79 +202,57 @@ func (ctrl *SwitchControl) selectNextValidServer() {
}
func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
+ // TODO: requested server is ignored in any case... fix this
if !ctrl.state.Settled {
return
}
+ if len(ctrl.servers) < 1 {
+ ctrl.state.Mood = MoodHappy
+ rhdl.Printf("SwitchCTRL: there are no servers configured -> now in mood: %s", ctrl.state.Mood)
+ return
+ }
+ if ctrl.state.Mood == MoodAwakening && requestedServer != "" {
+ rhl.Printf("SwitchCTRL: ignoreing preferred server requests while waking-up")
+ return
+ }
rhdl.Printf("SwitchCTRL: reconciling state... (requested server: '%s')", requestedServer)
- switch ctrl.state.Mood {
- case MoodAwakening:
- if len(ctrl.servers) < 1 {
- ctrl.state.Mood = MoodHappy
- rhdl.Printf("SwitchCTRL: there are no servers configured -> now in mood: %s", ctrl.state.Mood)
- return
- }
-
- if requestedServer != "" {
- rhl.Printf("SwitchCTRL: ignoreing preferred server requests while waking-up")
- return
- }
-
- swsrv, swch, err := ctrl.getSwitchServerAssignment()
- if err != nil {
- ctrl.state.Mood = MoodSad
- rhl.Printf("SwitchCTRL: just woken up... switch input assignments are ambigious or outdated -> now in mood: %s", ctrl.state.Mood)
- return
- }
+ swsrv, swch, err := ctrl.getSwitchServerAssignment()
+ if err != nil {
+ ctrl.state.Mood = MoodSad
+ rhl.Printf("SwitchCTRL: switch input assignments are ambigious -> now in mood: %s", ctrl.state.Mood)
+ return
+ }
+ rhl.Printf("SwitchCTRL: switch is set to server/channel: '%s/%s'", swsrv, swch)
- rhl.Printf("SwitchCTRL: just woken up... switch is set to server '%s' channel '%s'", swsrv, swch)
+ s, exists := ctrl.state.Server[swsrv]
+ if !exists || s.Health != ServerAlive || s.Channel == "" {
+ rhl.Printf("SwitchCTRL: server '%s' is unknown, dead or has invalid channel!", swsrv)
+ ctrl.selectNextValidServer()
+ return
+ }
+ ctrl.state.ActiveServer = swsrv
- s, exists := ctrl.state.Server[swsrv]
- if !exists || s.Health != ServerAlive || s.Channel == "" {
- rhl.Printf("SwitchCTRL: server '%s' is unknown, dead or has invalid channel!", swsrv)
+ if s.Channel != swch {
+ // TODO: during normal operation switching server channels is expected and shouldn't lead to mood nervous?!?!?
+ ctrl.state.Mood = MoodNervous
+ rhl.Printf("SwitchCTRL: switch and server channel mismatch: '%s' != '%s' -> now in mood: %s", swch, s.Channel, ctrl.state.Mood)
+ if !ctrl.selectServer(ctrl.state.ActiveServer) {
ctrl.selectNextValidServer()
- return
- }
-
- ctrl.state.ActiveServer = swsrv
-
- if s.Channel != swch {
- ctrl.state.Mood = MoodNervous
- rhl.Printf("SwitchCTRL: switch and server channel mismatch: '%s' != '%s' -> now in mood: %s", swch, s.Channel, ctrl.state.Mood)
- if !ctrl.selectServer(ctrl.state.ActiveServer) {
- ctrl.selectNextValidServer()
- }
- return
}
-
- for _, s := range ctrl.state.Server {
- if s.Health != ServerAlive {
- ctrl.state.Mood = MoodNervous
- rhl.Printf("SwitchCTRL: at least one configured server is dead -> now in mood: %s", ctrl.state.Mood)
- return
- }
- }
- ctrl.state.Mood = MoodHappy
- rhl.Printf("SwitchCTRL: all servers are alive -> now in mood: %s", ctrl.state.Mood)
return
+ }
- default:
- if len(ctrl.servers) < 1 {
- ctrl.state.Mood = MoodHappy
- rhdl.Printf("SwitchCTRL: there are no servers configured -> now in mood: %s", ctrl.state.Mood)
+ for _, s := range ctrl.state.Server {
+ if s.Health != ServerAlive {
+ ctrl.state.Mood = MoodNervous
+ rhl.Printf("SwitchCTRL: at least one configured server is dead -> now in mood: %s", ctrl.state.Mood)
return
}
-
- rhl.Printf("SwitchCTRL: error handling of mood %s is not implemented", ctrl.state.Mood)
}
-
- // TODO: change active server if it fails or on request
- // return true if requested server got selected
-
- // TODO: change switch output mappings if servers change channels or fail
-
- // TODO: set mood dependent on overall-state
+ ctrl.state.Mood = MoodHappy
+ rhl.Printf("SwitchCTRL: all servers are alive -> now in mood: %s", ctrl.state.Mood)
return
}