-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
40 lines (32 loc) · 773 Bytes
/
Copy pathapp.go
File metadata and controls
40 lines (32 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"sync"
"encoding/json"
"tinygo.org/x/bluetooth"
)
type App struct {
adapter *bluetooth.Adapter
discovered chan bluetooth.ScanResult
db map[string][]string
seen map[string]*StoredDevice
notSeen map[string]*StoredDevice
sync.RWMutex
}
func (app *App) Marshal(src interface{}) ([]byte, error) {
return json.Marshal(src)
}
func (app *App) Unmarshal(b []byte, dst interface{}) error {
return json.Unmarshal(b, dst)
}
func (app *App) see(uid string, sd *StoredDevice) {
app.Lock()
defer app.Unlock()
delete(app.notSeen, uid)
app.seen[uid] = sd
}
func (app *App) unsee(uid string, sd *StoredDevice) {
app.Lock()
defer app.Unlock()
delete(app.seen, uid)
app.notSeen[uid] = sd
}