From 5c05a42d8a008439285fec9b3b082ed30006f951 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 18 May 2013 20:42:01 +0200 Subject: Mixer: Handle write element Signed-off-by: Paul Kocialkowski --- mixer.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/mixer.c b/mixer.c index d0685e8..9608083 100644 --- a/mixer.c +++ b/mixer.c @@ -20,6 +20,7 @@ #define LOG_TAG "TinyALSA-Audio Mixer" +#include #include #include #include @@ -501,6 +502,43 @@ void tinyalsa_mixer_config_start(void *data, const XML_Char *elem, tinyalsa_mixer_data_free(mixer_data); list_head_free(list); } + } else if(strcmp(elem, "write") == 0) { + if(config_data->device != NULL && config_data->list_start != NULL) { + list = list_head_alloc(); + mixer_data = tinyalsa_mixer_data_alloc(); + + mixer_data->type = MIXER_DATA_TYPE_WRITE; + list->data = (void *) mixer_data; + } else { + LOGE("Missing device/path for elem: %s", elem); + return; + } + + for(i=0 ; attr[i] != NULL && attr[i+1] != NULL ; i++) { + if(strcmp(attr[i], "name") == 0) { + i++; + mixer_data->name = strdup((char *) attr[i]); + } else if(strcmp(attr[i], "value") == 0) { + i++; + mixer_data->value = strdup((char *) attr[i]); + } else { + LOGE("Unknown write attr: %s", attr[i]); + } + } + + if(mixer_data->name != NULL && mixer_data->value != NULL) { + if(*config_data->list_start == NULL) { + *config_data->list_start = list; + } else { + config_data->list->next = list; + list->prev = config_data->list; + } + + config_data->list = list; + } else { + tinyalsa_mixer_data_free(mixer_data); + list_head_free(list); + } } } @@ -696,6 +734,36 @@ int tinyalsa_mixer_set_route_ctrl(struct tinyalsa_mixer *mixer, return 0; } +int tinyalsa_mixer_set_route_write(struct tinyalsa_mixer *mixer, + struct tinyalsa_mixer_data *mixer_data) +{ + char *buffer = NULL; + int fd; + + if(mixer_data->type != MIXER_DATA_TYPE_WRITE) + return -1; + + LOGD("Writing %s to %s", mixer_data->value, mixer_data->name); + + asprintf(&buffer, "%s\n", mixer_data->value); + if(buffer == NULL) + return -1; + + fd = open(mixer_data->name, O_WRONLY); + if(fd < 0) { + free(buffer); + return -1; + } + + write(fd, buffer, strlen(buffer) + 1); + + free(buffer); + + close(fd); + + return 0; +} + int tinyalsa_mixer_set_route_list(struct tinyalsa_mixer *mixer, struct list_head *list) { struct tinyalsa_mixer_data *mixer_data = NULL; @@ -718,6 +786,12 @@ int tinyalsa_mixer_set_route_list(struct tinyalsa_mixer *mixer, struct list_head return -1; } } + } else if(mixer_data->type == MIXER_DATA_TYPE_WRITE) { + rc = tinyalsa_mixer_set_route_write(mixer, mixer_data); + if(rc < 0) { + LOGE("Unable to write!"); + return -1; + } } if(list->next != NULL) -- cgit v1.1