Documentation ¶
Overview ¶
Package bind contains code for binding to and controlling devices.
Index ¶
- Constants
- func PutRegistry(ctx context.Context, m *Registry) context.Context
- type Device
- type DeviceListener
- type Registry
- func (r *Registry) AddDevice(ctx context.Context, d Device)
- func (r *Registry) DefaultDevice() Device
- func (r *Registry) Device(id id.ID) Device
- func (r *Registry) DeviceProperty(ctx context.Context, d Device, k interface{}) interface{}
- func (r *Registry) Devices() []Device
- func (r *Registry) Listen(l DeviceListener) (unregister func())
- func (r *Registry) RemoveDevice(ctx context.Context, d Device)
- func (r *Registry) SetDeviceProperty(ctx context.Context, d Device, k, v interface{})
- type Simple
Constants ¶
const ( // ErrShellNotSupported may be returned by Start if the target does not support a shell. ErrShellNotSupported = fault.Const("bind.Simple does not support shell commands") )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Device ¶
type Device interface { // Instance returns the instance information for this device. Instance() *device.Instance // State returns the last known connected status of the device. Status() Status // Shell is a helper that builds a shell.Cmd with d.ShellTarget() as its target Shell(name string, args ...string) shell.Cmd }
Device represents a connection to an attached device.
type DeviceListener ¶
type DeviceListener interface { OnDeviceAdded(context.Context, Device) OnDeviceRemoved(context.Context, Device) }
DeviceListener is the interface implemented by types that respond to devices being added to and removed from the registry.
func NewDeviceListener ¶
func NewDeviceListener(onDeviceAdded, onDeviceRemoved func(context.Context, Device)) DeviceListener
NewDeviceListener returns a DeviceListener that delegates calls on to onDeviceAdded and onDeviceRemoved.
type Registry ¶
Registry is holds a list of registered devices. It provides methods for listening for devices that are added to and removed from the device.
func GetRegistry ¶
GetRegistry retrieves the registry from a context previously annotated by PutRegistry.
func (*Registry) DefaultDevice ¶
DefaultDevice returns the first device registered with the Registry.
func (*Registry) Device ¶
Device looks up the device with the specified identifier. If no device with the specified identifier was registered with the Registry then nil is returner.
func (*Registry) DeviceProperty ¶
DeviceProperty returns the property with the key k for the device d, previously set with SetDeviceProperty. If the property for the device does not exist then nil is returned.
func (*Registry) Listen ¶
func (r *Registry) Listen(l DeviceListener) (unregister func())
Listen registers l to be called whenever a device is added to or removed from the registry. l will be unregistered when the returned function is called.
func (*Registry) RemoveDevice ¶
RemoveDevice unregisters the device d with the Registry.
func (*Registry) SetDeviceProperty ¶
SetDeviceProperty sets the property with the key k to the value v for the device d. This property can be retrieved with DeviceProperty. Properties will persist in the registry even when the device has not been added or has been removed.
type Simple ¶
Simple is a very short implementation of the Device interface. It directly holds the devices Information struct, and it's last known Status, but provides no other active functionality. It can be used for fake devices, or as a building block to create a more complete device.
func (*Simple) ABI ¶
ABI implements the Device interface returning the first ABI from the Information, or UnknownABI if it has none.
func (*Simple) Instance ¶
Instance implements the Device interface returning the Information in the To field.
func (*Simple) Shell ¶
Shell implements the Device interface returning commands that will error if run.