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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 USB_TRANSFER_CANCELLED, | 30 USB_TRANSFER_CANCELLED, |
31 USB_TRANSFER_STALLED, | 31 USB_TRANSFER_STALLED, |
32 USB_TRANSFER_DISCONNECT, | 32 USB_TRANSFER_DISCONNECT, |
33 USB_TRANSFER_OVERFLOW, | 33 USB_TRANSFER_OVERFLOW, |
34 USB_TRANSFER_LENGTH_SHORT, | 34 USB_TRANSFER_LENGTH_SHORT, |
35 }; | 35 }; |
36 | 36 |
37 // UsbDeviceHandle class provides basic I/O related functionalities. | 37 // UsbDeviceHandle class provides basic I/O related functionalities. |
38 class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> { | 38 class UsbDeviceHandle : public base::RefCountedThreadSafe<UsbDeviceHandle> { |
39 public: | 39 public: |
| 40 struct IsochronousPacket { |
| 41 uint32_t length; |
| 42 uint32_t transferred_length; |
| 43 UsbTransferStatus status; |
| 44 }; |
| 45 |
40 using ResultCallback = base::Callback<void(bool)>; | 46 using ResultCallback = base::Callback<void(bool)>; |
41 using TransferCallback = base::Callback< | 47 using TransferCallback = base::Callback< |
42 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>; | 48 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>; |
| 49 using IsochronousTransferCallback = |
| 50 base::Callback<void(scoped_refptr<net::IOBuffer>, |
| 51 const std::vector<IsochronousPacket>& packets)>; |
43 | 52 |
44 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | 53 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
45 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | 54 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
46 | 55 |
47 virtual scoped_refptr<UsbDevice> GetDevice() const = 0; | 56 virtual scoped_refptr<UsbDevice> GetDevice() const = 0; |
48 | 57 |
49 // Notifies UsbDevice to drop the reference of this object; cancels all the | 58 // Notifies UsbDevice to drop the reference of this object; cancels all the |
50 // flying transfers. | 59 // flying transfers. |
51 // It is possible that the object has no other reference after this call. So | 60 // It is possible that the object has no other reference after this call. So |
52 // if it is called using a raw pointer, it could be invalidated. | 61 // if it is called using a raw pointer, it could be invalidated. |
(...skipping 18 matching lines...) Expand all Loading... |
71 TransferRequestType request_type, | 80 TransferRequestType request_type, |
72 TransferRecipient recipient, | 81 TransferRecipient recipient, |
73 uint8_t request, | 82 uint8_t request, |
74 uint16_t value, | 83 uint16_t value, |
75 uint16_t index, | 84 uint16_t index, |
76 scoped_refptr<net::IOBuffer> buffer, | 85 scoped_refptr<net::IOBuffer> buffer, |
77 size_t length, | 86 size_t length, |
78 unsigned int timeout, | 87 unsigned int timeout, |
79 const TransferCallback& callback) = 0; | 88 const TransferCallback& callback) = 0; |
80 | 89 |
81 virtual void IsochronousTransfer(UsbEndpointDirection direction, | 90 virtual void IsochronousTransferIn( |
82 uint8_t endpoint, | 91 uint8_t endpoint_number, |
83 scoped_refptr<net::IOBuffer> buffer, | 92 const std::vector<uint32_t>& packet_lengths, |
84 size_t length, | 93 unsigned int timeout, |
85 unsigned int packets, | 94 const IsochronousTransferCallback& callback) = 0; |
86 unsigned int packet_length, | 95 |
87 unsigned int timeout, | 96 virtual void IsochronousTransferOut( |
88 const TransferCallback& callback) = 0; | 97 uint8_t endpoint_number, |
| 98 scoped_refptr<net::IOBuffer> buffer, |
| 99 const std::vector<uint32_t>& packet_lengths, |
| 100 unsigned int timeout, |
| 101 const IsochronousTransferCallback& callback) = 0; |
89 | 102 |
90 virtual void GenericTransfer(UsbEndpointDirection direction, | 103 virtual void GenericTransfer(UsbEndpointDirection direction, |
91 uint8_t endpoint, | 104 uint8_t endpoint_number, |
92 scoped_refptr<net::IOBuffer> buffer, | 105 scoped_refptr<net::IOBuffer> buffer, |
93 size_t length, | 106 size_t length, |
94 unsigned int timeout, | 107 unsigned int timeout, |
95 const TransferCallback& callback) = 0; | 108 const TransferCallback& callback) = 0; |
96 | 109 |
97 // Gets the interface containing |endpoint_address|. Returns false if no | 110 // Gets the interface containing |endpoint_address|. Returns false if no |
98 // claimed interface contains that endpoint. | 111 // claimed interface contains that endpoint. |
99 virtual bool FindInterfaceByEndpoint(uint8_t endpoint_address, | 112 virtual bool FindInterfaceByEndpoint(uint8_t endpoint_address, |
100 uint8_t* interface_number) = 0; | 113 uint8_t* interface_number) = 0; |
101 | 114 |
102 protected: | 115 protected: |
103 friend class base::RefCountedThreadSafe<UsbDeviceHandle>; | 116 friend class base::RefCountedThreadSafe<UsbDeviceHandle>; |
104 | 117 |
105 UsbDeviceHandle(); | 118 UsbDeviceHandle(); |
106 | 119 |
107 virtual ~UsbDeviceHandle(); | 120 virtual ~UsbDeviceHandle(); |
108 | 121 |
| 122 private: |
109 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); | 123 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); |
110 }; | 124 }; |
111 | 125 |
112 } // namespace device | 126 } // namespace device |
113 | 127 |
114 #endif // DEVICE_USB_USB_DEVICE_HANDLE_H_ | 128 #endif // DEVICE_USB_USB_DEVICE_HANDLE_H_ |
OLD | NEW |