[gvfs/gdbus: 2/17] gdbus: Port GVfs side of proxy volume monitor



commit 0f126d3f1f02769997668a8523639f83b72d8c84
Author: Tomas Bzatek <tbzatek redhat com>
Date:   Wed Oct 26 18:43:36 2011 +0200

    gdbus: Port GVfs side of proxy volume monitor
    
    Still few things to do:
     * wrong error passing (G_IO_ERROR_FAILED_HANDLED getting ignored)
    
     * add proper locking, review existing code to be thread-safe
    
     * enabled debug prints by default for the moment

 monitor/proxy/Makefile.am                    |    2 -
 monitor/proxy/dbus-interfaces.xml            |   30 +-
 monitor/proxy/gvfsproxyvolumemonitordaemon.c | 1492 +++++++++++---------------
 3 files changed, 641 insertions(+), 883 deletions(-)
---
diff --git a/monitor/proxy/Makefile.am b/monitor/proxy/Makefile.am
index 087b2a9..6985cd4 100644
--- a/monitor/proxy/Makefile.am
+++ b/monitor/proxy/Makefile.am
@@ -63,7 +63,6 @@ libgvfsproxyvolumemonitordaemon_noin_la_SOURCES =		\
 libgvfsproxyvolumemonitordaemon_noin_la_CFLAGS =		\
 	-I$(top_srcdir)/common                  		\
 	$(GLIB_CFLAGS)                          		\
-	$(DBUS_CFLAGS)                          		\
 	$(GDU_CFLAGS)                           		\
 	-DG_LOG_DOMAIN=\"GVFS-RemoteVolumeMonitorDaemon\"	\
 	-DGVFS_LOCALEDIR=\""$(localedir)"\"			\
@@ -71,7 +70,6 @@ libgvfsproxyvolumemonitordaemon_noin_la_CFLAGS =		\
 
 libgvfsproxyvolumemonitordaemon_noin_la_LIBADD  =     		\
 	$(GLIB_LIBS)                                 		\
-	$(DBUS_LIBS)                                 		\
 	$(top_builddir)/common/libgvfscommon.la 		\
 	$(NULL)
 
diff --git a/monitor/proxy/dbus-interfaces.xml b/monitor/proxy/dbus-interfaces.xml
index 3e517d6..90e9e3a 100644
--- a/monitor/proxy/dbus-interfaces.xml
+++ b/monitor/proxy/dbus-interfaces.xml
@@ -30,62 +30,62 @@
     <signal name="DriveChanged">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssbbbbbbbbuasa{ss})' name='Drive'/>
+      <arg type='(sssbbbbbbbbuasa{ss}sa{sv})' name='Drive'/>
     </signal>
     <signal name="DriveConnected">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssbbbbbbbbuasa{ss})' name='Drive'/>
+      <arg type='(sssbbbbbbbbuasa{ss}sa{sv})' name='Drive'/>
     </signal>
     <signal name="DriveDisconnected">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssbbbbbbbbuasa{ss})' name='Drive'/> 
+      <arg type='(sssbbbbbbbbuasa{ss}sa{sv})' name='Drive'/> 
     </signal>
     <signal name="DriveEjectButton">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssbbbbbbbbuasa{ss})' name='Drive'/>
+      <arg type='(sssbbbbbbbbuasa{ss}sa{sv})' name='Drive'/>
     </signal>
     <signal name="DriveStopButton">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssbbbbbbbbuasa{ss})' name='Drive'/> 
+      <arg type='(sssbbbbbbbbuasa{ss}sa{sv})' name='Drive'/> 
     </signal>
     <signal name="VolumeChanged">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbbssa{ss})' name='Volume'/>
+      <arg type='(sssssbbssa{ss}sa{sv})' name='Volume'/>
     </signal>
     <signal name="VolumeAdded">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbbssa{ss})' name='Volume'/>
+      <arg type='(sssssbbssa{ss}sa{sv})' name='Volume'/>
     </signal>
     <signal name="VolumeRemoved">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbbssa{ss})' name='Volume'/>
+      <arg type='(sssssbbssa{ss}sa{sv})' name='Volume'/>
     </signal>
     <signal name="MountChanged">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbsas)' name='Mount'/>
+      <arg type='(sssssbsassa{sv})' name='Mount'/>
     </signal>
     <signal name="MountAdded">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbsas)' name='Mount'/>
+      <arg type='(sssssbsassa{sv})' name='Mount'/>
     </signal>
     <signal name="MountPreUnmount">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbsas)' name='Mount'/> 
+      <arg type='(sssssbsassa{sv})' name='Mount'/> 
     </signal>
     <signal name="MountRemoved">
       <arg type='s' name='TheDBusName'/>
       <arg type='s' name='Id'/>
-      <arg type='(sssssbsas)' name='Mount'/> 
+      <arg type='(sssssbsassa{sv})' name='Mount'/> 
     </signal>
     <method name="MountOpAskPassword">
       <arg type='s' name='TheDBusName' direction='in'/>
@@ -119,9 +119,9 @@
       <arg type='b' name='IsSupported' direction='out'/>
     </method>
     <method name="List">
-      <arg type='a(sssbbbbbbbbuasa{ss})' name='Drives' direction='out'/>
-      <arg type='a(sssssbbssa{ss})' name='Volumes' direction='out'/>
-      <arg type='a(sssssbsas)' name='Mounts' direction='out'/>
+      <arg type='a(sssbbbbbbbbuasa{ss}sa{sv})' name='Drives' direction='out'/>
+      <arg type='a(sssssbbssa{ss}sa{sv})' name='Volumes' direction='out'/>
+      <arg type='a(sssssbsassa{sv})' name='Mounts' direction='out'/>
     </method>
     <method name="CancelOperation">
       <arg type='s' name='CancellationId' direction='in'/>
diff --git a/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
index fe2f1a7..33eeae5 100644
--- a/monitor/proxy/gvfsproxyvolumemonitordaemon.c
+++ b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
@@ -25,25 +25,26 @@
 #include <string.h>
 #include <locale.h>
 #include <gio/gio.h>
-#include <dbus/dbus.h>
 #include <glib/gi18n.h>
 #include <stdlib.h>
 #include <glib/gprintf.h>
 
-#include "gvfsdbusutils.h"
 #include "gvfsproxyvolumemonitordaemon.h"
+#include "gvfsvolumemonitordbus.h"
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static GMainLoop *loop = NULL;
 static GVolumeMonitor *monitor = NULL;
-static DBusConnection *connection = NULL;
 static GType the_volume_monitor_type;
 static const char *the_dbus_name = NULL;
 static GList *outstanding_ops = NULL;
 static GList *outstanding_mount_op_objects = NULL;
 static GHashTable *unique_names_being_watched = NULL;
 
-/* #define DEBUG_ENABLED */
+static GVfsRemoteVolumeMonitor *monitor_daemon = NULL;
+
+#define DEBUG_ENABLED
 
 #ifdef DEBUG_ENABLED
 static void
@@ -135,6 +136,36 @@ g_proxy_mount_operation_class_init (GProxyMountOperationClass *klass)
   mount_op_class->show_processes = g_proxy_mount_operation_show_processes;
 }
 
+
+static gboolean
+create_proxy (const gchar *mount_op_owner, GVfsRemoteVolumeMonitor **proxy)
+{
+  GError *error = NULL;
+
+  *proxy = gvfs_remote_volume_monitor_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                              G_DBUS_PROXY_FLAGS_NONE,
+                                                              mount_op_owner,
+                                                              "/org/gtk/Private/RemoteVolumeMonitor",
+                                                              NULL,
+                                                              &error);
+  if (*proxy == NULL)
+    {
+      g_printerr ("Error creating proxy: %s (%s, %d)\n",
+                  error->message, g_quark_to_string (error->domain), error->code);
+      g_error_free (error);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+static void
+ask_password_cb_cb (GVfsRemoteVolumeMonitor *proxy, GAsyncResult *res, gpointer user_data)
+{
+  print_debug ("in ask_password_cb_cb");
+  gvfs_remote_volume_monitor_call_mount_op_ask_password_finish (proxy, res, NULL);
+}
+
 static void
 ask_password_cb (GMountOperation  *mount_operation,
                  const gchar      *message_to_show,
@@ -143,23 +174,17 @@ ask_password_cb (GMountOperation  *mount_operation,
                  GAskPasswordFlags flags,
                  gpointer          user_data)
 {
-  DBusMessage *message;
-  DBusMessageIter iter;
   const gchar *mount_op_id;
   const gchar *mount_op_owner;
+  GVfsRemoteVolumeMonitor *proxy;
 
   print_debug ("in ask_password_cb %s", message_to_show);
 
   mount_op_id = g_object_get_data (G_OBJECT (mount_operation), "mount_op_id");
   mount_op_owner = g_object_get_data (G_OBJECT (mount_operation), "mount_op_owner");
 
-  message = dbus_message_new_method_call (mount_op_owner,
-                                          "/org/gtk/Private/RemoteVolumeMonitor",
-                                          "org.gtk.Private.RemoteVolumeMonitor",
-                                          "MountOpAskPassword");
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &mount_op_id);
+  if (!create_proxy (mount_op_owner, &proxy))
+    return;
 
   if (message_to_show == NULL)
     message_to_show = "";
@@ -170,13 +195,24 @@ ask_password_cb (GMountOperation  *mount_operation,
   if (default_domain == NULL)
     default_domain = "";
 
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &message_to_show);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &default_user);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &default_domain);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags);
+  gvfs_remote_volume_monitor_call_mount_op_ask_password (proxy,
+                                                         the_dbus_name,
+                                                         mount_op_id,
+                                                         message_to_show,
+                                                         default_user,
+                                                         default_domain,
+                                                         flags,
+                                                         NULL,
+                                                         (GAsyncReadyCallback) ask_password_cb_cb,
+                                                         NULL);
+  g_object_unref (proxy);
+}
 
