topology: Look up references for an object based on its index

We can distinguish different use cases by the object index value, the default
value is 0, meaning applicable for all use cases, defined by macro "SND_TOLG_INDEX_ALL".
An element can only refer to other elements for "all" use cases or the same use
cases, i.e. it can only refer to elements with index value "SND_TOLG_INDEX_ALL"
or the same index value as itself.
The object list has been sorted in ascending order of index, so when we look up
a reference for an object, we traverse the object list it depends on, if we have
not found the reference until index of the object list is greater than index of
the object, we give up and return an error.

Signed-off-by: Fuwei Tang <fuweix.tang@intel.com>
Reviewed-by: Mengdong Lin <mengdong.lin@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Fuwei Tang 2017-04-13 14:52:46 +08:00 committed by Takashi Iwai
parent af231ea1db
commit a3b4bd2c8c
7 changed files with 39 additions and 27 deletions

View file

@ -366,7 +366,7 @@ static struct tplg_elem *get_tokens(snd_tplg_t *tplg, struct tplg_elem *elem)
if (!ref->elem) {
ref->elem = tplg_elem_lookup(&tplg->token_list,
ref->id, SND_TPLG_TYPE_TOKEN);
ref->id, SND_TPLG_TYPE_TOKEN, elem->index);
}
return ref->elem;
@ -508,7 +508,7 @@ static int build_tuples(snd_tplg_t *tplg, struct tplg_elem *elem)
if (!ref->elem)
ref->elem = tplg_elem_lookup(&tplg->tuple_list,
ref->id, SND_TPLG_TYPE_TUPLE);
ref->id, SND_TPLG_TYPE_TUPLE, elem->index);
tuples = ref->elem;
if (!tuples)
return -EINVAL;
@ -1036,7 +1036,7 @@ int tplg_copy_data(snd_tplg_t *tplg, struct tplg_elem *elem,
void *obj;
ref_elem = tplg_elem_lookup(&tplg->pdata_list,
ref->id, SND_TPLG_TYPE_DATA);
ref->id, SND_TPLG_TYPE_DATA, elem->index);
if (!ref_elem) {
SNDERR("error: cannot find data '%s' referenced by"
" element '%s'\n", ref->id, elem->id);