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 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
6 #define DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 6 #define DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 typedef libusb_device_handle* PlatformUsbDeviceHandle; | 31 typedef libusb_device_handle* PlatformUsbDeviceHandle; |
32 typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor; | 32 typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor; |
33 typedef libusb_transfer* PlatformUsbTransferHandle; | 33 typedef libusb_transfer* PlatformUsbTransferHandle; |
34 | 34 |
35 // UsbDeviceHandle class provides basic I/O related functionalities. | 35 // UsbDeviceHandle class provides basic I/O related functionalities. |
36 class UsbDeviceHandleImpl : public UsbDeviceHandle { | 36 class UsbDeviceHandleImpl : public UsbDeviceHandle { |
37 public: | 37 public: |
38 scoped_refptr<UsbDevice> GetDevice() const override; | 38 scoped_refptr<UsbDevice> GetDevice() const override; |
39 void Close() override; | 39 void Close() override; |
| 40 bool SetConfiguration(int configuration_value) override; |
40 bool ClaimInterface(int interface_number) override; | 41 bool ClaimInterface(int interface_number) override; |
41 bool ReleaseInterface(int interface_number) override; | 42 bool ReleaseInterface(int interface_number) override; |
42 bool SetInterfaceAlternateSetting(int interface_number, | 43 bool SetInterfaceAlternateSetting(int interface_number, |
43 int alternate_setting) override; | 44 int alternate_setting) override; |
44 bool ResetDevice() override; | 45 bool ResetDevice() override; |
45 bool GetStringDescriptor(uint8 string_id, base::string16* string) override; | 46 bool GetStringDescriptor(uint8 string_id, base::string16* string) override; |
46 | 47 |
47 void ControlTransfer(UsbEndpointDirection direction, | 48 void ControlTransfer(UsbEndpointDirection direction, |
48 TransferRequestType request_type, | 49 TransferRequestType request_type, |
49 TransferRecipient recipient, | 50 TransferRecipient recipient, |
(...skipping 29 matching lines...) Expand all Loading... |
79 const UsbTransferCallback& callback) override; | 80 const UsbTransferCallback& callback) override; |
80 | 81 |
81 PlatformUsbDeviceHandle handle() const { return handle_; } | 82 PlatformUsbDeviceHandle handle() const { return handle_; } |
82 | 83 |
83 protected: | 84 protected: |
84 friend class UsbDeviceImpl; | 85 friend class UsbDeviceImpl; |
85 | 86 |
86 // This constructor is called by UsbDevice. | 87 // This constructor is called by UsbDevice. |
87 UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, | 88 UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, |
88 UsbDeviceImpl* device, | 89 UsbDeviceImpl* device, |
89 PlatformUsbDeviceHandle handle, | 90 PlatformUsbDeviceHandle handle); |
90 const UsbConfigDescriptor& config); | |
91 | 91 |
92 ~UsbDeviceHandleImpl() override; | 92 ~UsbDeviceHandleImpl() override; |
93 | 93 |
94 private: | 94 private: |
95 friend class Transfer; | 95 friend class Transfer; |
96 | 96 |
97 class InterfaceClaimer; | 97 class InterfaceClaimer; |
98 class Transfer; | 98 class Transfer; |
99 | 99 |
100 // Refresh endpoint_map_ after ClaimInterface, ReleaseInterface and | 100 // Refresh endpoint_map_ after ClaimInterface, ReleaseInterface and |
(...skipping 22 matching lines...) Expand all Loading... |
123 | 123 |
124 bool GetSupportedLanguages(); | 124 bool GetSupportedLanguages(); |
125 | 125 |
126 // Informs the object to drop internal references. | 126 // Informs the object to drop internal references. |
127 void InternalClose(); | 127 void InternalClose(); |
128 | 128 |
129 UsbDeviceImpl* device_; | 129 UsbDeviceImpl* device_; |
130 | 130 |
131 PlatformUsbDeviceHandle handle_; | 131 PlatformUsbDeviceHandle handle_; |
132 | 132 |
133 const UsbConfigDescriptor& config_; | |
134 | |
135 std::vector<uint16> languages_; | 133 std::vector<uint16> languages_; |
136 std::map<uint8, base::string16> strings_; | 134 std::map<uint8, base::string16> strings_; |
137 | 135 |
138 typedef std::map<int, scoped_refptr<InterfaceClaimer>> ClaimedInterfaceMap; | 136 typedef std::map<int, scoped_refptr<InterfaceClaimer>> ClaimedInterfaceMap; |
139 ClaimedInterfaceMap claimed_interfaces_; | 137 ClaimedInterfaceMap claimed_interfaces_; |
140 | 138 |
141 // This set holds weak pointers to pending transfers. | 139 // This set holds weak pointers to pending transfers. |
142 std::set<Transfer*> transfers_; | 140 std::set<Transfer*> transfers_; |
143 | 141 |
144 // A map from endpoints to interfaces | 142 // A map from endpoints to interfaces |
145 typedef std::map<int, int> EndpointMap; | 143 typedef std::map<int, int> EndpointMap; |
146 EndpointMap endpoint_map_; | 144 EndpointMap endpoint_map_; |
147 | 145 |
148 // Retain the UsbContext so that the platform context will not be destroyed | 146 // Retain the UsbContext so that the platform context will not be destroyed |
149 // before this handle. | 147 // before this handle. |
150 scoped_refptr<UsbContext> context_; | 148 scoped_refptr<UsbContext> context_; |
151 | 149 |
152 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 150 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
153 | 151 |
154 base::ThreadChecker thread_checker_; | 152 base::ThreadChecker thread_checker_; |
155 base::WeakPtrFactory<UsbDeviceHandleImpl> weak_factory_; | 153 base::WeakPtrFactory<UsbDeviceHandleImpl> weak_factory_; |
156 | 154 |
157 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl); | 155 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl); |
158 }; | 156 }; |
159 | 157 |
160 } // namespace device | 158 } // namespace device |
161 | 159 |
162 #endif // DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 160 #endif // DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
OLD | NEW |