[pulseaudio-discuss] [PATCH v3 4/6] conf-parser: Add pa_config_parse_volume()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Mon Apr 27 04:34:04 PDT 2015
This will be used to parse the path default volume in the alsa mixer
configuration files. For now, percentages are the only supported
format, because I don't have need for anything else, but we can of
course add more volume formats later as needed.
---
src/pulsecore/conf-parser.c | 23 +++++++++++++++++++++++
src/pulsecore/conf-parser.h | 3 ++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
index 2dcd45a..7ec50fc 100644
--- a/src/pulsecore/conf-parser.c
+++ b/src/pulsecore/conf-parser.c
@@ -312,3 +312,26 @@ int pa_config_parse_string(pa_config_parser_state *state) {
*s = *state->rvalue ? pa_xstrdup(state->rvalue) : NULL;
return 0;
}
+
+int pa_config_parse_volume(pa_config_parser_state *state) {
+ size_t len;
+
+ pa_assert(state);
+
+ len = strlen(state->rvalue);
+
+ /* Only allow volumes in percentage format. This limitation can be lifted
+ * if necessary, it's currently done this way to make documentation
+ * easier for the users of pa_config_parse_volume(). */
+ if (len == 0 || state->rvalue[len - 1] != '%')
+ goto fail;
+
+ if (pa_parse_volume(state->rvalue, state->data) < 0)
+ goto fail;
+
+ return 0;
+
+fail:
+ pa_log("[%s:%u] Failed to parse volume value: \"%s\"", state->filename, state->lineno, state->rvalue);
+ return -1;
+}
diff --git a/src/pulsecore/conf-parser.h b/src/pulsecore/conf-parser.h
index dbb6f5c..62d7046 100644
--- a/src/pulsecore/conf-parser.h
+++ b/src/pulsecore/conf-parser.h
@@ -70,12 +70,13 @@ struct pa_config_parser_state {
* are not allowed at all in the configuration file. */
int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, void *userdata);
-/* Generic parsers for integers, size_t, booleans and strings */
+/* Generic parsers for integers, size_t, booleans, strings and pa_volume_t */
int pa_config_parse_int(pa_config_parser_state *state);
int pa_config_parse_unsigned(pa_config_parser_state *state);
int pa_config_parse_size(pa_config_parser_state *state);
int pa_config_parse_bool(pa_config_parser_state *state);
int pa_config_parse_not_bool(pa_config_parser_state *state);
int pa_config_parse_string(pa_config_parser_state *state);
+int pa_config_parse_volume(pa_config_parser_state *state);
#endif
--
1.9.3
More information about the pulseaudio-discuss
mailing list