Thread (9 messages) 9 messages, 1 author, 2016-09-13

[PATCH BlueZ 4/8] gap: Implement disconnect callback

flat view
STALE3690d

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2016-09-12 14:07:35
Subsystem: the rest · Maintainer: Linus Torvalds

From: Luiz Augusto von Dentz <redacted>

This implements the profile disconnect callback using it to cleanup
existing references of bt_gatt_client and gatt_db.
---
 profiles/gap/gas.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 93a9a6d..2077ed9 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -251,6 +251,15 @@ static void foreach_gap_service(struct gatt_db_attribute *attr, void *user_data)
 	handle_gap_service(gas);
 }
 
+static void gas_reset(struct gas *gas)
+{
+	gas->attr = NULL;
+	gatt_db_unref(gas->db);
+	gas->db = NULL;
+	bt_gatt_client_unref(gas->client);
+	gas->client = NULL;
+}
+
 static int gap_driver_accept(struct btd_service *service)
 {
 	struct btd_device *device = btd_service_get_device(service);
@@ -268,11 +277,6 @@ static int gap_driver_accept(struct btd_service *service)
 		return -1;
 	}
 
-	/* Clean-up any old client/db and acquire the new ones */
-	gas->attr = NULL;
-	gatt_db_unref(gas->db);
-	bt_gatt_client_unref(gas->client);
-
 	gas->db = gatt_db_ref(db);
 	gas->client = bt_gatt_client_ref(client);
 
@@ -282,6 +286,7 @@ static int gap_driver_accept(struct btd_service *service)
 
 	if (!gas->attr) {
 		error("GAP attribute not found");
+		gas_reset(gas);
 		return -1;
 	}
 
@@ -290,12 +295,24 @@ static int gap_driver_accept(struct btd_service *service)
 	return 0;
 }
 
+static int gap_disconnect(struct btd_service *service)
+{
+	struct gas *gas = btd_service_get_user_data(service);
+
+	gas_reset(gas);
+
+	btd_service_disconnecting_complete(service, 0);
+
+	return 0;
+}
+
 static struct btd_profile gap_profile = {
 	.name		= "gap-profile",
 	.remote_uuid	= GAP_UUID,
 	.device_probe	= gap_driver_probe,
 	.device_remove	= gap_driver_remove,
-	.accept		= gap_driver_accept
+	.accept		= gap_driver_accept,
+	.disconnect	= gap_disconnect,
 };
 
 static int gap_init(void)
-- 
2.7.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help