From 7107d9f5b47eee5232e9b021a20d9bb4ddb3bc40 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Wed, 8 Apr 2020 13:24:32 +0200 Subject: [PATCH] dbus: Check the disconnection of the handler has really succeeded --- dbus/gattlib.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/dbus/gattlib.c b/dbus/gattlib.c index b7e3064..6a2d614 100644 --- a/dbus/gattlib.c +++ b/dbus/gattlib.c @@ -961,26 +961,36 @@ int gattlib_notification_start(gatt_connection_t* connection, const uuid_t* uuid } int gattlib_notification_stop(gatt_connection_t* connection, const uuid_t* uuid) { + size_t count; + struct dbus_characteristic dbus_characteristic = get_characteristic_from_uuid(connection, uuid); if (dbus_characteristic.type == TYPE_NONE) { return GATTLIB_NOT_FOUND; } #if BLUEZ_VERSION > BLUEZ_VERSIONS(5, 40) else if (dbus_characteristic.type == TYPE_BATTERY_LEVEL) { - g_signal_handlers_disconnect_by_func( + count = g_signal_handlers_disconnect_by_func( dbus_characteristic.battery, G_CALLBACK (on_handle_battery_level_property_change), connection); + if (count == 0) { + fprintf(stderr, "Could not find any notification attached to this UUID"); + return GATTLIB_NOT_FOUND; + } return GATTLIB_SUCCESS; } else { assert(dbus_characteristic.type == TYPE_GATT); } #endif - g_signal_handlers_disconnect_by_func( + count = g_signal_handlers_disconnect_by_func( dbus_characteristic.gatt, G_CALLBACK (on_handle_characteristic_property_change), connection); + if (count == 0) { + fprintf(stderr, "Could not find any notification attached to this UUID"); + return GATTLIB_NOT_FOUND; + } GError *error = NULL; org_bluez_gatt_characteristic1_call_stop_notify_sync( @@ -1033,26 +1043,36 @@ int gattlib_indication_start(gatt_connection_t* connection, const uuid_t* uuid) } int gattlib_indication_stop(gatt_connection_t* connection, const uuid_t* uuid) { + size_t count; + struct dbus_characteristic dbus_characteristic = get_characteristic_from_uuid(connection, uuid); if (dbus_characteristic.type == TYPE_NONE) { return GATTLIB_NOT_FOUND; } #if BLUEZ_VERSION > BLUEZ_VERSIONS(5, 40) else if (dbus_characteristic.type == TYPE_BATTERY_LEVEL) { - g_signal_handlers_disconnect_by_func( + count = g_signal_handlers_disconnect_by_func( dbus_characteristic.battery, G_CALLBACK (on_handle_battery_level_property_change), connection); + if (count == 0) { + fprintf(stderr, "Could not find any notification attached to this UUID"); + return GATTLIB_NOT_FOUND; + } return GATTLIB_SUCCESS; } else { assert(dbus_characteristic.type == TYPE_GATT); } #endif - g_signal_handlers_disconnect_by_func( + count = g_signal_handlers_disconnect_by_func( dbus_characteristic.gatt, G_CALLBACK (on_handle_characteristic_indication), connection); + if (count == 0) { + fprintf(stderr, "Could not find any notification attached to this UUID"); + return GATTLIB_NOT_FOUND; + } GError *error = NULL; org_bluez_gatt_characteristic1_call_stop_notify_sync(