Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | |
| 6 #define DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/scoped_file.h" | |
| 13 #include "device/usb/usb_device_handle.h" | |
| 14 | |
| 15 struct usbdevfs_urb; | |
| 16 | |
| 17 namespace base { | |
| 18 class SequencedTaskRunner; | |
| 19 } | |
| 20 | |
| 21 namespace device { | |
| 22 | |
| 23 // Implementation of a USB device handle on top of the Linux USBFS ioctl | |
| 24 // interface available on Linux, Chrome OS and Android. | |
| 25 class UsbDeviceHandleUsbfs : public UsbDeviceHandle { | |
| 26 public: | |
| 27 // Constructs a new device handle from an existing |device| and open file | |
| 28 // descriptor to that device. |blocking_task_runner| must have a | |
| 29 // MessageLoopForIO. | |
| 30 UsbDeviceHandleUsbfs( | |
| 31 scoped_refptr<UsbDevice> device, | |
| 32 base::ScopedFD fd, | |
| 33 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | |
| 34 | |
| 35 // UsbDeviceHandle implementation. | |
|
juncai
2016/04/13 00:22:32
nit:
s/UsbDeviceHandle implementation./UsbDeviceHa
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
We're not very consistent about this in Chromium.
juncai
2016/04/13 23:52:12
nit: s/implementation/overrides
To be consistent,
Reilly Grant (use Gerrit)
2016/04/14 00:02:45
We discussed this offline and I explained the reas
| |
| 36 scoped_refptr<UsbDevice> GetDevice() const override; | |
| 37 void Close() override; | |
| 38 void SetConfiguration(int configuration_value, | |
| 39 const ResultCallback& callback) override; | |
| 40 void ClaimInterface(int interface_number, | |
| 41 const ResultCallback& callback) override; | |
| 42 void ReleaseInterface(int interface_number, | |
| 43 const ResultCallback& callback) override; | |
| 44 void SetInterfaceAlternateSetting(int interface_number, | |
| 45 int alternate_setting, | |
| 46 const ResultCallback& callback) override; | |
| 47 void ResetDevice(const ResultCallback& callback) override; | |
| 48 void ClearHalt(uint8_t endpoint, const ResultCallback& callback) override; | |
| 49 void ControlTransfer(UsbEndpointDirection direction, | |
| 50 TransferRequestType request_type, | |
| 51 TransferRecipient recipient, | |
| 52 uint8_t request, | |
| 53 uint16_t value, | |
| 54 uint16_t index, | |
| 55 scoped_refptr<net::IOBuffer> buffer, | |
| 56 size_t length, | |
| 57 unsigned int timeout, | |
| 58 const TransferCallback& callback) override; | |
| 59 void IsochronousTransferIn( | |
| 60 uint8_t endpoint_number, | |
| 61 const std::vector<uint32_t>& packet_lengths, | |
| 62 unsigned int timeout, | |
| 63 const IsochronousTransferCallback& callback) override; | |
| 64 | |
| 65 void IsochronousTransferOut( | |
| 66 uint8_t endpoint_number, | |
| 67 scoped_refptr<net::IOBuffer> buffer, | |
| 68 const std::vector<uint32_t>& packet_lengths, | |
| 69 unsigned int timeout, | |
| 70 const IsochronousTransferCallback& callback) override; | |
| 71 void GenericTransfer(UsbEndpointDirection direction, | |
| 72 uint8_t endpoint_number, | |
| 73 scoped_refptr<net::IOBuffer> buffer, | |
| 74 size_t length, | |
| 75 unsigned int timeout, | |
| 76 const TransferCallback& callback) override; | |
| 77 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( | |
| 78 uint8_t endpoint_address) override; | |
| 79 | |
| 80 private: | |
| 81 class FileThreadHelper; | |
| 82 struct Transfer; | |
| 83 struct InterfaceInfo { | |
| 84 uint8_t alternate_setting; | |
| 85 }; | |
| 86 struct EndpointInfo { | |
| 87 UsbTransferType type; | |
| 88 const UsbInterfaceDescriptor* interface; | |
| 89 }; | |
| 90 | |
| 91 ~UsbDeviceHandleUsbfs() override; | |
| 92 void CloseBlocking(); | |
| 93 void SetConfigurationBlocking(int configuration_value, | |
| 94 const ResultCallback& callback); | |
| 95 void SetConfigurationComplete(int configuration_value, | |
| 96 bool success, | |
| 97 const ResultCallback& callback); | |
| 98 void ReleaseInterfaceBlocking(int interface_number, | |
| 99 const ResultCallback& callback); | |
| 100 void ReleaseInterfaceComplete(int interface_number, | |
| 101 const ResultCallback& callback); | |
| 102 void SetInterfaceBlocking(int interface_number, | |
| 103 int alternate_setting, | |
| 104 const ResultCallback& callback); | |
| 105 void ResetDeviceBlocking(const ResultCallback& callback); | |
| 106 void ClearHaltBlocking(uint8_t endpoint_address, | |
| 107 const ResultCallback& callback); | |
| 108 void IsochronousTransferInternal(uint8_t endpoint_address, | |
| 109 scoped_refptr<net::IOBuffer> buffer, | |
| 110 int length, | |
| 111 const std::vector<uint32_t>& packet_lengths, | |
| 112 unsigned int timeout, | |
| 113 const IsochronousTransferCallback& callback); | |
| 114 void ReapedUrbs(std::vector<struct usbdevfs_urb*> urbs); | |
|
juncai
2016/04/13 00:22:33
The "struct" may be omitted.
Also here the parame
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
Done.
| |
| 115 void TransferComplete(scoped_ptr<Transfer> transfer); | |
| 116 void RefreshEndpointInfo(); | |
| 117 void ReportIsochronousError( | |
| 118 const std::vector<uint32_t> packet_lengths, | |
|
juncai
2016/04/13 00:22:33
Use const std::vector<uint32_t>& as parameter?
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
Good catch.
| |
| 119 const UsbDeviceHandle::IsochronousTransferCallback& callback, | |
| 120 UsbTransferStatus status); | |
| 121 void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout); | |
| 122 | |
| 123 static void TransferTimedOut(Transfer* transfer); | |
| 124 | |
| 125 scoped_refptr<UsbDevice> device_; | |
| 126 base::ScopedFD fd_; | |
| 127 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 128 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 129 base::ThreadChecker thread_checker_; | |
| 130 | |
| 131 // Maps claimed interfaces by interface number to their current alternate | |
| 132 // setting. | |
| 133 std::map<uint8_t, InterfaceInfo> interfaces_; | |
|
juncai
2016/04/13 00:22:33
The type of interface number is int elsewhere. Her
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
The type is int when a "not found" value (-1) is r
| |
| 134 | |
| 135 // Maps endpoints (by endpoint address) to the interface they are a part of. | |
| 136 // Only endpoints of currently claimed and selected interface alternates are | |
| 137 // included in the map. | |
| 138 std::map<uint8_t, EndpointInfo> endpoints_; | |
| 139 | |
| 140 // Helper object owned by the blocking task thread. I will be freed if that | |
|
juncai
2016/04/13 00:22:32
s/I/It/
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
Done.
Reilly Grant (use Gerrit)
2016/04/13 20:21:13
Done.
| |
| 141 // thread's message loop is destroyed but can also be freed by this class on | |
| 142 // destruction. | |
| 143 FileThreadHelper* helper_; | |
| 144 | |
| 145 std::list<scoped_ptr<Transfer>> transfers_; | |
| 146 }; | |
| 147 | |
| 148 } // namespace device | |
| 149 | |
| 150 #endif // DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | |
| OLD | NEW |