blob: e4d6106c8d92e4235dc48b284fb957b791c6f5fb [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#ifndef MIST_USB_INTERFACE_H_
6#define MIST_USB_INTERFACE_H_
7
Ben Chan64b60f62019-06-06 16:57:30 -07008#include <memory>
9
Ben Chan4746c8a2014-09-02 20:34:58 -070010#include <base/macros.h>
Ben Chanf4930e52013-05-28 13:24:54 -070011#include <base/memory/weak_ptr.h>
12
13struct libusb_interface;
14
15namespace mist {
16
17class UsbDevice;
18class UsbInterfaceDescriptor;
19
20// A USB interface, which wraps a libusb_interface C struct from libusb 1.0 into
21// a C++ object.
22class UsbInterface {
23 public:
24 // Constructs a UsbInterface object by taking a weak pointer to a UsbDevice
25 // object as |device| and a raw pointer to a libusb_interface struct as
26 // |interface|. |device| is passed to the constructor of
27 // UsbInterfaceDescriptor when creating a UsbInterfaceDescriptor object. The
28 // ownership of |interface| is not transferred, and thus it should outlive
29 // this object.
30 UsbInterface(const base::WeakPtr<UsbDevice>& device,
31 const libusb_interface* interface);
32
Ben Chana4c8c962014-08-13 20:36:10 -070033 ~UsbInterface() = default;
Ben Chanf4930e52013-05-28 13:24:54 -070034
35 // Getters for retrieving fields of the libusb_interface struct.
36 int GetNumAlternateSettings() const;
37
Ben Chand31d6c12013-08-07 21:28:33 -070038 // Returns a pointer to a UsbInterfaceDescriptor object for the interface
39 // descriptor indexed at |index|, or a NULL pointer if the index is invalid.
Ben Chan64b60f62019-06-06 16:57:30 -070040 // The returned object should not be held beyond the lifetime of this object.
41 std::unique_ptr<UsbInterfaceDescriptor> GetAlternateSetting(int index) const;
Ben Chanf4930e52013-05-28 13:24:54 -070042
43 private:
44 base::WeakPtr<UsbDevice> device_;
45 const libusb_interface* const interface_;
46
47 DISALLOW_COPY_AND_ASSIGN(UsbInterface);
48};
49
50} // namespace mist
51
52#endif // MIST_USB_INTERFACE_H_