blob: be6907358898b82d8d5cf588413357d90f698a53 [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 <stdint.h>
#include <ostream> // NOLINT(readability/streams)
#include <string>
#include <base/macros.h>
#include <base/memory/weak_ptr.h>
struct libusb_device_descriptor;
namespace mist {
class UsbDevice;
// A USB device descriptor, which wraps a libusb_device_descriptor C struct from
// libusb 1.0 into a C++ object.
class UsbDeviceDescriptor {
// Constructs a UsbDeviceDescriptor object by taking a weak pointer to a
// UsbDevice object as |device| and a raw pointer to a
// libusb_device_descriptor struct as |device_descriptor|. |device| is
// used for getting USB string descriptors related to this object. The
// ownership of |device_descriptor| is not transferred, and thus it should
// outlive this object.
UsbDeviceDescriptor(const base::WeakPtr<UsbDevice>& device,
const libusb_device_descriptor* device_descriptor);
UsbDeviceDescriptor(const UsbDeviceDescriptor&) = delete;
UsbDeviceDescriptor& operator=(const UsbDeviceDescriptor&) = delete;
~UsbDeviceDescriptor() = default;
// Getters for retrieving fields of the libusb_device_descriptor struct.
uint8_t GetLength() const;
uint8_t GetDescriptorType() const;
uint8_t GetDeviceClass() const;
uint8_t GetDeviceSubclass() const;
uint8_t GetDeviceProtocol() const;
uint8_t GetMaxPacketSize0() const;
uint16_t GetVendorId() const;
uint16_t GetProductId() const;
std::string GetManufacturer() const;
std::string GetProduct() const;
std::string GetSerialNumber() const;
uint8_t GetNumConfigurations() const;
// Returns a string describing the properties of this object for logging
// purpose.
std::string ToString() const;
base::WeakPtr<UsbDevice> device_;
const libusb_device_descriptor* const device_descriptor_;
} // namespace mist
// Output stream operator provided to facilitate logging.
std::ostream& operator<<(std::ostream& stream,
const mist::UsbDeviceDescriptor& device_descriptor);