| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/usb/usb_interface.h" | 5 #include "chrome/browser/usb/usb_interface.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/libusb/src/libusb/libusb.h" | 8 #include "third_party/libusb/src/libusb/libusb.h" |
| 9 | 9 |
| 10 UsbEndpointDescriptor::UsbEndpointDescriptor( | 10 UsbEndpointDescriptor::UsbEndpointDescriptor( |
| 11 scoped_refptr<const UsbConfigDescriptor> config, | 11 scoped_refptr<const UsbConfigDescriptor> config, |
| 12 PlatformUsbEndpointDescriptor descriptor) | 12 PlatformUsbEndpointDescriptor descriptor) |
| 13 : config_(config), descriptor_(descriptor) { | 13 : config_(config), descriptor_(descriptor) {} |
| 14 } | |
| 15 | 14 |
| 16 UsbEndpointDescriptor::~UsbEndpointDescriptor() {} | 15 UsbEndpointDescriptor::~UsbEndpointDescriptor() {} |
| 17 | 16 |
| 18 int UsbEndpointDescriptor::GetAddress() const { | 17 int UsbEndpointDescriptor::GetAddress() const { |
| 19 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; | 18 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; |
| 20 } | 19 } |
| 21 | 20 |
| 22 UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { | 21 UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { |
| 23 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { | 22 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { |
| 24 case LIBUSB_ENDPOINT_IN: | 23 case LIBUSB_ENDPOINT_IN: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 80 } |
| 82 } | 81 } |
| 83 | 82 |
| 84 int UsbEndpointDescriptor::GetPollingInterval() const { | 83 int UsbEndpointDescriptor::GetPollingInterval() const { |
| 85 return descriptor_->bInterval; | 84 return descriptor_->bInterval; |
| 86 } | 85 } |
| 87 | 86 |
| 88 UsbInterfaceDescriptor::UsbInterfaceDescriptor( | 87 UsbInterfaceDescriptor::UsbInterfaceDescriptor( |
| 89 scoped_refptr<const UsbConfigDescriptor> config, | 88 scoped_refptr<const UsbConfigDescriptor> config, |
| 90 PlatformUsbInterfaceDescriptor descriptor) | 89 PlatformUsbInterfaceDescriptor descriptor) |
| 91 : config_(config), descriptor_(descriptor) { | 90 : config_(config), descriptor_(descriptor) {} |
| 92 } | |
| 93 | 91 |
| 94 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {} | 92 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {} |
| 95 | 93 |
| 96 size_t UsbInterfaceDescriptor::GetNumEndpoints() const { | 94 size_t UsbInterfaceDescriptor::GetNumEndpoints() const { |
| 97 return descriptor_->bNumEndpoints; | 95 return descriptor_->bNumEndpoints; |
| 98 } | 96 } |
| 99 | 97 |
| 100 scoped_refptr<const UsbEndpointDescriptor> | 98 scoped_refptr<const UsbEndpointDescriptor> UsbInterfaceDescriptor::GetEndpoint( |
| 101 UsbInterfaceDescriptor::GetEndpoint(size_t index) const { | 99 size_t index) const { |
| 102 return make_scoped_refptr(new UsbEndpointDescriptor(config_, | 100 return make_scoped_refptr( |
| 103 &descriptor_->endpoint[index])); | 101 new UsbEndpointDescriptor(config_, &descriptor_->endpoint[index])); |
| 104 } | 102 } |
| 105 | 103 |
| 106 int UsbInterfaceDescriptor::GetInterfaceNumber() const { | 104 int UsbInterfaceDescriptor::GetInterfaceNumber() const { |
| 107 return descriptor_->bInterfaceNumber; | 105 return descriptor_->bInterfaceNumber; |
| 108 } | 106 } |
| 109 | 107 |
| 110 int UsbInterfaceDescriptor::GetAlternateSetting() const { | 108 int UsbInterfaceDescriptor::GetAlternateSetting() const { |
| 111 return descriptor_->bAlternateSetting; | 109 return descriptor_->bAlternateSetting; |
| 112 } | 110 } |
| 113 | 111 |
| 114 int UsbInterfaceDescriptor::GetInterfaceClass() const { | 112 int UsbInterfaceDescriptor::GetInterfaceClass() const { |
| 115 return descriptor_->bInterfaceClass; | 113 return descriptor_->bInterfaceClass; |
| 116 } | 114 } |
| 117 | 115 |
| 118 int UsbInterfaceDescriptor::GetInterfaceSubclass() const { | 116 int UsbInterfaceDescriptor::GetInterfaceSubclass() const { |
| 119 return descriptor_->bInterfaceSubClass; | 117 return descriptor_->bInterfaceSubClass; |
| 120 } | 118 } |
| 121 | 119 |
| 122 int UsbInterfaceDescriptor::GetInterfaceProtocol() const { | 120 int UsbInterfaceDescriptor::GetInterfaceProtocol() const { |
| 123 return descriptor_->bInterfaceProtocol; | 121 return descriptor_->bInterfaceProtocol; |
| 124 } | 122 } |
| 125 | 123 |
| 126 UsbInterface::UsbInterface(scoped_refptr<const UsbConfigDescriptor> config, | 124 UsbInterface::UsbInterface(scoped_refptr<const UsbConfigDescriptor> config, |
| 127 PlatformUsbInterface usbInterface) | 125 PlatformUsbInterface usbInterface) |
| 128 : config_(config), interface_(usbInterface) { | 126 : config_(config), interface_(usbInterface) {} |
| 129 } | |
| 130 | 127 |
| 131 UsbInterface::~UsbInterface() {} | 128 UsbInterface::~UsbInterface() {} |
| 132 | 129 |
| 133 size_t UsbInterface::GetNumAltSettings() const { | 130 size_t UsbInterface::GetNumAltSettings() const { |
| 134 return interface_->num_altsetting; | 131 return interface_->num_altsetting; |
| 135 } | 132 } |
| 136 | 133 |
| 137 scoped_refptr<const UsbInterfaceDescriptor> | 134 scoped_refptr<const UsbInterfaceDescriptor> UsbInterface::GetAltSetting( |
| 138 UsbInterface::GetAltSetting(size_t index) const { | 135 size_t index) const { |
| 139 return make_scoped_refptr(new UsbInterfaceDescriptor(config_, | 136 return make_scoped_refptr( |
| 140 &interface_->altsetting[index])); | 137 new UsbInterfaceDescriptor(config_, &interface_->altsetting[index])); |
| 141 } | 138 } |
| 142 | 139 |
| 143 UsbConfigDescriptor::UsbConfigDescriptor() | 140 UsbConfigDescriptor::UsbConfigDescriptor() : config_(NULL) {} |
| 144 : config_(NULL) { | |
| 145 } | |
| 146 | 141 |
| 147 UsbConfigDescriptor::~UsbConfigDescriptor() { | 142 UsbConfigDescriptor::~UsbConfigDescriptor() { |
| 148 if (config_ != NULL) { | 143 if (config_ != NULL) { |
| 149 libusb_free_config_descriptor(config_); | 144 libusb_free_config_descriptor(config_); |
| 150 config_ = NULL; | 145 config_ = NULL; |
| 151 } | 146 } |
| 152 } | 147 } |
| 153 | 148 |
| 154 void UsbConfigDescriptor::Reset(PlatformUsbConfigDescriptor config) { | 149 void UsbConfigDescriptor::Reset(PlatformUsbConfigDescriptor config) { |
| 155 config_ = config; | 150 config_ = config; |
| 156 } | 151 } |
| 157 | 152 |
| 158 size_t UsbConfigDescriptor::GetNumInterfaces() const { | 153 size_t UsbConfigDescriptor::GetNumInterfaces() const { |
| 159 return config_->bNumInterfaces; | 154 return config_->bNumInterfaces; |
| 160 } | 155 } |
| 161 | 156 |
| 162 scoped_refptr<const UsbInterface> | 157 scoped_refptr<const UsbInterface> UsbConfigDescriptor::GetInterface( |
| 163 UsbConfigDescriptor::GetInterface(size_t index) const { | 158 size_t index) const { |
| 164 return make_scoped_refptr(new UsbInterface(make_scoped_refptr(this), | 159 return make_scoped_refptr( |
| 165 &config_->interface[index])); | 160 new UsbInterface(make_scoped_refptr(this), &config_->interface[index])); |
| 166 } | 161 } |
| OLD | NEW |