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_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_H_ |
6 #define DEVICE_USB_USB_DEVICE_HANDLE_H_ | 6 #define DEVICE_USB_USB_DEVICE_HANDLE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 USB_TRANSFER_COMPLETED = 0, | 23 USB_TRANSFER_COMPLETED = 0, |
24 USB_TRANSFER_ERROR, | 24 USB_TRANSFER_ERROR, |
25 USB_TRANSFER_TIMEOUT, | 25 USB_TRANSFER_TIMEOUT, |
26 USB_TRANSFER_CANCELLED, | 26 USB_TRANSFER_CANCELLED, |
27 USB_TRANSFER_STALLED, | 27 USB_TRANSFER_STALLED, |
28 USB_TRANSFER_DISCONNECT, | 28 USB_TRANSFER_DISCONNECT, |
29 USB_TRANSFER_OVERFLOW, | 29 USB_TRANSFER_OVERFLOW, |
30 USB_TRANSFER_LENGTH_SHORT, | 30 USB_TRANSFER_LENGTH_SHORT, |
31 }; | 31 }; |
32 | 32 |
33 typedef base::Callback< | |
34 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)> | |
35 UsbTransferCallback; | |
36 | |
37 // UsbDeviceHandle class provides basic I/O related functionalities. | 33 // UsbDeviceHandle class provides basic I/O related functionalities. |
38 class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> { | 34 class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> { |
39 public: | 35 public: |
| 36 using ResultCallback = base::Callback<void(bool)>; |
| 37 using TransferCallback = base::Callback< |
| 38 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>; |
| 39 |
40 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | 40 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
41 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | 41 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
42 | 42 |
43 virtual scoped_refptr<UsbDevice> GetDevice() const = 0; | 43 virtual scoped_refptr<UsbDevice> GetDevice() const = 0; |
44 | 44 |
45 // Notifies UsbDevice to drop the reference of this object; cancels all the | 45 // Notifies UsbDevice to drop the reference of this object; cancels all the |
46 // flying transfers. | 46 // flying transfers. |
47 // It is possible that the object has no other reference after this call. So | 47 // It is possible that the object has no other reference after this call. So |
48 // if it is called using a raw pointer, it could be invalidated. | 48 // if it is called using a raw pointer, it could be invalidated. |
49 // The platform device handle will be closed when UsbDeviceHandle destructs. | 49 // The platform device handle will be closed when UsbDeviceHandle destructs. |
50 virtual void Close() = 0; | 50 virtual void Close() = 0; |
51 | 51 |
52 // Device manipulation operations. These methods are blocking and must be | 52 // Device manipulation operations. |
53 // called on FILE thread. | 53 virtual void SetConfiguration(int configuration_value, |
54 virtual bool SetConfiguration(int configuration_value) = 0; | 54 const ResultCallback& callback) = 0; |
55 virtual bool ClaimInterface(int interface_number) = 0; | 55 virtual void ClaimInterface(int interface_number, |
| 56 const ResultCallback& callback) = 0; |
56 virtual bool ReleaseInterface(int interface_number) = 0; | 57 virtual bool ReleaseInterface(int interface_number) = 0; |
57 virtual bool SetInterfaceAlternateSetting(int interface_number, | 58 virtual void SetInterfaceAlternateSetting(int interface_number, |
58 int alternate_setting) = 0; | 59 int alternate_setting, |
59 virtual bool ResetDevice() = 0; | 60 const ResultCallback& callback) = 0; |
| 61 virtual void ResetDevice(const ResultCallback& callback) = 0; |
60 | 62 |
61 // Gets the string descriptor with the given index from the device, or returns | 63 // The transfer functions may be called from any thread. The provided callback |
62 // false. This method is blocking and must be called on the FILE thread. | 64 // will be run on the caller's thread. |
63 virtual bool GetStringDescriptor(uint8 string_id, base::string16* string) = 0; | |
64 | |
65 // Async IO. Can be called on any thread. | |
66 virtual void ControlTransfer(UsbEndpointDirection direction, | 65 virtual void ControlTransfer(UsbEndpointDirection direction, |
67 TransferRequestType request_type, | 66 TransferRequestType request_type, |
68 TransferRecipient recipient, | 67 TransferRecipient recipient, |
69 uint8 request, | 68 uint8 request, |
70 uint16 value, | 69 uint16 value, |
71 uint16 index, | 70 uint16 index, |
72 net::IOBuffer* buffer, | 71 scoped_refptr<net::IOBuffer> buffer, |
73 size_t length, | 72 size_t length, |
74 unsigned int timeout, | 73 unsigned int timeout, |
75 const UsbTransferCallback& callback) = 0; | 74 const TransferCallback& callback) = 0; |
76 | 75 |
77 virtual void BulkTransfer(UsbEndpointDirection direction, | 76 virtual void BulkTransfer(UsbEndpointDirection direction, |
78 uint8 endpoint, | 77 uint8 endpoint, |
79 net::IOBuffer* buffer, | 78 scoped_refptr<net::IOBuffer> buffer, |
80 size_t length, | 79 size_t length, |
81 unsigned int timeout, | 80 unsigned int timeout, |
82 const UsbTransferCallback& callback) = 0; | 81 const TransferCallback& callback) = 0; |
83 | 82 |
84 virtual void InterruptTransfer(UsbEndpointDirection direction, | 83 virtual void InterruptTransfer(UsbEndpointDirection direction, |
85 uint8 endpoint, | 84 uint8 endpoint, |
86 net::IOBuffer* buffer, | 85 scoped_refptr<net::IOBuffer> buffer, |
87 size_t length, | 86 size_t length, |
88 unsigned int timeout, | 87 unsigned int timeout, |
89 const UsbTransferCallback& callback) = 0; | 88 const TransferCallback& callback) = 0; |
90 | 89 |
91 virtual void IsochronousTransfer(UsbEndpointDirection direction, | 90 virtual void IsochronousTransfer(UsbEndpointDirection direction, |
92 uint8 endpoint, | 91 uint8 endpoint, |
93 net::IOBuffer* buffer, | 92 scoped_refptr<net::IOBuffer> buffer, |
94 size_t length, | 93 size_t length, |
95 unsigned int packets, | 94 unsigned int packets, |
96 unsigned int packet_length, | 95 unsigned int packet_length, |
97 unsigned int timeout, | 96 unsigned int timeout, |
98 const UsbTransferCallback& callback) = 0; | 97 const TransferCallback& callback) = 0; |
99 | 98 |
100 protected: | 99 protected: |
101 friend class base::RefCountedThreadSafe<UsbDeviceHandle>; | 100 friend class base::RefCountedThreadSafe<UsbDeviceHandle>; |
102 | 101 |
103 UsbDeviceHandle() {}; | 102 UsbDeviceHandle() {}; |
104 | 103 |
105 virtual ~UsbDeviceHandle() {}; | 104 virtual ~UsbDeviceHandle() {}; |
106 | 105 |
107 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); | 106 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); |
108 }; | 107 }; |
109 | 108 |
110 } // namespace device | 109 } // namespace device |
111 | 110 |
112 #endif // DEVICE_USB_USB_DEVICE_HANDLE_H_ | 111 #endif // DEVICE_USB_USB_DEVICE_HANDLE_H_ |
OLD | NEW |