Index: components/usb_service/usb_device_handle_impl.h |
diff --git a/components/usb_service/usb_device_handle.h b/components/usb_service/usb_device_handle_impl.h |
similarity index 61% |
copy from components/usb_service/usb_device_handle.h |
copy to components/usb_service/usb_device_handle_impl.h |
index 2b03a8a93a7ad66501780d6cc13dadbe407a4eae..0af9f3a50536cd881b115fc3d543d921939b10af 100644 |
--- a/components/usb_service/usb_device_handle.h |
+++ b/components/usb_service/usb_device_handle_impl.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ |
-#define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ |
+#ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_ |
+#define COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_ |
#include <map> |
#include <vector> |
@@ -12,8 +12,8 @@ |
#include "base/memory/ref_counted.h" |
#include "base/strings/string16.h" |
#include "base/threading/thread_checker.h" |
+#include "components/usb_service/usb_device_handle.h" |
#include "components/usb_service/usb_interface.h" |
-#include "components/usb_service/usb_service_export.h" |
#include "net/base/io_buffer.h" |
struct libusb_device_handle; |
@@ -28,54 +28,24 @@ namespace usb_service { |
class UsbContext; |
class UsbConfigDescriptor; |
-class UsbDevice; |
+class UsbDeviceImpl; |
typedef libusb_device_handle* PlatformUsbDeviceHandle; |
typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor; |
typedef libusb_transfer* PlatformUsbTransferHandle; |
-enum UsbTransferStatus { |
- USB_TRANSFER_COMPLETED = 0, |
- USB_TRANSFER_ERROR, |
- USB_TRANSFER_TIMEOUT, |
- USB_TRANSFER_CANCELLED, |
- USB_TRANSFER_STALLED, |
- USB_TRANSFER_DISCONNECT, |
- USB_TRANSFER_OVERFLOW, |
- USB_TRANSFER_LENGTH_SHORT, |
-}; |
- |
-typedef base::Callback< |
- void(UsbTransferStatus, scoped_refptr<net::IOBuffer>, size_t)> |
- UsbTransferCallback; |
- |
// UsbDeviceHandle class provides basic I/O related functionalities. |
-class USB_SERVICE_EXPORT UsbDeviceHandle |
- : public base::RefCountedThreadSafe<UsbDeviceHandle> { |
+class UsbDeviceHandleImpl : public UsbDeviceHandle { |
public: |
- enum TransferRequestType { STANDARD, CLASS, VENDOR, RESERVED }; |
- enum TransferRecipient { DEVICE, INTERFACE, ENDPOINT, OTHER }; |
- |
- scoped_refptr<UsbDevice> device() const; |
- PlatformUsbDeviceHandle handle() const { return handle_; } |
- |
- // Notifies UsbDevice to drop the reference of this object; cancels all the |
- // flying transfers. |
- // It is possible that the object has no other reference after this call. So |
- // if it is called using a raw pointer, it could be invalidated. |
- // The platform device handle will be closed when UsbDeviceHandle destructs. |
- virtual void Close(); |
- |
- // Device manipulation operations. These methods are blocking and must be |
- // called on FILE thread. |
- virtual bool ClaimInterface(const int interface_number); |
- virtual bool ReleaseInterface(const int interface_number); |
- virtual bool SetInterfaceAlternateSetting(const int interface_number, |
- const int alternate_setting); |
- virtual bool ResetDevice(); |
- virtual bool GetSerial(base::string16* serial); |
- |
- // Async IO. Can be called on any thread. |
+ virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE; |
+ virtual void Close() OVERRIDE; |
+ virtual bool ClaimInterface(const int interface_number) OVERRIDE; |
+ virtual bool ReleaseInterface(const int interface_number) OVERRIDE; |
+ virtual bool SetInterfaceAlternateSetting( |
+ const int interface_number, |
+ const int alternate_setting) OVERRIDE; |
+ virtual bool ResetDevice() OVERRIDE; |
+ virtual bool GetSerial(base::string16* serial) OVERRIDE; |
virtual void ControlTransfer(const UsbEndpointDirection direction, |
const TransferRequestType request_type, |
const TransferRecipient recipient, |
@@ -85,46 +55,44 @@ class USB_SERVICE_EXPORT UsbDeviceHandle |
net::IOBuffer* buffer, |
const size_t length, |
const unsigned int timeout, |
- const UsbTransferCallback& callback); |
+ const UsbTransferCallback& callback) OVERRIDE; |
virtual void BulkTransfer(const UsbEndpointDirection direction, |
const uint8 endpoint, |
net::IOBuffer* buffer, |
const size_t length, |
const unsigned int timeout, |
- const UsbTransferCallback& callback); |
+ const UsbTransferCallback& callback) OVERRIDE; |
virtual void InterruptTransfer(const UsbEndpointDirection direction, |
const uint8 endpoint, |
net::IOBuffer* buffer, |
const size_t length, |
const unsigned int timeout, |
- const UsbTransferCallback& callback); |
+ const UsbTransferCallback& callback) OVERRIDE; |
+ |
+ virtual void IsochronousTransfer( |
+ const UsbEndpointDirection direction, |
+ const uint8 endpoint, |
+ net::IOBuffer* buffer, |
+ const size_t length, |
+ const unsigned int packets, |
+ const unsigned int packet_length, |
+ const unsigned int timeout, |
+ const UsbTransferCallback& callback) OVERRIDE; |
- virtual void IsochronousTransfer(const UsbEndpointDirection direction, |
- const uint8 endpoint, |
- net::IOBuffer* buffer, |
- const size_t length, |
- const unsigned int packets, |
- const unsigned int packet_length, |
- const unsigned int timeout, |
- const UsbTransferCallback& callback); |
+ PlatformUsbDeviceHandle handle() const { return handle_; } |
protected: |
- friend class base::RefCountedThreadSafe<UsbDeviceHandle>; |
friend class UsbDeviceImpl; |
// This constructor is called by UsbDevice. |
- UsbDeviceHandle(scoped_refptr<UsbContext> context, |
- UsbDevice* device, |
- PlatformUsbDeviceHandle handle, |
- scoped_refptr<UsbConfigDescriptor> interfaces); |
+ UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, |
+ UsbDeviceImpl* device, |
+ PlatformUsbDeviceHandle handle, |
+ scoped_refptr<UsbConfigDescriptor> interfaces); |
- // This constructor variant is for use in testing only. |
- UsbDeviceHandle(); |
- virtual ~UsbDeviceHandle(); |
- |
- UsbDevice* device_; |
+ virtual ~UsbDeviceHandleImpl(); |
private: |
friend void HandleTransferCompletion(PlatformUsbTransferHandle handle); |
@@ -158,6 +126,8 @@ class USB_SERVICE_EXPORT UsbDeviceHandle |
// Informs the object to drop internal references. |
void InternalClose(); |
+ UsbDeviceImpl* device_; |
+ |
PlatformUsbDeviceHandle handle_; |
scoped_refptr<UsbConfigDescriptor> interfaces_; |
@@ -178,9 +148,9 @@ class USB_SERVICE_EXPORT UsbDeviceHandle |
base::ThreadChecker thread_checker_; |
- DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandle); |
+ DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl); |
}; |
} // namespace usb_service |
-#endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_H_ |
+#endif // COMPONENTS_USB_SERVICE_USB_DEVICE_HANDLE_IMPL_H_ |