Skip to content

Commit

Permalink
TODO: CleanMe
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermartin committed Apr 8, 2024
1 parent a1da475 commit ad2700a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions common/gattlib_callback_connected_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions common/gattlib_common_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ 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
}

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);
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion common/gattlib_device_state_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions dbus/gattlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ad2700a

Please sign in to comment.