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. * @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 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. * @param locked Whether the lock is locked or release.
*/ */
typedef void (*bt_csis_client_lock_read_cb)(struct bt_conn *conn, int err, typedef void (*bt_csis_client_lock_read_cb)(struct bt_csis_client_set *set,
uint8_t inst_idx, bool locked); int err, bool locked);
struct bt_csis_client_cb { struct bt_csis_client_cb {
/* Set callbacks */ /* 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, struct bt_gatt_read_params *params,
const void *data, uint16_t length) const void *data, uint16_t length)
{ {
struct bt_csis_client_inst *client;
struct bt_csis_client_set *set;
uint8_t value = 0; uint8_t value = 0;
int cb_err = err; int cb_err = err;
uint8_t idx = cur_inst->cli.idx;
busy = false; 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; cur_inst = NULL;
if (csis_client_cbs != NULL && csis_client_cbs->lock_read != 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); value == BT_CSIS_LOCK_VALUE ? true : false);
} }
return BT_GATT_ITER_STOP; 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"); shell_print(ctx_shell, "Set released");
} }
static void csis_client_lock_get_cb(struct bt_conn *conn, int err, static void csis_client_lock_get_cb(struct bt_csis_client_set *set, int err,
uint8_t inst_idx, bool locked) bool locked)
{ {
if (err != 0) { if (err != 0) {
shell_error(ctx_shell, "Device (index 0x%02x) lock get " shell_error(ctx_shell, "Device (set %p) lock get "
"failed (%d)", inst_idx, err); "failed (%d)", set, err);
} }
shell_print(ctx_shell, "Device (index 0x%02x) lock value %d", shell_print(ctx_shell, "Device (set %p) lock value %d",
inst_idx, locked); set, locked);
} }
static struct bt_csis_client_cb cbs = { static struct bt_csis_client_cb cbs = {