-  dbus_connection_send (connection, message, NULL);
-  dbus_message_unref (message);
+static void
+ask_question_cb_cb (GVfsRemoteVolumeMonitor *proxy, GAsyncResult *res, gpointer user_data)
+{
+  print_debug ("in ask_question_cb_cb");
+  gvfs_remote_volume_monitor_call_mount_op_ask_question_finish (proxy, res, NULL);
 }
 
 static void
@@ -185,38 +221,37 @@ ask_question_cb (GMountOperation  *mount_operation,
                  gchar           **choices,
                  gpointer          user_data)
 {
-  DBusMessage *message;
-  DBusMessageIter iter;
-  DBusMessageIter iter_string_array;
   const gchar *mount_op_id;
   const gchar *mount_op_owner;
-  guint n;
+  GVfsRemoteVolumeMonitor *proxy;
 
   print_debug ("in ask_question_cb %s", message_to_show);
 
   mount_op_id = g_object_get_data (G_OBJECT (mount_operation), "mount_op_id");
   mount_op_owner = g_object_get_data (G_OBJECT (mount_operation), "mount_op_owner");
 
-  message = dbus_message_new_method_call (mount_op_owner,
-                                          "/org/gtk/Private/RemoteVolumeMonitor",
-                                          "org.gtk.Private.RemoteVolumeMonitor",
-                                          "MountOpAskQuestion");
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &mount_op_id);
-
+  if (!create_proxy (mount_op_owner, &proxy))
+    return;
+  
   if (message_to_show == NULL)
     message_to_show = "";
 
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &message_to_show);
-
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_string_array);
-  for (n = 0; choices != NULL && choices[n] != NULL; n++)
-    dbus_message_iter_append_basic (&iter_string_array, DBUS_TYPE_STRING, &(choices[n]));
-  dbus_message_iter_close_container (&iter, &iter_string_array);
+  gvfs_remote_volume_monitor_call_mount_op_ask_question (proxy,
+                                                         the_dbus_name,
+                                                         mount_op_id,
+                                                         message_to_show,
+                                                         (const gchar *const *) choices,
+                                                         NULL,
+                                                         (GAsyncReadyCallback) ask_question_cb_cb,
+                                                         NULL);
+  g_object_unref (proxy);
+}
 
-  dbus_connection_send (connection, message, NULL);
-  dbus_message_unref (message);
+static void
+show_processes_cb_cb (GVfsRemoteVolumeMonitor *proxy, GAsyncResult *res, gpointer user_data)
+{
+  print_debug ("in show_processes_cb_cb");
+  gvfs_remote_volume_monitor_call_mount_op_aborted_finish (proxy, res, NULL);
 }
 
 static void
@@ -226,73 +261,77 @@ show_processes_cb (GMountOperation  *mount_operation,
                    gchar           **choices,
                    gpointer          user_data)
 {
-  DBusMessage *message;
-  DBusMessageIter iter;
-  DBusMessageIter iter_string_array;
   const gchar *mount_op_id;
   const gchar *mount_op_owner;
   guint n;
+  GVariantBuilder *pids;
+  GVfsRemoteVolumeMonitor *proxy;
 
   print_debug ("in show_processes_cb %s", message_to_show);
 
   mount_op_id = g_object_get_data (G_OBJECT (mount_operation), "mount_op_id");
   mount_op_owner = g_object_get_data (G_OBJECT (mount_operation), "mount_op_owner");
 
-  message = dbus_message_new_method_call (mount_op_owner,
-                                          "/org/gtk/Private/RemoteVolumeMonitor",
-                                          "org.gtk.Private.RemoteVolumeMonitor",
-                                          "MountOpShowProcesses");
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &mount_op_id);
+  print_debug ("  owner =  '%s'", mount_op_owner);
+
+  if (!create_proxy (mount_op_owner, &proxy))
+    return;
 
   if (message_to_show == NULL)
     message_to_show = "";
 
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &message_to_show);
-
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &iter_string_array);
+  pids = g_variant_builder_new (G_VARIANT_TYPE ("ai"));
   for (n = 0; processes != NULL && n < processes->len; n++)
     {
       GPid pid;
       pid = g_array_index (processes, GPid, n);
-      dbus_message_iter_append_basic (&iter_string_array, DBUS_TYPE_INT32, &pid);
-    }
-  dbus_message_iter_close_container (&iter, &iter_string_array);
+      g_variant_builder_add (pids, "i", pid);
+    }
+ 
+  gvfs_remote_volume_monitor_call_mount_op_show_processes (proxy,
+                                                           the_dbus_name,
+                                                           mount_op_id,
+                                                           message_to_show,
+                                                           g_variant_builder_end (pids),
+                                                           (const gchar *const *) choices,
+                                                           NULL,
+                                                           (GAsyncReadyCallback) show_processes_cb_cb,
+                                                           NULL);
+  g_variant_builder_unref (pids);
+  g_object_unref (proxy);
+}
 
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_string_array);
-  for (n = 0; choices != NULL && choices[n] != NULL; n++)
-    dbus_message_iter_append_basic (&iter_string_array, DBUS_TYPE_STRING, &(choices[n]));
-  dbus_message_iter_close_container (&iter, &iter_string_array);
 
-  dbus_connection_send (connection, message, NULL);
-  dbus_message_unref (message);
+static void
+aborted_cb_cb (GVfsRemoteVolumeMonitor *proxy, GAsyncResult *res, gpointer user_data)
+{
+  print_debug ("in aborted_cb_cb");
+  gvfs_remote_volume_monitor_call_mount_op_aborted_finish (proxy, res, NULL);
 }
 
 static void
 aborted_cb (GMountOperation  *mount_operation,
             gpointer          user_data)
 {
-  DBusMessage *message;
-  DBusMessageIter iter;
   const gchar *mount_op_id;
   const gchar *mount_op_owner;
-
+  GVfsRemoteVolumeMonitor *proxy;
+  
   print_debug ("in aborted_cb");
 
   mount_op_id = g_object_get_data (G_OBJECT (mount_operation), "mount_op_id");
   mount_op_owner = g_object_get_data (G_OBJECT (mount_operation), "mount_op_owner");
 
-  message = dbus_message_new_method_call (mount_op_owner,
-                                          "/org/gtk/Private/RemoteVolumeMonitor",
-                                          "org.gtk.Private.RemoteVolumeMonitor",
-                                          "MountOpAborted");
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &mount_op_id);
+  if (!create_proxy (mount_op_owner, &proxy))
+    return;
 
-  dbus_connection_send (connection, message, NULL);
-  dbus_message_unref (message);
+  gvfs_remote_volume_monitor_call_mount_op_aborted (proxy,
+                                                    the_dbus_name,
+                                                    mount_op_id,
+                                                    NULL,
+                                                    (GAsyncReadyCallback) aborted_cb_cb,
+                                                    NULL);
+  g_object_unref (proxy);
 }
 
 static void
@@ -336,61 +375,79 @@ cancellable_destroyed_cb (gpointer user_data,
 }
 
 static void
-remove_name_owned_changed_for_unique_name (const gchar *unique_name)
+on_name_owner_vanished (GDBusConnection *connection,
+                        const gchar     *name,
+                        gpointer         user_data)
 {
-  const gchar *match_rule;
-  DBusError dbus_error;
+  GList *l;
+  gulong name_watcher_id;
+  
+  print_debug ("Name owner '%s' vanished", name);
 
-  match_rule = g_hash_table_lookup (unique_names_being_watched, unique_name);
-  if (match_rule == NULL)
+  /* if @name has outstanding mount operation objects; abort them */
+  for (l = outstanding_mount_op_objects; l != NULL; l = l->next)
     {
-      g_warning ("Was asked to remove match rule for unique_name %s but we don't have one", unique_name);
-      goto out;
+      GMountOperation *op = G_MOUNT_OPERATION (l->data);
+      const gchar *owner;
+
+      owner = g_object_get_data (G_OBJECT (op), "mount_op_owner");
+      if (g_strcmp0 (owner, name) == 0)
+        {
+          print_debug ("****** name `%s' has an outstanding mount operation object, aborting it",
+                       name);
+          g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
+        }
     }
 
-  dbus_error_init (&dbus_error);
-  dbus_bus_remove_match (connection,
-                         match_rule,
-                         &dbus_error);
-  if (dbus_error_is_set (&dbus_error)) {
-    g_warning ("cannot remove match rule '%s': %s: %s", match_rule, dbus_error.name, dbus_error.message);
-    dbus_error_free (&dbus_error);
-  }
+  /* see if @name has outstanding ops; if so, cancel them */
+  for (l = outstanding_ops; l != NULL; l = l->next)
+    {
+      GCancellable *cancellable = G_CANCELLABLE (l->data);
+      const gchar *owner;
 
-  g_hash_table_remove (unique_names_being_watched, unique_name);
+      owner = g_object_get_data (G_OBJECT (cancellable), "owner");
+      print_debug ("looking at op for %s", owner);
+      if (g_strcmp0 (owner, name) == 0)
+        {
+          print_debug ("****** name `%s' has an outstanding op, cancelling it",
+                       name);
+          g_cancellable_cancel (cancellable);
+        }
+    }
 
- out:
-  ;
+  /* unwatch the name */
+  name_watcher_id = (gulong) g_hash_table_lookup (unique_names_being_watched, name);
+  if (name_watcher_id == 0)
+    {
+      g_warning ("Was asked to remove match rule for unique_name %s but we don't have one", name);
+    }
+  else
+    {
+      g_bus_unwatch_name (name_watcher_id - 1);
+    }
+
+  g_hash_table_remove (unique_names_being_watched, name);
 }
 
 static void
