Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Changed back to websockets to simplify bi-directional communication. …
…Lots of organizational changes.
- Loading branch information
Showing
3 changed files
with
163 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,52 @@ | ||
package main | ||
|
||
import "sync" | ||
|
||
type StampedReading struct { | ||
Timestamp int | ||
Value interface{} | ||
Timestamp int `json:"timestamp"` | ||
Value interface{} `json:"value"` | ||
} | ||
|
||
type Packet struct { | ||
ID int `json:"id"` | ||
Kind string `json:"kind"` | ||
Message []byte `json:"message"` | ||
} | ||
|
||
type generator struct { | ||
databaseId int | ||
serverSn string | ||
socket *socketConn | ||
} | ||
|
||
type generatorMap struct { | ||
lock sync.Mutex | ||
mapping map[string]*generator | ||
} | ||
|
||
func newGenMap() *generatorMap { | ||
return &generatorMap{sync.Mutex{}, make(map[string]*generator)} | ||
} | ||
|
||
func (g *generatorMap) add(k string, v *generator) { | ||
g.lock.Lock() | ||
defer g.lock.Unlock() | ||
g.mapping[k] = v | ||
} | ||
|
||
type IDMap struct { | ||
lock sync.Mutex | ||
mapping map[int]string | ||
} | ||
|
||
func newIDMap() *IDMap { | ||
return &IDMap{sync.Mutex{}, make(map[int]string)} | ||
} | ||
|
||
func (m *IDMap) add(k int, v string) { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
m.mapping[k] = v | ||
} | ||
|
||
// TODO: maybe break this up a bit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters