| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/usb_device_handle_impl.h" | 5 #include "device/usb/usb_device_handle_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 GenericTransferInternal(endpoint_address, buffer, length, timeout, | 749 GenericTransferInternal(endpoint_address, buffer, length, timeout, |
| 750 task_runner_, callback); | 750 task_runner_, callback); |
| 751 } else { | 751 } else { |
| 752 task_runner_->PostTask( | 752 task_runner_->PostTask( |
| 753 FROM_HERE, base::Bind(&UsbDeviceHandleImpl::GenericTransferInternal, | 753 FROM_HERE, base::Bind(&UsbDeviceHandleImpl::GenericTransferInternal, |
| 754 this, endpoint_address, buffer, length, timeout, | 754 this, endpoint_address, buffer, length, timeout, |
| 755 base::ThreadTaskRunnerHandle::Get(), callback)); | 755 base::ThreadTaskRunnerHandle::Get(), callback)); |
| 756 } | 756 } |
| 757 } | 757 } |
| 758 | 758 |
| 759 bool UsbDeviceHandleImpl::FindInterfaceByEndpoint(uint8_t endpoint_address, | 759 const UsbInterfaceDescriptor* UsbDeviceHandleImpl::FindInterfaceByEndpoint( |
| 760 uint8_t* interface_number) { | 760 uint8_t endpoint_address) { |
| 761 DCHECK(thread_checker_.CalledOnValidThread()); | 761 DCHECK(thread_checker_.CalledOnValidThread()); |
| 762 const auto endpoint_it = endpoint_map_.find(endpoint_address); | 762 const auto endpoint_it = endpoint_map_.find(endpoint_address); |
| 763 if (endpoint_it != endpoint_map_.end()) { | 763 if (endpoint_it != endpoint_map_.end()) |
| 764 *interface_number = endpoint_it->second.interface_number; | 764 return endpoint_it->second.interface; |
| 765 return true; | 765 return nullptr; |
| 766 } | |
| 767 return false; | |
| 768 } | 766 } |
| 769 | 767 |
| 770 UsbDeviceHandleImpl::UsbDeviceHandleImpl( | 768 UsbDeviceHandleImpl::UsbDeviceHandleImpl( |
| 771 scoped_refptr<UsbContext> context, | 769 scoped_refptr<UsbContext> context, |
| 772 scoped_refptr<UsbDeviceImpl> device, | 770 scoped_refptr<UsbDeviceImpl> device, |
| 773 PlatformUsbDeviceHandle handle, | 771 PlatformUsbDeviceHandle handle, |
| 774 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | 772 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
| 775 : device_(device), | 773 : device_(device), |
| 776 handle_(handle), | 774 handle_(handle), |
| 777 context_(context), | 775 context_(context), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); | 899 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); |
| 902 if (config) { | 900 if (config) { |
| 903 for (const auto& map_entry : claimed_interfaces_) { | 901 for (const auto& map_entry : claimed_interfaces_) { |
| 904 int interface_number = map_entry.first; | 902 int interface_number = map_entry.first; |
| 905 const scoped_refptr<InterfaceClaimer>& claimed_iface = map_entry.second; | 903 const scoped_refptr<InterfaceClaimer>& claimed_iface = map_entry.second; |
| 906 | 904 |
| 907 for (const UsbInterfaceDescriptor& iface : config->interfaces) { | 905 for (const UsbInterfaceDescriptor& iface : config->interfaces) { |
| 908 if (iface.interface_number == interface_number && | 906 if (iface.interface_number == interface_number && |
| 909 iface.alternate_setting == claimed_iface->alternate_setting()) { | 907 iface.alternate_setting == claimed_iface->alternate_setting()) { |
| 910 for (const UsbEndpointDescriptor& endpoint : iface.endpoints) { | 908 for (const UsbEndpointDescriptor& endpoint : iface.endpoints) { |
| 911 endpoint_map_[endpoint.address] = {interface_number, | 909 endpoint_map_[endpoint.address] = {&iface, &endpoint}; |
| 912 endpoint.transfer_type}; | |
| 913 } | 910 } |
| 914 break; | 911 break; |
| 915 } | 912 } |
| 916 } | 913 } |
| 917 } | 914 } |
| 918 } | 915 } |
| 919 } | 916 } |
| 920 | 917 |
| 921 scoped_refptr<UsbDeviceHandleImpl::InterfaceClaimer> | 918 scoped_refptr<UsbDeviceHandleImpl::InterfaceClaimer> |
| 922 UsbDeviceHandleImpl::GetClaimedInterfaceForEndpoint(uint8_t endpoint) { | 919 UsbDeviceHandleImpl::GetClaimedInterfaceForEndpoint(uint8_t endpoint) { |
| 923 const auto endpoint_it = endpoint_map_.find(endpoint); | 920 const auto endpoint_it = endpoint_map_.find(endpoint); |
| 924 if (endpoint_it != endpoint_map_.end()) | 921 if (endpoint_it != endpoint_map_.end()) |
| 925 return claimed_interfaces_[endpoint_it->second.interface_number]; | 922 return claimed_interfaces_[endpoint_it->second.interface->interface_number]; |
| 926 return nullptr; | 923 return nullptr; |
| 927 } | 924 } |
| 928 | 925 |
| 929 void UsbDeviceHandleImpl::ControlTransferInternal( | 926 void UsbDeviceHandleImpl::ControlTransferInternal( |
| 930 UsbEndpointDirection direction, | 927 UsbEndpointDirection direction, |
| 931 TransferRequestType request_type, | 928 TransferRequestType request_type, |
| 932 TransferRecipient recipient, | 929 TransferRecipient recipient, |
| 933 uint8_t request, | 930 uint8_t request, |
| 934 uint16_t value, | 931 uint16_t value, |
| 935 uint16_t index, | 932 uint16_t index, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 } | 1048 } |
| 1052 | 1049 |
| 1053 if (!base::IsValueInRangeForNumericType<int>(length)) { | 1050 if (!base::IsValueInRangeForNumericType<int>(length)) { |
| 1054 USB_LOG(DEBUG) << "Transfer too long."; | 1051 USB_LOG(DEBUG) << "Transfer too long."; |
| 1055 RunTransferCallback(callback_task_runner, callback, USB_TRANSFER_ERROR, | 1052 RunTransferCallback(callback_task_runner, callback, USB_TRANSFER_ERROR, |
| 1056 buffer, 0); | 1053 buffer, 0); |
| 1057 return; | 1054 return; |
| 1058 } | 1055 } |
| 1059 | 1056 |
| 1060 scoped_ptr<Transfer> transfer; | 1057 scoped_ptr<Transfer> transfer; |
| 1061 UsbTransferType transfer_type = endpoint_it->second.transfer_type; | 1058 UsbTransferType transfer_type = endpoint_it->second.endpoint->transfer_type; |
| 1062 if (transfer_type == USB_TRANSFER_BULK) { | 1059 if (transfer_type == USB_TRANSFER_BULK) { |
| 1063 transfer = Transfer::CreateBulkTransfer(this, endpoint_address, buffer, | 1060 transfer = Transfer::CreateBulkTransfer(this, endpoint_address, buffer, |
| 1064 static_cast<int>(length), timeout, | 1061 static_cast<int>(length), timeout, |
| 1065 callback_task_runner, callback); | 1062 callback_task_runner, callback); |
| 1066 } else if (transfer_type == USB_TRANSFER_INTERRUPT) { | 1063 } else if (transfer_type == USB_TRANSFER_INTERRUPT) { |
| 1067 transfer = Transfer::CreateInterruptTransfer( | 1064 transfer = Transfer::CreateInterruptTransfer( |
| 1068 this, endpoint_address, buffer, static_cast<int>(length), timeout, | 1065 this, endpoint_address, buffer, static_cast<int>(length), timeout, |
| 1069 callback_task_runner, callback); | 1066 callback_task_runner, callback); |
| 1070 } else { | 1067 } else { |
| 1071 USB_LOG(DEBUG) << "Endpoint " << static_cast<int>(endpoint_address) | 1068 USB_LOG(DEBUG) << "Endpoint " << static_cast<int>(endpoint_address) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 map_entry.second = nullptr; | 1123 map_entry.second = nullptr; |
| 1127 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer); | 1124 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer); |
| 1128 } | 1125 } |
| 1129 | 1126 |
| 1130 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 1127 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
| 1131 // finish. | 1128 // finish. |
| 1132 device_ = nullptr; | 1129 device_ = nullptr; |
| 1133 } | 1130 } |
| 1134 | 1131 |
| 1135 } // namespace device | 1132 } // namespace device |
| OLD | NEW |