Ben Chan | 4d9ad04 | 2013-05-27 21:38:49 -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_ENDPOINT_DESCRIPTOR_H_ |
| 6 | #define MIST_USB_ENDPOINT_DESCRIPTOR_H_ |
| 7 | |
Ben Chan | 956f79b | 2014-08-06 17:11:01 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Ben Chan | abfa15a | 2014-06-16 20:07:35 -0700 | [diff] [blame] | 10 | #include <ostream> // NOLINT(readability/streams) |
Ben Chan | 4d9ad04 | 2013-05-27 21:38:49 -0700 | [diff] [blame] | 11 | #include <string> |
| 12 | |
Ben Chan | 4746c8a | 2014-09-02 20:34:58 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Ben Chan | 4d9ad04 | 2013-05-27 21:38:49 -0700 | [diff] [blame] | 14 | |
| 15 | #include "mist/usb_constants.h" |
| 16 | |
| 17 | struct libusb_endpoint_descriptor; |
| 18 | |
| 19 | namespace mist { |
| 20 | |
| 21 | // A USB endpoint descriptor, which wraps a libusb_endpoint_descriptor C struct |
| 22 | // from libusb 1.0 into a C++ object. |
| 23 | class UsbEndpointDescriptor { |
| 24 | public: |
| 25 | // Constructs a UsbEndpointDescriptor object by taking a raw pointer to a |
| 26 | // libusb_endpoint_descriptor struct as |endpoint_descriptor|. The ownership |
| 27 | // of |endpoint_descriptor| is not transferred, and thus it should outlive |
| 28 | // this object. |
| 29 | explicit UsbEndpointDescriptor( |
| 30 | const libusb_endpoint_descriptor* endpoint_descriptor); |
| 31 | |
Ben Chan | a4c8c96 | 2014-08-13 20:36:10 -0700 | [diff] [blame] | 32 | ~UsbEndpointDescriptor() = default; |
Ben Chan | 4d9ad04 | 2013-05-27 21:38:49 -0700 | [diff] [blame] | 33 | |
| 34 | // Getters for retrieving fields of the libusb_endpoint_descriptor struct. |
Ben Chan | 956f79b | 2014-08-06 17:11:01 -0700 | [diff] [blame] | 35 | uint8_t GetLength() const; |
| 36 | uint8_t GetDescriptorType() const; |
| 37 | uint8_t GetEndpointAddress() const; |
| 38 | uint8_t GetEndpointNumber() const; |
| 39 | uint8_t GetAttributes() const; |
| 40 | uint16_t GetMaxPacketSize() const; |
| 41 | uint8_t GetInterval() const; |
Ben Chan | 4d9ad04 | 2013-05-27 21:38:49 -0700 | [diff] [blame] | 42 | UsbDirection GetDirection() const; |
| 43 | UsbTransferType GetTransferType() const; |
| 44 | |
| 45 | // Returns a string describing the properties of this object for logging |
| 46 | // purpose. |
| 47 | std::string ToString() const; |
| 48 | |
| 49 | private: |
| 50 | const libusb_endpoint_descriptor* const endpoint_descriptor_; |
| 51 | |
| 52 | DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptor); |
| 53 | }; |
| 54 | |
| 55 | } // namespace mist |
| 56 | |
| 57 | // Output stream operator provided to facilitate logging. |
| 58 | std::ostream& operator<<( |
| 59 | std::ostream& stream, |
| 60 | const mist::UsbEndpointDescriptor& endpoint_descriptor); |
| 61 | |
| 62 | #endif // MIST_USB_ENDPOINT_DESCRIPTOR_H_ |