Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 1 | // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 | // |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 3 | // Modified by FRC Team 971. |
| 4 | // |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 5 | // Wrapper for libusb's endpoints. |
| 6 | |
| 7 | #ifndef _GLIBUSB_GLIBUSB_ENDPOINT_INTERNAL_H_ |
| 8 | #define _GLIBUSB_GLIBUSB_ENDPOINT_INTERNAL_H_ |
| 9 | |
| 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 12 | #include <libusb-1.0/libusb.h> |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 13 | |
| 14 | #include "glibusb_endpoint.h" |
| 15 | |
| 16 | class Notification; |
| 17 | |
| 18 | namespace glibusb { |
| 19 | |
| 20 | class Buffer; |
| 21 | |
| 22 | |
| 23 | // Provides an interface to allow reading from a USB endpoint. |
| 24 | class PhysicalUsbInEndpoint : public UsbInEndpoint { |
| 25 | public: |
| 26 | virtual ~PhysicalUsbInEndpoint(); |
| 27 | |
| 28 | private: |
| 29 | friend class PhysicalUsbDevice; // For constructor |
| 30 | // Constructs an endpoint given the context, handle, and a descriptor of the |
| 31 | // endpoint. The context and handle must remain valid throughout the |
| 32 | // lifetime of this object. |
| 33 | PhysicalUsbInEndpoint(struct libusb_context *context, |
| 34 | struct libusb_device_handle *handle, |
| 35 | const struct libusb_endpoint_descriptor *descriptor); |
| 36 | |
| 37 | virtual int DoGetMaxPacketSize(); |
| 38 | virtual int DoGetMaxIsoPacketSize(); |
| 39 | |
| 40 | // Actually executes the read, with the length, timeout, buffer, and |
| 41 | // notification. |
| 42 | virtual IoStatus DoRead( |
| 43 | uint32_t length, int32_t timeout_milliseconds, Buffer *out, |
| 44 | Notification *quit); |
| 45 | |
| 46 | // Libusb handles and endpoint information. |
| 47 | struct libusb_context *libusb_context_; |
| 48 | struct libusb_device_handle *handle_; |
| 49 | |
| 50 | PhysicalUsbInEndpoint(const PhysicalUsbInEndpoint &) = delete; |
| 51 | void operator=(const PhysicalUsbInEndpoint &) = delete; |
| 52 | }; |
| 53 | |
| 54 | // Provides an interface to allow writing to a USB endpoint. |
| 55 | class PhysicalUsbOutEndpoint : public UsbOutEndpoint { |
| 56 | public: |
| 57 | virtual ~PhysicalUsbOutEndpoint(); |
| 58 | |
| 59 | private: |
| 60 | friend class PhysicalUsbDevice; // For constructor |
| 61 | // Constructs an endpoint given the context, handle, and a descriptor of the |
| 62 | // endpoint. The context and handle must remain valid throughout the |
| 63 | // lifetime of this object. |
| 64 | PhysicalUsbOutEndpoint(struct libusb_context *context, |
| 65 | struct libusb_device_handle *handle, |
| 66 | const struct libusb_endpoint_descriptor *descriptor); |
| 67 | |
| 68 | virtual int DoGetMaxPacketSize(); |
| 69 | virtual int DoGetMaxIsoPacketSize(); |
| 70 | |
| 71 | // Implements the actual write. |
| 72 | virtual IoStatus DoWrite(const Buffer &buffer, |
| 73 | int32_t timeout_milliseconds); |
| 74 | |
| 75 | // Libusb handles and endpoint information. |
| 76 | struct libusb_context *libusb_context_; |
| 77 | struct libusb_device_handle *handle_; |
| 78 | |
| 79 | PhysicalUsbOutEndpoint(const PhysicalUsbOutEndpoint &) = delete; |
| 80 | void operator=(const PhysicalUsbOutEndpoint &) = delete; |
| 81 | }; |
| 82 | |
| 83 | } // namespace glibusb |
| 84 | |
| 85 | #endif // _GLIBUSB_GLIBUSB_ENDPOINT_INTERNAL_H_ |