-ensure_name_owner_changed_for_unique_name (const gchar *unique_name)
+ensure_name_owner_changed_for_unique_name (GDBusMethodInvocation *invocation)
 {
-  gchar *match_rule;
-  DBusError dbus_error;
+  gulong name_watcher_id;
+  const gchar *unique_name;
+  
+  unique_name = g_dbus_method_invocation_get_sender (invocation);
 
   if (g_hash_table_lookup (unique_names_being_watched, unique_name) != NULL)
     goto out;
-
-  match_rule = g_strdup_printf ("type='signal',"
-                                "interface='org.freedesktop.DBus',"
-                                "member='NameOwnerChanged',"
-                                "arg0='%s'",
-                                unique_name);
-
-  dbus_error_init (&dbus_error);
-  dbus_bus_add_match (connection,
-                      match_rule,
-                      &dbus_error);
-  if (dbus_error_is_set (&dbus_error))
-    {
-      g_warning ("cannot add match rule '%s': %s: %s", match_rule, dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      g_free (match_rule);
-      goto out;
-    }
-
-  g_hash_table_insert (unique_names_being_watched, g_strdup (unique_name), match_rule);
+  
+  name_watcher_id = g_bus_watch_name_on_connection (g_dbus_method_invocation_get_connection (invocation),
+                                                    unique_name,
+                                                    G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                                    NULL, /* name_appeared_handler */
+                                                    on_name_owner_vanished,
+                                                    NULL,
+                                                    NULL);
+  g_hash_table_insert (unique_names_being_watched, g_strdup (unique_name), (gpointer) (name_watcher_id + 1));
 
  out:
   ;
@@ -417,12 +474,9 @@ static void monitor_try_create (void);
  */
 #define DRIVE_STRUCT_TYPE "(sssbbbbbbbbuasa{ss}sa{sv})"
 
-static void
-append_drive (GDrive *drive, DBusMessageIter *iter_array)
+static GVariant *
+append_drive (GDrive *drive)
 {
-  DBusMessageIter iter_struct;
-  DBusMessageIter iter_volume_array;
-  DBusMessageIter iter_identifiers;
   char *id;
   char *name;
   GIcon *icon;
@@ -440,9 +494,11 @@ append_drive (GDrive *drive, DBusMessageIter *iter_array)
   char **identifiers;
   int n;
   const gchar *sort_key;
-  DBusMessageIter iter_expansion;
+  GVariant *result;
+  GVariantBuilder *volume_array_builder;
+  GVariantBuilder *identifiers_builder;
+  GVariantBuilder *expansion_builder;
 
-  dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
 
   id = g_strdup_printf ("%p", drive);
   name = g_drive_get_name (drive);
@@ -470,51 +526,63 @@ append_drive (GDrive *drive, DBusMessageIter *iter_array)
   if (sort_key == NULL)
     sort_key = "";
 
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_eject);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_poll_for_media);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &has_media);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &is_media_removable);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &is_media_check_automatic);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_start);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_start_degraded);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_stop);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &start_stop_type);
-
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_volume_array);
+  volume_array_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
   for (l = volumes; l != NULL; l = l->next)
     {
       GVolume *volume = G_VOLUME (l->data);
       char *volume_id;
       volume_id = g_strdup_printf ("%p", volume);
-      dbus_message_iter_append_basic (&iter_volume_array, DBUS_TYPE_STRING, &volume_id);
+      g_variant_builder_add (volume_array_builder, "s", volume_id);
       g_free (volume_id);
     }
-  dbus_message_iter_close_container (&iter_struct, &iter_volume_array);
 
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{ss}", &iter_identifiers);
+  identifiers_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{ss}"));
   for (n = 0; identifiers != NULL && identifiers[n] != NULL; n++)
     {
-      DBusMessageIter iter_dict_entry;
       char *id_value;
       id_value = g_drive_get_identifier (drive, identifiers[n]);
-      dbus_message_iter_open_container (&iter_identifiers,
-                                        DBUS_TYPE_DICT_ENTRY,
-                                        NULL,
-                                        &iter_dict_entry);
-      dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &(identifiers[n]));
-      dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &id_value);
-      dbus_message_iter_close_container (&iter_identifiers, &iter_dict_entry);
+
+      g_variant_builder_add (identifiers_builder, "{ss}",
+                             identifiers[n],
+                             id_value);
       g_free (id_value);
     }
-  dbus_message_iter_close_container (&iter_struct, &iter_identifiers);
 
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &sort_key);
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_expansion);
+  expansion_builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
   /* left for future expansion without ABI breaks */
-  dbus_message_iter_close_container (&iter_struct, &iter_expansion);
+
+  for (n = 0; identifiers != NULL && identifiers[n] != NULL; n++)
+    {
+      char *id_value;
+      id_value = g_drive_get_identifier (drive, identifiers[n]);
+
+      g_variant_builder_add (identifiers_builder, "{ss}",
+                             identifiers[n],
+                             id_value);
+      g_free (id_value);
+    }
+
+  result = g_variant_new (DRIVE_STRUCT_TYPE,
+                          id,
+                          name,
+                          icon_data,
+                          can_eject,
+                          can_poll_for_media,
+                          has_media,
+                          is_media_removable,
+                          is_media_check_automatic,
+                          can_start,
+                          can_start_degraded,
+                          can_stop,
+                          start_stop_type,
+                          volume_array_builder,
+                          identifiers_builder,
+                          sort_key,
+                          expansion_builder);
+
+  g_variant_builder_unref (volume_array_builder);
+  g_variant_builder_unref (identifiers_builder);
+  g_variant_builder_unref (expansion_builder);
 
   g_strfreev (identifiers);
   g_list_foreach (volumes, (GFunc) g_object_unref, NULL);
@@ -524,7 +592,7 @@ append_drive (GDrive *drive, DBusMessageIter *iter_array)
   g_free (name);
   g_free (id);
 
-  dbus_message_iter_close_container (iter_array, &iter_struct);
+  return result;
 }
 
 /* string               id
@@ -542,11 +610,9 @@ append_drive (GDrive *drive, DBusMessageIter *iter_array)
  */
 #define VOLUME_STRUCT_TYPE "(sssssbbssa{ss}sa{sv})"
 
-static void
-append_volume (GVolume *volume, DBusMessageIter *iter_array)
+static GVariant *
+append_volume (GVolume *volume)
 {
-  DBusMessageIter iter_struct;
-  DBusMessageIter iter_identifiers;
   char *id;
   char *name;
   GIcon *icon;
@@ -563,9 +629,10 @@ append_volume (GVolume *volume, DBusMessageIter *iter_array)
   char **identifiers;
   int n;
   const gchar *sort_key;
-  DBusMessageIter iter_expansion;
+  GVariant *result;
+  GVariantBuilder *identifiers_builder;
+  GVariantBuilder *expansion_builder;
 
-  dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
 
   id = g_strdup_printf ("%p", volume);
   name = g_volume_get_name (volume);
@@ -603,39 +670,39 @@ append_volume (GVolume *volume, DBusMessageIter *iter_array)
   if (sort_key == NULL)
     sort_key = "";
 
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &uuid);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &activation_uri);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_mount);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &should_automount);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &drive_id);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &mount_id);
-
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{ss}", &iter_identifiers);
+  identifiers_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{ss}"));
   for (n = 0; identifiers != NULL && identifiers[n] != NULL; n++)
     {
-      DBusMessageIter iter_dict_entry;
       char *id_value;
       id_value = g_volume_get_identifier (volume, identifiers[n]);
       if (id_value == NULL)
         continue;
-      dbus_message_iter_open_container (&iter_identifiers,
-                                        DBUS_TYPE_DICT_ENTRY,
-                                        NULL,
-                                        &iter_dict_entry);
-      dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &(identifiers[n]));
-      dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &id_value);
-      dbus_message_iter_close_container (&iter_identifiers, &iter_dict_entry);
+
+      g_variant_builder_add (identifiers_builder, "{ss}",
+                             identifiers[n],
+                             id_value);
       g_free (id_value);
     }
-  dbus_message_iter_close_container (&iter_struct, &iter_identifiers);
 
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &sort_key);
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_expansion);
+  expansion_builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
   /* left for future expansion without ABI breaks */
-  dbus_message_iter_close_container (&iter_struct, &iter_expansion);
+
+  result = g_variant_new (VOLUME_STRUCT_TYPE,
+                          id,
+                          name,
+                          icon_data,
+                          uuid,
+                          activation_uri,
+                          can_mount,
+                          should_automount,
+                          drive_id,
+                          mount_id,
+                          identifiers_builder,
+                          sort_key,
+                          expansion_builder);
+
+  g_variant_builder_unref (identifiers_builder);
+  g_variant_builder_unref (expansion_builder);
 
   g_strfreev (identifiers);
   g_free (mount_id);
