blob: ca6073dc5d2db0c84684cf8ff4f520e474d14fd3 [file] [log] [blame]
Brian Silverman395d6252013-09-13 20:58:14 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
Brian Silverman7037e872013-09-14 15:35:45 -07003// Modified by FRC Team 971.
4//
Brian Silverman395d6252013-09-13 20:58:14 -07005// 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 Silverman7037e872013-09-14 15:35:45 -070012#include <functional>
Brian Silverman395d6252013-09-13 20:58:14 -070013
14#include "glibusb.h"
15#include "glibusb_endpoint.h"
16
17namespace glibusb {
18
19// Provides an interface to an individual USB device.
20class 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 Silverman7037e872013-09-14 15:35:45 -070031 typedef ::std::function<bool(const struct libusb_endpoint_descriptor *)>
Brian Silverman395d6252013-09-13 20:58:14 -070032 EndpointMatcher;
33
34 // Iterates through all the endpoint descriptors for this device
Brian Silverman7037e872013-09-14 15:35:45 -070035 // and allocates and returns a UsbEndpointType for the first
36 // endpoint for which the matcher returns true or NULL.
Brian Silverman395d6252013-09-13 20:58:14 -070037 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_