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