@@ -653,7 +720,7 @@ append_volume (GVolume *volume, DBusMessageIter *iter_array)
   g_free (name);
   g_free (id);
 
-  dbus_message_iter_close_container (iter_array, &iter_struct);
+  return result;
 }
 
 /* string               id
@@ -669,11 +736,9 @@ append_volume (GVolume *volume, DBusMessageIter *iter_array)
  */
 #define MOUNT_STRUCT_TYPE "(sssssbsassa{sv})"
 
-static void
-append_mount (GMount *mount, DBusMessageIter *iter_array)
+static GVariant *
+append_mount (GMount *mount)
 {
-  DBusMessageIter iter_struct;
-  DBusMessageIter iter_x_content_types_array;
   char *id;
   char *name;
   GIcon *icon;
@@ -687,9 +752,9 @@ append_mount (GMount *mount, DBusMessageIter *iter_array)
   char **x_content_types;
   int n;
   const gchar *sort_key;
-  DBusMessageIter iter_expansion;
-
-  dbus_message_iter_open_container (iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
+  GVariant *result;
+  GVariantBuilder *x_content_types_array_builder;
+  GVariantBuilder *expansion_builder;
 
   id = g_strdup_printf ("%p", mount);
   name = g_mount_get_name (mount);
@@ -717,28 +782,31 @@ append_mount (GMount *mount, DBusMessageIter *iter_array)
   if (sort_key == NULL)
     sort_key = "";
 
-
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &id);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &icon_data);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &uuid);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &root_uri);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_BOOLEAN, &can_unmount);
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &volume_id);
-
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "s", &iter_x_content_types_array);
+  x_content_types_array_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
   x_content_types = (char **) g_object_get_data (G_OBJECT (mount), "x-content-types");
   if (x_content_types != NULL)
     {
       for (n = 0; x_content_types[n] != NULL; n++)
-        dbus_message_iter_append_basic (&iter_x_content_types_array, DBUS_TYPE_STRING, &(x_content_types[n]));
+        g_variant_builder_add (x_content_types_array_builder, "s", x_content_types[n]);
     }
-  dbus_message_iter_close_container (&iter_struct, &iter_x_content_types_array);
 
-  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &sort_key);
-  dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_expansion);
+  expansion_builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT);
   /* left for future expansion without ABI breaks */
-  dbus_message_iter_close_container (&iter_struct, &iter_expansion);
+
+  result = g_variant_new (MOUNT_STRUCT_TYPE,
+                          id,
+                          name,
+                          icon_data,
+                          uuid,
+                          root_uri,
+                          can_unmount,
+                          volume_id,
+                          x_content_types_array_builder,
+                          sort_key,
+                          expansion_builder);
+
+  g_variant_builder_unref (x_content_types_array_builder);
+  g_variant_builder_unref (expansion_builder);
 
   g_free (volume_id);
   if (volume != NULL)
@@ -751,18 +819,20 @@ append_mount (GMount *mount, DBusMessageIter *iter_array)
   g_free (name);
   g_free (id);
 
-  dbus_message_iter_close_container (iter_array, &iter_struct);
+  return result;
 }
 
-static DBusHandlerResult
-handle_list (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_list (GVfsRemoteVolumeMonitor *object,
+             GDBusMethodInvocation *invocation)
 {
   GList *drives;
   GList *volumes;
   GList *mounts;
-  DBusMessageIter iter;
-  DBusMessageIter iter_array;
-  DBusMessage *reply;
+  GList *l;
+  GVariantBuilder *drives_array;
+  GVariantBuilder *volumes_array;
+  GVariantBuilder *mounts_array;
 
   print_debug ("in handle_list");
 
@@ -770,20 +840,15 @@ handle_list (DBusConnection *connection, DBusMessage *message)
   volumes = g_volume_monitor_get_volumes (monitor);
   mounts = g_volume_monitor_get_mounts (monitor);
 
-  reply = dbus_message_new_method_return (message);
-  dbus_message_iter_init_append (reply, &iter);
-
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DRIVE_STRUCT_TYPE, &iter_array);
-  g_list_foreach (drives, (GFunc) append_drive, &iter_array);
-  dbus_message_iter_close_container (&iter, &iter_array);
-
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, VOLUME_STRUCT_TYPE, &iter_array);
-  g_list_foreach (volumes, (GFunc) append_volume, &iter_array);
-  dbus_message_iter_close_container (&iter, &iter_array);
-
-  dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, MOUNT_STRUCT_TYPE, &iter_array);
-  g_list_foreach (mounts, (GFunc) append_mount, &iter_array);
-  dbus_message_iter_close_container (&iter, &iter_array);
+  drives_array = g_variant_builder_new (G_VARIANT_TYPE ("a" DRIVE_STRUCT_TYPE));
+  for (l = drives; l; l = l->next)
+    g_variant_builder_add_value (drives_array, append_drive (l->data));
+  volumes_array = g_variant_builder_new (G_VARIANT_TYPE ("a" VOLUME_STRUCT_TYPE));
+  for (l = volumes; l; l = l->next)
+    g_variant_builder_add_value (volumes_array, append_volume (l->data));
+  mounts_array = g_variant_builder_new (G_VARIANT_TYPE ("a" MOUNT_STRUCT_TYPE));
+  for (l = mounts; l; l = l->next)
+    g_variant_builder_add_value (mounts_array, append_mount (l->data));
 
   g_list_foreach (drives, (GFunc) g_object_unref, NULL);
   g_list_free (drives);
