[pulseaudio-commits] 12 commits - configure.ac src/daemon src/.gitignore src/Makefile.am src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu Apr 19 11:52:59 UTC 2018


 configure.ac                                                 |   34 +
 src/.gitignore                                               |    2 
 src/Makefile.am                                              |   31 +
 src/daemon/default.pa.in                                     |   13 
 src/modules/gconf/module-gconf.c                             |  290 -----------
 src/modules/gsettings/gsettings-helper.c                     |  128 ++++
 src/modules/gsettings/module-gsettings.c                     |  114 ++++
 src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml |  115 ++++
 src/modules/stdin-util.c                                     |  279 ++++++++++
 src/modules/stdin-util.h                                     |   85 +++
 10 files changed, 801 insertions(+), 290 deletions(-)

New commits:
commit 5d66b442039527ef01ad00a1d85fd8a6a206f954
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:42 2018 +0300

    build-sys: enable GSettings by default
    
    A new paprefs release is expected soon, and it will only support
    GSettings. In order to have the default configuration work with the new
    paprefs version, we need to enable GSettings by default.
    
    If both module-gconf and module-gsettings are enabled when building
    PulseAudio, both modules will be part of the default configuration. That
    can cause trouble, because when the GConf database is migrated to
    GSettings, the old configuration in GConf is not removed, so both
    module-gconf and module-gsettings will try to load modules.
    
    Generally it's not necessary to have both modules enabled even at build
    time, so let's default to having only one of them enabled.

diff --git a/configure.ac b/configure.ac
index 2d3022e2..aa275a95 100644
--- a/configure.ac
+++ b/configure.ac
@@ -912,11 +912,21 @@ AS_IF([test "x$enable_gtk3" = "xyes" && test "x$HAVE_GTK30" = "x0"],
 AM_CONDITIONAL([HAVE_GTK30], [test "x$HAVE_GTK30" = x1])
 AS_IF([test "x$HAVE_GTK30" = "x1"], AC_DEFINE([HAVE_GTK], 1, [Have GTK?]))
 
-#### GConf support (optional) ####
+#### GSettings and GConf support (optional) ####
+
+AC_ARG_ENABLE([gsettings],
+    AS_HELP_STRING([--disable-gsettings],[Disable optional GSettings support]))
 
 AC_ARG_ENABLE([gconf],
     AS_HELP_STRING([--disable-gconf],[Disable optional GConf support]))
 
+AS_IF([test "x$enable_gsettings" != "xno"],
+    [PKG_CHECK_MODULES(GSETTINGS, [ gio-2.0 >= 2.26.0 ], [HAVE_GSETTINGS=1], [HAVE_GSETTINGS=0])],
+    HAVE_GSETTINGS=0)
+
+AS_IF([test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x0"],
+    [AC_MSG_ERROR([*** GSettings support not found])])
+
 AS_IF([test "x$enable_gconf" != "xno"],
     [PKG_CHECK_MODULES(GCONF, [ gconf-2.0 >= 2.4.0 gobject-2.0 ], HAVE_GCONF=1, HAVE_GCONF=0)],
     HAVE_GCONF=0)
@@ -924,23 +934,21 @@ AS_IF([test "x$enable_gconf" != "xno"],
 AS_IF([test "x$enable_gconf" = "xyes" && test "x$HAVE_GCONF" = "x0"],
     [AC_MSG_ERROR([*** GConf support not found])])
 
-AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = x1])
-AC_SUBST([HAVE_GCONF])
-
-#### GSettings support (optional) ####
-
-AC_ARG_ENABLE([gsettings],
-    AS_HELP_STRING([--enable-gsettings],[Enable optional GSettings support]))
-
-AS_IF([test "x$enable_gsettings" = "xyes"],
-    [PKG_CHECK_MODULES(GSETTINGS, [ gio-2.0 >= 2.26.0 ], [HAVE_GSETTINGS=1], [HAVE_GSETTINGS=0])],
-    HAVE_GSETTINGS=0)
-
-AS_IF([test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x0"],
-    [AC_MSG_ERROR([*** GSettings support not found])])
-
-AM_CONDITIONAL([HAVE_GSETTINGS], [test "x$HAVE_GSETTINGS" = x1])
+# Enable only one of GSettings and GConf, unless both were explicitly
+# requested. If neither was explicitly requested and both are available, prefer
+# GSettings. This is done, because if module-gsettings and module-gconf are
+# both loaded, they can cause conflicting or at least confusing configuration.
+# Distributions may want to enable both modules when building PulseAudio, if
+# they ensure that both modules are never installed at the same time.
+AS_IF([test "x$HAVE_GSETTINGS" = "x1" && test "x$enable_gconf" != "xyes"],
+      [HAVE_GCONF=0])
+AS_IF([test "x$HAVE_GCONF" = "x1" && test "x$enable_gsettings" != "xyes"],
+      [HAVE_GSETTINGS=0])
+
+AM_CONDITIONAL([HAVE_GSETTINGS], [test "x$HAVE_GSETTINGS" = "x1"])
 AC_SUBST([HAVE_GSETTINGS])
+AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = "x1"])
+AC_SUBST([HAVE_GCONF])
 
 if test "x$HAVE_GSETTINGS" = "x1" ; then
     GLIB_GSETTINGS

