Documentation
¶
Overview ¶
Package device keeps Core's view of the machine it runs on current while clients are connected, and tells them when it changes.
Index ¶
- Constants
- Variables
- func ChangedParams(snap *Snapshot) models.DeviceChangedNotification
- func DefaultReaders() hoststatus.Readers
- func StatusResponse(snap *Snapshot, actions map[string]string) models.DeviceStatusResponse
- type Bluetooth
- func (b *Bluetooth) Available(ctx context.Context) bool
- func (b *Bluetooth) ClientConnected()
- func (b *Bluetooth) ClientDisconnected()
- func (b *Bluetooth) Close()
- func (b *Bluetooth) Forget(ctx context.Context, address string) (models.DeviceBluetoothState, error)
- func (b *Bluetooth) Pair(ctx context.Context, address string) (models.DeviceBluetoothState, error)
- func (b *Bluetooth) StartScan(ctx context.Context, all bool, timeout time.Duration) (models.DeviceBluetoothState, error)
- func (b *Bluetooth) State(ctx context.Context) (models.DeviceBluetoothState, error)
- func (b *Bluetooth) StopScan(ctx context.Context) (models.DeviceBluetoothState, error)
- type BluetoothOptions
- type InternetProber
- type Monitor
- type Options
- type Snapshot
Constants ¶
const ( // BluetoothScanDefault and BluetoothScanMax bound a scan, so the radio // never stays searching because a client forgot about it. BluetoothScanDefault = 60 * time.Second BluetoothScanMax = 120 * time.Second )
Variables ¶
var ErrBluetoothBusy = errors.New("a bluetooth pairing attempt is already running")
ErrBluetoothBusy means a pairing attempt is already running.
Functions ¶
func ChangedParams ¶
func ChangedParams(snap *Snapshot) models.DeviceChangedNotification
ChangedParams builds the device.changed payload: the state a status display draws from, with nothing in it that identifies the device on its network.
func DefaultReaders ¶
func DefaultReaders() hoststatus.Readers
DefaultReaders returns the generic readers for this operating system.
func StatusResponse ¶
func StatusResponse(snap *Snapshot, actions map[string]string) models.DeviceStatusResponse
StatusResponse builds the device.status result. actions is keyed by method name and already reflects what the caller is allowed to do.
Types ¶
type Bluetooth ¶ added in v2.22.0
type Bluetooth struct {
// contains filtered or unexported fields
}
Bluetooth scans for, pairs and forgets Bluetooth devices, and tells clients what changed while any are connected. Scans end by themselves, and when the last client goes.
func NewBluetooth ¶ added in v2.22.0
func NewBluetooth(opts *BluetoothOptions) *Bluetooth
NewBluetooth builds a manager. It does nothing until it is asked to or a client connects.
func (*Bluetooth) Available ¶ added in v2.22.0
Available reports whether the stack is running and has an adapter, powered or not.
func (*Bluetooth) ClientConnected ¶ added in v2.22.0
func (b *Bluetooth) ClientConnected()
ClientConnected records that a client is listening for notifications.
func (*Bluetooth) ClientDisconnected ¶ added in v2.22.0
func (b *Bluetooth) ClientDisconnected()
ClientDisconnected records that a client has gone. With nobody left to see it, a running scan is stopped.
func (*Bluetooth) Close ¶ added in v2.22.0
func (b *Bluetooth) Close()
Close stops any scan and waits for background work to finish.
func (*Bluetooth) Forget ¶ added in v2.22.0
func (b *Bluetooth) Forget(ctx context.Context, address string) (models.DeviceBluetoothState, error)
Forget unpairs a device and removes it from the stack.
func (*Bluetooth) Pair ¶ added in v2.22.0
Pair starts pairing with a device and returns at once. The outcome arrives through device.bluetooth.changed. A running scan is stopped first: on many adapters an inquiry starves the connection pairing needs.
func (*Bluetooth) StartScan ¶ added in v2.22.0
func (b *Bluetooth) StartScan( ctx context.Context, all bool, timeout time.Duration, ) (models.DeviceBluetoothState, error)
StartScan starts discovery, or extends the one running, for timeout from now. Discovery stops by itself when timeout passes. Extending keeps what the running scan has found; only a scan started from idle begins empty.
type BluetoothOptions ¶ added in v2.22.0
type BluetoothOptions struct {
Control hoststatus.BluetoothController
Clock clockwork.Clock
// Publish delivers a notification to every connected client.
Publish func(models.Notification)
// Controllers returns the connected controllers last read, to match
// Bluetooth devices against.
Controllers func() []hoststatus.Controller
// PairTimeout and Debounce are zero for the defaults.
PairTimeout time.Duration
Debounce time.Duration
}
BluetoothOptions configures a Bluetooth manager.
type InternetProber ¶
type InternetProber interface {
Probe(ctx context.Context) hoststatus.InternetState
}
InternetProber decides whether the internet is reachable.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor reads device state on a schedule while at least one client is connected and publishes device.changed when it differs from what clients were last told. With nobody connected it does nothing at all.
func NewMonitor ¶
NewMonitor builds a monitor. It reads nothing until Run is called and a client connects, or a status is asked for.
func (*Monitor) Bluetooth ¶ added in v2.22.0
Bluetooth returns the Bluetooth manager, or nil when Core cannot manage Bluetooth devices here.
func (*Monitor) ClientConnected ¶
func (m *Monitor) ClientConnected()
ClientConnected records that a client is now listening for notifications.
func (*Monitor) ClientDisconnected ¶
func (m *Monitor) ClientDisconnected()
ClientDisconnected records that a client has gone.
func (*Monitor) PowerControl ¶
func (m *Monitor) PowerControl() hoststatus.PowerController
PowerControl returns the controller for power actions on this device.
type Options ¶
type Options struct {
Platform platforms.Platform
Config *config.Instance
Clock clockwork.Clock
// Publish delivers a notification to every connected client.
Publish func(models.Notification)
Prober InternetProber
// Readers are the per-section readers, already resolved against the
// platform.
Readers hoststatus.Readers
// ReadTimeout bounds one section's read. Zero means the default.
ReadTimeout time.Duration
}
Options configures a Monitor.
type Snapshot ¶
type Snapshot struct {
Power *power.Detail
Network *hoststatus.Network
Bluetooth *hoststatus.Bluetooth
Display *hoststatus.Display
System *hoststatus.System
Sections map[string]hoststatus.Availability
Timezone string
PlatformID string
Storage []hoststatus.Volume
Controllers []hoststatus.Controller
UTCOffset int
// StorageKnown and ControllersKnown tell an empty list from no reading.
StorageKnown bool
ControllersKnown bool
ClockReliable bool
}
Snapshot is everything Core knows about the device. A nil section has no reading.