bluetooth: audio: pacs: Remove duplicated code
Remove code duplicates Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
parent
b609c7a474
commit
7cc5be0dcf
3 changed files with 12 additions and 31 deletions
|
@ -402,7 +402,7 @@ int bt_audio_capability_register(struct bt_audio_capability *cap)
|
||||||
sys_slist_append(lst, &cap->_node);
|
sys_slist_append(lst, &cap->_node);
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PACS)
|
#if defined(CONFIG_BT_PACS)
|
||||||
bt_pacs_add_capability(cap->dir);
|
bt_pacs_capabilities_changed(cap->dir);
|
||||||
#endif /* CONFIG_BT_PACS */
|
#endif /* CONFIG_BT_PACS */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -445,7 +445,7 @@ int bt_audio_capability_unregister(struct bt_audio_capability *cap)
|
||||||
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER && CONFIG_BT_ASCS */
|
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER && CONFIG_BT_ASCS */
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PACS)
|
#if defined(CONFIG_BT_PACS)
|
||||||
bt_pacs_remove_capability(cap->dir);
|
bt_pacs_capabilities_changed(cap->dir);
|
||||||
#endif /* CONFIG_BT_PACS */
|
#endif /* CONFIG_BT_PACS */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -222,6 +222,8 @@ static ssize_t supported_context_read(struct bt_conn *conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PAC_SNK_LOC) || defined(CONFIG_BT_PAC_SRC_LOC)
|
#if defined(CONFIG_BT_PAC_SNK_LOC) || defined(CONFIG_BT_PAC_SRC_LOC)
|
||||||
|
static void pac_notify_loc(struct k_work *work);
|
||||||
|
|
||||||
static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
|
static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
|
||||||
enum bt_audio_location *location)
|
enum bt_audio_location *location)
|
||||||
{
|
{
|
||||||
|
@ -244,8 +246,10 @@ static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */
|
#endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */
|
||||||
|
|
||||||
|
static void pac_notify(struct k_work *work);
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PAC_SNK)
|
#if defined(CONFIG_BT_PAC_SNK)
|
||||||
static struct k_work_delayable snks_work;
|
static K_WORK_DELAYABLE_DEFINE(snks_work, pac_notify);
|
||||||
|
|
||||||
static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
|
@ -262,7 +266,7 @@ static void snk_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PAC_SNK_LOC)
|
#if defined(CONFIG_BT_PAC_SNK_LOC)
|
||||||
static struct k_work_delayable snks_loc_work;
|
static K_WORK_DELAYABLE_DEFINE(snks_loc_work, pac_notify_loc);
|
||||||
|
|
||||||
static ssize_t snk_loc_read(struct bt_conn *conn,
|
static ssize_t snk_loc_read(struct bt_conn *conn,
|
||||||
const struct bt_gatt_attr *attr, void *buf,
|
const struct bt_gatt_attr *attr, void *buf,
|
||||||
|
@ -341,7 +345,7 @@ static void snk_loc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||||
#endif /* CONFIG_BT_PAC_SNK */
|
#endif /* CONFIG_BT_PAC_SNK */
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PAC_SRC)
|
#if defined(CONFIG_BT_PAC_SRC)
|
||||||
static struct k_work_delayable srcs_work;
|
static K_WORK_DELAYABLE_DEFINE(srcs_work, pac_notify);
|
||||||
|
|
||||||
static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
void *buf, uint16_t len, uint16_t offset)
|
void *buf, uint16_t len, uint16_t offset)
|
||||||
|
@ -358,7 +362,7 @@ static void src_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_PAC_SRC_LOC)
|
#if defined(CONFIG_BT_PAC_SRC_LOC)
|
||||||
static struct k_work_delayable srcs_loc_work;
|
static K_WORK_DELAYABLE_DEFINE(srcs_loc_work, pac_notify_loc);
|
||||||
|
|
||||||
static ssize_t src_loc_read(struct bt_conn *conn,
|
static ssize_t src_loc_read(struct bt_conn *conn,
|
||||||
const struct bt_gatt_attr *attr, void *buf,
|
const struct bt_gatt_attr *attr, void *buf,
|
||||||
|
@ -588,24 +592,7 @@ static void pac_notify(struct k_work *work)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_pacs_add_capability(enum bt_audio_dir dir)
|
void bt_pacs_capabilities_changed(enum bt_audio_dir dir)
|
||||||
{
|
|
||||||
struct k_work_delayable *work;
|
|
||||||
|
|
||||||
work = bt_pacs_get_work(dir);
|
|
||||||
if (!work) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize handler if it hasn't been initialized */
|
|
||||||
if (!work->work.handler) {
|
|
||||||
k_work_init_delayable(work, pac_notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
k_work_reschedule(work, PAC_NOTIFY_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bt_pacs_remove_capability(enum bt_audio_dir dir)
|
|
||||||
{
|
{
|
||||||
struct k_work_delayable *work;
|
struct k_work_delayable *work;
|
||||||
|
|
||||||
|
@ -628,11 +615,6 @@ int bt_audio_pacs_location_changed(enum bt_audio_dir dir)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize handler if it hasn't been initialized */
|
|
||||||
if (!work->work.handler) {
|
|
||||||
k_work_init_delayable(work, pac_notify_loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
k_work_reschedule(work, PAC_NOTIFY_TIMEOUT);
|
k_work_reschedule(work, PAC_NOTIFY_TIMEOUT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -50,7 +50,6 @@ struct bt_pacs_context {
|
||||||
uint16_t src;
|
uint16_t src;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
void bt_pacs_add_capability(enum bt_audio_dir dir);
|
void bt_pacs_capabilities_changed(enum bt_audio_dir dir);
|
||||||
void bt_pacs_remove_capability(enum bt_audio_dir dir);
|
|
||||||
int bt_pacs_available_contexts_changed(void);
|
int bt_pacs_available_contexts_changed(void);
|
||||||
bool bt_pacs_context_available(enum bt_audio_dir dir, uint16_t context);
|
bool bt_pacs_context_available(enum bt_audio_dir dir, uint16_t context);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue