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