Add more debug logs

pull/185/merge 0.4.7
Olivier Martin 2024-03-07 23:58:35 +01:00
parent 24ab0ea95f
commit 36e0cb4934
2 changed files with 15 additions and 0 deletions

View File

@ -192,6 +192,8 @@ int gattlib_connect(void *adapter, const char *dst,
connection->on_connection.callback.connection_handler = connect_cb;
connection->on_connection.user_data = user_data;
GATTLIB_LOG(GATTLIB_DEBUG, "Connect bluetooth device %s", dst);
OrgBluezDevice1* device = org_bluez_device1_proxy_new_for_bus_sync(
G_BUS_TYPE_SYSTEM,
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
@ -289,6 +291,8 @@ int gattlib_disconnect(gatt_connection_t* connection) {
goto EXIT;
}
GATTLIB_LOG(GATTLIB_DEBUG, "Disconnect bluetooth device %s", conn_context->device_object_path);
// Remove signal
if (conn_context->on_handle_device_property_change_id != 0) {
g_signal_handler_disconnect(conn_context->device, conn_context->on_handle_device_property_change_id);

View File

@ -26,6 +26,8 @@ int gattlib_adapter_open(const char* adapter_name, void** adapter) {
adapter_name = GATTLIB_DEFAULT_ADAPTER;
}
GATTLIB_LOG(GATTLIB_DEBUG, "Open bluetooth adapter %s", adapter_name);
snprintf(object_path, sizeof(object_path), "/org/bluez/%s", adapter_name);
adapter_proxy = org_bluez_adapter1_proxy_new_for_bus_sync(
@ -329,6 +331,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
int ret;
if ((gattlib_adapter == NULL) || (gattlib_adapter->adapter_proxy == NULL)) {
GATTLIB_LOG(GATTLIB_ERROR, "Could not start BLE scan. No opened bluetooth adapter");
return GATTLIB_NO_ADAPTER;
}
@ -338,6 +341,8 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
char uuid_str[MAX_LEN_UUID_STR + 1];
GVariantBuilder list_uuid_builder;
GATTLIB_LOG(GATTLIB_DEBUG, "Configure bluetooth scan with UUID");
g_variant_builder_init(&list_uuid_builder, G_VARIANT_TYPE ("as"));
for (uuid_t **uuid_ptr = uuid_list; *uuid_ptr != NULL; uuid_ptr++) {
@ -349,6 +354,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
}
if (enabled_filters & GATTLIB_DISCOVER_FILTER_USE_RSSI) {
GATTLIB_LOG(GATTLIB_DEBUG, "Configure bluetooth scan with RSSI");
GVariant *rssi_variant = g_variant_new_int16(rssi_threshold);
g_variant_builder_add(&arg_properties_builder, "{sv}", "RSSI", rssi_variant);
}
@ -411,6 +417,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
return ret;
}
GATTLIB_LOG(GATTLIB_DEBUG, "Bluetooth scan started");
return GATTLIB_SUCCESS;
}
@ -491,6 +498,8 @@ int gattlib_adapter_scan_disable(void* adapter) {
goto EXIT;
}
GATTLIB_LOG(GATTLIB_DEBUG, "Stop bluetooth scan.");
org_bluez_adapter1_call_stop_discovery_sync(gattlib_adapter->adapter_proxy, NULL, &error);
if (error != NULL) {
if (((error->domain == 238) || (error->domain == 239)) && (error->code == 36)) {
@ -539,6 +548,8 @@ int gattlib_adapter_close(void* adapter)
goto EXIT;
}
GATTLIB_LOG(GATTLIB_DEBUG, "Close bluetooth adapter %s", gattlib_adapter->adapter_name);
if (gattlib_adapter->ble_scan.is_scanning) {
gattlib_adapter_scan_disable(gattlib_adapter);