You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
670 B
Go
37 lines
670 B
Go
package sensor
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
/*
|
|
this file serves as a map that the sensor library can use to determine which manager to call
|
|
*/
|
|
|
|
type NewManager interface {
|
|
// serves as interface to restrict managers can be relocated
|
|
}
|
|
|
|
type DM struct {
|
|
DeviceManagers map[uint]NewManager
|
|
sync.Mutex
|
|
}
|
|
|
|
func NewManagerDirectory() *DM {
|
|
m := map[uint]NewManager{
|
|
// map to set functions up
|
|
112: NewDOManager(),
|
|
}
|
|
return &DM{DeviceManagers: m}
|
|
}
|
|
|
|
func (d *DM) GetManager(addr uint) (NewManager, error) {
|
|
d.Lock()
|
|
defer d.Unlock()
|
|
if m, ok := d.DeviceManagers[addr]; ok {
|
|
return m, nil
|
|
}
|
|
return &DM{}, fmt.Errorf("No manager found for address %d!", addr)
|
|
}
|