2015-07-29 17:45:15 +01:00
|
|
|
/*
|
|
|
|
|
Copyright(c) 2014-2015 Intel Corporation
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
2017-01-24 14:59:08 +00:00
|
|
|
This library is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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 Lesser General Public License for more details.
|
2015-07-29 17:45:15 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-11-24 09:34:00 +08:00
|
|
|
struct tplg_texts *texts = elem->texts;
|
2015-07-29 17:45:15 +01:00
|
|
|
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;
|
|
|
|
|
|
2019-03-25 16:45:43 +01:00
|
|
|
snd_strlcpy(&texts->items[j][0], value,
|
2015-07-29 17:45:15 +01:00
|
|
|
SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
|
2016-11-24 09:34:00 +08:00
|
|
|
tplg_dbg("\t%s\n", &texts->items[j][0]);
|
2015-07-29 17:45:15 +01:00
|
|
|
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 09:34:00 +08:00
|
|
|
texts->num_items = j;
|
2015-07-29 17:45:15 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parse Text data */
|
|
|
|
|
int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg,
|
2019-12-13 22:07:46 +01:00
|
|
|
void *private ATTRIBUTE_UNUSED)
|
2015-07-29 17:45:15 +01:00
|
|
|
{
|
|
|
|
|
snd_config_iterator_t i, next;
|
|
|
|
|
snd_config_t *n;
|
|
|
|
|
const char *id;
|
|
|
|
|
int err = 0;
|
|
|
|
|
struct tplg_elem *elem;
|
|
|
|
|
|
2015-08-10 19:13:47 +01:00
|
|
|
elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_TEXT);
|
2015-07-29 17:45:15 +01:00
|
|
|
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;
|
|
|
|
|
}
|