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