Skip to content

Commit

Permalink
Add more debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermartin committed Mar 7, 2024
1 parent 24ab0ea commit 36e0cb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dbus/gattlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions dbus/gattlib_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

Expand All @@ -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++) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 36e0cb4

Please sign in to comment.