From 4ebc640ddd1df4321fb01d3bf151b547f6f7fb8f Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Thu, 9 Apr 2020 09:09:37 +0200 Subject: [PATCH] dbus: Only start BLE scan when all signals are connected --- dbus/gattlib_adapter.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dbus/gattlib_adapter.c b/dbus/gattlib_adapter.c index 9a349a9..57dd121 100644 --- a/dbus/gattlib_adapter.c +++ b/dbus/gattlib_adapter.c @@ -242,13 +242,6 @@ int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, i return GATTLIB_ERROR_DBUS; } - org_bluez_adapter1_call_start_discovery_sync(gattlib_adapter->adapter_proxy, NULL, &error); - if (error) { - fprintf(stderr, "Failed to start discovery: %s\n", error->message); - g_error_free(error); - return GATTLIB_ERROR_DBUS; - } - // // Get notification when objects are removed from the Bluez ObjectManager. // We should get notified when the connection is lost with the target to allow @@ -278,6 +271,14 @@ int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, i G_CALLBACK(on_interface_proxy_properties_changed), &discovered_device_arg); + // Now, start BLE discovery + org_bluez_adapter1_call_start_discovery_sync(gattlib_adapter->adapter_proxy, NULL, &error); + if (error) { + fprintf(stderr, "Failed to start discovery: %s\n", error->message); + g_error_free(error); + return GATTLIB_ERROR_DBUS; + } + // Run Glib loop for 'timeout' seconds gattlib_adapter->scan_loop = g_main_loop_new(NULL, 0); gattlib_adapter->timeout_id = g_timeout_add_seconds(timeout, stop_scan_func, gattlib_adapter->scan_loop);