| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 6 #define CHROME_BROWSER_USB_USB_DEVICE_H_ | 6 #define CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "chrome/browser/usb/usb_interface.h" |
| 12 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 13 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 14 | 16 |
| 15 struct libusb_device; | 17 struct libusb_device; |
| 16 struct libusb_device_handle; | 18 struct libusb_device_handle; |
| 17 struct libusb_iso_packet_descriptor; | 19 struct libusb_iso_packet_descriptor; |
| 18 struct libusb_transfer; | 20 struct libusb_transfer; |
| 19 | 21 |
| 20 typedef libusb_device* PlatformUsbDevice; | 22 typedef libusb_device* PlatformUsbDevice; |
| 21 typedef libusb_device_handle* PlatformUsbDeviceHandle; | 23 typedef libusb_device_handle* PlatformUsbDeviceHandle; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 USB_TRANSFER_COMPLETED = 0, | 34 USB_TRANSFER_COMPLETED = 0, |
| 33 USB_TRANSFER_ERROR, | 35 USB_TRANSFER_ERROR, |
| 34 USB_TRANSFER_TIMEOUT, | 36 USB_TRANSFER_TIMEOUT, |
| 35 USB_TRANSFER_CANCELLED, | 37 USB_TRANSFER_CANCELLED, |
| 36 USB_TRANSFER_STALLED, | 38 USB_TRANSFER_STALLED, |
| 37 USB_TRANSFER_DISCONNECT, | 39 USB_TRANSFER_DISCONNECT, |
| 38 USB_TRANSFER_OVERFLOW, | 40 USB_TRANSFER_OVERFLOW, |
| 39 USB_TRANSFER_LENGTH_SHORT, | 41 USB_TRANSFER_LENGTH_SHORT, |
| 40 }; | 42 }; |
| 41 | 43 |
| 42 enum UsbTransferType { | |
| 43 USB_TRANSFER_CONTROL = 0, | |
| 44 USB_TRANSFER_BULK, | |
| 45 USB_TRANSFER_INTERRUPT, | |
| 46 USB_TRANSFER_ISOCHRONOUS, | |
| 47 }; | |
| 48 | |
| 49 typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, | 44 typedef base::Callback<void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, |
| 50 size_t)> UsbTransferCallback; | 45 size_t)> UsbTransferCallback; |
| 51 typedef base::Callback<void(bool)> UsbInterfaceCallback; | 46 typedef base::Callback<void(bool)> UsbInterfaceCallback; |
| 52 | 47 |
| 53 // A UsbDevice wraps the platform's underlying representation of what a USB | 48 // A UsbDevice wraps the platform's underlying representation of what a USB |
| 54 // device actually is, and provides accessors for performing many of the | 49 // device actually is, and provides accessors for performing many of the |
| 55 // standard USB operations. | 50 // standard USB operations. |
| 56 class UsbDevice : public base::RefCounted<UsbDevice> { | 51 class UsbDevice : public base::RefCounted<UsbDevice> { |
| 57 public: | 52 public: |
| 58 enum TransferDirection { INBOUND, OUTBOUND }; | |
| 59 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | 53 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
| 60 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | 54 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
| 61 | 55 |
| 62 // Usually you will not want to directly create a UsbDevice, favoring to let | 56 // Usually you will not want to directly create a UsbDevice, favoring to let |
| 63 // the UsbService take care of the logistics of getting a platform device | 57 // the UsbService take care of the logistics of getting a platform device |
| 64 // handle and handling events for it. | 58 // handle and handling events for it. |
| 65 UsbDevice(UsbService* service, PlatformUsbDeviceHandle handle); | 59 UsbDevice(UsbService* service, PlatformUsbDeviceHandle handle); |
| 66 | 60 |
| 67 PlatformUsbDeviceHandle handle() { return handle_; } | 61 PlatformUsbDeviceHandle handle() { return handle_; } |
| 68 | 62 |
| 69 // Close the USB device and release the underlying platform device. |callback| | 63 // Close the USB device and release the underlying platform device. |callback| |
| 70 // is invoked after the device has been closed. | 64 // is invoked after the device has been closed. |
| 71 virtual void Close(const base::Callback<void()>& callback); | 65 virtual void Close(const base::Callback<void()>& callback); |
| 72 | 66 |
| 67 virtual void ListInterfaces(UsbConfigDescriptor* config, |
| 68 const UsbInterfaceCallback& callback); |
| 69 |
| 73 virtual void ClaimInterface(const int interface_number, | 70 virtual void ClaimInterface(const int interface_number, |
| 74 const UsbInterfaceCallback& callback); | 71 const UsbInterfaceCallback& callback); |
| 75 | 72 |
| 76 virtual void ReleaseInterface(const int interface_number, | 73 virtual void ReleaseInterface(const int interface_number, |
| 77 const UsbInterfaceCallback& callback); | 74 const UsbInterfaceCallback& callback); |
| 78 | 75 |
| 79 virtual void SetInterfaceAlternateSetting( | 76 virtual void SetInterfaceAlternateSetting( |
| 80 const int interface_number, | 77 const int interface_number, |
| 81 const int alternate_setting, | 78 const int alternate_setting, |
| 82 const UsbInterfaceCallback& callback); | 79 const UsbInterfaceCallback& callback); |
| 83 | 80 |
| 84 virtual void ControlTransfer(const TransferDirection direction, | 81 virtual void ControlTransfer(const UsbEndpointDirection direction, |
| 85 const TransferRequestType request_type, | 82 const TransferRequestType request_type, |
| 86 const TransferRecipient recipient, | 83 const TransferRecipient recipient, |
| 87 const uint8 request, | 84 const uint8 request, |
| 88 const uint16 value, | 85 const uint16 value, |
| 89 const uint16 index, | 86 const uint16 index, |
| 90 net::IOBuffer* buffer, | 87 net::IOBuffer* buffer, |
| 91 const size_t length, | 88 const size_t length, |
| 92 const unsigned int timeout, | 89 const unsigned int timeout, |
| 93 const UsbTransferCallback& callback); | 90 const UsbTransferCallback& callback); |
| 94 | 91 |
| 95 virtual void BulkTransfer(const TransferDirection direction, | 92 virtual void BulkTransfer(const UsbEndpointDirection direction, |
| 96 const uint8 endpoint, | 93 const uint8 endpoint, |
| 97 net::IOBuffer* buffer, | 94 net::IOBuffer* buffer, |
| 98 const size_t length, | 95 const size_t length, |
| 99 const unsigned int timeout, | 96 const unsigned int timeout, |
| 100 const UsbTransferCallback& callback); | 97 const UsbTransferCallback& callback); |
| 101 | 98 |
| 102 virtual void InterruptTransfer(const TransferDirection direction, | 99 virtual void InterruptTransfer(const UsbEndpointDirection direction, |
| 103 const uint8 endpoint, | 100 const uint8 endpoint, |
| 104 net::IOBuffer* buffer, | 101 net::IOBuffer* buffer, |
| 105 const size_t length, | 102 const size_t length, |
| 106 const unsigned int timeout, | 103 const unsigned int timeout, |
| 107 const UsbTransferCallback& callback); | 104 const UsbTransferCallback& callback); |
| 108 | 105 |
| 109 virtual void IsochronousTransfer(const TransferDirection direction, | 106 virtual void IsochronousTransfer(const UsbEndpointDirection direction, |
| 110 const uint8 endpoint, | 107 const uint8 endpoint, |
| 111 net::IOBuffer* buffer, | 108 net::IOBuffer* buffer, |
| 112 const size_t length, | 109 const size_t length, |
| 113 const unsigned int packets, | 110 const unsigned int packets, |
| 114 const unsigned int packet_length, | 111 const unsigned int packet_length, |
| 115 const unsigned int timeout, | 112 const unsigned int timeout, |
| 116 const UsbTransferCallback& callback); | 113 const UsbTransferCallback& callback); |
| 117 | 114 |
| 118 virtual void ResetDevice(const base::Callback<void(bool)>& callback); | 115 virtual void ResetDevice(const base::Callback<void(bool)>& callback); |
| 119 | 116 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // transfers_ tracks all in-flight transfers associated with this device, | 160 // transfers_ tracks all in-flight transfers associated with this device, |
| 164 // allowing the device to retain the buffer and callback associated with a | 161 // allowing the device to retain the buffer and callback associated with a |
| 165 // transfer until such time that it completes. It is protected by lock_. | 162 // transfer until such time that it completes. It is protected by lock_. |
| 166 base::Lock lock_; | 163 base::Lock lock_; |
| 167 std::map<PlatformUsbTransferHandle, Transfer> transfers_; | 164 std::map<PlatformUsbTransferHandle, Transfer> transfers_; |
| 168 | 165 |
| 169 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | 166 DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
| 170 }; | 167 }; |
| 171 | 168 |
| 172 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ | 169 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ |
| OLD | NEW |