commit f97cd3449ebd1c03feb4961308337fff54928d8b
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:41 2018 +0300

    gsettings: free group_names after use

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index 120456b3..d59cc832 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -114,6 +114,11 @@ int main(int argc, char *argv[]) {
     g_main_loop_unref(g);
 
     g_ptr_array_unref(groups);
+
+    /* group_names can't be freed earlier, because the values are being used as
+     * the user_data for module_group_callback(). */
+    g_strfreev(group_names);
+
     g_object_unref(G_OBJECT(settings));
 
     return 0;

commit 2977afb9b060a2523dea64b5bea46f368ec82993
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:40 2018 +0300

    gsettings: free the module-group GSettings objects after use
    
    g_settings_get_child() returns a new GSettings object that needs to be
    freed when it's not used any more. This patch collects all the childern
    to a GPtrArray and frees them at the end of main(). They can't be freed
    earlier, because that would prevent the "changed" signals from being
    delivered.

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index cf047e23..120456b3 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -79,6 +79,7 @@ static void module_group_callback(GSettings *settings, gchar *key, gpointer user
 int main(int argc, char *argv[]) {
     GMainLoop *g;
     GSettings *settings;
+    GPtrArray *groups;
     gchar **group_names, **name;
 
 #if !GLIB_CHECK_VERSION(2,36,0)
@@ -88,6 +89,7 @@ int main(int argc, char *argv[]) {
     if (!(settings = g_settings_new(PA_GSETTINGS_MODULE_GROUPS_SCHEMA)))
         goto fail;
 
+    groups = g_ptr_array_new_full(0, g_object_unref);
     group_names = g_settings_list_children(settings);
 
     for (name = group_names; *name; name++) {
@@ -98,6 +100,7 @@ int main(int argc, char *argv[]) {
         if (!child)
             continue;
 
+        g_ptr_array_add(groups, child);
         g_signal_connect(child, "changed", (GCallback) module_group_callback, *name);
         handle_module_group(*name);
     }
@@ -110,6 +113,7 @@ int main(int argc, char *argv[]) {
     g_main_loop_run(g);
     g_main_loop_unref(g);
 
+    g_ptr_array_unref(groups);
     g_object_unref(G_OBJECT(settings));
 
     return 0;

commit 705779eddd2dfc0460d0440cf58261f5da1dbc7a
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:39 2018 +0300

    gsettings: remove bad signal connection
    
    The removed g_signal_connect() call didn't make sense. The callback
    expects to be called when individual module groups are changed, not when
    the top level object is changed. Also, module_group_callback() expects
    user_data to be non-NULL, but here it was set to NULL.

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index 5d1d210a..cf047e23 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -88,8 +88,6 @@ int main(int argc, char *argv[]) {
     if (!(settings = g_settings_new(PA_GSETTINGS_MODULE_GROUPS_SCHEMA)))
         goto fail;
 
-    g_signal_connect(settings, "changed", (GCallback) module_group_callback, NULL);
-
     group_names = g_settings_list_children(settings);
 
     for (name = group_names; *name; name++) {

commit 8484b63c18741307e77c66d830a2bbde26dc834a
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:38 2018 +0300

    gsettings: check that children haven't been deleted before using them
    
    According to the documentation of g_settings_list_children(), the listed
    children may be removed at any time, so g_settings_get_child() may
    return NULL. This is probably very unlikely to happen in practice, but
    it's good to check anyway.

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index 36c1df77..5d1d210a 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -93,8 +93,14 @@ int main(int argc, char *argv[]) {
     group_names = g_settings_list_children(settings);
 
     for (name = group_names; *name; name++) {
-        g_signal_connect(g_settings_get_child(settings, *name), "changed",
-                         (GCallback) module_group_callback, *name);
+        GSettings *child = g_settings_get_child(settings, *name);
+
+        /* The child may have been removed between the
+         * g_settings_list_children() and g_settings_get_child() calls. */
+        if (!child)
+            continue;
+
+        g_signal_connect(child, "changed", (GCallback) module_group_callback, *name);
         handle_module_group(*name);
     }
 

commit f5ff5d8bf21ebe4d50487079d2f3f3f2b5b446c0
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:37 2018 +0300

    build-sys: remove a redundant enable_gsettings check
    
    If HAVE_GSETTINGS is 1, then enable_gsettings must be yes, so checking
    enable_gsettings isn't necessary.

diff --git a/configure.ac b/configure.ac
index 5720c28e..2d3022e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -942,7 +942,7 @@ AS_IF([test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x0"],
 AM_CONDITIONAL([HAVE_GSETTINGS], [test "x$HAVE_GSETTINGS" = x1])
 AC_SUBST([HAVE_GSETTINGS])
 
-if test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x1" ; then
+if test "x$HAVE_GSETTINGS" = "x1" ; then
     GLIB_GSETTINGS
 fi
 

commit 890bc108d61f2c6d37082771819435ae46616bbe
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:36 2018 +0300

    gsettings: rename "module" to "module-group"
    
    It is confusing if there's a thing named "module" which defines up to 10
    modules to load. Calling the thing a "module group" instead should make
    it easier to understand.

diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
index 8275e45c..36c1df77 100644
--- a/src/modules/gsettings/gsettings-helper.c
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -28,21 +28,19 @@
 
 #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/"
+#define PA_GSETTINGS_MODULE_GROUP_SCHEMA "org.freedesktop.pulseaudio.module-group"
+#define PA_GSETTINGS_MODULE_GROUPS_SCHEMA "org.freedesktop.pulseaudio.module-groups"
+#define PA_GSETTINGS_MODULE_GROUPS_PATH "/org/freedesktop/pulseaudio/module-groups/"
 
-static void modules_callback(GSettings *settings, gchar *key, gpointer user_data);
-
-static void handle_module(gchar *name) {
+static void handle_module_group(gchar *name) {
     GSettings *settings;
     gchar p[1024];
     gboolean enabled;
     int i;
 
-    pa_snprintf(p, sizeof(p), PA_GSETTINGS_MODULES_PATH"%s/", name);
+    pa_snprintf(p, sizeof(p), PA_GSETTINGS_MODULE_GROUPS_PATH"%s/", name);
 
-    if (!(settings = g_settings_new_with_path(PA_GSETTINGS_MODULE_SCHEMA,
+    if (!(settings = g_settings_new_with_path(PA_GSETTINGS_MODULE_GROUP_SCHEMA,
                                               p)))
         return;
 
@@ -74,30 +72,30 @@ static void handle_module(gchar *name) {
     g_object_unref(G_OBJECT(settings));
 }
 
-static void modules_callback(GSettings *settings, gchar *key, gpointer user_data) {
-    handle_module(user_data);
+static void module_group_callback(GSettings *settings, gchar *key, gpointer user_data) {
+    handle_module_group(user_data);
 }
 
 int main(int argc, char *argv[]) {
     GMainLoop *g;
     GSettings *settings;
-    gchar **modules, **m;
+    gchar **group_names, **name;
 
 #if !GLIB_CHECK_VERSION(2,36,0)
     g_type_init();
 #endif
 
-    if (!(settings = g_settings_new(PA_GSETTINGS_MODULES_SCHEMA)))
+    if (!(settings = g_settings_new(PA_GSETTINGS_MODULE_GROUPS_SCHEMA)))
         goto fail;
 
-    g_signal_connect(settings, "changed", (GCallback) modules_callback, NULL);
+    g_signal_connect(settings, "changed", (GCallback) module_group_callback, NULL);
 
-    modules = g_settings_list_children (settings);
+    group_names = 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);
+    for (name = group_names; *name; name++) {
+        g_signal_connect(g_settings_get_child(settings, *name), "changed",
+                         (GCallback) module_group_callback, *name);
+        handle_module_group(*name);
     }
 
     /* Signal the parent that we are now initialized */
diff --git a/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
index 644e77bd..9d06383d 100644
--- a/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
+++ b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
@@ -1,19 +1,26 @@
 <schemalist gettext-domain="pulseaudio">
-  <schema id="org.freedesktop.pulseaudio.modules" path="/org/freedesktop/pulseaudio/modules/">
-    <child name="combine" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="remote-access" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="zeroconf-discover" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="raop-discover" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="rtp-recv" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="rtp-send" schema="org.freedesktop.pulseaudio.module"/>
-    <child name="upnp-media-server" schema="org.freedesktop.pulseaudio.module"/>
+  <!-- The module-groups object is just an entry point to find the individual
+       module-group objects. -->
+  <schema id="org.freedesktop.pulseaudio.module-groups" path="/org/freedesktop/pulseaudio/module-groups/">
+    <child name="combine" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="remote-access" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="zeroconf-discover" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="raop-discover" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="rtp-recv" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="rtp-send" schema="org.freedesktop.pulseaudio.module-group"/>
+    <child name="upnp-media-server" schema="org.freedesktop.pulseaudio.module-group"/>
   </schema>
 
-  <schema id="org.freedesktop.pulseaudio.module">
+  <!-- Paprefs puts related modules into groups that are enabled or disabled as
+       a whole. One group can contain up to 10 module instances (either of the
+       same module or different modules). A module-group object defines up to
+       10 modules to load. The name0..name9 keys contain the module names and
+       the args0..args9 keys provide the module arguments. -->
+  <schema id="org.freedesktop.pulseaudio.module-group">
     <key name="name" type="s">
       <default>''</default>
-      <summary>Module name</summary>
-      <description>Name of the pulseaudio module</description>
+      <summary>Module group name</summary>
+      <description>Module group name</description>
     </key>
 
     <key name="enabled" type="b">

commit 0623b3c91e906b0579befd5d3ffc05c32b2a0342
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:35 2018 +0300

    gconf, gsettings: fix config.h includes
    
    config.h should be included by all .c files and none of the .h files.

diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c
index e5ddf0df..c0f4dde5 100644
--- a/src/modules/gconf/module-gconf.c
+++ b/src/modules/gconf/module-gconf.c
@@ -17,7 +17,9 @@
   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "../stdin-util.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -26,6 +28,8 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/start-child.h>
 
+#include "../stdin-util.h"
+
 PA_MODULE_AUTHOR("Lennart Poettering");
 PA_MODULE_DESCRIPTION("GConf Adapter");
 PA_MODULE_VERSION(PACKAGE_VERSION);
diff --git a/src/modules/gsettings/module-gsettings.c b/src/modules/gsettings/module-gsettings.c
index 7df933d6..330eca1d 100644
--- a/src/modules/gsettings/module-gsettings.c
+++ b/src/modules/gsettings/module-gsettings.c
@@ -17,7 +17,9 @@
   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "../stdin-util.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -26,6 +28,8 @@
 #include <pulsecore/core-util.h>
 #include <pulsecore/start-child.h>
 
+#include "../stdin-util.h"
+
 PA_MODULE_AUTHOR("Sylvain Baubeau");
 PA_MODULE_DESCRIPTION("GSettings Adapter");
 PA_MODULE_VERSION(PACKAGE_VERSION);
diff --git a/src/modules/stdin-util.c b/src/modules/stdin-util.c
index db394acb..37bd1a4a 100644
--- a/src/modules/stdin-util.c
+++ b/src/modules/stdin-util.c
@@ -17,8 +17,6 @@
   License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "stdin-util.h"
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
diff --git a/src/modules/stdin-util.h b/src/modules/stdin-util.h
index 6b97f238..9177026a 100644
--- a/src/modules/stdin-util.h
+++ b/src/modules/stdin-util.h
@@ -20,10 +20,6 @@
   License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <errno.h>
 #include <stdint.h>
 #include <sys/types.h>

commit d7a457eaedfa04be792f869379f61623e36539e6
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:34 2018 +0300

    gsettings: add the modules schema to the schema description file
    
    Originally the idea was to provide the "modules" schema with paprefs,
    but since module-gsettings refers to the "modules" schema in its code,
    that would make module-gsettings depend on paprefs, which is not good.
    Now all schemas are provided by module-gsettings, so the paprefs
    dependency is avoided. Unfortunately this means that if paprefs is
    modified to load some new modules, the schema in pulseaudio needs to be
    updated as well.

diff --git a/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
index 8e2302cc..644e77bd 100644
--- a/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
+++ b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
@@ -1,4 +1,14 @@
 <schemalist gettext-domain="pulseaudio">
+  <schema id="org.freedesktop.pulseaudio.modules" path="/org/freedesktop/pulseaudio/modules/">
+    <child name="combine" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="remote-access" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="zeroconf-discover" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="raop-discover" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="rtp-recv" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="rtp-send" schema="org.freedesktop.pulseaudio.module"/>
+    <child name="upnp-media-server" schema="org.freedesktop.pulseaudio.module"/>
+  </schema>
+
   <schema id="org.freedesktop.pulseaudio.module">
     <key name="name" type="s">
       <default>''</default>

commit b43d47f0051a6f9c17452c56c73d69d9e96b338a
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:33 2018 +0300

    default.pa: add module-gsettings
    
    This also makes the module-gconf section conditional on HAVE_GCONF,
    because if only gsettings support is built, the gconf section in the
    configuration file would be redundant and confusing.

diff --git a/configure.ac b/configure.ac
index bdaaef29..5720c28e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -925,6 +925,7 @@ AS_IF([test "x$enable_gconf" = "xyes" && test "x$HAVE_GCONF" = "x0"],
     [AC_MSG_ERROR([*** GConf support not found])])
 
 AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = x1])
+AC_SUBST([HAVE_GCONF])
 
 #### GSettings support (optional) ####
 
@@ -939,6 +940,7 @@ AS_IF([test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x0"],
     [AC_MSG_ERROR([*** GSettings support not found])])
 
 AM_CONDITIONAL([HAVE_GSETTINGS], [test "x$HAVE_GSETTINGS" = x1])
+AC_SUBST([HAVE_GSETTINGS])
 
 if test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x1" ; then
     GLIB_GSETTINGS
diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in
index 7a686538..14b6a6f9 100755
--- a/src/daemon/default.pa.in
+++ b/src/daemon/default.pa.in
@@ -110,6 +110,18 @@ ifelse(@OS_IS_WIN32@, 0, [dnl
 #load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 sink_properties="device.description='RTP Multicast Sink'"
 #load-module module-rtp-send source=rtp.monitor
 
+ifelse(@HAVE_GSETTINGS@, 1, [dnl
+### Load additional modules from GSettings. This can be configured with the paprefs tool.
+### Please keep in mind that the modules configured by paprefs might conflict with manually
+### loaded modules.
+.ifexists module-gsettings at PA_SOEXT@
+.nofail
+load-module module-gsettings
+.fail
+.endif
+])dnl
+
+ifelse(@HAVE_GCONF@, 1, [dnl
 ### Load additional modules from GConf settings. This can be configured with the paprefs tool.
 ### Please keep in mind that the modules configured by paprefs might conflict with manually
 ### loaded modules.
@@ -118,6 +130,7 @@ ifelse(@OS_IS_WIN32@, 0, [dnl
 load-module module-gconf
 .fail
 .endif
+])dnl
 
 ### Automatically restore the default sink/source when changed by the user
 ### during runtime

commit 29ed94600cfbfe225370ee5827f50053761a2f65
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Tue Apr 17 09:07:32 2018 +0300

    .gitignore: add module-gsettings related things

diff --git a/src/.gitignore b/src/.gitignore
index d8c080ea..685bed0b 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -15,6 +15,8 @@ default.pa
 echo-cancel-test
 esdcompat
 gconf-helper
+gsettings-helper
+org.freedesktop.pulseaudio.gschema.valid
 pacat
 pacmd
 pactl

commit 785b660d8a3854204dbb85f025dbe95df1e3c4fd
Author: Sylvain Baubeau <lebauce at gmail.com>
Date:   Mon Jul 25 21:58:48 2016 +0200

    module-gsettings: new module to store configuration using gsettings
    
    GConf is deprecated, and distributions are removing it. paprefs depends
    on GConf, so in order to avoid paprefs getting removed as well, paprefs
    has to be changed to use something else than GConf. GSettings is the
    easiest alternative to migrate to, although it has the same problems
    that GConf had: no support for system mode or networking.
    
    This patch takes the non-GConf specific code from module-gconf and puts
    it in stdin-util.[ch], which is then reused by module-gsettings.
    module-gsettings is designed to be very similar to module-gconf.
    
    Migration is expected to happen as follows: Distributions update
    PulseAudio and paprefs at the same time, or first PulseAudio and then
    paprefs. paprefs depends on module-gsettings, and module-gsettings
    conflicts with module-gconf. Therefore module-gconf gets automatically
    removed during the paprefs update. After the update an old PulseAudio is
    likely to be running with module-gconf loaded. If the user tries to use
    paprefs during this period, whatever the user does in paprefs won't have
    any effect until PulseAudio is restarted (probably by a reboot or
    relogin). This is not ideal, but will have to do.
    
    When module-gsettings is loaded, it runs gsettings-data-convert
    (implemented in a later patch). That will copy the settings from GConf
    to GSettings. If gsettings-data-convert is not available (it's part of
    GConf, so it may have already been uninstalled), then any previous
    paprefs settings are lost.

diff --git a/configure.ac b/configure.ac
index 0eb44b08..bdaaef29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -926,6 +926,24 @@ AS_IF([test "x$enable_gconf" = "xyes" && test "x$HAVE_GCONF" = "x0"],
 
 AM_CONDITIONAL([HAVE_GCONF], [test "x$HAVE_GCONF" = x1])
 
+#### GSettings support (optional) ####
+
+AC_ARG_ENABLE([gsettings],
+    AS_HELP_STRING([--enable-gsettings],[Enable optional GSettings support]))
+
+AS_IF([test "x$enable_gsettings" = "xyes"],
+    [PKG_CHECK_MODULES(GSETTINGS, [ gio-2.0 >= 2.26.0 ], [HAVE_GSETTINGS=1], [HAVE_GSETTINGS=0])],
+    HAVE_GSETTINGS=0)
+
+AS_IF([test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x0"],
+    [AC_MSG_ERROR([*** GSettings support not found])])
+
+AM_CONDITIONAL([HAVE_GSETTINGS], [test "x$HAVE_GSETTINGS" = x1])
+
+if test "x$enable_gsettings" = "xyes" && test "x$HAVE_GSETTINGS" = "x1" ; then
+    GLIB_GSETTINGS
+fi
+
 #### Avahi support (optional) ####
 
 AC_ARG_ENABLE([avahi],
@@ -1566,6 +1584,7 @@ AS_IF([test "x$HAVE_WAVEOUT" = "x1"], ENABLE_WAVEOUT=yes, ENABLE_WAVEOUT=no)
 AS_IF([test "x$HAVE_GLIB20" = "x1"], ENABLE_GLIB20=yes, ENABLE_GLIB20=no)
 AS_IF([test "x$HAVE_GTK30" = "x1"], ENABLE_GTK30=yes, ENABLE_GTK30=no)
 AS_IF([test "x$HAVE_GCONF" = "x1"], ENABLE_GCONF=yes, ENABLE_GCONF=no)
+AS_IF([test "x$HAVE_GSETTINGS" = "x1"], ENABLE_GSETTINGS=yes, ENABLE_GSETTINGS=no)
 AS_IF([test "x$HAVE_AVAHI" = "x1"], ENABLE_AVAHI=yes, ENABLE_AVAHI=no)
 AS_IF([test "x$HAVE_JACK" = "x1"], ENABLE_JACK=yes, ENABLE_JACK=no)
 AS_IF([test "x$HAVE_LIBASYNCNS" = "x1"], ENABLE_LIBASYNCNS=yes, ENABLE_LIBASYNCNS=no)
@@ -1628,6 +1647,7 @@ echo "
     Enable GLib 2.0:               ${ENABLE_GLIB20}
     Enable Gtk+ 3.0:               ${ENABLE_GTK30}
     Enable GConf:                  ${ENABLE_GCONF}
+    Enable GSettings:              ${ENABLE_GSETTINGS}
     Enable Avahi:                  ${ENABLE_AVAHI}
     Enable Jack:                   ${ENABLE_JACK}
     Enable Async DNS:              ${ENABLE_LIBASYNCNS}
diff --git a/src/Makefile.am b/src/Makefile.am
index 45616c01..b59cec96 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1412,6 +1412,14 @@ pulselibexec_PROGRAMS += \
 		gconf-helper
 endif
 
+if HAVE_GSETTINGS
+modlibexec_LTLIBRARIES += \
+		module-gsettings.la
+
+pulselibexec_PROGRAMS += \
+		gsettings-helper
+endif
+
 if HAVE_WAVEOUT
 modlibexec_LTLIBRARIES += \
 		module-waveout.la
@@ -2057,7 +2065,10 @@ module_systemd_login_la_LIBADD = $(MODULE_LIBADD) $(SYSTEMD_LIBS) $(SYSTEMDLOGIN
 module_systemd_login_la_CFLAGS = $(AM_CFLAGS) $(SYSTEMD_CFLAGS) $(SYSTEMDLOGIN_CFLAGS) -DPA_MODULE_NAME=module_systemd_login
 
 # GConf support
-module_gconf_la_SOURCES = modules/gconf/module-gconf.c
+module_gconf_la_SOURCES = \
+		 modules/stdin-util.c modules/stdin-util.h \
+		 modules/gconf/module-gconf.c
+
 module_gconf_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_gconf_la_LIBADD = $(MODULE_LIBADD)
 module_gconf_la_CFLAGS = $(AM_CFLAGS) -DPA_GCONF_HELPER=\"$(pulselibexecdir)/gconf-helper\" -DPA_MODULE_NAME=module_gconf
@@ -2067,6 +2078,24 @@ gconf_helper_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulsecommon-
 gconf_helper_CFLAGS = $(AM_CFLAGS) $(GCONF_CFLAGS)
 gconf_helper_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
+# GSettings support
+module_gsettings_la_SOURCES = \
+		modules/stdin-util.c modules/stdin-util.h \
+		modules/gsettings/module-gsettings.c
+module_gsettings_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_gsettings_la_LIBADD = $(MODULE_LIBADD)
+module_gsettings_la_CFLAGS = $(AM_CFLAGS) -DPA_GSETTINGS_HELPER=\"$(pulselibexecdir)/gsettings-helper\" -DPA_MODULE_NAME=module_gsettings
+
+gsettings_helper_SOURCES = modules/gsettings/gsettings-helper.c
+gsettings_helper_LDADD = $(AM_LDADD) libpulsecore- at PA_MAJORMINOR@.la libpulsecommon- at PA_MAJORMINOR@.la libpulse.la $(GSETTINGS_LIBS)
+gsettings_helper_CFLAGS = $(AM_CFLAGS) $(GSETTINGS_CFLAGS)
+gsettings_helper_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+
+if HAVE_GSETTINGS
+gsettings_SCHEMAS = modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
+ at GSETTINGS_RULES@
+endif
+
 # Bluetooth policy
 module_bluetooth_policy_la_SOURCES = modules/bluetooth/module-bluetooth-policy.c
 module_bluetooth_policy_la_LDFLAGS = $(MODULE_LDFLAGS)
diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c
index df397797..e5ddf0df 100644
--- a/src/modules/gconf/module-gconf.c
+++ b/src/modules/gconf/module-gconf.c
@@ -17,25 +17,13 @@
   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "../stdin-util.h"
 
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include <pulse/xmalloc.h>
-#include <pulsecore/module.h>
-#include <pulsecore/core.h>
-#include <pulsecore/core-util.h>
-#include <pulsecore/log.h>
-#include <pulse/mainloop-api.h>
 #include <pulsecore/core-error.h>
+#include <pulsecore/core-util.h>
 #include <pulsecore/start-child.h>
 
 PA_MODULE_AUTHOR("Lennart Poettering");
@@ -43,282 +31,6 @@ PA_MODULE_DESCRIPTION("GConf Adapter");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
 
-#define MAX_MODULES 10
-#define BUF_MAX 2048
-
-struct userdata;
-
-struct module_item {
-    char *name;
-    char *args;
-    uint32_t index;
-};
-
-struct pa_module_info {
-    struct userdata *userdata;
-    char *name;
-
-    struct module_item items[MAX_MODULES];
-    unsigned n_items;
-};
-
-struct userdata {
-    pa_core *core;
-    pa_module *module;
-
-    pa_hashmap *module_infos;
-
-    pid_t pid;
-
-    int fd;
-    int fd_type;
-    pa_io_event *io_event;
-
-    char buf[BUF_MAX];
-    size_t buf_fill;
-};
-
-static int fill_buf(struct userdata *u) {
-    ssize_t r;
-    pa_assert(u);
-
-    if (u->buf_fill >= BUF_MAX) {
-        pa_log("read buffer overflow");
-        return -1;
-    }
-
-    if ((r = pa_read(u->fd, u->buf + u->buf_fill, BUF_MAX - u->buf_fill, &u->fd_type)) <= 0)
-        return -1;
-
-    u->buf_fill += (size_t) r;
-    return 0;
-}
-
-static int read_byte(struct userdata *u) {
-    int ret;
-    pa_assert(u);
-
-    if (u->buf_fill < 1)
-        if (fill_buf(u) < 0)
-            return -1;
-
-    ret = u->buf[0];
-    pa_assert(u->buf_fill > 0);
-    u->buf_fill--;
-    memmove(u->buf, u->buf+1, u->buf_fill);
-    return ret;
-}
-
-static char *read_string(struct userdata *u) {
-    pa_assert(u);
-
-    for (;;) {
-        char *e;
-
-        if ((e = memchr(u->buf, 0, u->buf_fill))) {
-            char *ret = pa_xstrdup(u->buf);
-            u->buf_fill -= (size_t) (e - u->buf +1);
-            memmove(u->buf, e+1, u->buf_fill);
-            return ret;
-        }
-
-        if (fill_buf(u) < 0)
-            return NULL;
-    }
-}
-
-static void unload_one_module(struct pa_module_info *m, unsigned i) {
-    struct userdata *u;
-
-    pa_assert(m);
-    pa_assert(i < m->n_items);
-
-    u = m->userdata;
-
-    if (m->items[i].index == PA_INVALID_INDEX)
-        return;
-
-    pa_log_debug("Unloading module #%i", m->items[i].index);
-    pa_module_unload_by_index(u->core, m->items[i].index, true);
-    m->items[i].index = PA_INVALID_INDEX;
-    pa_xfree(m->items[i].name);
-    pa_xfree(m->items[i].args);
-    m->items[i].name = m->items[i].args = NULL;
-}
-
-static void unload_all_modules(struct pa_module_info *m) {
-    unsigned i;
-
-    pa_assert(m);
-
-    for (i = 0; i < m->n_items; i++)
-        unload_one_module(m, i);
-
-    m->n_items = 0;
-}
-
-static void load_module(
-        struct pa_module_info *m,
-        unsigned i,
-        const char *name,
-        const char *args,
-        bool is_new) {
-
-    struct userdata *u;
-    pa_module *mod;
-
-    pa_assert(m);
-    pa_assert(name);
-    pa_assert(args);
-
-    u = m->userdata;
-
-    if (!is_new) {
-        if (m->items[i].index != PA_INVALID_INDEX &&
-            pa_streq(m->items[i].name, name) &&
-            pa_streq(m->items[i].args, args))
-            return;
-
-        unload_one_module(m, i);
-    }
-
-    pa_log_debug("Loading module '%s' with args '%s' due to GConf configuration.", name, args);
-
-    m->items[i].name = pa_xstrdup(name);
-    m->items[i].args = pa_xstrdup(args);
-    m->items[i].index = PA_INVALID_INDEX;
-
-    if (pa_module_load(&mod, u->core, name, args) < 0) {
-        pa_log("pa_module_load() failed");
-        return;
-    }
-
-    m->items[i].index = mod->index;
-}
-
-static void module_info_free(void *p) {
-    struct pa_module_info *m = p;
-
-    pa_assert(m);
-
-    unload_all_modules(m);
-    pa_xfree(m->name);
-    pa_xfree(m);
-}
-
-static int handle_event(struct userdata *u) {
-    int opcode;
-    int ret = 0;
-
-    do {
-        if ((opcode = read_byte(u)) < 0) {
-            if (errno == EINTR || errno == EAGAIN)
-                break;
-            goto fail;
-        }
-
-        switch (opcode) {
-            case '!':
-                /* The helper tool is now initialized */
-                ret = 1;
-                break;
-
-            case '+': {
-                char *name;
-                struct pa_module_info *m;
-                unsigned i, j;
-
-                if (!(name = read_string(u)))
-                    goto fail;
-
-                if (!(m = pa_hashmap_get(u->module_infos, name))) {
-                    m = pa_xnew(struct pa_module_info, 1);
-                    m->userdata = u;
-                    m->name = name;
-                    m->n_items = 0;
-                    pa_hashmap_put(u->module_infos, m->name, m);
-                } else
-                    pa_xfree(name);
-
-                i = 0;
-                while (i < MAX_MODULES) {
-                    char *module, *args;
-
-                    if (!(module = read_string(u))) {
-                        if (i > m->n_items) m->n_items = i;
-                        goto fail;
-                    }
-
-                    if (!*module) {
-                        pa_xfree(module);
-                        break;
-                    }
-
-                    if (!(args = read_string(u))) {
-                        pa_xfree(module);
-
-                        if (i > m->n_items) m->n_items = i;
-                        goto fail;
-                    }
-
-                    load_module(m, i, module, args, i >= m->n_items);
-
-                    i++;
-
-                    pa_xfree(module);
-                    pa_xfree(args);
-                }
-
-                /* Unload all removed modules */
-                for (j = i; j < m->n_items; j++)
-                    unload_one_module(m, j);
-
-                m->n_items = i;
-
-                break;
-            }
-
-            case '-': {
-                char *name;
-
-                if (!(name = read_string(u)))
-                    goto fail;
-
-                pa_hashmap_remove_and_free(u->module_infos, name);
-                pa_xfree(name);
-
-                break;
-            }
-        }
-    } while (u->buf_fill > 0 && ret == 0);
-
-    return ret;
-
-fail:
-    pa_log("Unable to read or parse data from client.");
-    return -1;
-}
-
-static void io_event_cb(
-        pa_mainloop_api*a,
-        pa_io_event* e,
-        int fd,
-        pa_io_event_flags_t events,
-        void *userdata) {
-
-    struct userdata *u = userdata;
-
-    if (handle_event(u) < 0) {
-
-        if (u->io_event) {
-            u->core->mainloop->io_free(u->io_event);
-            u->io_event = NULL;
-        }
-
-        pa_module_unload_request(u->module, true);
-    }
-}
-
 int pa__init(pa_module*m) {
     struct userdata *u;
     int r;
diff --git a/src/modules/gsettings/gsettings-helper.c b/src/modules/gsettings/gsettings-helper.c
new file mode 100644
index 00000000..8275e45c
--- /dev/null
+++ b/src/modules/gsettings/gsettings-helper.c
@@ -0,0 +1,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;
+}
diff --git a/src/modules/gsettings/module-gsettings.c b/src/modules/gsettings/module-gsettings.c
new file mode 100644
index 00000000..7df933d6
--- /dev/null
+++ b/src/modules/gsettings/module-gsettings.c
@@ -0,0 +1,110 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2006 Lennart Poettering
+
+  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/>.
+***/
+
+#include "../stdin-util.h"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <pulsecore/core-error.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/start-child.h>
+
+PA_MODULE_AUTHOR("Sylvain Baubeau");
+PA_MODULE_DESCRIPTION("GSettings Adapter");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(true);
+
+int pa__init(pa_module*m) {
+    struct userdata *u;
+    int r;
+
+    u = pa_xnew(struct userdata, 1);
+    u->core = m->core;
+    u->module = m;
+    m->userdata = u;
+    u->module_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) module_info_free);
+    u->pid = (pid_t) -1;
+    u->fd = -1;
+    u->fd_type = 0;
+    u->io_event = NULL;
+    u->buf_fill = 0;
+
+    if ((u->fd = pa_start_child_for_read(
+#if defined(__linux__) && !defined(__OPTIMIZE__)
+                              pa_run_from_build_tree() ? PA_BUILDDIR "/gsettings-helper" :
+#endif
+                 PA_GSETTINGS_HELPER, NULL, &u->pid)) < 0)
+        goto fail;
+
+    u->io_event = m->core->mainloop->io_new(
+            m->core->mainloop,
+            u->fd,
+            PA_IO_EVENT_INPUT,
+            io_event_cb,
+            u);
+
+    do {
+        if ((r = handle_event(u)) < 0)
+            goto fail;
+
+        /* Read until the client signalled us that it is ready with
+         * initialization */
+    } while (r != 1);
+
+    return 0;
+
+fail:
+    pa__done(m);
+    return -1;
+}
+
+void pa__done(pa_module*m) {
+    struct userdata *u;
+
+    pa_assert(m);
+
+    if (!(u = m->userdata))
+        return;
+
+    if (u->pid != (pid_t) -1) {
+        kill(u->pid, SIGTERM);
+
+        for (;;) {
+            if (waitpid(u->pid, NULL, 0) >= 0)
+                break;
+
+            if (errno != EINTR) {
+                pa_log("waitpid() failed: %s", pa_cstrerror(errno));
+                break;
+            }
+        }
+    }
+
+    if (u->io_event)
+        m->core->mainloop->io_free(u->io_event);
+
+    if (u->fd >= 0)
+        pa_close(u->fd);
+
+    if (u->module_infos)
+        pa_hashmap_free(u->module_infos);
+
+    pa_xfree(u);
+}
diff --git a/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
new file mode 100644
index 00000000..8e2302cc
--- /dev/null
+++ b/src/modules/gsettings/org.freedesktop.pulseaudio.gschema.xml
@@ -0,0 +1,98 @@
+<schemalist gettext-domain="pulseaudio">
+  <schema id="org.freedesktop.pulseaudio.module">
+    <key name="name" type="s">
+      <default>''</default>
+      <summary>Module name</summary>
+      <description>Name of the pulseaudio module</description>
+    </key>
+
+    <key name="enabled" type="b">
+      <default>false</default>
+    </key>
+
+    <key name="locked" type="b">
+      <default>false</default>
+    </key>
+
+    <key name="args0" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args1" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args2" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args3" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args4" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args5" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args6" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args7" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args8" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="args9" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name0" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name1" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name2" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name3" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name4" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name5" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name6" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name7" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name8" type="s">
+      <default>''</default>
+    </key>
+
+    <key name="name9" type="s">
+      <default>''</default>
+    </key>
+  </schema>
+
+</schemalist>
diff --git a/src/modules/stdin-util.c b/src/modules/stdin-util.c
new file mode 100644
index 00000000..db394acb
--- /dev/null
+++ b/src/modules/stdin-util.c
@@ -0,0 +1,281 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  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/>.
+***/
+
+#include "stdin-util.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/module.h>
+#include <pulsecore/core.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+#include <pulse/mainloop-api.h>
+#include <pulsecore/core-error.h>
+#include <pulsecore/start-child.h>
+
+#include "stdin-util.h"
+
+int fill_buf(struct userdata *u) {
+    ssize_t r;
+    pa_assert(u);
+
+    if (u->buf_fill >= BUF_MAX) {
+        pa_log("read buffer overflow");
+        return -1;
+    }
+
+    if ((r = pa_read(u->fd, u->buf + u->buf_fill, BUF_MAX - u->buf_fill, &u->fd_type)) <= 0)
+        return -1;
+
+    u->buf_fill += (size_t) r;
+    return 0;
+}
+
+int read_byte(struct userdata *u) {
+    int ret;
+    pa_assert(u);
+
+    if (u->buf_fill < 1)
+        if (fill_buf(u) < 0)
+            return -1;
+
+    ret = u->buf[0];
+    pa_assert(u->buf_fill > 0);
+    u->buf_fill--;
+    memmove(u->buf, u->buf+1, u->buf_fill);
+    return ret;
+}
+
+char *read_string(struct userdata *u) {
+    pa_assert(u);
+
+    for (;;) {
+        char *e;
+
+        if ((e = memchr(u->buf, 0, u->buf_fill))) {
+            char *ret = pa_xstrdup(u->buf);
+            u->buf_fill -= (size_t) (e - u->buf +1);
+            memmove(u->buf, e+1, u->buf_fill);
+            return ret;
+        }
+
+        if (fill_buf(u) < 0)
+            return NULL;
+    }
+}
+
+void unload_one_module(struct pa_module_info *m, unsigned i) {
+    struct userdata *u;
+
+    pa_assert(m);
+    pa_assert(i < m->n_items);
+
+    u = m->userdata;
+
+    if (m->items[i].index == PA_INVALID_INDEX)
+        return;
+
+    pa_log_debug("Unloading module #%i", m->items[i].index);
+    pa_module_unload_by_index(u->core, m->items[i].index, true);
+    m->items[i].index = PA_INVALID_INDEX;
+    pa_xfree(m->items[i].name);
+    pa_xfree(m->items[i].args);
+    m->items[i].name = m->items[i].args = NULL;
+}
+
+void unload_all_modules(struct pa_module_info *m) {
+    unsigned i;
+
+    pa_assert(m);
+
+    for (i = 0; i < m->n_items; i++)
+        unload_one_module(m, i);
+
+    m->n_items = 0;
+}
+
+void load_module(
+        struct pa_module_info *m,
+        unsigned i,
+        const char *name,
+        const char *args,
+        bool is_new) {
+
+    struct userdata *u;
+    pa_module *mod;
+
+    pa_assert(m);
+    pa_assert(name);
+    pa_assert(args);
+
+    u = m->userdata;
+
+    if (!is_new) {
+        if (m->items[i].index != PA_INVALID_INDEX &&
+            pa_streq(m->items[i].name, name) &&
+            pa_streq(m->items[i].args, args))
+            return;
+
+        unload_one_module(m, i);
+    }
+
+    pa_log_debug("Loading module '%s' with args '%s' due to GConf/GSettings configuration.", name, args);
+
+    m->items[i].name = pa_xstrdup(name);
+    m->items[i].args = pa_xstrdup(args);
+    m->items[i].index = PA_INVALID_INDEX;
+
+    if (pa_module_load(&mod, u->core, name, args) < 0) {
+        pa_log("pa_module_load() failed");
+        return;
+    }
+
+    m->items[i].index = mod->index;
+}
+
+void module_info_free(void *p) {
+    struct pa_module_info *m = p;
+
+    pa_assert(m);
+
+    unload_all_modules(m);
+    pa_xfree(m->name);
+    pa_xfree(m);
+}
+
+int handle_event(struct userdata *u) {
+    int opcode;
+    int ret = 0;
+
+    do {
+        if ((opcode = read_byte(u)) < 0) {
+            if (errno == EINTR || errno == EAGAIN)
+                break;
+            goto fail;
+        }
+
+        switch (opcode) {
+            case '!':
+                /* The helper tool is now initialized */
+                ret = 1;
+                break;
+
+            case '+': {
+                char *name;
+                struct pa_module_info *m;
+                unsigned i, j;
+
+                if (!(name = read_string(u)))
+                    goto fail;
+
+                if (!(m = pa_hashmap_get(u->module_infos, name))) {
+                    m = pa_xnew(struct pa_module_info, 1);
+                    m->userdata = u;
+                    m->name = name;
+                    m->n_items = 0;
+                    pa_hashmap_put(u->module_infos, m->name, m);
+                } else
+                    pa_xfree(name);
+
+                i = 0;
+                while (i < MAX_MODULES) {
+                    char *module, *args;
+
+                    if (!(module = read_string(u))) {
+                        if (i > m->n_items) m->n_items = i;
+                        goto fail;
+                    }
+
+                    if (!*module) {
+                        pa_xfree(module);
+                        break;
+                    }
+
+                    if (!(args = read_string(u))) {
+                        pa_xfree(module);
+
+                        if (i > m->n_items) m->n_items = i;
+                        goto fail;
+                    }
+
+                    load_module(m, i, module, args, i >= m->n_items);
+
+                    i++;
+
+                    pa_xfree(module);
+                    pa_xfree(args);
+                }
+
+                /* Unload all removed modules */
+                for (j = i; j < m->n_items; j++)
+                    unload_one_module(m, j);
+
+                m->n_items = i;
+
+                break;
+            }
+
+            case '-': {
+                char *name;
+
+                if (!(name = read_string(u)))
+                    goto fail;
+
+                pa_hashmap_remove_and_free(u->module_infos, name);
+                pa_xfree(name);
+
+                break;
+            }
+        }
+    } while (u->buf_fill > 0 && ret == 0);
+
+    return ret;
+
+fail:
+    pa_log("Unable to read or parse data from client.");
+    return -1;
+}
+
+void io_event_cb(
+        pa_mainloop_api*a,
+        pa_io_event* e,
+        int fd,
+        pa_io_event_flags_t events,
+        void *userdata) {
+
+    struct userdata *u = userdata;
+
+    if (handle_event(u) < 0) {
+
+        if (u->io_event) {
+            u->core->mainloop->io_free(u->io_event);
+            u->io_event = NULL;
+        }
+
+        pa_module_unload_request(u->module, true);
+    }
+}
diff --git a/src/modules/stdin-util.h b/src/modules/stdin-util.h
new file mode 100644
index 00000000..6b97f238
--- /dev/null
+++ b/src/modules/stdin-util.h
@@ -0,0 +1,89 @@
+#ifndef foostdinutilhfoo
+#define foostdinutilhfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 Lennart Poettering
+
+  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 <errno.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <pulsecore/module.h>
+#include <pulsecore/typedefs.h>
+
+#define MAX_MODULES 10
+#define BUF_MAX 2048
+
+struct userdata;
+
+struct module_item {
+    char *name;
+    char *args;
+    uint32_t index;
+};
+
+struct pa_module_info {
+    struct userdata *userdata;
+    char *name;
+
+    struct module_item items[MAX_MODULES];
+    unsigned n_items;
+};
+
+struct userdata {
+    pa_core *core;
+    pa_module *module;
+
+    pa_hashmap *module_infos;
+
+    pid_t pid;
+
+    int fd;
+    int fd_type;
+    pa_io_event *io_event;
+
+    char buf[BUF_MAX];
+    size_t buf_fill;
+};
+
+int fill_buf(struct userdata *u);
+int read_byte(struct userdata *u);
+char *read_string(struct userdata *u);
+void unload_one_module(struct pa_module_info *m, unsigned i);
+void unload_all_modules(struct pa_module_info *m);
+void load_module(
+  struct pa_module_info *m,
+  unsigned i,
+  const char *name,
+  const char *args,
+  bool is_new);
+void module_info_free(void *p);
+int handle_event(struct userdata *u);
+void io_event_cb(
+  pa_mainloop_api*a,
+  pa_io_event* e,
+  int fd,
+  pa_io_event_flags_t events,
+  void *userdata);
+
+#endif



More information about the pulseaudio-commits mailing list