Bluetooth: Audio: MCC - pass structs by reference

Changes the media control client API to pass structs by reference
instead of by value.

Also change internals of test to pass struct by reference.

Signed-off-by: Asbjørn Sæbø <asbjorn.sabo@nordicsemi.no>
This commit is contained in:
Asbjørn Sæbø 2022-04-06 10:50:34 +02:00 committed by Johan Hedberg
commit fa5b8a1e38
5 changed files with 72 additions and 72 deletions

View file

@ -313,7 +313,7 @@ typedef void (*bt_mcc_read_media_state_cb)(struct bt_conn *conn, int err, uint8_
* @param err Error value. 0 on success, GATT error or errno on fail
* @param cmd The command sent
*/
typedef void (*bt_mcc_send_cmd_cb)(struct bt_conn *conn, int err, struct mpl_cmd cmd);
typedef void (*bt_mcc_send_cmd_cb)(struct bt_conn *conn, int err, const struct mpl_cmd *cmd);
/**
* @brief Callback function for command notifications
@ -328,7 +328,7 @@ typedef void (*bt_mcc_send_cmd_cb)(struct bt_conn *conn, int err, struct mpl_cmd
* @param err Error value. 0 on success, GATT error or errno on fail
* @param ntf The command notification
*/
typedef void (*bt_mcc_cmd_ntf_cb)(struct bt_conn *conn, int err, struct mpl_cmd_ntf ntf);
typedef void (*bt_mcc_cmd_ntf_cb)(struct bt_conn *conn, int err, const struct mpl_cmd_ntf *ntf);
/**
* @brief Callback function for bt_mcc_read_opcodes_supported()
@ -353,7 +353,7 @@ typedef void (*bt_mcc_read_opcodes_supported_cb)(struct bt_conn *conn, int err,
* @param search The search set (or attempted to set)
*/
typedef void (*bt_mcc_send_search_cb)(struct bt_conn *conn, int err,
struct mpl_search search);
const struct mpl_search *search);
/**
* @brief Callback function for search notifications
@ -815,7 +815,7 @@ int bt_mcc_read_media_state(struct bt_conn *conn);
*
* @return 0 if success, errno on failure.
*/
int bt_mcc_send_cmd(struct bt_conn *conn, struct mpl_cmd cmd);
int bt_mcc_send_cmd(struct bt_conn *conn, const struct mpl_cmd *cmd);
/**
* @brief Read Opcodes Supported
@ -837,7 +837,7 @@ int bt_mcc_read_opcodes_supported(struct bt_conn *conn);
*
* @return 0 if success, errno on failure.
*/
int bt_mcc_send_search(struct bt_conn *conn, struct mpl_search search);
int bt_mcc_send_search(struct bt_conn *conn, const struct mpl_search *search);
/**
* @brief Search Results Group Object ID

View file

@ -789,7 +789,7 @@ static void mcs_write_cp_cb(struct bt_conn *conn, uint8_t err,
}
if (mcc_cb && mcc_cb->send_cmd) {
mcc_cb->send_cmd(conn, cb_err, cmd);
mcc_cb->send_cmd(conn, cb_err, &cmd);
}
}
@ -843,7 +843,7 @@ static void mcs_write_scp_cb(struct bt_conn *conn, uint8_t err,
}
if (mcc_cb && mcc_cb->send_search) {
mcc_cb->send_search(conn, cb_err, search);
mcc_cb->send_search(conn, cb_err, &search);
}
}
@ -1006,7 +1006,7 @@ static uint8_t mcs_notify_handler(struct bt_conn *conn,
}
if (mcc_cb && mcc_cb->cmd_ntf) {
mcc_cb->cmd_ntf(conn, cb_err, ntf);
mcc_cb->cmd_ntf(conn, cb_err, &ntf);
}
} else if (handle == cur_mcs_inst->opcodes_supported_handle) {
@ -2142,10 +2142,10 @@ int bt_mcc_read_media_state(struct bt_conn *conn)
return err;
}
int bt_mcc_send_cmd(struct bt_conn *conn, struct mpl_cmd cmd)
int bt_mcc_send_cmd(struct bt_conn *conn, const struct mpl_cmd *cmd)
{
int err;
int length = sizeof(cmd.opcode);
int length = sizeof(cmd->opcode);
CHECKIF(!conn) {
return -EINVAL;
@ -2158,11 +2158,11 @@ int bt_mcc_send_cmd(struct bt_conn *conn, struct mpl_cmd cmd)
return -EBUSY;
}
memcpy(cur_mcs_inst->write_buf, &cmd.opcode, length);
if (cmd.use_param) {
length += sizeof(cmd.param);
memcpy(&cur_mcs_inst->write_buf[sizeof(cmd.opcode)], &cmd.param,
sizeof(cmd.param));
memcpy(cur_mcs_inst->write_buf, &cmd->opcode, length);
if (cmd->use_param) {
length += sizeof(cmd->param);
memcpy(&cur_mcs_inst->write_buf[sizeof(cmd->opcode)], &cmd->param,
sizeof(cmd->param));
}
cur_mcs_inst->write_params.offset = 0;
@ -2171,7 +2171,7 @@ int bt_mcc_send_cmd(struct bt_conn *conn, struct mpl_cmd cmd)
cur_mcs_inst->write_params.handle = cur_mcs_inst->cp_handle;
cur_mcs_inst->write_params.func = mcs_write_cp_cb;
BT_HEXDUMP_DBG(cur_mcs_inst->write_params.data, sizeof(cmd),
BT_HEXDUMP_DBG(cur_mcs_inst->write_params.data, sizeof(*cmd),
"Command sent");
err = bt_gatt_write(conn, &cur_mcs_inst->write_params);
@ -2209,7 +2209,7 @@ int bt_mcc_read_opcodes_supported(struct bt_conn *conn)
}
#ifdef CONFIG_BT_MCC_OTS
int bt_mcc_send_search(struct bt_conn *conn, struct mpl_search search)
int bt_mcc_send_search(struct bt_conn *conn, const struct mpl_search *search)
{
int err;
@ -2224,15 +2224,15 @@ int bt_mcc_send_search(struct bt_conn *conn, struct mpl_search search)
return -EBUSY;
}
memcpy(cur_mcs_inst->write_buf, &search.search, search.len);
memcpy(cur_mcs_inst->write_buf, &search->search, search->len);
cur_mcs_inst->write_params.offset = 0;
cur_mcs_inst->write_params.data = cur_mcs_inst->write_buf;
cur_mcs_inst->write_params.length = search.len;
cur_mcs_inst->write_params.length = search->len;
cur_mcs_inst->write_params.handle = cur_mcs_inst->scp_handle;
cur_mcs_inst->write_params.func = mcs_write_scp_cb;
BT_HEXDUMP_DBG(cur_mcs_inst->write_params.data, search.len,
BT_HEXDUMP_DBG(cur_mcs_inst->write_params.data, search->len,
"Search sent");
err = bt_gatt_write(conn, &cur_mcs_inst->write_params);

View file

@ -522,30 +522,30 @@ static void mcc_read_media_state_cb(struct bt_conn *conn, int err, uint8_t state
}
}
static void mcc_send_cmd_cb(struct bt_conn *conn, int err, struct mpl_cmd cmd)
static void mcc_send_cmd_cb(struct bt_conn *conn, int err, const struct mpl_cmd *cmd)
{
if (err) {
BT_ERR("Command send failed (%d) - opcode: %d, param: %d",
err, cmd.opcode, cmd.param);
err, cmd->opcode, cmd->param);
}
if (mprx.ctrlr.cbs && mprx.ctrlr.cbs->command_send) {
mprx.ctrlr.cbs->command_send(&mprx.remote_player, err, cmd);
mprx.ctrlr.cbs->command_send(&mprx.remote_player, err, *cmd);
} else {
BT_DBG("No callback");
}
}
static void mcc_cmd_ntf_cb(struct bt_conn *conn, int err,
struct mpl_cmd_ntf ntf)
const struct mpl_cmd_ntf *ntf)
{
if (err) {
BT_ERR("Command notification error (%d) - command opcode: %d, result: %d",
err, ntf.requested_opcode, ntf.result_code);
err, ntf->requested_opcode, ntf->result_code);
}
if (mprx.ctrlr.cbs && mprx.ctrlr.cbs->command_recv) {
mprx.ctrlr.cbs->command_recv(&mprx.remote_player, err, ntf);
mprx.ctrlr.cbs->command_recv(&mprx.remote_player, err, *ntf);
} else {
BT_DBG("No callback");
}
@ -565,14 +565,14 @@ static void mcc_read_opcodes_supported_cb(struct bt_conn *conn, int err, uint32_
}
#ifdef CONFIG_MCTL_REMOTE_PLAYER_CONTROL_OBJECTS
static void mcc_send_search_cb(struct bt_conn *conn, int err, struct mpl_search search)
static void mcc_send_search_cb(struct bt_conn *conn, int err, const struct mpl_search *search)
{
if (err) {
BT_ERR("Search send failed (%d)", err);
}
if (mprx.ctrlr.cbs && mprx.ctrlr.cbs->search_send) {
mprx.ctrlr.cbs->search_send(&mprx.remote_player, err, search);
mprx.ctrlr.cbs->search_send(&mprx.remote_player, err, *search);
} else {
BT_DBG("No callback");
}
@ -1551,7 +1551,7 @@ int media_proxy_ctrl_send_command(struct media_player *player, struct mpl_cmd cm
#if defined(CONFIG_MCTL_REMOTE_PLAYER_CONTROL)
if (mprx.remote_player.registered && player == &mprx.remote_player) {
return bt_mcc_send_cmd(mprx.remote_player.conn, cmd);
return bt_mcc_send_cmd(mprx.remote_player.conn, &cmd);
}
#endif /* CONFIG_MCTL_REMOTE_PLAYER_CONTROL */
@ -1622,7 +1622,7 @@ int media_proxy_ctrl_send_search(struct media_player *player, struct mpl_search
#if defined(CONFIG_MCTL_REMOTE_PLAYER_CONTROL_OBJECTS)
if (mprx.remote_player.registered && player == &mprx.remote_player) {
return bt_mcc_send_search(mprx.remote_player.conn, search);
return bt_mcc_send_search(mprx.remote_player.conn, &search);
}
#endif /* CONFIG_MCTL_REMOTE_PLAYER_CONTROL_OBJECTS */

View file

@ -353,30 +353,30 @@ static void mcc_read_media_state_cb(struct bt_conn *conn, int err, uint8_t state
shell_print(ctx_shell, "Media State: %d", state);
}
static void mcc_send_cmd_cb(struct bt_conn *conn, int err, struct mpl_cmd cmd)
static void mcc_send_cmd_cb(struct bt_conn *conn, int err, const struct mpl_cmd *cmd)
{
if (err) {
shell_error(ctx_shell,
"Command send failed (%d) - opcode: %d, param: %d",
err, cmd.opcode, cmd.param);
err, cmd->opcode, cmd->param);
return;
}
shell_print(ctx_shell, "Command opcode: %d, param: %d", cmd.opcode, cmd.param);
shell_print(ctx_shell, "Command opcode: %d, param: %d", cmd->opcode, cmd->param);
}
static void mcc_cmd_ntf_cb(struct bt_conn *conn, int err,
struct mpl_cmd_ntf ntf)
const struct mpl_cmd_ntf *ntf)
{
if (err) {
shell_error(ctx_shell,
"Command notification error (%d) - opcode: %d, result: %d",
err, ntf.requested_opcode, ntf.result_code);
err, ntf->requested_opcode, ntf->result_code);
return;
}
shell_print(ctx_shell, "Command opcode: %d, result: %d",
ntf.requested_opcode, ntf.result_code);
ntf->requested_opcode, ntf->result_code);
}
static void mcc_read_opcodes_supported_cb(struct bt_conn *conn, int err,
@ -393,7 +393,7 @@ static void mcc_read_opcodes_supported_cb(struct bt_conn *conn, int err,
#ifdef CONFIG_BT_MCC_OTS
static void mcc_send_search_cb(struct bt_conn *conn, int err,
struct mpl_search search)
const struct mpl_search *search)
{
if (err) {
shell_error(ctx_shell,
@ -948,7 +948,7 @@ int cmd_mcc_set_cp(const struct shell *sh, size_t argc, char *argv[])
cmd.param = 0;
}
result = bt_mcc_send_cmd(default_conn, cmd);
result = bt_mcc_send_cmd(default_conn, &cmd);
if (result) {
shell_print(sh, "Fail: %d", result);
}
@ -977,7 +977,7 @@ int cmd_mcc_send_search_raw(const struct shell *sh, size_t argc, char *argv[])
memcpy(search.search, argv[1], search.len);
BT_DBG("Search string: %s", log_strdup(argv[1]));
result = bt_mcc_send_search(default_conn, search);
result = bt_mcc_send_search(default_conn, &search);
if (result) {
shell_print(sh, "Fail: %d", result);
}
@ -1075,7 +1075,7 @@ int cmd_mcc_send_search_ioptest(const struct shell *sh, size_t argc,
shell_print(sh, "Search string: ");
shell_hexdump(sh, (uint8_t *)&search.search, search.len);
result = bt_mcc_send_search(default_conn, search);
result = bt_mcc_send_search(default_conn, &search);
if (result) {
shell_print(sh, "Fail: %d", result);
}
@ -1098,7 +1098,7 @@ int cmd_mcc_test_send_search_iop_invalid_type(const struct shell *sh,
shell_print(sh, "Search string: ");
shell_hexdump(sh, (uint8_t *)&search.search, search.len);
result = bt_mcc_send_search(default_conn, search);
result = bt_mcc_send_search(default_conn, &search);
if (result) {
shell_print(sh, "Fail: %d", result);
}
@ -1123,7 +1123,7 @@ int cmd_mcc_test_send_search_invalid_sci_len(const struct shell *sh,
shell_print(sh, "Search string: ");
shell_hexdump(sh, (uint8_t *)&search.search, search.len);
result = bt_mcc_send_search(default_conn, search);
result = bt_mcc_send_search(default_conn, &search);
if (result) {
shell_print(sh, "Fail: %d", result);
}

View file

@ -350,31 +350,31 @@ static void mcc_read_media_state_cb(struct bt_conn *conn, int err, uint8_t state
SET_FLAG(media_state_read);
}
static void mcc_send_command_cb(struct bt_conn *conn, int err, struct mpl_cmd cmd)
static void mcc_send_command_cb(struct bt_conn *conn, int err, const struct mpl_cmd *cmd)
{
if (err) {
FAIL("Command send failed (%d) - opcode: %u, param: %d",
err, cmd.opcode, cmd.param);
err, cmd->opcode, cmd->param);
return;
}
SET_FLAG(command_sent);
}
static void mcc_cmd_ntf_cb(struct bt_conn *conn, int err, struct mpl_cmd_ntf ntf)
static void mcc_cmd_ntf_cb(struct bt_conn *conn, int err, const struct mpl_cmd_ntf *ntf)
{
if (err) {
FAIL("Command notification error (%d) - opcode: %u, result: %u",
err, ntf.requested_opcode, ntf.result_code);
err, ntf->requested_opcode, ntf->result_code);
return;
}
g_command_result = ntf.result_code;
g_command_result = ntf->result_code;
SET_FLAG(command_notified);
}
static void mcc_send_search_cb(struct bt_conn *conn, int err,
struct mpl_search search)
const struct mpl_search *search)
{
if (err) {
FAIL("Search send failed (%d)", err);
@ -647,7 +647,7 @@ static bool test_verify_media_state_wait_flags(uint8_t expected_state)
* Will FAIL on error to send the command.
* Will WAIT for the required flags before returning.
*/
static void test_send_cmd_wait_flags(struct mpl_cmd cmd)
static void test_send_cmd_wait_flags(struct mpl_cmd *cmd)
{
int err;
@ -661,7 +661,7 @@ static void test_send_cmd_wait_flags(struct mpl_cmd cmd)
err = bt_mcc_send_cmd(default_conn, cmd);
if (err) {
FAIL("Failed to send command: %d, opcode: %u",
err, cmd.opcode);
err, cmd->opcode);
return;
}
@ -676,7 +676,7 @@ static void test_cp_play(void)
cmd.opcode = BT_MCS_OPC_PLAY;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("PLAY command failed\n");
@ -695,7 +695,7 @@ static void test_cp_pause(void)
cmd.opcode = BT_MCS_OPC_PAUSE;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("PAUSE command failed\n");
@ -714,7 +714,7 @@ static void test_cp_fast_rewind(void)
cmd.opcode = BT_MCS_OPC_FAST_REWIND;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("FAST REWIND command failed\n");
@ -733,7 +733,7 @@ static void test_cp_fast_forward(void)
cmd.opcode = BT_MCS_OPC_FAST_FORWARD;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("FAST FORWARD command failed\n");
@ -752,7 +752,7 @@ static void test_cp_stop(void)
cmd.opcode = BT_MCS_OPC_STOP;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("STOP command failed\n");
@ -789,7 +789,7 @@ static void test_cp_move_relative(void)
cmd.use_param = true;
cmd.param = 1000; /* Position change, measured in 1/100 of a second */
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("MOVE RELATIVE command failed\n");
@ -833,7 +833,7 @@ static void test_cp_prev_segment(void)
cmd.opcode = BT_MCS_OPC_PREV_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("PREV SEGMENT command failed\n");
@ -850,7 +850,7 @@ static void test_cp_next_segment(void)
cmd.opcode = BT_MCS_OPC_NEXT_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("NEXT SEGMENT command failed\n");
@ -867,7 +867,7 @@ static void test_cp_first_segment(void)
cmd.opcode = BT_MCS_OPC_FIRST_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("FIRST SEGMENT command failed\n");
@ -884,7 +884,7 @@ static void test_cp_last_segment(void)
cmd.opcode = BT_MCS_OPC_LAST_SEGMENT;
cmd.use_param = false;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("LAST SEGMENT command failed\n");
@ -902,7 +902,7 @@ static void test_cp_goto_segment(void)
cmd.use_param = true;
cmd.param = 2; /* Second segment - not the first, maybe not last */
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("GOTO SEGMENT command failed\n");
@ -949,7 +949,7 @@ static void test_cp_prev_track(void)
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("PREV TRACK command failed\n");
@ -981,7 +981,7 @@ static void test_cp_next_track_and_track_changed(void)
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("NEXT TRACK command failed\n");
@ -1012,7 +1012,7 @@ static void test_cp_first_track(void)
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("FIRST TRACK command failed\n");
@ -1040,7 +1040,7 @@ static void test_cp_last_track(void)
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("LAST TRACK command failed\n");
@ -1069,7 +1069,7 @@ static void test_cp_goto_track(void)
test_read_current_track_object_id_wait_flags();
object_id = g_current_track_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("GOTO TRACK command failed\n");
@ -1123,7 +1123,7 @@ static void test_cp_prev_group(void)
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("PREV GROUP command failed\n");
@ -1152,7 +1152,7 @@ static void test_cp_next_group(void)
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("NEXT GROUP command failed\n");
@ -1180,7 +1180,7 @@ static void test_cp_first_group(void)
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("FIRST GROUP command failed\n");
@ -1208,7 +1208,7 @@ static void test_cp_last_group(void)
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("LAST GROUP command failed\n");
@ -1237,7 +1237,7 @@ static void test_cp_goto_group(void)
test_read_current_group_object_id_wait_flags();
object_id = g_current_group_object_id;
test_send_cmd_wait_flags(cmd);
test_send_cmd_wait_flags(&cmd);
if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) {
FAIL("GOTO GROUP command failed\n");
@ -1306,7 +1306,7 @@ static void test_search(void)
UNSET_FLAG(search_notified);
UNSET_FLAG(search_results_object_id_read);
err = bt_mcc_send_search(default_conn, search);
err = bt_mcc_send_search(default_conn, &search);
if (err) {
FAIL("Failed to write to search control point\n");
return;