Rename more "Info" fields to "Desc"
This commit is contained in:
18
config.go
18
config.go
@@ -20,11 +20,11 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ConfigInfo contains the information about a USB device configuration,
|
||||
// ConfigDesc contains the information about a USB device configuration,
|
||||
// extracted from the device descriptor.
|
||||
type ConfigDesc struct {
|
||||
// Config is the configuration number.
|
||||
Config int
|
||||
// Number is the configuration number.
|
||||
Number int
|
||||
// SelfPowered is true if the device is powered externally, i.e. not
|
||||
// drawing power from the USB bus.
|
||||
SelfPowered bool
|
||||
@@ -39,7 +39,7 @@ type ConfigDesc struct {
|
||||
|
||||
// String returns the human-readable description of the configuration descriptor.
|
||||
func (c ConfigDesc) String() string {
|
||||
return fmt.Sprintf("Configuration %d", c.Config)
|
||||
return fmt.Sprintf("Configuration %d", c.Number)
|
||||
}
|
||||
|
||||
// Config represents a USB device set to use a particular configuration.
|
||||
@@ -47,7 +47,7 @@ func (c ConfigDesc) String() string {
|
||||
// To access device endpoints, claim an interface and it's alternate
|
||||
// setting number through a call to Interface().
|
||||
type Config struct {
|
||||
Info ConfigDesc
|
||||
Desc ConfigDesc
|
||||
|
||||
dev *Device
|
||||
|
||||
@@ -79,7 +79,7 @@ func (c *Config) Close() error {
|
||||
|
||||
// String returns the human-readable description of the configuration.
|
||||
func (c *Config) String() string {
|
||||
return fmt.Sprintf("%s,config=%d", c.dev.String(), c.Info.Config)
|
||||
return fmt.Sprintf("%s,config=%d", c.dev.String(), c.Desc.Number)
|
||||
}
|
||||
|
||||
// Interface claims and returns an interface on a USB device.
|
||||
@@ -89,10 +89,10 @@ func (c *Config) Interface(intf, alt int) (*Interface, error) {
|
||||
if c.dev == nil {
|
||||
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c)
|
||||
}
|
||||
if intf < 0 || intf >= len(c.Info.Interfaces) {
|
||||
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Info.Interfaces)-1)
|
||||
if intf < 0 || intf >= len(c.Desc.Interfaces) {
|
||||
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Desc.Interfaces)-1)
|
||||
}
|
||||
ifInfo := c.Info.Interfaces[intf]
|
||||
ifInfo := c.Desc.Interfaces[intf]
|
||||
if alt < 0 || alt >= len(ifInfo.AltSettings) {
|
||||
return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1)
|
||||
}
|
||||
|
@@ -117,12 +117,12 @@ func (d *Device) Config(cfgNum int) (*Config, error) {
|
||||
if d.handle == nil {
|
||||
return nil, fmt.Errorf("Config(%d) called on %s after Close", cfgNum, d)
|
||||
}
|
||||
info, ok := d.Desc.Configs[cfgNum]
|
||||
desc, ok := d.Desc.Configs[cfgNum]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device %s. Available config ids: %v", cfgNum, d, d.Desc.sortedConfigIds())
|
||||
}
|
||||
cfg := &Config{
|
||||
Info: info,
|
||||
Desc: desc,
|
||||
dev: d,
|
||||
claimed: make(map[int]bool),
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (d *Device) Close() error {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
if d.claimed != nil {
|
||||
return fmt.Errorf("can't release the device %s, it has an open config %s", d, d.claimed.Info.Config)
|
||||
return fmt.Errorf("can't release the device %s, it has an open config %s", d, d.claimed.Desc.Number)
|
||||
}
|
||||
libusb.close(d.handle)
|
||||
d.handle = nil
|
||||
|
@@ -62,7 +62,7 @@ func TestClaimAndRelease(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("%s.InEndpoint(%d): got error %v, want nil", intf, ep1Num, err)
|
||||
}
|
||||
if want := fakeDevices[devIdx].Configs[cfgNum].Interfaces[if1Num].AltSettings[alt1Num].Endpoints[ep1Num]; !reflect.DeepEqual(got.Info, want) {
|
||||
if want := fakeDevices[devIdx].Configs[cfgNum].Interfaces[if1Num].AltSettings[alt1Num].Endpoints[ep1Num]; !reflect.DeepEqual(got.Desc, want) {
|
||||
t.Errorf("%s.InEndpoint(%d): got %+v, want %+v", intf, ep1Num, got, want)
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// EndpointInfo contains the information about an interface endpoint, extracted
|
||||
// EndpointDesc contains the information about an interface endpoint, extracted
|
||||
// from the descriptor.
|
||||
type EndpointDesc struct {
|
||||
// Number represents the endpoint number. Note that the endpoint number is different from the
|
||||
@@ -72,14 +72,14 @@ type endpoint struct {
|
||||
h *libusbDevHandle
|
||||
|
||||
InterfaceSetting
|
||||
Info EndpointDesc
|
||||
Desc EndpointDesc
|
||||
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// String returns a human-readable description of the endpoint.
|
||||
func (e *endpoint) String() string {
|
||||
return e.Info.String()
|
||||
return e.Desc.String()
|
||||
}
|
||||
|
||||
func (e *endpoint) transfer(buf []byte) (int, error) {
|
||||
@@ -87,7 +87,7 @@ func (e *endpoint) transfer(buf []byte) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
t, err := newUSBTransfer(e.h, &e.Info, buf, e.Timeout)
|
||||
t, err := newUSBTransfer(e.h, &e.Desc, buf, e.Timeout)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ package gousb
|
||||
func (e *endpoint) newStream(size, count int, submit bool) (*stream, error) {
|
||||
var ts []transferIntf
|
||||
for i := 0; i < count; i++ {
|
||||
t, err := newUSBTransfer(e.h, &e.Info, make([]byte, size), e.Timeout)
|
||||
t, err := newUSBTransfer(e.h, &e.Desc, make([]byte, size), e.Timeout)
|
||||
if err != nil {
|
||||
for _, t := range ts {
|
||||
t.free()
|
||||
|
@@ -89,7 +89,7 @@ func TestEndpoint(t *testing.T) {
|
||||
wantErr: true,
|
||||
},
|
||||
} {
|
||||
ep := &endpoint{h: nil, InterfaceSetting: epData.intf, Info: epData.ei}
|
||||
ep := &endpoint{h: nil, InterfaceSetting: epData.intf, Desc: epData.ei}
|
||||
if tc.wantSubmit {
|
||||
go func() {
|
||||
fakeT := lib.waitForSubmitted()
|
||||
|
@@ -28,7 +28,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Product: ID(0x0001),
|
||||
Protocol: 255,
|
||||
Configs: map[int]ConfigDesc{1: {
|
||||
Config: 1,
|
||||
Number: 1,
|
||||
MaxPower: Milliamperes(100),
|
||||
Interfaces: []InterfaceDesc{{
|
||||
Number: 0,
|
||||
@@ -67,7 +67,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Product: ID(0x0002),
|
||||
Protocol: 255,
|
||||
Configs: map[int]ConfigDesc{1: {
|
||||
Config: 1,
|
||||
Number: 1,
|
||||
MaxPower: Milliamperes(100),
|
||||
Interfaces: []InterfaceDesc{{
|
||||
Number: 0,
|
||||
|
10
interface.go
10
interface.go
@@ -20,7 +20,7 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// InterfaceInfo contains information about a USB interface, extracted from
|
||||
// InterfaceDesc contains information about a USB interface, extracted from
|
||||
// the descriptor.
|
||||
type InterfaceDesc struct {
|
||||
// Number is the number of this interface, a zero-based index in the array
|
||||
@@ -39,7 +39,7 @@ func (i InterfaceDesc) String() string {
|
||||
// InterfaceSetting contains information about a USB interface with a particular
|
||||
// alternate setting, extracted from the descriptor.
|
||||
type InterfaceSetting struct {
|
||||
// Number is the number of this interface, the same as in InterfaceInfo.
|
||||
// Number is the number of this interface, the same as in InterfaceDesc.
|
||||
Number int
|
||||
// Alternate is the number of this alternate setting.
|
||||
Alternate int
|
||||
@@ -102,7 +102,7 @@ func (i *Interface) openEndpoint(epNum int) (*endpoint, error) {
|
||||
}
|
||||
return &endpoint{
|
||||
InterfaceSetting: i.Setting,
|
||||
Info: ep,
|
||||
Desc: ep,
|
||||
h: i.config.dev.handle,
|
||||
}, nil
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (i *Interface) InEndpoint(epNum int) (*InEndpoint, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ep.Info.Direction != EndpointDirectionIn {
|
||||
if ep.Desc.Direction != EndpointDirectionIn {
|
||||
return nil, fmt.Errorf("%s is not an IN endpoint", ep)
|
||||
}
|
||||
return &InEndpoint{
|
||||
@@ -133,7 +133,7 @@ func (i *Interface) OutEndpoint(epNum int) (*OutEndpoint, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ep.Info.Direction != EndpointDirectionOut {
|
||||
if ep.Desc.Direction != EndpointDirectionOut {
|
||||
return nil, fmt.Errorf("%s is not an OUT endpoint", ep)
|
||||
}
|
||||
return &OutEndpoint{
|
||||
|
@@ -214,7 +214,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
return nil, err
|
||||
}
|
||||
c := ConfigDesc{
|
||||
Config: int(cfg.bConfigurationValue),
|
||||
Number: int(cfg.bConfigurationValue),
|
||||
SelfPowered: (cfg.bmAttributes & selfPoweredMask) != 0,
|
||||
RemoteWakeup: (cfg.bmAttributes & remoteWakeupMask) != 0,
|
||||
// TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA.
|
||||
@@ -249,10 +249,10 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
Protocol: Protocol(alt.bInterfaceProtocol),
|
||||
}
|
||||
if ifNum != i.Number {
|
||||
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Config, ifNum, i.Number)
|
||||
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Number, ifNum, i.Number)
|
||||
}
|
||||
if altNum != i.Alternate {
|
||||
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Config, i.Number, altNum, i.Alternate)
|
||||
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Number, i.Number, altNum, i.Alternate)
|
||||
}
|
||||
var ends []C.struct_libusb_endpoint_descriptor
|
||||
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
||||
@@ -274,7 +274,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
})
|
||||
}
|
||||
C.libusb_free_config_descriptor(cfg)
|
||||
cfgs[c.Config] = c
|
||||
cfgs[c.Number] = c
|
||||
}
|
||||
|
||||
return &DeviceDesc{
|
||||
|
@@ -194,7 +194,7 @@ func Example_complex() {
|
||||
}
|
||||
|
||||
// Buffer large enough for 10 USB packets from endpoint 6.
|
||||
buf := make([]byte, 10*epIn.Info.MaxPacketSize)
|
||||
buf := make([]byte, 10*epIn.Desc.MaxPacketSize)
|
||||
total := 0
|
||||
// Repeat the read/write cycle 10 times.
|
||||
for i := 0; i < 10; i++ {
|
||||
|
Reference in New Issue
Block a user