summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-19 00:41:28 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-19 00:41:28 (GMT)
commitdf0caeadd4412bc25573665cad3e6e49551a7163 (patch)
tree2ac52f9f830780d20be86ea417dee8e836441c4e /src
parent80e141f45e0d017816e7fe41ff4aba6c72f3965e (diff)
enforce uniqueness in confi switch port assignment
Diffstat (limited to 'src')
-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) {