In gattlib_adapter_scan_enable_with_filter in file dbus/gattlib_adapter.c scan_loop is used to wait for the timeout to expire before calling scan disable. Relevant code below:
// Run Glib loop for 'timeout' seconds
gattlib_adapter->scan_loop = g_main_loop_new(NULL, 0);
if (timeout > 0) {
gattlib_adapter->timeout_id = g_timeout_add_seconds(timeout, stop_scan_func, gattlib_adapter->scan_loop);
}
g_main_loop_run(gattlib_adapter->scan_loop);
// Note: The function only resumes when loop timeout as expired or g_main_loop_quit has been called.
g_signal_handler_disconnect(G_DBUS_OBJECT_MANAGER(device_manager), added_signal_id);
g_signal_handler_disconnect(G_DBUS_OBJECT_MANAGER(device_manager), changed_signal_id);
DISABLE_SCAN:
// Stop BLE device discovery
gattlib_adapter_scan_disable(adapter);
In gattlib_adapter_scan_disable, scan is only disabled if scan_loop is running. However, since gattlib_adapter_scan_disable is only called after scan_loop terminates, the if condition evaluates to false and the scan isn't actually disabled. Relevant code below:
In
gattlib_adapter_scan_enable_with_filter
in filedbus/gattlib_adapter.c
scan_loop is used to wait for the timeout to expire before calling scan disable. Relevant code below:In
gattlib_adapter_scan_disable
, scan is only disabled if scan_loop is running. However, sincegattlib_adapter_scan_disable
is only called after scan_loop terminates, the if condition evaluates to false and the scan isn't actually disabled. Relevant code below: