hotplug

package module
v0.0.0-...-77bd9a5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

README

Hardware Hotplug Detection for Go

hotplug lets you listen for new hardware devices being connected to the host computer.

Copying

Copyright 2023 Sam Hanes

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package hotplug provides for cross-platform discovery of connected devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Path  string
	Class DeviceClass
	// contains filtered or unexported fields
}

func (*Device) Address

func (dev *Device) Address() (int, error)

Address is the address of the device on its bus.

The interpretation of the address depends on the bus.

func (*Device) BusNumber

func (dev *Device) BusNumber() (int, error)

BusNumber is a number distinguishing the bus the device is connected to from other busses of the same type on the computer.

The bus numbering scheme is bus-specific.

func (*Device) Parent

func (dev *Device) Parent() (*Device, error)

func (*Device) ProductId

func (dev *Device) ProductId() (int, error)

func (*Device) Up

func (dev *Device) Up(class DeviceClass) (*Device, error)

Up finds the nearest ancestor of this device which is of the given class.

func (*Device) VendorId

func (dev *Device) VendorId() (int, error)

type DeviceClass

type DeviceClass uint
const (
	DevUnknown DeviceClass = iota

	DevHid

	DevUsbDevice
	DevUsbInterface
)

type DeviceInterface

type DeviceInterface struct {
	Path   string
	Class  InterfaceClass
	Device *Device
	// contains filtered or unexported fields
}

A DeviceInterface describes a particular way to interact with a Device.

func (*DeviceInterface) OnDetach

func (devIf *DeviceInterface) OnDetach(callback func()) error

type InterfaceClass

type InterfaceClass uint
const (
	DevIfUnknown InterfaceClass = iota

	DevIfHid

	DevIfPrinter
)

type Listener

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

func New

func New(
	class InterfaceClass,
	callback ListenerCallback,
) (*Listener, error)

func (*Listener) Enumerate

func (l *Listener) Enumerate() error

Enumerate calls the ArriveCallback for each device present in the system.

func (*Listener) Listen

func (l *Listener) Listen() error

Listen calls the ArriveCallback each time a device is connected.

func (*Listener) Stop

func (l *Listener) Stop() error

type ListenerCallback

type ListenerCallback func(iface *DeviceInterface)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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