summaryrefslogtreecommitdiff
path: root/src/rhctl
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-20 19:20:23 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-20 19:20:23 (GMT)
commitb1350a8096e1d7d11408b19b438ca09912e03c2d (patch)
tree457cd0da66535a2c4e6824105ad9b4874d4da908 /src/rhctl
parent68bf38157465311e6e5bb83723c2097d1d11da58 (diff)
selecting server should work now - needs testing!
Diffstat (limited to 'src/rhctl')
-rw-r--r--src/rhctl/conf.go8
-rw-r--r--src/rhctl/switch_control.go40
2 files changed, 35 insertions, 13 deletions
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index 36a3b5a..bf68fec 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -40,6 +40,14 @@ type ConfigSwitchInputs []struct {
func (p ConfigSwitchInputs) Len() int { return len(p) }
func (p ConfigSwitchInputs) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p ConfigSwitchInputs) Less(i, j int) bool { return p[i].Number < p[j].Number }
+func (p ConfigSwitchInputs) Get(server, channel string) SwitchInputNum {
+ for _, i := range p {
+ if i.Server == server && i.Channel == channel {
+ return i.Number
+ }
+ }
+ return SwitchInputNum(0)
+}
type Config struct {
Audioswitch struct {
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 8440e61..a7b5a58 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -173,8 +173,13 @@ func (ctrl *SwitchControl) getSwitchServerAssignment() (swsrv, swch string, err
return "", "", errors.New("unknown input")
}
-func (ctrl *SwitchControl) selectServer(server string) {
- newIn := SwitchInputNum(1) // TODO: get input num from server name
+func (ctrl *SwitchControl) selectServer(server string) bool {
+ newIn := ctrl.sw.Inputs.Get(server, ctrl.state.Server[server].Channel)
+ if newIn == SwitchInputNum(0) {
+ rhdl.Printf("SwitchCTRL: no audio input configured for server/channel: '%s/%s'", server, ctrl.state.Server[server].Channel)
+ return false
+ }
+
for idx, in := range ctrl.state.Switch.Audio[0].Inputs {
if in && SwitchInputNum(idx+1) != newIn {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdAudioFadeDownInput, []interface{}{SwitchInputNum(idx + 1)}, nil}
@@ -183,6 +188,22 @@ func (ctrl *SwitchControl) selectServer(server string) {
ctrl.sw.Commands <- &SwitchCommand{SwitchCmdAudioFadeUpInput, []interface{}{newIn}, nil}
ctrl.settling.Reset(10 * time.Second) // TODO: hardcoded value
ctrl.state.Settled = false
+ return true
+}
+
+func (ctrl *SwitchControl) selectNextValidServer() {
+ for name, state := range ctrl.state.Server {
+ if state.Health == ServerAlive && state.Channel != "" {
+ if !ctrl.selectServer(name) {
+ continue
+ }
+ ctrl.state.Mood = MoodNervous
+ rhl.Printf("SwitchCTRL: found another valid server -> now in mood: %s", ctrl.state.Mood)
+ return
+ }
+ }
+ ctrl.state.Mood = MoodSad
+ rhl.Printf("SwitchCTRL: found no alive/valid server -> now in mood: %s", ctrl.state.Mood)
}
func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
@@ -217,16 +238,7 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
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)
- for name, state := range ctrl.state.Server {
- if state.Health == ServerAlive && state.Channel != "" {
- ctrl.state.Mood = MoodNervous
- rhl.Printf("SwitchCTRL: found another valid server -> now in mood: %s", ctrl.state.Mood)
- ctrl.selectServer(name)
- return
- }
- }
- ctrl.state.Mood = MoodSad
- rhl.Printf("SwitchCTRL: found no alive server -> now in mood: %s", ctrl.state.Mood)
+ ctrl.selectNextValidServer()
return
}
@@ -235,7 +247,9 @@ func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {
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)
- ctrl.selectServer(ctrl.state.ActiveServer)
+ if !ctrl.selectServer(ctrl.state.ActiveServer) {
+ ctrl.selectNextValidServer()
+ }
return
}