From 99309507de8f43a83e353e25e72a66ce28105191 Mon Sep 17 00:00:00 2001 From: Jakub Tyszkowski Date: Mon, 28 Apr 2014 15:32:02 +0200 Subject: [PATCH] android/gatt: Rename connection list This list will be used for both, client and server apps connections. --- android/gatt.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/android/gatt.c b/android/gatt.c index 6d29ccb6b..14fd16406 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -150,7 +150,7 @@ static bool scanning = false; static struct queue *gatt_apps = NULL; static struct queue *gatt_devices = NULL; -static struct queue *client_connections = NULL; +static struct queue *app_connections = NULL; static int32_t app_id = 1; @@ -318,7 +318,7 @@ static bool match_connection_by_device_and_app(const void *data, static struct connection *find_connection_by_id(int32_t conn_id) { - return queue_find(client_connections, match_connection_by_id, + return queue_find(app_connections, match_connection_by_id, INT_TO_PTR(conn_id)); } @@ -709,10 +709,10 @@ cleanup: static void device_disconnect_clients(struct gatt_device *dev) { /* Notify disconnection to all clients */ - queue_foreach(client_connections, disconnect_notify_by_device, dev); + queue_foreach(app_connections, disconnect_notify_by_device, dev); /* Remove all clients by given device's */ - queue_remove_all(client_connections, match_connection_by_device, dev, + queue_remove_all(app_connections, match_connection_by_device, dev, destroy_connection); } @@ -970,8 +970,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) reply: data.dev = dev; data.status = status; - queue_foreach(client_connections, send_app_connect_notifications, - &data); + queue_foreach(app_connections, send_app_connect_notifications, &data); device_unref(dev); /* Check if we should restart scan */ @@ -1139,7 +1138,7 @@ static struct connection *create_connection(struct gatt_device *device, new_conn->app = app; new_conn->id = last_conn_id++; - if (!queue_push_head(client_connections, new_conn)) { + if (!queue_push_head(app_connections, new_conn)) { error("gatt: Cannot push client on the client queue!?"); free(new_conn); @@ -1155,7 +1154,7 @@ static struct connection *create_connection(struct gatt_device *device, static void trigger_disconnection(struct connection *connection) { /* Notify client */ - if (queue_remove(client_connections, connection)) + if (queue_remove(app_connections, connection)) send_app_disconnect_notify(connection, GATT_SUCCESS); destroy_connection(connection); @@ -1166,12 +1165,12 @@ static void app_disconnect_devices(struct gatt_app *client) struct connection *conn; /* find every connection for client record and trigger disconnect */ - conn = queue_remove_if(client_connections, match_connection_by_app, + conn = queue_remove_if(app_connections, match_connection_by_app, client); while (conn) { trigger_disconnection(conn); - conn = queue_remove_if(client_connections, + conn = queue_remove_if(app_connections, match_connection_by_app, client); } } @@ -1250,9 +1249,8 @@ static struct connection *find_conn(const bdaddr_t *addr, int32_t app_id, conn_match.device = dev; conn_match.app = app; - return queue_find(client_connections, - match_connection_by_device_and_app, - &conn_match); + return queue_find(app_connections, match_connection_by_device_and_app, + &conn_match); } static void handle_client_connect(const void *buf, uint16_t len) @@ -1287,9 +1285,8 @@ static void handle_client_connect(const void *buf, uint16_t len) conn_match.device = device; conn_match.app = client; - conn = queue_find(client_connections, - match_connection_by_device_and_app, - &conn_match); + conn = queue_find(app_connections, match_connection_by_device_and_app, + &conn_match); if (!conn) { conn = create_connection(device, client); if (!conn) { @@ -3482,11 +3479,11 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr) gatt_devices = queue_new(); gatt_apps = queue_new(); - client_connections = queue_new(); + app_connections = queue_new(); listen_clients = queue_new(); if (!gatt_devices || !gatt_apps || !listen_clients || - !client_connections) { + !app_connections) { error("gatt: Failed to allocate memory for queues"); queue_destroy(gatt_apps, NULL); @@ -3495,8 +3492,8 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr) queue_destroy(gatt_devices, NULL); gatt_devices = NULL; - queue_destroy(client_connections, NULL); - client_connections = NULL; + queue_destroy(app_connections, NULL); + app_connections = NULL; queue_destroy(listen_clients, NULL); listen_clients = NULL; @@ -3524,8 +3521,8 @@ void bt_gatt_unregister(void) queue_destroy(gatt_apps, destroy_gatt_app); gatt_apps = NULL; - queue_destroy(client_connections, destroy_connection); - client_connections = NULL; + queue_destroy(app_connections, destroy_connection); + app_connections = NULL; queue_destroy(gatt_devices, destroy_device); gatt_devices = NULL; -- 2.47.3