gattlib: Introduce indefinite scan timeout

pull/167/head
Olivier Martin 2020-04-09 10:02:44 +02:00 committed by Olivier Martin
parent c0215ee4ce
commit 825fc4d07c
4 changed files with 14 additions and 12 deletions

View File

@ -189,7 +189,7 @@ static int ble_scan(void *adapter, int device_desc, gattlib_discovered_device_t
return GATTLIB_SUCCESS; return GATTLIB_SUCCESS;
} }
int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data) { int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data) {
int device_desc = *(int*)adapter; int device_desc = *(int*)adapter;
uint16_t interval = htobs(DISCOV_LE_SCAN_INT); uint16_t interval = htobs(DISCOV_LE_SCAN_INT);
@ -219,7 +219,7 @@ int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t disco
} }
int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters, int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters,
gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data) gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data)
{ {
return GATTLIB_NOT_SUPPORTED; return GATTLIB_NOT_SUPPORTED;
} }

View File

@ -43,7 +43,7 @@ static void on_eddystone_discovered_device(void *adapter, const char* addr, cons
} }
int gattlib_adapter_scan_eddystone(void *adapter, int16_t rssi_threshold, uint32_t eddystone_types, int gattlib_adapter_scan_eddystone(void *adapter, int16_t rssi_threshold, uint32_t eddystone_types,
gattlib_discovered_device_with_data_t discovered_device_cb, int timeout, void *user_data) gattlib_discovered_device_with_data_t discovered_device_cb, size_t timeout, void *user_data)
{ {
uuid_t eddystone_uuid; uuid_t eddystone_uuid;
uint32_t enabled_filters = GATTLIB_DISCOVER_FILTER_USE_UUID; uint32_t enabled_filters = GATTLIB_DISCOVER_FILTER_USE_UUID;

View File

@ -199,7 +199,7 @@ on_interface_proxy_properties_changed (GDBusObjectManagerClient *device_manager,
} }
int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters, int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters,
gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data) gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data)
{ {
struct gattlib_adapter *gattlib_adapter = adapter; struct gattlib_adapter *gattlib_adapter = adapter;
GDBusObjectManager *device_manager; GDBusObjectManager *device_manager;
@ -285,7 +285,9 @@ int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, i
// Run Glib loop for 'timeout' seconds // Run Glib loop for 'timeout' seconds
gattlib_adapter->scan_loop = g_main_loop_new(NULL, 0); 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); 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); 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. // Note: The function only resumes when loop timeout as expired or g_main_loop_quit has been called.
@ -302,7 +304,7 @@ DISABLE_SCAN:
return ret; return ret;
} }
int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data) int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data)
{ {
return gattlib_adapter_scan_enable_with_filter(adapter, return gattlib_adapter_scan_enable_with_filter(adapter,
NULL, 0 /* RSSI Threshold */, NULL, 0 /* RSSI Threshold */,

View File

@ -230,12 +230,12 @@ int gattlib_adapter_open(const char* adapter_name, void** adapter);
* *
* @param adapter is the context of the newly opened adapter * @param adapter is the context of the newly opened adapter
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered * @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning * @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()` * @param user_data is the data passed to the callback `discovered_device_cb()`
* *
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code * @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/ */
int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data); int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data);
/** /**
* @brief Enable Bluetooth scanning on a given adapter * @brief Enable Bluetooth scanning on a given adapter
@ -247,13 +247,13 @@ int gattlib_adapter_scan_enable(void* adapter, gattlib_discovered_device_t disco
* @param enabled_filters defines the parameters to use for filtering. There are selected by using the macros * @param enabled_filters defines the parameters to use for filtering. There are selected by using the macros
* GATTLIB_DISCOVER_FILTER_USE_UUID and GATTLIB_DISCOVER_FILTER_USE_RSSI. * GATTLIB_DISCOVER_FILTER_USE_UUID and GATTLIB_DISCOVER_FILTER_USE_RSSI.
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered * @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning * @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()` * @param user_data is the data passed to the callback `discovered_device_cb()`
* *
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code * @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/ */
int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters, int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, int16_t rssi_threshold, uint32_t enabled_filters,
gattlib_discovered_device_t discovered_device_cb, int timeout, void *user_data); gattlib_discovered_device_t discovered_device_cb, size_t timeout, void *user_data);
/** /**
* @brief Enable Eddystone Bluetooth Device scanning on a given adapter * @brief Enable Eddystone Bluetooth Device scanning on a given adapter
@ -264,13 +264,13 @@ int gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid_list, i
* The types are defined by the macros `GATTLIB_EDDYSTONE_TYPE_*`. The macro `GATTLIB_EDDYSTONE_LIMIT_RSSI` * The types are defined by the macros `GATTLIB_EDDYSTONE_TYPE_*`. The macro `GATTLIB_EDDYSTONE_LIMIT_RSSI`
* can also be used to limit RSSI with rssi_threshold. * can also be used to limit RSSI with rssi_threshold.
* @param discovered_device_cb is the function callback called for each new Bluetooth device discovered * @param discovered_device_cb is the function callback called for each new Bluetooth device discovered
* @param timeout defines the duration of the Bluetooth scanning * @param timeout defines the duration of the Bluetooth scanning. When timeout=0, we scan indefinitely.
* @param user_data is the data passed to the callback `discovered_device_cb()` * @param user_data is the data passed to the callback `discovered_device_cb()`
* *
* @return GATTLIB_SUCCESS on success or GATTLIB_* error code * @return GATTLIB_SUCCESS on success or GATTLIB_* error code
*/ */
int gattlib_adapter_scan_eddystone(void *adapter, int16_t rssi_threshold, uint32_t eddystone_types, int gattlib_adapter_scan_eddystone(void *adapter, int16_t rssi_threshold, uint32_t eddystone_types,
gattlib_discovered_device_with_data_t discovered_device_cb, int timeout, void *user_data); gattlib_discovered_device_with_data_t discovered_device_cb, size_t timeout, void *user_data);
/** /**
* @brief Disable Bluetooth scanning on a given adapter * @brief Disable Bluetooth scanning on a given adapter