[polypaudio-commits] r1026 - in /trunk: doc/modules.html.in doc/todo src/daemon/cmdline.c src/modules/module-cli.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Jun 18 04:10:46 PDT 2006


Author: lennart
Date: Sun Jun 18 13:10:45 2006
New Revision: 1026

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1026&root=polypaudio&view=rev
Log:
* add new argument 'exit_on_eof' to module-cli and make use of it if "-C" is passed to the daemon

Modified:
    trunk/doc/modules.html.in
    trunk/doc/todo
    trunk/src/daemon/cmdline.c
    trunk/src/modules/module-cli.c

Modified: trunk/doc/modules.html.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/doc/modules.html.in?rev=1026&root=polypaudio&r1=1025&r2=1026&view=diff
==============================================================================
--- trunk/doc/modules.html.in (original)
+++ trunk/doc/modules.html.in Sun Jun 18 13:10:45 2006
@@ -193,7 +193,9 @@
 <p>For an explanation of the simple command line language used by this
 module see <a href="cli.html"><tt>cli.html</tt></a>.
 
-<p>This module doesn't accept any arguments.</p>
+<table>
+  <tr><td><tt>exit_on_eof=</tt></td><td>Accepts a binary numerical argument specifying whether the daemon shuld exit after an EOF was recieved from STDIN (default: 0)</td></tr>
+</table>
 
 <a name="module-cli-protocol-unix"/>
 <a name="module-cli-protocol-tcp"/>

Modified: trunk/doc/todo
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/doc/todo?rev=1026&root=polypaudio&r1=1025&r2=1026&view=diff
==============================================================================
--- trunk/doc/todo (original)
+++ trunk/doc/todo Sun Jun 18 13:10:45 2006
@@ -35,7 +35,6 @@
 - check if using prctl(PR_GET_NAME) makes sense in pa_get_binary_name()
 - gconf module + frontend
 - hooks for creating sink inputs
-- module-cli argument exit-on-eof
 
 Long term:
 - pass meta info for hearing impaired

Modified: trunk/src/daemon/cmdline.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/cmdline.c?rev=1026&root=polypaudio&r1=1025&r2=1026&view=diff
==============================================================================
--- trunk/src/daemon/cmdline.c (original)
+++ trunk/src/daemon/cmdline.c Sun Jun 18 13:10:45 2006
@@ -186,7 +186,7 @@
                 break;
                 
             case 'C':
-                pa_strbuf_puts(buf, "load-module module-cli\n");
+                pa_strbuf_puts(buf, "load-module module-cli exit_on_eof=1\n");
                 break;
                 
             case ARG_DAEMONIZE:

Modified: trunk/src/modules/module-cli.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-cli.c?rev=1026&root=polypaudio&r1=1025&r2=1026&view=diff
==============================================================================
--- trunk/src/modules/module-cli.c (original)
+++ trunk/src/modules/module-cli.c Sun Jun 18 13:10:45 2006
@@ -32,38 +32,64 @@
 #include <polypcore/cli.h>
 #include <polypcore/sioman.h>
 #include <polypcore/log.h>
+#include <polypcore/modargs.h>
 
 #include "module-cli-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Command line interface")
 PA_MODULE_VERSION(PACKAGE_VERSION)
-PA_MODULE_USAGE("No arguments")
+PA_MODULE_USAGE("exit_on_eof=<exit daemon after EOF?>")
 
-static void eof_cb(pa_cli*c, void *userdata) {
+static const char* const valid_modargs[] = {
+    "exit_on_eof",
+    NULL
+};
+
+static void eof_and_unload_cb(pa_cli*c, void *userdata) {
     pa_module *m = userdata;
-    assert(c && m);
+    
+    assert(c);
+    assert(m);
 
     pa_module_unload_request(m);
 }
 
+static void eof_and_exit_cb(pa_cli*c, void *userdata) {
+    pa_module *m = userdata;
+
+    assert(c);
+    assert(m);
+
+    m->core->mainloop->quit(m->core->mainloop, 0);
+}
+
 int pa__init(pa_core *c, pa_module*m) {
     pa_iochannel *io;
-    assert(c && m);
+    pa_modargs *ma;
+    int exit_on_eof = 0;
+    
+    assert(c);
+    assert(m);
 
     if (c->running_as_daemon) {
-        pa_log_info(__FILE__": Running as daemon so won't load this module.");
+        pa_log_info(__FILE__": Running as daemon, refusing to load this module.");
         return 0;
     }
 
-    if (m->argument) {
-        pa_log(__FILE__": module doesn't accept arguments.");
-        return -1;
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log(__FILE__": failed to parse module arguments.");
+        goto fail;
     }
     
+    if (pa_modargs_get_value_boolean(ma, "exit_on_eof", &exit_on_eof) < 0) {
+        pa_log(__FILE__": exit_on_eof= expects boolean argument.");
+        goto fail;
+    }
+
     if (pa_stdio_acquire() < 0) {
         pa_log(__FILE__": STDIN/STDUSE already in use.");
-        return -1;
+        goto fail;
     }
 
     io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO);
@@ -73,13 +99,23 @@
     m->userdata = pa_cli_new(c, io, m);
     assert(m->userdata);
 
-    pa_cli_set_eof_callback(m->userdata, eof_cb, m);
+    pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m);
+
+    pa_modargs_free(ma);
     
     return 0;
+
+fail:
+
+    if (ma)
+        pa_modargs_free(ma);
+
+    return -1;
 }
 
 void pa__done(pa_core *c, pa_module*m) {
-    assert(c && m);
+    assert(c);
+    assert(m);
 
     if (c->running_as_daemon == 0) {
         pa_cli_free(m->userdata);




More information about the pulseaudio-commits mailing list