summaryrefslogtreecommitdiff
path: root/src/rhctl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl')
-rw-r--r--src/rhctl/conf.go34
-rw-r--r--src/rhctl/switch_control.go1
2 files changed, 25 insertions, 10 deletions
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index 77ab174..bbf546c 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -22,24 +22,32 @@
package main
import (
+ "errors"
"os"
+ "sort"
"strings"
"time"
"github.com/naoina/toml"
)
+type ConfigSwitchPorts []struct {
+ Number SwitchInputNum `toml:"number"`
+ Server string `toml:"server"`
+ Channel string `toml:"channel"`
+}
+
+func (p ConfigSwitchPorts) Len() int { return len(p) }
+func (p ConfigSwitchPorts) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+func (p ConfigSwitchPorts) Less(i, j int) bool { return p[i].Number < p[j].Number }
+
type Config struct {
Audioswitch struct {
- Device string `toml:"dev"`
- Baudrate Baudrate `toml:"baud"`
- Timeout Duration `toml:"timeout"`
- Unit SwitchUnitID `toml:"unit"`
- Ports []struct {
- Server string `toml:"server"`
- Channel string `toml:"channel"`
- Number SwitchInputNum `toml:"number"`
- }
+ Device string `toml:"dev"`
+ Baudrate Baudrate `toml:"baud"`
+ Timeout Duration `toml:"timeout"`
+ Unit SwitchUnitID `toml:"unit"`
+ Ports ConfigSwitchPorts `toml:"ports"`
}
Servers map[string]struct {
@@ -84,5 +92,13 @@ func ReadConfig(configfile string) (conf *Config, err error) {
if err = decoder.Decode(conf); err != nil {
return
}
+
+ sort.Sort(conf.Audioswitch.Ports)
+ for i := 1; i < len(conf.Audioswitch.Ports); i++ {
+ if conf.Audioswitch.Ports[i].Number == conf.Audioswitch.Ports[i-1].Number {
+ return nil, errors.New("audioswitch port assignments must be unique")
+ }
+ }
+
return
}
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 822c044..425278e 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -148,7 +148,6 @@ func (ctrl *SwitchControl) checkMissingOrStaleStates(maxAge time.Duration) {
server.UpdateRequest <- true
}
}
-
}
func (ctrl *SwitchControl) reconcile(requestedServer string) (result bool) {