succd: split out http server, daemon state, daemon controller
This improves the structure of the code, separating the data/control interface out and then implementing the http interface as a user of this interface.
This commit is contained in:
parent
3ec6fd1d1b
commit
8f7ec7e141
5 changed files with 190 additions and 180 deletions
49
succbone/succd/process_controller.go
Normal file
49
succbone/succd/process_controller.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
// daemonController is the control/data interface passed on to external system
|
||||
// controllers, eg. the web interface.
|
||||
//
|
||||
// This is a subset of daemon functions limited to a safe, explicit subset.
|
||||
type daemonController interface {
|
||||
// snapshot returns an internally consistent copy of the daemon state.
|
||||
snapshot() *daemonState
|
||||
// rpSet enables/disables the roughing pump.
|
||||
rpSet(bool)
|
||||
// dpSet enables/disables the diffusion pump.
|
||||
dpSet(bool)
|
||||
// pumpDownPress simulates a pumpdown button press.
|
||||
pumpDownPress()
|
||||
// ventPRess simulates a vent button press.
|
||||
ventPress()
|
||||
}
|
||||
|
||||
func (d *daemon) snapshot() *daemonState {
|
||||
d.mu.RLock()
|
||||
ds := d.daemonState
|
||||
d.mu.RUnlock()
|
||||
return &ds
|
||||
}
|
||||
|
||||
func (d *daemon) rpSet(state bool) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.rpOn = state
|
||||
}
|
||||
|
||||
func (d *daemon) dpSet(state bool) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.dpOn = state
|
||||
}
|
||||
|
||||
func (d *daemon) pumpDownPress() {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.pumpdown.trigger()
|
||||
}
|
||||
|
||||
func (d *daemon) ventPress() {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
d.vent.trigger()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue