device

package
v0.0.0-...-4ac2c6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReportDataSuggestedIdentifier  = "Identifier"
	ReportDataSuggestedDescription = "Description"
)

Variables

View Source
var (
	ErrNotFound       = errors.New("device not found")
	ErrInvalidID      = errors.New("invalid device identifier")
	ErrIDAlreadyTaken = errors.New("device identifier already taken")
)

Functions

func Register

func Register(name string, f NewTrackerFunc)

Register records a Tracker factory function by name.

Types

type NewTrackerFunc

type NewTrackerFunc func(config.Settings) Tracker

NewTrackerFunc is a factory function for instantiating a new Tracker.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maintains the status of all tracked devices together with their presence status.

func NewRegistry

func NewRegistry(cfg config.Config) *Registry

NewRegistry builds a new device registry.

func (*Registry) AddDevice

func (r *Registry) AddDevice(d model.Device) error

AddDevice adds a new device to the registry.

func (*Registry) ExecuteDeviceAction

func (r *Registry) ExecuteDeviceAction(id string, action string) error

ExecuteDeviceAction executes an action on a device given its identifier.

func (*Registry) FindDevice

func (r *Registry) FindDevice(id string) (model.Device, error)

FindDevice lookups a device given its identifier.

func (*Registry) GetDevices

func (r *Registry) GetDevices(status model.Status) []model.Device

GetDevices returns all known devices.

func (*Registry) RemoveDevice

func (r *Registry) RemoveDevice(id string) error

RemoveDevice removes a device.

func (*Registry) Start

func (r *Registry) Start(ctx context.Context)

Start activates the tracking of devices.

func (*Registry) Stop

func (r *Registry) Stop()

Stop de-activates the tracking of devices.

func (*Registry) UpdateDevice

func (r *Registry) UpdateDevice(id string, ud model.Device) (model.Device, error)

UpdateDevice updates an existing device.

func (*Registry) UpdateDevicesPresence

func (r *Registry) UpdateDevicesPresence(t time.Time)

type ReportPresenceFunc

type ReportPresenceFunc func(model.Interface, map[string]string)

ReportPresenceFunc is a function that can be used by a Tracker to report the presence of a given device interface. Optionally some data related to the inteface/device may be provided.

type Tracker

type Tracker interface {
	Loop(deviceReport ReportPresenceFunc, ctx context.Context, wg *sync.WaitGroup) error

	Ping(model.Device)
}

Tracker tracks the presence of devices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL