[PATCH v2 BlueZ 2/3] shared/gatt-client: Validate cached services

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

 



Remove services that were not found in current discovery.
---
 src/shared/gatt-client.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 0134721..a919d32 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -316,6 +316,7 @@ struct discovery_op {
 	struct queue *pending_svcs;
 	struct queue *pending_chrcs;
 	struct queue *svcs;
+	struct queue *found_svcs;
 	struct queue *ext_prop_desc;
 	struct gatt_db_attribute *cur_svc;
 	bool success;
@@ -332,13 +333,31 @@ static void discovery_op_free(struct discovery_op *op)
 	queue_destroy(op->pending_svcs, NULL);
 	queue_destroy(op->pending_chrcs, free);
 	queue_destroy(op->svcs, NULL);
+	queue_destroy(op->found_svcs, NULL);
 	queue_destroy(op->ext_prop_desc, NULL);
 	free(op);
 }
 
+static bool validate_svc_cb(struct gatt_db_attribute *attrib, void *user_data)
+{
+	struct discovery_op *op = user_data;
+	uint16_t start_h;
+
+	gatt_db_attribute_get_service_data(attrib, &start_h, NULL, NULL, NULL);
+
+	if (op->start > start_h || op->end < start_h)
+		return false;
+
+	return (queue_find(op->found_svcs, NULL, attrib) == NULL);
+}
+
 static void discovery_op_complete(struct discovery_op *op, bool success,
 								uint8_t err)
 {
+	struct bt_gatt_client *client = op->client;
+
+	gatt_db_remove_services(client->db, validate_svc_cb, op);
+
 	/* Reset remaining range */
 	if (op->last != UINT16_MAX)
 		gatt_db_clear_range(op->client->db, op->last + 1, UINT16_MAX);
@@ -358,6 +377,7 @@ static struct discovery_op *discovery_op_create(struct bt_gatt_client *client,
 	op->pending_svcs = queue_new();
 	op->pending_chrcs = queue_new();
 	op->svcs = queue_new();
+	op->found_svcs = queue_new();
 	op->ext_prop_desc = queue_new();
 	op->client = client;
 	op->complete_func = complete_func;
@@ -988,6 +1008,8 @@ static void discover_secondary_cb(bool success, uint8_t att_ecode,
 		if (!gatt_db_service_get_active(attr))
 			queue_push_tail(op->pending_svcs, attr);
 
+		queue_push_tail(op->found_svcs, attr);
+
 		/* Update last handle */
 		if (end > op->last)
 			op->last = end;
@@ -1101,6 +1123,8 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
 		if (!gatt_db_service_get_active(attr))
 			queue_push_tail(op->pending_svcs, attr);
 
+		queue_push_tail(op->found_svcs, attr);
+
 		/* Update last handle */
 		if (end > op->last)
 			op->last = end;
-- 
2.4.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