Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / usb_service / usb_device_handle.h
blob0115e64d17c123e2dae4341cc0637dfa2e915e58
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.
5 #ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_
6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_
8 #include <map>
9 #include <vector>
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"
19 namespace usb_service {
21 class UsbDevice;
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,
34 typedef base::Callback<
35 void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)>
36 UsbTransferCallback;
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 };
45 virtual scoped_refptr<UsbDevice> GetDevice() const = 0;
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;
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;
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;
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;
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;
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;
100 protected:
101 friend class base::RefCountedThreadSafe<UsbDeviceHandle>;
103 UsbDeviceHandle() {};
105 virtual ~UsbDeviceHandle() {};
107 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle);
110 } // namespace usb_service
112 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_