blob: ea8d07fcfc3d4373c43b06f365512a87a4644788 [file] [log] [blame]
Ben Chanf4930e52013-05-28 13:24:54 -07001// 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 Chandcc0c7a2014-02-05 18:03:39 -080010#include <base/strings/stringprintf.h>
Ben Chanf4930e52013-05-28 13:24:54 -070011
12#include "mist/usb_device.h"
13#include "mist/usb_interface_descriptor.h"
14
15using base::StringPrintf;
16
17namespace mist {
18
19UsbInterface::UsbInterface(const base::WeakPtr<UsbDevice>& device,
20 const libusb_interface* interface)
Ben Chanc440db52017-09-26 06:30:47 -070021 : device_(device), interface_(interface) {
Ben Chanf4930e52013-05-28 13:24:54 -070022 CHECK(interface_);
23}
24
Ben Chanf4930e52013-05-28 13:24:54 -070025int UsbInterface::GetNumAlternateSettings() const {
26 return interface_->num_altsetting;
27}
28
Ben Chanc440db52017-09-26 06:30:47 -070029UsbInterfaceDescriptor* UsbInterface::GetAlternateSetting(int index) const {
Ben Chanf4930e52013-05-28 13:24:54 -070030 if (index < 0 || index >= GetNumAlternateSettings()) {
Ben Chanc440db52017-09-26 06:30:47 -070031 LOG(ERROR) << StringPrintf(
32 "Invalid alternate setting index %d. "
33 "Must be non-negative and less than %d.",
34 index, GetNumAlternateSettings());
Ben Chan61ac5ba2014-08-29 18:06:43 -070035 return nullptr;
Ben Chanf4930e52013-05-28 13:24:54 -070036 }
37
Ben Chand31d6c12013-08-07 21:28:33 -070038 return new UsbInterfaceDescriptor(device_, &interface_->altsetting[index]);
Ben Chanf4930e52013-05-28 13:24:54 -070039}
40
41} // namespace mist