blob: 8a8fc6a4e0fe13b19a78c1e575db420f6f8f00c1 [file] [log] [blame]
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mist/usb_interface.h"
#include <libusb.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include "mist/usb_device.h"
#include "mist/usb_interface_descriptor.h"
namespace mist {
UsbInterface::UsbInterface(const base::WeakPtr<UsbDevice>& device,
const libusb_interface* interface)
: device_(device), interface_(interface) {
int UsbInterface::GetNumAlternateSettings() const {
return interface_->num_altsetting;
std::unique_ptr<UsbInterfaceDescriptor> UsbInterface::GetAlternateSetting(
int index) const {
if (index < 0 || index >= GetNumAlternateSettings()) {
LOG(ERROR) << base::StringPrintf(
"Invalid alternate setting index %d. "
"Must be non-negative and less than %d.",
index, GetNumAlternateSettings());
return nullptr;
return std::make_unique<UsbInterfaceDescriptor>(
device_, &interface_->altsetting[index]);
} // namespace mist