[pulseaudio-commits] 3 commits - src/pulsecore src/utils

David Henningsson diwic at kemper.freedesktop.org
Fri Aug 2 07:28:26 PDT 2013


 src/pulsecore/cli.c |   22 ++++++++++------------
 src/utils/pacmd.c   |   11 +++++++++--
 2 files changed, 19 insertions(+), 14 deletions(-)

New commits:
commit 834d10fe650933cb3841cc972a45ee56a742e0bf
Author: Peter Meerwald <pmeerw at pmeerw.net>
Date:   Mon Jul 29 22:13:42 2013 +0200

    cli: Use pa_xnew0 to save some 0 inits
    
    Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>

diff --git a/src/pulsecore/cli.c b/src/pulsecore/cli.c
index 4f66812..407173a 100644
--- a/src/pulsecore/cli.c
+++ b/src/pulsecore/cli.c
@@ -82,25 +82,16 @@ pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
     if (!client)
         return NULL;
 
-    c = pa_xnew(pa_cli, 1);
+    c = pa_xnew0(pa_cli, 1);
     c->core = core;
     c->client = client;
     pa_assert_se(c->line = pa_ioline_new(io));
 
-    c->userdata = NULL;
-    c->eof_callback = NULL;
-
     c->client->kill = client_kill;
     c->client->userdata = c;
 
     pa_ioline_set_callback(c->line, line_callback, c);
 
-    c->fail = c->kill_requested = false;
-    c->defer_kill = 0;
-
-    c->interactive = false;
-    c->last_line = NULL;
-
     return c;
 }
 

commit 193bf997c1f6934bfb79db6c106b656fcdb7a137
Author: Peter Meerwald <pmeerw at pmeerw.net>
Date:   Mon Jul 29 22:13:41 2013 +0200

    pacmd: Discriminate between interactive and non-interactive mode
    
    interactive sessions are initiated with a hello message in order to
    receive a welcome message from the PA daemon and a command prompt
    
    interactive sessions have a terminal connected to stdin
    
    non-interactive sessions execute commands given on the command line
    or received via stdin; non-interactive sessions have neither welcome
    message nor command prompt
    
    Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>

diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
index cf0eb44..61b87a0 100644
--- a/src/utils/pacmd.c
+++ b/src/utils/pacmd.c
@@ -83,7 +83,7 @@ static void help(const char *argv0) {
     printf(_("\n"
          "  -h, --help                            Show this help\n"
          "      --version                         Show version\n"
-         "When no command is given pacmd starts in the interactive mode\n" ));
+         "When no command is given pacmd starts in the interactive mode.\n" ));
 }
 
 enum {
@@ -102,7 +102,6 @@ int main(int argc, char*argv[]) {
     bool ibuf_eof, obuf_eof, ibuf_closed, obuf_closed;
     struct pollfd pollfd[3];
     struct pollfd *watch_socket, *watch_stdin, *watch_stdout;
-
     int stdin_type = 0, stdout_type = 0, fd_type = 0;
 
     char *bn = NULL;
@@ -209,6 +208,14 @@ int main(int argc, char*argv[]) {
         ibuf_eof = true;
     }
 
+    if (!ibuf_eof && isatty(STDIN_FILENO)) {
+        /* send hello to enable interactive mode (welcome message, prompt) */
+        if (pa_write(fd, "hello\n", 6, &fd_type) < 0) {
+            pa_log(_("write(): %s"), strerror(errno));
+            goto quit;
+        }
+    }
+
     for (;;) {
         struct pollfd *p;
 

commit e729783331f31a793e21ccf2da21cd9d4388a344
Author: Peter Meerwald <pmeerw at pmeerw.net>
Date:   Mon Jul 29 22:13:40 2013 +0200

    cli: Output prompt and welcome message only when requested by 'hello'
    
    Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>

diff --git a/src/pulsecore/cli.c b/src/pulsecore/cli.c
index af2f871..4f66812 100644
--- a/src/pulsecore/cli.c
+++ b/src/pulsecore/cli.c
@@ -55,6 +55,7 @@ struct pa_cli {
     bool fail, kill_requested;
     int defer_kill;
 
+    bool interactive;
     char *last_line;
 };
 
@@ -93,11 +94,11 @@ pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
     c->client->userdata = c;
 
     pa_ioline_set_callback(c->line, line_callback, c);
-    pa_ioline_puts(c->line, "Welcome to PulseAudio! Use \"help\" for usage information.\n"PROMPT);
 
     c->fail = c->kill_requested = false;
     c->defer_kill = 0;
 
+    c->interactive = false;
     c->last_line = NULL;
 
     return c;
@@ -154,7 +155,13 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
 
     pa_assert_se(buf = pa_strbuf_new());
     c->defer_kill++;
-    pa_cli_command_execute_line(c->core, s, buf, &c->fail);
+    if (pa_streq(s, "hello")) {
+        pa_strbuf_printf(buf, "Welcome to PulseAudio %s! "
+            "Use \"help\" for usage information.\n", PACKAGE_VERSION);
+        c->interactive = true;
+    }
+    else
+        pa_cli_command_execute_line(c->core, s, buf, &c->fail);
     c->defer_kill--;
     pa_ioline_puts(line, p = pa_strbuf_tostring_free(buf));
     pa_xfree(p);
@@ -162,7 +169,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
     if (c->kill_requested) {
         if (c->eof_callback)
             c->eof_callback(c, c->userdata);
-    } else
+    } else if (c->interactive)
         pa_ioline_puts(line, PROMPT);
 }
 



More information about the pulseaudio-commits mailing list