blob: fd833eb5977b5abf534e5af75171571e30d353d3 [file] [log] [blame]
Ben Chan4d9ad042013-05-27 21:38:49 -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_ENDPOINT_DESCRIPTOR_H_
6#define MIST_USB_ENDPOINT_DESCRIPTOR_H_
7
Ben Chan956f79b2014-08-06 17:11:01 -07008#include <stdint.h>
9
Ben Chanabfa15a2014-06-16 20:07:35 -070010#include <ostream> // NOLINT(readability/streams)
Ben Chan4d9ad042013-05-27 21:38:49 -070011#include <string>
12
Ben Chan4746c8a2014-09-02 20:34:58 -070013#include <base/macros.h>
Ben Chan4d9ad042013-05-27 21:38:49 -070014
15#include "mist/usb_constants.h"
16
17struct libusb_endpoint_descriptor;
18
19namespace mist {
20
21// A USB endpoint descriptor, which wraps a libusb_endpoint_descriptor C struct
22// from libusb 1.0 into a C++ object.
23class 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);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090031 UsbEndpointDescriptor(const UsbEndpointDescriptor&) = delete;
32 UsbEndpointDescriptor& operator=(const UsbEndpointDescriptor&) = delete;
Ben Chan4d9ad042013-05-27 21:38:49 -070033
Ben Chana4c8c962014-08-13 20:36:10 -070034 ~UsbEndpointDescriptor() = default;
Ben Chan4d9ad042013-05-27 21:38:49 -070035
36 // Getters for retrieving fields of the libusb_endpoint_descriptor struct.
Ben Chan956f79b2014-08-06 17:11:01 -070037 uint8_t GetLength() const;
38 uint8_t GetDescriptorType() const;
39 uint8_t GetEndpointAddress() const;
40 uint8_t GetEndpointNumber() const;
41 uint8_t GetAttributes() const;
42 uint16_t GetMaxPacketSize() const;
43 uint8_t GetInterval() const;
Ben Chan4d9ad042013-05-27 21:38:49 -070044 UsbDirection GetDirection() const;
45 UsbTransferType GetTransferType() const;
46
47 // Returns a string describing the properties of this object for logging
48 // purpose.
49 std::string ToString() const;
50
51 private:
52 const libusb_endpoint_descriptor* const endpoint_descriptor_;
Ben Chan4d9ad042013-05-27 21:38:49 -070053};
54
55} // namespace mist
56
57// Output stream operator provided to facilitate logging.
58std::ostream& operator<<(
59 std::ostream& stream,
60 const mist::UsbEndpointDescriptor& endpoint_descriptor);
61
62#endif // MIST_USB_ENDPOINT_DESCRIPTOR_H_