shared/gatt-client: Fix tracking current service during discovery 55/204955/1
authorAndrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
Thu, 22 Mar 2018 15:21:01 +0000 (16:21 +0100)
committerAmit Purwar <amit.purwar@samsung.com>
Fri, 26 Apr 2019 10:53:47 +0000 (16:23 +0530)
We should mark service as completed before trying to insert another
characteristic - in case inserting characteristic for new service
fails, previous one won't be discarded.

Change-Id: I14b6af270aebc358a88ffd2419c39573a1728b31
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
src/shared/gatt-client.c

index f699d25..0c24a6f 100644 (file)
@@ -647,6 +647,19 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
                struct gatt_db_attribute *svc;
                uint16_t start, end;
 
+               /* Adjust current service */
+               svc = gatt_db_get_service(client->db, chrc_data->value_handle);
+               if (op->cur_svc != svc) {
+                       if (op->cur_svc) {
+                               queue_remove(op->pending_svcs, op->cur_svc);
+
+                               /* Done with the current service */
+                               gatt_db_service_set_active(op->cur_svc, true);
+                       }
+
+                       op->cur_svc = svc;
+               }
+
                attr = gatt_db_insert_characteristic(client->db,
                                                        chrc_data->value_handle,
                                                        &chrc_data->uuid, 0,
@@ -664,19 +677,6 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
                                                        chrc_data->value_handle)
                        goto failed;
 
-               /* Adjust current service */
-               svc = gatt_db_get_service(client->db, chrc_data->value_handle);
-               if (op->cur_svc != svc) {
-                       if (op->cur_svc) {
-                               queue_remove(op->pending_svcs, op->cur_svc);
-
-                               /* Done with the current service */
-                               gatt_db_service_set_active(op->cur_svc, true);
-                       }
-
-                       op->cur_svc = svc;
-               }
-
                gatt_db_attribute_get_service_handles(svc, &start, &end);
 
                /*