1 /***
2 This file is part of PulseAudio.
3
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
8
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
16 ***/
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25
26 #include <gio/gio.h>
27 #include <glib.h>
28
29 #include <pulsecore/core-util.h>
30
31 #define PA_GSETTINGS_MODULE_GROUP_SCHEMA "org.freedesktop.pulseaudio.module-group"
32 #define PA_GSETTINGS_MODULE_GROUPS_SCHEMA "org.freedesktop.pulseaudio.module-groups"
33 #define PA_GSETTINGS_MODULE_GROUPS_PATH "/org/freedesktop/pulseaudio/module-groups/"
34
handle_module_group(gchar * name)35 static void handle_module_group(gchar *name) {
36 GSettings *settings;
37 gchar p[1024];
38 gboolean enabled;
39 int i;
40
41 pa_snprintf(p, sizeof(p), PA_GSETTINGS_MODULE_GROUPS_PATH"%s/", name);
42
43 if (!(settings = g_settings_new_with_path(PA_GSETTINGS_MODULE_GROUP_SCHEMA,
44 p)))
45 return;
46
47 enabled = g_settings_get_boolean(settings, "enabled");
48
49 printf("%c%s%c", enabled ? '+' : '-', name, 0);
50
51 if (enabled) {
52 for (i = 0; i < 10; i++) {
53 gchar *n, *a;
54
55 pa_snprintf(p, sizeof(p), "name%d", i);
56 n = g_settings_get_string(settings, p);
57
58 pa_snprintf(p, sizeof(p), "args%i", i);
59 a = g_settings_get_string(settings, p);
60
61 printf("%s%c%s%c", n, 0, a, 0);
62
63 g_free(n);
64 g_free(a);
65 }
66
67 printf("%c", 0);
68 }
69
70 fflush(stdout);
71
72 g_object_unref(G_OBJECT(settings));
73 }
74
module_group_callback(GSettings * settings,gchar * key,gpointer user_data)75 static void module_group_callback(GSettings *settings, gchar *key, gpointer user_data) {
76 handle_module_group(user_data);
77 }
78
main(int argc,char * argv[])79 int main(int argc, char *argv[]) {
80 GMainLoop *g;
81 GSettings *settings;
82 GPtrArray *groups;
83 gchar **group_names, **name;
84
85 #if !GLIB_CHECK_VERSION(2,36,0)
86 g_type_init();
87 #endif
88
89 /* gsettings-data-convert copies data from GConf to GSettings. The
90 * conversion is defined in the pulseaudio.convert file. The conversion is
91 * done only once, so running the command every time gsettings-helper
92 * starts is safe. */
93 g_spawn_command_line_sync("gsettings-data-convert", NULL, NULL, NULL, NULL);
94
95 if (!(settings = g_settings_new(PA_GSETTINGS_MODULE_GROUPS_SCHEMA)))
96 goto fail;
97
98 groups = g_ptr_array_new_full(0, g_object_unref);
99 group_names = g_settings_list_children(settings);
100
101 for (name = group_names; *name; name++) {
102 GSettings *child = g_settings_get_child(settings, *name);
103
104 /* The child may have been removed between the
105 * g_settings_list_children() and g_settings_get_child() calls. */
106 if (!child)
107 continue;
108
109 g_ptr_array_add(groups, child);
110 g_signal_connect(child, "changed", (GCallback) module_group_callback, *name);
111 handle_module_group(*name);
112 }
113
114 /* Signal the parent that we are now initialized */
115 printf("!");
116 fflush(stdout);
117
118 g = g_main_loop_new(NULL, FALSE);
119 g_main_loop_run(g);
120 g_main_loop_unref(g);
121
122 g_ptr_array_unref(groups);
123
124 /* group_names can't be freed earlier, because the values are being used as
125 * the user_data for module_group_callback(). */
126 g_strfreev(group_names);
127
128 g_object_unref(G_OBJECT(settings));
129
130 return 0;
131
132 fail:
133 return 1;
134 }
135