begin implementing mutexes and adjusting the way we reference and instantiate instances of types accordingly

This commit is contained in:
kayos@tcp.direct 2021-08-17 09:25:41 -07:00
parent df3dfabe22
commit 38210653b8
4 changed files with 18 additions and 17 deletions

@ -197,8 +197,8 @@ func Exists(Addr string) bool {
return false
}
// Remember stores device details into the database
func Remember(dev Device) error {
// Remember stores device details into the database via an argument
func Remember(dev *Device) error {
var err error
var rhist map[time.Time]int16

@ -1,9 +1,9 @@
package eros
import (
"time"
"sync"
bluetooth "git.tcp.direct/kayos/prototooth"
"sync"
"time"
)
type Permissions struct {

@ -8,7 +8,7 @@ import (
"protomolecule/src/eros"
bluetooth "git.tcp.direct/kayos/prototooth"
"sync"
"time"
)
@ -40,20 +40,21 @@ func (m *Meta) NewScan() *Scan {
scan := m.Scans[newid]
scan.Device = make(map[int]*eros.Device)
scan.mu = &sync.RWMutex{}
return scan
}
func (s *Scan) NewDevice(name string, addr string, manuf string, rssi int16) *eros.Device {
s.mu.Lock()
defer s.mu.Unlock()
s.Device[len(s.Device)] = eros.FinalizeDevice(eros.Device{
draft := eros.Device{
Name: name,
Addr: addr,
Manufacturer: manuf,
RSSIlast: rssi,
})
return s.Device[len(s.Device)]
}
return eros.FinalizeDevice(draft)
}
/*
@ -128,7 +129,7 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc
layToRest := func(dev *eros.Device) {
sublog.Debug().Msg("Storing data with Eros")
eros.Remember(*dev)
eros.Remember(dev)
// simple eros test
fromEros, err := eros.Recall(addr)

@ -3,8 +3,8 @@ package protogen
import (
bluetooth "git.tcp.direct/kayos/prototooth"
"protomolecule/src/eros"
"time"
"sync"
"time"
)
/*
@ -15,7 +15,7 @@ Why the Meta struct?
I've mocked up some commented out examples in the source code below.
*/
type Meta struct {
Scans map[int]*Scan
Scans map[int]*Scan
Mailbox chan Postcard
// // // Future Concepts // // //
// BLEScans map[int]*BLEScan
@ -45,18 +45,18 @@ type Postcard struct {
// Scan represents an instance of a BLE scan
type Scan struct {
Count int
ID int
ID int
// Started the scan at this time
Started time.Time
Started time.Time
// Activity was last seen at this time
Activity time.Time
Activity time.Time
// Device represents a bluetooth endpoints
Device map[int]*eros.Device
Device map[int]*eros.Device
// Connection is an active connection to a bluetooth endpoint
Connection map[int]*bluetooth.Connection
/* Ignore is a map of devices to disregard during a scan,
by using the hardware address as a key. (needs disclaimer?) */
Ignore map[string]bool
Ignore map[string]bool
// Gonna plan on mutexing scan operations just to be safe
mu *sync.RWMutex