Class: LIBUSB::Bos

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/libusb/bos.rb

Overview

A structure representing the Binary Device Object Store (BOS) descriptor. This descriptor is documented in section 9.6.2 of the USB 3.0 specification. All multiple-byte fields are represented in host-endian format.

Defined Under Namespace

Modules: GenericMethods Classes: ContainerId, DeviceCapability, PlatformDescriptor, SsUsbDeviceCapability, SsplusSublinkAttribute, SsplusUsbDeviceCapability, Usb20Extension

Instance Method Summary collapse

Constructor Details

#initialize(ctx, *args) ⇒ Bos

Returns a new instance of Bos.



408
409
410
411
412
413
# File 'lib/libusb/bos.rb', line 408

def initialize(ctx, *args)
  @ctx = ctx
  super(*args)

  register_context(ctx, :libusb_free_bos_descriptor)
end

Instance Method Details

#bDescriptorTypeInteger

in this context.

Returns:

  • (Integer)

    Descriptor type. Will have value LIBUSB::DT_BOS LIBUSB_DT_BOS



428
429
430
# File 'lib/libusb/bos.rb', line 428

def bDescriptorType
  self[:bDescriptorType]
end

#bLengthInteger

Returns Size of this descriptor (in bytes).

Returns:

  • (Integer)

    Size of this descriptor (in bytes)



422
423
424
# File 'lib/libusb/bos.rb', line 422

def bLength
  self[:bLength]
end

#bNumDeviceCapsInteger

the BOS

Returns:

  • (Integer)

    The number of separate device capability descriptors in



439
440
441
# File 'lib/libusb/bos.rb', line 439

def bNumDeviceCaps
  self[:bNumDeviceCaps]
end

#device_capabilitiesArray<Bos::DeviceCapability, Bos::Usb20Extension, Bos::SsUsbDeviceCapability, Bos::ContainerId>

bNumDeviceCap Device Capability Descriptors



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/libusb/bos.rb', line 454

def device_capabilities
  caps = []
  # Capabilities are appended to the bos header
  ptr = pointer + offset_of(:dev_capability)
  bNumDeviceCaps.times do
    cap = DeviceCapability.new self, ptr.read_pointer
    cap = case cap.bDevCapabilityType
      when LIBUSB::BT_WIRELESS_USB_DEVICE_CAPABILITY
        # no struct defined in libusb -> use generic DeviceCapability
        cap
      when LIBUSB::BT_USB_2_0_EXTENSION
        wrap_device_capability(cap, :libusb_get_usb_2_0_extension_descriptor, Usb20Extension)
      when LIBUSB::BT_SS_USB_DEVICE_CAPABILITY
        wrap_device_capability(cap, :libusb_get_ss_usb_device_capability_descriptor, SsUsbDeviceCapability)
      when LIBUSB::BT_SUPERSPEED_PLUS_CAPABILITY
        wrap_device_capability(cap, :libusb_get_ssplus_usb_device_capability_descriptor, SsplusUsbDeviceCapability)
      when LIBUSB::BT_CONTAINER_ID
        wrap_device_capability(cap, :libusb_get_container_id_descriptor, ContainerId)
      when LIBUSB::BT_PLATFORM_DESCRIPTOR
        wrap_device_capability(cap, :libusb_get_platform_descriptor, PlatformDescriptor)
      else
        # unknown capability -> use generic DeviceCapability
        cap
    end
    ptr += FFI.type_size(:pointer)
    caps << cap
  end
  caps
end

#device_capability_typesArray<Symbol>

Returns Types of Capabilities.

Returns:

  • (Array<Symbol>)

    Types of Capabilities

See Also:



487
488
489
490
491
492
493
494
495
# File 'lib/libusb/bos.rb', line 487

def device_capability_types
  # Capabilities are appended to the bos header
  ptr = pointer + offset_of(:dev_capability)
  bNumDeviceCaps.times.map do
    cap = DeviceCapability.new self, ptr.read_pointer
    ptr += FFI.type_size(:pointer)
    Call::BosTypes.find cap.bDevCapabilityType
  end
end

#inspectObject



497
498
499
# File 'lib/libusb/bos.rb', line 497

def inspect
  "\#<#{self.class} #{device_capability_types.join(", ")}>"
end

#wTotalLengthInteger

Returns Length of this descriptor and all of its sub descriptors.

Returns:

  • (Integer)

    Length of this descriptor and all of its sub descriptors



433
434
435
# File 'lib/libusb/bos.rb', line 433

def wTotalLength
  self[:wTotalLength]
end