Bluetooth: CSIS: Refactor bt_csis_client_lock_get to use member

Refactor the bt_csis_client_lock_get function to use a
pointer to a member and a set instead of a bt_conn
pointer and an index.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-11-23 16:56:09 +01:00 committed by Anas Nashif
commit 170d094ca8
3 changed files with 15 additions and 16 deletions

View file

@ -292,14 +292,15 @@ void bt_csis_client_register_cb(struct bt_csis_client_cb *cb);
/** /**
* @brief Read the lock value of a specific device and instance. * @brief Read the lock value of a specific device and instance.
*
* @param conn Pointer to the connection to the device. * @param members Member to get the lock value from
* @param inst_idx Index of the CSIS index of the peer device (as it may have * @param set Pointer to the specific set of the @p member to get the
* multiple CSIS instances). * lock value from.
* *
* @return Return 0 on success, or an errno value on error. * @return Return 0 on success, or an errno value on error.
*/ */
int bt_csis_client_lock_get(struct bt_conn *conn, uint8_t inst_idx); int bt_csis_client_lock_get(struct bt_csis_client_set_member *member,
const struct bt_csis_client_set *set);
/** /**
* @brief Lock an array of set members * @brief Lock an array of set members

View file

@ -1195,25 +1195,23 @@ int bt_csis_client_discover_sets(struct bt_csis_client_set_member *member)
return err; return err;
} }
int bt_csis_client_lock_get(struct bt_conn *conn, uint8_t inst_idx) int bt_csis_client_lock_get(struct bt_csis_client_set_member *member,
const struct bt_csis_client_set *set)
{ {
int err; int err;
if (inst_idx >= CONFIG_BT_CSIS_CLIENT_MAX_CSIS_INSTANCES) { if (busy) {
BT_DBG("Invalid index %u", inst_idx);
return -EINVAL;
} else if (busy) {
BT_DBG("csis_client busy"); BT_DBG("csis_client busy");
return -EBUSY; return -EBUSY;
} else if (cur_inst != NULL) { } else if (cur_inst != NULL) {
if (cur_inst != lookup_instance_by_index(conn, inst_idx)) { if (cur_inst != set->csis) {
BT_DBG("csis_client busy with current instance"); BT_DBG("csis_client busy with current instance");
return -EBUSY; return -EBUSY;
} }
} else { } else {
cur_inst = lookup_instance_by_index(conn, inst_idx); cur_inst = set->csis;
if (cur_inst == NULL) { if (cur_inst == NULL) {
BT_DBG("Inst not found"); BT_DBG("set->csis is NULL");
return -EINVAL; return -EINVAL;
} }
} }
@ -1229,7 +1227,7 @@ int bt_csis_client_lock_get(struct bt_conn *conn, uint8_t inst_idx)
read_params.single.handle = cur_inst->cli.set_lock_handle; read_params.single.handle = cur_inst->cli.set_lock_handle;
read_params.single.offset = 0U; read_params.single.offset = 0U;
err = bt_gatt_read(conn, &read_params); err = bt_gatt_read(member->conn, &read_params);
if (err != 0) { if (err != 0) {
cur_inst = NULL; cur_inst = NULL;

View file

@ -419,8 +419,8 @@ static int cmd_csis_client_lock_get(const struct shell *sh, size_t argc,
} }
} }
err = bt_csis_client_lock_get(set_members[member_index].conn, err = bt_csis_client_lock_get(&set_members[member_index],
(uint8_t)idx); &set_members[member_index].sets[idx]);
if (err != 0) { if (err != 0) {
shell_error(sh, "Fail: %d", err); shell_error(sh, "Fail: %d", err);
} }