summaryrefslogtreecommitdiff
path: root/src/modules/gsettings/gsettings-helper.c
blob: 8275e45c953e0efabcc525d5fa891a303629b970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***
  This file is part of PulseAudio.

  PulseAudio is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License,
  or (at your option) any later version.

  PulseAudio is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <gio/gio.h>
#include <glib.h>

#include <pulsecore/core-util.h>

#define PA_GSETTINGS_MODULE_SCHEMA "org.freedesktop.pulseaudio.module"
#define PA_GSETTINGS_MODULES_SCHEMA "org.freedesktop.pulseaudio.modules"
#define PA_GSETTINGS_MODULES_PATH "/org/freedesktop/pulseaudio/modules/"

static void modules_callback(GSettings *settings, gchar *key, gpointer user_data);

static void handle_module(gchar *name) {
    GSettings *settings;
    gchar p[1024];
    gboolean enabled;
    int i;

    pa_snprintf(p, sizeof(p), PA_GSETTINGS_MODULES_PATH"%s/", name);

    if (!(settings = g_settings_new_with_path(PA_GSETTINGS_MODULE_SCHEMA,
                                              p)))
        return;

    enabled = g_settings_get_boolean(settings, "enabled");

    printf("%c%s%c", enabled ? '+' : '-', name, 0);

    if (enabled) {
        for (i = 0; i < 10; i++) {
            gchar *n, *a;

            pa_snprintf(p, sizeof(p), "name%d", i);
            n = g_settings_get_string(settings, p);

            pa_snprintf(p, sizeof(p), "args%i", i);
            a = g_settings_get_string(settings, p);

            printf("%s%c%s%c", n, 0, a, 0);

            g_free(n);
            g_free(a);
        }

        printf("%c", 0);
    }

    fflush(stdout);

    g_object_unref(G_OBJECT(settings));
}

static void modules_callback(GSettings *settings, gchar *key, gpointer user_data) {
    handle_module(user_data);
}

int main(int argc, char *argv[]) {
    GMainLoop *g;
    GSettings *settings;
    gchar **modules, **m;

#if !GLIB_CHECK_VERSION(2,36,0)
    g_type_init();
#endif

    if (!(settings = g_settings_new(PA_GSETTINGS_MODULES_SCHEMA)))
        goto fail;

    g_signal_connect(settings, "changed", (GCallback) modules_callback, NULL);

    modules = g_settings_list_children (settings);

    for (m = modules; *m; m++) {
        g_signal_connect(g_settings_get_child (settings, *m), "changed",
                         (GCallback) modules_callback, *m);
        handle_module(*m);
    }

    /* Signal the parent that we are now initialized */
    printf("!");
    fflush(stdout);

    g = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(g);
    g_main_loop_unref(g);

    g_object_unref(G_OBJECT(settings));

    return 0;

fail:
    return 1;
}