]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 't/interactive'
authorAndre Noll <maan@systemlinux.org>
Sat, 22 Jun 2013 13:58:29 +0000 (15:58 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 22 Jun 2013 13:58:29 +0000 (15:58 +0200)
Was cooking for almost two weeks.

f8931d Simplify i9e_line_handler.
f99dbe i9e: Fix a prompt display issue
cf39e4 audioc: Abstract out connection code.

audioc.c
client.c
interactive.c
play.c

index 74fb11cb0622cbab54f5c46ce28cbd5856efffe8..b2c6786a6573ba2636606cde09403e38a590e0c6 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -42,6 +42,25 @@ static char *concat_args(unsigned argc, char * const *argv)
        return buf;
 }
 
+static int connect_audiod(const char *sname, char *args)
+{
+       int fd = -1, ret;
+
+       ret = connect_local_socket(sname);
+       if (ret < 0)
+               goto fail;
+       fd = ret;
+       ret = send_cred_buffer(fd, args);
+       if (ret < 0)
+               goto fail;
+       return fd;
+fail:
+       PARA_ERROR_LOG("could not connect %s\n", sname);
+       if (fd >= 0)
+               close(fd);
+       return ret;
+}
+
 #ifdef HAVE_READLINE
 #include "list.h"
 #include "sched.h"
@@ -146,8 +165,6 @@ static int audioc_i9e_line_handler(char *line)
 {
        char *args = NULL;
        int ret;
-       if (!line || !*line)
-               return 0;
 
        PARA_DEBUG_LOG("line: %s\n", line);
        ret = create_argv(line, " ", &conf.inputs);
@@ -157,14 +174,11 @@ static int audioc_i9e_line_handler(char *line)
        args = concat_args(conf.inputs_num, conf.inputs);
        free_argv(conf.inputs);
        conf.inputs_num = 0; /* required for audioc_cmdline_parser_free() */
-       ret = connect_local_socket(socket_name);
+       ret = connect_audiod(socket_name, args);
        if (ret < 0)
                goto out;
        at->fd = ret;
        ret = mark_fd_nonblocking(at->fd);
-       if (ret < 0)
-               goto close;
-       ret = send_cred_buffer(at->fd, args);
        if (ret < 0)
                goto close;
        free(args);
@@ -320,21 +334,16 @@ int main(int argc, char *argv[])
                interactive_session();
        args = concat_args(conf.inputs_num, conf.inputs);
 
-       ret = connect_local_socket(socket_name);
+       ret = connect_audiod(socket_name, args);
        free(socket_name);
-       if (ret < 0) {
-               PARA_EMERG_LOG("failed to connect to local socket\n");
+       if (ret < 0)
                goto out;
-       }
        fd = ret;
-       ret = send_cred_buffer(fd, args);
+       ret = mark_fd_blocking(STDOUT_FILENO);
        if (ret < 0)
                goto out;
        bufsize = conf.bufsize_arg;
        buf = para_malloc(bufsize);
-       ret = mark_fd_blocking(STDOUT_FILENO);
-       if (ret < 0)
-               goto out;
        do {
                size_t n = ret = recv_bin_buffer(fd, buf, bufsize);
                if (ret <= 0)
index 90dc432b8829426cd9d4ce081e4f8e20a5fb194e..c47dafe8afd300183c8d3853f9da7e0198b4c88d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -445,9 +445,7 @@ static int client_i9e_line_handler(char *line)
        int ret;
 
        client_disconnect(ct);
-       if (!line || !*line)
-               return 0;
-       PARA_DEBUG_LOG("line handler: %s\n", line);
+       PARA_DEBUG_LOG("line: %s\n", line);
        ret = make_client_argv(line);
        if (ret < 0)
                return ret;
index f281901248e3aebe878553220dda938d1c3fbece..6d30e12aae63503061114e18b3e1fc7b4a118ec8 100644 (file)
@@ -290,21 +290,25 @@ static bool input_available(void)
 static void i9e_line_handler(char *line)
 {
        int ret;
+       struct btr_node *dummy;
 
+       if (!line) {
+               i9ep->input_eof = true;
+               return;
+       }
+       if (!*line)
+               goto free_line;
+       rl_set_prompt("");
+       dummy = btr_new_node(&(struct btr_node_description)
+               EMBRACE(.name = "dummy line handler"));
+       i9e_attach_to_stdout(dummy);
        ret = i9ep->ici->line_handler(line);
        if (ret < 0)
                PARA_WARNING_LOG("%s\n", para_strerror(-ret));
-       rl_set_prompt("");
-       if (line) {
-               if (!*line)
-                       rl_set_prompt(i9ep->ici->prompt);
-               else
-                       add_history(line);
-               free(line);
-       } else {
-               rl_set_prompt("");
-               i9ep->input_eof = true;
-       }
+       add_history(line);
+       btr_remove_node(&dummy);
+free_line:
+       free(line);
 }
 
 static int i9e_post_select(__a_unused struct sched *s, __a_unused struct task *t)
diff --git a/play.c b/play.c
index 2cb0536dfc410eae63c0484ec9bd5535a50fe5ae..02128af0582aba2f724d70a459b427b096797a39 100644 (file)
--- a/play.c
+++ b/play.c
@@ -990,15 +990,7 @@ out:
 
 static int play_i9e_line_handler(char *line)
 {
-       struct play_task *pt = &play_task;
-       int ret;
-
-       if (line == NULL || !*line)
-               return 0;
-       ret = run_command(line, pt);
-       if (ret < 0)
-               return ret;
-       return 0;
+       return run_command(line, &play_task);
 }
 
 static int play_i9e_key_handler(int key)