43e61e
--- a/meson.build
43e61e
+++ b/meson.build
43e61e
@@ -75,6 +75,7 @@ gio_unix_req_version = '>= 2.25.7'
43e61e
 
43e61e
 glib_dep = dependency('glib-2.0', version: '>= 2.44.0')
43e61e
 gio_unix_dep = dependency('gio-unix-2.0', version: gio_unix_req_version)
43e61e
+dbus_1_dep = dependency('dbus-1')
43e61e
 
43e61e
 gio_querymodules = find_program('gio-querymodules', required: false)
43e61e
 if gio_querymodules.found()
43e61e
@@ -101,6 +102,7 @@ subdir('gvdb')
43e61e
 subdir('common')
43e61e
 subdir('engine')
43e61e
 subdir('service')
43e61e
+subdir('dbus-1')
43e61e
 subdir('gdbus')
43e61e
 subdir('gsettings')
43e61e
 subdir('client')
43e61e
--- /dev/null
43e61e
+++ b/dbus-1/meson.build
43e61e
@@ -0,0 +1,43 @@
43e61e
+client_inc = include_directories('.')
43e61e
+
43e61e
+libdbus_1_sources = files('dconf-libdbus-1.c', 'dconf-libdbus-1.h')
43e61e
+
43e61e
+cflags = '-DG_LOG_DOMAIN="@0@"'.format(meson.project_name())
43e61e
+
43e61e
+libdconf_libdbus_1_shared = static_library(
43e61e
+  meson.project_name() + '-libdbus-1-shared',
43e61e
+  sources: libdbus_1_sources,
43e61e
+  include_directories: top_inc,
43e61e
+  dependencies: [gio_unix_dep, dbus_1_dep],
43e61e
+  c_args: cflags,
43e61e
+  pic: true
43e61e
+)
43e61e
+
43e61e
+libdconf_libdbus_1 = static_library(
43e61e
+  meson.project_name() + '-libdbus-1',
43e61e
+  sources: libdbus_1_sources,
43e61e
+  include_directories: top_inc,
43e61e
+  dependencies: [gio_unix_dep, dbus_1_dep],
43e61e
+  c_args: cflags,
43e61e
+)
43e61e
+
43e61e
+dbus_1_sources = files('dconf-dbus-1.c')
43e61e
+
43e61e
+libdconf_dbus_1 = shared_library(
43e61e
+  meson.project_name() + '-dbus-1',
43e61e
+  sources: dbus_1_sources,
43e61e
+  version: '0.0.0',
43e61e
+  soversion: '0',
43e61e
+  include_directories: top_inc,
43e61e
+  dependencies: [gio_unix_dep, dbus_1_dep],
43e61e
+  c_args: cflags,
43e61e
+  link_with: [
43e61e
+    libdconf_common_hidden,
43e61e
+    libdconf_engine_shared,
43e61e
+    libdconf_libdbus_1_shared,
43e61e
+    libdconf_shm_shared,
43e61e
+    libgvdb_shared
43e61e
+  ],
43e61e
+  install: true,
43e61e
+  install_dir: dconf_libdir
43e61e
+)
43e61e
--- /dev/null
43e61e
+++ b/dbus-1/dconf-dbus-1.c
43e61e
@@ -0,0 +1,188 @@
43e61e
+/**
43e61e
+ * Copyright © 2010 Canonical Limited
43e61e
+ *
43e61e
+ * This program is free software: you can redistribute it and/or modify
43e61e
+ * it under the terms of the GNU General Public License as published by
43e61e
+ * the Free Software Foundation, either version 3 of the licence, or (at
43e61e
+ * your option) any later version.
43e61e
+ *
43e61e
+ * This program is distributed in the hope that it will be useful, but
43e61e
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
43e61e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43e61e
+ * General Public License for more details.
43e61e
+ *
43e61e
+ * You should have received a copy of the GNU General Public License
43e61e
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
43e61e
+ *
43e61e
+ * Author: Ryan Lortie <desrt@desrt.ca>
43e61e
+ **/
43e61e
+
43e61e
+#include "config.h"
43e61e
+
43e61e
+#include "dconf-dbus-1.h"
43e61e
+
43e61e
+#include "../engine/dconf-engine.h"
43e61e
+#include "dconf-libdbus-1.h"
43e61e
+
43e61e
+#include <string.h>
43e61e
+
43e61e
+struct _DConfDBusClient
43e61e
+{
43e61e
+  DConfEngine *engine;
43e61e
+  GSList *watches;
43e61e
+  gint ref_count;
43e61e
+};
43e61e
+
43e61e
+typedef struct
43e61e
+{
43e61e
+  gchar           *path;
43e61e
+  DConfDBusNotify  notify;
43e61e
+  gpointer         user_data;
43e61e
+} Watch;
43e61e
+
43e61e
+void
43e61e
+dconf_engine_change_notify (DConfEngine         *engine,
43e61e
+                            const gchar         *prefix,
43e61e
+                            const gchar * const *changes,
43e61e
+                            const gchar         *tag,
43e61e
+                            gboolean             is_writability,
43e61e
+                            gpointer             origin_tag,
43e61e
+                            gpointer             user_data)
43e61e
+{
43e61e
+  DConfDBusClient *dcdbc = user_data;
43e61e
+  gchar **my_changes;
43e61e
+  gint n_changes;
43e61e
+  GSList *iter;
43e61e
+  gint i;
43e61e
+
43e61e
+  n_changes = g_strv_length ((gchar **) changes);
43e61e
+  my_changes = g_new (gchar *, n_changes + 1);
43e61e
+
43e61e
+  for (i = 0; i < n_changes; i++)
43e61e
+    my_changes[i] = g_strconcat (prefix, changes[i], NULL);
43e61e
+  my_changes[i] = NULL;
43e61e
+
43e61e
+  for (iter = dcdbc->watches; iter; iter = iter->next)
43e61e
+    {
43e61e
+      Watch *watch = iter->data;
43e61e
+
43e61e
+      for (i = 0; i < n_changes; i++)
43e61e
+        if (g_str_has_prefix (my_changes[i], watch->path))
43e61e
+          watch->notify (dcdbc, my_changes[i], watch->user_data);
43e61e
+    }
43e61e
+
43e61e
+  g_strfreev (my_changes);
43e61e
+}
43e61e
+
43e61e
+GVariant *
43e61e
+dconf_dbus_client_read (DConfDBusClient *dcdbc,
43e61e
+                        const gchar     *key)
43e61e
+{
43e61e
+  return dconf_engine_read (dcdbc->engine, DCONF_READ_FLAGS_NONE, NULL, key);
43e61e
+}
43e61e
+
43e61e
+gboolean
43e61e
+dconf_dbus_client_write (DConfDBusClient *dcdbc,
43e61e
+                         const gchar     *key,
43e61e
+                         GVariant        *value)
43e61e
+{
43e61e
+  DConfChangeset *changeset;
43e61e
+  gboolean success;
43e61e
+
43e61e
+  changeset = dconf_changeset_new_write (key, value);
43e61e
+  success = dconf_engine_change_fast (dcdbc->engine, changeset, NULL, NULL);
43e61e
+  dconf_changeset_unref (changeset);
43e61e
+
43e61e
+  return success;
43e61e
+}
43e61e
+
43e61e
+void
43e61e
+dconf_dbus_client_subscribe (DConfDBusClient *dcdbc,
43e61e
+                             const gchar     *path,
43e61e
+                             DConfDBusNotify  notify,
43e61e
+                             gpointer         user_data)
43e61e
+{
43e61e
+  Watch *watch;
43e61e
+
43e61e
+  watch = g_slice_new (Watch);
43e61e
+  watch->path = g_strdup (path);
43e61e
+  watch->notify = notify;
43e61e
+  watch->user_data = user_data;
43e61e
+
43e61e
+  dcdbc->watches = g_slist_prepend (dcdbc->watches, watch);
43e61e
+
43e61e
+  dconf_engine_watch_fast (dcdbc->engine, path);
43e61e
+}
43e61e
+
43e61e
+void
43e61e
+dconf_dbus_client_unsubscribe (DConfDBusClient *dcdbc,
43e61e
+                               DConfDBusNotify  notify,
43e61e
+                               gpointer         user_data)
43e61e
+{
43e61e
+  GSList **ptr;
43e61e
+
43e61e
+  for (ptr = &dcdbc->watches; *ptr; ptr = &(*ptr)->next)
43e61e
+    {
43e61e
+      Watch *watch = (*ptr)->data;
43e61e
+
43e61e
+      if (watch->notify == notify && watch->user_data == user_data)
43e61e
+        {
43e61e
+          *ptr = g_slist_remove_link (*ptr, *ptr);
43e61e
+          dconf_engine_unwatch_fast (dcdbc->engine, watch->path);
43e61e
+          g_free (watch->path);
43e61e
+          g_slice_free (Watch, watch);
43e61e
+          return;
43e61e
+        }
43e61e
+    }
43e61e
+
43e61e
+  g_warning ("No matching watch found to unsubscribe");
43e61e
+}
43e61e
+
43e61e
+gboolean
43e61e
+dconf_dbus_client_has_pending (DConfDBusClient *dcdbc)
43e61e
+{
43e61e
+  return dconf_engine_has_outstanding (dcdbc->engine);
43e61e
+}
43e61e
+
43e61e
+DConfDBusClient *
43e61e
+dconf_dbus_client_new (const gchar    *profile,
43e61e
+                       DBusConnection *session,
43e61e
+                       DBusConnection *system)
43e61e
+{
43e61e
+  DConfDBusClient *dcdbc;
43e61e
+
43e61e
+  if (session == NULL)
43e61e
+    session = dbus_bus_get (DBUS_BUS_SESSION, NULL);
43e61e
+
43e61e
+  if (system == NULL)
43e61e
+    system = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
43e61e
+
43e61e
+  dconf_libdbus_1_provide_bus (G_BUS_TYPE_SESSION, session);
43e61e
+  dconf_libdbus_1_provide_bus (G_BUS_TYPE_SYSTEM, system);
43e61e
+
43e61e
+  dcdbc = g_slice_new (DConfDBusClient);
43e61e
+  dcdbc->engine = dconf_engine_new (NULL, dcdbc, NULL);
43e61e
+  dcdbc->watches = NULL;
43e61e
+  dcdbc->ref_count = 1;
43e61e
+
43e61e
+  return dcdbc;
43e61e
+}
43e61e
+
43e61e
+void
43e61e
+dconf_dbus_client_unref (DConfDBusClient *dcdbc)
43e61e
+{
43e61e
+  if (--dcdbc->ref_count == 0)
43e61e
+    {
43e61e
+      g_return_if_fail (dcdbc->watches == NULL);
43e61e
+
43e61e
+      g_slice_free (DConfDBusClient, dcdbc);
43e61e
+    }
43e61e
+}
43e61e
+
43e61e
+DConfDBusClient *
43e61e
+dconf_dbus_client_ref (DConfDBusClient *dcdbc)
43e61e
+{
43e61e
+  dcdbc->ref_count++;
43e61e
+
43e61e
+  return dcdbc;
43e61e
+}
43e61e
--- /dev/null
43e61e
+++ b/dbus-1/dconf-dbus-1.h
43e61e
@@ -0,0 +1,56 @@
43e61e
+/**
43e61e
+ * Copyright © 2010 Canonical Limited
43e61e
+ *
43e61e
+ * This program is free software: you can redistribute it and/or modify
43e61e
+ * it under the terms of the GNU General Public License as published by
43e61e
+ * the Free Software Foundation, either version 3 of the licence, or (at
43e61e
+ * your option) any later version.
43e61e
+ *
43e61e
+ * This program is distributed in the hope that it will be useful, but
43e61e
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
43e61e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43e61e
+ * General Public License for more details.
43e61e
+ *
43e61e
+ * You should have received a copy of the GNU General Public License
43e61e
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
43e61e
+ *
43e61e
+ * Author: Ryan Lortie <desrt@desrt.ca>
43e61e
+ **/
43e61e
+
43e61e
+#ifndef _dconf_dbus_1_h_
43e61e
+#define _dconf_dbus_1_h_
43e61e
+
43e61e
+#include <dbus/dbus.h>
43e61e
+#include <glib.h>
43e61e
+
43e61e
+G_BEGIN_DECLS
43e61e
+
43e61e
+typedef struct _DConfDBusClient DConfDBusClient;
43e61e
+
43e61e
+typedef void         (* DConfDBusNotify)                                (DConfDBusClient *dcdbc,
43e61e
+                                                                         const gchar     *key,
43e61e
+                                                                         gpointer         user_data);
43e61e
+
43e61e
+DConfDBusClient *       dconf_dbus_client_new                           (const gchar     *profile,
43e61e
+                                                                         DBusConnection  *session,
43e61e
+                                                                         DBusConnection  *system);
43e61e
+void                    dconf_dbus_client_unref                         (DConfDBusClient *dcdbc);
43e61e
+DConfDBusClient *       dconf_dbus_client_ref                           (DConfDBusClient *dcdbc);
43e61e
+
43e61e
+GVariant *              dconf_dbus_client_read                          (DConfDBusClient *dcdbc,
43e61e
+                                                                         const gchar     *key);
43e61e
+gboolean                dconf_dbus_client_write                         (DConfDBusClient *dcdbc,
43e61e
+                                                                         const gchar     *key,
43e61e
+                                                                         GVariant        *value);
43e61e
+void                    dconf_dbus_client_subscribe                     (DConfDBusClient *dcdbc,
43e61e
+                                                                         const gchar     *name,
43e61e
+                                                                         DConfDBusNotify  notify,
43e61e
+                                                                         gpointer         user_data);
43e61e
+void                    dconf_dbus_client_unsubscribe                   (DConfDBusClient *dcdbc,
43e61e
+                                                                         DConfDBusNotify  notify,
43e61e
+                                                                         gpointer         user_data);
43e61e
+gboolean                dconf_dbus_client_has_pending                   (DConfDBusClient *dcdbc);
43e61e
+
43e61e
+G_END_DECLS
43e61e
+
43e61e
+#endif /* _dconf_dbus_1_h_ */
43e61e
--- /dev/null
43e61e
+++ b/dbus-1/dconf-libdbus-1.c
43e61e
@@ -0,0 +1,365 @@
43e61e
+/**
43e61e
+ * Copyright © 2010 Canonical Limited
43e61e
+ *
43e61e
+ * This program is free software: you can redistribute it and/or modify
43e61e
+ * it under the terms of the GNU General Public License as published by
43e61e
+ * the Free Software Foundation, either version 3 of the licence, or (at
43e61e
+ * your option) any later version.
43e61e
+ *
43e61e
+ * This program is distributed in the hope that it will be useful, but
43e61e
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
43e61e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43e61e
+ * General Public License for more details.
43e61e
+ *
43e61e
+ * You should have received a copy of the GNU General Public License
43e61e
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
43e61e
+ *
43e61e
+ * Author: Ryan Lortie <desrt@desrt.ca>
43e61e
+ **/
43e61e
+
43e61e
+#include "config.h"
43e61e
+
43e61e
+#include "dconf-libdbus-1.h"
43e61e
+
43e61e
+#include "../engine/dconf-engine.h"
43e61e
+
43e61e
+#include <string.h>
43e61e
+
43e61e
+static DBusConnection *dconf_libdbus_1_buses[5];
43e61e
+
43e61e
+struct _DConfDBusClient
43e61e
+{
43e61e
+  DConfEngine *engine;
43e61e
+  GSList *watches;
43e61e
+  gint ref_count;
43e61e
+};
43e61e
+
43e61e
+#define DCONF_LIBDBUS_1_ERROR (g_quark_from_static_string("DCONF_LIBDBUS_1_ERROR"))
43e61e
+#define DCONF_LIBDBUS_1_ERROR_FAILED 0
43e61e
+
43e61e
+static DBusMessage *
43e61e
+dconf_libdbus_1_new_method_call (const gchar *bus_name,
43e61e
+                                 const gchar *object_path,
43e61e
+                                 const gchar *interface_name,
43e61e
+                                 const gchar *method_name,
43e61e
+                                 GVariant    *parameters)
43e61e
+{
43e61e
+  DBusMessageIter dbus_iter;
43e61e
+  DBusMessage *message;
43e61e
+  GVariantIter iter;
43e61e
+  GVariant *child;
43e61e
+
43e61e
+  g_variant_ref_sink (parameters);
43e61e
+
43e61e
+  message = dbus_message_new_method_call (bus_name, object_path, interface_name, method_name);
43e61e
+  dbus_message_iter_init_append (message, &dbus_iter);
43e61e
+  g_variant_iter_init (&iter, parameters);
43e61e
+
43e61e
+  while ((child = g_variant_iter_next_value (&iter)))
43e61e
+    {
43e61e
+      if (g_variant_is_of_type (child, G_VARIANT_TYPE_STRING))
43e61e
+        {
43e61e
+          const gchar *str;
43e61e
+
43e61e
+          str = g_variant_get_string (child, NULL);
43e61e
+          dbus_message_iter_append_basic (&dbus_iter, DBUS_TYPE_STRING, &str);
43e61e
+        }
43e61e
+
43e61e
+      else if (g_variant_is_of_type (child, G_VARIANT_TYPE_UINT32))
43e61e
+        {
43e61e
+          guint32 uint;
43e61e
+
43e61e
+          uint = g_variant_get_uint32 (child);
43e61e
+          dbus_message_iter_append_basic (&dbus_iter, DBUS_TYPE_UINT32, &uint);
43e61e
+        }
43e61e
+
43e61e
+      else
43e61e
+        {
43e61e
+          DBusMessageIter subiter;
43e61e
+          const guint8 *bytes;
43e61e
+          gsize n_elements;
43e61e
+
43e61e
+          g_assert (g_variant_is_of_type (child, G_VARIANT_TYPE_BYTESTRING));
43e61e
+
43e61e
+          bytes = g_variant_get_fixed_array (child, &n_elements, sizeof (guint8));
43e61e
+          dbus_message_iter_open_container (&dbus_iter, DBUS_TYPE_ARRAY, "y", &subiter);
43e61e
+          dbus_message_iter_append_fixed_array (&subiter, DBUS_TYPE_BYTE, &bytes, n_elements);
43e61e
+          dbus_message_iter_close_container (&dbus_iter, &subiter);
43e61e
+        }
43e61e
+
43e61e
+      g_variant_unref (child);
43e61e
+    }
43e61e
+
43e61e
+  g_variant_unref (parameters);
43e61e
+
43e61e
+  return message;
43e61e
+}
43e61e
+
43e61e
+static GVariant *
43e61e
+dconf_libdbus_1_get_message_body (DBusMessage  *message,
43e61e
+                                  GError      **error)
43e61e
+{
43e61e
+  GVariantBuilder builder;
43e61e
+  const gchar *signature;
43e61e
+  DBusMessageIter iter;
43e61e
+
43e61e
+  /* We support two types: strings and arrays of strings.
43e61e
+   *
43e61e
+   * It's very simple to detect if the message contains only these
43e61e
+   * types: check that the signature contains only the letters "a" and
43e61e
+   * "s" and that it does not contain "aa".
43e61e
+   */
43e61e
+  signature = dbus_message_get_signature (message);
43e61e
+  if (signature[strspn(signature, "as")] != '\0' || strstr (signature, "aa"))
43e61e
+    {
43e61e
+      g_set_error (error, DCONF_LIBDBUS_1_ERROR, DCONF_LIBDBUS_1_ERROR_FAILED,
43e61e
+                   "unable to handle message type '(%s)'", signature);
43e61e
+      return NULL;
43e61e
+    }
43e61e
+
43e61e
+  g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
43e61e
+  dbus_message_iter_init (message, &iter);
43e61e
+  while (dbus_message_iter_get_arg_type (&iter))
43e61e
+    {
43e61e
+      const gchar *string;
43e61e
+
43e61e
+      if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_STRING)
43e61e
+        {
43e61e
+          dbus_message_iter_get_basic (&iter, &string);
43e61e
+          g_variant_builder_add (&builder, "s", string);
43e61e
+        }
43e61e
+      else
43e61e
+        {
43e61e
+          DBusMessageIter sub;
43e61e
+
43e61e
+          g_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY &&
43e61e
+                    dbus_message_iter_get_element_type (&iter) == DBUS_TYPE_STRING);
43e61e
+
43e61e
+          g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
43e61e
+          dbus_message_iter_recurse (&iter, &sub);
43e61e
+
43e61e
+          while (dbus_message_iter_get_arg_type (&sub))
43e61e
+            {
43e61e
+              const gchar *string;
43e61e
+              dbus_message_iter_get_basic (&sub, &string);
43e61e
+              g_variant_builder_add (&builder, "s", string);
43e61e
+              dbus_message_iter_next (&sub);
43e61e
+            }
43e61e
+
43e61e
+          g_variant_builder_close (&builder);
43e61e
+        }
43e61e
+      dbus_message_iter_next (&iter);
43e61e
+    }
43e61e
+
43e61e
+  return g_variant_ref_sink (g_variant_builder_end (&builder));
43e61e
+}
43e61e
+
43e61e
+static GVariant *
43e61e
+dconf_libdbus_1_interpret_result (DBusMessage         *result,
43e61e
+                                  const GVariantType  *expected_type,
43e61e
+                                  GError             **error)
43e61e
+{
43e61e
+  GVariant *reply;
43e61e
+
43e61e
+  if (dbus_message_get_type (result) == DBUS_MESSAGE_TYPE_ERROR)
43e61e
+    {
43e61e
+      const gchar *errstr = "(no message)";
43e61e
+
43e61e
+      dbus_message_get_args (result, NULL, DBUS_TYPE_STRING, &errstr, DBUS_TYPE_INVALID);
43e61e
+      g_set_error (error, DCONF_LIBDBUS_1_ERROR, DCONF_LIBDBUS_1_ERROR_FAILED,
43e61e
+                   "%s: %s", dbus_message_get_error_name (result), errstr);
43e61e
+      return NULL;
43e61e
+    }
43e61e
+
43e61e
+  reply = dconf_libdbus_1_get_message_body (result, error);
43e61e
+
43e61e
+  if (reply && expected_type && !g_variant_is_of_type (reply, expected_type))
43e61e
+    {
43e61e
+      gchar *expected_string;
43e61e
+
43e61e
+      expected_string = g_variant_type_dup_string (expected_type);
43e61e
+      g_set_error (error, DCONF_LIBDBUS_1_ERROR, DCONF_LIBDBUS_1_ERROR_FAILED,
43e61e
+                   "received reply '%s' is not of the expected type %s",
43e61e
+                   g_variant_get_type_string (reply), expected_string);
43e61e
+      g_free (expected_string);
43e61e
+
43e61e
+      g_variant_unref (reply);
43e61e
+      reply = NULL;
43e61e
+    }
43e61e
+
43e61e
+  return reply;
43e61e
+}
43e61e
+
43e61e
+static void
43e61e
+dconf_libdbus_1_method_call_done (DBusPendingCall *pending,
43e61e
+                                  gpointer         user_data)
43e61e
+{
43e61e
+  DConfEngineCallHandle *handle = user_data;
43e61e
+  const GVariantType *expected_type;
43e61e
+  DBusMessage *message;
43e61e
+  GError *error = NULL;
43e61e
+  GVariant *reply;
43e61e
+
43e61e
+  if (pending == NULL)
43e61e
+    return;
43e61e
+
43e61e
+  message = dbus_pending_call_steal_reply (pending);
43e61e
+  dbus_pending_call_unref (pending);
43e61e
+
43e61e
+  expected_type = dconf_engine_call_handle_get_expected_type (handle);
43e61e
+  reply = dconf_libdbus_1_interpret_result (message, expected_type, &error);
43e61e
+  dbus_message_unref (message);
43e61e
+
43e61e
+  dconf_engine_call_handle_reply (handle, reply, error);
43e61e
+
43e61e
+  if (reply)
43e61e
+    g_variant_unref (reply);
43e61e
+  if (error)
43e61e
+    g_error_free (error);
43e61e
+}
43e61e
+
43e61e
+gboolean
43e61e
+dconf_engine_dbus_call_async_func (GBusType                bus_type,
43e61e
+                                   const gchar            *bus_name,
43e61e
+                                   const gchar            *object_path,
43e61e
+                                   const gchar            *interface_name,
43e61e
+                                   const gchar            *method_name,
43e61e
+                                   GVariant               *parameters,
43e61e
+                                   DConfEngineCallHandle  *handle,
43e61e
+                                   GError                **error)
43e61e
+{
43e61e
+  DBusConnection *connection;
43e61e
+  DBusPendingCall *pending;
43e61e
+  DBusMessage *message;
43e61e
+
43e61e
+  g_assert_cmpint (bus_type, <, G_N_ELEMENTS (dconf_libdbus_1_buses));
43e61e
+  connection = dconf_libdbus_1_buses[bus_type];
43e61e
+  g_assert (connection != NULL);
43e61e
+
43e61e
+  message = dconf_libdbus_1_new_method_call (bus_name, object_path, interface_name, method_name, parameters);
43e61e
+  dbus_connection_send_with_reply (connection, message, &pending, -1);
43e61e
+  dbus_pending_call_set_notify (pending, dconf_libdbus_1_method_call_done, handle, NULL);
43e61e
+  dbus_message_unref (message);
43e61e
+
43e61e
+  return TRUE;
43e61e
+}
43e61e
+
43e61e
+static void
43e61e
+dconf_libdbus_1_convert_error (DBusError  *dbus_error,
43e61e
+                               GError    **error)
43e61e
+{
43e61e
+  g_set_error (error, DCONF_LIBDBUS_1_ERROR, DCONF_LIBDBUS_1_ERROR_FAILED,
43e61e
+               "%s: %s", dbus_error->name, dbus_error->message);
43e61e
+}
43e61e
+
43e61e
+GVariant *
43e61e
+dconf_engine_dbus_call_sync_func (GBusType             bus_type,
43e61e
+                                  const gchar         *bus_name,
43e61e
+                                  const gchar         *object_path,
43e61e
+                                  const gchar         *interface_name,
43e61e
+                                  const gchar         *method_name,
43e61e
+                                  GVariant            *parameters,
43e61e
+                                  const GVariantType  *expected_type,
43e61e
+                                  GError             **error)
43e61e
+{
43e61e
+  DBusConnection *connection;
43e61e
+  DBusMessage *message;
43e61e
+  DBusError dbus_error;
43e61e
+  DBusMessage *result;
43e61e
+  GVariant *reply;
43e61e
+
43e61e
+  g_assert_cmpint (bus_type, <, G_N_ELEMENTS (dconf_libdbus_1_buses));
43e61e
+  connection = dconf_libdbus_1_buses[bus_type];
43e61e
+  g_assert (connection != NULL);
43e61e
+
43e61e
+  dbus_error_init (&dbus_error);
43e61e
+  message = dconf_libdbus_1_new_method_call (bus_name, object_path, interface_name, method_name, parameters);
43e61e
+  result = dbus_connection_send_with_reply_and_block (connection, message, -1, &dbus_error);
43e61e
+  dbus_message_unref (message);
43e61e
+
43e61e
+  if (result == NULL)
43e61e
+    {
43e61e
+      dconf_libdbus_1_convert_error (&dbus_error, error);
43e61e
+      dbus_error_free (&dbus_error);
43e61e
+      return NULL;
43e61e
+    }
43e61e
+
43e61e
+  reply = dconf_libdbus_1_interpret_result (result, expected_type, error);
43e61e
+  dbus_message_unref (result);
43e61e
+
43e61e
+  return reply;
43e61e
+}
43e61e
+
43e61e
+static DBusHandlerResult
43e61e
+dconf_libdbus_1_filter (DBusConnection *connection,
43e61e
+                        DBusMessage    *message,
43e61e
+                        gpointer        user_data)
43e61e
+{
43e61e
+  GBusType bus_type = GPOINTER_TO_INT (user_data);
43e61e
+
43e61e
+  if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_SIGNAL)
43e61e
+    {
43e61e
+      const gchar *interface;
43e61e
+
43e61e
+      interface = dbus_message_get_interface (message);
43e61e
+
43e61e
+      if (interface && g_str_equal (interface, "ca.desrt.dconf.Writer"))
43e61e
+        {
43e61e
+          GVariant *parameters;
43e61e
+
43e61e
+          parameters = dconf_libdbus_1_get_message_body (message, NULL);
43e61e
+
43e61e
+          if (parameters != NULL)
43e61e
+            {
43e61e
+              dconf_engine_handle_dbus_signal (bus_type,
43e61e
+                                               dbus_message_get_sender (message),
43e61e
+                                               dbus_message_get_path (message),
43e61e
+                                               dbus_message_get_member (message),
43e61e
+                                               parameters);
43e61e
+              g_variant_unref (parameters);
43e61e
+            }
43e61e
+        }
43e61e
+    }
43e61e
+
43e61e
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
43e61e
+}
43e61e
+
43e61e
+void
43e61e
+dconf_libdbus_1_provide_bus (GBusType        bus_type,
43e61e
+                             DBusConnection *connection)
43e61e
+{
43e61e
+  g_assert_cmpint (bus_type, <, G_N_ELEMENTS (dconf_libdbus_1_buses));
43e61e
+
43e61e
+  if (!dconf_libdbus_1_buses[bus_type])
43e61e
+    {
43e61e
+      dconf_libdbus_1_buses[bus_type] = dbus_connection_ref (connection);
43e61e
+      dbus_connection_add_filter (connection, dconf_libdbus_1_filter, GINT_TO_POINTER (bus_type), NULL);
43e61e
+    }
43e61e
+}
43e61e
+
43e61e
+#ifndef PIC
43e61e
+static gboolean
43e61e
+dconf_libdbus_1_check_connection (gpointer user_data)
43e61e
+{
43e61e
+  DBusConnection *connection = user_data;
43e61e
+
43e61e
+  dbus_connection_read_write (connection, 0);
43e61e
+  dbus_connection_dispatch (connection);
43e61e
+
43e61e
+  return G_SOURCE_CONTINUE;
43e61e
+}
43e61e
+
43e61e
+void
43e61e
+dconf_engine_dbus_init_for_testing (void)
43e61e
+{
43e61e
+  DBusConnection *session;
43e61e
+  DBusConnection *system;
43e61e
+
43e61e
+  dconf_libdbus_1_provide_bus (G_BUS_TYPE_SESSION, session = dbus_bus_get (DBUS_BUS_SESSION, NULL));
43e61e
+  dconf_libdbus_1_provide_bus (G_BUS_TYPE_SYSTEM, system = dbus_bus_get (DBUS_BUS_SYSTEM, NULL));
43e61e
+
43e61e
+  /* "mainloop integration" */
43e61e
+  g_timeout_add (1, dconf_libdbus_1_check_connection, session);
43e61e
+  g_timeout_add (1, dconf_libdbus_1_check_connection, system);
43e61e
+}
43e61e
+#endif
43e61e
--- /dev/null
43e61e
+++ b/dbus-1/dconf-libdbus-1.h
43e61e
@@ -0,0 +1,11 @@
43e61e
+#ifndef __dconf_libdbus_1_h__
43e61e
+#define __dconf_libdbus_1_h__
43e61e
+
43e61e
+#include <dbus/dbus.h>
43e61e
+#include <gio/gio.h>
43e61e
+
43e61e
+G_GNUC_INTERNAL
43e61e
+void                    dconf_libdbus_1_provide_bus                     (GBusType        bus_type,
43e61e
+                                                                         DBusConnection *connection);
43e61e
+
43e61e
+#endif /* __dconf_libdbus_1_h__ */
43e61e
--- a/tests/meson.build
43e61e
+++ b/tests/meson.build
43e61e
@@ -23,6 +23,7 @@ unit_tests = [
43e61e
   ['gvdb', 'gvdb.c', '-DSRCDIR="@0@"'.format(test_dir), glib_dep, libgvdb],
43e61e
   ['gdbus-thread', 'dbus.c', '-DDBUS_BACKEND="/gdbus/thread"', gio_unix_dep, libdconf_gdbus_thread],
43e61e
   ['gdbus-filter', 'dbus.c', '-DDBUS_BACKEND="/gdbus/filter"', gio_unix_dep, libdconf_gdbus_filter],
43e61e
+  ['libdbus-1', 'dbus.c', '-DDBUS_BACKEND="/libdbus-1"', gio_unix_dep, libdconf_libdbus_1],
43e61e
   ['engine', 'engine.c', '-DSRCDIR="@0@"'.format(test_dir), [glib_dep, dl_dep, m_dep], [libdconf_engine, libdconf_common, libdconf_mock]],
43e61e
   ['client', 'client.c', '-DSRCDIR="@0@"'.format(test_dir), gio_unix_dep, [libdconf_client, libdconf_engine, libdconf_common, libdconf_mock]]
43e61e
 ]