From patchwork Wed Jul 29 16:45:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 6895381 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 84FD19F39D for ; Wed, 29 Jul 2015 16:47:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A66F32062D for ; Wed, 29 Jul 2015 16:47:25 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id E16BD20663 for ; Wed, 29 Jul 2015 16:47:19 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 45093265D21; Wed, 29 Jul 2015 18:47:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E14BE2659DF; Wed, 29 Jul 2015 18:45:59 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9F4AE2658D2; Wed, 29 Jul 2015 18:45:54 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by alsa0.perex.cz (Postfix) with ESMTP id 4C94D2605E8 for ; Wed, 29 Jul 2015 18:45:47 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 29 Jul 2015 09:45:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,572,1432623600"; d="scan'208";a="615321001" Received: from iikavana-mobl1.ger.corp.intel.com (HELO loki.ger.corp.intel.com) ([10.252.21.221]) by orsmga003.jf.intel.com with ESMTP; 29 Jul 2015 09:45:45 -0700 From: Liam Girdwood To: Date: Wed, 29 Jul 2015 17:45:15 +0100 Message-Id: <1438188325-11553-4-git-send-email-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438188325-11553-1-git-send-email-liam.r.girdwood@linux.intel.com> References: <1438188325-11553-1-git-send-email-liam.r.girdwood@linux.intel.com> Cc: Takashi Iwai , Liam Girdwood , Mark Brown Subject: [alsa-devel] [PATCH v3 03/13] topology: Add text section parser. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Parse text lists (like enum values) and store for later attachment to other objects. Signed-off-by: Liam Girdwood --- src/topology/text.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 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..ebb6e38 --- /dev/null +++ b/src/topology/text.c @@ -0,0 +1,88 @@ +/* + 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 + Yao Jin + Liam Girdwood + +*/ + +#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; + + elem_copy_text(&elem->texts[j][0], value, + SNDRV_CTL_ELEM_ID_NAME_MAXLEN); + tplg_dbg("\t%s\n", &elem->texts[j][0]); + + j++; + } + + return 0; +} + +/* Parse Text data */ +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, OBJECT_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) { + SNDERR("error: failed to parse text values"); + return err; + } + continue; + } + } + + return err; +}