OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ | 5 #ifndef CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ |
6 #define CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ | 6 #define CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 USB_TRANSFER_TIMEOUT, | 36 USB_TRANSFER_TIMEOUT, |
37 USB_TRANSFER_CANCELLED, | 37 USB_TRANSFER_CANCELLED, |
38 USB_TRANSFER_STALLED, | 38 USB_TRANSFER_STALLED, |
39 USB_TRANSFER_DISCONNECT, | 39 USB_TRANSFER_DISCONNECT, |
40 USB_TRANSFER_OVERFLOW, | 40 USB_TRANSFER_OVERFLOW, |
41 USB_TRANSFER_LENGTH_SHORT, | 41 USB_TRANSFER_LENGTH_SHORT, |
42 }; | 42 }; |
43 | 43 |
44 typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, | 44 typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, |
45 size_t)> UsbTransferCallback; | 45 size_t)> UsbTransferCallback; |
46 typedef base::Callback<void(bool success)> UsbInterfaceCallback; | |
47 | 46 |
48 // A UsbDevice wraps the platform's underlying representation of what a USB | 47 // A UsbDevice wraps the platform's underlying representation of what a USB |
49 // device actually is, and provides accessors for performing many of the | 48 // device actually is, and provides accessors for performing many of the |
50 // standard USB operations. | 49 // standard USB operations. |
51 class UsbDeviceHandle : public base::RefCounted<UsbDeviceHandle> { | 50 class UsbDeviceHandle : public base::RefCounted<UsbDeviceHandle> { |
52 public: | 51 public: |
53 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | 52 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
54 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | 53 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
55 | 54 |
56 // Usually you will not want to directly create a UsbDevice, favoring to let | 55 // Usually you will not want to directly create a UsbDevice, favoring to let |
57 // the UsbService take care of the logistics of getting a platform device | 56 // the UsbService take care of the logistics of getting a platform device |
58 // handle and handling events for it. | 57 // handle and handling events for it. |
59 UsbDeviceHandle(UsbService* service, PlatformUsbDeviceHandle handle); | 58 UsbDeviceHandle(UsbService* service, PlatformUsbDeviceHandle handle); |
60 | 59 |
61 PlatformUsbDeviceHandle handle() { return handle_; } | 60 PlatformUsbDeviceHandle handle() { return handle_; } |
62 | 61 |
63 // Close the USB device and release the underlying platform device. |callback| | 62 // Close the USB device and release the underlying platform device. |
64 // is invoked after the device has been closed. | 63 virtual void Close(); |
65 virtual void Close(const base::Callback<void()>& callback); | |
66 | 64 |
67 virtual void ListInterfaces(UsbConfigDescriptor* config, | 65 // Device manipulation operations. These methods are blocking. |
68 const UsbInterfaceCallback& callback); | 66 virtual bool ListInterfaces(UsbConfigDescriptor* config); |
| 67 virtual bool ClaimInterface(const int interface_number); |
| 68 virtual bool ReleaseInterface(const int interface_number); |
| 69 virtual bool SetInterfaceAlternateSetting( |
| 70 const int interface_number, |
| 71 const int alternate_setting); |
| 72 virtual bool ResetDevice(); |
69 | 73 |
70 virtual void ClaimInterface(const int interface_number, | 74 // Async IO. |
71 const UsbInterfaceCallback& callback); | |
72 | |
73 virtual void ReleaseInterface(const int interface_number, | |
74 const UsbInterfaceCallback& callback); | |
75 | |
76 virtual void SetInterfaceAlternateSetting( | |
77 const int interface_number, | |
78 const int alternate_setting, | |
79 const UsbInterfaceCallback& callback); | |
80 | |
81 virtual void ControlTransfer(const UsbEndpointDirection direction, | 75 virtual void ControlTransfer(const UsbEndpointDirection direction, |
82 const TransferRequestType request_type, | 76 const TransferRequestType request_type, |
83 const TransferRecipient recipient, | 77 const TransferRecipient recipient, |
84 const uint8 request, | 78 const uint8 request, |
85 const uint16 value, | 79 const uint16 value, |
86 const uint16 index, | 80 const uint16 index, |
87 net::IOBuffer* buffer, | 81 net::IOBuffer* buffer, |
88 const size_t length, | 82 const size_t length, |
89 const unsigned int timeout, | 83 const unsigned int timeout, |
90 const UsbTransferCallback& callback); | 84 const UsbTransferCallback& callback); |
(...skipping 14 matching lines...) Expand all Loading... |
105 | 99 |
106 virtual void IsochronousTransfer(const UsbEndpointDirection direction, | 100 virtual void IsochronousTransfer(const UsbEndpointDirection direction, |
107 const uint8 endpoint, | 101 const uint8 endpoint, |
108 net::IOBuffer* buffer, | 102 net::IOBuffer* buffer, |
109 const size_t length, | 103 const size_t length, |
110 const unsigned int packets, | 104 const unsigned int packets, |
111 const unsigned int packet_length, | 105 const unsigned int packet_length, |
112 const unsigned int timeout, | 106 const unsigned int timeout, |
113 const UsbTransferCallback& callback); | 107 const UsbTransferCallback& callback); |
114 | 108 |
115 virtual void ResetDevice(const base::Callback<void(bool success)>& callback); | |
116 | |
117 // Normal code should not call this function. It is called by the platform's | 109 // Normal code should not call this function. It is called by the platform's |
118 // callback mechanism in such a way that it cannot be made private. Invokes | 110 // callback mechanism in such a way that it cannot be made private. Invokes |
119 // the callbacks associated with a given transfer, and removes it from the | 111 // the callbacks associated with a given transfer, and removes it from the |
120 // in-flight transfer set. | 112 // in-flight transfer set. |
121 void TransferComplete(PlatformUsbTransferHandle transfer); | 113 void TransferComplete(PlatformUsbTransferHandle transfer); |
122 | 114 |
123 protected: | 115 protected: |
124 // This constructor variant is for use in testing only. | 116 // This constructor variant is for use in testing only. |
125 UsbDeviceHandle(); | 117 UsbDeviceHandle(); |
126 | 118 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // transfers_ tracks all in-flight transfers associated with this device, | 152 // transfers_ tracks all in-flight transfers associated with this device, |
161 // allowing the device to retain the buffer and callback associated with a | 153 // allowing the device to retain the buffer and callback associated with a |
162 // transfer until such time that it completes. It is protected by lock_. | 154 // transfer until such time that it completes. It is protected by lock_. |
163 base::Lock lock_; | 155 base::Lock lock_; |
164 std::map<PlatformUsbTransferHandle, Transfer> transfers_; | 156 std::map<PlatformUsbTransferHandle, Transfer> transfers_; |
165 | 157 |
166 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); | 158 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); |
167 }; | 159 }; |
168 | 160 |
169 #endif // CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ | 161 #endif // CHROME_BROWSER_USB_USB_DEVICE_HANDLE_H_ |
OLD | NEW |