Bluetooth: Audio: AICS client add function to get conn pointer

Add a function that returns the bluetooth connection
pointer of a given AICS client instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-06-09 10:34:22 +02:00 committed by Anas Nashif
commit 141620519b
4 changed files with 59 additions and 0 deletions

View file

@ -131,6 +131,19 @@ struct bt_aics *bt_aics_free_instance_get(void);
*/
void *bt_aics_svc_decl_get(struct bt_aics *aics);
/**
* @brief Get the connection pointer of a client instance
*
* Get the Bluetooth connection pointer of a Audio Input Control Service
* client instance.
*
* @param aics Audio Input Control Service client instance pointer.
* @param conn Connection pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn);
/**
* @brief Initialize the Audio Input Control Service instance.
*

View file

@ -702,6 +702,28 @@ struct bt_aics *bt_aics_client_free_instance_get(void)
return NULL;
}
int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn)
{
CHECKIF(aics == NULL) {
BT_DBG("NULL aics pointer");
return -EINVAL;
}
if (!aics->client_instance) {
BT_DBG("aics pointer shall be client instance");
return -EINVAL;
}
if (aics->cli.conn == NULL) {
BT_DBG("aics pointer not associated with a connection. "
"Do discovery first");
return -ENOTCONN;
}
*conn = aics->cli.conn;
return 0;
}
int bt_aics_client_state_get(struct bt_aics *inst)
{
int err;

View file

@ -235,6 +235,18 @@ static int test_aics(void)
uint8_t expected_mode;
uint8_t expected_input_type;
char expected_aics_desc[AICS_DESC_SIZE];
struct bt_conn *cached_conn;
printk("Getting AICS client conn\n");
err = bt_aics_client_conn_get(mics_included.aics[0], &cached_conn);
if (err != 0) {
FAIL("Could not get AICS client conn (err %d)\n", err);
return err;
}
if (cached_conn != g_conn) {
FAIL("Cached conn was not the conn used to discover");
return -ENOTCONN;
}
printk("Getting AICS state\n");
g_cb = false;

View file

@ -308,6 +308,18 @@ static int test_aics(void)
uint8_t expected_mode;
uint8_t expected_input_type;
char expected_aics_desc[AICS_DESC_SIZE];
struct bt_conn *cached_conn;
printk("Getting AICS client conn\n");
err = bt_aics_client_conn_get(vcs_included.aics[0], &cached_conn);
if (err != 0) {
FAIL("Could not get AICS client conn (err %d)\n", err);
return err;
}
if (cached_conn != g_conn) {
FAIL("Cached conn was not the conn used to discover");
return -ENOTCONN;
}
printk("Getting AICS state\n");
g_cb = false;