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 | |
| 8 | #include <base/basictypes.h> |
| 9 | #include <base/memory/scoped_ptr.h> |
| 10 | #include <base/memory/weak_ptr.h> |
| 11 | |
| 12 | struct libusb_interface; |
| 13 | |
| 14 | namespace mist { |
| 15 | |
| 16 | class UsbDevice; |
| 17 | class UsbInterfaceDescriptor; |
| 18 | |
| 19 | // A USB interface, which wraps a libusb_interface C struct from libusb 1.0 into |
| 20 | // a C++ object. |
| 21 | class UsbInterface { |
| 22 | public: |
| 23 | // Constructs a UsbInterface object by taking a weak pointer to a UsbDevice |
| 24 | // object as |device| and a raw pointer to a libusb_interface struct as |
| 25 | // |interface|. |device| is passed to the constructor of |
| 26 | // UsbInterfaceDescriptor when creating a UsbInterfaceDescriptor object. The |
| 27 | // ownership of |interface| is not transferred, and thus it should outlive |
| 28 | // this object. |
| 29 | UsbInterface(const base::WeakPtr<UsbDevice>& device, |
| 30 | const libusb_interface* interface); |
| 31 | |
| 32 | ~UsbInterface(); |
| 33 | |
| 34 | // Getters for retrieving fields of the libusb_interface struct. |
| 35 | int GetNumAlternateSettings() const; |
| 36 | |
| 37 | // Returns a scoped pointer to a UsbInterfaceDescriptor object for the |
| 38 | // interface descriptor indexed at |index|, or null scoped pointer if the |
| 39 | // index is invalid. The returned object becomes invalid, and thus should not |
| 40 | // be held, beyond the lifetime of this object. |
| 41 | scoped_ptr<UsbInterfaceDescriptor> GetAlternateSetting(int index) const; |
| 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_ |