OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ |
6 #define DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | 6 #define DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( | 82 const UsbInterfaceDescriptor* FindInterfaceByEndpoint( |
83 uint8_t endpoint_address) override; | 83 uint8_t endpoint_address) override; |
84 | 84 |
85 protected: | 85 protected: |
86 ~UsbDeviceHandleUsbfs() override; | 86 ~UsbDeviceHandleUsbfs() override; |
87 | 87 |
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { | 88 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { |
89 return task_runner_; | 89 return task_runner_; |
90 } | 90 } |
91 | 91 |
92 // Stops |helper_| and releases ownership of |fd_| without closing it. | 92 // Destroys |helper_| and releases ownership of |fd_| without closing it. |
93 void ReleaseFileDescriptor(); | 93 void ReleaseFileDescriptor(); |
94 | 94 |
| 95 // Destroys |helper_| and closes |fd_|. Override to call |
| 96 // ReleaseFileDescriptor() if necessary. |
| 97 virtual void CloseBlocking(); |
| 98 |
95 private: | 99 private: |
96 class FileThreadHelper; | 100 class FileThreadHelper; |
97 struct Transfer; | 101 struct Transfer; |
98 struct InterfaceInfo { | 102 struct InterfaceInfo { |
99 uint8_t alternate_setting; | 103 uint8_t alternate_setting; |
100 }; | 104 }; |
101 struct EndpointInfo { | 105 struct EndpointInfo { |
102 UsbTransferType type; | 106 UsbTransferType type; |
103 const UsbInterfaceDescriptor* interface; | 107 const UsbInterfaceDescriptor* interface; |
104 }; | 108 }; |
105 | 109 |
106 virtual void CloseBlocking(); | |
107 void SetConfigurationBlocking(int configuration_value, | |
108 const ResultCallback& callback); | |
109 void SetConfigurationComplete(int configuration_value, | 110 void SetConfigurationComplete(int configuration_value, |
110 bool success, | 111 bool success, |
111 const ResultCallback& callback); | 112 const ResultCallback& callback); |
112 void ReleaseInterfaceBlocking(int interface_number, | |
113 const ResultCallback& callback); | |
114 void ReleaseInterfaceComplete(int interface_number, | 113 void ReleaseInterfaceComplete(int interface_number, |
115 const ResultCallback& callback); | 114 const ResultCallback& callback); |
116 void SetInterfaceBlocking(int interface_number, | |
117 int alternate_setting, | |
118 const ResultCallback& callback); | |
119 void ResetDeviceBlocking(const ResultCallback& callback); | |
120 void ClearHaltBlocking(uint8_t endpoint_address, | |
121 const ResultCallback& callback); | |
122 void IsochronousTransferInternal(uint8_t endpoint_address, | 115 void IsochronousTransferInternal(uint8_t endpoint_address, |
123 scoped_refptr<net::IOBuffer> buffer, | 116 scoped_refptr<net::IOBuffer> buffer, |
124 size_t total_length, | 117 size_t total_length, |
125 const std::vector<uint32_t>& packet_lengths, | 118 const std::vector<uint32_t>& packet_lengths, |
126 unsigned int timeout, | 119 unsigned int timeout, |
127 const IsochronousTransferCallback& callback); | 120 const IsochronousTransferCallback& callback); |
128 void GenericTransferInternal( | 121 void GenericTransferInternal( |
129 UsbEndpointDirection direction, | 122 UsbEndpointDirection direction, |
130 uint8_t endpoint_number, | 123 uint8_t endpoint_number, |
131 scoped_refptr<net::IOBuffer> buffer, | 124 scoped_refptr<net::IOBuffer> buffer, |
132 size_t length, | 125 size_t length, |
133 unsigned int timeout, | 126 unsigned int timeout, |
134 const TransferCallback& callback, | 127 const TransferCallback& callback, |
135 scoped_refptr<base::SingleThreadTaskRunner> callback_runner); | 128 scoped_refptr<base::SingleThreadTaskRunner> callback_runner); |
136 void ReapedUrbs(const std::vector<usbdevfs_urb*>& urbs); | 129 void ReapedUrbs(const std::vector<usbdevfs_urb*>& urbs); |
137 void TransferComplete(std::unique_ptr<Transfer> transfer); | 130 void TransferComplete(std::unique_ptr<Transfer> transfer); |
138 void RefreshEndpointInfo(); | 131 void RefreshEndpointInfo(); |
139 void ReportIsochronousError( | 132 void ReportIsochronousError( |
140 const std::vector<uint32_t>& packet_lengths, | 133 const std::vector<uint32_t>& packet_lengths, |
141 const UsbDeviceHandle::IsochronousTransferCallback& callback, | 134 const UsbDeviceHandle::IsochronousTransferCallback& callback, |
142 UsbTransferStatus status); | 135 UsbTransferStatus status); |
143 void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout); | 136 void SetUpTimeoutCallback(Transfer* transfer, unsigned int timeout); |
144 std::unique_ptr<Transfer> RemoveFromTransferList(Transfer* transfer); | 137 std::unique_ptr<Transfer> RemoveFromTransferList(Transfer* transfer); |
145 void CancelTransfer(Transfer* transfer, UsbTransferStatus status); | 138 void CancelTransfer(Transfer* transfer, UsbTransferStatus status); |
146 void DiscardUrbBlocking(Transfer* transfer); | 139 void DiscardUrbBlocking(Transfer* transfer); |
147 void UrbDiscarded(Transfer* transfer); | 140 void UrbDiscarded(Transfer* transfer); |
148 | 141 |
149 scoped_refptr<UsbDevice> device_; | 142 scoped_refptr<UsbDevice> device_; |
150 base::ScopedFD fd_; | 143 int fd_; // Copy of the base::ScopedFD held by |helper_| valid if |device_|. |
151 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 144 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
152 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 145 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
153 | 146 |
154 // Maps claimed interfaces by interface number to their current alternate | 147 // Maps claimed interfaces by interface number to their current alternate |
155 // setting. | 148 // setting. |
156 std::map<uint8_t, InterfaceInfo> interfaces_; | 149 std::map<uint8_t, InterfaceInfo> interfaces_; |
157 | 150 |
158 // Maps endpoints (by endpoint address) to the interface they are a part of. | 151 // Maps endpoints (by endpoint address) to the interface they are a part of. |
159 // Only endpoints of currently claimed and selected interface alternates are | 152 // Only endpoints of currently claimed and selected interface alternates are |
160 // included in the map. | 153 // included in the map. |
161 std::map<uint8_t, EndpointInfo> endpoints_; | 154 std::map<uint8_t, EndpointInfo> endpoints_; |
162 | 155 |
163 // Helper object owned by the blocking task thread. It will be freed if that | 156 // Helper object exists on the blocking task thread and all calls to it and |
164 // thread's message loop is destroyed but can also be freed by this class on | 157 // its destruction must be posted there. |
165 // destruction. | 158 std::unique_ptr<FileThreadHelper> helper_; |
166 FileThreadHelper* helper_; | |
167 | 159 |
168 std::list<std::unique_ptr<Transfer>> transfers_; | 160 std::list<std::unique_ptr<Transfer>> transfers_; |
169 }; | 161 }; |
170 | 162 |
171 } // namespace device | 163 } // namespace device |
172 | 164 |
173 #endif // DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ | 165 #endif // DEVICE_USB_USB_DEVICE_HANDLE_USBFS_H_ |
OLD | NEW |