[gvfs/gdbus: 7/17] gdbus: Port GIO side of proxy volume monitor
- From: Tomas Bzatek <tbzatek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/gdbus: 7/17] gdbus: Port GIO side of proxy volume monitor
- Date: Wed, 4 Apr 2012 16:30:36 +0000 (UTC)
commit a633ced02e95f93755dd632d4c40bb9fd3c876ad
Author: Tomas Bzatek <tbzatek redhat com>
Date: Wed Oct 26 19:04:38 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 | 389 +++++-------
monitor/proxy/gproxydrive.h | 14 +-
monitor/proxy/gproxymount.c | 163 ++---
monitor/proxy/gproxymount.h | 2 +-
monitor/proxy/gproxymountoperation.c | 184 ++----
monitor/proxy/gproxymountoperation.h | 27 +-
monitor/proxy/gproxyshadowmount.c | 2 -
monitor/proxy/gproxyvolume.c | 158 ++---
monitor/proxy/gproxyvolume.h | 2 +-
monitor/proxy/gproxyvolumemonitor.c | 1221 +++++++++++++++++++---------------
monitor/proxy/gproxyvolumemonitor.h | 17 +-
14 files changed, 1076 insertions(+), 1108 deletions(-)
---
diff --git a/monitor/afc/Makefile.am b/monitor/afc/Makefile.am
index e524481..0b022b2 100644
--- a/monitor/afc/Makefile.am
+++ b/monitor/afc/Makefile.am
@@ -23,7 +23,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 4945445..5d49cbc 100644
--- a/monitor/gdu/Makefile.am
+++ b/monitor/gdu/Makefile.am
@@ -19,7 +19,6 @@ gvfs_gdu_volume_monitor_CFLAGS = \
$(GLIB_CFLAGS) \
$(GDU_CFLAGS) \
$(GUDEV_CFLAGS) \
- $(DBUS_CFLAGS) \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
-DGDU_API_IS_SUBJECT_TO_CHANGE \
@@ -32,7 +31,6 @@ gvfs_gdu_volume_monitor_LDADD = \
$(GLIB_LIBS) \
$(GDU_LIBS) \
$(GUDEV_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 6985cd4..4d477b3 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)"\" \
@@ -46,7 +45,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 be2b600..6453b00 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);
@@ -139,80 +138,52 @@ g_proxy_drive_new (GProxyVolumeMonitor *volume_monitor)
* string sort_key
* a{sv} expansion
*/
-#define DRIVE_STRUCT_TYPE "(sssbbbbbbbbuasa{ss}sa{sv})"
+#define DRIVE_STRUCT_TYPE "(&s&s&sbbbbbbbbuasa{ss}&sa{sv})"
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;
const char *sort_key;
+ const gchar *volume_id;
+ GVariantIter *iter_volume_ids;
+ GVariantIter *iter_identifiers;
+ GVariantIter *iter_expansion;
+
- 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);
+ sort_key = NULL;
+ 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,
+ &sort_key,
+ &iter_expansion);
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);
-
- /* make sure we are backwards compat with old daemon instance */
- sort_key = NULL;
- if (dbus_message_iter_has_next (&iter_struct))
- {
- dbus_message_iter_get_basic (&iter_struct, &sort_key);
- dbus_message_iter_next (&iter_struct);
- /* TODO: decode expansion, once used */
- }
+ identifiers = _get_identifiers (iter_identifiers);
if (drive->id != NULL && strcmp (drive->id, id) != 0)
{
g_warning ("id mismatch during update of drive");
@@ -255,7 +226,12 @@ g_proxy_drive_update (GProxyDrive *drive,
drive->volume_ids = g_strdupv ((char **) volume_ids->pdata);
drive->sort_key = g_strdup (sort_key);
+ /* TODO: decode expansion, once used */
+
out:
+ g_variant_iter_free (iter_volume_ids);
+ g_variant_iter_free (iter_identifiers);
+ g_variant_iter_free (iter_expansion);
g_ptr_array_free (volume_ids, TRUE);
g_hash_table_unref (identifiers);
}
@@ -511,13 +487,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);
}
}
@@ -527,9 +510,7 @@ operation_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -543,35 +524,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);
@@ -599,6 +576,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
@@ -610,11 +589,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);
@@ -653,32 +629,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:
;
}
@@ -716,10 +678,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);
@@ -747,6 +716,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
@@ -758,11 +729,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);
@@ -801,32 +769,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:
;
}
@@ -856,11 +811,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))
@@ -890,6 +852,8 @@ start_cb (DBusMessage *reply,
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
static void
@@ -898,9 +862,7 @@ start_cancelled (GCancellable *cancellable,
{
DBusStartOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_drive);
@@ -914,26 +876,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
@@ -946,9 +897,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);
@@ -987,33 +936,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:
;
}
@@ -1031,10 +965,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;
@@ -1060,6 +1001,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
@@ -1069,10 +1012,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);
@@ -1109,29 +1050,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 cd3ca49..dde2865 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"
@@ -145,58 +143,38 @@ 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&sa{sv})"
+
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 gchar *sort_key;
+ const char *x_content_type;
+ GVariantIter *iter_content_types;
+ GVariantIter *iter_expansion;
- 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);
+ sort_key = NULL;
+ g_variant_get (iter, MOUNT_STRUCT_TYPE,
+ &id, &name, &gicon_data,
+ &uuid, &root_uri,
+ &can_unmount, &volume_id,
+ &iter_content_types,
+ &sort_key,
+ &iter_expansion);
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);
-
- /* make sure we are backwards compat with old daemon instance */
- sort_key = NULL;
- if (dbus_message_iter_has_next (&iter_struct))
- {
- dbus_message_iter_get_basic (&iter_struct, &sort_key);
- dbus_message_iter_next (&iter_struct);
- /* TODO: decode expansion, once used */
- }
if (mount->id != NULL && strcmp (mount->id, id) != 0)
{
@@ -237,7 +215,11 @@ g_proxy_mount_update (GProxyMount *mount,
mount->x_content_types = g_strdupv ((char **) x_content_types->pdata);
mount->sort_key = g_strdup (sort_key);
+ /* TODO: decode expansion, once used */
+
out:
+ g_variant_iter_free (iter_content_types);
+ g_variant_iter_free (iter_expansion);
g_ptr_array_free (x_content_types, TRUE);
}
@@ -458,13 +440,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);
}
}
@@ -474,9 +463,7 @@ operation_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_mount);
@@ -490,33 +477,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);
@@ -543,6 +526,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
@@ -554,11 +539,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);
@@ -597,33 +579,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);
+
+
+ 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);
- _g_dbus_connection_call_async (connection,
- message,
- G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT, /* 30 minute timeout */
- (GAsyncDBusCallback) unmount_cb,
- data);
-
- 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 b83d2f1..02ebe87 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 b6b8c91..a3e8e1e 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"
@@ -193,7 +191,6 @@ g_proxy_volume_new (GProxyVolumeMonitor *volume_monitor)
return volume;
}
-
static void
union_monitor_mount_added (GVolumeMonitor *union_monitor,
GMount *mount,
@@ -356,10 +353,11 @@ update_shadow_mount_in_idle (GProxyVolume *volume)
* a{sv} expansion
*/
+#define VOLUME_STRUCT_TYPE "(&s&s&s&s&sbb&s&sa{ss}&sa{sv})"
+
void g_proxy_volume_update (GProxyVolume *volume,
- DBusMessageIter *iter)
+ GVariant *iter)
{
- DBusMessageIter iter_struct;
const char *id;
const char *name;
const char *gicon_data;
@@ -367,42 +365,24 @@ 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;
const gchar *sort_key;
+ GVariantIter *iter_identifiers;
+ GVariantIter *iter_expansion;
- 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);
-
- /* make sure we are backwards compat with old daemon instance */
sort_key = NULL;
- if (dbus_message_iter_has_next (&iter_struct))
- {
- dbus_message_iter_get_basic (&iter_struct, &sort_key);
- dbus_message_iter_next (&iter_struct);
- /* TODO: decode expansion, once used */
- }
+ g_variant_get (iter, VOLUME_STRUCT_TYPE,
+ &id, &name, &gicon_data,
+ &uuid, &activation_uri,
+ &can_mount, &should_automount,
+ &drive_id, &mount_id,
+ &iter_identifiers,
+ &sort_key,
+ &iter_expansion);
+
+ identifiers = _get_identifiers (iter_identifiers);
if (volume->id != NULL && strcmp (volume->id, id) != 0)
{
@@ -448,10 +428,14 @@ void g_proxy_volume_update (GProxyVolume *volume,
volume->identifiers = identifiers != NULL ? g_hash_table_ref (identifiers) : NULL;
volume->sort_key = g_strdup (sort_key);
+ /* TODO: decode expansion, once used */
+
/* this calls into the union monitor; do it in idle to avoid locking issues */
update_shadow_mount_in_idle (volume);
out:
+ g_variant_iter_free (iter_identifiers);
+ g_variant_iter_free (iter_expansion);
g_hash_table_unref (identifiers);
}
@@ -741,10 +725,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);
@@ -775,6 +766,8 @@ mount_cb (DBusMessage *reply,
g_object_unref (data->cancellable);
g_free (data);
+ if (error != NULL)
+ g_error_free (error);
}
typedef struct
@@ -796,13 +789,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);
}
}
@@ -812,9 +812,7 @@ mount_cancelled (GCancellable *cancellable,
{
DBusOp *data = user_data;
GSimpleAsyncResult *simple;
- DBusConnection *connection;
- DBusMessage *message;
- const char *name;
+ GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_volume);
@@ -828,26 +826,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
@@ -887,10 +874,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))
{
@@ -927,32 +911,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 2bf74ba..ed823ed 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,25 +99,6 @@ 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)
{
@@ -365,6 +346,569 @@ get_mount_for_mount_path (const char *mount_path,
return mount;
}
+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,
@@ -374,8 +918,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);
@@ -387,6 +931,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));
@@ -396,37 +942,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);
@@ -491,336 +1052,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
@@ -855,6 +1090,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;
@@ -864,56 +1100,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;
}
@@ -923,7 +1148,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)
@@ -961,86 +1186,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:
;
@@ -1093,47 +1302,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
@@ -1171,11 +1360,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;
@@ -1189,25 +1378,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:
@@ -1220,10 +1405,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]