OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ | |
6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ | |
7 | |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/strings/string16.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "components/usb_service/usb_interface.h" | |
16 #include "components/usb_service/usb_service_export.h" | |
17 #include "net/base/io_buffer.h" | |
18 | |
19 namespace usb_service { | |
20 | |
21 class UsbDevice; | |
22 | |
23 enum UsbTransferStatus { | |
24 USB_TRANSFER_COMPLETED = 0, | |
25 USB_TRANSFER_ERROR, | |
26 USB_TRANSFER_TIMEOUT, | |
27 USB_TRANSFER_CANCELLED, | |
28 USB_TRANSFER_STALLED, | |
29 USB_TRANSFER_DISCONNECT, | |
30 USB_TRANSFER_OVERFLOW, | |
31 USB_TRANSFER_LENGTH_SHORT, | |
32 }; | |
33 | |
34 typedef base::Callback< | |
35 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)> | |
36 UsbTransferCallback; | |
37 | |
38 // UsbDeviceHandle class provides basic I/O related functionalities. | |
39 class USB_SERVICE_EXPORT UsbDeviceHandle | |
40 : public base::RefCountedThreadSafe<UsbDeviceHandle> { | |
41 public: | |
42 enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; | |
43 enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; | |
44 | |
45 virtual scoped_refptr<UsbDevice> GetDevice() const = 0; | |
46 | |
47 // Notifies UsbDevice to drop the reference of this object; cancels all the | |
48 // flying transfers. | |
49 // It is possible that the object has no other reference after this call. So | |
50 // if it is called using a raw pointer, it could be invalidated. | |
51 // The platform device handle will be closed when UsbDeviceHandle destructs. | |
52 virtual void Close() = 0; | |
53 | |
54 // Device manipulation operations. These methods are blocking and must be | |
55 // called on FILE thread. | |
56 virtual bool ClaimInterface(const int interface_number) = 0; | |
57 virtual bool ReleaseInterface(const int interface_number) = 0; | |
58 virtual bool SetInterfaceAlternateSetting(const int interface_number, | |
59 const int alternate_setting) = 0; | |
60 virtual bool ResetDevice() = 0; | |
61 virtual bool GetManufacturer(base::string16* manufacturer) = 0; | |
62 virtual bool GetProduct(base::string16* product) = 0; | |
63 virtual bool GetSerial(base::string16* serial) = 0; | |
64 | |
65 // Async IO. Can be called on any thread. | |
66 virtual void ControlTransfer(const UsbEndpointDirection direction, | |
67 const TransferRequestType request_type, | |
68 const TransferRecipient recipient, | |
69 const uint8 request, | |
70 const uint16 value, | |
71 const uint16 index, | |
72 net::IOBuffer* buffer, | |
73 const size_t length, | |
74 const unsigned int timeout, | |
75 const UsbTransferCallback& callback) = 0; | |
76 | |
77 virtual void BulkTransfer(const UsbEndpointDirection direction, | |
78 const uint8 endpoint, | |
79 net::IOBuffer* buffer, | |
80 const size_t length, | |
81 const unsigned int timeout, | |
82 const UsbTransferCallback& callback) = 0; | |
83 | |
84 virtual void InterruptTransfer(const UsbEndpointDirection direction, | |
85 const uint8 endpoint, | |
86 net::IOBuffer* buffer, | |
87 const size_t length, | |
88 const unsigned int timeout, | |
89 const UsbTransferCallback& callback) = 0; | |
90 | |
91 virtual void IsochronousTransfer(const UsbEndpointDirection direction, | |
92 const uint8 endpoint, | |
93 net::IOBuffer* buffer, | |
94 const size_t length, | |
95 const unsigned int packets, | |
96 const unsigned int packet_length, | |
97 const unsigned int timeout, | |
98 const UsbTransferCallback& callback) = 0; | |
99 | |
100 protected: | |
101 friend class base::RefCountedThreadSafe<UsbDeviceHandle>; | |
102 | |
103 UsbDeviceHandle() {}; | |
104 | |
105 virtual ~UsbDeviceHandle() {}; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); | |
108 }; | |
109 | |
110 } // namespace usb_service | |
111 | |
112 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ | |
OLD | NEW |