All of lore.kernel.org
 help / color / mirror / Atom feed
From: fuweix.tang@intel.com
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com,
	Fuwei Tang <fuweix.tang@intel.com>,
	mengdong.lin@intel.com
Subject: [PATCH 1/4] topology: Insert new element based on its index value
Date: Thu, 13 Apr 2017 14:52:44 +0800	[thread overview]
Message-ID: <e66116f15b18105a993a73047069b2ebe2ed438e.1492065639.git.fuweix.tang@intel.com> (raw)
In-Reply-To: <cover.1492065639.git.fuweix.tang@intel.com>
In-Reply-To: <cover.1492065639.git.fuweix.tang@intel.com>

From: Fuwei Tang <fuweix.tang@intel.com>

When creating a new element, insert it into the list in the ascending order of
index value.

Signed-off-by: Fuwei Tang <fuweix.tang@intel.com>
Reviewed-by: Mengdong Lin <mengdong.lin@linux.intel.com>
---
 src/topology/elem.c | 67 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 18 deletions(-)

diff --git a/src/topology/elem.c b/src/topology/elem.c
index efcf3e9..3ed655a 100644
--- a/src/topology/elem.c
+++ b/src/topology/elem.c
@@ -126,14 +126,33 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id,
 	return NULL;
 }
 
