Bluetooth: OTS - Client APIs to have instance as first parameter

Move the instance as the first parameter of the client function calls
and callbacks, for consistency with the server implementation.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
This commit is contained in:
Asbjørn Sæbø 2022-02-09 17:01:50 +01:00 committed by Carles Cufí
commit eecd94409c
5 changed files with 105 additions and 106 deletions

View file

@ -822,46 +822,46 @@ struct bt_ots_client_cb {
* have been reset, and metadata should be read again with
* bt_ots_client_read_object_metadata().
*
* @param ots_inst Pointer to the OTC instance.
* @param conn The connection to the peer device.
* @param err Error code (bt_ots_olcp_res_code).
* @param ots_inst Pointer to the OTC instance.
*/
void (*obj_selected)(struct bt_conn *conn, int err,
struct bt_ots_client *ots_inst);
void (*obj_selected)(struct bt_ots_client *ots_inst,
struct bt_conn *conn, int err);
/** @brief Callback function for content of the selected object.
*
* Called when the object content is received.
*
* @param ots_inst Pointer to the OTC instance.
* @param conn The connection to the peer device.
* @param offset Offset of the received data.
* @param len Length of the received data.
* @param data_p Pointer to the received data.
* @param is_complete Indicate if the whole object has been received.
* @param ots_inst Pointer to the OTC instance.
*
* @return int BT_OTS_STOP or BT_OTS_CONTINUE. BT_OTS_STOP can
* be used to stop reading.
*/
int (*obj_content_recv)(struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete,
struct bt_ots_client *ots_inst);
int (*obj_content_recv)(struct bt_ots_client *ots_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete);
/** @brief Callback function for metadata of the selected object.
*
* Called when metadata of the selected object are read. Not all of
* the metadata may have been initialized.
*
* @param ots_inst Pointer to the OTC instance.
* @param conn The connection to the peer device.
* @param err Error value. 0 on success,
* GATT error or ERRNO on fail.
* @param ots_inst Pointer to the OTC instance.
* @param metadata_read Bitfield of the metadata that was
* successfully read.
*/
void (*obj_metadata_recv)(struct bt_conn *conn, int err,
struct bt_ots_client *ots_inst,
void (*obj_metadata_recv)(struct bt_ots_client *ots_inst,
struct bt_conn *conn, int err,
uint8_t metadata_read);
};
@ -894,77 +894,77 @@ uint8_t bt_ots_client_indicate_handler(struct bt_conn *conn,
/** @brief Read the OTS feature characteristic.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_read_feature(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_read_feature(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Select an object by its Object ID.
*
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
* @param obj_id Object's ID.
* @param otc_inst Pointer to the OTC instance.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_select_id(struct bt_conn *conn,
struct bt_ots_client *otc_inst,
int bt_ots_client_select_id(struct bt_ots_client *otc_inst,
struct bt_conn *conn,
uint64_t obj_id);
/** @brief Select the first object.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_select_first(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_select_first(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Select the last object.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_select_last(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_select_last(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Select the next object.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_select_next(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_select_next(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Select the previous object.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_select_prev(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_select_prev(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Read the metadata of the current object.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
* @param metadata Bitfield (`BT_OTS_METADATA_REQ_*`) of the metadata
* to read.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_read_object_metadata(struct bt_conn *conn,
struct bt_ots_client *otc_inst,
int bt_ots_client_read_object_metadata(struct bt_ots_client *otc_inst,
struct bt_conn *conn,
uint8_t metadata);
/** @brief Read the data of the current selected object.
@ -972,13 +972,13 @@ int bt_ots_client_read_object_metadata(struct bt_conn *conn,
* This will trigger an OACP read operation for the current size of the object
* with a 0 offset and then expect receiving the content via the L2CAP CoC.
*
* @param conn Pointer to the connection object.
* @param otc_inst Pointer to the OTC instance.
* @param conn Pointer to the connection object.
*
* @return int 0 if success, ERRNO on failure.
*/
int bt_ots_client_read_object_data(struct bt_conn *conn,
struct bt_ots_client *otc_inst);
int bt_ots_client_read_object_data(struct bt_ots_client *otc_inst,
struct bt_conn *conn);
/** @brief Directory listing object metadata callback
*

View file

@ -166,16 +166,16 @@ static struct bt_ots_client_cb otc_cb;
#ifdef CONFIG_BT_MCC_OTS
void on_obj_selected(struct bt_conn *conn, int err,
struct bt_ots_client *otc_inst);
void on_obj_selected(struct bt_ots_client *otc_inst,
struct bt_conn *conn, int err);
void on_object_metadata(struct bt_conn *conn, int err,
struct bt_ots_client *otc_inst,
void on_object_metadata(struct bt_ots_client *otc_inst,
struct bt_conn *conn, int err,
uint8_t metadata_read);
int on_icon_content(struct bt_conn *conn, uint32_t offset, uint32_t len,
uint8_t *data_p,
bool is_complete, struct bt_ots_client *otc_inst);
int on_icon_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete);
#endif /* CONFIG_BT_MCC_OTS */
@ -2299,8 +2299,8 @@ int bt_mcc_read_content_control_id(struct bt_conn *conn)
#ifdef CONFIG_BT_MCC_OTS
void on_obj_selected(struct bt_conn *conn, int result,
struct bt_ots_client *otc_inst)
void on_obj_selected(struct bt_ots_client *otc_inst,
struct bt_conn *conn, int result)
{
BT_DBG("Current object selected");
/* TODO: Read metadata here? */
@ -2318,9 +2318,9 @@ void on_obj_selected(struct bt_conn *conn, int result,
/* TODO: Merge the object callback functions into one */
/* Use a notion of the "active" object, as done in mpl.c, for tracking */
int on_icon_content(struct bt_conn *conn, uint32_t offset, uint32_t len,
uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_icon_content(struct bt_ots_client *otc_inst, struct bt_conn *conn,
uint32_t offset, uint32_t len, uint8_t *data_p,
bool is_complete)
{
int cb_err = 0;
@ -2403,9 +2403,9 @@ static void decode_track_segments(struct net_buf_simple *buff,
}
#endif /* CONFIG_BT_DEBUG_MCC */
int on_track_segments_content(struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_track_segments_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete)
{
int cb_err = 0;
@ -2447,9 +2447,9 @@ int on_track_segments_content(struct bt_conn *conn, uint32_t offset,
return BT_OTS_CONTINUE;
}
int on_current_track_content(struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_current_track_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete)
{
int cb_err = 0;
@ -2479,9 +2479,9 @@ int on_current_track_content(struct bt_conn *conn, uint32_t offset,
return BT_OTS_CONTINUE;
}
int on_next_track_content(struct bt_conn *conn, uint32_t offset, uint32_t len,
uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_next_track_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset, uint32_t len,
uint8_t *data_p, bool is_complete)
{
int cb_err = 0;
@ -2538,9 +2538,9 @@ static void decode_group(struct net_buf_simple *buff,
}
#endif /* CONFIG_BT_DEBUG_MCC */
int on_parent_group_content(struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_parent_group_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete)
{
int cb_err = 0;
@ -2584,9 +2584,9 @@ int on_parent_group_content(struct bt_conn *conn, uint32_t offset,
return BT_OTS_CONTINUE;
}
int on_current_group_content(struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete,
struct bt_ots_client *otc_inst)
int on_current_group_content(struct bt_ots_client *otc_inst,
struct bt_conn *conn, uint32_t offset,
uint32_t len, uint8_t *data_p, bool is_complete)
{
int cb_err = 0;
@ -2630,8 +2630,8 @@ int on_current_group_content(struct bt_conn *conn, uint32_t offset,
return BT_OTS_CONTINUE;
}
void on_object_metadata(struct bt_conn *conn, int err,
struct bt_ots_client *otc_inst,
void on_object_metadata(struct bt_ots_client *otc_inst,
struct bt_conn *conn, int err,
uint8_t metadata_read)
{
BT_INFO("Object's meta data:");
@ -2652,7 +2652,7 @@ int bt_mcc_otc_read_object_metadata(struct bt_conn *conn)
{
int err;
err = bt_ots_client_read_object_metadata(conn, &cur_mcs_inst->otc,
err = bt_ots_client_read_object_metadata(&cur_mcs_inst->otc, conn,
BT_OTS_METADATA_REQ_ALL);
if (err) {
BT_DBG("Error reading the object: %d", err);
@ -2669,7 +2669,7 @@ int bt_mcc_otc_read_icon_object(struct bt_conn *conn)
cur_mcs_inst->otc.cb->obj_content_recv = on_icon_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}
@ -2686,7 +2686,7 @@ int bt_mcc_otc_read_track_segments_object(struct bt_conn *conn)
/* TODO: Assumes object is already selected */
cur_mcs_inst->otc.cb->obj_content_recv = on_track_segments_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}
@ -2703,7 +2703,7 @@ int bt_mcc_otc_read_current_track_object(struct bt_conn *conn)
/* TODO: Assumes object is already selected */
cur_mcs_inst->otc.cb->obj_content_recv = on_current_track_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}
@ -2720,7 +2720,7 @@ int bt_mcc_otc_read_next_track_object(struct bt_conn *conn)
/* TODO: Assumes object is already selected */
cur_mcs_inst->otc.cb->obj_content_recv = on_next_track_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}
@ -2739,7 +2739,7 @@ int bt_mcc_otc_read_parent_group_object(struct bt_conn *conn)
/* Reuse callback for current group */
cur_mcs_inst->otc.cb->obj_content_recv = on_parent_group_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}
@ -2756,7 +2756,7 @@ int bt_mcc_otc_read_current_group_object(struct bt_conn *conn)
/* TODO: Assumes object is already selected */
cur_mcs_inst->otc.cb->obj_content_recv = on_current_group_content;
err = bt_ots_client_read_object_data(conn, &cur_mcs_inst->otc);
err = bt_ots_client_read_object_data(&cur_mcs_inst->otc, conn);
if (err) {
BT_DBG("Error reading the object: %d", err);
}

View file

@ -156,10 +156,9 @@ static ssize_t rx_done(struct bt_gatt_ots_l2cap *l2cap_ctx,
cur_inst->rcvd_size, cur_object->size.cur);
}
cb_ret = cur_inst->otc_inst->cb->obj_content_recv(conn, offset,
cb_ret = cur_inst->otc_inst->cb->obj_content_recv(0, conn, offset,
buf->len, buf->data,
is_complete, 0);
is_complete);
if (is_complete) {
const uint32_t rcv_size = cur_object->size.cur;
@ -248,7 +247,7 @@ static void on_object_selected(struct bt_conn *conn,
otc_inst->cur_object.id = OTS_CLIENT_UNKNOWN_ID;
if (otc_inst->cb->obj_selected) {
otc_inst->cb->obj_selected(conn, res, otc_inst);
otc_inst->cb->obj_selected(otc_inst, conn, res);
}
BT_DBG("Object selected");
@ -448,8 +447,8 @@ int bt_ots_client_unregister(uint8_t index)
return 0;
}
int bt_ots_client_read_feature(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_read_feature(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
if (OTS_CLIENT_INST_COUNT > 0) {
struct bt_otc_internal_instance_t *inst;
@ -534,8 +533,8 @@ static int write_olcp(struct bt_otc_internal_instance_t *inst,
return err;
}
int bt_ots_client_select_id(struct bt_conn *conn,
struct bt_ots_client *otc_inst,
int bt_ots_client_select_id(struct bt_ots_client *otc_inst,
struct bt_conn *conn,
uint64_t obj_id)
{
if (OTS_CLIENT_INST_COUNT > 0) {
@ -574,8 +573,8 @@ int bt_ots_client_select_id(struct bt_conn *conn,
return -EOPNOTSUPP;
}
int bt_ots_client_select_first(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_select_first(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
if (OTS_CLIENT_INST_COUNT > 0) {
struct bt_otc_internal_instance_t *inst;
@ -608,8 +607,8 @@ int bt_ots_client_select_first(struct bt_conn *conn,
return -EOPNOTSUPP;
}
int bt_ots_client_select_last(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_select_last(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
if (OTS_CLIENT_INST_COUNT > 0) {
struct bt_otc_internal_instance_t *inst;
@ -643,8 +642,8 @@ int bt_ots_client_select_last(struct bt_conn *conn,
return -EOPNOTSUPP;
}
int bt_ots_client_select_next(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_select_next(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
if (OTS_CLIENT_INST_COUNT > 0) {
struct bt_otc_internal_instance_t *inst;
@ -677,8 +676,8 @@ int bt_ots_client_select_next(struct bt_conn *conn,
return -EOPNOTSUPP;
}
int bt_ots_client_select_prev(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_select_prev(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
if (OTS_CLIENT_INST_COUNT > 0) {
struct bt_otc_internal_instance_t *inst;
@ -1152,8 +1151,8 @@ static int oacp_read(struct bt_conn *conn,
return err;
}
int bt_ots_client_read_object_data(struct bt_conn *conn,
struct bt_ots_client *otc_inst)
int bt_ots_client_read_object_data(struct bt_ots_client *otc_inst,
struct bt_conn *conn)
{
struct bt_otc_internal_instance_t *inst;
@ -1222,7 +1221,7 @@ static void read_next_metadata(struct bt_conn *conn,
inst->busy = false;
if (inst->otc_inst->cb->obj_metadata_recv) {
inst->otc_inst->cb->obj_metadata_recv(
conn, inst->metadata_err, inst->otc_inst,
inst->otc_inst, conn, inst->metadata_err,
inst->metadata_read);
}
return;
@ -1234,8 +1233,8 @@ static void read_next_metadata(struct bt_conn *conn,
}
}
int bt_ots_client_read_object_metadata(struct bt_conn *conn,
struct bt_ots_client *otc_inst,
int bt_ots_client_read_object_metadata(struct bt_ots_client *otc_inst,
struct bt_conn *conn,
uint8_t metadata)
{
struct bt_otc_internal_instance_t *inst;

View file

@ -1164,7 +1164,7 @@ int cmd_mcc_otc_read_features(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_read_feature(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_read_feature(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1175,7 +1175,7 @@ int cmd_mcc_otc_read(const struct shell *sh, size_t argc, char *argv[])
{
int result;
result = bt_ots_client_read_object_data(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_read_object_data(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1187,8 +1187,8 @@ int cmd_mcc_otc_read_metadata(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_read_object_metadata(default_conn,
bt_mcc_otc_inst(),
result = bt_ots_client_read_object_metadata(bt_mcc_otc_inst(),
default_conn,
BT_OTS_METADATA_REQ_ALL);
if (result) {
shell_error(sh, "Fail: %d", result);
@ -1208,7 +1208,7 @@ int cmd_mcc_otc_select(const struct shell *sh, size_t argc, char *argv[])
return -ENOEXEC;
}
result = bt_ots_client_select_id(default_conn, bt_mcc_otc_inst(), id);
result = bt_ots_client_select_id(bt_mcc_otc_inst(), default_conn, id);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1220,7 +1220,7 @@ int cmd_mcc_otc_select_first(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_first(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_select_first(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1232,7 +1232,7 @@ int cmd_mcc_otc_select_last(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_last(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_select_last(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1244,7 +1244,7 @@ int cmd_mcc_otc_select_next(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_next(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_select_next(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1256,7 +1256,7 @@ int cmd_mcc_otc_select_prev(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_prev(default_conn, bt_mcc_otc_inst());
result = bt_ots_client_select_prev(bt_mcc_otc_inst(), default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1352,7 +1352,7 @@ int cmd_mcc_ots_select_first(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_first(default_conn, 0);
result = bt_ots_client_select_first(0, default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1364,7 +1364,7 @@ int cmd_mcc_ots_select_last(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_last(default_conn, 0);
result = bt_ots_client_select_last(0, default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1376,7 +1376,7 @@ int cmd_mcc_ots_select_next(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_next(default_conn, 0);
result = bt_ots_client_select_next(0, default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}
@ -1388,7 +1388,7 @@ int cmd_mcc_ots_select_prev(const struct shell *sh, size_t argc,
{
int result;
result = bt_ots_client_select_prev(default_conn, 0);
result = bt_ots_client_select_prev(0, default_conn);
if (result) {
shell_error(sh, "Fail: %d", result);
}

View file

@ -592,7 +592,7 @@ static void select_read_meta(int64_t id)
/* TODO: Fix the instance pointer - it is neither valid nor used */
UNSET_FLAG(object_selected);
err = bt_ots_client_select_id(default_conn, bt_mcc_otc_inst(), id);
err = bt_ots_client_select_id(bt_mcc_otc_inst(), default_conn, id);
if (err) {
FAIL("Failed to select object\n");
return;
@ -603,7 +603,7 @@ static void select_read_meta(int64_t id)
/* TODO: Fix the instance pointer - it is neither valid nor used */
UNSET_FLAG(metadata_read);
err = bt_ots_client_read_object_metadata(default_conn, bt_mcc_otc_inst(),
err = bt_ots_client_read_object_metadata(bt_mcc_otc_inst(), default_conn,
BT_OTS_METADATA_REQ_ALL);
if (err) {
FAIL("Failed to read object metadata\n");