Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Girdwood <liam.r.girdwood@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Takashi Iwai <tiwai@suse.de>, Vinod Koul <vinod.koul@intel.com>,
	Mark Brown <broonie@kernel.org>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>
Subject: [PATCH v2 04/13] topology: Add text section parser.
Date: Wed,  1 Jul 2015 14:44:26 +0100	[thread overview]
Message-ID: <1435758275-4047-4-git-send-email-liam.r.girdwood@linux.intel.com> (raw)
In-Reply-To: <1435758275-4047-1-git-send-email-liam.r.girdwood@linux.intel.com>

Parse text lists (like enum values) and store for later attachment
to other objects.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
---
 src/topology/text.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 src/topology/text.c

diff --git a/src/topology/text.c b/src/topology/text.c
new file mode 100644
index 0000000..d24d027
--- /dev/null
+++ b/src/topology/text.c
@@ -0,0 +1,99 @@
+/*
+  Copyright(c) 2014-2015 Intel Corporation
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of version 2 of the GNU General Public License as
+  published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  General Public License for more details.
+
+  Authors: Mengdong Lin <mengdong.lin@intel.com>
+           Yao Jin <yao.jin@intel.com>
+           Liam Girdwood <liam.r.girdwood@linux.intel.com>
+
+*/
+
+#include "list.h"
+#include "tplg_local.h"
+
+#define TEXT_SIZE_MAX \
+	(SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
+
+static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem)
+{
+	snd_config_iterator_t i, next;
+	snd_config_t *n;
+	const char *value = NULL;
+	int j = 0;
+
+	tplg_dbg(" Text Values: %s\n", elem->id);
+
+	snd_config_for_each(i, next, cfg) {
+		n = snd_config_iterator_entry(i);
+
+		if (j == SND_SOC_TPLG_NUM_TEXTS) {
+			tplg_dbg("error: text string number exceeds %d\n", j);
+			return -ENOMEM;
+		}
+
+		/* get value */
+		if (snd_config_get_string(n, &value) < 0)
+			continue;
+
+		strncpy(&elem->texts[j][0], value,
+			SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
+		elem->texts[j][SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0;
+		tplg_dbg("\t%s\n", &elem->texts[j][0]);
+
+		j++;
+	}
+
+	return 0;
+}
+
+/* Parse Text data.
+ *
+ * Object text strings.
+ *
+ * SectionText."text name" {
+ *
+ *		Values [
+ *
+ *		]
+ * }
+ */
+int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg,
+	void *private ATTRIBUTE_UNUSED)
+{
+	snd_config_iterator_t i, next;
+	snd_config_t *n;
+	const char *id;
+	int err = 0;
+	struct tplg_elem *elem;
+
+	elem = tplg_elem_new_common(tplg, cfg, PARSER_TYPE_TEXT);
+	if (!elem)
+		return -ENOMEM;
+
+	snd_config_for_each(i, next, cfg) {
+
+		n = snd_config_iterator_entry(i);
+		if (snd_config_get_id(n, &id) < 0)
+			continue;
+
+		if (strcmp(id, "values") == 0) {
+			err = parse_text_values(n, elem);
+			if (err < 0) {
+				fprintf(stderr, "error: failed to parse text values");
+				return err;
+			}
+			continue;
+		}
+	}
+
+	return err;
+}
-- 
2.1.4

  parent reply	other threads:[~2015-07-01 13:45 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 13:44 [PATCH v2 01/13] topology: uapi: Add UAPI headers for topology ABI Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 02/13] conf: topology: Add topology file for broadwell audio DSP Liam Girdwood
2015-07-01 15:47   ` Takashi Iwai
2015-07-01 16:16     ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 03/13] topology: Add topology core parser Liam Girdwood
2015-07-01 16:00   ` Takashi Iwai
2015-07-01 13:44 ` Liam Girdwood [this message]
2015-07-01 16:03   ` [PATCH v2 04/13] topology: Add text section parser Takashi Iwai
2015-07-01 13:44 ` [PATCH v2 05/13] topology: Add PCM parser Liam Girdwood
2015-07-01 16:14   ` Takashi Iwai
2015-07-01 16:20     ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 06/13] topology: Add operations parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 07/13] topology: Add private data parser Liam Girdwood
2015-07-01 16:20   ` Takashi Iwai
2015-07-07 15:54     ` Liam Girdwood
2015-07-07 16:19       ` Takashi Iwai
2015-07-08  8:57         ` Liam Girdwood
2015-07-08 13:31           ` Jin, Yao
2015-07-08 14:14             ` Takashi Iwai
2015-07-08 14:21               ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 08/13] topology: Add DAPM object parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 09/13] topology: Add CTL parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 10/13] topology: Add Channel map parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 11/13] topology: Add binary file builder Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 12/13] topology: autotools: Add build support for topology core Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 13/13] topology: doxygen: Add doxygen " Liam Girdwood

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=1435758275-4047-4-git-send-email-liam.r.girdwood@linux.intel.com \
    --to=liam.r.girdwood@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox