linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range
Date: Thu,  1 Dec 2016 22:40:29 +0200	[thread overview]
Message-ID: <20161201204030.27626-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20161201204030.27626-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes gatt_db_clear much simpler while making gatt_db_clear_range
detect full database clear resetting next_handle properly if the
database is empty.
---
 src/shared/gatt-db.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 513451f..8ef6f3b 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -410,14 +410,7 @@ bool gatt_db_remove_service(struct gatt_db *db,
 
 bool gatt_db_clear(struct gatt_db *db)
 {
-	if (!db)
-		return false;
-
-	queue_remove_all(db->services, NULL, NULL, gatt_db_service_destroy);
-
-	db->next_handle = 0;
-
-	return true;
+	return gatt_db_clear_range(db, 1, UINT16_MAX);
 }
 
 static void gatt_db_service_get_handles(const struct gatt_db_service *service,
@@ -455,12 +448,23 @@ bool gatt_db_clear_range(struct gatt_db *db, uint16_t start_handle,
 	if (!db || start_handle > end_handle)
 		return false;
 
+	/* Check if it is a full clear */
+	if (start_handle == 1 && end_handle == UINT16_MAX) {
+		queue_remove_all(db->services, NULL, NULL,
+						gatt_db_service_destroy);
+		goto done;
+	}
+
 	range.start = start_handle;
 	range.end = end_handle;
 
 	queue_remove_all(db->services, match_range, &range,
 						gatt_db_service_destroy);
 
+done:
+	if (gatt_db_isempty(db))
+		db->next_handle = 0;
+
 	return true;
 }
 
-- 
2.9.3


  reply	other threads:[~2016-12-01 20:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01 20:40 [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
2016-12-01 20:40 ` Luiz Augusto von Dentz [this message]
2016-12-01 20:40 ` [PATCH BlueZ 3/3] shared/gatt-client: Don't clear db in case of errors Luiz Augusto von Dentz
2016-12-02 11:54 ` [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly 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=20161201204030.27626-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --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).