blob: d250c79111ba14d6e9c4aa8c5ffae15673f43f5e [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);
31
Ben Chana4c8c962014-08-13 20:36:10 -070032 ~UsbEndpointDescriptor() = default;
Ben Chan4d9ad042013-05-27 21:38:49 -070033
34 // Getters for retrieving fields of the libusb_endpoint_descriptor struct.
Ben Chan956f79b2014-08-06 17:11:01 -070035 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 Chan4d9ad042013-05-27 21:38:49 -070042 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.
58std::ostream& operator<<(
59 std::ostream& stream,
60 const mist::UsbEndpointDescriptor& endpoint_descriptor);
61
62#endif // MIST_USB_ENDPOINT_DESCRIPTOR_H_