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);
op->failure_func = failure_func;
op->start = start;
op->end = end;
+ op->last = gatt_db_isempty(client->db) ? 0 : UINT16_MAX;
return op;
}
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);
success = false;
goto done;
}
+ /* Database has changed adjust last handle */
+ op->last = end;
}
/* Skip if service already active */
success = false;
goto done;
}
+ /* Database has changed adjust last handle */
+ op->last = end;
}
/* Skip if service already active */
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;
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;