@@ -791,20 +856,25 @@ handle_list (DBusConnection *connection, DBusMessage *message)
   g_list_free (volumes);
   g_list_foreach (mounts, (GFunc) g_object_unref, NULL);
   g_list_free (mounts);
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (reply);
-
-  return DBUS_HANDLER_RESULT_HANDLED;
+  
+  gvfs_remote_volume_monitor_complete_list (object, invocation,
+                                            g_variant_builder_end (drives_array),
+                                            g_variant_builder_end (volumes_array),
+                                            g_variant_builder_end (mounts_array));
+  
+  g_variant_builder_unref (drives_array);
+  g_variant_builder_unref (volumes_array);
+  g_variant_builder_unref (mounts_array);
+  
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-mount_unmount_cb (GMount *mount, GAsyncResult *result, DBusMessage *message)
+mount_unmount_cb (GMount *mount, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in mount_unmount_cb");
 
@@ -815,59 +885,36 @@ mount_unmount_cb (GMount *mount, GAsyncResult *result, DBusMessage *message)
   if (!g_mount_unmount_with_operation_finish (mount, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_mount_unmount (NULL, invocation);
     }
 
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
-
   g_object_unref (mount);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_mount_unmount (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_mount_unmount (GVfsRemoteVolumeMonitor *object,
+                      GDBusMethodInvocation *invocation,
+                      const gchar *Id,
+                      const gchar *CancellationId,
+                      guint UnmountFlags,
+                      const gchar *MountOpId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
-  const char *mount_op_id;
   GCancellable *cancellable;
   GMountOperation *mount_operation;
-  dbus_uint32_t unmount_flags;
-  DBusError dbus_error;
   GList *mounts, *l;
   GMount *mount;
-  DBusHandlerResult ret;
-
-  mounts = NULL;
-  unmount_flags = 0;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_UINT32, &unmount_flags,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for MountUnmount(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
 
   print_debug ("in handle_mount_unmount");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   mount = NULL;
   mounts = g_volume_monitor_get_mounts (monitor);
@@ -877,7 +924,7 @@ handle_mount_unmount (DBusConnection *connection, DBusMessage *message)
 
       mount = G_MOUNT (l->data);
       mount_id = g_strdup_printf ("%p", mount);
-      if (strcmp (mount_id, id) == 0)
+      if (strcmp (mount_id, Id) == 0)
         break;
 
       g_free (mount_id);
@@ -887,49 +934,43 @@ handle_mount_unmount (DBusConnection *connection, DBusMessage *message)
 
   if (mount == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given mount was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given mount was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (mount), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (mount), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
                      NULL);
 
   mount_operation = NULL;
-  if (mount_op_id != NULL && strlen (mount_op_id) > 0)
+  if (MountOpId != NULL && strlen (MountOpId) > 0)
     {
-      mount_operation = wrap_mount_op (mount_op_id, sender);
+      mount_operation = wrap_mount_op (MountOpId, sender);
       g_object_set_data_full (G_OBJECT (mount), "mount_operation", mount_operation, g_object_unref);
     }
 
   g_object_ref (mount);
   g_mount_unmount_with_operation (mount,
-                                  unmount_flags,
+                                  UnmountFlags,
                                   mount_operation,
                                   cancellable,
                                   (GAsyncReadyCallback) mount_unmount_cb,
-                                  dbus_message_ref (message));
+                                  g_object_ref (invocation));
 
  out:
   if (mounts != NULL)
@@ -937,57 +978,33 @@ handle_mount_unmount (DBusConnection *connection, DBusMessage *message)
       g_list_foreach (mounts, (GFunc) g_object_unref, NULL);
       g_list_free (mounts);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static DBusHandlerResult
-handle_mount_op_reply (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_mount_op_reply (GVfsRemoteVolumeMonitor *object,
+                       GDBusMethodInvocation *invocation,
+                       const gchar *MountOpId,
+                       guint Result,
+                       const gchar *UserName,
+                       const gchar *Domain,
+                       const gchar *EncodedPassword,
+                       guint PasswordSave,
+                       guint Choice,
+                       gboolean Anonymous)
 {
-  const char *mount_op_id;
-  dbus_int32_t result;
-  const char *user_name;
-  const char *domain;
-  const char *encoded_password;
   char *decoded_password;
   gsize decoded_password_len;
-  dbus_int32_t password_save;
-  dbus_int32_t choice;
-  dbus_bool_t anonymous;
-  DBusError dbus_error;
-  DBusHandlerResult ret;
   GList *l;
-  DBusMessage *reply;
   GMountOperation *mount_operation;
   const gchar *sender;
 
-  decoded_password = NULL;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message,
-                              &dbus_error,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INT32, &result,
-                              DBUS_TYPE_STRING, &user_name,
-                              DBUS_TYPE_STRING, &domain,
-                              DBUS_TYPE_STRING, &encoded_password,
-                              DBUS_TYPE_INT32, &password_save,
-                              DBUS_TYPE_INT32, &choice,
-                              DBUS_TYPE_BOOLEAN, &anonymous,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for MountOpReply(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
-
   print_debug ("in handle_mount_op_reply");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  decoded_password = NULL;
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   /* Find the op */
   mount_operation = NULL;
@@ -1000,7 +1017,7 @@ handle_mount_op_reply (DBusConnection *connection, DBusMessage *message)
 
       owner = g_object_get_data (G_OBJECT (op), "mount_op_owner");
       id = g_object_get_data (G_OBJECT (op), "mount_op_id");
-      if (g_strcmp0 (owner, sender) == 0 && g_strcmp0 (id, mount_op_id) == 0)
+      if (g_strcmp0 (owner, sender) == 0 && g_strcmp0 (id, MountOpId) == 0)
         {
           print_debug ("found mount_op");
           mount_operation = op;
@@ -1010,42 +1027,36 @@ handle_mount_op_reply (DBusConnection *connection, DBusMessage *message)
 
   if (mount_operation == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "No outstanding mount operation");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "No outstanding mount operation");
       goto out;
     }
 
-  decoded_password = (gchar *) g_base64_decode (encoded_password, &decoded_password_len);
+  decoded_password = (gchar *) g_base64_decode (EncodedPassword, &decoded_password_len);
 
-  g_mount_operation_set_username (mount_operation, user_name);
-  g_mount_operation_set_domain (mount_operation, domain);
+  g_mount_operation_set_username (mount_operation, UserName);
+  g_mount_operation_set_domain (mount_operation, Domain);
   g_mount_operation_set_password (mount_operation, decoded_password);
-  g_mount_operation_set_password_save (mount_operation, password_save);
-  g_mount_operation_set_choice (mount_operation, choice);
-  g_mount_operation_set_anonymous (mount_operation, anonymous);
+  g_mount_operation_set_password_save (mount_operation, PasswordSave);
+  g_mount_operation_set_choice (mount_operation, Choice);
+  g_mount_operation_set_anonymous (mount_operation, Anonymous);
 
-  g_mount_operation_reply (mount_operation, result);
+  g_mount_operation_reply (mount_operation, Result);
 
-  reply = dbus_message_new_method_return (message);
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (reply);
+  gvfs_remote_volume_monitor_complete_mount_op_reply (object, invocation);
 
  out:
   g_free (decoded_password);
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-volume_mount_cb (GVolume *volume, GAsyncResult *result, DBusMessage *message)
+volume_mount_cb (GVolume *volume, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in volume_mount_cb");
 
@@ -1056,56 +1067,34 @@ volume_mount_cb (GVolume *volume, GAsyncResult *result, DBusMessage *message)
   if (!g_volume_mount_finish (volume, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_volume_mount (NULL, invocation);      
     }
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_volume_mount (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_volume_mount (GVfsRemoteVolumeMonitor *object,
+                     GDBusMethodInvocation *invocation,
+                     const gchar *Id,
+                     const gchar *CancellationId,
+                     guint MountFlags,
+                     const gchar *MountOpId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
-  dbus_uint32_t mount_flags;
-  const char *mount_op_id;
-  DBusError dbus_error;
   GList *volumes, *l;
   GVolume *volume;
-  DBusHandlerResult ret;
   GMountOperation *mount_operation;
   GCancellable *cancellable;
 
-  volumes = NULL;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_UINT32, &mount_flags,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for VolumeMount(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
-
   print_debug ("in handle_volume_mount");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   volume = NULL;
   volumes = g_volume_monitor_get_volumes (monitor);
@@ -1115,7 +1104,7 @@ handle_volume_mount (DBusConnection *connection, DBusMessage *message)
 
       volume = G_VOLUME (l->data);
       volume_id = g_strdup_printf ("%p", volume);
-      if (strcmp (volume_id, id) == 0)
+      if (strcmp (volume_id, Id) == 0)
         break;
 
       g_free (volume_id);
@@ -1125,48 +1114,42 @@ handle_volume_mount (DBusConnection *connection, DBusMessage *message)
 
   if (volume == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given volume was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given volume was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (volume), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   mount_operation = NULL;
-  if (mount_op_id != NULL && strlen (mount_op_id) > 0)
+  if (MountOpId != NULL && strlen (MountOpId) > 0)
     {
-      mount_operation = wrap_mount_op (mount_op_id, sender);
+      mount_operation = wrap_mount_op (MountOpId, sender);
       g_object_set_data_full (G_OBJECT (volume), "mount_operation", mount_operation, g_object_unref);
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (volume), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
                      NULL);
 
   g_volume_mount (volume,
-                  mount_flags,
+                  MountFlags,
                   mount_operation,
                   cancellable,
                   (GAsyncReadyCallback) volume_mount_cb,
-                  dbus_message_ref (message));
+                  g_object_ref (invocation));
 
  out:
   if (volumes != NULL)
@@ -1174,16 +1157,15 @@ handle_volume_mount (DBusConnection *connection, DBusMessage *message)
       g_list_foreach (volumes, (GFunc) g_object_unref, NULL);
       g_list_free (volumes);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-drive_eject_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
+drive_eject_cb (GDrive *drive, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in drive_eject_cb");
 
@@ -1194,58 +1176,34 @@ drive_eject_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
   if (!g_drive_eject_with_operation_finish (drive, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_drive_eject (NULL, invocation);
     }
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_drive_eject (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_drive_eject (GVfsRemoteVolumeMonitor *object,
+                    GDBusMethodInvocation *invocation,
+                    const gchar *Id,
+                    const gchar *CancellationId,
+                    guint UnmountFlags,
+                    const gchar *MountOpId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
-  const char *mount_op_id;
   GMountOperation *mount_operation;
   GCancellable *cancellable;
-  dbus_uint32_t unmount_flags;
-  DBusError dbus_error;
   GList *drives, *l;
   GDrive *drive;
-  DBusHandlerResult ret;
-
-  drive = NULL;
-  drives = NULL;
-  unmount_flags = 0;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_UINT32, &unmount_flags,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for DriveEject(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
 
   print_debug ("in handle_drive_eject");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   drive = NULL;
   drives = g_volume_monitor_get_connected_drives (monitor);
@@ -1255,7 +1213,7 @@ handle_drive_eject (DBusConnection *connection, DBusMessage *message)
 
       drive = G_DRIVE (l->data);
       drive_id = g_strdup_printf ("%p", drive);
-      if (strcmp (drive_id, id) == 0)
+      if (strcmp (drive_id, Id) == 0)
         break;
 
       g_free (drive_id);
@@ -1265,48 +1223,42 @@ handle_drive_eject (DBusConnection *connection, DBusMessage *message)
 
   if (drive == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given drive was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given drive was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (drive), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
                      NULL);
 
   mount_operation = NULL;
-  if (mount_op_id != NULL && strlen (mount_op_id) > 0)
+  if (MountOpId != NULL && strlen (MountOpId) > 0)
     {
-      mount_operation = wrap_mount_op (mount_op_id, sender);
+      mount_operation = wrap_mount_op (MountOpId, sender);
       g_object_set_data_full (G_OBJECT (drive), "mount_operation", mount_operation, g_object_unref);
     }
 
   g_drive_eject_with_operation (drive,
-                                unmount_flags,
+                                UnmountFlags,
                                 mount_operation,
                                 cancellable,
                                 (GAsyncReadyCallback) drive_eject_cb,
-                                dbus_message_ref (message));
+                                g_object_ref (invocation));
 
  out:
   if (drives != NULL)
@@ -1314,16 +1266,15 @@ handle_drive_eject (DBusConnection *connection, DBusMessage *message)
       g_list_foreach (drives, (GFunc) g_object_unref, NULL);
       g_list_free (drives);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-drive_stop_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
+drive_stop_cb (GDrive *drive, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in drive_stop_cb");
 
@@ -1334,58 +1285,34 @@ drive_stop_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
   if (!g_drive_stop_finish (drive, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_drive_stop (NULL, invocation);
     }
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_drive_stop (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_drive_stop (GVfsRemoteVolumeMonitor *object,
+                   GDBusMethodInvocation *invocation,
+                   const gchar *Id,
+                   const gchar *CancellationId,
+                   guint UnmountFlags,
+                   const gchar *MountOpId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
-  const char *mount_op_id;
   GMountOperation *mount_operation;
   GCancellable *cancellable;
-  dbus_uint32_t unmount_flags;
-  DBusError dbus_error;
   GList *drives, *l;
   GDrive *drive;
-  DBusHandlerResult ret;
-
-  drive = NULL;
-  drives = NULL;
-  unmount_flags = 0;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_UINT32, &unmount_flags,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for DriveStop(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
 
   print_debug ("in handle_drive_stop");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   drive = NULL;
   drives = g_volume_monitor_get_connected_drives (monitor);
@@ -1395,7 +1322,7 @@ handle_drive_stop (DBusConnection *connection, DBusMessage *message)
 
       drive = G_DRIVE (l->data);
       drive_id = g_strdup_printf ("%p", drive);
-      if (strcmp (drive_id, id) == 0)
+      if (strcmp (drive_id, Id) == 0)
         break;
 
       g_free (drive_id);
@@ -1405,48 +1332,42 @@ handle_drive_stop (DBusConnection *connection, DBusMessage *message)
 
   if (drive == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given drive was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given drive was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (drive), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
                      NULL);
 
   mount_operation = NULL;
-  if (mount_op_id != NULL && strlen (mount_op_id) > 0)
+  if (MountOpId != NULL && strlen (MountOpId) > 0)
     {
-      mount_operation = wrap_mount_op (mount_op_id, sender);
+      mount_operation = wrap_mount_op (MountOpId, sender);
       g_object_set_data_full (G_OBJECT (drive), "mount_operation", mount_operation, g_object_unref);
     }
 
   g_drive_stop (drive,
-                unmount_flags,
+                UnmountFlags,
                 mount_operation,
                 cancellable,
                 (GAsyncReadyCallback) drive_stop_cb,
-                dbus_message_ref (message));
+                g_object_ref (invocation));
 
  out:
   if (drives != NULL)
@@ -1454,16 +1375,15 @@ handle_drive_stop (DBusConnection *connection, DBusMessage *message)
       g_list_foreach (drives, (GFunc) g_object_unref, NULL);
       g_list_free (drives);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-drive_start_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
+drive_start_cb (GDrive *drive, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in drive_start_cb");
 
@@ -1474,56 +1394,34 @@ drive_start_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
   if (!g_drive_start_finish (drive, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_drive_start (NULL, invocation);
     }
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_drive_start (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_drive_start (GVfsRemoteVolumeMonitor *object,
+                    GDBusMethodInvocation *invocation,
+                    const gchar *Id,
+                    const gchar *CancellationId,
+                    guint Flags,
+                    const gchar *MountOpId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
-  const char *mount_op_id;
-  GDriveStartFlags flags;
-  DBusError dbus_error;
   GList *drives, *l;
   GDrive *drive;
-  DBusHandlerResult ret;
   GMountOperation *mount_operation;
   GCancellable *cancellable;
 
-  drives = NULL;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_UINT32, &flags,
-                              DBUS_TYPE_STRING, &mount_op_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for DriveStart(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
-
   print_debug ("in handle_drive_start");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   drive = NULL;
   drives = g_volume_monitor_get_connected_drives (monitor);
@@ -1533,7 +1431,7 @@ handle_drive_start (DBusConnection *connection, DBusMessage *message)
 
       drive = G_DRIVE (l->data);
       drive_id = g_strdup_printf ("%p", drive);
-      if (strcmp (drive_id, id) == 0)
+      if (strcmp (drive_id, Id) == 0)
         break;
 
       g_free (drive_id);
@@ -1543,48 +1441,42 @@ handle_drive_start (DBusConnection *connection, DBusMessage *message)
 
   if (drive == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given drive was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given drive was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (drive), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   mount_operation = NULL;
-  if (mount_op_id != NULL && strlen (mount_op_id) > 0)
+  if (MountOpId != NULL && strlen (MountOpId) > 0)
     {
-      mount_operation = wrap_mount_op (mount_op_id, sender);
+      mount_operation = wrap_mount_op (MountOpId, sender);
       g_object_set_data_full (G_OBJECT (drive), "mount_operation", mount_operation, g_object_unref);
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
                      NULL);
 
   g_drive_start (drive,
-                 flags,
+                 Flags,
                  mount_operation,
                  cancellable,
                  (GAsyncReadyCallback) drive_start_cb,
-                 dbus_message_ref (message));
+                 g_object_ref (invocation));
 
  out:
   if (drives != NULL)
@@ -1592,16 +1484,15 @@ handle_drive_start (DBusConnection *connection, DBusMessage *message)
       g_list_foreach (drives, (GFunc) g_object_unref, NULL);
       g_list_free (drives);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
-drive_poll_for_media_cb (GDrive *drive, GAsyncResult *result, DBusMessage *message)
+drive_poll_for_media_cb (GDrive *drive, GAsyncResult *result, GDBusMethodInvocation *invocation)
 {
   GError *error;
-  DBusMessage *reply;
 
   print_debug ("in drive_poll_for_media_cb");
 
@@ -1611,52 +1502,31 @@ drive_poll_for_media_cb (GDrive *drive, GAsyncResult *result, DBusMessage *messa
   if (!g_drive_poll_for_media_finish (drive, result, &error))
     {
       print_debug ("  error: %s", error->message);
-      reply = _dbus_message_new_from_gerror (message, error);
+      g_dbus_method_invocation_return_gerror (invocation, error);
       g_error_free (error);
     }
   else
     {
       print_debug (" success");
-      reply = dbus_message_new_method_return (message);
+      gvfs_remote_volume_monitor_complete_drive_poll_for_media (NULL, invocation);
     }
-
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (message);
-  dbus_message_unref (reply);
+  g_object_unref (invocation);
 }
 
-static DBusHandlerResult
-handle_drive_poll_for_media (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_drive_poll_for_media (GVfsRemoteVolumeMonitor *object,
+                             GDBusMethodInvocation *invocation,
+                             const gchar *Id,
+                             const gchar *CancellationId)
 {
-  const char *id;
-  const char *cancellation_id;
   const char *sender;
   GCancellable *cancellable;
-  DBusError dbus_error;
   GList *drives, *l;
   GDrive *drive;
-  DBusHandlerResult ret;
-
-  drive = NULL;
-  drives = NULL;
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &id,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for DrivePollForMedia(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
 
   print_debug ("in handle_drive_poll_for_media");
 
-  ret = DBUS_HANDLER_RESULT_HANDLED;
-
-  sender = dbus_message_get_sender (message);
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   drive = NULL;
   drives = g_volume_monitor_get_connected_drives (monitor);
@@ -1666,7 +1536,7 @@ handle_drive_poll_for_media (DBusConnection *connection, DBusMessage *message)
 
       drive = G_DRIVE (l->data);
       drive_id = g_strdup_printf ("%p", drive);
-      if (strcmp (drive_id, id) == 0)
+      if (strcmp (drive_id, Id) == 0)
         break;
 
       g_free (drive_id);
@@ -1676,30 +1546,24 @@ handle_drive_poll_for_media (DBusConnection *connection, DBusMessage *message)
 
   if (drive == NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.NotFound",
-                                      "The given drive was not found");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.NotFound",
+                                                  "The given drive was not found");
       goto out;
     }
 
   if (g_object_get_data (G_OBJECT (drive), "cancellable") != NULL)
     {
-      DBusMessage *reply;
-      reply = dbus_message_new_error (message,
-                                      "org.gtk.Private.RemoteVolumeMonitor.Failed",
-                                      "An operation is already pending");
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
+      g_dbus_method_invocation_return_dbus_error (invocation,
+                                                  "org.gtk.Private.RemoteVolumeMonitor.Failed",
+                                                  "An operation is already pending");
       goto out;
     }
 
   cancellable = g_cancellable_new ();
   g_object_set_data_full (G_OBJECT (drive), "cancellable", cancellable, g_object_unref);
   g_object_set_data_full (G_OBJECT (cancellable), "owner", g_strdup (sender), g_free);
-  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (cancellation_id), g_free);
+  g_object_set_data_full (G_OBJECT (cancellable), "cancellation_id", g_strdup (CancellationId), g_free);
   outstanding_ops = g_list_prepend (outstanding_ops, cancellable);
   g_object_weak_ref (G_OBJECT (cancellable),
                      cancellable_destroyed_cb,
@@ -1708,69 +1572,54 @@ handle_drive_poll_for_media (DBusConnection *connection, DBusMessage *message)
   g_drive_poll_for_media (drive,
                           cancellable,
                           (GAsyncReadyCallback) drive_poll_for_media_cb,
-                          dbus_message_ref (message));
-
+                          g_object_ref (invocation));
+  
  out:
   if (drives != NULL)
     {
       g_list_foreach (drives, (GFunc) g_object_unref, NULL);
       g_list_free (drives);
     }
-  return ret;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static DBusHandlerResult
-handle_is_supported (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_is_supported (GVfsRemoteVolumeMonitor *object,
+                     GDBusMethodInvocation *invocation)
 {
-  dbus_bool_t is_supported;
-  DBusMessage *reply;
-  DBusMessageIter iter;
-
   print_debug ("in handle_supported");
 
   /* if monitor wasn't created on startup; try again */
   if (monitor == NULL)
     monitor_try_create ();
 
-  is_supported = (monitor != NULL);
-
-  reply = dbus_message_new_method_return (message);
-  dbus_message_iter_init_append (reply, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_supported);
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (reply);
-
-  return DBUS_HANDLER_RESULT_HANDLED;
+  /* If someone is calling into this object and interface, start watching their name so
+   * we can cancel operations initiated by them when they disconnect
+   */
+  ensure_name_owner_changed_for_unique_name (invocation);
+  
+  gvfs_remote_volume_monitor_complete_is_supported (object, invocation,
+                                                    monitor != NULL);
+  
+  return TRUE; /* invocation was handled */
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static DBusHandlerResult
-handle_cancel_operation (DBusConnection *connection, DBusMessage *message)
+static gboolean
+handle_cancel_operation (GVfsRemoteVolumeMonitor *object,
+                         GDBusMethodInvocation *invocation,
+                         const gchar *CancellationId)
 {
-  DBusMessage *reply;
-  DBusMessageIter iter;
-  DBusError dbus_error;
-  dbus_bool_t was_cancelled;
+  gboolean was_cancelled;
   const char *sender;
-  const char *cancellation_id;
   GList *l;
 
   was_cancelled = FALSE;
 
-  sender = dbus_message_get_sender (message);
-
-  dbus_error_init (&dbus_error);
-  if (!dbus_message_get_args (message, &dbus_error,
-                              DBUS_TYPE_STRING, &cancellation_id,
-                              DBUS_TYPE_INVALID))
-    {
-      g_warning ("Error parsing args for CancelOperation(): %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
+  sender = g_dbus_method_invocation_get_sender (invocation);
 
   print_debug ("in handle_cancel_operation");
 
@@ -1783,7 +1632,7 @@ handle_cancel_operation (DBusConnection *connection, DBusMessage *message)
 
       owner = g_object_get_data (G_OBJECT (cancellable), "owner");
       id = g_object_get_data (G_OBJECT (cancellable), "cancellation_id");
-      if (g_strcmp0 (owner, sender) == 0 && g_strcmp0 (id, cancellation_id) == 0)
+      if (g_strcmp0 (owner, sender) == 0 && g_strcmp0 (id, CancellationId) == 0)
         {
           print_debug ("found op to cancel");
           g_cancellable_cancel (cancellable);
@@ -1796,215 +1645,87 @@ handle_cancel_operation (DBusConnection *connection, DBusMessage *message)
   if (!was_cancelled)
     g_warning ("didn't find op to cancel");
 
- out:
-  reply = dbus_message_new_method_return (message);
-  dbus_message_iter_init_append (reply, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &was_cancelled);
-  dbus_connection_send (connection, reply, NULL);
-  dbus_message_unref (reply);
+  gvfs_remote_volume_monitor_complete_cancel_operation (object, invocation, was_cancelled);
 
-  return DBUS_HANDLER_RESULT_HANDLED;
+  return TRUE;
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static DBusHandlerResult
-filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
-{
-  DBusHandlerResult ret;
-
-  ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameLost"))
-    {
-      /* means that someone has claimed our name (we allow replacement) */
-      g_warning ("Got NameLost, some other instance replaced us");
-      exit (0);
-    }
-  else if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameOwnerChanged"))
-    {
-      DBusMessageIter iter;
-      const gchar *name;
-      const gchar *old_owner;
-      const gchar *new_owner;
-
-      dbus_message_iter_init (message, &iter);
-      dbus_message_iter_get_basic (&iter, &name);
-      dbus_message_iter_next (&iter);
-      dbus_message_iter_get_basic (&iter, &old_owner);
-      dbus_message_iter_next (&iter);
-      dbus_message_iter_get_basic (&iter, &new_owner);
-      dbus_message_iter_next (&iter);
-
-      print_debug ("NameOwnerChanged: '%s' '%s' '%s'", name, old_owner, new_owner);
-
-      if (strlen (new_owner) == 0)
-        {
-          GList *l;
-
-          /* if @name has outstanding mount operation objects; abort them */
-          for (l = outstanding_mount_op_objects; l != NULL; l = l->next)
-            {
-              GMountOperation *op = G_MOUNT_OPERATION (l->data);
-              const gchar *owner;
-
-              owner = g_object_get_data (G_OBJECT (op), "mount_op_owner");
-              if (g_strcmp0 (owner, name) == 0)
-                {
-                  print_debug ("****** name `%s' has an outstanding mount operation object, aborting it",
-                               name);
-                  g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
-                }
-            }
-
-          /* see if @name has outstanding ops; if so, cancel them */
-          for (l = outstanding_ops; l != NULL; l = l->next)
-            {
-              GCancellable *cancellable = G_CANCELLABLE (l->data);
-              const gchar *owner;
-
-              owner = g_object_get_data (G_OBJECT (cancellable), "owner");
-              print_debug ("looking at op for %s", owner);
-              if (g_strcmp0 (owner, name) == 0)
-                {
-                  print_debug ("****** name `%s' has an outstanding op, cancelling it",
-                               name);
-                  g_cancellable_cancel (cancellable);
-                }
-            }
-
-          remove_name_owned_changed_for_unique_name (name);
-        }
-
-    }
-  else if (g_strcmp0 (dbus_message_get_interface (message), "org.gtk.Private.RemoteVolumeMonitor") == 0 &&
-           g_strcmp0 (dbus_message_get_path (message), "/org/gtk/Private/RemoteVolumeMonitor") == 0)
-    {
-      /* If someone is calling into this object and interface, start watching their name so
-       * we can cancel operations initiated by them when they disconnect
-       */
-      ensure_name_owner_changed_for_unique_name (dbus_message_get_sender (message));
-
-      if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "IsSupported"))
-        {
-          ret = handle_is_supported (connection, message);
-        }
-      else
-        {
-          if (monitor != NULL)
-            {
-              if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "List"))
-                ret = handle_list (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "CancelOperation"))
-                ret = handle_cancel_operation (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "MountUnmount"))
-                ret = handle_mount_unmount (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeMount"))
-                ret = handle_volume_mount (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveEject"))
-                ret = handle_drive_eject (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DrivePollForMedia"))
-                ret = handle_drive_poll_for_media (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveStart"))
-                ret = handle_drive_start (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveStop"))
-                ret = handle_drive_stop (connection, message);
-
-              else if (dbus_message_is_method_call (message, "org.gtk.Private.RemoteVolumeMonitor", "MountOpReply"))
-                ret = handle_mount_op_reply (connection, message);
-            }
-        }
-    }
-
-  return ret;
-}
-
-typedef void (*AppendFunc) (void *object, DBusMessageIter *iter);
+typedef GVariant * (*AppendFunc) (void *object);
+typedef void (*MonitorSignalFunc) (GVfsRemoteVolumeMonitor *object, 
+                                   const gchar *TheDBusName,
+                                   const gchar *Id,
+                                   GVariant *val);
 
 static void
-emit_signal (DBusConnection *connection, const char *signal_name, void *object, AppendFunc func)
+emit_signal (GVfsRemoteVolumeMonitor *instance, MonitorSignalFunc signal_func, void *object, AppendFunc func)
 {
   char *id;
-  DBusMessage *message;
-  DBusMessageIter iter;
-
+  GVariant *val;
+  
+  print_debug ("emit_signal: %p", object);
+  
   id = g_strdup_printf ("%p", object);
+  val = func (object);
 
-  message = dbus_message_new_signal ("/org/gtk/Private/RemoteVolumeMonitor",
-                                     "org.gtk.Private.RemoteVolumeMonitor",
-                                     signal_name);
-  dbus_message_iter_init_append (message, &iter);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &the_dbus_name);
-  dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &id);
-
-  func (object, &iter);
-
-  dbus_connection_send (connection, message, NULL);
-  dbus_message_unref (message);
-
+  signal_func (instance, the_dbus_name, id, val);
 
   g_free (id);
 }
 
 static void
-drive_changed (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection)
+drive_changed (GVolumeMonitor *monitor, GDrive *drive, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "DriveChanged", drive, (AppendFunc) append_drive);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_drive_changed, drive, (AppendFunc) append_drive);
 }
 
 static void
-drive_connected (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection)
+drive_connected (GVolumeMonitor *monitor, GDrive *drive, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "DriveConnected", drive, (AppendFunc) append_drive);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_drive_connected, drive, (AppendFunc) append_drive);
 }
 
 static void
-drive_disconnected (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection)
+drive_disconnected (GVolumeMonitor *monitor, GDrive *drive, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "DriveDisconnected", drive, (AppendFunc) append_drive);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_drive_disconnected, drive, (AppendFunc) append_drive);
 }
 
 static void
-drive_eject_button (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection)
+drive_eject_button (GVolumeMonitor *monitor, GDrive *drive, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "DriveEjectButton", drive, (AppendFunc) append_drive);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_drive_eject_button, drive, (AppendFunc) append_drive);
 }
 
 static void
-drive_stop_button (GVolumeMonitor *monitor, GDrive *drive, DBusConnection *connection)
+drive_stop_button (GVolumeMonitor *monitor, GDrive *drive, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "DriveStopButton", drive, (AppendFunc) append_drive);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_drive_stop_button, drive, (AppendFunc) append_drive);
 }
 
 static void
-volume_changed (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection)
+volume_changed (GVolumeMonitor *monitor, GVolume *volume, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "VolumeChanged", volume, (AppendFunc) append_volume);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_volume_changed, volume, (AppendFunc) append_volume);
 }
 
 static void
-volume_added (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection)
+volume_added (GVolumeMonitor *monitor, GVolume *volume, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "VolumeAdded", volume, (AppendFunc) append_volume);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_volume_added, volume, (AppendFunc) append_volume);
 }
 
 static void
-volume_removed (GVolumeMonitor *monitor, GVolume *volume, DBusConnection *connection)
+volume_removed (GVolumeMonitor *monitor, GVolume *volume, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "VolumeRemoved", volume, (AppendFunc) append_volume);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_volume_removed, volume, (AppendFunc) append_volume);
 }
 
 static void
-mount_changed (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection)
+mount_changed (GVolumeMonitor *monitor, GMount *mount, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "MountChanged", mount, (AppendFunc) append_mount);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_mount_changed, mount, (AppendFunc) append_mount);
 }
 
 static void
@@ -2016,22 +1737,22 @@ mount_sniff_x_content_type (GMount *mount)
 }
 
 static void
-mount_added (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection)
+mount_added (GVolumeMonitor *monitor, GMount *mount, GVfsRemoteVolumeMonitor *instance)
 {
   mount_sniff_x_content_type (mount);
-  emit_signal (connection, "MountAdded", mount, (AppendFunc) append_mount);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_mount_added, mount, (AppendFunc) append_mount);
 }
 
 static void
-mount_pre_unmount (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection)
+mount_pre_unmount (GVolumeMonitor *monitor, GMount *mount, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "MountPreUnmount", mount, (AppendFunc) append_mount);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_mount_pre_unmount, mount, (AppendFunc) append_mount);
 }
 
 static void
-mount_removed (GVolumeMonitor *monitor, GMount *mount, DBusConnection *connection)
+mount_removed (GVolumeMonitor *monitor, GMount *mount, GVfsRemoteVolumeMonitor *instance)
 {
-  emit_signal (connection, "MountRemoved", mount, (AppendFunc) append_mount);
+  emit_signal (instance, (MonitorSignalFunc) gvfs_remote_volume_monitor_emit_mount_removed, mount, (AppendFunc) append_mount);
 }
 
 void
@@ -2049,7 +1770,6 @@ g_vfs_proxy_volume_monitor_daemon_init (void)
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
-  dbus_threads_init_default ();
   g_type_init ();
 }
 
@@ -2096,17 +1816,95 @@ monitor_try_create (void)
     g_type_class_unref (klass);
 }
 
+static void
+bus_acquired_handler_cb (GDBusConnection *conn,
+                         const gchar *name,
+                         gpointer user_data)
+{
+  GError *error;
+  
+  g_warning ("Bus acquired at %s", name);
+
+  if (! conn)
+    return;
+
+  monitor_daemon = gvfs_remote_volume_monitor_skeleton_new ();
+
+  g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (monitor_daemon),
+                                       G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD);
+  
+  g_signal_connect (monitor_daemon, "handle-is-supported", G_CALLBACK (handle_is_supported), NULL);
+  if (monitor != NULL)
+    {
+      g_signal_connect (monitor_daemon, "handle-list", G_CALLBACK (handle_list), NULL);
+      g_signal_connect (monitor_daemon, "handle-cancel-operation", G_CALLBACK (handle_cancel_operation), NULL);
+      g_signal_connect (monitor_daemon, "handle-drive-eject", G_CALLBACK (handle_drive_eject), NULL);
+      g_signal_connect (monitor_daemon, "handle-drive-poll-for-media", G_CALLBACK (handle_drive_poll_for_media), NULL);
+      g_signal_connect (monitor_daemon, "handle-drive-start", G_CALLBACK (handle_drive_start), NULL);
+      g_signal_connect (monitor_daemon, "handle-drive-stop", G_CALLBACK (handle_drive_stop), NULL);
+      g_signal_connect (monitor_daemon, "handle-mount-op-reply", G_CALLBACK (handle_mount_op_reply), NULL);
+      g_signal_connect (monitor_daemon, "handle-mount-unmount", G_CALLBACK (handle_mount_unmount), NULL);
+      g_signal_connect (monitor_daemon, "handle-volume-mount", G_CALLBACK (handle_volume_mount), NULL);
+    }
+
+  /*  This way we open our d-bus API to public, though there's the "Private" path element  */
+  error = NULL;
+  if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (monitor_daemon), conn,
+                                         "/org/gtk/Private/RemoteVolumeMonitor", &error))
+    {
+      g_printerr ("Error exporting volume monitor: %s (%s, %d)\n",
+                  error->message, g_quark_to_string (error->domain), error->code);
+      g_error_free (error);
+    }
+
+
+  if (monitor != NULL)
+    {
+      g_signal_connect (monitor, "drive-changed", (GCallback) drive_changed, monitor_daemon);
+      g_signal_connect (monitor, "drive-connected", (GCallback) drive_connected, monitor_daemon);
+      g_signal_connect (monitor, "drive-disconnected", (GCallback) drive_disconnected, monitor_daemon);
+      g_signal_connect (monitor, "drive-eject-button", (GCallback) drive_eject_button, monitor_daemon);
+      g_signal_connect (monitor, "drive-stop-button", (GCallback) drive_stop_button, monitor_daemon);
+
+      g_signal_connect (monitor, "volume-changed", (GCallback) volume_changed, monitor_daemon);
+      g_signal_connect (monitor, "volume-added", (GCallback) volume_added, monitor_daemon);
+      g_signal_connect (monitor, "volume-removed", (GCallback) volume_removed, monitor_daemon);
+
+      g_signal_connect (monitor, "mount-changed", (GCallback) mount_changed, monitor_daemon);
+      g_signal_connect (monitor, "mount-added", (GCallback) mount_added, monitor_daemon);
+      g_signal_connect (monitor, "mount-pre-unmount", (GCallback) mount_pre_unmount, monitor_daemon);
+      g_signal_connect (monitor, "mount-removed", (GCallback) mount_removed, monitor_daemon);
+    }
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+              const gchar     *name,
+              gpointer         user_data)
+{
+  /* means that someone has claimed our name (we allow replacement) */
+  g_warning ("Got NameLost, some other instance replaced us");
+  g_main_loop_quit (loop);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+                  const gchar     *name,
+                  gpointer         user_data)
+{
+  g_warning ("Acquired the name %s on the session message bus\n", name);
+}
+
 int
 g_vfs_proxy_volume_monitor_daemon_main (int argc,
                                         char *argv[],
                                         const char *dbus_name,
                                         GType volume_monitor_type)
 {
-  int rc G_GNUC_UNUSED;
   int ret;
-  GMainLoop *loop;
-  DBusError dbus_error;
+  guint name_owner_id;
 
+  name_owner_id = 0;
   ret = 1;
 
   loop = g_main_loop_new (NULL, FALSE);
@@ -2118,69 +1916,31 @@ g_vfs_proxy_volume_monitor_daemon_main (int argc,
 
   the_volume_monitor_type = volume_monitor_type;
   the_dbus_name = dbus_name;
-  unique_names_being_watched = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  unique_names_being_watched = g_hash_table_new_full (g_str_hash, g_int_equal, g_free, NULL);
 
   /* try and create the monitor */
   monitor_try_create ();
 
-  dbus_error_init (&dbus_error);
-  connection = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error);
-  if (dbus_error_is_set (&dbus_error))
-    {
-      g_warning ("Cannot connect to session bus: %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
-
-  _g_dbus_connection_integrate_with_main (connection);
-
-  rc = dbus_bus_request_name (connection,
-                              dbus_name,
-                              DBUS_NAME_FLAG_ALLOW_REPLACEMENT |
-                              DBUS_NAME_FLAG_DO_NOT_QUEUE |
-                              DBUS_NAME_FLAG_REPLACE_EXISTING,
-                              &dbus_error);
-  if (dbus_error_is_set (&dbus_error))
-    {
-      g_warning ("dbus_bus_request_name failed: %s: %s", dbus_error.name, dbus_error.message);
-      dbus_error_free (&dbus_error);
-      goto out;
-    }
-  if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      g_warning ("Cannot become primary owner");
-      goto out;
-    }
-
-  if (!dbus_connection_add_filter (connection, filter_function, NULL, NULL))
-    {
-      g_warning ("Cannot add filter function");
-      goto out;
-    }
-
-  if (monitor != NULL)
-    {
-      g_signal_connect (monitor, "drive-changed", (GCallback) drive_changed, connection);
-      g_signal_connect (monitor, "drive-connected", (GCallback) drive_connected, connection);
-      g_signal_connect (monitor, "drive-disconnected", (GCallback) drive_disconnected, connection);
-      g_signal_connect (monitor, "drive-eject-button", (GCallback) drive_eject_button, connection);
-      g_signal_connect (monitor, "drive-stop-button", (GCallback) drive_stop_button, connection);
-
-      g_signal_connect (monitor, "volume-changed", (GCallback) volume_changed, connection);
-      g_signal_connect (monitor, "volume-added", (GCallback) volume_added, connection);
-      g_signal_connect (monitor, "volume-removed", (GCallback) volume_removed, connection);
-
-      g_signal_connect (monitor, "mount-changed", (GCallback) mount_changed, connection);
-      g_signal_connect (monitor, "mount-added", (GCallback) mount_added, connection);
-      g_signal_connect (monitor, "mount-pre-unmount", (GCallback) mount_pre_unmount, connection);
-      g_signal_connect (monitor, "mount-removed", (GCallback) mount_removed, connection);
-    }
-
+  name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+                                  dbus_name,
+                                  G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+                                  G_BUS_NAME_OWNER_FLAGS_REPLACE,
+                                  bus_acquired_handler_cb,
+                                  on_name_acquired,
+                                  on_name_lost,
+                                  NULL,
+                                  NULL);
   g_main_loop_run (loop);
-  g_main_loop_unref (loop);
 
   ret = 0;
 
 out:
+  if (name_owner_id != 0)
+    g_bus_unown_name (name_owner_id);
+  if (loop != NULL)
+    g_main_loop_unref (loop);
+  if (unique_names_being_watched)
+    g_hash_table_unref (unique_names_being_watched);
+
   return ret;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]