+/* insert a new element into list in the ascending order of index value*/
+static void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list)
+{
+	struct list_head *pos, *p = &(elem_p->list);
+	struct tplg_elem *elem;
+
+	list_for_each(pos, list) {
+		elem = list_entry(pos, struct tplg_elem, list);
+		if (elem_p->index < elem->index)
+			break;
+	}
+	p->prev = pos->prev;
+	pos->prev->next = p;
+	pos->prev = p;
+	p->next = pos;
+}
+
 /* create a new common element and object */
 struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
 	snd_config_t *cfg, const char *name, enum snd_tplg_type type)
 {
 	struct tplg_elem *elem;
-	const char *id;
+	const char *id, *val = NULL;
 	int obj_size = 0;
 	void *obj;
+	snd_config_iterator_t i, next;
+	snd_config_t *n;
 
 	if (!cfg && !name)
 		return NULL;
@@ -147,75 +166,87 @@ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
 		snd_config_get_id(cfg, &id);
 		elem_copy_text(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
 		elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
+		/* as we insert new elem based on the index value, move index
+		   parsing here */
+		snd_config_for_each(i, next, cfg) {
+			n = snd_config_iterator_entry(i);
+			if (snd_config_get_id(n, &id))
+				continue;
+			if (strcmp(id, "index") == 0) {
+				if (snd_config_get_string(n, &val) < 0)
+					return NULL;
+				elem->index = atoi(val);
+			}
+		}
 	} else if (name != NULL)
 		elem_copy_text(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
 
 	switch (type) {
 	case SND_TPLG_TYPE_DATA:
-		list_add_tail(&elem->list, &tplg->pdata_list);
+		tplg_elem_insert(elem, &tplg->pdata_list);
 		break;
 	case SND_TPLG_TYPE_MANIFEST:
-		list_add_tail(&elem->list, &tplg->manifest_list);
+		tplg_elem_insert(elem, &tplg->manifest_list);
 		obj_size = sizeof(struct snd_soc_tplg_manifest);
 		break;
 	case SND_TPLG_TYPE_TEXT:
-		list_add_tail(&elem->list, &tplg->text_list);
+		tplg_elem_insert(elem, &tplg->text_list);
 		obj_size = sizeof(struct tplg_texts);
 		break;
 	case SND_TPLG_TYPE_TLV:
-		list_add_tail(&elem->list, &tplg->tlv_list);
+		tplg_elem_insert(elem, &tplg->tlv_list);
 		elem->size = sizeof(struct snd_soc_tplg_ctl_tlv);
 		break;
 	case SND_TPLG_TYPE_BYTES:
-		list_add_tail(&elem->list, &tplg->bytes_ext_list);
+		tplg_elem_insert(elem, &tplg->bytes_ext_list);
 		obj_size = sizeof(struct snd_soc_tplg_bytes_control);
 		break;
 	case SND_TPLG_TYPE_ENUM:
-		list_add_tail(&elem->list, &tplg->enum_list);
+		tplg_elem_insert(elem, &tplg->enum_list);
 		obj_size = sizeof(struct snd_soc_tplg_enum_control);
 		break;
 	case SND_TPLG_TYPE_MIXER:
-		list_add_tail(&elem->list, &tplg->mixer_list);
+		tplg_elem_insert(elem, &tplg->mixer_list);
 		obj_size = sizeof(struct snd_soc_tplg_mixer_control);
 		break;
 	case SND_TPLG_TYPE_DAPM_WIDGET:
-		list_add_tail(&elem->list, &tplg->widget_list);
+		tplg_elem_insert(elem, &tplg->widget_list);
 		obj_size = sizeof(struct snd_soc_tplg_dapm_widget);
 		break;
 	case SND_TPLG_TYPE_STREAM_CONFIG:
-		list_add_tail(&elem->list, &tplg->pcm_config_list);
+		tplg_elem_insert(elem, &tplg->pcm_config_list);
 		obj_size = sizeof(struct snd_soc_tplg_stream);
 		break;
 	case SND_TPLG_TYPE_STREAM_CAPS:
-		list_add_tail(&elem->list, &tplg->pcm_caps_list);
+		tplg_elem_insert(elem, &tplg->pcm_caps_list);
 		obj_size = sizeof(struct snd_soc_tplg_stream_caps);
 		break;
 	case SND_TPLG_TYPE_PCM:
-		list_add_tail(&elem->list, &tplg->pcm_list);
+		tplg_elem_insert(elem, &tplg->pcm_list);
 		obj_size = sizeof(struct snd_soc_tplg_pcm);
 		break;
 	case SND_TPLG_TYPE_DAI:
-		list_add_tail(&elem->list, &tplg->dai_list);
+		tplg_elem_insert(elem, &tplg->dai_list);
 		obj_size = sizeof(struct snd_soc_tplg_dai);
 		break;
 	case SND_TPLG_TYPE_BE:
 	case SND_TPLG_TYPE_LINK:
-		list_add_tail(&elem->list, &tplg->be_list);
+		tplg_elem_insert(elem, &tplg->be_list);
 		obj_size = sizeof(struct snd_soc_tplg_link_config);
 		break;
 	case SND_TPLG_TYPE_CC:
-		list_add_tail(&elem->list, &tplg->cc_list);
+		tplg_elem_insert(elem, &tplg->cc_list);
 		obj_size = sizeof(struct snd_soc_tplg_link_config);
 		break;
 	case SND_TPLG_TYPE_TOKEN:
-		list_add_tail(&elem->list, &tplg->token_list);
+		tplg_elem_insert(elem, &tplg->token_list);
 		break;
 	case SND_TPLG_TYPE_TUPLE:
-		list_add_tail(&elem->list, &tplg->tuple_list);
+		tplg_elem_insert(elem, &tplg->tuple_list);
 		elem->free = tplg_free_tuples;
 		break;
 	case SND_TPLG_TYPE_HW_CONFIG:
-		list_add_tail(&elem->list, &tplg->hw_cfg_list);
+		tplg_elem_insert(elem, &tplg->hw_cfg_list);
 		obj_size = sizeof(struct snd_soc_tplg_hw_config);
 		break;
 	default:
-- 
2.7.4

  reply	other threads:[~2017-04-13  6:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13  6:52 [PATCH 0/4] topology: Support using "index" to group objects when generating binary for kernel fuweix.tang
2017-04-13  6:52 ` fuweix.tang [this message]
2017-04-13  6:52 ` [PATCH 2/4] topology: Remove code parsing index value in paring each object fuweix.tang
2017-04-13  6:52 ` [PATCH 3/4] topology: Look up references for an object based on its index fuweix.tang
2017-04-13  6:52 ` [PATCH 4/4] topology: Group elements with the same index value into a block fuweix.tang
2017-04-21 10:58 ` [PATCH 0/4] topology: Support using "index" to group objects when generating binary for kernel Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e66116f15b18105a993a73047069b2ebe2ed438e.1492065639.git.fuweix.tang@intel.com \
    --to=fuweix.tang@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=mengdong.lin@intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.