From owner-svn-ports-all@freebsd.org Fri Jun 30 15:11:56 2017 Return-Path: Delivered-To: svn-ports-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5EA91D93A6B; Fri, 30 Jun 2017 15:11:56 +0000 (UTC) (envelope-from jbeich@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2032C71559; Fri, 30 Jun 2017 15:11:56 +0000 (UTC) (envelope-from jbeich@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5UFBtUf070783; Fri, 30 Jun 2017 15:11:55 GMT (envelope-from jbeich@FreeBSD.org) Received: (from jbeich@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5UFBtlC070781; Fri, 30 Jun 2017 15:11:55 GMT (envelope-from jbeich@FreeBSD.org) Message-Id: <201706301511.v5UFBtlC070781@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jbeich set sender to jbeich@FreeBSD.org using -f From: Jan Beich Date: Fri, 30 Jun 2017 15:11:55 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r444762 - in head/devel/android-tools-adb-devel: . files X-SVN-Group: ports-head X-SVN-Commit-Author: jbeich X-SVN-Commit-Paths: in head/devel/android-tools-adb-devel: . files X-SVN-Commit-Revision: 444762 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jun 2017 15:11:56 -0000 Author: jbeich Date: Fri Jun 30 15:11:54 2017 New Revision: 444762 URL: https://svnweb.freebsd.org/changeset/ports/444762 Log: devel/android-tools-adb-devel: restore USB transport for < 11.0 https://android.googlesource.com/platform/system/core/+/6da1cd49b5ea%5E%21/ Modified: head/devel/android-tools-adb-devel/Makefile (contents, props changed) head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp (contents, props changed) Modified: head/devel/android-tools-adb-devel/Makefile ============================================================================== --- head/devel/android-tools-adb-devel/Makefile Fri Jun 30 15:10:26 2017 (r444761) +++ head/devel/android-tools-adb-devel/Makefile Fri Jun 30 15:11:54 2017 (r444762) @@ -3,7 +3,7 @@ # Hint: git describe --abbrev=12 --match android-o-preview-2 DISTVERSION= o-preview-2-332 DISTVERSIONSUFFIX= -gd1e9e7bc06f0 -PORTREVISION= 0 +PORTREVISION= 1 PKGNAMESUFFIX= -devel CONFLICTS_INSTALL= ${PORTNAME}-[0-9]* Modified: head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp ============================================================================== --- head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp Fri Jun 30 15:10:26 2017 (r444761) +++ head/devel/android-tools-adb-devel/files/patch-adb_client_usb__libusb.cpp Fri Jun 30 15:11:54 2017 (r444762) @@ -21,33 +21,62 @@ usb_handle(const std::string& device_address, const std::string& serial, unique_device_handle&& device_handle, uint8_t interface, uint8_t bulk_in, uint8_t bulk_out, size_t zero_mask, size_t max_packet_size) -@@ -152,7 +156,9 @@ struct usb_handle : public ::usb_handle { +@@ -152,7 +156,14 @@ struct usb_handle : public ::usb_handle { static auto& usb_handles = *new std::unordered_map>(); static auto& usb_handles_mutex = *new std::mutex(); +#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 static libusb_hotplug_callback_handle hotplug_handle; ++#else ++static std::thread* device_poll_thread = nullptr; ++static bool terminate_device_poll_thread = false; ++static auto& device_poll_mutex = *new std::mutex(); ++static auto& device_poll_cv = *new std::condition_variable(); +#endif static std::string get_device_address(libusb_device* device) { return StringPrintf("usb:%d:%d", libusb_get_bus_number(device), -@@ -420,6 +426,7 @@ static void device_disconnected(libusb_device* device) - } +@@ -380,6 +391,7 @@ static void process_device(libusb_device* device) { + LOG(INFO) << "registered new usb device '" << device_serial << "'"; } +#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 - static auto& hotplug_queue = *new BlockingQueue>(); - static void hotplug_thread() { - adb_thread_setname("libusb hotplug"); -@@ -449,6 +456,7 @@ static int hotplug_callback(libusb_context*, libusb_de + static std::atomic connecting_devices(0); + + static void device_connected(libusb_device* device) { +@@ -449,7 +461,31 @@ static int hotplug_callback(libusb_context*, libusb_de hotplug_queue.Push({event, device}); return 0; } -+#endif ++#else ++static void poll_for_devices() { ++ libusb_device** list; ++ adb_thread_setname("device poll"); ++ while (true) { ++ const ssize_t device_count = libusb_get_device_list(nullptr, &list); ++ LOG(VERBOSE) << "found " << device_count << " attached devices"; ++ ++ for (ssize_t i = 0; i < device_count; ++i) { ++ process_device(list[i]); ++ } ++ ++ libusb_free_device_list(list, 1); ++ ++ adb_notify_device_scan_complete(); ++ ++ std::unique_lock lock(device_poll_mutex); ++ if (device_poll_cv.wait_for(lock, 500ms, []() { return terminate_device_poll_thread; })) { ++ return; ++ } ++ } ++} ++#endif ++ void usb_init() { LOG(DEBUG) << "initializing libusb..."; -@@ -457,6 +465,7 @@ void usb_init() { + int rc = libusb_init(nullptr); +@@ -457,6 +493,7 @@ void usb_init() { LOG(FATAL) << "failed to initialize libusb: " << libusb_error_name(rc); } @@ -55,22 +84,39 @@ // Register the hotplug callback. rc = libusb_hotplug_register_callback( nullptr, static_cast(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | -@@ -467,6 +476,9 @@ void usb_init() { +@@ -467,6 +504,7 @@ void usb_init() { if (rc != LIBUSB_SUCCESS) { LOG(FATAL) << "failed to register libusb hotplug callback"; } -+#else -+ LOG(FATAL) << "libusb doesn't support hotplug but scanning isn't implemented"; +#endif // Spawn a thread for libusb_handle_events. std::thread([]() { -@@ -478,7 +490,9 @@ void usb_init() { +@@ -475,10 +513,28 @@ void usb_init() { + libusb_handle_events(nullptr); + } + }).detach(); ++ ++#if !defined(LIBUSB_API_VERSION) || LIBUSB_API_VERSION < 0x01000102 ++ std::unique_lock lock(device_poll_mutex); ++ device_poll_thread = new std::thread(poll_for_devices); ++#endif } void usb_cleanup() { +#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102 libusb_hotplug_deregister_callback(nullptr, hotplug_handle); ++#else ++ { ++ std::unique_lock lock(device_poll_mutex); ++ terminate_device_poll_thread = true; ++ ++ if (!device_poll_thread) { ++ return; ++ } ++ } ++ device_poll_cv.notify_all(); ++ device_poll_thread->join(); +#endif }