forked from alsa-project/alsa-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
[RFC]topology: pre-processor: support to include conf block with IncludeByKey #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -485,9 +485,12 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf | |
| snd_input_t *in; | ||
| snd_config_t *n; | ||
| regex_t regex; | ||
| const char *filename; | ||
| const char *matched_value; | ||
| const char *id; | ||
| char *full_path; | ||
| char *file_ext; | ||
| bool is_conf_file; | ||
| const char* conf_file_ext = ".conf"; | ||
|
|
||
| n = snd_config_iterator_entry(i); | ||
| if (snd_config_get_id(n, &id) < 0) | ||
|
|
@@ -504,23 +507,39 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf | |
| if (ret) | ||
| continue; | ||
|
|
||
| /* regex matched. now include the conf file */ | ||
| ret = snd_config_get_string(n, &filename); | ||
| /* regex matched. get the value for the matched key */ | ||
| ret = snd_config_get_string(n, &matched_value); | ||
| if (ret < 0) | ||
| goto err; | ||
|
|
||
| if (filename && filename[0] != '/') | ||
| full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename); | ||
| else | ||
| full_path = tplg_snprintf("%s", filename); | ||
|
|
||
| ret = snd_input_stdio_open(&in, full_path, "r"); | ||
| if (ret < 0) { | ||
| fprintf(stderr, "Unable to open included conf file %s\n", full_path); | ||
| /* | ||
| * Check whether the value for the matched key is a conf file or conf block, | ||
| * If it ends with '.conf', it is a conf file, otherwise, it is conf block. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add in the comment what the supported input strings are and how they are converted to the runtime string value. |
||
| file_ext = matched_value + strlen(matched_value) - strlen(conf_file_ext); | ||
| is_conf_file = !strcmp(file_ext, conf_file_ext); | ||
|
|
||
| if (is_conf_file) { | ||
| if (matched_value[0] != '/') | ||
| full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, matched_value); | ||
| else | ||
| full_path = tplg_snprintf("%s", matched_value); | ||
|
|
||
| ret = snd_input_stdio_open(&in, full_path, "r"); | ||
| if (ret < 0) { | ||
| fprintf(stderr, "Unable to open included conf file %s\n", full_path); | ||
| free(full_path); | ||
| goto err; | ||
| } | ||
| free(full_path); | ||
| goto err; | ||
| } else { | ||
| ret = snd_input_buffer_open(&in, matched_value, -1); | ||
| if (ret < 0) { | ||
| fprintf(stderr, "Unable to open buffer for conf input\n"); | ||
| goto err; | ||
| } | ||
| } | ||
| free(full_path); | ||
|
|
||
| /* load config */ | ||
| ret = snd_config_load(*new, in); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aiChaoSONG the code looks good. Can you please add an example of this in the commit message and what the limitations are?