[gvfs/gdbus] gdbus: Port GIO side of proxy volume monitor
- From: Tomas Bzatek <tbzatek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/gdbus] gdbus: Port GIO side of proxy volume monitor
- Date: Tue, 31 May 2011 13:38:55 +0000 (UTC)
commit 1e73d252050c79086bac06d480357c175ad236b9
Author: Tomas Bzatek <tbzatek redhat com>
Date: Tue May 31 15:34:56 2011 +0200
gdbus: Port GIO side of proxy volume monitor
Few leftovers:
* Nuke the complicated is_supported machinery if possible
* Tweak timeouts for some operations
* Fix occasional GMountOperation lookup failures
monitor/afc/Makefile.am | 1 -
monitor/gdu/Makefile.am | 2 -
monitor/proxy/Makefile.am | 2 -
monitor/proxy/gproxydrive.c | 378 +++++------
monitor/proxy/gproxydrive.h | 14 +-
monitor/proxy/gproxymount.c | 151 ++---
monitor/proxy/gproxymount.h | 2 +-
monitor/proxy/gproxymountoperation.c | 184 ++----
monitor/proxy/gproxymountoperation.h | 27 +-
monitor/proxy/gproxyshadowmount.c | 2 -
monitor/proxy/gproxyvolume.c | 145 ++---
monitor/proxy/gproxyvolume.h | 2 +-
monitor/proxy/gproxyvolumemonitor.c | 1257 +++++++++++++++++++---------------
monitor/proxy/gproxyvolumemonitor.h | 17 +-
14 files changed, 1068 insertions(+), 1116 deletions(-)
---
diff --git a/monitor/afc/Makefile.am b/monitor/afc/Makefile.am
index a823080..023c413 100644
--- a/monitor/afc/Makefile.am
+++ b/monitor/afc/Makefile.am
@@ -24,7 +24,6 @@ gvfs_afc_volume_monitor_CFLAGS = \
gvfs_afc_volume_monitor_LDADD = \
$(GLIB_LIBS) \
- $(DBUS_LIBS) \
$(AFC_LIBS) \
$(top_builddir)/common/libgvfscommon.la \
$(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \
diff --git a/monitor/gdu/Makefile.am b/monitor/gdu/Makefile.am
index cb64944..6ffa71a 100644
--- a/monitor/gdu/Makefile.am
+++ b/monitor/gdu/Makefile.am
@@ -18,7 +18,6 @@ gvfs_gdu_volume_monitor_CFLAGS = \
-I$(top_srcdir)/monitor/proxy \
$(GLIB_CFLAGS) \
$(GDU_CFLAGS) \
- $(DBUS_CFLAGS) \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
-DG_DISABLE_DEPRECATED \
@@ -31,7 +30,6 @@ gvfs_gdu_volume_monitor_LDFLAGS = \
gvfs_gdu_volume_monitor_LDADD = \
$(GLIB_LIBS) \
$(GDU_LIBS) \
- $(DBUS_LIBS) \
$(top_builddir)/common/libgvfscommon.la \
$(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \
$(NULL)
diff --git a/monitor/proxy/Makefile.am b/monitor/proxy/Makefile.am
index 397f037..51a2d8b 100644
--- a/monitor/proxy/Makefile.am
+++ b/monitor/proxy/Makefile.am
@@ -34,7 +34,6 @@ libgioremote_volume_monitor_la_CFLAGS = \
-DG_LOG_DOMAIN=\"GVFS-RemoteVolumeMonitor\" \
-I$(top_srcdir)/common \
$(GLIB_CFLAGS) \
- $(DBUS_CFLAGS) \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
-DREMOTE_VOLUME_MONITORS_DIR=\"$(remote_volume_monitorsdir)\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
@@ -47,7 +46,6 @@ libgioremote_volume_monitor_la_LDFLAGS = \
libgioremote_volume_monitor_la_LIBADD = \
$(GLIB_LIBS) \
- $(DBUS_LIBS) \
$(top_builddir)/common/libgvfscommon.la \
$(NULL)
diff --git a/monitor/proxy/gproxydrive.c b/monitor/proxy/gproxydrive.c
index 49e9ae1..8e1d840 100644
--- a/monitor/proxy/gproxydrive.c
+++ b/monitor/proxy/gproxydrive.c
@@ -30,12 +30,11 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
-#include <gvfsdbusutils.h>
-
#include "gproxyvolumemonitor.h"
#include "gproxydrive.h"
#include "gproxyvolume.h"
#include "gproxymountoperation.h"
+#include "gvfsvolumemonitordbus.h"
/* Protects all fields of GProxyDrive that can change */
G_LOCK_DEFINE_STATIC(proxy_drive);
@@ -134,70 +133,48 @@ g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor)
* array:string volume-ids
* dict:string->string identifiers
*/
-#define DRIVE_STRUCT_TYPE "(sssbbbbbbbbuasa{ss})"
+#define DRIVE_STRUCT_TYPE "(&s&s&sbbbbbbbbuasa{ss})"
void
-g_proxy_drive_update (GProxyDrive *drive,
- DBusMessageIter *iter)
+g_proxy_drive_update (GProxyDrive *drive,
+ GVariant *iter)
{
- DBusMessageIter iter_struct;
- DBusMessageIter iter_volume_ids_iter;
const char *id;
const char *name;
const char *gicon_data;
- dbus_bool_t can_eject;
- dbus_bool_t can_poll_for_media;
- dbus_bool_t has_media;
- dbus_bool_t is_media_removable;
- dbus_bool_t is_media_check_automatic;
- dbus_bool_t can_start;
- dbus_bool_t can_start_degraded;
- dbus_bool_t can_stop;
- dbus_uint32_t start_stop_type;
+ gboolean can_eject;
+ gboolean can_poll_for_media;
+ gboolean has_media;
+ gboolean is_media_removable;
+ gboolean is_media_check_automatic;
+ gboolean can_start;
+ gboolean can_start_degraded;
+ gboolean can_stop;
+ guint32 start_stop_type;
GPtrArray *volume_ids;
GHashTable *identifiers;
-
- dbus_message_iter_recurse (iter, &iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &id);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &name);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &gicon_data);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_eject);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_poll_for_media);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &has_media);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &is_media_removable);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &is_media_check_automatic);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_start);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_start_degraded);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_stop);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &start_stop_type);
- dbus_message_iter_next (&iter_struct);
-
+ const gchar *volume_id;
+ GVariantIter *iter_volume_ids;
+ GVariantIter *iter_identifiers;
+
+
+ g_variant_get (iter, DRIVE_STRUCT_TYPE,
+ &id, &name, &gicon_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,
+ &iter_volume_ids,
+ &iter_identifiers);
+
volume_ids = g_ptr_array_new ();
- dbus_message_iter_recurse (&iter_struct, &iter_volume_ids_iter);
- while (dbus_message_iter_get_arg_type (&iter_volume_ids_iter) != DBUS_TYPE_INVALID)
- {
- const char *volume_id;
- dbus_message_iter_get_basic (&iter_volume_ids_iter, &volume_id);
- dbus_message_iter_next (&iter_volume_ids_iter);
- g_ptr_array_add (volume_ids, (gpointer) volume_id);
- }
+ while (g_variant_iter_loop (iter_volume_ids, "&s", &volume_id))
+ g_ptr_array_add (volume_ids, (gpointer) volume_id);
g_ptr_array_add (volume_ids, NULL);
- dbus_message_iter_next (&iter_struct);
-
- identifiers = _get_identifiers (&iter_struct);
- dbus_message_iter_next (&iter_struct);
+ identifiers = _get_identifiers (iter_identifiers);
+
if (drive->id != NULL && strcmp (drive->id, id) != 0)
{
g_warning ("id mismatch during update of drive");
@@ -237,6 +214,8 @@ g_proxy_drive_update (GProxyDrive *drive,
drive->volume_ids = g_strdupv ((char **) volume_ids->pdata);
out:
+ g_variant_iter_free (iter_volume_ids);
+ g_variant_iter_free (iter_identifiers);
g_ptr_array_free (volume_ids, TRUE);
g_hash_table_unref (identifiers);
}
@@ -484,13 +463,20 @@ typedef struct {
} DBusOp;
static void
-cancel_operation_reply_cb (DBusMessage *reply,
- GError *error,
- gpointer user_data)
+cancel_operation_reply_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- if (error != NULL)
+ gboolean out_WasCancelled;
+ GError *error = NULL;
+
+ if (!gvfs_remote_volume_monitor_call_cancel_operation_finish (proxy,
+ &out_WasCancelled,
+ res,
+ &error))
{
g_warning ("Error from CancelOperation(): %s", error->message);
+ g_error_free (error);
}
}
@@ -500,9 +486,7 @@ operation_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -516,35 +500,31 @@ operation_cancelled (GCancellable *cancellable,
g_object_unref (simple);
/* Now tell the remote volume monitor that the op has been cancelled */
- connection = g_proxy_volume_monitor_get_dbus_connection (data->drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (data->drive->volume_monitor);
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "CancelOperation");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_cancel_operation (proxy,
+ data->cancellation_id,
+ NULL,
+ (GAsyncReadyCallback) cancel_operation_reply_cb,
+ NULL);
+ g_object_unref (proxy);
G_UNLOCK (proxy_drive);
-
- _g_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) cancel_operation_reply_cb,
- NULL);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-eject_cb (DBusMessage *reply,
- GError *error,
- DBusOp *data)
+eject_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ DBusOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_drive_eject_finish (proxy,
+ res,
+ &error);
+
if (data->cancelled_handler_id > 0)
g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
@@ -572,6 +552,8 @@ eject_cb (DBusMessage *reply,
if (data->cancellable != NULL)
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -583,11 +565,8 @@ g_proxy_drive_eject_with_operation (GDrive *drive,
gpointer user_data)
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
DBusOp *data;
- dbus_uint32_t _flags = flags;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -626,32 +605,18 @@ g_proxy_drive_eject_with_operation (GDrive *drive,
data->cancellation_id = g_strdup ("");
}
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "DriveEject");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_drive->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_UINT32,
- &_flags,
- DBUS_TYPE_STRING,
- &(data->mount_op_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_drive_eject (proxy,
+ proxy_drive->id,
+ data->cancellation_id,
+ flags,
+ data->mount_op_id,
+ NULL,
+ (GAsyncReadyCallback) eject_cb,
+ data);
+ g_object_unref (proxy);
G_UNLOCK (proxy_drive);
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT, /* 30 minute timeout */
- (GAsyncDBusCallback) eject_cb,
- data);
- dbus_connection_unref (connection);
- dbus_message_unref (message);
out:
;
}
@@ -689,10 +654,17 @@ g_proxy_drive_eject_finish (GDrive *drive,
/* ---------------------------------------------------------------------------------------------------- */
static void
-stop_cb (DBusMessage *reply,
- GError *error,
- DBusOp *data)
+stop_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ DBusOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_drive_stop_finish (proxy,
+ res,
+ &error);
+
if (data->cancelled_handler_id > 0)
g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
@@ -720,6 +692,8 @@ stop_cb (DBusMessage *reply,
if (data->cancellable != NULL)
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -731,11 +705,8 @@ g_proxy_drive_stop (GDrive *drive,
gpointer user_data)
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
DBusOp *data;
- dbus_uint32_t _flags = flags;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -774,32 +745,19 @@ g_proxy_drive_stop (GDrive *drive,
data->cancellation_id = g_strdup ("");
}
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "DriveStop");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_drive->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_UINT32,
- &_flags,
- DBUS_TYPE_STRING,
- &(data->mount_op_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_drive_stop (proxy,
+ proxy_drive->id,
+ data->cancellation_id,
+ flags,
+ data->mount_op_id,
+ NULL,
+ (GAsyncReadyCallback) stop_cb,
+ data);
+ g_object_unref (proxy);
+
G_UNLOCK (proxy_drive);
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT, /* 30 minute timeout */
- (GAsyncDBusCallback) stop_cb,
- data);
- dbus_connection_unref (connection);
- dbus_message_unref (message);
out:
;
}
@@ -829,11 +787,18 @@ typedef struct {
} DBusStartOp;
static void
-start_cb (DBusMessage *reply,
- GError *error,
- DBusStartOp *data)
+start_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- if (data->cancelled_handler_id > 0)
+ DBusStartOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_drive_start_finish (proxy,
+ res,
+ &error);
+
+if (data->cancelled_handler_id > 0)
g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
if (!g_cancellable_is_cancelled (data->cancellable))
@@ -863,6 +828,8 @@ start_cb (DBusMessage *reply,
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -871,9 +838,7 @@ start_cancelled (GCancellable *cancellable,
{
DBusStartOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -887,26 +852,15 @@ start_cancelled (GCancellable *cancellable,
g_object_unref (simple);
/* Now tell the remote drive monitor that the op has been cancelled */
- connection = g_proxy_volume_monitor_get_dbus_connection (data->drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (data->drive->volume_monitor);
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "CancelOperation");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_cancel_operation (proxy,
+ data->cancellation_id,
+ NULL,
+ (GAsyncReadyCallback) cancel_operation_reply_cb,
+ NULL);
+ g_object_unref (proxy);
G_UNLOCK (proxy_drive);
-
- _g_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) cancel_operation_reply_cb,
- NULL);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
}
static void
@@ -919,9 +873,7 @@ g_proxy_drive_start (GDrive *drive,
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
DBusStartOp *data;
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -960,33 +912,18 @@ g_proxy_drive_start (GDrive *drive,
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_drive->volume_monitor);
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "DriveStart");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_drive->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_UINT32,
- &(flags),
- DBUS_TYPE_STRING,
- &(data->mount_op_id),
- DBUS_TYPE_INVALID);
- G_UNLOCK (proxy_drive);
-
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT,
- (GAsyncDBusCallback) start_cb,
- data);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_drive_start (proxy,
+ proxy_drive->id,
+ data->cancellation_id,
+ flags,
+ data->mount_op_id,
+ NULL,
+ (GAsyncReadyCallback) start_cb,
+ data);
+ g_object_unref (proxy);
+ G_UNLOCK (proxy_drive);
out:
;
}
@@ -1004,10 +941,17 @@ g_proxy_drive_start_finish (GDrive *drive,
/* ---------------------------------------------------------------------------------------------------- */
static void
-poll_for_media_cb (DBusMessage *reply,
- GError *error,
- DBusOp *data)
+poll_for_media_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ DBusOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_drive_poll_for_media_finish (proxy,
+ res,
+ &error);
+
if (!g_cancellable_is_cancelled (data->cancellable))
{
GSimpleAsyncResult *simple;
@@ -1033,6 +977,8 @@ poll_for_media_cb (DBusMessage *reply,
if (data->cancellable != NULL)
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -1042,10 +988,8 @@ g_proxy_drive_poll_for_media (GDrive *drive,
gpointer user_data)
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
DBusOp *data;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -1082,29 +1026,17 @@ g_proxy_drive_poll_for_media (GDrive *drive,
{
data->cancellation_id = g_strdup ("");
}
+
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ gvfs_remote_volume_monitor_call_drive_poll_for_media (proxy,
+ proxy_drive->id,
+ data->cancellation_id,
+ NULL,
+ (GAsyncReadyCallback) poll_for_media_cb,
+ data);
+ g_object_unref (proxy);
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_drive->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_drive->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "DrivePollForMedia");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_drive->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_INVALID);
G_UNLOCK (proxy_drive);
-
- _g_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) poll_for_media_cb,
- data);
- dbus_connection_unref (connection);
- dbus_message_unref (message);
out:
;
}
diff --git a/monitor/proxy/gproxydrive.h b/monitor/proxy/gproxydrive.h
index ab26244..206ea1c 100644
--- a/monitor/proxy/gproxydrive.h
+++ b/monitor/proxy/gproxydrive.h
@@ -47,17 +47,17 @@ GType g_proxy_drive_get_type (void) G_GNUC_CONST;
void g_proxy_drive_register (GIOModule *module);
GProxyDrive *g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor);
void g_proxy_drive_update (GProxyDrive *drive,
- DBusMessageIter *iter);
+ GVariant *iter);
const char *g_proxy_drive_get_id (GProxyDrive *drive);
-void g_proxy_drive_handle_start_op_ask_password (GProxyDrive *drive,
- DBusMessageIter *iter);
+void g_proxy_drive_handle_start_op_ask_password (GProxyDrive *drive,
+ GVariant *iter);
-void g_proxy_drive_handle_start_op_ask_question (GProxyDrive *drive,
- DBusMessageIter *iter);
+void g_proxy_drive_handle_start_op_ask_question (GProxyDrive *drive,
+ GVariant *iter);
-void g_proxy_drive_handle_start_op_aborted (GProxyDrive *drive,
- DBusMessageIter *iter);
+void g_proxy_drive_handle_start_op_aborted (GProxyDrive *drive,
+ GVariant *iter);
G_END_DECLS
diff --git a/monitor/proxy/gproxymount.c b/monitor/proxy/gproxymount.c
index 626d592..aab20d0 100644
--- a/monitor/proxy/gproxymount.c
+++ b/monitor/proxy/gproxymount.c
@@ -31,8 +31,6 @@
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
-#include <gvfsdbusutils.h>
-
#include "gproxyvolumemonitor.h"
#include "gproxymount.h"
#include "gproxyvolume.h"
@@ -142,49 +140,34 @@ g_proxy_mount_has_mount_path (GProxyMount *mount, const char *mount_path)
* array:string x-content-types
*/
+#define MOUNT_STRUCT_TYPE "(&s&s&s&s&sb&sas)"
+
void
g_proxy_mount_update (GProxyMount *mount,
- DBusMessageIter *iter)
+ GVariant *iter)
{
- DBusMessageIter iter_struct;
- DBusMessageIter iter_x_content_types;
const char *id;
const char *name;
const char *gicon_data;
const char *uuid;
const char *root_uri;
- dbus_bool_t can_unmount;
+ gboolean can_unmount;
const char *volume_id;
GPtrArray *x_content_types;
+ const char *x_content_type;
+ GVariantIter *iter_content_types;
- dbus_message_iter_recurse (iter, &iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &id);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &name);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &gicon_data);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &uuid);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &root_uri);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_unmount);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &volume_id);
- dbus_message_iter_next (&iter_struct);
+ g_variant_get (iter, MOUNT_STRUCT_TYPE,
+ &id, &name, &gicon_data,
+ &uuid, &root_uri,
+ &can_unmount, &volume_id,
+ &iter_content_types);
x_content_types = g_ptr_array_new ();
- dbus_message_iter_recurse (&iter_struct, &iter_x_content_types);
- while (dbus_message_iter_get_arg_type (&iter_x_content_types) != DBUS_TYPE_INVALID)
- {
- const char *x_content_type;
- dbus_message_iter_get_basic (&iter_x_content_types, &x_content_type);
- dbus_message_iter_next (&iter_x_content_types);
- g_ptr_array_add (x_content_types, (gpointer) x_content_type);
- }
+ while (g_variant_iter_loop (iter_content_types, "&s", &x_content_type))
+ g_ptr_array_add (x_content_types, (gpointer) x_content_type);
g_ptr_array_add (x_content_types, NULL);
- dbus_message_iter_next (&iter_struct);
-
+
if (mount->id != NULL && strcmp (mount->id, id) != 0)
{
g_warning ("id mismatch during update of mount");
@@ -221,7 +204,8 @@ g_proxy_mount_update (GProxyMount *mount,
mount->x_content_types = g_strdupv ((char **) x_content_types->pdata);
out:
- g_ptr_array_free (x_content_types, TRUE);
+ g_variant_iter_free (iter_content_types);
+ g_ptr_array_free (x_content_types, TRUE);
}
const char *
@@ -441,13 +425,20 @@ typedef struct {
} DBusOp;
static void
-cancel_operation_reply_cb (DBusMessage *reply,
- GError *error,
- gpointer user_data)
-{
- if (error != NULL)
+cancel_operation_reply_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ gboolean out_WasCancelled;
+ GError *error = NULL;
+
+ if (!gvfs_remote_volume_monitor_call_cancel_operation_finish (proxy,
+ &out_WasCancelled,
+ res,
+ &error))
{
g_warning ("Error from CancelOperation(): %s", error->message);
+ g_error_free (error);
}
}
@@ -457,9 +448,7 @@ operation_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_mount);
@@ -473,33 +462,29 @@ operation_cancelled (GCancellable *cancellable,
g_object_unref (simple);
/* Now tell the remote volume monitor that the op has been cancelled */
- connection = g_proxy_volume_monitor_get_dbus_connection (data->mount->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (data->mount->volume_monitor);
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "CancelOperation");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->mount->volume_monitor);
+ gvfs_remote_volume_monitor_call_cancel_operation (proxy,
+ data->cancellation_id,
+ NULL,
+ (GAsyncReadyCallback) cancel_operation_reply_cb,
+ NULL);
+ g_object_unref (proxy);
G_UNLOCK (proxy_mount);
-
- _g_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) cancel_operation_reply_cb,
- NULL);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
}
static void
-unmount_cb (DBusMessage *reply,
- GError *error,
- DBusOp *data)
+unmount_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ DBusOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_mount_unmount_finish (proxy,
+ res,
+ &error);
+
if (data->cancelled_handler_id > 0)
g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
@@ -526,6 +511,8 @@ unmount_cb (DBusMessage *reply,
if (data->cancellable != NULL)
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -537,11 +524,8 @@ g_proxy_mount_unmount_with_operation (GMount *mount,
gpointer user_data)
{
GProxyMount *proxy_mount = G_PROXY_MOUNT (mount);
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
DBusOp *data;
- dbus_uint32_t _flags = flags;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_mount);
@@ -580,33 +564,20 @@ g_proxy_mount_unmount_with_operation (GMount *mount,
data->cancellation_id = g_strdup ("");
}
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_mount->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_mount->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "MountUnmount");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_mount->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_UINT32,
- &_flags,
- DBUS_TYPE_STRING,
- &(data->mount_op_id),
- DBUS_TYPE_INVALID);
- G_UNLOCK (proxy_mount);
-
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT, /* 30 minute timeout */
- (GAsyncDBusCallback) unmount_cb,
- data);
+
+
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_mount->volume_monitor);
+ gvfs_remote_volume_monitor_call_mount_unmount (proxy,
+ proxy_mount->id,
+ data->cancellation_id,
+ flags,
+ data->mount_op_id,
+ NULL,
+ (GAsyncReadyCallback) unmount_cb,
+ data);
+ g_object_unref (proxy);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
+ G_UNLOCK (proxy_mount);
out:
;
}
diff --git a/monitor/proxy/gproxymount.h b/monitor/proxy/gproxymount.h
index c635651..50262fd 100644
--- a/monitor/proxy/gproxymount.h
+++ b/monitor/proxy/gproxymount.h
@@ -47,7 +47,7 @@ GType g_proxy_mount_get_type (void) G_GNUC_CONST;
void g_proxy_mount_register (GIOModule *module);
GProxyMount *g_proxy_mount_new (GProxyVolumeMonitor *volume_monitor);
void g_proxy_mount_update (GProxyMount *mount,
- DBusMessageIter *iter);
+ GVariant *iter);
const char *g_proxy_mount_get_id (GProxyMount *mount);
gboolean g_proxy_mount_has_mount_path (GProxyMount *mount, const char *mount_path);
diff --git a/monitor/proxy/gproxymountoperation.c b/monitor/proxy/gproxymountoperation.c
index 8826f31..0edaf96 100644
--- a/monitor/proxy/gproxymountoperation.c
+++ b/monitor/proxy/gproxymountoperation.c
@@ -27,8 +27,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include <gvfsdbusutils.h>
-
#include "gproxymountoperation.h"
/* for protecting the id_to_op and id_count */
@@ -109,13 +107,18 @@ g_proxy_mount_operation_wrap (GMountOperation *op,
/* ---------------------------------------------------------------------------------------------------- */
static void
-mount_op_reply_cb (DBusMessage *reply,
- GError *error,
- gpointer user_data)
+mount_op_reply_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- if (error != NULL)
+ GError *error = NULL;
+
+ if (!gvfs_remote_volume_monitor_call_mount_op_reply_finish (proxy,
+ res,
+ &error))
{
g_warning ("Error from MountOpReply(): %s", error->message);
+ g_error_free (error);
}
}
@@ -125,20 +128,15 @@ mount_operation_reply (GMountOperation *mount_operation,
gpointer user_data)
{
ProxyMountOpData *data = user_data;
- DBusConnection *connection;
- const gchar *name;
- DBusMessage *message;
+ GVfsRemoteVolumeMonitor *proxy;
const gchar *user_name;
const gchar *domain;
const gchar *password;
gchar *encoded_password;
- dbus_uint32_t password_save;
- dbus_uint32_t choice;
- dbus_bool_t anonymous;
-
- connection = g_proxy_volume_monitor_get_dbus_connection (data->monitor);
- name = g_proxy_volume_monitor_get_dbus_name (data->monitor);
-
+ gint password_save;
+ gint choice;
+ gboolean anonymous;
+
user_name = g_mount_operation_get_username (mount_operation);
domain = g_mount_operation_get_domain (mount_operation);
password = g_mount_operation_get_password (mount_operation);
@@ -158,54 +156,35 @@ mount_operation_reply (GMountOperation *mount_operation,
*/
encoded_password = g_base64_encode ((const guchar *) password, (gsize) (strlen (password) + 1));
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "MountOpReply");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(data->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_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) mount_op_reply_cb,
- data);
-
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->monitor);
+ gvfs_remote_volume_monitor_call_mount_op_reply (proxy,
+ data->id,
+ result,
+ user_name,
+ domain,
+ encoded_password,
+ password_save,
+ choice,
+ anonymous,
+ NULL,
+ (GAsyncReadyCallback) mount_op_reply_cb,
+ data);
+ g_object_unref (proxy);
g_free (encoded_password);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
}
/* ---------------------------------------------------------------------------------------------------- */
void
-g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
- DBusMessageIter *iter)
+g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
+ const gchar *message,
+ const gchar *default_user,
+ const gchar *default_domain,
+ guint flags)
{
ProxyMountOpData *data;
- const gchar *message;
- const gchar *default_user;
- const gchar *default_domain;
- dbus_int32_t flags;
g_return_if_fail (wrapped_id != NULL);
- g_return_if_fail (iter != NULL);
G_LOCK (proxy_op);
data = g_hash_table_lookup (id_to_op, wrapped_id);
@@ -218,19 +197,7 @@ g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
wrapped_id);
goto out;
}
-
- dbus_message_iter_get_basic (iter, &message);
- dbus_message_iter_next (iter);
-
- dbus_message_iter_get_basic (iter, &default_user);
- dbus_message_iter_next (iter);
-
- dbus_message_iter_get_basic (iter, &default_domain);
- dbus_message_iter_next (iter);
-
- dbus_message_iter_get_basic (iter, &flags);
- dbus_message_iter_next (iter);
-
+
if (data->reply_handler_id == 0)
{
data->reply_handler_id = g_signal_connect (data->op,
@@ -253,18 +220,13 @@ g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
/* ---------------------------------------------------------------------------------------------------- */
void
-g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
- DBusMessageIter *iter)
+g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
+ const gchar *message,
+ const gchar *const *choices)
{
ProxyMountOpData *data;
- const gchar *message;
- GPtrArray *choices;
- DBusMessageIter iter_array;
g_return_if_fail (wrapped_id != NULL);
- g_return_if_fail (iter != NULL);
-
- choices = NULL;
G_LOCK (proxy_op);
data = g_hash_table_lookup (id_to_op, wrapped_id);
@@ -278,21 +240,6 @@ g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
goto out;
}
- dbus_message_iter_get_basic (iter, &message);
- dbus_message_iter_next (iter);
-
- choices = g_ptr_array_new ();
- dbus_message_iter_recurse (iter, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
- {
- const gchar *choice;
- dbus_message_iter_get_basic (&iter_array, &choice);
- dbus_message_iter_next (&iter_array);
-
- g_ptr_array_add (choices, g_strdup (choice));
- }
- g_ptr_array_add (choices, NULL);
-
if (data->reply_handler_id == 0)
{
data->reply_handler_id = g_signal_connect (data->op,
@@ -304,28 +251,27 @@ g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
g_signal_emit_by_name (data->op,
"ask-question",
message,
- choices->pdata);
+ choices);
out:
- g_ptr_array_free (choices, TRUE);
+ ;
}
/* ---------------------------------------------------------------------------------------------------- */
void
-g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
- DBusMessageIter *iter)
+g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
+ const gchar *message,
+ GVariant *pids,
+ const gchar *const *choices)
{
ProxyMountOpData *data;
- const gchar *message;
- GPtrArray *choices;
GArray *processes;
- DBusMessageIter iter_array;
+ GVariantIter iter;
+ GPid pid;
g_return_if_fail (wrapped_id != NULL);
- g_return_if_fail (iter != NULL);
- choices = NULL;
processes = NULL;
G_LOCK (proxy_op);
@@ -340,34 +286,12 @@ g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
goto out;
}
- dbus_message_iter_get_basic (iter, &message);
- dbus_message_iter_next (iter);
-
+
processes = g_array_new (FALSE, FALSE, sizeof (GPid));
- dbus_message_iter_recurse (iter, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
- {
- GPid pid;
-
- dbus_message_iter_get_basic (&iter_array, &pid);
- dbus_message_iter_next (&iter_array);
- g_array_append_val (processes, pid);
- }
-
- dbus_message_iter_next (iter);
-
- choices = g_ptr_array_new ();
- dbus_message_iter_recurse (iter, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
- {
- const gchar *choice;
- dbus_message_iter_get_basic (&iter_array, &choice);
- dbus_message_iter_next (&iter_array);
-
- g_ptr_array_add (choices, g_strdup (choice));
- }
- g_ptr_array_add (choices, NULL);
-
+ g_variant_iter_init (&iter, pids);
+ while (g_variant_iter_loop (&iter, "i", &pid))
+ g_array_append_val (processes, pid);
+
if (data->reply_handler_id == 0)
{
data->reply_handler_id = g_signal_connect (data->op,
@@ -380,11 +304,9 @@ g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
"show-processes",
message,
processes,
- choices->pdata);
+ choices);
out:
- if (choices)
- g_ptr_array_free (choices, TRUE);
if (processes)
g_array_unref (processes);
}
@@ -392,13 +314,11 @@ g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
/* ---------------------------------------------------------------------------------------------------- */
void
-g_proxy_mount_operation_handle_aborted (const gchar *wrapped_id,
- DBusMessageIter *iter)
+g_proxy_mount_operation_handle_aborted (const gchar *wrapped_id)
{
ProxyMountOpData *data;
g_return_if_fail (wrapped_id != NULL);
- g_return_if_fail (iter != NULL);
G_LOCK (proxy_op);
data = g_hash_table_lookup (id_to_op, wrapped_id);
diff --git a/monitor/proxy/gproxymountoperation.h b/monitor/proxy/gproxymountoperation.h
index a57b50e..a7d51b8 100644
--- a/monitor/proxy/gproxymountoperation.h
+++ b/monitor/proxy/gproxymountoperation.h
@@ -34,17 +34,22 @@ G_BEGIN_DECLS
const gchar *g_proxy_mount_operation_wrap (GMountOperation *op,
GProxyVolumeMonitor *monitor);
-void g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
- DBusMessageIter *iter);
-
-void g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
- DBusMessageIter *iter);
-
-void g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
- DBusMessageIter *iter);
-
-void g_proxy_mount_operation_handle_aborted (const gchar *wrapped_id,
- DBusMessageIter *iter);
+void g_proxy_mount_operation_handle_ask_password (const gchar *wrapped_id,
+ const gchar *message,
+ const gchar *default_user,
+ const gchar *default_domain,
+ guint flags);
+
+void g_proxy_mount_operation_handle_ask_question (const gchar *wrapped_id,
+ const gchar *message,
+ const gchar *const *choices);
+
+void g_proxy_mount_operation_handle_show_processes (const gchar *wrapped_id,
+ const gchar *message,
+ GVariant *pids,
+ const gchar *const *choices);
+
+void g_proxy_mount_operation_handle_aborted (const gchar *wrapped_id);
void g_proxy_mount_operation_destroy (const gchar *wrapped_id);
diff --git a/monitor/proxy/gproxyshadowmount.c b/monitor/proxy/gproxyshadowmount.c
index f8a5dfb..dede082 100644
--- a/monitor/proxy/gproxyshadowmount.c
+++ b/monitor/proxy/gproxyshadowmount.c
@@ -31,8 +31,6 @@
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
-#include <gvfsdbusutils.h>
-
#include "gproxyvolumemonitor.h"
#include "gproxyshadowmount.h"
#include "gproxyvolume.h"
diff --git a/monitor/proxy/gproxyvolume.c b/monitor/proxy/gproxyvolume.c
index d70ebc6..14f382d 100644
--- a/monitor/proxy/gproxyvolume.c
+++ b/monitor/proxy/gproxyvolume.c
@@ -31,8 +31,6 @@
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
-#include <gvfsdbusutils.h>
-
#include "gproxydrive.h"
#include "gproxyvolume.h"
#include "gproxymount.h"
@@ -190,7 +188,6 @@ g_proxy_volume_new (GProxyVolumeMonitor *volume_monitor)
return volume;
}
-
static void
union_monitor_mount_added (GVolumeMonitor *union_monitor,
GMount *mount,
@@ -351,10 +348,11 @@ update_shadow_mount_in_idle (GProxyVolume *volume)
* dict:string->string identifiers
*/
+#define VOLUME_STRUCT_TYPE "(&s&s&s&s&sbb&s&sa{ss})"
+
void g_proxy_volume_update (GProxyVolume *volume,
- DBusMessageIter *iter)
+ GVariant *iter)
{
- DBusMessageIter iter_struct;
const char *id;
const char *name;
const char *gicon_data;
@@ -362,32 +360,20 @@ void g_proxy_volume_update (GProxyVolume *volume,
const char *activation_uri;
const char *drive_id;
const char *mount_id;
- dbus_bool_t can_mount;
- dbus_bool_t should_automount;
+ gboolean can_mount;
+ gboolean should_automount;
GHashTable *identifiers;
+ GVariantIter *iter_identifiers;
- dbus_message_iter_recurse (iter, &iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &id);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &name);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &gicon_data);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &uuid);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &activation_uri);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &can_mount);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &should_automount);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &drive_id);
- dbus_message_iter_next (&iter_struct);
- dbus_message_iter_get_basic (&iter_struct, &mount_id);
- dbus_message_iter_next (&iter_struct);
-
- identifiers = _get_identifiers (&iter_struct);
- dbus_message_iter_next (&iter_struct);
+
+ g_variant_get (iter, VOLUME_STRUCT_TYPE,
+ &id, &name, &gicon_data,
+ &uuid, &activation_uri,
+ &can_mount, &should_automount,
+ &drive_id, &mount_id,
+ &iter_identifiers);
+
+ identifiers = _get_identifiers (iter_identifiers);
if (volume->id != NULL && strcmp (volume->id, id) != 0)
{
@@ -433,6 +419,7 @@ void g_proxy_volume_update (GProxyVolume *volume,
update_shadow_mount_in_idle (volume);
out:
+ g_variant_iter_free (iter_identifiers);
g_hash_table_unref (identifiers);
}
@@ -722,10 +709,17 @@ typedef struct {
} DBusOp;
static void
-mount_cb (DBusMessage *reply,
- GError *error,
- DBusOp *data)
+mount_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ DBusOp *data = user_data;
+ GError *error = NULL;
+
+ gvfs_remote_volume_monitor_call_volume_mount_finish (proxy,
+ res,
+ &error);
+
if (data->cancelled_handler_id > 0)
g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
@@ -756,6 +750,8 @@ mount_cb (DBusMessage *reply,
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
typedef struct
@@ -777,13 +773,20 @@ mount_foreign_callback (GObject *source_object,
}
static void
-cancel_operation_reply_cb (DBusMessage *reply,
- GError *error,
- gpointer user_data)
+cancel_operation_reply_cb (GVfsRemoteVolumeMonitor *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- if (error != NULL)
+ gboolean out_WasCancelled;
+ GError *error = NULL;
+
+ if (!gvfs_remote_volume_monitor_call_cancel_operation_finish (proxy,
+ &out_WasCancelled,
+ res,
+ &error))
{
g_warning ("Error from CancelOperation(): %s", error->message);
+ g_error_free (error);
}
}
@@ -793,9 +796,7 @@ mount_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_volume);
@@ -809,26 +810,15 @@ mount_cancelled (GCancellable *cancellable,
g_object_unref (simple);
/* Now tell the remote volume monitor that the op has been cancelled */
- connection = g_proxy_volume_monitor_get_dbus_connection (data->volume->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (data->volume->volume_monitor);
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "CancelOperation");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_INVALID);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (data->volume->volume_monitor);
+ gvfs_remote_volume_monitor_call_cancel_operation (proxy,
+ data->cancellation_id,
+ NULL,
+ (GAsyncReadyCallback) cancel_operation_reply_cb,
+ NULL);
+ g_object_unref (proxy);
G_UNLOCK (proxy_volume);
-
- _g_dbus_connection_call_async (connection,
- message,
- -1,
- (GAsyncDBusCallback) cancel_operation_reply_cb,
- NULL);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
}
static void
@@ -868,10 +858,7 @@ g_proxy_volume_mount (GVolume *volume,
else
{
DBusOp *data;
- DBusConnection *connection;
- const char *name;
- DBusMessage *message;
- dbus_uint32_t _flags = flags;
+ GVfsRemoteVolumeMonitor *proxy;
if (g_cancellable_is_cancelled (cancellable))
{
@@ -908,32 +895,18 @@ g_proxy_volume_mount (GVolume *volume,
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_volume->volume_monitor);
- connection = g_proxy_volume_monitor_get_dbus_connection (proxy_volume->volume_monitor);
- name = g_proxy_volume_monitor_get_dbus_name (proxy_volume->volume_monitor);
-
- message = dbus_message_new_method_call (name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "VolumeMount");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING,
- &(proxy_volume->id),
- DBUS_TYPE_STRING,
- &(data->cancellation_id),
- DBUS_TYPE_UINT32,
- &_flags,
- DBUS_TYPE_STRING,
- &(data->mount_op_id),
- DBUS_TYPE_INVALID);
- G_UNLOCK (proxy_volume);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_volume->volume_monitor);
+ gvfs_remote_volume_monitor_call_volume_mount (proxy,
+ proxy_volume->id,
+ data->cancellation_id,
+ flags,
+ data->mount_op_id,
+ NULL,
+ (GAsyncReadyCallback) mount_cb,
+ data);
+ g_object_unref (proxy);
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT, /* 30 minute timeout */
- (GAsyncDBusCallback) mount_cb,
- data);
- dbus_message_unref (message);
- dbus_connection_unref (connection);
+ G_UNLOCK (proxy_volume);
}
out:
diff --git a/monitor/proxy/gproxyvolume.h b/monitor/proxy/gproxyvolume.h
index 953b800..0c6a2c4 100644
--- a/monitor/proxy/gproxyvolume.h
+++ b/monitor/proxy/gproxyvolume.h
@@ -47,7 +47,7 @@ struct _GProxyVolumeClass {
GType g_proxy_volume_get_type (void) G_GNUC_CONST;
GProxyVolume *g_proxy_volume_new (GProxyVolumeMonitor *volume_monitor);
void g_proxy_volume_update (GProxyVolume *volume,
- DBusMessageIter *iter);
+ GVariant *iter);
const char *g_proxy_volume_get_id (GProxyVolume *volume);
void g_proxy_volume_register (GIOModule *module);
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index f4936e2..4fdbef9 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -35,30 +35,30 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
-#include <gvfsdbusutils.h>
#include "gproxyvolumemonitor.h"
#include "gproxymount.h"
#include "gproxyvolume.h"
#include "gproxydrive.h"
#include "gproxymountoperation.h"
+#include "gvfsvolumemonitordbus.h"
G_LOCK_DEFINE_STATIC(proxy_vm);
-static DBusConnection *the_session_bus = NULL;
-static gboolean the_session_bus_is_integrated = FALSE;
+static GDBusConnection *the_session_bus = NULL;
static GHashTable *the_volume_monitors = NULL;
struct _GProxyVolumeMonitor {
GNativeVolumeMonitor parent;
- DBusConnection *session_bus;
+
+ guint name_owner_id;
+ GVfsRemoteVolumeMonitor *proxy;
GHashTable *drives;
GHashTable *volumes;
GHashTable *mounts;
- /* The unique D-Bus name of the remote monitor or NULL if disconnected */
- gchar *unique_name;
+ gulong name_watcher_id;
};
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyVolumeMonitor,
@@ -67,9 +67,9 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GProxyVolumeMonitor,
G_TYPE_FLAG_ABSTRACT,
{})
-static void seed_monitor (GProxyVolumeMonitor *monitor);
+static gboolean g_proxy_volume_monitor_setup_session_bus_connection (void);
-static DBusHandlerResult filter_function (DBusConnection *connection, DBusMessage *message, void *user_data);
+static void seed_monitor (GProxyVolumeMonitor *monitor);
static void signal_emit_in_idle (gpointer object, const char *signal_name, gpointer other_object);
@@ -99,31 +99,10 @@ static is_supported_func is_supported_funcs[] = {
NULL
};
-static char *
-get_match_rule_for_signals (GProxyVolumeMonitor *monitor)
-{
- return g_strdup_printf ("type='signal',"
- "interface='org.gtk.Private.RemoteVolumeMonitor',"
- "sender='%s',",
- g_proxy_volume_monitor_get_dbus_name (monitor));
-}
-
-static char *
-get_match_rule_for_name_owner_changed (GProxyVolumeMonitor *monitor)
-{
- return g_strdup_printf ("type='signal',"
- "interface='org.freedesktop.DBus',"
- "member='NameOwnerChanged',"
- "arg0='%s'",
- g_proxy_volume_monitor_get_dbus_name (monitor));
-}
-
static void
g_proxy_volume_monitor_finalize (GObject *object)
{
GProxyVolumeMonitor *monitor;
- DBusError dbus_error;
- char *match_rule;
GObjectClass *parent_class;
/* since GProxyVolumeMonitor is a non-instantiatable type we're dealing with a
@@ -134,38 +113,16 @@ g_proxy_volume_monitor_finalize (GObject *object)
monitor = G_PROXY_VOLUME_MONITOR (object);
+ if (monitor->name_watcher_id > 0)
+ g_bus_unwatch_name (monitor->name_watcher_id);
+
g_hash_table_unref (monitor->drives);
g_hash_table_unref (monitor->volumes);
g_hash_table_unref (monitor->mounts);
- g_free (monitor->unique_name);
-
- dbus_connection_remove_filter (monitor->session_bus, filter_function, monitor);
-
- match_rule = get_match_rule_for_signals (monitor);
- dbus_error_init (&dbus_error);
- dbus_bus_remove_match (monitor->session_bus,
- 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);
- }
- g_free (match_rule);
-
- match_rule = get_match_rule_for_name_owner_changed (monitor);
- dbus_error_init (&dbus_error);
- dbus_bus_remove_match (monitor->session_bus,
- 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);
- }
- g_free (match_rule);
-
- dbus_connection_unref (monitor->session_bus);
-
+ if (monitor->proxy != NULL)
+ g_object_unref (monitor->proxy);
+
if (parent_class->finalize)
parent_class->finalize (object);
}
@@ -413,6 +370,569 @@ volume_monitor_went_away (gpointer data,
G_UNLOCK (proxy_vm);
}
+static void
+drive_changed (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Drive,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyDrive *d;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ d = g_hash_table_lookup (monitor->drives, Id);
+ if (d != NULL)
+ {
+ g_proxy_drive_update (d, Drive);
+ signal_emit_in_idle (d, "changed", NULL);
+ signal_emit_in_idle (monitor, "drive-changed", d);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+drive_connected (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Drive,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyDrive *d;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ d = g_hash_table_lookup (monitor->drives, Id);
+ if (d == NULL)
+ {
+ d = g_proxy_drive_new (monitor);
+ g_proxy_drive_update (d, Drive);
+ g_hash_table_insert (monitor->drives, g_strdup (g_proxy_drive_get_id (d)), d);
+ signal_emit_in_idle (monitor, "drive-connected", d);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+drive_disconnected (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Drive,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyDrive *d;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ d = g_hash_table_lookup (monitor->drives, Id);
+ if (d != NULL)
+ {
+ g_object_ref (d);
+ g_hash_table_remove (monitor->drives, Id);
+ signal_emit_in_idle (d, "disconnected", NULL);
+ signal_emit_in_idle (monitor, "drive-disconnected", d);
+ g_object_unref (d);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+drive_eject_button (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Drive,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyDrive *d;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ d = g_hash_table_lookup (monitor->drives, Id);
+ if (d != NULL)
+ {
+ signal_emit_in_idle (d, "eject-button", NULL);
+ signal_emit_in_idle (monitor, "drive-eject-button", d);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+drive_stop_button (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Drive,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyDrive *d;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ d = g_hash_table_lookup (monitor->drives, Id);
+ if (d != NULL)
+ {
+ signal_emit_in_idle (d, "stop-button", NULL);
+ signal_emit_in_idle (monitor, "drive-stop-button", d);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_added (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Mount,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyMount *m;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ m = g_hash_table_lookup (monitor->mounts, Id);
+ if (m == NULL)
+ {
+ m = g_proxy_mount_new (monitor);
+ g_proxy_mount_update (m, Mount);
+ g_hash_table_insert (monitor->mounts, g_strdup (g_proxy_mount_get_id (m)), m);
+ signal_emit_in_idle (monitor, "mount-added", m);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_changed (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Mount,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyMount *m;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ m = g_hash_table_lookup (monitor->mounts, Id);
+ if (m != NULL)
+ {
+ g_proxy_mount_update (m, Mount);
+ signal_emit_in_idle (m, "changed", NULL);
+ signal_emit_in_idle (monitor, "mount-changed", m);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_pre_unmount (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Mount,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyMount *m;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ m = g_hash_table_lookup (monitor->mounts, Id);
+ if (m != NULL)
+ {
+ signal_emit_in_idle (m, "pre-unmount", NULL);
+ signal_emit_in_idle (monitor, "mount-pre-unmount", m);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_removed (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Mount,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyMount *m;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ m = g_hash_table_lookup (monitor->mounts, Id);
+ if (m != NULL)
+ {
+ g_object_ref (m);
+ g_hash_table_remove (monitor->mounts, Id);
+ signal_emit_in_idle (m, "unmounted", NULL);
+ signal_emit_in_idle (monitor, "mount-removed", m);
+ g_object_unref (m);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_op_aborted (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ g_proxy_mount_operation_handle_aborted (Id);
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_op_ask_password (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ const gchar *MessageToShow,
+ const gchar *DefaultUser,
+ const gchar *DefaultDomain,
+ guint Flags,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ g_proxy_mount_operation_handle_ask_password (Id,
+ MessageToShow,
+ DefaultUser,
+ DefaultDomain,
+ Flags);
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_op_ask_question (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ const gchar *MessageToShow,
+ const gchar *const *Choices,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ g_proxy_mount_operation_handle_ask_question (Id,
+ MessageToShow,
+ Choices);
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+mount_op_show_processes (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ const gchar *MessageToShow,
+ GVariant *Pid,
+ const gchar *const *Choices,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ g_proxy_mount_operation_handle_show_processes (Id,
+ MessageToShow,
+ Pid,
+ Choices);
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+volume_added (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Volume,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyVolume *v;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ v = g_hash_table_lookup (monitor->volumes, Id);
+ if (v == NULL)
+ {
+ v = g_proxy_volume_new (monitor);
+ g_proxy_volume_update (v, Volume);
+ g_hash_table_insert (monitor->volumes, g_strdup (g_proxy_volume_get_id (v)), v);
+ signal_emit_in_idle (monitor, "volume-added", v);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+volume_changed (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Volume,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyVolume *v;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ v = g_hash_table_lookup (monitor->volumes, Id);
+ if (v != NULL)
+ {
+ GProxyShadowMount *shadow_mount;
+
+ g_proxy_volume_update (v, Volume);
+ signal_emit_in_idle (v, "changed", NULL);
+ signal_emit_in_idle (monitor, "volume-changed", v);
+
+ shadow_mount = g_proxy_volume_get_shadow_mount (v);
+ if (shadow_mount != NULL)
+ {
+ signal_emit_in_idle (shadow_mount, "changed", NULL);
+ signal_emit_in_idle (monitor, "mount-changed", shadow_mount);
+ g_object_unref (shadow_mount);
+ }
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+volume_removed (GVfsRemoteVolumeMonitor *object,
+ const gchar *TheDBusName,
+ const gchar *Id,
+ GVariant *Volume,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GProxyVolume *v;
+
+ G_LOCK (proxy_vm);
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ if (strcmp (TheDBusName, klass->dbus_name) != 0)
+ goto not_for_us;
+
+ v = g_hash_table_lookup (monitor->volumes, Id);
+ if (v != NULL)
+ {
+ g_object_ref (v);
+ g_hash_table_remove (monitor->volumes, Id);
+ signal_emit_in_idle (v, "removed", NULL);
+ signal_emit_in_idle (monitor, "volume-removed", v);
+ dispose_in_idle (v);
+ g_object_unref (v);
+ }
+
+ not_for_us:
+ G_UNLOCK (proxy_vm);
+}
+
+static void
+on_name_owner_appeared (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GHashTableIter hash_iter;
+ GProxyDrive *drive;
+ GProxyVolume *volume;
+ GProxyMount *mount;
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ g_warning ("New owner %s for volume monitor %s connected to the bus; seeding drives/volumes/mounts",
+ name_owner,
+ klass->dbus_name);
+
+ seed_monitor (monitor);
+
+ /* emit signals for all the drives/volumes/mounts "added" */
+ g_hash_table_iter_init (&hash_iter, monitor->drives);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &drive))
+ signal_emit_in_idle (monitor, "drive-connected", drive);
+
+ g_hash_table_iter_init (&hash_iter, monitor->volumes);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume))
+ signal_emit_in_idle (monitor, "volume-added", volume);
+
+ g_hash_table_iter_init (&hash_iter, monitor->mounts);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount))
+ signal_emit_in_idle (monitor, "mount-added", mount);
+}
+
+static void
+on_name_owner_vanished (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
+ GProxyVolumeMonitorClass *klass;
+ GHashTableIter hash_iter;
+ GProxyDrive *drive;
+ GProxyVolume *volume;
+ GProxyMount *mount;
+
+ klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
+
+ g_warning ("Owner of %s of volume monitor %s disconnected from the bus; removing drives/volumes/mounts",
+ name,
+ klass->dbus_name);
+
+ g_hash_table_iter_init (&hash_iter, monitor->mounts);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount))
+ {
+ signal_emit_in_idle (mount, "unmounted", NULL);
+ signal_emit_in_idle (monitor, "mount-removed", mount);
+ }
+ g_hash_table_remove_all (monitor->mounts);
+
+ g_hash_table_iter_init (&hash_iter, monitor->volumes);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume))
+ {
+ signal_emit_in_idle (volume, "removed", NULL);
+ signal_emit_in_idle (monitor, "volume-removed", volume);
+ }
+ g_hash_table_remove_all (monitor->volumes);
+
+ g_hash_table_iter_init (&hash_iter, monitor->drives);
+ while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &drive))
+ {
+ signal_emit_in_idle (drive, "disconnected", NULL);
+ signal_emit_in_idle (monitor, "drive-disconnected", drive);
+ }
+ g_hash_table_remove_all (monitor->drives);
+
+ /* TODO: maybe try to relaunch the monitor? */
+}
+
static GObject *
g_proxy_volume_monitor_constructor (GType type,
guint n_construct_properties,
@@ -422,8 +942,8 @@ g_proxy_volume_monitor_constructor (GType type,
GProxyVolumeMonitor *monitor;
GProxyVolumeMonitorClass *klass;
GObjectClass *parent_class;
- DBusError dbus_error;
- char *match_rule;
+ GError *error;
+ const char *dbus_name;
G_LOCK (proxy_vm);
@@ -435,6 +955,8 @@ g_proxy_volume_monitor_constructor (GType type,
goto out;
}
+ dbus_name = klass->dbus_name;
+
/* Invoke parent constructor. */
klass = G_PROXY_VOLUME_MONITOR_CLASS (g_type_class_peek (G_TYPE_PROXY_VOLUME_MONITOR));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
@@ -444,37 +966,52 @@ g_proxy_volume_monitor_constructor (GType type,
monitor = G_PROXY_VOLUME_MONITOR (object);
- dbus_error_init (&dbus_error);
- monitor->session_bus = dbus_connection_ref (the_session_bus);
+ error = NULL;
+ monitor->proxy = gvfs_remote_volume_monitor_proxy_new_sync (the_session_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ dbus_name,
+ "/org/gtk/Private/RemoteVolumeMonitor",
+ NULL,
+ &error);
+ if (monitor->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);
+ goto out;
+ }
+
+ /* listen to volume monitor signals */
+ g_signal_connect (monitor->proxy, "drive-changed", G_CALLBACK (drive_changed), monitor);
+ g_signal_connect (monitor->proxy, "drive-connected", G_CALLBACK (drive_connected), monitor);
+ g_signal_connect (monitor->proxy, "drive-disconnected", G_CALLBACK (drive_disconnected), monitor);
+ g_signal_connect (monitor->proxy, "drive-eject-button", G_CALLBACK (drive_eject_button), monitor);
+ g_signal_connect (monitor->proxy, "drive-stop-button", G_CALLBACK (drive_stop_button), monitor);
+ g_signal_connect (monitor->proxy, "mount-added", G_CALLBACK (mount_added), monitor);
+ g_signal_connect (monitor->proxy, "mount-changed", G_CALLBACK (mount_changed), monitor);
+ g_signal_connect (monitor->proxy, "mount-op-aborted", G_CALLBACK (mount_op_aborted), monitor);
+ g_signal_connect (monitor->proxy, "mount-op-ask-password", G_CALLBACK (mount_op_ask_password), monitor);
+ g_signal_connect (monitor->proxy, "mount-op-ask-question", G_CALLBACK (mount_op_ask_question), monitor);
+ g_signal_connect (monitor->proxy, "mount-op-show-processes", G_CALLBACK (mount_op_show_processes), monitor);
+ g_signal_connect (monitor->proxy, "mount-pre-unmount", G_CALLBACK (mount_pre_unmount), monitor);
+ g_signal_connect (monitor->proxy, "mount-removed", G_CALLBACK (mount_removed), monitor);
+ g_signal_connect (monitor->proxy, "volume-added", G_CALLBACK (volume_added), monitor);
+ g_signal_connect (monitor->proxy, "volume-changed", G_CALLBACK (volume_changed), monitor);
+ g_signal_connect (monitor->proxy, "volume-removed", G_CALLBACK (volume_removed), monitor);
+
monitor->drives = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
monitor->volumes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
monitor->mounts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- dbus_connection_add_filter (monitor->session_bus, filter_function, monitor, NULL);
-
- /* listen to volume monitor signals */
- match_rule = get_match_rule_for_signals (monitor);
- dbus_bus_add_match (monitor->session_bus,
- 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);
-
/* listen to when the owner of the service appears/disappears */
- match_rule = get_match_rule_for_name_owner_changed (monitor);
- dbus_bus_add_match (monitor->session_bus,
- 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);
-
- seed_monitor (monitor);
+ /* this will automatically call on_name_owner_appeared() when the daemon is ready and seed drives/volumes/mounts */
+ monitor->name_watcher_id = g_bus_watch_name_on_connection (the_session_bus,
+ dbus_name,
+ G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
+ on_name_owner_appeared,
+ on_name_owner_vanished,
+ monitor,
+ NULL);
g_hash_table_insert (the_volume_monitors, (gpointer) type, object);
g_object_weak_ref (G_OBJECT (object), volume_monitor_went_away, (gpointer) type);
@@ -535,336 +1072,10 @@ dispose_in_idle (gpointer object)
g_idle_add ((GSourceFunc) dispose_in_idle_do, g_object_ref (object));
}
-
-
-static DBusHandlerResult
-filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- GProxyVolumeMonitor *monitor = G_PROXY_VOLUME_MONITOR (user_data);
- DBusMessageIter iter;
- const char *id;
- const char *the_dbus_name;
- const char *member;
- GProxyDrive *drive;
- GProxyVolume *volume;
- GProxyMount *mount;
- GProxyVolumeMonitorClass *klass;
-
- G_LOCK (proxy_vm);
-
- klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (monitor));
-
- member = dbus_message_get_member (message);
-
- if (dbus_message_is_signal (message, "org.freedesktop.DBus", "NameOwnerChanged"))
- {
- GHashTableIter hash_iter;
- GProxyMount *mount;
- GProxyVolume *volume;
- GProxyDrive *drive;
- 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);
-
- if (strcmp (name, klass->dbus_name) != 0)
- goto not_for_us;
-
- if (monitor->unique_name != NULL && g_strcmp0 (new_owner, monitor->unique_name) != 0)
- {
- g_warning ("Owner %s of volume monitor %s disconnected from the bus; removing drives/volumes/mounts",
- monitor->unique_name,
- klass->dbus_name);
-
- g_hash_table_iter_init (&hash_iter, monitor->mounts);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount))
- {
- signal_emit_in_idle (mount, "unmounted", NULL);
- signal_emit_in_idle (monitor, "mount-removed", mount);
- }
- g_hash_table_remove_all (monitor->mounts);
-
- g_hash_table_iter_init (&hash_iter, monitor->volumes);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume))
- {
- signal_emit_in_idle (volume, "removed", NULL);
- signal_emit_in_idle (monitor, "volume-removed", volume);
- }
- g_hash_table_remove_all (monitor->volumes);
-
- g_hash_table_iter_init (&hash_iter, monitor->drives);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &drive))
- {
- signal_emit_in_idle (drive, "disconnected", NULL);
- signal_emit_in_idle (monitor, "drive-disconnected", drive);
- }
- g_hash_table_remove_all (monitor->drives);
-
- g_free (monitor->unique_name);
- monitor->unique_name = NULL;
-
- /* TODO: maybe try to relaunch the monitor? */
-
- }
-
- if (strlen (new_owner) > 0 && monitor->unique_name == NULL)
- {
- g_warning ("New owner %s for volume monitor %s connected to the bus; seeding drives/volumes/mounts",
- new_owner,
- klass->dbus_name);
-
- seed_monitor (monitor);
-
- /* emit signals for all the drives/volumes/mounts "added" */
- g_hash_table_iter_init (&hash_iter, monitor->drives);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &drive))
- signal_emit_in_idle (monitor, "drive-connected", drive);
-
- g_hash_table_iter_init (&hash_iter, monitor->volumes);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &volume))
- signal_emit_in_idle (monitor, "volume-added", volume);
-
- g_hash_table_iter_init (&hash_iter, monitor->mounts);
- while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &mount))
- signal_emit_in_idle (monitor, "mount-added", mount);
- }
-
- }
- else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveChanged") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveConnected") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveDisconnected") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveEjectButton") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "DriveStopButton"))
- {
-
- dbus_message_iter_init (message, &iter);
- dbus_message_iter_get_basic (&iter, &the_dbus_name);
- dbus_message_iter_next (&iter);
- dbus_message_iter_get_basic (&iter, &id);
- dbus_message_iter_next (&iter);
-
- if (strcmp (the_dbus_name, klass->dbus_name) != 0)
- goto not_for_us;
-
- if (strcmp (member, "DriveChanged") == 0)
- {
- drive = g_hash_table_lookup (monitor->drives, id);
- if (drive != NULL)
- {
- g_proxy_drive_update (drive, &iter);
- signal_emit_in_idle (drive, "changed", NULL);
- signal_emit_in_idle (monitor, "drive-changed", drive);
- }
- }
- else if (strcmp (member, "DriveConnected") == 0)
- {
- drive = g_hash_table_lookup (monitor->drives, id);
- if (drive == NULL)
- {
- drive = g_proxy_drive_new (monitor);
- g_proxy_drive_update (drive, &iter);
- g_hash_table_insert (monitor->drives, g_strdup (g_proxy_drive_get_id (drive)), drive);
- signal_emit_in_idle (monitor, "drive-connected", drive);
- }
- }
- else if (strcmp (member, "DriveDisconnected") == 0)
- {
- drive = g_hash_table_lookup (monitor->drives, id);
- if (drive != NULL)
- {
- g_object_ref (drive);
- g_hash_table_remove (monitor->drives, id);
- signal_emit_in_idle (drive, "disconnected", NULL);
- signal_emit_in_idle (monitor, "drive-disconnected", drive);
- g_object_unref (drive);
- }
- }
- else if (strcmp (member, "DriveEjectButton") == 0)
- {
- drive = g_hash_table_lookup (monitor->drives, id);
- if (drive != NULL)
- {
- signal_emit_in_idle (drive, "eject-button", NULL);
- signal_emit_in_idle (monitor, "drive-eject-button", drive);
- }
- }
- else if (strcmp (member, "DriveStopButton") == 0)
- {
- drive = g_hash_table_lookup (monitor->drives, id);
- if (drive != NULL)
- {
- signal_emit_in_idle (drive, "stop-button", NULL);
- signal_emit_in_idle (monitor, "drive-stop-button", drive);
- }
- }
-
- }
- else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeChanged") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeAdded") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "VolumeRemoved"))
- {
- dbus_message_iter_init (message, &iter);
- dbus_message_iter_get_basic (&iter, &the_dbus_name);
- dbus_message_iter_next (&iter);
- dbus_message_iter_get_basic (&iter, &id);
- dbus_message_iter_next (&iter);
-
- if (strcmp (the_dbus_name, klass->dbus_name) != 0)
- goto not_for_us;
-
- if (strcmp (member, "VolumeChanged") == 0)
- {
- volume = g_hash_table_lookup (monitor->volumes, id);
- if (volume != NULL)
- {
- GProxyShadowMount *shadow_mount;
-
- g_proxy_volume_update (volume, &iter);
- signal_emit_in_idle (volume, "changed", NULL);
- signal_emit_in_idle (monitor, "volume-changed", volume);
-
- shadow_mount = g_proxy_volume_get_shadow_mount (volume);
- if (shadow_mount != NULL)
- {
- signal_emit_in_idle (shadow_mount, "changed", NULL);
- signal_emit_in_idle (monitor, "mount-changed", shadow_mount);
- g_object_unref (shadow_mount);
- }
- }
- }
- else if (strcmp (member, "VolumeAdded") == 0)
- {
- volume = g_hash_table_lookup (monitor->volumes, id);
- if (volume == NULL)
- {
- volume = g_proxy_volume_new (monitor);
- g_proxy_volume_update (volume, &iter);
- g_hash_table_insert (monitor->volumes, g_strdup (g_proxy_volume_get_id (volume)), volume);
- signal_emit_in_idle (monitor, "volume-added", volume);
- }
- }
- else if (strcmp (member, "VolumeRemoved") == 0)
- {
- volume = g_hash_table_lookup (monitor->volumes, id);
- if (volume != NULL)
- {
- g_object_ref (volume);
- g_hash_table_remove (monitor->volumes, id);
- signal_emit_in_idle (volume, "removed", NULL);
- signal_emit_in_idle (monitor, "volume-removed", volume);
- dispose_in_idle (volume);
- g_object_unref (volume);
- }
- }
-
- }
- else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountChanged") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountAdded") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountPreUnmount") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountRemoved"))
- {
-
- dbus_message_iter_init (message, &iter);
- dbus_message_iter_get_basic (&iter, &the_dbus_name);
- dbus_message_iter_next (&iter);
- dbus_message_iter_get_basic (&iter, &id);
- dbus_message_iter_next (&iter);
-
- if (strcmp (the_dbus_name, klass->dbus_name) != 0)
- goto not_for_us;
-
- if (strcmp (member, "MountChanged") == 0)
- {
- mount = g_hash_table_lookup (monitor->mounts, id);
- if (mount != NULL)
- {
- g_proxy_mount_update (mount, &iter);
- signal_emit_in_idle (mount, "changed", NULL);
- signal_emit_in_idle (monitor, "mount-changed", mount);
- }
- }
- else if (strcmp (member, "MountAdded") == 0)
- {
- mount = g_hash_table_lookup (monitor->mounts, id);
- if (mount == NULL)
- {
- mount = g_proxy_mount_new (monitor);
- g_proxy_mount_update (mount, &iter);
- g_hash_table_insert (monitor->mounts, g_strdup (g_proxy_mount_get_id (mount)), mount);
- signal_emit_in_idle (monitor, "mount-added", mount);
- }
- }
- else if (strcmp (member, "MountPreUnmount") == 0)
- {
- mount = g_hash_table_lookup (monitor->mounts, id);
- if (mount != NULL)
- {
- signal_emit_in_idle (mount, "pre-unmount", NULL);
- signal_emit_in_idle (monitor, "mount-pre-unmount", mount);
- }
- }
- else if (strcmp (member, "MountRemoved") == 0)
- {
- mount = g_hash_table_lookup (monitor->mounts, id);
- if (mount != NULL)
- {
- g_object_ref (mount);
- g_hash_table_remove (monitor->mounts, id);
- signal_emit_in_idle (mount, "unmounted", NULL);
- signal_emit_in_idle (monitor, "mount-removed", mount);
- g_object_unref (mount);
- }
- }
- }
- else if (dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountOpAskPassword") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountOpAskQuestion") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountOpShowProcesses") ||
- dbus_message_is_signal (message, "org.gtk.Private.RemoteVolumeMonitor", "MountOpAborted"))
- {
- dbus_message_iter_init (message, &iter);
- dbus_message_iter_get_basic (&iter, &the_dbus_name);
- dbus_message_iter_next (&iter);
- dbus_message_iter_get_basic (&iter, &id);
- dbus_message_iter_next (&iter);
-
- if (strcmp (the_dbus_name, klass->dbus_name) != 0)
- goto not_for_us;
-
- if (strcmp (member, "MountOpAskPassword") == 0)
- {
- g_proxy_mount_operation_handle_ask_password (id, &iter);
- }
- else if (strcmp (member, "MountOpAskQuestion") == 0)
- {
- g_proxy_mount_operation_handle_ask_question (id, &iter);
- }
- else if (strcmp (member, "MountOpShowProcesses") == 0)
- {
- g_proxy_mount_operation_handle_show_processes (id, &iter);
- }
- else if (strcmp (member, "MountOpAborted") == 0)
- {
- g_proxy_mount_operation_handle_aborted (id, &iter);
- }
- }
-
- not_for_us:
- G_UNLOCK (proxy_vm);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
static void
g_proxy_volume_monitor_init (GProxyVolumeMonitor *monitor)
{
- g_proxy_volume_monitor_setup_session_bus_connection (TRUE);
+ g_proxy_volume_monitor_setup_session_bus_connection ();
}
static void
@@ -899,6 +1110,7 @@ static void
g_proxy_volume_monitor_class_intern_init_pre (GProxyVolumeMonitorClass *klass, gconstpointer class_data)
{
ProxyClassData *data = (ProxyClassData *) class_data;
+
klass->dbus_name = g_strdup (data->dbus_name);
klass->is_native = data->is_native;
klass->is_supported_nr = data->is_supported_nr;
@@ -908,56 +1120,45 @@ g_proxy_volume_monitor_class_intern_init_pre (GProxyVolumeMonitorClass *klass, g
static gboolean
is_remote_monitor_supported (const char *dbus_name)
{
- DBusMessage *message;
- DBusMessage *reply;
- DBusError dbus_error;
- dbus_bool_t is_supported;
+ gboolean is_supported;
+ GVfsRemoteVolumeMonitor *proxy;
+ GError *error;
- message = NULL;
- reply = NULL;
is_supported = FALSE;
+ error = NULL;
- message = dbus_message_new_method_call (dbus_name,
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "IsSupported");
- if (message == NULL)
- {
- g_warning ("Cannot allocate memory for DBusMessage");
- goto fail;
- }
- dbus_error_init (&dbus_error);
- reply = dbus_connection_send_with_reply_and_block (the_session_bus,
- message,
- -1,
- &dbus_error);
- if (dbus_error_is_set (&dbus_error))
+ proxy = gvfs_remote_volume_monitor_proxy_new_sync (the_session_bus,
+ G_DBUS_PROXY_FLAGS_NONE,
+ dbus_name,
+ "/org/gtk/Private/RemoteVolumeMonitor",
+ NULL,
+ &error);
+ if (proxy == NULL)
{
- g_warning ("invoking IsSupported() failed for remote volume monitor with dbus name %s: %s: %s",
- dbus_name,
- dbus_error.name,
- dbus_error.message);
- dbus_error_free (&dbus_error);
- goto fail;
+ g_printerr ("Error creating proxy: %s (%s, %d)\n",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
}
- if (!dbus_message_get_args (reply, &dbus_error,
- DBUS_TYPE_BOOLEAN, &is_supported,
- DBUS_TYPE_INVALID))
+ error = NULL;
+ if (!gvfs_remote_volume_monitor_call_is_supported_sync (proxy,
+ &is_supported,
+ NULL,
+ &error))
{
- g_warning ("Error parsing args in reply for IsSupported(): %s: %s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- goto fail;
+ g_printerr ("invoking IsSupported() failed for remote volume monitor with dbus name %s:: %s (%s, %d)\n",
+ dbus_name, error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
}
-
+
if (!is_supported)
g_warning ("remote volume monitor with dbus name %s is not supported", dbus_name);
- fail:
- if (message != NULL)
- dbus_message_unref (message);
- if (reply != NULL)
- dbus_message_unref (reply);
+ out:
+ if (proxy != NULL)
+ g_object_unref (proxy);
return is_supported;
}
@@ -967,7 +1168,7 @@ is_supported (GProxyVolumeMonitorClass *klass)
gboolean res;
G_LOCK (proxy_vm);
- res = g_proxy_volume_monitor_setup_session_bus_connection (FALSE);
+ res = g_proxy_volume_monitor_setup_session_bus_connection ();
G_UNLOCK (proxy_vm);
if (res)
@@ -1005,86 +1206,70 @@ g_proxy_volume_monitor_class_init (GProxyVolumeMonitorClass *klass)
static void
seed_monitor (GProxyVolumeMonitor *monitor)
{
- DBusMessage *message;
- DBusMessage *reply;
- DBusError dbus_error;
- DBusMessageIter iter_reply;
- DBusMessageIter iter_array;
-
- message = dbus_message_new_method_call (g_proxy_volume_monitor_get_dbus_name (monitor),
- "/org/gtk/Private/RemoteVolumeMonitor",
- "org.gtk.Private.RemoteVolumeMonitor",
- "List");
- if (message == NULL)
- {
- g_warning ("Cannot allocate memory for DBusMessage");
- goto fail;
- }
- dbus_error_init (&dbus_error);
- reply = dbus_connection_send_with_reply_and_block (monitor->session_bus,
- message,
- -1,
- &dbus_error);
- dbus_message_unref (message);
- if (dbus_error_is_set (&dbus_error))
+ GVariant *Drives;
+ GVariant *Volumes;
+ GVariant *Mounts;
+ GVariantIter iter;
+ GVariant *child;
+ GError *error;
+
+ error = NULL;
+ if (!gvfs_remote_volume_monitor_call_list_sync (monitor->proxy,
+ &Drives,
+ &Volumes,
+ &Mounts,
+ NULL,
+ &error))
{
- g_warning ("invoking List() failed for type %s: %s: %s",
+ g_warning ("invoking List() failed for type %s: %s (%s, %d)",
G_OBJECT_TYPE_NAME (monitor),
- dbus_error.name,
- dbus_error.message);
- dbus_error_free (&dbus_error);
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
goto fail;
}
- dbus_message_iter_init (reply, &iter_reply);
-
- /* TODO: verify signature */
-
/* drives */
- dbus_message_iter_recurse (&iter_reply, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
+ g_variant_iter_init (&iter, Drives);
+ while ((child = g_variant_iter_next_value (&iter)))
{
GProxyDrive *drive;
const char *id;
drive = g_proxy_drive_new (monitor);
- g_proxy_drive_update (drive, &iter_array);
+ g_proxy_drive_update (drive, child);
id = g_proxy_drive_get_id (drive);
g_hash_table_insert (monitor->drives, g_strdup (id), drive);
- dbus_message_iter_next (&iter_array);
+ g_variant_unref (child);
}
- dbus_message_iter_next (&iter_reply);
/* volumes */
- dbus_message_iter_recurse (&iter_reply, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
+ g_variant_iter_init (&iter, Volumes);
+ while ((child = g_variant_iter_next_value (&iter)))
{
GProxyVolume *volume;
const char *id;
volume = g_proxy_volume_new (monitor);
- g_proxy_volume_update (volume, &iter_array);
+ g_proxy_volume_update (volume, child);
id = g_proxy_volume_get_id (volume);
g_hash_table_insert (monitor->volumes, g_strdup (id), volume);
- dbus_message_iter_next (&iter_array);
+ g_variant_unref (child);
}
- dbus_message_iter_next (&iter_reply);
/* mounts */
- dbus_message_iter_recurse (&iter_reply, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
+ g_variant_iter_init (&iter, Mounts);
+ while ((child = g_variant_iter_next_value (&iter)))
{
GProxyMount *mount;
const char *id;
mount = g_proxy_mount_new (monitor);
- g_proxy_mount_update (mount, &iter_array);
+ g_proxy_mount_update (mount, child);
id = g_proxy_mount_get_id (mount);
g_hash_table_insert (monitor->mounts, g_strdup (id), mount);
- dbus_message_iter_next (&iter_array);
+ g_variant_unref (child);
}
- dbus_message_iter_next (&iter_reply);
- monitor->unique_name = g_strdup (dbus_message_get_sender (reply));
-
- dbus_message_unref (reply);
+ g_variant_unref (Drives);
+ g_variant_unref (Volumes);
+ g_variant_unref (Mounts);
fail:
;
@@ -1137,47 +1322,27 @@ g_proxy_volume_monitor_get_mount_for_id (GProxyVolumeMonitor *volume_monitor,
GHashTable *
-_get_identifiers (DBusMessageIter *iter)
+_get_identifiers (GVariantIter *iter)
{
GHashTable *hash_table;
- DBusMessageIter iter_array;
+ char *key;
+ char *value;
hash_table = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_free);
- dbus_message_iter_recurse (iter, &iter_array);
- while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
- {
- DBusMessageIter iter_dict_entry;
- const char *key;
- const char *value;
-
- dbus_message_iter_recurse (&iter_array, &iter_dict_entry);
- dbus_message_iter_get_basic (&iter_dict_entry, &key);
- dbus_message_iter_next (&iter_dict_entry);
- dbus_message_iter_get_basic (&iter_dict_entry, &value);
-
- g_hash_table_insert (hash_table, g_strdup (key), g_strdup (value));
-
- dbus_message_iter_next (&iter_array);
- }
-
+ while (g_variant_iter_next (iter, "{ss}", &key, &value))
+ g_hash_table_insert (hash_table, key, value);
+
return hash_table;
}
-DBusConnection *
-g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor)
-{
- return dbus_connection_ref (volume_monitor->session_bus);
-}
-
-const char *
-g_proxy_volume_monitor_get_dbus_name (GProxyVolumeMonitor *volume_monitor)
+GVfsRemoteVolumeMonitor *
+g_proxy_volume_monitor_get_dbus_proxy (GProxyVolumeMonitor *volume_monitor)
{
- GProxyVolumeMonitorClass *klass = G_PROXY_VOLUME_MONITOR_CLASS (G_OBJECT_GET_CLASS (volume_monitor));
- return klass->dbus_name;
+ return g_object_ref (volume_monitor->proxy);
}
static void
@@ -1215,11 +1380,11 @@ register_volume_monitor (GTypeModule *type_module,
}
/* Call with proxy_vm lock held */
-gboolean
-g_proxy_volume_monitor_setup_session_bus_connection (gboolean need_integration)
+static gboolean
+g_proxy_volume_monitor_setup_session_bus_connection (void)
{
gboolean ret;
- DBusError dbus_error;
+ GError *error;
ret = FALSE;
@@ -1233,25 +1398,21 @@ g_proxy_volume_monitor_setup_session_bus_connection (gboolean need_integration)
if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL)
goto out;
- dbus_error_init (&dbus_error);
- the_session_bus = dbus_bus_get_private (DBUS_BUS_SESSION, &dbus_error);
- if (dbus_error_is_set (&dbus_error))
+ error = NULL;
+ the_session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (error != NULL)
{
- g_warning ("cannot connect to the session bus: %s: %s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
+ g_printerr ("cannot connect to the session bus: %s (%s, %d)\n",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
goto out;
}
+ g_object_set (the_session_bus, "exit-on-close", FALSE, NULL);
the_volume_monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
has_bus_already:
-
- if (need_integration && !the_session_bus_is_integrated)
- {
- _g_dbus_connection_integrate_with_main (the_session_bus);
- the_session_bus_is_integrated = TRUE;
- }
-
+
ret = TRUE;
out:
@@ -1264,10 +1425,8 @@ g_proxy_volume_monitor_teardown_session_bus_connection (void)
G_LOCK (proxy_vm);
if (the_session_bus != NULL)
{
- if (the_session_bus_is_integrated)
- _g_dbus_connection_remove_from_main (the_session_bus);
- the_session_bus_is_integrated = FALSE;
- dbus_connection_close (the_session_bus);
+ g_dbus_connection_close_sync (the_session_bus, NULL, NULL);
+ g_object_unref (the_session_bus);
the_session_bus = NULL;
g_hash_table_unref (the_volume_monitors);
diff --git a/monitor/proxy/gproxyvolumemonitor.h b/monitor/proxy/gproxyvolumemonitor.h
index 3d29d7b..137e56b 100644
--- a/monitor/proxy/gproxyvolumemonitor.h
+++ b/monitor/proxy/gproxyvolumemonitor.h
@@ -27,7 +27,8 @@
#include <glib-object.h>
#include <gio/gio.h>
#include <gio/gunixmounts.h>
-#include <dbus/dbus.h>
+
+#include "gvfsvolumemonitordbus.h"
G_BEGIN_DECLS
@@ -64,21 +65,19 @@ struct _GProxyVolumeMonitorClass {
GType g_proxy_volume_monitor_get_type (void) G_GNUC_CONST;
-void g_proxy_volume_monitor_register (GIOModule *module);
-GProxyDrive *g_proxy_volume_monitor_get_drive_for_id (GProxyVolumeMonitor *volume_monitor,
+void g_proxy_volume_monitor_register (GIOModule *module);
+GProxyDrive *g_proxy_volume_monitor_get_drive_for_id (GProxyVolumeMonitor *volume_monitor,
const char *id);
-GProxyVolume *g_proxy_volume_monitor_get_volume_for_id (GProxyVolumeMonitor *volume_monitor,
+GProxyVolume *g_proxy_volume_monitor_get_volume_for_id (GProxyVolumeMonitor *volume_monitor,
const char *id);
-GProxyMount *g_proxy_volume_monitor_get_mount_for_id (GProxyVolumeMonitor *volume_monitor,
+GProxyMount *g_proxy_volume_monitor_get_mount_for_id (GProxyVolumeMonitor *volume_monitor,
const char *id);
-DBusConnection *g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor);
-const char *g_proxy_volume_monitor_get_dbus_name (GProxyVolumeMonitor *volume_monitor);
+GVfsRemoteVolumeMonitor *g_proxy_volume_monitor_get_dbus_proxy (GProxyVolumeMonitor *volume_monitor);
-gboolean g_proxy_volume_monitor_setup_session_bus_connection (gboolean need_integration);
void g_proxy_volume_monitor_teardown_session_bus_connection (void);
-GHashTable *_get_identifiers (DBusMessageIter *iter);
+GHashTable *_get_identifiers (GVariantIter *identifiers);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]