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_
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
{
23 enum UsbTransferStatus
{
24 USB_TRANSFER_COMPLETED
= 0,
27 USB_TRANSFER_CANCELLED
,
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)>
38 // UsbDeviceHandle class provides basic I/O related functionalities.
39 class USB_SERVICE_EXPORT UsbDeviceHandle
40 : public base::RefCountedThreadSafe
<UsbDeviceHandle
> {
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
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
,
72 net::IOBuffer
* buffer
,
74 const unsigned int timeout
,
75 const UsbTransferCallback
& callback
) = 0;
77 virtual void BulkTransfer(const UsbEndpointDirection direction
,
79 net::IOBuffer
* buffer
,
81 const unsigned int timeout
,
82 const UsbTransferCallback
& callback
) = 0;
84 virtual void InterruptTransfer(const UsbEndpointDirection direction
,
86 net::IOBuffer
* buffer
,
88 const unsigned int timeout
,
89 const UsbTransferCallback
& callback
) = 0;
91 virtual void IsochronousTransfer(const UsbEndpointDirection direction
,
93 net::IOBuffer
* buffer
,
95 const unsigned int packets
,
96 const unsigned int packet_length
,
97 const unsigned int timeout
,
98 const UsbTransferCallback
& callback
) = 0;
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_