Bluetooth: add destroy callback to indication

Adds a `destroy` callback to the `struct bt_gatt_indicate_params` which
is used to signify to the application that the indication operation has
completed and the struct instance can be freed/destroyed.

This is required as the number of indication value callbacks that will
be triggered is not known by the caller when the `conn` parameter is
`NULL`.

Tracking when this callback should be run is mananged by a private
reference counter inside the struct.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2020-10-20 22:40:41 +10:00 committed by Carles Cufí
commit ffab099eb9
7 changed files with 23 additions and 1 deletions

View file

@ -1900,7 +1900,11 @@ static void gatt_indicate_rsp(struct bt_conn *conn, uint8_t err,
{
struct bt_gatt_indicate_params *params = user_data;
params->_ref--;
params->func(conn, params, err);
if (params->destroy && (params->_ref == 0)) {
params->destroy(params);
}
}
static int gatt_send(struct bt_conn *conn, struct net_buf *buf,
@ -2056,6 +2060,9 @@ static uint8_t notify_cb(const struct bt_gatt_attr *attr, uint16_t handle,
if (data->type == BT_GATT_CCC_INDICATE) {
err = gatt_indicate(conn, data->handle,
data->ind_params);
if (err == 0) {
data->ind_params->_ref++;
}
} else {
err = gatt_notify(conn, data->handle, data->nfy_params);
}
@ -2212,6 +2219,7 @@ int bt_gatt_indicate(struct bt_conn *conn,
}
if (conn) {
params->_ref = 1;
return gatt_indicate(conn, data.handle, params);
}
@ -2219,6 +2227,7 @@ int bt_gatt_indicate(struct bt_conn *conn,
data.type = BT_GATT_CCC_INDICATE;
data.ind_params = params;
params->_ref = 0;
bt_gatt_foreach_attr_type(data.handle, 0xffff, BT_UUID_GATT_CCC, NULL,
1, notify_cb, &data);