linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ v3 7/8] core: gatt: Use "claimed" instead of "active"
Date: Tue, 13 Jan 2015 19:31:06 -0800	[thread overview]
Message-ID: <1421206267-26369-8-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1421206267-26369-1-git-send-email-armansito@chromium.org>

Using the "active" state of a gatt-db service to mark a service as
claimed by a profile somewhat abuses the API and has the additional
side-effect of sending a service_removed event. This causes errors in
the way btd_device manages profile/service lifetime. To fix this, this
patch uses the new "claimed" state to mark a service as claimed.

Also included is a minor fix to btd_gatt_client_* APIs that early return
if the client is not yet ready.
---
 src/device.c      | 7 +++++--
 src/gatt-client.c | 9 ++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/device.c b/src/device.c
index 9d1a480..1253986 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2566,7 +2566,7 @@ static void dev_probe_gatt(struct btd_profile *p, void *user_data)
 	}
 
 	/* Mark service as claimed */
-	gatt_db_service_set_active(data->cur_attr, false);
+	gatt_db_service_set_claimed(data->cur_attr, true);
 
 	data->dev->services = g_slist_append(data->dev->services, service);
 }
@@ -2603,8 +2603,11 @@ static void dev_probe_gatt_profile(struct gatt_db_attribute *attr,
 	}
 
 	/* Don't probe the profiles if a matching service already exists. */
-	if (find_service_with_uuid(data->dev->services, data->cur_uuid))
+	if (find_service_with_uuid(data->dev->services, data->cur_uuid)) {
+		/* Mark the service as claimed by the existing profile. */
+		gatt_db_service_set_claimed(data->cur_attr, true);
 		return;
+	}
 
 	btd_profile_foreach(dev_probe_gatt, data);
 
diff --git a/src/gatt-client.c b/src/gatt-client.c
index a12c656..cb8ddf6 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -52,6 +52,7 @@
 
 struct btd_gatt_client {
 	struct btd_device *device;
+	bool ready;
 	char devaddr[18];
 	struct gatt_db *db;
 	struct bt_gatt_client *gatt;
@@ -1373,7 +1374,7 @@ static void export_service(struct gatt_db_attribute *attr, void *user_data)
 	struct btd_gatt_client *client = user_data;
 	struct service *service;
 
-	if (!gatt_db_service_get_active(attr))
+	if (gatt_db_service_get_claimed(attr))
 		return;
 
 	service = service_create(attr, client);
@@ -1461,13 +1462,15 @@ void btd_gatt_client_ready(struct btd_gatt_client *client)
 	bt_gatt_client_unref(client->gatt);
 	client->gatt = bt_gatt_client_ref(gatt);
 
+	client->ready = true;
+
 	create_services(client);
 }
 
 void btd_gatt_client_service_added(struct btd_gatt_client *client,
 					struct gatt_db_attribute *attrib)
 {
-	if (!client)
+	if (!client || !attrib || !client->ready)
 		return;
 
 	export_service(attrib, client);
@@ -1486,7 +1489,7 @@ void btd_gatt_client_service_removed(struct btd_gatt_client *client,
 {
 	uint16_t start_handle, end_handle;
 
-	if (!client || !attrib)
+	if (!client || !attrib || !client->ready)
 		return;
 
 	gatt_db_attribute_get_service_handles(attrib, &start_handle,
-- 
2.2.0.rc0.207.ga3a616c


  parent reply	other threads:[~2015-01-14  3:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14  3:30 [PATCH BlueZ v3 0/8] Implement doc/gatt-api.txt for client Arman Uguray
2015-01-14  3:31 ` [PATCH BlueZ v3 1/8] shared/gatt-db: Add service getter by UUID Arman Uguray
2015-01-14  3:31 ` [PATCH BlueZ v3 2/8] core: device: Fix GATT profile probing Arman Uguray
2015-01-14  3:31 ` [PATCH BlueZ v3 3/8] core: device: Fix broken GATT UUID management Arman Uguray
2015-01-14 13:17   ` Luiz Augusto von Dentz
2015-01-14 19:38     ` Arman Uguray
2015-01-16  0:58       ` Arman Uguray
2015-01-16  8:53         ` Luiz Augusto von Dentz
2015-01-14  3:31 ` [PATCH BlueZ v3 4/8] profiles/gap: Fix probe/accept behavior Arman Uguray
2015-01-14  3:31 ` [PATCH BlueZ v3 5/8] core: service: Remove GATT handle logic Arman Uguray
2015-01-14  3:31 ` [PATCH BlueZ v3 6/8] shared/gatt-db: Add "claimed" field to services Arman Uguray
2015-01-14  3:31 ` Arman Uguray [this message]
2015-01-14  3:31 ` [PATCH BlueZ v3 8/8] doc/gatt-api.txt: Update error names Arman Uguray
2015-01-16 14:21 ` [PATCH BlueZ v3 0/8] Implement doc/gatt-api.txt for client Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421206267-26369-8-git-send-email-armansito@chromium.org \
    --to=armansito@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).