summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-03-26 19:23:34 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-03-26 19:23:34 (GMT)
commitf27fa7e80e6052ce927b064bf9292dd94a480f39 (patch)
tree9ce0a440f7bd098cc801df416658e4d96283b3b4
parent9c3fc8f9fa3f54566286f2e2222ab16f7634c325 (diff)
add timeout for audioswtich commands to config file
-rw-r--r--sample-config.toml1
-rw-r--r--src/rhctl/conf.go18
-rw-r--r--src/rhctl/main.go5
3 files changed, 22 insertions, 2 deletions
diff --git a/sample-config.toml b/sample-config.toml
index 9afeff2..e5f87df 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -1,6 +1,7 @@
[audioswitch]
dev = "/dev/ttyUSB0"
baud = 9600
+timeout = "500ms"
[servers]
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index acd5cd1..7a1aea0 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -23,6 +23,8 @@ package main
import (
"os"
+ "strings"
+ "time"
"github.com/naoina/toml"
)
@@ -31,6 +33,7 @@ type Config struct {
Audioswitch struct {
Device string `toml:"dev"`
Baudrate Baudrate `toml:"baud"`
+ Timeout Duration `toml:"timeout"`
}
Servers map[string]struct {
@@ -47,6 +50,16 @@ type Config struct {
}
}
+type Duration struct {
+ time.Duration
+}
+
+func (d *Duration) UnmarshalTOML(data []byte) (err error) {
+ ds := strings.TrimRight(strings.TrimLeft(string(data), "\""), "\"")
+ d.Duration, err = time.ParseDuration(ds)
+ return
+}
+
func ReadConfig(configfile string) (conf *Config, err error) {
conf = &Config{}
@@ -60,5 +73,10 @@ func ReadConfig(configfile string) (conf *Config, err error) {
if err = decoder.Decode(conf); err != nil {
return
}
+
+ if conf.Audioswitch.Timeout.Duration <= time.Duration(0) {
+ conf.Audioswitch.Timeout.Duration = time.Second
+ }
+
return
}
diff --git a/src/rhctl/main.go b/src/rhctl/main.go
index dff1758..e6164a0 100644
--- a/src/rhctl/main.go
+++ b/src/rhctl/main.go
@@ -77,8 +77,6 @@ func main() {
}
rhl.Printf("just started...")
- stop := make(chan bool)
-
sw, err := SwitchInit(conf)
if err != nil {
rhl.Println("error initializing audio switch: ", err)
@@ -95,6 +93,9 @@ func main() {
servers = append(servers, server)
}
+ // running essential parts
+ stop := make(chan bool)
+
go func() {
rhl.Printf("starting audioswitch handler")
sw.Run()