Commit 7cc5be0d authored by Mariusz Skamra's avatar Mariusz Skamra Committed by Carles Cufi
Browse files

bluetooth: audio: pacs: Remove duplicated code

Remove code duplicates

Signed-off-by: default avatarMariusz Skamra <mariusz.skamra@codecoup.pl>
parent b609c7a4
Loading
Loading
Loading
Loading
+2 −2
Changes for subsys/bluetooth/audio/capabilities.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ int bt_audio_capability_register(struct bt_audio_capability *cap)
	sys_slist_append(lst, &cap->_node);

#if defined(CONFIG_BT_PACS)
	bt_pacs_add_capability(cap->dir);
	bt_pacs_capabilities_changed(cap->dir);
#endif /* CONFIG_BT_PACS */

	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 */

#if defined(CONFIG_BT_PACS)
	bt_pacs_remove_capability(cap->dir);
	bt_pacs_capabilities_changed(cap->dir);
#endif /* CONFIG_BT_PACS */

	return 0;
+9 −27
Changes for subsys/bluetooth/audio/pacs.c: 9 added lines, 27 removed lines.
Original line number Diff line number Diff line
@@ -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)
static void pac_notify_loc(struct k_work *work);

static int get_pac_loc(struct bt_conn *conn, enum bt_audio_dir dir,
		       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 */

static void pac_notify(struct k_work *work);

#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,
			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)
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,
			    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 */

#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,
			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)
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,
			    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)
{
	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)
void bt_pacs_capabilities_changed(enum bt_audio_dir dir)
{
	struct k_work_delayable *work;

@@ -628,11 +615,6 @@ int bt_audio_pacs_location_changed(enum bt_audio_dir dir)
		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);

	return 0;
+1 −2
Changes for subsys/bluetooth/audio/pacs_internal.h: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ struct bt_pacs_context {
	uint16_t  src;
} __packed;

void bt_pacs_add_capability(enum bt_audio_dir dir);
void bt_pacs_remove_capability(enum bt_audio_dir dir);
void bt_pacs_capabilities_changed(enum bt_audio_dir dir);
int bt_pacs_available_contexts_changed(void);
bool bt_pacs_context_available(enum bt_audio_dir dir, uint16_t context);