Bluetooth: CSIS: Refactor bt_csis_client_lock_read_cb to use set

Refactor the bt_csis_client_lock_read_cb callback to use
a bt_csis_client_set pointer instead of conn and index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-11-23 15:05:01 +01:00 committed by Anas Nashif
commit 9c3745a69b
3 changed files with 14 additions and 12 deletions

View file

@ -253,13 +253,12 @@ typedef void (*bt_csis_client_lock_changed_cb)(struct bt_csis_client_set *set,
/**
* @brief Callback when the lock value is read on a device.
*
* @param conn Connection of the CSIS server.
* @param set The set that was read.
* @param err Error value. 0 on success, GATT error or errno on fail.
* @param inst_idx The index of the CSIS service.
* @param locked Whether the lock is locked or release.
*/
typedef void (*bt_csis_client_lock_read_cb)(struct bt_conn *conn, int err,
uint8_t inst_idx, bool locked);
typedef void (*bt_csis_client_lock_read_cb)(struct bt_csis_client_set *set,
int err, bool locked);
struct bt_csis_client_cb {
/* Set callbacks */

View file

@ -858,9 +858,10 @@ static uint8_t csis_client_read_lock_cb(struct bt_conn *conn, uint8_t err,
struct bt_gatt_read_params *params,
const void *data, uint16_t length)
{
struct bt_csis_client_inst *client;
struct bt_csis_client_set *set;
uint8_t value = 0;
int cb_err = err;
uint8_t idx = cur_inst->cli.idx;
busy = false;
@ -889,10 +890,12 @@ static uint8_t csis_client_read_lock_cb(struct bt_conn *conn, uint8_t err,
}
}
client = &client_insts[bt_conn_index(conn)];
set = &client->set_member->sets[cur_inst->cli.idx];
cur_inst = NULL;
if (csis_client_cbs != NULL && csis_client_cbs->lock_read != NULL) {
csis_client_cbs->lock_read(conn, cb_err, idx,
csis_client_cbs->lock_read(set, cb_err,
value == BT_CSIS_LOCK_VALUE ? true : false);
}
return BT_GATT_ITER_STOP;

View file

@ -137,16 +137,16 @@ static void csis_client_release_set_cb(int err)
shell_print(ctx_shell, "Set released");
}
static void csis_client_lock_get_cb(struct bt_conn *conn, int err,
uint8_t inst_idx, bool locked)
static void csis_client_lock_get_cb(struct bt_csis_client_set *set, int err,
bool locked)
{
if (err != 0) {
shell_error(ctx_shell, "Device (index 0x%02x) lock get "
"failed (%d)", inst_idx, err);
shell_error(ctx_shell, "Device (set %p) lock get "
"failed (%d)", set, err);
}
shell_print(ctx_shell, "Device (index 0x%02x) lock value %d",
inst_idx, locked);
shell_print(ctx_shell, "Device (set %p) lock value %d",
set, locked);
}
static struct bt_csis_client_cb cbs = {