virtualbus

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package virtualbus manages USB bus topology and auto-assigns device addresses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeviceMeta

type DeviceMeta struct {
	Dev  usb.Device
	Meta usbip.ExportMeta
}

DeviceMeta exposes a registered device and its metadata for external queries.

type VirtualBus

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

VirtualBus manages USB bus topology and auto-assigns device addresses.

func New

func New(busID uint32) *VirtualBus

New creates a new VirtualBus instance with a unique auto-assigned bus number.

func NewWithBusId

func NewWithBusId(busId uint32) (*VirtualBus, error)

NewWithBusId creates a new VirtualBus instance starting at a specific bus number. Returns an error if the bus number is already allocated.

func (*VirtualBus) Add

func (vb *VirtualBus) Add(dev usb.Device) (context.Context, error)

Add registers a device using a descriptor provider implemented by the device. This is a convenience wrapper so callers can simply do "bus.Add(dev)". The device must implement a method:

GetDeviceDescriptor() DeviceDescriptorStruct

which returns a static descriptor that will be used for bus registration. Returns a context containing the device's lifecycle and metadata (use GetDeviceMeta to extract).

func (*VirtualBus) BusID

func (vb *VirtualBus) BusID() uint32

BusID returns the bus number for this VirtualBus.

func (*VirtualBus) Close

func (vb *VirtualBus) Close() error

Close frees the bus number allocated to this VirtualBus, allowing it to be reused. After calling Close, this VirtualBus instance should not be used.

func (*VirtualBus) Devices

func (vb *VirtualBus) Devices() []usb.Device

Devices returns all devices currently attached to this bus.

func (*VirtualBus) GetAllDeviceMetas

func (vb *VirtualBus) GetAllDeviceMetas() []DeviceMeta

GetAllDeviceMetas returns a copy of all registered devices with their descriptors and export metadata.

func (*VirtualBus) GetBusEmptyContext added in v0.2.2

func (vb *VirtualBus) GetBusEmptyContext() context.Context

func (*VirtualBus) GetDeviceContext

func (vb *VirtualBus) GetDeviceContext(dev usb.Device) context.Context

GetDeviceContext returns the context for a specific device. Returns nil if the device is not found or has no active context.

func (*VirtualBus) Remove

func (vb *VirtualBus) Remove(dev usb.Device) error

Remove unregisters a device from the bus. This removes the device from the internal list; it does not currently free the global bus number. Removal should be used for dynamic device teardown during runtime.

func (*VirtualBus) RemoveDeviceByID

func (vb *VirtualBus) RemoveDeviceByID(deviceID string) error

RemoveDeviceByID removes a device by its ID (e.g., "1"). Returns error if not found.

Jump to

Keyboard shortcuts

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