Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 1 | // 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 Chan | 64b60f6 | 2019-06-06 16:57:30 -0700 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
Ben Chan | 4746c8a | 2014-09-02 20:34:58 -0700 | [diff] [blame] | 10 | #include <base/macros.h> |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 11 | #include <base/memory/weak_ptr.h> |
| 12 | |
| 13 | struct libusb_interface; |
| 14 | |
| 15 | namespace mist { |
| 16 | |
| 17 | class UsbDevice; |
| 18 | class UsbInterfaceDescriptor; |
| 19 | |
| 20 | // A USB interface, which wraps a libusb_interface C struct from libusb 1.0 into |
| 21 | // a C++ object. |
| 22 | class 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 Chan | a4c8c96 | 2014-08-13 20:36:10 -0700 | [diff] [blame] | 33 | ~UsbInterface() = default; |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 34 | |
| 35 | // Getters for retrieving fields of the libusb_interface struct. |
| 36 | int GetNumAlternateSettings() const; |
| 37 | |
Ben Chan | d31d6c1 | 2013-08-07 21:28:33 -0700 | [diff] [blame] | 38 | // 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 Chan | 64b60f6 | 2019-06-06 16:57:30 -0700 | [diff] [blame] | 40 | // The returned object should not be held beyond the lifetime of this object. |
| 41 | std::unique_ptr<UsbInterfaceDescriptor> GetAlternateSetting(int index) const; |
Ben Chan | f4930e5 | 2013-05-28 13:24:54 -0700 | [diff] [blame] | 42 | |
| 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_ |