diff options
author | zvorygin@chromium.org <zvorygin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 11:35:35 +0000 |
---|---|---|
committer | zvorygin@chromium.org <zvorygin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-12 11:35:35 +0000 |
commit | a8eaa18939a710b11d5bfda37ac18a0b98d76837 (patch) | |
tree | 2d532f9bc9018b810dc7387b6b79a0a8bc3d6ecd /components | |
parent | 7a4c78e0c7e8cecb8884d05098c08d4a48b058f6 (diff) | |
download | chromium_src-a8eaa18939a710b11d5bfda37ac18a0b98d76837.zip chromium_src-a8eaa18939a710b11d5bfda37ac18a0b98d76837.tar.gz chromium_src-a8eaa18939a710b11d5bfda37ac18a0b98d76837.tar.bz2 |
Extracted UsbConfigDescriptor, UsbInterfaceDescriptor and helper classes
as interfaces.
BUG=367094
R=rockot@chromium.org
Review URL: https://codereview.chromium.org/270323003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/usb_service.gypi | 3 | ||||
-rw-r--r-- | components/usb_service/usb_device_impl.cc | 3 | ||||
-rw-r--r-- | components/usb_service/usb_device_impl.h | 2 | ||||
-rw-r--r-- | components/usb_service/usb_interface.h | 101 | ||||
-rw-r--r-- | components/usb_service/usb_interface_impl.cc (renamed from components/usb_service/usb_interface.cc) | 78 | ||||
-rw-r--r-- | components/usb_service/usb_interface_impl.h | 118 |
6 files changed, 192 insertions, 113 deletions
diff --git a/components/usb_service.gypi b/components/usb_service.gypi index 83de742..5f58d61 100644 --- a/components/usb_service.gypi +++ b/components/usb_service.gypi @@ -27,8 +27,9 @@ 'usb_service/usb_device.h', 'usb_service/usb_device_handle.cc', 'usb_service/usb_device_handle.h', - 'usb_service/usb_interface.cc', 'usb_service/usb_interface.h', + 'usb_service/usb_interface_impl.cc', + 'usb_service/usb_interface_impl.h', 'usb_service/usb_service.h', 'usb_service/usb_service_impl.cc', ], diff --git a/components/usb_service/usb_device_impl.cc b/components/usb_service/usb_device_impl.cc index 17c8337..f1d69a3 100644 --- a/components/usb_service/usb_device_impl.cc +++ b/components/usb_service/usb_device_impl.cc @@ -9,6 +9,7 @@ #include "base/stl_util.h" #include "components/usb_service/usb_context.h" #include "components/usb_service/usb_device_handle.h" +#include "components/usb_service/usb_interface_impl.h" #include "content/public/browser/browser_thread.h" #include "third_party/libusb/src/libusb/libusb.h" @@ -126,7 +127,7 @@ scoped_refptr<UsbConfigDescriptor> UsbDeviceImpl::ListInterfaces() { const int list_result = libusb_get_active_config_descriptor(platform_device_, &platform_config); if (list_result == 0) - return new UsbConfigDescriptor(platform_config); + return new UsbConfigDescriptorImpl(platform_config); return NULL; } diff --git a/components/usb_service/usb_device_impl.h b/components/usb_service/usb_device_impl.h index eafbe15..5a7cc24 100644 --- a/components/usb_service/usb_device_impl.h +++ b/components/usb_service/usb_device_impl.h @@ -13,6 +13,7 @@ #include "components/usb_service/usb_device.h" struct libusb_device; +struct libusb_config_descriptor; namespace usb_service { @@ -20,6 +21,7 @@ class UsbDeviceHandle; class UsbContext; typedef libusb_device* PlatformUsbDevice; +typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; class UsbDeviceImpl : public UsbDevice { public: diff --git a/components/usb_service/usb_interface.h b/components/usb_service/usb_interface.h index dc5ad85..7ca3197 100644 --- a/components/usb_service/usb_interface.h +++ b/components/usb_service/usb_interface.h @@ -8,18 +8,8 @@ #include "base/memory/ref_counted.h" #include "components/usb_service/usb_service_export.h" -struct libusb_config_descriptor; -struct libusb_endpoint_descriptor; -struct libusb_interface; -struct libusb_interface_descriptor; - namespace usb_service { -typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; -typedef const libusb_endpoint_descriptor* PlatformUsbEndpointDescriptor; -typedef const libusb_interface* PlatformUsbInterface; -typedef const libusb_interface_descriptor* PlatformUsbInterfaceDescriptor; - enum UsbTransferType { USB_TRANSFER_CONTROL = 0, USB_TRANSFER_ISOCHRONOUS, @@ -45,32 +35,22 @@ enum UsbUsageType { USB_USAGE_EXPLICIT_FEEDBACK }; -class UsbDevice; -class UsbConfigDescriptor; -class UsbInterfaceDescriptor; -class UsbInterfaceAltSettingDescriptor; - class USB_SERVICE_EXPORT UsbEndpointDescriptor : public base::RefCounted<const UsbEndpointDescriptor> { public: - int GetAddress() const; - UsbEndpointDirection GetDirection() const; - int GetMaximumPacketSize() const; - UsbSynchronizationType GetSynchronizationType() const; - UsbTransferType GetTransferType() const; - UsbUsageType GetUsageType() const; - int GetPollingInterval() const; - - private: - friend class base::RefCounted<const UsbEndpointDescriptor>; - friend class UsbInterfaceAltSettingDescriptor; + virtual int GetAddress() const = 0; + virtual UsbEndpointDirection GetDirection() const = 0; + virtual int GetMaximumPacketSize() const = 0; + virtual UsbSynchronizationType GetSynchronizationType() const = 0; + virtual UsbTransferType GetTransferType() const = 0; + virtual UsbUsageType GetUsageType() const = 0; + virtual int GetPollingInterval() const = 0; - UsbEndpointDescriptor(scoped_refptr<const UsbConfigDescriptor> config, - PlatformUsbEndpointDescriptor descriptor); - ~UsbEndpointDescriptor(); + protected: + friend class base::RefCounted<const UsbEndpointDescriptor>; - scoped_refptr<const UsbConfigDescriptor> config_; - PlatformUsbEndpointDescriptor descriptor_; + UsbEndpointDescriptor() {}; + virtual ~UsbEndpointDescriptor() {}; DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptor); }; @@ -78,26 +58,21 @@ class USB_SERVICE_EXPORT UsbEndpointDescriptor class USB_SERVICE_EXPORT UsbInterfaceAltSettingDescriptor : public base::RefCounted<const UsbInterfaceAltSettingDescriptor> { public: - size_t GetNumEndpoints() const; - scoped_refptr<const UsbEndpointDescriptor> GetEndpoint(size_t index) const; + virtual size_t GetNumEndpoints() const = 0; + virtual scoped_refptr<const UsbEndpointDescriptor> GetEndpoint( + size_t index) const = 0; - int GetInterfaceNumber() const; - int GetAlternateSetting() const; - int GetInterfaceClass() const; - int GetInterfaceSubclass() const; - int GetInterfaceProtocol() const; + virtual int GetInterfaceNumber() const = 0; + virtual int GetAlternateSetting() const = 0; + virtual int GetInterfaceClass() const = 0; + virtual int GetInterfaceSubclass() const = 0; + virtual int GetInterfaceProtocol() const = 0; - private: + protected: friend class base::RefCounted<const UsbInterfaceAltSettingDescriptor>; - friend class UsbInterfaceDescriptor; - - UsbInterfaceAltSettingDescriptor( - scoped_refptr<const UsbConfigDescriptor> config, - PlatformUsbInterfaceDescriptor descriptor); - ~UsbInterfaceAltSettingDescriptor(); - scoped_refptr<const UsbConfigDescriptor> config_; - PlatformUsbInterfaceDescriptor descriptor_; + UsbInterfaceAltSettingDescriptor() {}; + virtual ~UsbInterfaceAltSettingDescriptor() {}; DISALLOW_COPY_AND_ASSIGN(UsbInterfaceAltSettingDescriptor); }; @@ -105,20 +80,15 @@ class USB_SERVICE_EXPORT UsbInterfaceAltSettingDescriptor class USB_SERVICE_EXPORT UsbInterfaceDescriptor : public base::RefCounted<const UsbInterfaceDescriptor> { public: - size_t GetNumAltSettings() const; - scoped_refptr<const UsbInterfaceAltSettingDescriptor> GetAltSetting( - size_t index) const; + virtual size_t GetNumAltSettings() const = 0; + virtual scoped_refptr<const UsbInterfaceAltSettingDescriptor> GetAltSetting( + size_t index) const = 0; - private: + protected: friend class base::RefCounted<const UsbInterfaceDescriptor>; - friend class UsbConfigDescriptor; - UsbInterfaceDescriptor(scoped_refptr<const UsbConfigDescriptor> config, - PlatformUsbInterface usbInterface); - ~UsbInterfaceDescriptor(); - - scoped_refptr<const UsbConfigDescriptor> config_; - PlatformUsbInterface interface_; + UsbInterfaceDescriptor() {}; + virtual ~UsbInterfaceDescriptor() {}; DISALLOW_COPY_AND_ASSIGN(UsbInterfaceDescriptor); }; @@ -126,22 +96,15 @@ class USB_SERVICE_EXPORT UsbInterfaceDescriptor class USB_SERVICE_EXPORT UsbConfigDescriptor : public base::RefCounted<UsbConfigDescriptor> { public: - virtual size_t GetNumInterfaces() const; + virtual size_t GetNumInterfaces() const = 0; virtual scoped_refptr<const UsbInterfaceDescriptor> GetInterface( - size_t index) const; + size_t index) const = 0; protected: - // Constructor called in test only - UsbConfigDescriptor(); - virtual ~UsbConfigDescriptor(); - - private: friend class base::RefCounted<UsbConfigDescriptor>; - friend class UsbDeviceImpl; - - explicit UsbConfigDescriptor(PlatformUsbConfigDescriptor config); - PlatformUsbConfigDescriptor config_; + UsbConfigDescriptor() {}; + virtual ~UsbConfigDescriptor() {}; DISALLOW_COPY_AND_ASSIGN(UsbConfigDescriptor); }; diff --git a/components/usb_service/usb_interface.cc b/components/usb_service/usb_interface_impl.cc index 3194440..1eb1b2f 100644 --- a/components/usb_service/usb_interface.cc +++ b/components/usb_service/usb_interface_impl.cc @@ -2,27 +2,27 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/usb_service/usb_interface.h" +#include "components/usb_service/usb_interface_impl.h" #include "base/logging.h" #include "third_party/libusb/src/libusb/libusb.h" namespace usb_service { -UsbEndpointDescriptor::UsbEndpointDescriptor( +UsbEndpointDescriptorImpl::UsbEndpointDescriptorImpl( scoped_refptr<const UsbConfigDescriptor> config, PlatformUsbEndpointDescriptor descriptor) : config_(config), descriptor_(descriptor) { } -UsbEndpointDescriptor::~UsbEndpointDescriptor() { +UsbEndpointDescriptorImpl::~UsbEndpointDescriptorImpl() { } -int UsbEndpointDescriptor::GetAddress() const { +int UsbEndpointDescriptorImpl::GetAddress() const { return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; } -UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { +UsbEndpointDirection UsbEndpointDescriptorImpl::GetDirection() const { switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { case LIBUSB_ENDPOINT_IN: return USB_DIRECTION_INBOUND; @@ -34,11 +34,12 @@ UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { } } -int UsbEndpointDescriptor::GetMaximumPacketSize() const { +int UsbEndpointDescriptorImpl::GetMaximumPacketSize() const { return descriptor_->wMaxPacketSize; } -UsbSynchronizationType UsbEndpointDescriptor::GetSynchronizationType() const { +UsbSynchronizationType + UsbEndpointDescriptorImpl::GetSynchronizationType() const { switch (descriptor_->bmAttributes & LIBUSB_ISO_SYNC_TYPE_MASK) { case LIBUSB_ISO_SYNC_TYPE_NONE: return USB_SYNCHRONIZATION_NONE; @@ -54,7 +55,7 @@ UsbSynchronizationType UsbEndpointDescriptor::GetSynchronizationType() const { } } -UsbTransferType UsbEndpointDescriptor::GetTransferType() const { +UsbTransferType UsbEndpointDescriptorImpl::GetTransferType() const { switch (descriptor_->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) { case LIBUSB_TRANSFER_TYPE_CONTROL: return USB_TRANSFER_CONTROL; @@ -70,7 +71,7 @@ UsbTransferType UsbEndpointDescriptor::GetTransferType() const { } } -UsbUsageType UsbEndpointDescriptor::GetUsageType() const { +UsbUsageType UsbEndpointDescriptorImpl::GetUsageType() const { switch (descriptor_->bmAttributes & LIBUSB_ISO_USAGE_TYPE_MASK) { case LIBUSB_ISO_USAGE_TYPE_DATA: return USB_USAGE_DATA; @@ -84,91 +85,84 @@ UsbUsageType UsbEndpointDescriptor::GetUsageType() const { } } -int UsbEndpointDescriptor::GetPollingInterval() const { +int UsbEndpointDescriptorImpl::GetPollingInterval() const { return descriptor_->bInterval; } -UsbInterfaceAltSettingDescriptor::UsbInterfaceAltSettingDescriptor( +UsbInterfaceAltSettingDescriptorImpl::UsbInterfaceAltSettingDescriptorImpl( scoped_refptr<const UsbConfigDescriptor> config, PlatformUsbInterfaceDescriptor descriptor) : config_(config), descriptor_(descriptor) { } -UsbInterfaceAltSettingDescriptor::~UsbInterfaceAltSettingDescriptor() { +UsbInterfaceAltSettingDescriptorImpl::~UsbInterfaceAltSettingDescriptorImpl() { } -size_t UsbInterfaceAltSettingDescriptor::GetNumEndpoints() const { +size_t UsbInterfaceAltSettingDescriptorImpl::GetNumEndpoints() const { return descriptor_->bNumEndpoints; } scoped_refptr<const UsbEndpointDescriptor> -UsbInterfaceAltSettingDescriptor::GetEndpoint(size_t index) const { - return new UsbEndpointDescriptor(config_, &descriptor_->endpoint[index]); +UsbInterfaceAltSettingDescriptorImpl::GetEndpoint(size_t index) const { + return new UsbEndpointDescriptorImpl(config_, &descriptor_->endpoint[index]); } -int UsbInterfaceAltSettingDescriptor::GetInterfaceNumber() const { +int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceNumber() const { return descriptor_->bInterfaceNumber; } -int UsbInterfaceAltSettingDescriptor::GetAlternateSetting() const { +int UsbInterfaceAltSettingDescriptorImpl::GetAlternateSetting() const { return descriptor_->bAlternateSetting; } -int UsbInterfaceAltSettingDescriptor::GetInterfaceClass() const { +int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceClass() const { return descriptor_->bInterfaceClass; } -int UsbInterfaceAltSettingDescriptor::GetInterfaceSubclass() const { +int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceSubclass() const { return descriptor_->bInterfaceSubClass; } -int UsbInterfaceAltSettingDescriptor::GetInterfaceProtocol() const { +int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceProtocol() const { return descriptor_->bInterfaceProtocol; } -UsbInterfaceDescriptor::UsbInterfaceDescriptor( +UsbInterfaceDescriptorImpl::UsbInterfaceDescriptorImpl( scoped_refptr<const UsbConfigDescriptor> config, PlatformUsbInterface usbInterface) : config_(config), interface_(usbInterface) { } -UsbInterfaceDescriptor::~UsbInterfaceDescriptor() { +UsbInterfaceDescriptorImpl::~UsbInterfaceDescriptorImpl() { } -size_t UsbInterfaceDescriptor::GetNumAltSettings() const { +size_t UsbInterfaceDescriptorImpl::GetNumAltSettings() const { return interface_->num_altsetting; } scoped_refptr<const UsbInterfaceAltSettingDescriptor> -UsbInterfaceDescriptor::GetAltSetting(size_t index) const { - return new UsbInterfaceAltSettingDescriptor(config_, - &interface_->altsetting[index]); +UsbInterfaceDescriptorImpl::GetAltSetting(size_t index) const { + return new UsbInterfaceAltSettingDescriptorImpl( + config_, &interface_->altsetting[index]); } -UsbConfigDescriptor::UsbConfigDescriptor(PlatformUsbConfigDescriptor config) +UsbConfigDescriptorImpl::UsbConfigDescriptorImpl( + PlatformUsbConfigDescriptor config) : config_(config) { + DCHECK(config); } -// TODO(zvorygin): Used for tests only. Should be removed when -// all interfaces are extracted properly. -UsbConfigDescriptor::UsbConfigDescriptor() { - config_ = NULL; +UsbConfigDescriptorImpl::~UsbConfigDescriptorImpl() { + libusb_free_config_descriptor(config_); } -UsbConfigDescriptor::~UsbConfigDescriptor() { - if (config_ != NULL) { - libusb_free_config_descriptor(config_); - config_ = NULL; - } -} - -size_t UsbConfigDescriptor::GetNumInterfaces() const { +size_t UsbConfigDescriptorImpl::GetNumInterfaces() const { return config_->bNumInterfaces; } -scoped_refptr<const UsbInterfaceDescriptor> UsbConfigDescriptor::GetInterface( - size_t index) const { - return new UsbInterfaceDescriptor(this, &config_->interface[index]); +scoped_refptr<const UsbInterfaceDescriptor> + UsbConfigDescriptorImpl::GetInterface(size_t index) const { + return new UsbInterfaceDescriptorImpl(this, &config_->interface[index]); } } // namespace usb_service diff --git a/components/usb_service/usb_interface_impl.h b/components/usb_service/usb_interface_impl.h new file mode 100644 index 0000000..defde69 --- /dev/null +++ b/components/usb_service/usb_interface_impl.h @@ -0,0 +1,118 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// 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_INTERFACE_IMPL_H_ +#define COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_ + +#include "base/memory/ref_counted.h" +#include "components/usb_service/usb_interface.h" +#include "components/usb_service/usb_service_export.h" + +struct libusb_config_descriptor; +struct libusb_endpoint_descriptor; +struct libusb_interface; +struct libusb_interface_descriptor; + +namespace usb_service { + +typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; +typedef const libusb_endpoint_descriptor* PlatformUsbEndpointDescriptor; +typedef const libusb_interface* PlatformUsbInterface; +typedef const libusb_interface_descriptor* PlatformUsbInterfaceDescriptor; + +class UsbConfigDescriptorImpl; +class UsbInterfaceAltSettingDescriptor; + +class UsbEndpointDescriptorImpl : public UsbEndpointDescriptor { + public: + virtual int GetAddress() const OVERRIDE; + virtual UsbEndpointDirection GetDirection() const OVERRIDE; + virtual int GetMaximumPacketSize() const OVERRIDE; + virtual UsbSynchronizationType GetSynchronizationType() const OVERRIDE; + virtual UsbTransferType GetTransferType() const OVERRIDE; + virtual UsbUsageType GetUsageType() const OVERRIDE; + virtual int GetPollingInterval() const OVERRIDE; + + private: + friend class base::RefCounted<const UsbEndpointDescriptorImpl>; + friend class UsbInterfaceAltSettingDescriptorImpl; + + UsbEndpointDescriptorImpl(scoped_refptr<const UsbConfigDescriptor> config, + PlatformUsbEndpointDescriptor descriptor); + virtual ~UsbEndpointDescriptorImpl(); + + scoped_refptr<const UsbConfigDescriptor> config_; + PlatformUsbEndpointDescriptor descriptor_; + + DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptorImpl); +}; + +class UsbInterfaceAltSettingDescriptorImpl + : public UsbInterfaceAltSettingDescriptor { + public: + virtual size_t GetNumEndpoints() const OVERRIDE; + virtual scoped_refptr<const UsbEndpointDescriptor> GetEndpoint( + size_t index) const OVERRIDE; + + virtual int GetInterfaceNumber() const OVERRIDE; + virtual int GetAlternateSetting() const OVERRIDE; + virtual int GetInterfaceClass() const OVERRIDE; + virtual int GetInterfaceSubclass() const OVERRIDE; + virtual int GetInterfaceProtocol() const OVERRIDE; + + private: + friend class UsbInterfaceDescriptorImpl; + + UsbInterfaceAltSettingDescriptorImpl( + scoped_refptr<const UsbConfigDescriptor> config, + PlatformUsbInterfaceDescriptor descriptor); + virtual ~UsbInterfaceAltSettingDescriptorImpl(); + + scoped_refptr<const UsbConfigDescriptor> config_; + PlatformUsbInterfaceDescriptor descriptor_; + + DISALLOW_COPY_AND_ASSIGN(UsbInterfaceAltSettingDescriptorImpl); +}; + +class UsbInterfaceDescriptorImpl : public UsbInterfaceDescriptor { + public: + virtual size_t GetNumAltSettings() const OVERRIDE; + virtual scoped_refptr<const UsbInterfaceAltSettingDescriptor> GetAltSetting( + size_t index) const OVERRIDE; + + private: + friend class base::RefCounted<const UsbInterfaceDescriptorImpl>; + friend class UsbConfigDescriptorImpl; + + UsbInterfaceDescriptorImpl(scoped_refptr<const UsbConfigDescriptor> config, + PlatformUsbInterface usbInterface); + virtual ~UsbInterfaceDescriptorImpl(); + + scoped_refptr<const UsbConfigDescriptor> config_; + PlatformUsbInterface interface_; + + DISALLOW_COPY_AND_ASSIGN(UsbInterfaceDescriptorImpl); +}; + +class UsbConfigDescriptorImpl : public UsbConfigDescriptor { + public: + virtual size_t GetNumInterfaces() const OVERRIDE; + virtual scoped_refptr<const UsbInterfaceDescriptor> GetInterface( + size_t index) const OVERRIDE; + + private: + friend class base::RefCounted<UsbConfigDescriptor>; + friend class UsbDeviceImpl; + + explicit UsbConfigDescriptorImpl(PlatformUsbConfigDescriptor config); + virtual ~UsbConfigDescriptorImpl(); + + PlatformUsbConfigDescriptor config_; + + DISALLOW_COPY_AND_ASSIGN(UsbConfigDescriptorImpl); +}; + +} // namespace usb_service; + +#endif // COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_ |