[PATCHv1 4/4] gatt: Add remove_service function to gatt-db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It will remove service with given handle. Return true if service
was found and removed, otherwise false.
---
 src/shared/gatt-db.c | 21 +++++++++++++++++++++
 src/shared/gatt-db.h | 11 +++++++++++
 2 files changed, 32 insertions(+)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 0094616..7dc5908 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -50,6 +50,13 @@ struct gatt_db_service {
 	struct gatt_db_attribute **attributes;
 };
 
+static bool match_service_by_handle(const void *data, const void *user_data)
+{
+	const struct gatt_db_service *service = data;
+
+	return service->attributes[0]->handle == PTR_TO_INT(user_data);
+}
+
 struct gatt_db *gatt_db_new(void)
 {
 	struct gatt_db *db;
@@ -166,3 +173,17 @@ uint16_t gatt_db_new_service(struct gatt_db *db, const bt_uuid_t *uuid,
 
 	return service->attributes[0]->handle;
 }
+
+bool gatt_db_remove_service(struct gatt_db *db, uint16_t handle)
+{
+	struct gatt_db_service *service;
+
+	service = queue_remove_if(db->services, match_service_by_handle,
+							INT_TO_PTR(handle));
+	if (!service)
+		return false;
+
+	gatt_db_service_destroy(service);
+
+	return true;
+}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 1656bb0..a98684b 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -50,3 +50,14 @@ void gatt_db_destroy(struct gatt_db *db);
  */
 uint16_t gatt_db_new_service(struct gatt_db *db, const bt_uuid_t *uuid,
 					bool primary, uint16_t num_handles);
+
+/*
+ * gatt_db_remove_service - remove service from attribute database
+ *
+ * @db - gatt database
+ * @handle - service handle
+ *
+ * Return true if service was successfully removed. In case of error false is
+ * returned
+ */
+bool gatt_db_remove_service(struct gatt_db *db, uint16_t handle);
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux