diff --git a/android/gatt.c b/android/gatt.c
index f9cef4f..33eeba9 100644
--- a/android/gatt.c
+++ b/android/gatt.c
send_server_connection_state_notify(conn, !status);
}
-static void notify_app_disconnect_status_by_device(void *data, void *user_data)
+static void destroy_connection(void *data)
{
struct app_connection *conn = data;
- struct gatt_device *dev = user_data;
- if (dev != conn->device || !conn->app)
- return;
+ if (conn->timeout_id > 0)
+ g_source_remove(conn->timeout_id);
- switch (dev->state) {
+ switch (conn->device->state) {
case DEVICE_CONNECTED:
notify_app_disconnect_status(conn, GATT_SUCCESS);
break;
case DEVICE_DISCONNECTED:
break;
}
-}
-
-static void destroy_connection(void *data)
-{
- struct app_connection *conn = data;
-
- if (conn->timeout_id > 0)
- g_source_remove(conn->timeout_id);
if (!queue_find(app_connections, match_connection_by_device,
conn->device))
free(conn);
}
-static void device_disconnect_clients(struct gatt_device *dev)
-{
- /* Notify disconnection to all clients */
- queue_foreach(app_connections, notify_app_disconnect_status_by_device,
- dev);
-
- /* Remove all clients by given device's */
- queue_remove_all(app_connections, match_connection_by_device, dev,
- destroy_connection);
-}
-
static gboolean disconnected_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
if (!getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len))
DBG("%s (%d)", strerror(err), err);
- device_disconnect_clients(dev);
+ queue_remove_all(app_connections, match_connection_by_device, dev,
+ destroy_connection);
return FALSE;
}
status);
}
-static void trigger_disconnection(struct app_connection *connection)
-{
- /* Notify client */
- if (queue_remove(app_connections, connection))
- notify_app_disconnect_status(connection, GATT_SUCCESS);
-
- destroy_connection(connection);
-}
-
-static void app_disconnect_devices(struct gatt_app *client)
-{
- struct app_connection *conn;
-
- /* find every connection for client record and trigger disconnect */
- conn = queue_remove_if(app_connections, match_connection_by_app,
- client);
- while (conn) {
- trigger_disconnection(conn);
-
- conn = queue_remove_if(app_connections,
- match_connection_by_app, client);
- }
-}
-
static int connect_bredr(struct gatt_device *dev)
{
BtIOSecLevel sec_level;
}
/* Destroy app connections with proper notifications for this app. */
- app_disconnect_devices(cl);
+ queue_remove_all(app_connections, match_connection_by_app, cl,
+ destroy_connection);
destroy_gatt_app(cl);
return HAL_STATUS_SUCCESS;
DBG("");
/* TODO: should we care to match also bdaddr when conn_id is unique? */
- conn = find_connection_by_id(cmd->conn_id);
+ conn = queue_remove_if(app_connections, match_connection_by_id,
+ INT_TO_PTR(cmd->conn_id));
if (conn)
- trigger_disconnection(conn);
+ destroy_connection(conn);
status = HAL_STATUS_SUCCESS;
app = queue_find(gatt_apps, match_app_by_id,
INT_TO_PTR(test_client_if));
if (app)
- app_disconnect_devices(app);
+ queue_remove_all(app_connections,
+ match_connection_by_app, app,
+ destroy_connection);
status = HAL_STATUS_SUCCESS;
break;
DBG("");
/* TODO: should we care to match also bdaddr when conn_id is unique? */
- conn = find_connection_by_id(cmd->conn_id);
+ conn = queue_remove_if(app_connections, match_connection_by_id,
+ INT_TO_PTR(cmd->conn_id));
if (conn)
- trigger_disconnection(conn);
+ destroy_connection(conn);
status = HAL_STATUS_SUCCESS;
match.device = device;
match.app = app;
- conn = queue_find(app_connections, match_connection_by_device_and_app,
- &match);
+ conn = queue_remove_if(app_connections,
+ match_connection_by_device_and_app, &match);
if (!conn)
return false;
- trigger_disconnection(conn);
+ destroy_connection(conn);
return true;
}