From 5f72973e05277ade59c91fd959aecd92fae09773 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Mon, 8 Apr 2024 13:04:30 +0200 Subject: [PATCH] TODO: CleanMe --- common/gattlib_callback_connected_device.c | 12 ++++++------ common/gattlib_callback_disconnected_device.c | 6 +++--- common/gattlib_common.c | 2 +- common/gattlib_common_adapter.c | 12 ++++++------ common/gattlib_device_state_management.c | 2 +- dbus/gattlib.c | 10 +++++----- dbus/gattlib_adapter.c | 4 ++-- dbus/gattlib_notification.c | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/common/gattlib_callback_connected_device.c b/common/gattlib_callback_connected_device.c index d4e7611..6be62e1 100644 --- a/common/gattlib_callback_connected_device.c +++ b/common/gattlib_callback_connected_device.c @@ -48,12 +48,12 @@ void gattlib_connected_device_python_callback(gattlib_adapter_t* adapter, const static gpointer _gattlib_connected_device_thread(gpointer data) { gattlib_connection_t* connection = data; - puts("_gattlib_connected_device_thread A"); + //puts("_gattlib_connected_device_thread A"); const gchar *device_mac_address = org_bluez_device1_get_address(connection->backend.device); // Mutex to ensure the handler is valid g_rec_mutex_lock(&m_gattlib_mutex); - puts("_gattlib_connected_device_thread B"); + //puts("_gattlib_connected_device_thread B"); if (!gattlib_connection_is_connected(connection)) { GATTLIB_LOG(GATTLIB_ERROR, "_gattlib_connected_device_thread: Device is not connected (state:%s)", @@ -68,22 +68,22 @@ static gpointer _gattlib_connected_device_thread(gpointer data) { return NULL; } - puts("_gattlib_connected_device_thread C"); + //puts("_gattlib_connected_device_thread C"); // Ensure we increment device reference counter to prevent the device/connection is freed during the execution gattlib_device_ref(connection->device); // We need to release the lock here to ensure the connection callback that is actually // doing the application sepcific work is not locking the BLE state. g_rec_mutex_unlock(&m_gattlib_mutex); - puts("_gattlib_connected_device_thread D"); + //puts("_gattlib_connected_device_thread D"); connection->on_connection.callback.connection_handler( connection->device->adapter, device_mac_address, connection, 0 /* no error */, connection->on_connection.user_data); - puts("_gattlib_connected_device_thread E"); + //puts("_gattlib_connected_device_thread E"); gattlib_device_unref(connection->device); - puts("_gattlib_connected_device_thread DONE"); + //puts("_gattlib_connected_device_thread DONE"); return NULL; } diff --git a/common/gattlib_callback_disconnected_device.c b/common/gattlib_callback_disconnected_device.c index efc25b0..c72f577 100644 --- a/common/gattlib_callback_disconnected_device.c +++ b/common/gattlib_callback_disconnected_device.c @@ -31,9 +31,9 @@ void gattlib_disconnected_device_python_callback(gattlib_connection_t* connectio #endif void gattlib_on_disconnected_device(gattlib_connection_t* connection) { - puts("--- gattlib_on_disconnected_device"); + //puts("--- gattlib_on_disconnected_device"); g_rec_mutex_lock(&m_gattlib_mutex); - puts("--- gattlib_on_disconnected_device A"); + //puts("--- gattlib_on_disconnected_device A"); if (!gattlib_device_is_valid(connection->device)) { GATTLIB_LOG(GATTLIB_ERROR, "gattlib_on_disconnected_device: Device not valid"); @@ -65,5 +65,5 @@ void gattlib_on_disconnected_device(gattlib_connection_t* connection) { g_cond_broadcast(&m_gattlib_signal.condition); g_mutex_unlock(&m_gattlib_signal.mutex); - puts("--- gattlib_on_disconnected_device DONE"); + //puts("--- gattlib_on_disconnected_device DONE"); } diff --git a/common/gattlib_common.c b/common/gattlib_common.c index 969ad02..7d58b86 100644 --- a/common/gattlib_common.c +++ b/common/gattlib_common.c @@ -266,7 +266,7 @@ void gattlib_free_mem(void *ptr) { int gattlib_device_ref(gattlib_device_t* device) { g_rec_mutex_lock(&m_gattlib_mutex); device->reference_counter++; - printf("DEVICE INC REF_COUNTER:%d\n", device->reference_counter); + //printf("DEVICE INC REF_COUNTER:%d\n", device->reference_counter); g_rec_mutex_unlock(&m_gattlib_mutex); return GATTLIB_SUCCESS; } diff --git a/common/gattlib_common_adapter.c b/common/gattlib_common_adapter.c index 0e00d9c..4f14821 100644 --- a/common/gattlib_common_adapter.c +++ b/common/gattlib_common_adapter.c @@ -110,7 +110,7 @@ struct _connection_is_connected { static gint _is_device_connection(gconstpointer a, gconstpointer b) { const gattlib_device_t* device = a; - printf("- %s connection:%p / %p\n", device->device_id, &device->connection); + //printf("- %s connection:%p / %p\n", device->device_id, &device->connection); return (&device->connection == b) ? 0 : -1; // We need to return 0 when it matches } @@ -118,16 +118,16 @@ static void _gattlib_connection_is_connected(gpointer data, gpointer user_data) gattlib_adapter_t* adapter = data; struct _connection_is_connected* connection_is_connected = user_data; - printf("_gattlib_connection_is_connected: Check device in adapter:%s\n", adapter->id); + //printf("_gattlib_connection_is_connected: Check device in adapter:%s\n", adapter->id); GSList *device_entry = g_slist_find_custom(adapter->devices, connection_is_connected->connection, _is_device_connection); if (device_entry == NULL) { - printf("_gattlib_connection_is_connected: Did not find device %s\n", connection_is_connected->connection->device->device_id); + //printf("_gattlib_connection_is_connected: Did not find device %s\n", connection_is_connected->connection->device->device_id); return; } gattlib_device_t* device = device_entry->data; - printf("_gattlib_connection_is_connected: device %s state is %s\n", device->device_id, device_state_str[device->state]); + //printf("_gattlib_connection_is_connected: device %s state is %s\n", device->device_id, device_state_str[device->state]); connection_is_connected->is_connected = (device->state == CONNECTED); } @@ -138,9 +138,9 @@ bool gattlib_connection_is_connected(gattlib_connection_t* connection) { }; g_rec_mutex_lock(&m_gattlib_mutex); - printf("gattlib_connection_is_connected A"); + //printf("gattlib_connection_is_connected A"); g_slist_foreach(m_adapter_list, _gattlib_connection_is_connected, &connection_is_connected); - printf("gattlib_connection_is_connected B"); + //printf("gattlib_connection_is_connected B"); g_rec_mutex_unlock(&m_gattlib_mutex); return connection_is_connected.is_connected; diff --git a/common/gattlib_device_state_management.c b/common/gattlib_device_state_management.c index ed3cb06..27a198b 100644 --- a/common/gattlib_device_state_management.c +++ b/common/gattlib_device_state_management.c @@ -149,7 +149,7 @@ int gattlib_devices_free(gattlib_adapter_t* adapter) { int gattlib_device_unref(gattlib_device_t* device) { g_rec_mutex_lock(&m_gattlib_mutex); device->reference_counter--; - printf("DEVICE DEC REF_COUNTER:%d\n", device->reference_counter); + //printf("DEVICE DEC REF_COUNTER:%d\n", device->reference_counter); if (device->reference_counter > 0) { goto EXIT; } diff --git a/dbus/gattlib.c b/dbus/gattlib.c index 4dac84e..e98d500 100644 --- a/dbus/gattlib.c +++ b/dbus/gattlib.c @@ -48,9 +48,9 @@ static void _on_device_connect(gattlib_connection_t* connection) { gattlib_device_set_state(connection->device->adapter, connection->device->device_id, CONNECTED); - puts("Go gattlib_on_connected_device"); + //puts("Go gattlib_on_connected_device"); gattlib_on_connected_device(connection); - puts("Go gattlib_on_connected_device DONE"); + //puts("Go gattlib_on_connected_device DONE"); EXIT: g_rec_mutex_unlock(&m_gattlib_mutex); @@ -251,7 +251,7 @@ int gattlib_connect(gattlib_adapter_t* adapter, const char *dst, } // Register a handle for notification - printf("DEVICE CONNECT property change 3\n"); + //printf("DEVICE CONNECT property change 3\n"); device->connection.backend.on_handle_device_property_change_id = g_signal_connect(bluez_device, "g-properties-changed", G_CALLBACK(on_handle_device_property_change), @@ -319,7 +319,7 @@ int gattlib_connect(gattlib_adapter_t* adapter, const char *dst, void gattlib_connection_free(gattlib_connection_t* connection) { char* device_id; - puts("gattlib_connection_free()"); + //puts("gattlib_connection_free()"); device_id = connection->device->device_id; @@ -355,7 +355,7 @@ void gattlib_connection_free(gattlib_connection_t* connection) { // Mark the device has disconnected gattlib_device_set_state(connection->device->adapter, device_id, DISCONNECTED); - puts("gattlib_connection_free() DONE"); + //puts("gattlib_connection_free() DONE"); } int gattlib_disconnect(gattlib_connection_t* connection, bool wait_disconnection) { diff --git a/dbus/gattlib_adapter.c b/dbus/gattlib_adapter.c index 7d80efe..c8fca6d 100644 --- a/dbus/gattlib_adapter.c +++ b/dbus/gattlib_adapter.c @@ -705,7 +705,7 @@ int gattlib_adapter_close(gattlib_adapter_t* adapter) { int gattlib_adapter_ref(gattlib_adapter_t* adapter) { g_rec_mutex_lock(&m_gattlib_mutex); adapter->reference_counter++; - printf("ADAPTER INC REF_COUNTER:%d\n", adapter->reference_counter); + //printf("ADAPTER INC REF_COUNTER:%d\n", adapter->reference_counter); g_rec_mutex_unlock(&m_gattlib_mutex); return GATTLIB_SUCCESS; } @@ -715,7 +715,7 @@ int gattlib_adapter_unref(gattlib_adapter_t* adapter) { g_rec_mutex_lock(&m_gattlib_mutex); adapter->reference_counter--; - printf("ADAPTER DEC REF_COUNTER:%d\n", adapter->reference_counter); + //printf("ADAPTER DEC REF_COUNTER:%d\n", adapter->reference_counter); if (adapter->reference_counter > 0) { goto EXIT; diff --git a/dbus/gattlib_notification.c b/dbus/gattlib_notification.c index 1d20f6e..f282375 100644 --- a/dbus/gattlib_notification.c +++ b/dbus/gattlib_notification.c @@ -183,7 +183,7 @@ static int connect_signal_to_characteristic_uuid(gattlib_connection_t* connectio #if BLUEZ_VERSION > BLUEZ_VERSIONS(5, 40) else if (dbus_characteristic.type == TYPE_BATTERY_LEVEL) { // Register a handle for notification - printf("DEVICE CONNECT property change 1\n"); + //printf("DEVICE CONNECT property change 1\n"); g_signal_connect(dbus_characteristic.battery, "g-properties-changed", G_CALLBACK (on_handle_battery_level_property_change), @@ -197,7 +197,7 @@ static int connect_signal_to_characteristic_uuid(gattlib_connection_t* connectio #endif // Register a handle for notification - printf("DEVICE CONNECT property change 2\n"); + //printf("DEVICE CONNECT property change 2\n"); gulong signal_id = g_signal_connect(dbus_characteristic.gatt, "g-properties-changed", G_CALLBACK(callback),