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 device that implements the UsbDevice interface. |
| 6 | |
| 7 | #ifndef _GLIBUSB_GLIBUSB_DEVICE_INTERNAL_H_ |
| 8 | #define _GLIBUSB_GLIBUSB_DEVICE_INTERNAL_H_ |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <utility> |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 12 | #include <functional> |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 13 | |
| 14 | #include "glibusb.h" |
| 15 | #include "glibusb_endpoint.h" |
| 16 | |
| 17 | namespace glibusb { |
| 18 | |
| 19 | // Provides an interface to an individual USB device. |
| 20 | class PhysicalUsbDevice : public UsbDevice { |
| 21 | public: |
| 22 | virtual ~PhysicalUsbDevice(); |
| 23 | |
| 24 | private: |
| 25 | friend class Libusb; // For private constructor. |
| 26 | // Constructs a device given the context and handle. |
| 27 | // Frees the handle on destruction. |
| 28 | PhysicalUsbDevice(struct libusb_context *context, |
| 29 | struct libusb_device_handle *handle); |
| 30 | |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 31 | typedef ::std::function<bool(const struct libusb_endpoint_descriptor *)> |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 32 | EndpointMatcher; |
| 33 | |
| 34 | // Iterates through all the endpoint descriptors for this device |
Brian Silverman | 7037e87 | 2013-09-14 15:35:45 -0700 | [diff] [blame] | 35 | // and allocates and returns a UsbEndpointType for the first |
| 36 | // endpoint for which the matcher returns true or NULL. |
Brian Silverman | 395d625 | 2013-09-13 20:58:14 -0700 | [diff] [blame] | 37 | template <class UsbEndpointType> |
| 38 | UsbEndpointType *MatchEndpoint(EndpointMatcher matcher); |
| 39 | |
| 40 | virtual bool DoSetAlternateSetting(int setting); |
| 41 | virtual UsbInEndpoint *DoFindInEndpoint(UsbEndpoint::TransferType endpoint); |
| 42 | virtual UsbOutEndpoint *DoFindOutEndpoint(UsbEndpoint::TransferType endpoint); |
| 43 | virtual UsbInEndpoint *DoInEndpoint(int number); |
| 44 | virtual UsbOutEndpoint *DoOutEndpoint(int number); |
| 45 | virtual struct DeviceLocationAndId DoDeviceLocationAndId(); |
| 46 | |
| 47 | // Libusb context and handle used to interact with libusb. |
| 48 | struct libusb_context *libusb_context_; |
| 49 | struct libusb_device_handle *device_handle_; |
| 50 | |
| 51 | PhysicalUsbDevice(const PhysicalUsbDevice &) = delete; |
| 52 | void operator=(const PhysicalUsbDevice &) = delete; |
| 53 | }; |
| 54 | |
| 55 | } // namespace glibusb |
| 56 | |
| 57 | #endif // _GLIBUSB_GLIBUSB_DEVICE_INTERNAL_H_ |