OSDN Git Service

shared/gatt-client: Don't clear db in case of errors
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 1 Dec 2016 09:21:01 +0000 (11:21 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 2 Dec 2016 11:31:44 +0000 (13:31 +0200)
If the db was not empty when initializing the instance set the
discovery last handle to avoid clearing the database in case of
cache validation error.

src/shared/gatt-client.c

index dc98aaa..0134721 100644 (file)
@@ -340,12 +340,8 @@ static void discovery_op_complete(struct discovery_op *op, bool success,
                                                                uint8_t err)
 {
        /* Reset remaining range */
-       if (success) {
-               if (op->last != UINT16_MAX)
-                       gatt_db_clear_range(op->client->db, op->last + 1,
-                                                               UINT16_MAX);
-       } else
-               gatt_db_clear(op->client->db);
+       if (op->last != UINT16_MAX)
+               gatt_db_clear_range(op->client->db, op->last + 1, UINT16_MAX);
 
        op->success = success;
        op->complete_func(op, success, err);
@@ -368,6 +364,7 @@ static struct discovery_op *discovery_op_create(struct bt_gatt_client *client,
        op->failure_func = failure_func;
        op->start = start;
        op->end = end;
+       op->last = gatt_db_isempty(client->db) ? 0 : UINT16_MAX;
 
        return op;
 }
@@ -386,7 +383,7 @@ static void discovery_op_unref(void *data)
        if (__sync_sub_and_fetch(&op->ref_count, 1))
                return;
 
-       if (!op->success)
+       if (!op->success && op->failure_func)
                op->failure_func(op);
 
        discovery_op_free(op);
@@ -983,6 +980,8 @@ static void discover_secondary_cb(bool success, uint8_t att_ecode,
                                success = false;
                                goto done;
                        }
+                       /* Database has changed adjust last handle */
+                       op->last = end;
                }
 
                /* Skip if service already active */
@@ -1094,6 +1093,8 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
                                success = false;
                                goto done;
                        }
+                       /* Database has changed adjust last handle */
+                       op->last = end;
                }
 
                /* Skip if service already active */
@@ -1609,13 +1610,6 @@ done:
        notify_client_ready(client, success, att_ecode);
 }
 
-static void init_fail(struct discovery_op *op)
-{
-       struct bt_gatt_client *client = op->client;
-
-       gatt_db_clear(client->db);
-}
-
 static bool gatt_client_init(struct bt_gatt_client *client, uint16_t mtu)
 {
        struct discovery_op *op;
@@ -1623,8 +1617,7 @@ static bool gatt_client_init(struct bt_gatt_client *client, uint16_t mtu)
        if (client->in_init || client->ready)
                return false;
 
-       op = discovery_op_create(client, 0x0001, 0xffff, init_complete,
-                                                               init_fail);
+       op = discovery_op_create(client, 0x0001, 0xffff, init_complete, NULL);
        if (!op)
                return false;