summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctld/statemachine.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-13 19:19:39 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-13 19:19:39 +0100
commitb9f081d1aeb87186e7118ed796ab51eeac9b8fab (patch)
tree0a21dece426ecd7f002af26063e444f00bdcb23c /cmd/dolmetschctld/statemachine.go
parentimplemented set_language command via web sockets (diff)
implemented command to fetch list of languages
Diffstat (limited to 'cmd/dolmetschctld/statemachine.go')
-rw-r--r--cmd/dolmetschctld/statemachine.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd/dolmetschctld/statemachine.go b/cmd/dolmetschctld/statemachine.go
index 2cea91d..99416a5 100644
--- a/cmd/dolmetschctld/statemachine.go
+++ b/cmd/dolmetschctld/statemachine.go
@@ -95,6 +95,10 @@ type getLanguageReq struct {
resCh chan Language
}
+type getLanguagesReq struct {
+ resCh chan []Language
+}
+
type setOriginal2InterpreterRatioReq struct {
ratio float32
resCh chan error
@@ -119,6 +123,7 @@ type StateMachine struct {
setLanguageCh chan setLanguageReq
getLanguageCh chan getLanguageReq
+ getLanguagesCh chan getLanguagesReq
setOriginal2InterpreterRatioCh chan setOriginal2InterpreterRatioReq
getOriginal2InterpreterRatioCh chan getOriginal2InterpreterRatioReq
getStateCh chan getStateReq
@@ -181,6 +186,14 @@ func (sm *StateMachine) initMixer() {
sm.state = StateSettled
}
+func (sm *StateMachine) getLanguages() (langs []Language) {
+ langs = append(langs, "none")
+ for lang, _ := range sm.languages {
+ langs = append(langs, lang)
+ }
+ return
+}
+
// the "current language" is what is currently spoken on stage
func (sm *StateMachine) setLanguage(l Language) error {
if l == "none" {
@@ -263,6 +276,8 @@ func (sm *StateMachine) run() {
sm.reconcile(false)
case req := <-sm.getLanguageCh:
req.resCh <- sm.language
+ case req := <-sm.getLanguagesCh:
+ req.resCh <- sm.getLanguages()
case req := <-sm.setOriginal2InterpreterRatioCh:
req.resCh <- sm.setOriginal2InterpreterRatio(req.ratio)
sm.reconcile(false)
@@ -283,6 +298,7 @@ func NewStateMachine(m *mixer.Mixer) (*StateMachine, error) {
sm := &StateMachine{mixer: m}
sm.setLanguageCh = make(chan setLanguageReq, 10)
sm.getLanguageCh = make(chan getLanguageReq, 10)
+ sm.getLanguagesCh = make(chan getLanguagesReq, 10)
sm.setOriginal2InterpreterRatioCh = make(chan setOriginal2InterpreterRatioReq, 10)
sm.getOriginal2InterpreterRatioCh = make(chan getOriginal2InterpreterRatioReq, 10)
sm.getStateCh = make(chan getStateReq, 10)
@@ -346,6 +362,12 @@ func (sm *StateMachine) GetLanguage() Language {
return <-resCh
}
+func (sm *StateMachine) GetLanguages() []Language {
+ resCh := make(chan []Language)
+ sm.getLanguagesCh <- getLanguagesReq{resCh}
+ return <-resCh
+}
+
func (sm *StateMachine) SetOriginal2InterpreterRatio(r float32) error {
resCh := make(chan error)
sm.setOriginal2InterpreterRatioCh <- setOriginal2InterpreterRatioReq{r, resCh}