blob: c6bd78cafd9cff516838b07d0076778b481f9fb8 [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
8#include <base/basictypes.h>
Ben Chanf4930e52013-05-28 13:24:54 -07009#include <base/memory/weak_ptr.h>
10
11struct libusb_interface;
12
13namespace mist {
14
15class UsbDevice;
16class UsbInterfaceDescriptor;
17
18// A USB interface, which wraps a libusb_interface C struct from libusb 1.0 into
19// a C++ object.
20class UsbInterface {
21 public:
22 // Constructs a UsbInterface object by taking a weak pointer to a UsbDevice
23 // object as |device| and a raw pointer to a libusb_interface struct as
24 // |interface|. |device| is passed to the constructor of
25 // UsbInterfaceDescriptor when creating a UsbInterfaceDescriptor object. The
26 // ownership of |interface| is not transferred, and thus it should outlive
27 // this object.
28 UsbInterface(const base::WeakPtr<UsbDevice>& device,
29 const libusb_interface* interface);
30
Ben Chana4c8c962014-08-13 20:36:10 -070031 ~UsbInterface() = default;
Ben Chanf4930e52013-05-28 13:24:54 -070032
33 // Getters for retrieving fields of the libusb_interface struct.
34 int GetNumAlternateSettings() const;
35
Ben Chand31d6c12013-08-07 21:28:33 -070036 // Returns a pointer to a UsbInterfaceDescriptor object for the interface
37 // descriptor indexed at |index|, or a NULL pointer if the index is invalid.
38 // The returned object should be deleted by the caller after use and should
39 // not be held beyond the lifetime of this object.
40 UsbInterfaceDescriptor* GetAlternateSetting(int index) const;
Ben Chanf4930e52013-05-28 13:24:54 -070041
42 private:
43 base::WeakPtr<UsbDevice> device_;
44 const libusb_interface* const interface_;
45
46 DISALLOW_COPY_AND_ASSIGN(UsbInterface);
47};
48
49} // namespace mist
50
51#endif // MIST_USB_INTERFACE_H_