]>
code.delx.au - pulseaudio/blob - src/modules/module-cli.c
2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulsecore/module.h>
30 #include <pulsecore/iochannel.h>
31 #include <pulsecore/cli.h>
32 #include <pulsecore/sioman.h>
33 #include <pulsecore/log.h>
34 #include <pulsecore/modargs.h>
35 #include <pulsecore/macro.h>
37 #include "module-cli-symdef.h"
39 PA_MODULE_AUTHOR("Lennart Poettering");
40 PA_MODULE_DESCRIPTION("Command line interface");
41 PA_MODULE_VERSION(PACKAGE_VERSION
);
42 PA_MODULE_LOAD_ONCE(TRUE
);
43 PA_MODULE_USAGE("exit_on_eof=<exit daemon after EOF?>");
45 static const char* const valid_modargs
[] = {
50 static void eof_and_unload_cb(pa_cli
*c
, void *userdata
) {
51 pa_module
*m
= userdata
;
56 pa_module_unload_request(m
, TRUE
);
59 static void eof_and_exit_cb(pa_cli
*c
, void *userdata
) {
60 pa_module
*m
= userdata
;
65 pa_core_exit(m
->core
, FALSE
, 0);
68 int pa__init(pa_module
*m
) {
71 pa_bool_t exit_on_eof
= FALSE
;
75 if (m
->core
->running_as_daemon
) {
76 pa_log_info("Running as daemon, refusing to load this module.");
80 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
81 pa_log("failed to parse module arguments.");
85 if (pa_modargs_get_value_boolean(ma
, "exit_on_eof", &exit_on_eof
) < 0) {
86 pa_log("exit_on_eof= expects boolean argument.");
90 if (pa_stdio_acquire() < 0) {
91 pa_log("STDIN/STDUSE already in use.");
95 io
= pa_iochannel_new(m
->core
->mainloop
, STDIN_FILENO
, STDOUT_FILENO
);
96 pa_iochannel_set_noclose(io
, 1);
98 m
->userdata
= pa_cli_new(m
->core
, io
, m
);
100 pa_cli_set_eof_callback(m
->userdata
, exit_on_eof
? eof_and_exit_cb
: eof_and_unload_cb
, m
);
114 void pa__done(pa_module
*m
) {
117 if (m
->core
->running_as_daemon
== 0) {
118 pa_cli_free(m
->userdata
);