Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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. |
| 4 | |
| 5 | #include "mist/usb_interface.h" |
| 6 | |
| 7 | #include <libusb.h> |
| 8 | |
| 9 | #include <base/logging.h> |
Ben Chan | dcc0c7a | 2014-02-05 18:03:39 -0800 | [diff] [blame] | 10 | #include <base/strings/stringprintf.h> |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 11 | |
| 12 | #include "mist/usb_device.h" |
| 13 | #include "mist/usb_interface_descriptor.h" |
| 14 | |
| 15 | using base::StringPrintf; |
| 16 | |
| 17 | namespace mist { |
| 18 | |
| 19 | UsbInterface::UsbInterface(const base::WeakPtr<UsbDevice>& device, |
| 20 | const libusb_interface* interface) |
| 21 | : device_(device), |
| 22 | interface_(interface) { |
| 23 | CHECK(interface_); |
| 24 | } |
| 25 | |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 26 | int UsbInterface::GetNumAlternateSettings() const { |
| 27 | return interface_->num_altsetting; |
| 28 | } |
| 29 | |
Ben Chan | d31d6c1 | 2013-08-07 21:28:33 -0700 | [diff] [blame] | 30 | UsbInterfaceDescriptor* UsbInterface::GetAlternateSetting( |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 31 | int index) const { |
| 32 | if (index < 0 || index >= GetNumAlternateSettings()) { |
| 33 | LOG(ERROR) << StringPrintf("Invalid alternate setting index %d. " |
| 34 | "Must be non-negative and less than %d.", |
| 35 | index, GetNumAlternateSettings()); |
Ben Chan | 61ac5ba | 2014-08-29 18:06:43 -0700 | [diff] [blame] | 36 | return nullptr; |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Ben Chan | d31d6c1 | 2013-08-07 21:28:33 -0700 | [diff] [blame] | 39 | return new UsbInterfaceDescriptor(device_, &interface_->altsetting[index]); |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | } // namespace mist |