blob: 26f43e58900453245645daa9a211a668d9bbe4a4 [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>
10#include <base/stringprintf.h>
11
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)
21 : device_(device),
22 interface_(interface) {
23 CHECK(interface_);
24}
25
26UsbInterface::~UsbInterface() {}
27
28int UsbInterface::GetNumAlternateSettings() const {
29 return interface_->num_altsetting;
30}
31
32scoped_ptr<UsbInterfaceDescriptor> UsbInterface::GetAlternateSetting(
33 int index) const {
34 if (index < 0 || index >= GetNumAlternateSettings()) {
35 LOG(ERROR) << StringPrintf("Invalid alternate setting index %d. "
36 "Must be non-negative and less than %d.",
37 index, GetNumAlternateSettings());
38 return scoped_ptr<UsbInterfaceDescriptor>();
39 }
40
41 return scoped_ptr<UsbInterfaceDescriptor>(
42 new UsbInterfaceDescriptor(device_, &interface_->altsetting[index]));
43}
44
45} // namespace mist