blob: a43afd06754fe57accaef7b7269eee61ae20a4e6 [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);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090032 UsbInterface(const UsbInterface&) = delete;
33 UsbInterface& operator=(const UsbInterface&) = delete;
Ben Chanf4930e52013-05-28 13:24:54 -070034
Ben Chana4c8c962014-08-13 20:36:10 -070035 ~UsbInterface() = default;
Ben Chanf4930e52013-05-28 13:24:54 -070036
37 // Getters for retrieving fields of the libusb_interface struct.
38 int GetNumAlternateSettings() const;
39
Ben Chand31d6c12013-08-07 21:28:33 -070040 // Returns a pointer to a UsbInterfaceDescriptor object for the interface
41 // descriptor indexed at |index|, or a NULL pointer if the index is invalid.
Ben Chan64b60f62019-06-06 16:57:30 -070042 // The returned object should not be held beyond the lifetime of this object.
43 std::unique_ptr<UsbInterfaceDescriptor> GetAlternateSetting(int index) const;
Ben Chanf4930e52013-05-28 13:24:54 -070044
45 private:
46 base::WeakPtr<UsbDevice> device_;
47 const libusb_interface* const interface_;
Ben Chanf4930e52013-05-28 13:24:54 -070048};
49
50} // namespace mist
51
52#endif // MIST_USB_INTERFACE_H_