Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: VCP: Allow for multiple vol_ctrl cb registers #65608

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion include/zephyr/bluetooth/audio/vcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,33 @@ struct bt_vcp_vol_ctlr_cb {

/* Audio Input Control Service callbacks */
struct bt_aics_cb aics_cb;

/** Internally used field for list handling */
sys_snode_t _node;
};

/**
* @brief Registers the callbacks used by the Volume Controller.
*
* @param cb The callback structure.
*
* @return 0 if success, errno on failure.
* @retval 0 on success
* @retval -EINVAL if @p cb is NULL
* @retval -EALREADY if @p cb was already registered
*/
int bt_vcp_vol_ctlr_cb_register(struct bt_vcp_vol_ctlr_cb *cb);

/**
* @brief Unregisters the callbacks used by the Volume Controller.
*
* @param cb The callback structure.
*
* @retval 0 on success
* @retval -EINVAL if @p cb is NULL
* @retval -EALREADY if @p cb was not registered
fredrikdanebjer marked this conversation as resolved.
Show resolved Hide resolved
*/
int bt_vcp_vol_ctlr_cb_unregister(struct bt_vcp_vol_ctlr_cb *cb);

/**
* @brief Discover Volume Control Service and included services.
*
Expand Down
13 changes: 9 additions & 4 deletions subsys/bluetooth/audio/shell/vcp_vol_ctlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,21 @@ static struct bt_vcp_vol_ctlr_cb vcp_cbs = {
static int cmd_vcp_vol_ctlr_discover(const struct shell *sh, size_t argc,
char **argv)
{
static bool cb_registered;
int result;

if (!ctx_shell) {
ctx_shell = sh;
}

result = bt_vcp_vol_ctlr_cb_register(&vcp_cbs);
if (result != 0) {
shell_print(sh, "CB register failed: %d", result);
return result;
if (!cb_registered) {
result = bt_vcp_vol_ctlr_cb_register(&vcp_cbs);
if (result != 0) {
shell_print(sh, "CB register failed: %d", result);
return result;
}

cb_registered = true;
}

if (default_conn == NULL) {
Expand Down
Loading
Loading