• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***
2   This file is part of PulseAudio.
3 
4   Copyright 2006 Lennart Poettering
5 
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.1 of the License,
9   or (at your option) any later version.
10 
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.
15 
16   You should have received a copy of the GNU Lesser General Public License
17   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
18 ***/
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include <string.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 
28 #include <gconf/gconf-client.h>
29 #include <glib.h>
30 
31 #include <pulsecore/core-util.h>
32 
33 #define PA_GCONF_ROOT "/system/pulseaudio"
34 #define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules"
35 
handle_module(GConfClient * client,const char * name)36 static void handle_module(GConfClient *client, const char *name) {
37     gchar p[1024];
38     gboolean enabled, locked;
39     int i;
40 
41     pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/locked", name);
42     locked = gconf_client_get_bool(client, p, FALSE);
43 
44     if (locked)
45         return;
46 
47     pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/enabled", name);
48     enabled = gconf_client_get_bool(client, p, FALSE);
49 
50     printf("%c%s%c", enabled ? '+' : '-', name, 0);
51 
52     if (enabled) {
53 
54         for (i = 0; i < 10; i++) {
55             gchar *n, *a;
56 
57             pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/name%i", name, i);
58             if (!(n = gconf_client_get_string(client, p, NULL)) || !*n)
59                 break;
60 
61             pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/args%i", name, i);
62             a = gconf_client_get_string(client, p, NULL);
63 
64             printf("%s%c%s%c", n, 0, a ? a : "", 0);
65 
66             g_free(n);
67             g_free(a);
68         }
69 
70         printf("%c", 0);
71     }
72 
73     fflush(stdout);
74 }
75 
modules_callback(GConfClient * client,guint cnxn_id,GConfEntry * entry,gpointer user_data)76 static void modules_callback(
77         GConfClient* client,
78         guint cnxn_id,
79         GConfEntry *entry,
80         gpointer user_data) {
81 
82     const char *n;
83     char buf[128];
84 
85     g_assert(strncmp(entry->key, PA_GCONF_PATH_MODULES"/", sizeof(PA_GCONF_PATH_MODULES)) == 0);
86 
87     n = entry->key + sizeof(PA_GCONF_PATH_MODULES);
88 
89     g_strlcpy(buf, n, sizeof(buf));
90     buf[strcspn(buf, "/")] = 0;
91 
92     handle_module(client, buf);
93 }
94 
main(int argc,char * argv[])95 int main(int argc, char *argv[]) {
96     GMainLoop *g;
97     GConfClient *client;
98     GSList *modules, *m;
99 
100 #if !GLIB_CHECK_VERSION(2,36,0)
101     g_type_init();
102 #endif
103 
104     if (!(client = gconf_client_get_default()))
105         goto fail;
106 
107     gconf_client_add_dir(client, PA_GCONF_ROOT, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
108     gconf_client_notify_add(client, PA_GCONF_PATH_MODULES, modules_callback, NULL, NULL, NULL);
109 
110     modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
111 
112     for (m = modules; m; m = m->next) {
113         char *e = strrchr(m->data, '/');
114         handle_module(client, e ? e+1 : m->data);
115     }
116 
117     g_slist_free(modules);
118 
119     /* Signal the parent that we are now initialized */
120     printf("!");
121     fflush(stdout);
122 
123     g = g_main_loop_new(NULL, FALSE);
124     g_main_loop_run(g);
125     g_main_loop_unref(g);
126 
127     g_object_unref(G_OBJECT(client));
128 
129     return 0;
130 
131 fail:
132     return 1;
133 }
134