| Index: device/usb/usb_device_impl.cc
|
| diff --git a/device/usb/usb_device_impl.cc b/device/usb/usb_device_impl.cc
|
| index bc3d68978e50376a0f27e3c8964fa18fbe07e5f0..782b0caa182a01c94c6601c5e59c36fc3fd21e29 100644
|
| --- a/device/usb/usb_device_impl.cc
|
| +++ b/device/usb/usb_device_impl.cc
|
| @@ -113,12 +113,11 @@ UsbDeviceImpl::UsbDeviceImpl(
|
| uint32 unique_id)
|
| : UsbDevice(vendor_id, product_id, unique_id),
|
| platform_device_(platform_device),
|
| - current_configuration_cached_(false),
|
| context_(context),
|
| ui_task_runner_(ui_task_runner) {
|
| CHECK(platform_device) << "platform_device cannot be NULL";
|
| libusb_ref_device(platform_device);
|
| -
|
| + RefreshConfiguration();
|
| #if defined(USE_UDEV)
|
| ScopedUdevPtr udev(udev_new());
|
| ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev.get()));
|
| @@ -217,13 +216,8 @@ scoped_refptr<UsbDeviceHandle> UsbDeviceImpl::Open() {
|
| PlatformUsbDeviceHandle handle;
|
| const int rv = libusb_open(platform_device_, &handle);
|
| if (LIBUSB_SUCCESS == rv) {
|
| - GetConfiguration();
|
| - if (!current_configuration_cached_) {
|
| - libusb_close(handle);
|
| - return NULL;
|
| - }
|
| scoped_refptr<UsbDeviceHandleImpl> device_handle =
|
| - new UsbDeviceHandleImpl(context_, this, handle, current_configuration_);
|
| + new UsbDeviceHandleImpl(context_, this, handle);
|
| handles_.push_back(device_handle);
|
| return device_handle;
|
| } else {
|
| @@ -246,78 +240,9 @@ bool UsbDeviceImpl::Close(scoped_refptr<UsbDeviceHandle> handle) {
|
| return false;
|
| }
|
|
|
| -const UsbConfigDescriptor& UsbDeviceImpl::GetConfiguration() {
|
| +const UsbConfigDescriptor* UsbDeviceImpl::GetConfiguration() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| - if (!current_configuration_cached_) {
|
| - libusb_config_descriptor* platform_config;
|
| - const int rv =
|
| - libusb_get_active_config_descriptor(platform_device_, &platform_config);
|
| - if (rv != LIBUSB_SUCCESS) {
|
| - VLOG(1) << "Failed to get config descriptor: "
|
| - << ConvertPlatformUsbErrorToString(rv);
|
| - return current_configuration_;
|
| - }
|
| -
|
| - current_configuration_.configuration_value =
|
| - platform_config->bConfigurationValue;
|
| - current_configuration_.self_powered =
|
| - (platform_config->bmAttributes & 0x40) != 0;
|
| - current_configuration_.remote_wakeup =
|
| - (platform_config->bmAttributes & 0x20) != 0;
|
| - current_configuration_.maximum_power = platform_config->MaxPower * 2;
|
| -
|
| - for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) {
|
| - const struct libusb_interface* platform_interface =
|
| - &platform_config->interface[i];
|
| - for (int j = 0; j < platform_interface->num_altsetting; ++j) {
|
| - const struct libusb_interface_descriptor* platform_alt_setting =
|
| - &platform_interface->altsetting[j];
|
| - UsbInterfaceDescriptor interface;
|
| -
|
| - interface.interface_number = platform_alt_setting->bInterfaceNumber;
|
| - interface.alternate_setting = platform_alt_setting->bAlternateSetting;
|
| - interface.interface_class = platform_alt_setting->bInterfaceClass;
|
| - interface.interface_subclass = platform_alt_setting->bInterfaceSubClass;
|
| - interface.interface_protocol = platform_alt_setting->bInterfaceProtocol;
|
| -
|
| - for (size_t k = 0; k < platform_alt_setting->bNumEndpoints; ++k) {
|
| - const struct libusb_endpoint_descriptor* platform_endpoint =
|
| - &platform_alt_setting->endpoint[k];
|
| - UsbEndpointDescriptor endpoint;
|
| -
|
| - endpoint.address = platform_endpoint->bEndpointAddress;
|
| - endpoint.direction = GetDirection(platform_endpoint);
|
| - endpoint.maximum_packet_size = platform_endpoint->wMaxPacketSize;
|
| - endpoint.synchronization_type =
|
| - GetSynchronizationType(platform_endpoint);
|
| - endpoint.transfer_type = GetTransferType(platform_endpoint);
|
| - endpoint.usage_type = GetUsageType(platform_endpoint);
|
| - endpoint.polling_interval = platform_endpoint->bInterval;
|
| - endpoint.extra_data = std::vector<uint8_t>(
|
| - platform_endpoint->extra,
|
| - platform_endpoint->extra + platform_endpoint->extra_length);
|
| -
|
| - interface.endpoints.push_back(endpoint);
|
| - }
|
| -
|
| - interface.extra_data = std::vector<uint8_t>(
|
| - platform_alt_setting->extra,
|
| - platform_alt_setting->extra + platform_alt_setting->extra_length);
|
| -
|
| - current_configuration_.interfaces.push_back(interface);
|
| - }
|
| - }
|
| -
|
| - current_configuration_.extra_data = std::vector<uint8_t>(
|
| - platform_config->extra,
|
| - platform_config->extra + platform_config->extra_length);
|
| -
|
| - libusb_free_config_descriptor(platform_config);
|
| - current_configuration_cached_ = true;
|
| - }
|
| -
|
| - return current_configuration_;
|
| + return configuration_.get();
|
| }
|
|
|
| bool UsbDeviceImpl::GetManufacturer(base::string16* manufacturer) {
|
| @@ -372,6 +297,71 @@ void UsbDeviceImpl::OnDisconnect() {
|
| }
|
| }
|
|
|
| +void UsbDeviceImpl::RefreshConfiguration() {
|
| + libusb_config_descriptor* platform_config;
|
| + int rv =
|
| + libusb_get_active_config_descriptor(platform_device_, &platform_config);
|
| + if (rv != LIBUSB_SUCCESS) {
|
| + VLOG(1) << "Failed to get config descriptor: "
|
| + << ConvertPlatformUsbErrorToString(rv);
|
| + return;
|
| + }
|
| +
|
| + configuration_.reset(new UsbConfigDescriptor());
|
| + configuration_->configuration_value = platform_config->bConfigurationValue;
|
| + configuration_->self_powered = (platform_config->bmAttributes & 0x40) != 0;
|
| + configuration_->remote_wakeup = (platform_config->bmAttributes & 0x20) != 0;
|
| + configuration_->maximum_power = platform_config->MaxPower * 2;
|
| +
|
| + for (size_t i = 0; i < platform_config->bNumInterfaces; ++i) {
|
| + const struct libusb_interface* platform_interface =
|
| + &platform_config->interface[i];
|
| + for (int j = 0; j < platform_interface->num_altsetting; ++j) {
|
| + const struct libusb_interface_descriptor* platform_alt_setting =
|
| + &platform_interface->altsetting[j];
|
| + UsbInterfaceDescriptor interface;
|
| +
|
| + interface.interface_number = platform_alt_setting->bInterfaceNumber;
|
| + interface.alternate_setting = platform_alt_setting->bAlternateSetting;
|
| + interface.interface_class = platform_alt_setting->bInterfaceClass;
|
| + interface.interface_subclass = platform_alt_setting->bInterfaceSubClass;
|
| + interface.interface_protocol = platform_alt_setting->bInterfaceProtocol;
|
| +
|
| + for (size_t k = 0; k < platform_alt_setting->bNumEndpoints; ++k) {
|
| + const struct libusb_endpoint_descriptor* platform_endpoint =
|
| + &platform_alt_setting->endpoint[k];
|
| + UsbEndpointDescriptor endpoint;
|
| +
|
| + endpoint.address = platform_endpoint->bEndpointAddress;
|
| + endpoint.direction = GetDirection(platform_endpoint);
|
| + endpoint.maximum_packet_size = platform_endpoint->wMaxPacketSize;
|
| + endpoint.synchronization_type =
|
| + GetSynchronizationType(platform_endpoint);
|
| + endpoint.transfer_type = GetTransferType(platform_endpoint);
|
| + endpoint.usage_type = GetUsageType(platform_endpoint);
|
| + endpoint.polling_interval = platform_endpoint->bInterval;
|
| + endpoint.extra_data = std::vector<uint8_t>(
|
| + platform_endpoint->extra,
|
| + platform_endpoint->extra + platform_endpoint->extra_length);
|
| +
|
| + interface.endpoints.push_back(endpoint);
|
| + }
|
| +
|
| + interface.extra_data = std::vector<uint8_t>(
|
| + platform_alt_setting->extra,
|
| + platform_alt_setting->extra + platform_alt_setting->extra_length);
|
| +
|
| + configuration_->interfaces.push_back(interface);
|
| + }
|
| + }
|
| +
|
| + configuration_->extra_data = std::vector<uint8_t>(
|
| + platform_config->extra,
|
| + platform_config->extra + platform_config->extra_length);
|
| +
|
| + libusb_free_config_descriptor(platform_config);
|
| +}
|
| +
|
| #if !defined(USE_UDEV)
|
| void UsbDeviceImpl::CacheStrings() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|