diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rhctl/switch_control.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go index 523269f..09c68a3 100644 --- a/src/rhctl/switch_control.go +++ b/src/rhctl/switch_control.go @@ -61,19 +61,18 @@ func (ctrl *SwitchControl) updateOverallState(update interface{}) { switch update.(type) { case SwitchState: // s := update.(SwitchState) - rhdl.Printf("SwitchCTRL overall-state: got switch update") + rhdl.Printf("SwitchCTRL: got switch update updateting overall-state") // TODO: update ctrl.state - // TODO: publish new "state" case ServerState: s := update.(ServerState) - rhdl.Printf("SwitchCTRL overall-state: got server update from '%s'", s.Name) + rhdl.Printf("SwitchCTRL: got server update from '%s' updateting overall-state", s.Name) // TODO: update ctrl.state - // TODO: publish new "state" default: - rhl.Printf("SwitchCTRL overall-state: got unknown state-update of type %T", update) + rhl.Printf("SwitchCTRL: got unknown state-update of type %T", update) return } - rhdl.Printf("SwitchCTRL overall-state: %+v", ctrl.state) + rhdl.Printf("SwitchCTRL: overall-state is now: %+v", ctrl.state) + return } type CommandType uint8 @@ -140,7 +139,6 @@ func handleServer(in <-chan ServerState, out chan<- ServerState) { func (ctrl *SwitchControl) reconcile() { rhdl.Printf("SwitchCTRL: reconciling state...") // TODO: set mood dependent on overall-state - // if mood changes publish new "state" // TODO: send out commands to switch, server to get missing infos @@ -155,6 +153,7 @@ func (ctrl *SwitchControl) Run() { go handleServer(srv.StateChanges, serverStateChanges) } + ctrl.reconcile() for { select { case update := <-ctrl.sw.Updates: @@ -168,11 +167,13 @@ func (ctrl *SwitchControl) Run() { ctrl.Updates.Pub(state, "switch:state") ctrl.updateOverallState(state) ctrl.reconcile() + ctrl.Updates.Pub(ctrl.state, "state") case state := <-serverStateChanges: rhdl.Printf("got server state update: %+v", state) ctrl.Updates.Pub(state, "server:state") ctrl.updateOverallState(state) ctrl.reconcile() + ctrl.Updates.Pub(ctrl.state, "state") case cmd := <-ctrl.Commands: ctrl.handleCommand(cmd) } |