Josh Gao | 1c70e1b | 2016-09-28 12:32:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | // USB host/client interface. |
| 20 | |
| 21 | #define ADB_USB_INTERFACE(handle_ref_type) \ |
| 22 | void usb_init(); \ |
| 23 | int usb_write(handle_ref_type h, const void* data, int len); \ |
| 24 | int usb_read(handle_ref_type h, void* data, int len); \ |
| 25 | int usb_close(handle_ref_type h); \ |
| 26 | void usb_kick(handle_ref_type h) |
| 27 | |
| 28 | #if defined(_WIN32) || !ADB_HOST |
| 29 | // Windows and the daemon have a single implementation. |
| 30 | |
| 31 | struct usb_handle; |
| 32 | ADB_USB_INTERFACE(usb_handle*); |
| 33 | |
| 34 | #else // linux host || darwin |
| 35 | // Linux and Darwin clients have native and libusb implementations. |
| 36 | |
| 37 | namespace libusb { |
| 38 | struct usb_handle; |
| 39 | ADB_USB_INTERFACE(libusb::usb_handle*); |
| 40 | } |
| 41 | |
| 42 | namespace native { |
| 43 | struct usb_handle; |
| 44 | ADB_USB_INTERFACE(native::usb_handle*); |
| 45 | } |
| 46 | |
| 47 | // Empty base that both implementations' opaque handles inherit from. |
| 48 | struct usb_handle { |
| 49 | }; |
| 50 | |
| 51 | ADB_USB_INTERFACE(::usb_handle*); |
| 52 | |
| 53 | #endif // linux host || darwin |
| 54 | |
| 55 | |
| 56 | // USB device detection. |
| 57 | int is_adb_interface(int usb_class, int usb_subclass, int usb_protocol); |