From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ v1 5/5] shared/gatt-db: Add clear functions
Date: Wed, 26 Nov 2014 15:03:12 -0800 [thread overview]
Message-ID: <1417042992-10142-6-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1417042992-10142-1-git-send-email-armansito@chromium.org>
This patch introduces gatt_db_clear and gatt_db_clear_range functions
for removing services from the database.
---
src/shared/gatt-db.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/shared/gatt-db.h | 3 +++
2 files changed, 48 insertions(+)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 0c24904..2515e5a 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -305,6 +305,51 @@ bool gatt_db_remove_service(struct gatt_db *db,
return true;
}
+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;
+}
+
+struct clear_range {
+ uint16_t start, end;
+};
+
+static bool match_range(const void *a, const void *b)
+{
+ const struct gatt_db_service *service = a;
+ const struct clear_range *range = b;
+ uint16_t svc_start, svc_end;
+
+ svc_start = service->attributes[0]->handle;
+ svc_end = service->attributes[0]->handle + service->num_handles - 1;
+
+ return svc_start <= range->end && svc_end >= range->start;
+}
+
+bool gatt_db_clear_range(struct gatt_db *db, uint16_t start_handle,
+ uint16_t end_handle)
+{
+ struct clear_range range;
+
+ if (!db || start_handle > end_handle)
+ return false;
+
+ range.start = start_handle;
+ range.end = end_handle;
+
+ queue_remove_all(db->services, match_range, &range,
+ gatt_db_service_destroy);
+
+ return true;
+}
+
struct insert_loc_data {
struct gatt_db_service *cur;
uint16_t start, end;
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index c9e3b59..ea9f2dc 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -34,6 +34,9 @@ struct gatt_db_attribute *gatt_db_add_service(struct gatt_db *db,
bool gatt_db_remove_service(struct gatt_db *db,
struct gatt_db_attribute *attrib);
+bool gatt_db_clear(struct gatt_db *db);
+bool gatt_db_clear_range(struct gatt_db *db, uint16_t start_handle,
+ uint16_t end_handle);
struct gatt_db_attribute *gatt_db_insert_service(struct gatt_db *db,
uint16_t handle,
--
2.2.0.rc0.207.ga3a616c
next prev parent reply other threads:[~2014-11-26 23:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 23:03 [PATCH BlueZ v1 0/5] shared/gatt-db: Add support for client role Arman Uguray
2014-11-26 23:03 ` [PATCH BlueZ v1 1/5] shared/gatt-db: Add high-level functions for client Arman Uguray
2014-11-26 23:03 ` [PATCH BlueZ v1 2/5] shared: Add function to insert element after entry Arman Uguray
2014-11-26 23:03 ` [PATCH BlueZ v1 3/5] unit/test-queue: Add /queue/insert_after test Arman Uguray
2014-11-26 23:03 ` [PATCH BlueZ v1 4/5] shared/gatt-db: Add gatt_db_insert_service function Arman Uguray
2014-11-26 23:03 ` Arman Uguray [this message]
2014-11-28 12:06 ` [PATCH BlueZ v1 0/5] shared/gatt-db: Add support for client role 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=1417042992-10142-6-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).