From patchwork Tue Aug 4 17:09:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 6942851 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 365A7C05AC for ; Tue, 4 Aug 2015 17:09:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 319CE205B4 for ; Tue, 4 Aug 2015 17:09:47 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id CD0E120585 for ; Tue, 4 Aug 2015 17:09:45 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id F10452659CC; Tue, 4 Aug 2015 19:09:44 +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,NO_DNS_FOR_FROM, 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 C8C4F26057F; Tue, 4 Aug 2015 19:09:36 +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 09DA4260656; Tue, 4 Aug 2015 19:09:34 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 03EC5260532 for ; Tue, 4 Aug 2015 19:09:28 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 04 Aug 2015 10:09:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,610,1432623600"; d="scan'208";a="742067047" Received: from unknown (HELO loki.ger.corp.intel.com) ([10.252.23.69]) by orsmga001.jf.intel.com with ESMTP; 04 Aug 2015 10:09:17 -0700 From: Liam Girdwood To: Date: Tue, 4 Aug 2015 18:09:12 +0100 Message-Id: <1438708152-16223-1-git-send-email-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 1.9.1 Cc: Takashi Iwai , Mengdong Lin , Jin Yao , Mark Brown Subject: [alsa-devel] [PATCH] topology: Add element ID so we can look up references by name. 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 From: Jin Yao Add support to lookup elements by name. This is in preparation for adding some new API calls that will allow building topology data using a C API. This will allow applications to build thier own topology data directly. Signed-off-by: Jin Yao Signed-off-by: Mengdong Lin --- src/topology/ctl.c | 9 ++++----- src/topology/dapm.c | 2 +- src/topology/data.c | 2 +- src/topology/elem.c | 15 +++++++++++---- src/topology/pcm.c | 10 +++++----- src/topology/text.c | 2 +- src/topology/tplg_local.h | 2 +- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/topology/ctl.c b/src/topology/ctl.c index 9c1333c..aa06ff6 100644 --- a/src/topology/ctl.c +++ b/src/topology/ctl.c @@ -264,7 +264,7 @@ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, int err = 0; struct tplg_elem *elem; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_TLV); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_TLV); if (!elem) return -ENOMEM; @@ -298,7 +298,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, const char *id, *val = NULL; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_BYTES); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_BYTES); if (!elem) return -ENOMEM; @@ -403,11 +403,10 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, const char *id, *val = NULL; int err, j; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_ENUM); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_ENUM); if (!elem) return -ENOMEM; - /* init new mixer */ ec = elem->enum_ctrl; elem_copy_text(ec->hdr.name, elem->id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); ec->hdr.type = SND_SOC_TPLG_TYPE_ENUM; @@ -501,7 +500,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, const char *id, *val = NULL; int err, j; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_MIXER); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_MIXER); if (!elem) return -ENOMEM; diff --git a/src/topology/dapm.c b/src/topology/dapm.c index 1da82ad..7e26ea0 100644 --- a/src/topology/dapm.c +++ b/src/topology/dapm.c @@ -420,7 +420,7 @@ int tplg_parse_dapm_widget(snd_tplg_t *tplg, const char *id, *val = NULL; int widget_type, err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_DAPM_WIDGET); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_DAPM_WIDGET); if (!elem) return -ENOMEM; diff --git a/src/topology/data.c b/src/topology/data.c index 13e1e2b..c768bc5 100644 --- a/src/topology/data.c +++ b/src/topology/data.c @@ -268,7 +268,7 @@ int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, int err = 0; struct tplg_elem *elem; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_DATA); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_DATA); if (!elem) return -ENOMEM; diff --git a/src/topology/elem.c b/src/topology/elem.c index d7a1fd7..7fee653 100644 --- a/src/topology/elem.c +++ b/src/topology/elem.c @@ -103,20 +103,27 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id, /* create a new common element and object */ struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, - snd_config_t *cfg, enum object_type type) + snd_config_t *cfg, const char *name, enum object_type type) { struct tplg_elem *elem; const char *id; int obj_size = 0; void *obj; + if (!cfg && !name) + return NULL; + elem = tplg_elem_new(); if (!elem) return NULL; - snd_config_get_id(cfg, &id); - strncpy(elem->id, id, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); - elem->id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0; + /* do we get name from cfg */ + if (cfg) { + 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; + } else if (name != NULL) + elem_copy_text(elem->id, name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); switch (type) { case OBJECT_TYPE_DATA: diff --git a/src/topology/pcm.c b/src/topology/pcm.c index 8f23a6f..deae47b 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -228,7 +228,7 @@ int tplg_parse_pcm_config(snd_tplg_t *tplg, const char *id; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_STREAM_CONFIG); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_STREAM_CONFIG); if (!elem) return -ENOMEM; @@ -294,7 +294,7 @@ int tplg_parse_pcm_caps(snd_tplg_t *tplg, char *s; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_STREAM_CAPS); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_STREAM_CAPS); if (!elem) return -ENOMEM; @@ -461,7 +461,7 @@ int tplg_parse_pcm(snd_tplg_t *tplg, const char *id, *val = NULL; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_PCM); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_PCM); if (!elem) return -ENOMEM; @@ -524,7 +524,7 @@ int tplg_parse_be(snd_tplg_t *tplg, const char *id, *val = NULL; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_BE); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_BE); if (!elem) return -ENOMEM; @@ -587,7 +587,7 @@ int tplg_parse_cc(snd_tplg_t *tplg, const char *id, *val = NULL; int err; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_CC); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_CC); if (!elem) return -ENOMEM; diff --git a/src/topology/text.c b/src/topology/text.c index ebb6e38..7128056 100644 --- a/src/topology/text.c +++ b/src/topology/text.c @@ -64,7 +64,7 @@ int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, int err = 0; struct tplg_elem *elem; - elem = tplg_elem_new_common(tplg, cfg, OBJECT_TYPE_TEXT); + elem = tplg_elem_new_common(tplg, cfg, NULL, OBJECT_TYPE_TEXT); if (!elem) return -ENOMEM; diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h index 688c78f..62788e4 100644 --- a/src/topology/tplg_local.h +++ b/src/topology/tplg_local.h @@ -216,7 +216,7 @@ struct tplg_elem *tplg_elem_lookup(struct list_head *base, const char* id, unsigned int type); struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg, - snd_config_t *cfg, enum object_type type); + snd_config_t *cfg, const char *name, enum object_type type); static inline void elem_copy_text(char *dest, const char *src, int len) {