From bd432f0590bdda2c42887f1d6da07ff0bb571013 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 18 Jun 2006 11:10:45 +0000 Subject: [PATCH] * add new argument 'exit_on_eof' to module-cli and make use of it if "-C" is passed to the daemon git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1026 fefdeb5f-60dc-0310-8127-8f9354f1896f --- doc/modules.html.in | 4 ++- doc/todo | 1 - src/daemon/cmdline.c | 2 +- src/modules/module-cli.c | 58 ++++++++++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/doc/modules.html.in b/doc/modules.html.in index af6b6de6..85479523 100644 --- a/doc/modules.html.in +++ b/doc/modules.html.in @@ -193,7 +193,9 @@ once.

For an explanation of the simple command line language used by this module see cli.html. -

This module doesn't accept any arguments.

+ + +
exit_on_eof=Accepts a binary numerical argument specifying whether the daemon shuld exit after an EOF was recieved from STDIN (default: 0)
diff --git a/doc/todo b/doc/todo index 7b83ea98..1ea40d3e 100644 --- a/doc/todo +++ b/doc/todo @@ -35,7 +35,6 @@ Post 0.9.0: - 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 diff --git a/src/daemon/cmdline.c b/src/daemon/cmdline.c index 21fd5a25..b71be2e6 100644 --- a/src/daemon/cmdline.c +++ b/src/daemon/cmdline.c @@ -186,7 +186,7 @@ int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d 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: diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index 41e33c7f..ce50a46b 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -32,38 +32,64 @@ #include #include #include +#include #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=") -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 @@ int pa__init(pa_core *c, pa_module*m) { 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); -- 2.39.2