test implementation of channels for IPC, prep for currency
This commit is contained in:
parent
086b479e43
commit
91ba197c6c
35
main.go
35
main.go
@ -15,9 +15,6 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// ScanMgr will keep track of concurrently running scans
|
||||
var ScanMgr *protogen.Meta
|
||||
|
||||
func listen() {
|
||||
flag.Parse()
|
||||
|
||||
@ -58,9 +55,10 @@ func init() {
|
||||
|
||||
dust.PrintBanner()
|
||||
|
||||
ScanMgr = &protogen.Meta{
|
||||
Count: 0,
|
||||
Scans: make(map[int]*protogen.Scan),
|
||||
protogen.ScanMgr = &protogen.Meta{
|
||||
Count: 0,
|
||||
Scans: make(map[int]*protogen.Scan),
|
||||
Mailbox: make(chan protogen.Postcard),
|
||||
}
|
||||
|
||||
// setup json logfile
|
||||
@ -107,9 +105,30 @@ func main() {
|
||||
defer eros.Slumber()
|
||||
var scan *protogen.Scan
|
||||
|
||||
scan = ScanMgr.NewScan()
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case postcard := <- protogen.ScanMgr.Mailbox:
|
||||
log.Info().
|
||||
Int("originating_scan_id", postcard.From).
|
||||
Str("message", postcard.Message).
|
||||
Msg("Mailbox_IPC")
|
||||
|
||||
if postcard.Message == "quit" {
|
||||
log.Warn().
|
||||
Int("from", postcard.From).
|
||||
Msg("Received command to quit via Mailbox")
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
scan = protogen.ScanMgr.NewScan()
|
||||
|
||||
//time.Sleep(30 * time.Millisecond)
|
||||
dust.Must("Scan", scan.Start())
|
||||
go dust.Must("Scan", scan.Start())
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ScanMgr will keep track of concurrently running scans
|
||||
var ScanMgr *Meta
|
||||
|
||||
func (m *Meta) NewScan() *Scan {
|
||||
// Here we are creating an "anonymous" instance of a Scan struct
|
||||
// You'll notice it doesn't contain most of the data that actually is supposed to live within that struct
|
||||
|
@ -16,6 +16,8 @@ type Meta struct {
|
||||
Count int
|
||||
Scans map[int]*Scan
|
||||
|
||||
Mailbox chan Postcard
|
||||
|
||||
// // // Future Concepts // // //
|
||||
// BLEScans map[int]*BLEScan
|
||||
// LoraScans map[int]*LoraScan
|
||||
@ -23,12 +25,25 @@ type Meta struct {
|
||||
// WiFiScans map[int]*WiFiScan
|
||||
}
|
||||
|
||||
// Postcard will encapsulate interprocess communication messages that we send back to the main thread
|
||||
type Postcard struct {
|
||||
// From is the ScanID the message originated from
|
||||
From int
|
||||
Stamp time.Time
|
||||
// Device ID - relevant DeviceID (if applicable) - Remember to use Scan.Devices[id] for easy referral
|
||||
DeviceID int
|
||||
|
||||
// probably a string
|
||||
Message string
|
||||
}
|
||||
|
||||
// Instance of a BLE scan
|
||||
type Scan struct {
|
||||
Count int
|
||||
|
||||
// The ID is how we will refer back to running scans during IPC to react or cancel a scan
|
||||
ID int
|
||||
Started time.Time
|
||||
Activity time.Time
|
||||
Devices map[int]*eros.Device
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user