Skip to content

Commit 57b35e1

Browse files
Thalleyfabiobaltieri
authored andcommitted
Bluetooth: TBS: Allow multiple callbacks for client
The TBS client callbacks are just informative so we provide the information to multiple listeners. To support this for the long strings, the function handle_string_long_read was refactored. This also allows for multiple users of the TBS client. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 94e5481 commit 57b35e1

File tree

8 files changed

+420
-249
lines changed

8 files changed

+420
-249
lines changed

doc/releases/release-notes-4.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Bluetooth
7878

7979
* Audio
8080

81+
* :c:func:`bt_tbs_client_register_cb` now supports multiple listeners and may now return an error.
82+
8183
* Host
8284

8385
* Added API :c:func:`bt_gatt_get_uatt_mtu` to get current Unenhanced ATT MTU of a given

include/zephyr/bluetooth/audio/tbs.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdbool.h>
3131

3232
#include <zephyr/bluetooth/conn.h>
33+
#include <zephyr/sys/slist.h>
3334
#include <zephyr/sys/util_macro.h>
3435

3536
#ifdef __cplusplus
@@ -680,6 +681,9 @@ struct bt_tbs_client_cb {
680681
/** Bearer friendly name has been read */
681682
bt_tbs_client_read_string_cb friendly_name;
682683
#endif /* defined(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) */
684+
685+
/** @internal Internally used field for list handling */
686+
sys_snode_t _node;
683687
};
684688

685689
/**
@@ -998,8 +1002,12 @@ int bt_tbs_client_read_optional_opcodes(struct bt_conn *conn,
9981002
* @brief Register the callbacks for CCP.
9991003
*
10001004
* @param cbs Pointer to the callback structure.
1005+
*
1006+
* @retval 0 Success
1007+
* @retval -EINVAL @p cbs is NULL
1008+
* @retval -EEXIST @p cbs is already registered
10011009
*/
1002-
void bt_tbs_client_register_cb(const struct bt_tbs_client_cb *cbs);
1010+
int bt_tbs_client_register_cb(struct bt_tbs_client_cb *cbs);
10031011

10041012
/**
10051013
* @brief Look up Telephone Bearer Service instance by CCID

samples/bluetooth/hap_ha/src/ccp_call_ctrl.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,5 @@ struct bt_tbs_client_cb tbs_client_cb = {
155155

156156
int ccp_call_ctrl_init(void)
157157
{
158-
bt_tbs_client_register_cb(&tbs_client_cb);
159-
160-
return 0;
158+
return bt_tbs_client_register_cb(&tbs_client_cb);
161159
}

samples/bluetooth/tmap_peripheral/src/ccp_call_ctrl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ int ccp_call_ctrl_init(struct bt_conn *conn)
124124
int err;
125125

126126
default_conn = bt_conn_ref(conn);
127-
bt_tbs_client_register_cb(&tbs_client_cb);
127+
err = bt_tbs_client_register_cb(&tbs_client_cb);
128+
if (err != 0) {
129+
return err;
130+
}
131+
128132
err = bt_tbs_client_discover(conn);
129133
if (err != 0) {
130134
return err;

0 commit comments

Comments
 (0)