From 0400f2132d064a2e88e08f2ad9513203979bca1c Mon Sep 17 00:00:00 2001 From: Lukasz Rymanowski Date: Tue, 2 Sep 2014 12:09:56 +0200 Subject: [PATCH] android/gatt: Notify apps interested in autoconnect about connection This patch makes sure that application interested in auto connect for particular devices, will be notified about new connections. --- android/gatt.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/android/gatt.c b/android/gatt.c index acbb42339..4cc262179 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -1373,6 +1373,21 @@ static struct app_connection *find_conn(const bdaddr_t *addr, int32_t app_id) &conn_match); } +static void create_app_connection(void *data, void *user_data) +{ + struct gatt_device *dev = user_data; + struct gatt_app *app; + + app = find_app_by_id(PTR_TO_INT(data)); + if (!app) + return; + + DBG("Autoconnect application id=%d", app->id); + + if (!find_conn(&dev->bdaddr, PTR_TO_INT(data))) + create_connection(dev, app); +} + static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) { struct gatt_device *dev = user_data; @@ -1419,7 +1434,8 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) device_set_state(dev, DEVICE_CONNECTED); - bt_auto_connect_remove(&dev->bdaddr); + if (queue_isempty(dev->autoconnect_apps)) + bt_auto_connect_remove(&dev->bdaddr); /* Send exchange mtu request as we assume being client and server */ /* TODO: Dont exchange mtu if no client apps */ @@ -1444,6 +1460,12 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) status = GATT_SUCCESS; reply: + /* + * Make sure there are app_connections for all apps interested in auto + * connect to that device + */ + queue_foreach(dev->autoconnect_apps, create_app_connection, dev); + if (!dev->conn_cnt) { struct app_connection *conn; -- 2.47.3