Skip to content

Commit

Permalink
Don't be confusing and alias my types.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Jun 23, 2012
1 parent 8e49683 commit eb376d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions monitor/state.go
@@ -1,12 +1,10 @@
package main

type ApplianceState Reading

type tracker struct {
state ApplianceState
state Reading

input chan ApplianceState
reqs chan chan ApplianceState
input chan Reading
reqs chan chan Reading
}

var global_tracker tracker
Expand All @@ -23,18 +21,18 @@ func tracker_loop() {
}

func init() {
global_tracker.input = make(chan ApplianceState)
global_tracker.reqs = make(chan chan ApplianceState)
global_tracker.input = make(chan Reading)
global_tracker.reqs = make(chan chan Reading)

go tracker_loop()
}

func saveState(s ApplianceState) {
func saveState(s Reading) {
global_tracker.input <- s
}

func getState() ApplianceState {
r := make(chan ApplianceState)
func getState() Reading {
r := make(chan Reading)
global_tracker.reqs <- r
return <-r
}
4 changes: 2 additions & 2 deletions monitor/structs.go
Expand Up @@ -17,7 +17,7 @@ type Reading struct {
StateDuration time.Duration
}

func (r *Reading) MarshalJSON() ([]byte, error) {
func (r Reading) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"port": r.Port,
"reading": r.Reading,
Expand Down Expand Up @@ -47,7 +47,7 @@ func processReading(line string) {
On: parts[5] == "ON",
StateDuration: time.Duration(1e6 * parseInt(parts[6], 64))}

saveState(ApplianceState(r))
saveState(r)
log.Printf("Read %d/%d (%s), from %d (%d). In that state %s",
r.Reading, r.High, parts[5], r.Port, r.Seq,
r.StateDuration.String())
Expand Down

0 comments on commit eb376d8

Please sign in to comment.