Skip to content

Commit 867f363

Browse files
committed
bluetooth: audio: pacs: Remove duplicated code
Remove code duplicates Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 8544547 commit 867f363

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

subsys/bluetooth/audio/capabilities.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ int bt_audio_capability_register(struct bt_audio_capability *cap)
402402
sys_slist_append(lst, &cap->_node);
403403

404404
#if defined(CONFIG_BT_PACS)
405-
bt_pacs_add_capability(cap->dir);
405+
bt_pacs_capabilities_changed(cap->dir);
406406
#endif /* CONFIG_BT_PACS */
407407

408408
return 0;
@@ -445,7 +445,7 @@ int bt_audio_capability_unregister(struct bt_audio_capability *cap)
445445
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER && CONFIG_BT_ASCS */
446446

447447
#if defined(CONFIG_BT_PACS)
448-
bt_pacs_remove_capability(cap->dir);
448+
bt_pacs_capabilities_changed(cap->dir);
449449
#endif /* CONFIG_BT_PACS */
450450

451451
return 0;

subsys/bluetooth/audio/pacs.c

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ static ssize_t supported_context_read(struct bt_conn *conn,
222222
}
223223

224224
#if defined(CONFIG_BT_PAC_SNK_LOC) || defined(CONFIG_BT_PAC_SRC_LOC)
225+
static void pac_notify_loc(struct k_work *work);
226+
225227
static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
226228
enum bt_audio_location *location)
227229
{
@@ -244,8 +246,10 @@ static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
244246
}
245247
#endif /* CONFIG_BT_PAC_SNK_LOC || CONFIG_BT_PAC_SRC_LOC */
246248

249+
static void pac_notify(struct k_work *work);
250+
247251
#if defined(CONFIG_BT_PAC_SNK)
248-
static struct k_work_delayable snks_work;
252+
static K_WORK_DELAYABLE_DEFINE(snks_work, pac_notify);
249253

250254
static ssize_t snk_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
251255
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)
262266
}
263267

264268
#if defined(CONFIG_BT_PAC_SNK_LOC)
265-
static struct k_work_delayable snks_loc_work;
269+
static K_WORK_DELAYABLE_DEFINE(snks_loc_work, pac_notify_loc);
266270

267271
static ssize_t snk_loc_read(struct bt_conn *conn,
268272
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)
341345
#endif /* CONFIG_BT_PAC_SNK */
342346

343347
#if defined(CONFIG_BT_PAC_SRC)
344-
static struct k_work_delayable srcs_work;
348+
static K_WORK_DELAYABLE_DEFINE(srcs_work, pac_notify);
345349

346350
static ssize_t src_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
347351
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)
358362
}
359363

360364
#if defined(CONFIG_BT_PAC_SRC_LOC)
361-
static struct k_work_delayable srcs_loc_work;
365+
static K_WORK_DELAYABLE_DEFINE(srcs_loc_work, pac_notify_loc);
362366

363367
static ssize_t src_loc_read(struct bt_conn *conn,
364368
const struct bt_gatt_attr *attr, void *buf,
@@ -588,24 +592,7 @@ static void pac_notify(struct k_work *work)
588592
}
589593
}
590594

591-
void bt_pacs_add_capability(enum bt_audio_dir dir)
592-
{
593-
struct k_work_delayable *work;
594-
595-
work = bt_pacs_get_work(dir);
596-
if (!work) {
597-
return;
598-
}
599-
600-
/* Initialize handler if it hasn't been initialized */
601-
if (!work->work.handler) {
602-
k_work_init_delayable(work, pac_notify);
603-
}
604-
605-
k_work_reschedule(work, PAC_NOTIFY_TIMEOUT);
606-
}
607-
608-
void bt_pacs_remove_capability(enum bt_audio_dir dir)
595+
void bt_pacs_capabilities_changed(enum bt_audio_dir dir)
609596
{
610597
struct k_work_delayable *work;
611598

@@ -628,11 +615,6 @@ int bt_audio_pacs_location_changed(enum bt_audio_dir dir)
628615
return -EINVAL;
629616
}
630617

631-
/* Initialize handler if it hasn't been initialized */
632-
if (!work->work.handler) {
633-
k_work_init_delayable(work, pac_notify_loc);
634-
}
635-
636618
k_work_reschedule(work, PAC_NOTIFY_TIMEOUT);
637619

638620
return 0;

subsys/bluetooth/audio/pacs_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct bt_pacs_context {
5050
uint16_t src;
5151
} __packed;
5252

53-
void bt_pacs_add_capability(enum bt_audio_dir dir);
54-
void bt_pacs_remove_capability(enum bt_audio_dir dir);
53+
void bt_pacs_capabilities_changed(enum bt_audio_dir dir);
5554
int bt_pacs_available_contexts_changed(void);
5655
bool bt_pacs_context_available(enum bt_audio_dir dir, uint16_t context);

0 commit comments

Comments
 (0)