summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-27 01:03:44 -0500
committerXANTRONIX Development2022-02-27 01:03:44 -0500
commit69d3def8de3cb36076aef6e0c6f9b471c545f6d6 (patch)
treeea378682c79e3aa383cbcb2393c457b46b09076c
parent455efe0d2d06e37569631089843e38cadee5cc4a (diff)
downloadxas-69d3def8de3cb36076aef6e0c6f9b471c545f6d6.tar.gz
xas-69d3def8de3cb36076aef6e0c6f9b471c545f6d6.tar.bz2
xas-69d3def8de3cb36076aef6e0c6f9b471c545f6d6.zip
Implement methods for writing settings to tmpfile
-rw-r--r--include/xas/vox.h12
-rw-r--r--src/vox.c58
2 files changed, 65 insertions, 5 deletions
diff --git a/include/xas/vox.h b/include/xas/vox.h
index 7aa43e4..5a1cacf 100644
--- a/include/xas/vox.h
+++ b/include/xas/vox.h
@@ -54,6 +54,18 @@ int xas_vox_set_parameter(xas_vox *vox,
const char *name,
const char *value);
+int xas_vox_set_parameter_str(xas_vox *vox,
+ const char *name,
+ const char *value);
+
+int xas_vox_set_parameter_float(xas_vox *vox,
+ const char *name,
+ float value);
+
+int xas_vox_set_parameter_int(xas_vox *vox,
+ const char *name,
+ int value);
+
int xas_vox_stop(xas_vox *vox);
int xas_vox_active(xas_vox *vox);
diff --git a/src/vox.c b/src/vox.c
index bcfab5d..475300d 100644
--- a/src/vox.c
+++ b/src/vox.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -87,6 +88,12 @@ static int vox_start(xas_vox *vox) {
(void)vox_stop(vox);
}
+ if (vox->tmpfh) {
+ if (fflush(vox->tmpfh) < 0) {
+ goto error_fflush;
+ }
+ }
+
if (pipe(pipe_stdin) < 0) {
goto error_pipe_stdin;
}
@@ -168,6 +175,7 @@ error_pipe_stdout:
(void)close(pipe_stdin[0]);
error_pipe_stdin:
+error_fflush:
return -1;
}
@@ -276,6 +284,7 @@ xas_vox *xas_vox_new_args(xas_audio_format format,
memset(vox->tmpfile, '\0', sizeof(vox->tmpfile));
vox->tmpfd = -1;
+ vox->tmpfh = NULL;
return vox;
@@ -317,26 +326,65 @@ error_tmpfile_open:
return -1;
}
-int xas_vox_set_parameter(xas_vox *vox,
+static int set_parameter_va(xas_vox *vox,
const char *name,
- const char *value) {
+ const char *format,
+ ...) {
+ va_list args;
+
if (tmpfile_open(vox) < 0) {
goto error_tmpfile_open;
}
- if (fprintf(vox->tmpfh, "(Parameter.set '%s %s)\n",
- name,
- value) < 0) {
+ va_start(args, format);
+
+ if (fprintf(vox->tmpfh, "(Parameter.set '%s ", name) < 0) {
+ goto error_fprintf;
+ }
+
+ if (vfprintf(vox->tmpfh, format, args) < 0) {
+ goto error_fprintf;
+ }
+
+ if (fprintf(vox->tmpfh, ")\n") < 0) {
goto error_fprintf;
}
+ va_end(args);
+
return 0;
error_fprintf:
+ va_end(args);
+
error_tmpfile_open:
return -1;
}
+int xas_vox_set_parameter(xas_vox *vox,
+ const char *name,
+ const char *value) {
+ return set_parameter_va(vox, name, "%s", value);
+}
+
+int xas_vox_set_parameter_str(xas_vox *vox,
+ const char *name,
+ const char *value) {
+ return set_parameter_va(vox, name, "\"%s\"", value);
+}
+
+int xas_vox_set_parameter_float(xas_vox *vox,
+ const char *name,
+ float value) {
+ return set_parameter_va(vox, name, "%f", value);
+}
+
+int xas_vox_set_parameter_int(xas_vox *vox,
+ const char *name,
+ int value) {
+ return set_parameter_va(vox, name, "%d", value);
+}
+
int xas_vox_stop(xas_vox *vox) {
if (vox->state == XAS_VOX_ACTIVE) {
return vox_stop(vox);