summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2012-07-31 11:58:09 +0200
committerTomas Bzatek <tbzatek@redhat.com>2012-07-31 11:58:09 +0200
commit622a5c0d167556188c38fcde40a42a0dfad9c625 (patch)
tree04f27be7f2a54779e17029ede2554e39c3464aa0 /common
parenta494b809eaf82994108bfbbe5d950fed1a0a8c7c (diff)
gdbus: Core daemon and client port
Port of most of the gvfs core, few bits still missing. Lot of debug prints around, will be removed in further commits. Same amount of TODOs and FIXMEs. Notes: * kill serials? * get rid of mainloops where applicable (copy/move progress callback, enumerator) * fix keyring integration * use gdbus builtin fd passing within gvfsdaemon.c, kill the extra_fd stuff
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am20
-rw-r--r--common/dbus-interfaces.xml351
-rw-r--r--common/gmountoperationdbus.c506
-rw-r--r--common/gmountoperationdbus.h2
-rw-r--r--common/gmountsource.c476
-rw-r--r--common/gmountsource.h4
-rw-r--r--common/gmountspec.c106
-rw-r--r--common/gmountspec.h28
-rw-r--r--common/gmounttracker.c255
-rw-r--r--common/gmounttracker.h4
-rw-r--r--common/gvfsdaemonprotocol.c558
-rw-r--r--common/gvfsdaemonprotocol.h16
12 files changed, 1109 insertions, 1217 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 5d5a54ea..4755711d 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -8,6 +8,21 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/gvfs \
-DG_LOG_DOMAIN=\"GVFS\" \
-DDBUS_API_SUBJECT_TO_CHANGE
+dbus_built_sources = gvfsdbus.c gvfsdbus.h
+BUILT_SOURCES = $(dbus_built_sources)
+
+$(dbus_built_sources) : Makefile.am dbus-interfaces.xml
+ gdbus-codegen \
+ --interface-prefix org.gtk.vfs. \
+ --c-namespace GVfsDBus \
+ --generate-c-code gvfsdbus \
+ --annotate "org.gtk.vfs.Mount.OpenForRead()" \
+ org.gtk.GDBus.C.UnixFD true \
+ --annotate "org.gtk.vfs.Mount.OpenForWrite()" \
+ org.gtk.GDBus.C.UnixFD true \
+ dbus-interfaces.xml \
+ $(NULL)
+
libgvfscommon_la_SOURCES = \
gsysutils.c gsysutils.h \
gvfsdbusutils.c gvfsdbusutils.h \
@@ -19,6 +34,7 @@ libgvfscommon_la_SOURCES = \
gvfsicon.h gvfsicon.c \
gvfsmountinfo.h gvfsmountinfo.c \
gvfsfileinfo.c gvfsfileinfo.h \
+ $(dbus_built_sources) \
$(NULL)
# needed by cygwin (see bug #564003)
@@ -46,3 +62,7 @@ libgvfscommon_dnssd_la_LIBADD = \
$(GLIB_LIBS)
endif
+
+EXTRA_DIST = dbus-interfaces.xml
+
+CLEANFILES = $(dbus_built_sources)
diff --git a/common/dbus-interfaces.xml b/common/dbus-interfaces.xml
new file mode 100644
index 00000000..8bd349cd
--- /dev/null
+++ b/common/dbus-interfaces.xml
@@ -0,0 +1,351 @@
+<!DOCTYPE node PUBLIC
+"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+
+<!--
+ Copyright (C) 2011 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Tomas Bzatek <tbzatek@redhat.com>
+-->
+
+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
+ <!--
+ org.gtk.vfs.Daemon:
+
+ Each daemon (main and for mounts) implement this.
+ -->
+ <interface name='org.gtk.vfs.Daemon'>
+ <method name="GetConnection">
+ <arg type='s' name='address1' direction='out'/>
+ <arg type='s' name='address2' direction='out'/>
+ </method>
+ <method name="Cancel">
+ <arg type='u' name='serial' direction='in'/>
+ </method>
+ <method name="mount">
+ <arg type='b' name='automount' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ <arg type='a{sv}' name='reply' direction='out'/>
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.Spawner:
+
+ Implemented by the spawner of a process, the spawned process sends the
+ spawned message (with noreply) when it has spawned and gotten a dbus id.
+ -->
+ <interface name='org.gtk.vfs.Spawner'>
+ <method name="spawned">
+ <arg type='b' name='succeeded' direction='in'/>
+ <arg type='s' name='error_message' direction='in'/>
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.MountTracker:
+
+ The mount tracking interface in the main daemon.
+ -->
+ <interface name='org.gtk.vfs.MountTracker'>
+ <method name="lookupMount">
+ <arg type='(aya{sv})' name='mount_spec' direction='in'/>
+ <arg type='(sosssssbay(aya{sv})ay)' name='mount' direction='out'/>
+ </method>
+ <method name="lookupMountByFusePath">
+ <arg type='ay' name='fuse_path' direction='in'/>
+ <arg type='(sosssssbay(aya{sv})ay)' name='mount' direction='out'/>
+ </method>
+ <method name="mountLocation">
+ <arg type='(aya{sv})' name='mount_spec' direction='in'/>
+ <arg type='(so)' name='mount_source' direction='in'/>
+ </method>
+ <method name="listMounts">
+ <arg type='a(sosssssbay(aya{sv})ay)' name='mounts' direction='out'/>
+ </method>
+ <method name="registerMount">
+ <arg type='o' name='obj_path' direction='in'/>
+ <arg type='s' name='display_name' direction='in'/>
+ <arg type='s' name='stable_name' direction='in'/>
+ <arg type='s' name='x_content_types' direction='in'/>
+ <arg type='s' name='icon' direction='in'/>
+ <arg type='s' name='prefered_filename_encoding' direction='in'/>
+ <arg type='b' name='user_visible' direction='in'/>
+ <arg type='(aya{sv})' name='mount_spec' direction='in'/>
+ <arg type='ay' name='default_location' direction='in'/>
+ </method>
+ <method name="unregisterMount">
+ <arg type='o' name='obj_path' direction='in'/>
+ </method>
+ <method name="listMountTypes">
+ <arg type='as' name='mount_types' direction='out'/>
+ </method>
+ <method name="listMountableInfo">
+ <arg type='a(ssasib)' name='mountables' direction='out'/>
+ </method>
+ <method name="registerFuse">
+ </method>
+ <signal name="mounted">
+ <arg type='(sosssssbay(aya{sv})ay)' name='mount'/>
+ </signal>
+ <signal name="unmounted">
+ <arg type='(sosssssbay(aya{sv})ay)' name='mount'/>
+ </signal>
+ </interface>
+
+ <!--
+ org.gtk.vfs.Mountable:
+
+ Mount daemons that support mounting more mounts implement this,
+ and set the dbus name in the mountable description file.
+ -->
+ <interface name='org.gtk.vfs.Mountable'>
+ <method name="mount">
+ <arg type='(aya{sv})' name='mount_spec' direction='in'/>
+ <arg type='b' name='automount' direction='in'/>
+ <arg type='(so)' name='mount_source' direction='in'/>
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.MountOperation:
+
+ Used by the dbus-proxying implementation of GMoutOperation.
+ -->
+ <interface name='org.gtk.vfs.MountOperation'>
+ <method name="askPassword">
+ <arg type='s' name='message_string' direction='in'/>
+ <arg type='s' name='default_user' direction='in'/>
+ <arg type='s' name='default_domain' direction='in'/>
+ <arg type='u' name='flags_as_int' direction='in'/>
+ <arg type='b' name='handled' direction='out'/>
+ <arg type='b' name='aborted' direction='out'/>
+ <arg type='s' name='password' direction='out'/>
+ <arg type='s' name='username' direction='out'/>
+ <arg type='s' name='domain' direction='out'/>
+ <arg type='b' name='anonymous' direction='out'/>
+ <arg type='u' name='password_save' direction='out'/>
+ </method>
+ <method name="askQuestion">
+ <arg type='s' name='message_string' direction='in'/>
+ <arg type='as' name='choices' direction='in'/>
+ <arg type='b' name='handled' direction='out'/>
+ <arg type='b' name='aborted' direction='out'/>
+ <arg type='u' name='choice' direction='out'/>
+ </method>
+ <method name="showProcesses">
+ <arg type='s' name='message_string' direction='in'/>
+ <arg type='as' name='choices' direction='in'/>
+ <arg type='ai' name='processes' direction='in'/>
+ <arg type='b' name='handled' direction='out'/>
+ <arg type='b' name='aborted' direction='out'/>
+ <arg type='u' name='choice' direction='out'/>
+ </method>
+ <method name="ShowUnmountProgress">
+ <arg type='s' name='message_string' direction='in'/>
+ <arg type='t' name='time_left' direction='in'/>
+ <arg type='t' name='bytes_left' direction='in'/>
+ </method>
+ <method name="aborted">
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.Mount:
+
+ Each mount (there might be several in a daemon) implements one of these interfaces
+ for standard i/o operations.
+ -->
+ <interface name='org.gtk.vfs.Mount'>
+ <method name="Unmount">
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ </method>
+ <method name="OpenForRead">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='pid' direction='in'/>
+ <arg type='u' name='fd_id' direction='out'/>
+ <arg type='b' name='can_seek' direction='out'/>
+ </method>
+ <method name="OpenForWrite">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='q' name='mode' direction='in'/>
+ <arg type='s' name='etag' direction='in'/>
+ <arg type='b' name='make_backup' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='u' name='pid' direction='in'/>
+ <arg type='u' name='fd_id' direction='out'/>
+ <arg type='b' name='can_seek' direction='out'/>
+ <arg type='t' name='initial_offset' direction='out'/>
+ </method>
+ <method name="QueryInfo">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='attributes' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='uri' direction='in'/>
+ <arg type='a(suv)' name='info' direction='out'/>
+ </method>
+ <method name="QueryFilesystemInfo">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='attributes' direction='in'/>
+ <arg type='a(suv)' name='info' direction='out'/>
+ </method>
+ <method name="Enumerate">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='obj_path' direction='in'/>
+ <arg type='s' name='attributes' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='uri' direction='in'/>
+ </method>
+ <method name="CreateDirectoryMonitor">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='obj_path' direction='out'/>
+ </method>
+ <method name="CreateFileMonitor">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='obj_path' direction='out'/>
+ </method>
+ <method name="MountMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ <arg type='b' name='is_uri' direction='out'/>
+ <arg type='ay' name='path' direction='out'/>
+ <arg type='b' name='must_mount_location' direction='out'/>
+ <arg type='(aya{sv})' name='mount_spec' direction='out'/>
+ </method>
+ <method name="UnmountMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ </method>
+ <method name="EjectMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ </method>
+ <method name="StartMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ </method>
+ <method name="StopMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='s' name='dbus_id' direction='in'/>
+ <arg type='o' name='obj_path' direction='in'/>
+ </method>
+ <method name="PollMountable">
+ <arg type='ay' name='path_data' direction='in'/>
+ </method>
+ <method name="SetDisplayName">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='s' name='display_name' direction='in'/>
+ <arg type='ay' name='new_path' direction='out'/>
+ </method>
+ <method name="Delete">
+ <arg type='ay' name='path_data' direction='in'/>
+ </method>
+ <method name="Trash">
+ <arg type='ay' name='path_data' direction='in'/>
+ </method>
+ <method name="MakeDirectory">
+ <arg type='ay' name='path_data' direction='in'/>
+ </method>
+ <method name="MakeSymbolicLink">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='ay' name='symlink_value' direction='in'/>
+ </method>
+ <method name="Copy">
+ <arg type='ay' name='path1_data' direction='in'/>
+ <arg type='ay' name='path2_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='o' name='progress_obj_path' direction='in'/>
+ </method>
+ <method name="Move">
+ <arg type='ay' name='path1_data' direction='in'/>
+ <arg type='ay' name='path2_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='o' name='progress_obj_path' direction='in'/>
+ </method>
+ <method name="Push">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='ay' name='local_path' direction='in'/>
+ <arg type='b' name='send_progress' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='o' name='progress_obj_path' direction='in'/>
+ <arg type='b' name='remove_source' direction='in'/>
+ </method>
+ <method name="Pull">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='ay' name='local_path' direction='in'/>
+ <arg type='b' name='send_progress' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='o' name='progress_obj_path' direction='in'/>
+ <arg type='b' name='remove_source' direction='in'/>
+ </method>
+ <method name="SetAttribute">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='u' name='flags' direction='in'/>
+ <arg type='(suv)' name='attribute' direction='in'/>
+ </method>
+ <method name="QuerySettableAttributes">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='a(suu)' name='list' direction='out'/>
+ </method>
+ <method name="QueryWritableNamespaces">
+ <arg type='ay' name='path_data' direction='in'/>
+ <arg type='a(suu)' name='list' direction='out'/>
+ </method>
+ <method name="OpenIconForRead">
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.Enumerator:
+
+ Implemented by client side for a file enumerator.
+ -->
+ <interface name='org.gtk.vfs.Enumerator'>
+ <method name="Done">
+ </method>
+ <method name="GotInfo">
+ <arg type='aa(suv)' name='infos' direction='in'/>
+ </method>
+ </interface>
+
+ <!--
+ org.gtk.vfs.Progress:
+
+ Progress callback interface for copy and move.
+ -->
+ <interface name='org.gtk.vfs.Progress'>
+ <method name="Progress">
+ <arg type='t' name='current' direction='in'/>
+ <arg type='t' name='total' direction='in'/>
+ </method>
+ </interface>
+
+</node>
+
diff --git a/common/gmountoperationdbus.c b/common/gmountoperationdbus.c
index b1989c16..dc332648 100644
--- a/common/gmountoperationdbus.c
+++ b/common/gmountoperationdbus.c
@@ -24,152 +24,32 @@
#include <string.h>
-#include <dbus/dbus.h>
-
-#define I_(string) g_intern_static_string (string)
-
#include <gio/gio.h>
-#include "gmountoperationdbus.h"
-#include "gvfsdaemonprotocol.h"
-#include "gvfsdbusutils.h"
#include <glib/gi18n-lib.h>
+#include "gmountoperationdbus.h"
+#include "gvfsdbus.h"
typedef struct
{
GMountOperation *op;
char *obj_path;
char *dbus_id;
- DBusConnection *connection;
+ GDBusConnection *connection;
+ GVfsDBusMountOperation *mount_op_skeleton;
} GMountOperationDBus;
-static DBusHandlerResult mount_op_message_function (DBusConnection *connection,
- DBusMessage *message,
- void *user_data);
-static void mount_op_unregister_function (DBusConnection *connection,
- void *user_data);
-static void mount_op_ask_password (GMountOperationDBus *op_dbus,
- DBusMessage *message);
-static void mount_op_ask_question (GMountOperationDBus *op_dbus,
- DBusMessage *message);
-static void mount_op_show_processes (GMountOperationDBus *op_dbus,
- DBusMessage *message);
-static void mount_op_show_unmount_progress (GMountOperationDBus *op_dbus,
- DBusMessage *message);
-static void mount_op_aborted (GMountOperationDBus *op_dbus,
- DBusMessage *message);
-
-static void
-g_mount_operation_dbus_free (GMountOperationDBus *op_dbus)
-{
- if (op_dbus->connection)
- {
- dbus_connection_unregister_object_path (op_dbus->connection,
- op_dbus->obj_path);
- dbus_connection_unref (op_dbus->connection);
- }
- g_free (op_dbus->dbus_id);
- g_free (op_dbus->obj_path);
- g_free (op_dbus);
-}
-
-GMountSource *
-g_mount_operation_dbus_wrap (GMountOperation *op,
- DBusConnection *connection)
-{
- GMountOperationDBus *op_dbus;
- static int mount_id = 0;
- DBusObjectPathVTable mount_vtable = {
- mount_op_unregister_function,
- mount_op_message_function
- };
-
- if (op == NULL)
- return g_mount_source_new_dummy ();
-
- op_dbus = g_new0 (GMountOperationDBus, 1);
-
- op_dbus->op = op;
- op_dbus->connection = dbus_connection_ref (connection);
- op_dbus->obj_path = g_strdup_printf ("/org/gtk/gvfs/mountop/%d", mount_id++);
- if (op_dbus->connection)
- {
- op_dbus->dbus_id = g_strdup (dbus_bus_get_unique_name (op_dbus->connection));
- if (!dbus_connection_register_object_path (op_dbus->connection,
- op_dbus->obj_path,
- &mount_vtable,
- op_dbus))
- _g_dbus_oom ();
- }
-
- g_object_set_data_full (G_OBJECT (op), "dbus-op",
- op_dbus, (GDestroyNotify)g_mount_operation_dbus_free);
-
- return g_mount_source_new (op_dbus->dbus_id, op_dbus->obj_path);
-}
-
-/**
- * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
- * Found in #DBusObjectPathVTable.
- */
-static void
-mount_op_unregister_function (DBusConnection *connection,
- void *user_data)
-{
-}
-
-/**
- * Called when a message is sent to a registered object path. Found in
- * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
- * or dbus_connection_register_fallback().
- */
-static DBusHandlerResult
-mount_op_message_function (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- GMountOperationDBus *op_dbus = user_data;
-
- if (dbus_message_is_method_call (message,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_PASSWORD))
- mount_op_ask_password (op_dbus, message);
- else if (dbus_message_is_method_call (message,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_QUESTION))
- mount_op_ask_question (op_dbus, message);
- else if (dbus_message_is_method_call (message,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_PROCESSES))
- mount_op_show_processes (op_dbus, message);
- else if (dbus_message_is_method_call (message,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_UNMOUNT_PROGRESS))
- mount_op_show_unmount_progress (op_dbus, message);
- else if (dbus_message_is_method_call (message,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ABORTED))
- mount_op_aborted (op_dbus, message);
- else
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
static void
mount_op_send_reply (GMountOperationDBus *op_dbus,
- DBusMessage *reply)
+ GDBusMethodInvocation *invocation)
{
- if (!dbus_connection_send (op_dbus->connection, reply, NULL))
- _g_dbus_oom ();
-
g_signal_handlers_disconnect_matched (op_dbus->op,
G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA,
g_signal_lookup ("reply", G_TYPE_MOUNT_OPERATION),
0,
NULL,
NULL,
- reply);
- dbus_message_unref (reply);
+ invocation);
+ g_object_unref (invocation);
}
static void
@@ -177,11 +57,11 @@ ask_password_reply (GMountOperation *op,
GMountOperationResult result,
gpointer data)
{
- DBusMessage *reply = data;
+ GDBusMethodInvocation *invocation = data;
const char *username, *password, *domain;
- dbus_bool_t anonymous;
+ gboolean anonymous;
guint32 password_save;
- dbus_bool_t handled, abort_dbus;
+ gboolean handled, abort_dbus;
GMountOperationDBus *op_dbus;
op_dbus = g_object_get_data (G_OBJECT (op), "dbus-op");
@@ -201,63 +81,42 @@ ask_password_reply (GMountOperation *op,
anonymous = g_mount_operation_get_anonymous (op);
password_save = g_mount_operation_get_password_save (op);
- _g_dbus_message_append_args (reply,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &abort_dbus,
- DBUS_TYPE_STRING, &password,
- DBUS_TYPE_STRING, &username,
- DBUS_TYPE_STRING, &domain,
- DBUS_TYPE_BOOLEAN, &anonymous,
- DBUS_TYPE_UINT32, &password_save,
- 0);
-
- mount_op_send_reply (op_dbus, reply);
+ gvfs_dbus_mount_operation_complete_ask_password (NULL, /* FIXME */
+ invocation,
+ handled,
+ abort_dbus,
+ password,
+ username,
+ domain,
+ anonymous,
+ password_save);
+
+ mount_op_send_reply (op_dbus, invocation);
}
-static void
-mount_op_ask_password (GMountOperationDBus *op_dbus,
- DBusMessage *message)
+static gboolean
+handle_ask_password (GVfsDBusMountOperation *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_message_string,
+ const gchar *arg_default_user,
+ const gchar *arg_default_domain,
+ guint arg_flags_as_int,
+ gpointer data)
{
- const char *message_string, *default_user, *default_domain;
- guint32 flags;
- DBusMessageIter iter;
- DBusMessage *reply;
- DBusError error;
+ GMountOperationDBus *op_dbus = data;
- reply = NULL;
+ g_print ("gmountoperationdbus.c: handle_ask_password()\n");
- dbus_message_iter_init (message, &iter);
-
- dbus_error_init (&error);
- if (!_g_dbus_message_iter_get_args (&iter,
- &error,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_STRING, &default_user,
- DBUS_TYPE_STRING, &default_domain,
- DBUS_TYPE_UINT32, &flags,
- 0))
- {
- reply = dbus_message_new_error (message, error.name, error.message);
- if (reply == NULL)
- _g_dbus_oom ();
- if (!dbus_connection_send (op_dbus->connection, reply, NULL))
- _g_dbus_oom ();
- dbus_message_unref (reply);
- dbus_error_free (&error);
- return;
- }
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- _g_dbus_oom ();
-
- g_signal_connect (op_dbus->op, "reply", (GCallback)ask_password_reply, reply);
+ g_signal_connect (op_dbus->op, "reply",
+ (GCallback)ask_password_reply,
+ g_object_ref (invocation));
g_signal_emit_by_name (op_dbus->op, "ask_password",
- message_string,
- default_user,
- default_domain,
- flags);
+ arg_message_string,
+ arg_default_user,
+ arg_default_domain,
+ arg_flags_as_int);
+ return TRUE;
}
static void
@@ -265,9 +124,9 @@ ask_question_reply (GMountOperation *op,
GMountOperationResult result,
gpointer data)
{
- DBusMessage *reply = data;
+ GDBusMethodInvocation *invocation = data;
guint32 choice;
- dbus_bool_t handled, abort_dbus;
+ gboolean handled, abort_dbus;
GMountOperationDBus *op_dbus;
op_dbus = g_object_get_data (G_OBJECT (op), "dbus-op");
@@ -277,58 +136,35 @@ ask_question_reply (GMountOperation *op,
choice = g_mount_operation_get_choice (op);
- _g_dbus_message_append_args (reply,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &abort_dbus,
- DBUS_TYPE_UINT32, &choice,
- 0);
+ gvfs_dbus_mount_operation_complete_ask_question (NULL, /* FIXME */
+ invocation,
+ handled,
+ abort_dbus,
+ choice);
- mount_op_send_reply (op_dbus, reply);
+ mount_op_send_reply (op_dbus, invocation);
}
-static void
-mount_op_ask_question (GMountOperationDBus *op_dbus,
- DBusMessage *message)
+static gboolean
+handle_ask_question (GVfsDBusMountOperation *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_message_string,
+ const gchar *const *arg_choices,
+ gpointer data)
{
- const char *message_string;
- char **choices;
- int num_choices;
- DBusMessage *reply;
- DBusError error;
- DBusMessageIter iter;
-
- reply = NULL;
-
- dbus_message_iter_init (message, &iter);
- dbus_error_init (&error);
- if (!_g_dbus_message_iter_get_args (&iter,
- &error,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &choices, &num_choices,
- 0))
- {
- reply = dbus_message_new_error (message, error.name, error.message);
- if (reply == NULL)
- _g_dbus_oom ();
- if (!dbus_connection_send (op_dbus->connection, reply, NULL))
- _g_dbus_oom ();
- dbus_message_unref (reply);
- dbus_error_free (&error);
- return;
- }
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- _g_dbus_oom ();
-
- g_signal_connect (op_dbus->op, "reply", (GCallback)ask_question_reply, reply);
+ GMountOperationDBus *op_dbus = data;
+
+ g_print ("gmountoperationdbus.c: handle_ask_question()\n");
+
+ g_signal_connect (op_dbus->op,
+ "reply",
+ (GCallback)ask_question_reply,
+ g_object_ref (invocation));
g_signal_emit_by_name (op_dbus->op, "ask_question",
- message_string,
- choices);
-
- dbus_free_string_array (choices);
+ arg_message_string,
+ arg_choices);
+ return TRUE;
}
static void
@@ -336,9 +172,9 @@ show_processes_reply (GMountOperation *op,
GMountOperationResult result,
gpointer data)
{
- DBusMessage *reply = data;
+ GDBusMethodInvocation *invocation = data;
guint32 choice;
- dbus_bool_t handled, abort_dbus;
+ gboolean handled, abort_dbus;
GMountOperationDBus *op_dbus;
op_dbus = g_object_get_data (G_OBJECT (op), "dbus-op");
@@ -347,119 +183,149 @@ show_processes_reply (GMountOperation *op,
abort_dbus = (result == G_MOUNT_OPERATION_ABORTED);
choice = g_mount_operation_get_choice (op);
+
+ gvfs_dbus_mount_operation_complete_show_processes (NULL, /* FIXME */
+ invocation,
+ handled,
+ abort_dbus,
+ choice);
- _g_dbus_message_append_args (reply,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &abort_dbus,
- DBUS_TYPE_UINT32, &choice,
- 0);
-
- mount_op_send_reply (op_dbus, reply);
+ mount_op_send_reply (op_dbus, invocation);
}
-static void
-mount_op_show_processes (GMountOperationDBus *op_dbus,
- DBusMessage *message)
+static gboolean
+handle_show_processes (GVfsDBusMountOperation *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_message_string,
+ const gchar *const *arg_choices,
+ GVariant *arg_processes,
+ gpointer data)
{
- const char *message_string;
- char **choices;
- int num_choices;
- gint32 **process_pids;
- int num_process_pids;
- DBusMessage *reply;
- DBusError error;
- DBusMessageIter iter;
+ GMountOperationDBus *op_dbus = data;
GArray *processes;
+ GPid pid;
+ GVariantIter iter;
- reply = NULL;
-
- dbus_message_iter_init (message, &iter);
- dbus_error_init (&error);
- if (!_g_dbus_message_iter_get_args (&iter,
- &error,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &choices, &num_choices,
- DBUS_TYPE_ARRAY, DBUS_TYPE_INT32,
- &process_pids, &num_process_pids,
- 0))
- {
- reply = dbus_message_new_error (message, error.name, error.message);
- if (reply == NULL)
- _g_dbus_oom ();
- if (!dbus_connection_send (op_dbus->connection, reply, NULL))
- _g_dbus_oom ();
- dbus_message_unref (reply);
- dbus_error_free (&error);
- return;
- }
-
- processes = g_array_sized_new (FALSE, FALSE, sizeof (GPid), num_process_pids);
- g_array_append_vals (processes, process_pids, num_process_pids);
+ g_print ("gmountoperationdbus.c: handle_show_processes()\n");
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- _g_dbus_oom ();
+ processes = g_array_new (FALSE, FALSE, sizeof (GPid));
+ g_variant_iter_init (&iter, arg_processes);
+ while (g_variant_iter_loop (&iter, "i", &pid))
+ g_array_append_val (processes, pid);
- g_signal_connect (op_dbus->op, "reply", (GCallback)show_processes_reply, reply);
+ g_signal_connect (op_dbus->op,
+ "reply",
+ (GCallback)show_processes_reply,
+ g_object_ref (invocation));
g_signal_emit_by_name (op_dbus->op, "show_processes",
- message_string,
+ arg_message_string,
processes,
- choices);
+ arg_choices);
- dbus_free_string_array (choices);
g_array_unref (processes);
+
+ return TRUE;
}
-static void
-mount_op_show_unmount_progress (GMountOperationDBus *op_dbus,
- DBusMessage *message)
+static gboolean
+handle_show_unmount_progress (GVfsDBusMountOperation *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_message_string,
+ guint64 arg_time_left,
+ guint64 arg_bytes_left,
+ gpointer data)
{
- const gchar *message_string;
- guint64 time_left, bytes_left;
- DBusMessage *reply;
- DBusMessageIter iter;
- DBusError error;
-
- reply = NULL;
-
- dbus_message_iter_init (message, &iter);
- dbus_error_init (&error);
- if (!_g_dbus_message_iter_get_args (&iter,
- &error,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_UINT64, &time_left,
- DBUS_TYPE_UINT64, &bytes_left,
- 0))
- {
- reply = dbus_message_new_error (message, error.name, error.message);
- if (reply == NULL)
- _g_dbus_oom ();
- if (!dbus_connection_send (op_dbus->connection, reply, NULL))
- _g_dbus_oom ();
- dbus_message_unref (reply);
- dbus_error_free (&error);
- return;
- }
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- _g_dbus_oom ();
+ GMountOperationDBus *op_dbus = data;
+
+ g_print ("gmountoperationdbus.c: handle_show_unmount_progress()\n");
g_signal_emit_by_name (op_dbus->op, "show-unmount-progress",
- message_string,
- time_left,
- bytes_left);
+ arg_message_string,
+ arg_time_left,
+ arg_bytes_left);
- mount_op_send_reply (op_dbus, reply);
+ gvfs_dbus_mount_operation_complete_show_unmount_progress (object, invocation);
+
+ return TRUE;
}
-static void
-mount_op_aborted (GMountOperationDBus *op_dbus,
- DBusMessage *message)
+static gboolean
+handle_aborted (GVfsDBusMountOperation *object,
+ GDBusMethodInvocation *invocation,
+ gpointer data)
{
+ GMountOperationDBus *op_dbus = data;
+
+ g_print ("gmountoperationdbus.c: handle_aborted()\n");
+
/* also emit reply to make the all DBus ops return */
g_mount_operation_reply (op_dbus->op, G_MOUNT_OPERATION_UNHANDLED);
g_signal_emit_by_name (op_dbus->op, "aborted");
+ gvfs_dbus_mount_operation_complete_aborted (object, invocation);
+
+ return TRUE;
+}
+
+
+static void
+g_mount_operation_dbus_free (GMountOperationDBus *op_dbus)
+{
+ if (op_dbus->connection)
+ {
+ if (op_dbus->mount_op_skeleton != NULL)
+ {
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (op_dbus->mount_op_skeleton));
+ g_object_unref (op_dbus->mount_op_skeleton);
+ }
+ g_object_unref (op_dbus->connection);
+ }
+ g_free (op_dbus->dbus_id);
+ g_free (op_dbus->obj_path);
+ g_free (op_dbus);
+}
+
+GMountSource *
+g_mount_operation_dbus_wrap (GMountOperation *op,
+ GDBusConnection *connection)
+{
+ GMountOperationDBus *op_dbus;
+ static int mount_id = 0;
+ GError *error;
+
+ if (op == NULL)
+ return g_mount_source_new_dummy ();
+
+ op_dbus = g_new0 (GMountOperationDBus, 1);
+
+ op_dbus->op = op;
+ op_dbus->connection = g_object_ref (connection);
+ op_dbus->obj_path = g_strdup_printf ("/org/gtk/gvfs/mountop/%d", mount_id++);
+ if (op_dbus->connection)
+ {
+ op_dbus->dbus_id = g_strdup (g_dbus_connection_get_unique_name (op_dbus->connection));
+ op_dbus->mount_op_skeleton = gvfs_dbus_mount_operation_skeleton_new ();
+
+ g_signal_connect (op_dbus->mount_op_skeleton, "handle-ask-password", G_CALLBACK (handle_ask_password), op_dbus);
+ g_signal_connect (op_dbus->mount_op_skeleton, "handle-ask-question", G_CALLBACK (handle_ask_question), op_dbus);
+ g_signal_connect (op_dbus->mount_op_skeleton, "handle-show-processes", G_CALLBACK (handle_show_processes), op_dbus);
+ g_signal_connect (op_dbus->mount_op_skeleton, "handle-show-unmount-progress", G_CALLBACK (handle_show_unmount_progress), op_dbus);
+ g_signal_connect (op_dbus->mount_op_skeleton, "handle-aborted", G_CALLBACK (handle_aborted), op_dbus);
+
+ error = NULL;
+ if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (op_dbus->mount_op_skeleton),
+ op_dbus->connection,
+ op_dbus->obj_path,
+ &error))
+ {
+ g_warning ("Error exporting GMountOperationDBus: %s (%s, %d)\n",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ }
+ }
+
+ g_object_set_data_full (G_OBJECT (op), "dbus-op",
+ op_dbus, (GDestroyNotify)g_mount_operation_dbus_free);
+
+ return g_mount_source_new (op_dbus->dbus_id, op_dbus->obj_path);
}
diff --git a/common/gmountoperationdbus.h b/common/gmountoperationdbus.h
index 564fc739..7d4111a4 100644
--- a/common/gmountoperationdbus.h
+++ b/common/gmountoperationdbus.h
@@ -33,7 +33,7 @@
G_BEGIN_DECLS
GMountSource *g_mount_operation_dbus_wrap (GMountOperation *op,
- DBusConnection *connection);
+ GDBusConnection *connection);
G_END_DECLS
diff --git a/common/gmountsource.c b/common/gmountsource.c
index 95202280..4aa107c9 100644
--- a/common/gmountsource.c
+++ b/common/gmountsource.c
@@ -23,9 +23,8 @@
#include <config.h>
#include <gmountsource.h>
-#include <gvfsdbusutils.h>
#include <gio/gio.h>
-#include <gvfsdaemonprotocol.h>
+#include <gvfsdbus.h>
#include <string.h>
@@ -93,20 +92,27 @@ g_mount_source_new_dummy (void)
return source;
}
-
-void
-g_mount_source_to_dbus (GMountSource *source,
- DBusMessage *message)
+GVariant *
+g_mount_source_to_dbus (GMountSource *source)
{
g_assert (source->dbus_id != NULL);
g_assert (source->obj_path != NULL);
- if (!dbus_message_append_args (message,
- DBUS_TYPE_STRING, &source->dbus_id,
- DBUS_TYPE_OBJECT_PATH, &source->obj_path,
- 0))
- _g_dbus_oom ();
+ return g_variant_new ("(so)",
+ source->dbus_id,
+ source->obj_path);
+}
+
+GMountSource *
+g_mount_source_from_dbus (GVariant *iter)
+{
+ const gchar *obj_path, *dbus_id;
+
+ g_variant_get (iter, "(&s&o)",
+ &dbus_id,
+ &obj_path);
+ return g_mount_source_new (dbus_id, obj_path);
}
const char *
@@ -156,64 +162,103 @@ ask_password_data_free (gpointer _data)
g_free (data);
}
+static GVfsDBusMountOperation *
+create_mount_operation_proxy (GMountSource *source,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GVfsDBusMountOperation *proxy;
+ GError *error;
+
+ /* If no dbus id specified, reply that we weren't handled */
+ if (source->dbus_id[0] == 0)
+ {
+ if (callback != NULL)
+ g_simple_async_report_error_in_idle (G_OBJECT (source),
+ callback,
+ user_data,
+ G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Internal Error");
+ return NULL;
+ }
+
+ error = NULL;
+ proxy = gvfs_dbus_mount_operation_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ source->dbus_id,
+ source->obj_path,
+ NULL,
+ &error);
+ if (proxy == NULL)
+ if (callback != NULL)
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (source),
+ callback,
+ user_data,
+ error);
+
+ return proxy;
+}
+
/* the callback from dbus -> main thread */
static void
-ask_password_reply (DBusMessage *reply,
- GError *error,
- gpointer _data)
+ask_password_reply (GVfsDBusMountOperation *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
GSimpleAsyncResult *result;
AskPasswordData *data;
- dbus_bool_t handled, aborted, anonymous;
+ gboolean handled, aborted, anonymous;
guint32 password_save;
- const char *password, *username, *domain;
- DBusMessageIter iter;
+ gchar *password, *username, *domain;
+ GError *error;
- result = G_SIMPLE_ASYNC_RESULT (_data);
+ result = G_SIMPLE_ASYNC_RESULT (user_data);
handled = TRUE;
+ g_print ("gmountsource.c: ask_password_reply()\n");
+
data = g_new0 (AskPasswordData, 1);
g_simple_async_result_set_op_res_gpointer (result, data, ask_password_data_free);
- if (reply == NULL)
+ error = NULL;
+ if (!gvfs_dbus_mount_operation_call_ask_password_finish (proxy,
+ &handled,
+ &aborted,
+ &password,
+ &username,
+ &domain,
+ &anonymous,
+ &password_save,
+ res,
+ &error))
{
data->aborted = TRUE;
+ g_simple_async_result_take_error (result, error);
}
else
{
- dbus_message_iter_init (reply, &iter);
- if (!_g_dbus_message_iter_get_args (&iter, NULL,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &aborted,
- DBUS_TYPE_STRING, &password,
- DBUS_TYPE_STRING, &username,
- DBUS_TYPE_STRING, &domain,
- DBUS_TYPE_BOOLEAN, &anonymous,
- DBUS_TYPE_UINT32, &password_save,
- 0))
- data->aborted = TRUE;
- else
- {
- data->aborted = aborted;
-
- if (!anonymous)
- {
- data->password = g_strdup (password);
- data->username = *username == 0 ? NULL : g_strdup (username);
- data->domain = *domain == 0 ? NULL : g_strdup (domain);
- }
- data->password_save = (GPasswordSave)password_save;
- data->anonymous = anonymous;
-
- /* TODO: handle more args */
- }
+ data->aborted = aborted;
+
+ if (!anonymous)
+ {
+ data->password = g_strdup (password);
+ data->username = *username == 0 ? NULL : g_strdup (username);
+ data->domain = *domain == 0 ? NULL : g_strdup (domain);
+ }
+ data->password_save = (GPasswordSave)password_save;
+ data->anonymous = anonymous;
+
+ /* TODO: handle more args */
+ g_free (password);
+ g_free (username);
+ g_free (domain);
}
if (handled == FALSE)
{
g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
}
-
+
g_simple_async_result_complete (result);
g_object_unref (result);
}
@@ -228,49 +273,27 @@ g_mount_source_ask_password_async (GMountSource *source,
gpointer user_data)
{
GSimpleAsyncResult *result;
- DBusMessage *message;
- guint32 flags_as_int;
-
-
- /* If no dbus id specified, reply that we weren't handled */
- if (source->dbus_id[0] == 0)
- {
- g_simple_async_report_error_in_idle (G_OBJECT (source),
- callback,
- user_data,
- G_IO_ERROR, G_IO_ERROR_FAILED,
- "Internal Error");
- return;
- }
-
- if (message_string == NULL)
- message_string = "";
- if (default_user == NULL)
- default_user = "";
- if (default_domain == NULL)
- default_domain = "";
-
- flags_as_int = flags;
-
- message = dbus_message_new_method_call (source->dbus_id,
- source->obj_path,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_PASSWORD);
+ GVfsDBusMountOperation *proxy;
- _g_dbus_message_append_args (message,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_STRING, &default_user,
- DBUS_TYPE_STRING, &default_domain,
- DBUS_TYPE_UINT32, &flags_as_int,
- 0);
+ proxy = create_mount_operation_proxy (source, callback, user_data);
+ if (proxy == NULL)
+ return;
- result = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
- g_mount_source_ask_password_async);
/* 30 minute timeout */
- _g_dbus_connection_call_async (NULL, message, 1000 * 60 * 30,
- ask_password_reply, result);
- dbus_message_unref (message);
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), 1000 * 60 * 30);
+ result = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
+ g_mount_source_ask_password_async);
+
+ gvfs_dbus_mount_operation_call_ask_password (proxy,
+ message_string ? message_string : "",
+ default_user ? default_user : "",
+ default_domain ? default_domain : "",
+ flags,
+ NULL,
+ (GAsyncReadyCallback) ask_password_reply,
+ result);
+ g_object_unref (proxy);
}
/**
@@ -493,40 +516,39 @@ struct AskQuestionData {
/* the callback from dbus -> main thread */
static void
-ask_question_reply (DBusMessage *reply,
- GError *error,
- gpointer _data)
+ask_question_reply (GVfsDBusMountOperation *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
GSimpleAsyncResult *result;
AskQuestionData *data;
- dbus_bool_t handled, aborted;
+ gboolean handled, aborted;
guint32 choice;
- DBusMessageIter iter;
-
- result = G_SIMPLE_ASYNC_RESULT (_data);
+ GError *error;
+
+ result = G_SIMPLE_ASYNC_RESULT (user_data);
handled = TRUE;
+ g_print ("gmountsource.c: ask_question_reply()\n");
+
data = g_new0 (AskQuestionData, 1);
g_simple_async_result_set_op_res_gpointer (result, data, g_free);
- if (reply == NULL)
+ error = NULL;
+ if (!gvfs_dbus_mount_operation_call_ask_question_finish (proxy,
+ &handled,
+ &aborted,
+ &choice,
+ res,
+ &error))
{
data->aborted = TRUE;
+ g_simple_async_result_take_error (result, error);
}
else
{
- dbus_message_iter_init (reply, &iter);
- if (!_g_dbus_message_iter_get_args (&iter, NULL,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &aborted,
- DBUS_TYPE_UINT32, &choice,
- 0))
- data->aborted = TRUE;
- else
- {
- data->aborted = aborted;
- data->choice = choice;
- }
+ data->aborted = aborted;
+ data->choice = choice;
}
if (handled == FALSE)
@@ -593,40 +615,25 @@ g_mount_source_ask_question_async (GMountSource *source,
gpointer user_data)
{
GSimpleAsyncResult *result;
- DBusMessage *message;
-
- /* If no dbus id specified, reply that we weren't handled */
- if (source->dbus_id[0] == 0)
- {
- g_simple_async_report_error_in_idle (G_OBJECT (source),
- callback,
- user_data,
- G_IO_ERROR, G_IO_ERROR_FAILED,
- "Internal Error");
- return;
- }
-
- if (message_string == NULL)
- message_string = "";
+ GVfsDBusMountOperation *proxy;
- message = dbus_message_new_method_call (source->dbus_id,
- source->obj_path,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_QUESTION);
+ proxy = create_mount_operation_proxy (source, callback, user_data);
+ if (proxy == NULL)
+ return;
- _g_dbus_message_append_args (message,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &choices, n_choices,
- 0);
+ /* 30 minute timeout */
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), 1000 * 60 * 30);
result = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
g_mount_source_ask_question_async);
- /* 30 minute timeout */
- _g_dbus_connection_call_async (NULL, message, 1000 * 60 * 30,
- ask_question_reply, result);
- dbus_message_unref (message);
-
+
+ gvfs_dbus_mount_operation_call_ask_question (proxy,
+ message_string ? message_string : "",
+ choices,
+ NULL,
+ (GAsyncReadyCallback) ask_question_reply,
+ result);
+ g_object_unref (proxy);
}
gboolean
@@ -714,40 +721,40 @@ struct ShowProcessesData {
/* the callback from dbus -> main thread */
static void
-show_processes_reply (DBusMessage *reply,
- GError *error,
- gpointer _data)
+show_processes_reply (GVfsDBusMountOperation *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
GSimpleAsyncResult *result;
ShowProcessesData *data;
- dbus_bool_t handled, aborted;
+ gboolean handled, aborted;
guint32 choice;
- DBusMessageIter iter;
-
- result = G_SIMPLE_ASYNC_RESULT (_data);
+ GError *error;
+
+ result = G_SIMPLE_ASYNC_RESULT (user_data);
handled = TRUE;
+ g_print ("gmountsource.c: show_processes_reply()\n");
+
data = g_new0 (ShowProcessesData, 1);
g_simple_async_result_set_op_res_gpointer (result, data, g_free);
- if (reply == NULL)
+
+ error = NULL;
+ if (!gvfs_dbus_mount_operation_call_show_processes_finish (proxy,
+ &handled,
+ &aborted,
+ &choice,
+ res,
+ &error))
{
data->aborted = TRUE;
+ g_simple_async_result_take_error (result, error);
}
else
{
- dbus_message_iter_init (reply, &iter);
- if (!_g_dbus_message_iter_get_args (&iter, NULL,
- DBUS_TYPE_BOOLEAN, &handled,
- DBUS_TYPE_BOOLEAN, &aborted,
- DBUS_TYPE_UINT32, &choice,
- 0))
- data->aborted = TRUE;
- else
- {
- data->aborted = aborted;
- data->choice = choice;
- }
+ data->aborted = aborted;
+ data->choice = choice;
}
if (handled == FALSE)
@@ -769,42 +776,33 @@ g_mount_source_show_processes_async (GMountSource *source,
gpointer user_data)
{
GSimpleAsyncResult *result;
- DBusMessage *message;
+ GVfsDBusMountOperation *proxy;
+ GVariantBuilder builder;
+ guint i;
+
+ proxy = create_mount_operation_proxy (source, callback, user_data);
+ if (proxy == NULL)
+ return;
- /* If no dbus id specified, reply that we weren't handled */
- if (source->dbus_id[0] == 0)
- {
- g_simple_async_report_error_in_idle (G_OBJECT (source),
- callback,
- user_data,
- G_IO_ERROR, G_IO_ERROR_FAILED,
- "Internal Error");
- return;
- }
+ /* 30 minute timeout */
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), 1000 * 60 * 30);
result = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
g_mount_source_show_processes_async);
-
- if (message_string == NULL)
- message_string = "";
-
- message = dbus_message_new_method_call (source->dbus_id,
- source->obj_path,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_PROCESSES);
-
- _g_dbus_message_append_args (message,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &choices, n_choices,
- DBUS_TYPE_ARRAY, DBUS_TYPE_INT32,
- &processes->data, processes->len,
- 0);
-
- /* 30 minute timeout */
- _g_dbus_connection_call_async (NULL, message, 1000 * 60 * 30,
- show_processes_reply, result);
- dbus_message_unref (message);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("ai"));
+ for (i = 0; i < processes->len; i++)
+ g_variant_builder_add (&builder, "i",
+ g_array_index (processes, gint32, i));
+
+ gvfs_dbus_mount_operation_call_show_processes (proxy,
+ message_string ? message_string : "",
+ choices,
+ g_variant_builder_end (&builder),
+ NULL,
+ (GAsyncReadyCallback) show_processes_reply,
+ result);
+ g_object_unref (proxy);
}
gboolean
@@ -931,23 +929,28 @@ op_show_processes (GMountOperation *op,
return TRUE;
}
-/* the callback from dbus -> main thread */
static void
-show_unmount_progress_reply (DBusMessage *reply,
- GError *error,
- gpointer _data)
+show_unmount_progress_reply (GVfsDBusMountOperation *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- if (error != NULL)
- g_warning ("ShowUnmountProgress request failed: %s", error->message);
+ GError *error;
+
+ error = NULL;
+ if (!gvfs_dbus_mount_operation_call_show_unmount_progress_finish (proxy, res, &error))
+ {
+ g_warning ("ShowUnmountProgress request failed: %s", error->message);
+ g_error_free (error);
+ }
}
void
-g_mount_source_show_unmount_progress (GMountSource *source,
- const char *message_string,
- guint64 time_left,
- guint64 bytes_left)
+g_mount_source_show_unmount_progress (GMountSource *source,
+ const char *message_string,
+ guint64 time_left,
+ guint64 bytes_left)
{
- DBusMessage *message;
+ GVfsDBusMountOperation *proxy;
/* If no dbus id specified, warn and return */
if (source->dbus_id[0] == 0)
@@ -956,25 +959,22 @@ g_mount_source_show_unmount_progress (GMountSource *source,
"ignoring show-unmount-progress request");
return;
}
-
- if (message_string == NULL)
- message_string = "";
-
- message = dbus_message_new_method_call (source->dbus_id,
- source->obj_path,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_UNMOUNT_PROGRESS);
-
- _g_dbus_message_append_args (message,
- DBUS_TYPE_STRING, &message_string,
- DBUS_TYPE_UINT64, &time_left,
- DBUS_TYPE_UINT64, &bytes_left,
- 0);
+
+ proxy = create_mount_operation_proxy (source, NULL, NULL);
+ if (proxy == NULL)
+ return;
/* 30 minute timeout */
- _g_dbus_connection_call_async (NULL, message, 1000 * 60 * 30,
- show_unmount_progress_reply, NULL);
- dbus_message_unref (message);
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), 1000 * 60 * 30);
+
+ gvfs_dbus_mount_operation_call_show_unmount_progress (proxy,
+ message_string ? message_string : "",
+ time_left,
+ bytes_left,
+ NULL,
+ (GAsyncReadyCallback) show_unmount_progress_reply,
+ NULL);
+ g_object_unref (proxy);
}
static void
@@ -991,38 +991,30 @@ op_show_unmount_progress (GMountOperation *op,
g_signal_stop_emission_by_name (op, "show_unmount_progress");
}
-gboolean
-g_mount_source_abort (GMountSource *source)
+static void
+abort_reply (GVfsDBusMountOperation *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
{
- DBusMessage *message;
- DBusConnection *connection;
- gboolean ret;
-
- ret = FALSE;
-
- /* If no dbus id specified, reply that we weren't handled */
- if (source->dbus_id[0] == 0)
- goto out;
+ g_print ("gmountsource.c: abort_reply()\n");
- connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
- if (connection == NULL)
- goto out;
-
- message = dbus_message_new_method_call (source->dbus_id,
- source->obj_path,
- G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
- G_VFS_DBUS_MOUNT_OPERATION_OP_ABORTED);
-
- if (message)
- {
- dbus_connection_send (connection, message, NULL);
- dbus_message_unref (message);
- }
+ gvfs_dbus_mount_operation_call_aborted_finish (proxy, res, NULL);
+}
- ret = TRUE;
+gboolean
+g_mount_source_abort (GMountSource *source)
+{
+ GVfsDBusMountOperation *proxy;
- out:
- return ret;
+ proxy = create_mount_operation_proxy (source, NULL, NULL);
+ if (proxy == NULL)
+ return FALSE;
+
+ gvfs_dbus_mount_operation_call_aborted (proxy, NULL,
+ (GAsyncReadyCallback) abort_reply, NULL);
+
+ g_object_unref (proxy);
+ return TRUE;
}
static void
diff --git a/common/gmountsource.h b/common/gmountsource.h
index 31b58afe..ce93cb3b 100644
--- a/common/gmountsource.h
+++ b/common/gmountsource.h
@@ -54,8 +54,8 @@ GType g_mount_source_get_type (void) G_GNUC_CONST;
GMountSource *g_mount_source_new (const char *dbus_id,
const char *obj_path);
GMountSource *g_mount_source_new_dummy (void);
-void g_mount_source_to_dbus (GMountSource *source,
- DBusMessage *message);
+GVariant *g_mount_source_to_dbus (GMountSource *source);
+GMountSource *g_mount_source_from_dbus (GVariant *iter);
gboolean g_mount_source_ask_password (GMountSource *mount_source,
const char *message,
const char *initial_user,
diff --git a/common/gmountspec.c b/common/gmountspec.c
index 5c42d900..968032ca 100644
--- a/common/gmountspec.c
+++ b/common/gmountspec.c
@@ -27,7 +27,6 @@
#include <glib/gi18n-lib.h>
-#include "gvfsdbusutils.h"
#include "gmountspec.h"
static GHashTable *unique_hash = NULL;
@@ -226,113 +225,64 @@ g_mount_spec_unref (GMountSpec *spec)
}
GMountSpec *
-g_mount_spec_from_dbus (DBusMessageIter *iter)
+g_mount_spec_from_dbus (GVariant *iter)
{
GMountSpec *spec;
- DBusMessageIter array_iter, struct_iter, spec_iter;
- const char *key;
- char *value;
- char *mount_prefix;
-
- if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRUCT)
- return NULL;
-
- dbus_message_iter_recurse (iter, &spec_iter);
+ const gchar *key;
+ const gchar *mount_prefix;
+ GVariantIter *iter_mount_spec_items;
+ GVariant *value;
mount_prefix = NULL;
- if (!_g_dbus_message_iter_get_args (&spec_iter, NULL,
- G_DBUS_TYPE_CSTRING, &mount_prefix,
- 0))
- return NULL;
-
+ g_variant_get (iter, "(^&aya{sv})",
+ &mount_prefix,
+ &iter_mount_spec_items);
+
spec = g_mount_spec_new (NULL);
g_free (spec->mount_prefix);
- spec->mount_prefix = mount_prefix;
-
- if (dbus_message_iter_get_arg_type (&spec_iter) != DBUS_TYPE_ARRAY ||
- dbus_message_iter_get_element_type (&spec_iter) != DBUS_TYPE_STRUCT)
- {
- g_mount_spec_unref (spec);
- return NULL;
- }
+ spec->mount_prefix = g_strdup (mount_prefix);
- dbus_message_iter_recurse (&spec_iter, &array_iter);
- while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRUCT)
+ while (g_variant_iter_loop (iter_mount_spec_items, "{&sv}", &key, &value))
{
- dbus_message_iter_recurse (&array_iter, &struct_iter);
- if (_g_dbus_message_iter_get_args (&struct_iter, NULL,
- DBUS_TYPE_STRING, &key,
- G_DBUS_TYPE_CSTRING, &value,
- 0))
- add_item (spec, key, value);
- dbus_message_iter_next (&array_iter);
+ add_item (spec, key, g_variant_dup_bytestring (value, NULL));
}
- dbus_message_iter_next (iter);
-
/* Sort on key */
g_array_sort (spec->items, item_compare);
return spec;
}
-void
-g_mount_spec_to_dbus_with_path (DBusMessageIter *iter,
- GMountSpec *spec,
+GVariant *
+g_mount_spec_to_dbus_with_path (GMountSpec *spec,
const char *path)
{
- DBusMessageIter spec_iter, array_iter, item_iter;
+ GVariantBuilder builder;
+ GVariant *v;
int i;
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &spec_iter))
- _g_dbus_oom ();
-
- _g_dbus_message_iter_append_cstring (&spec_iter, path ? path : "");
-
- if (!dbus_message_iter_open_container (&spec_iter,
- DBUS_TYPE_ARRAY,
- G_MOUNT_SPEC_ITEM_TYPE_AS_STRING,
- &array_iter))
- _g_dbus_oom ();
-
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
for (i = 0; i < spec->items->len; i++)
{
GMountSpecItem *item = &g_array_index (spec->items, GMountSpecItem, i);
- if (!dbus_message_iter_open_container (&array_iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &item_iter))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_append_basic (&item_iter, DBUS_TYPE_STRING,
- &item->key))
- _g_dbus_oom ();
- _g_dbus_message_iter_append_cstring (&item_iter, item->value);
-
- if (!dbus_message_iter_close_container (&array_iter, &item_iter))
- _g_dbus_oom ();
-
+ g_variant_builder_add_value (&builder, g_variant_new ("{sv}",
+ item->key,
+ g_variant_new_bytestring (item->value)));
}
- if (!dbus_message_iter_close_container (&spec_iter, &array_iter))
- _g_dbus_oom ();
-
+ v = g_variant_new ("(^aya{sv})",
+ path ? path : "",
+ &builder);
+ g_variant_builder_clear (&builder);
-
- if (!dbus_message_iter_close_container (iter, &spec_iter))
- _g_dbus_oom ();
-
+ return v;
}
-void
-g_mount_spec_to_dbus (DBusMessageIter *iter,
- GMountSpec *spec)
+GVariant *
+g_mount_spec_to_dbus (GMountSpec *spec)
{
- g_mount_spec_to_dbus_with_path (iter, spec, spec->mount_prefix);
+ return g_mount_spec_to_dbus_with_path (spec, spec->mount_prefix);
}
static gboolean
diff --git a/common/gmountspec.h b/common/gmountspec.h
index f7837e65..da903e1b 100644
--- a/common/gmountspec.h
+++ b/common/gmountspec.h
@@ -24,28 +24,10 @@
#define __G_MOUNT_SPEC_H__
#include <glib.h>
-#include <dbus/dbus.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
-#define G_MOUNT_SPEC_ITEM_INNER_TYPE_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING
-
-#define G_MOUNT_SPEC_ITEM_TYPE_AS_STRING \
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
- G_MOUNT_SPEC_ITEM_INNER_TYPE_AS_STRING \
- DBUS_STRUCT_END_CHAR_AS_STRING
-
-#define G_MOUNT_SPEC_INNER_TYPE_AS_STRING \
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING \
- DBUS_TYPE_ARRAY_AS_STRING G_MOUNT_SPEC_ITEM_TYPE_AS_STRING
-
-#define G_MOUNT_SPEC_TYPE_AS_STRING \
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
- G_MOUNT_SPEC_INNER_TYPE_AS_STRING \
- DBUS_STRUCT_END_CHAR_AS_STRING
-
typedef struct {
char *key;
char *value;
@@ -65,11 +47,9 @@ GMountSpec *g_mount_spec_ref (GMountSpec *spec);
void g_mount_spec_unref (GMountSpec *spec);
GMountSpec *g_mount_spec_get_unique_for (GMountSpec *spec);
GMountSpec *g_mount_spec_copy (GMountSpec *spec);
-GMountSpec *g_mount_spec_from_dbus (DBusMessageIter *iter);
-void g_mount_spec_to_dbus (DBusMessageIter *iter,
- GMountSpec *spec);
-void g_mount_spec_to_dbus_with_path (DBusMessageIter *iter,
- GMountSpec *spec,
+GMountSpec *g_mount_spec_from_dbus (GVariant *iter);
+GVariant *g_mount_spec_to_dbus (GMountSpec *spec);
+GVariant *g_mount_spec_to_dbus_with_path (GMountSpec *spec,
const char *path);
void g_mount_spec_set_mount_prefix (GMountSpec *spec,
const char *mount_prefix);
diff --git a/common/gmounttracker.c b/common/gmounttracker.c
index 00908ca0..a3909884 100644
--- a/common/gmounttracker.c
+++ b/common/gmounttracker.c
@@ -25,8 +25,8 @@
#include <string.h>
#include <gmounttracker.h>
-#include <gvfsdbusutils.h>
#include <gvfsdaemonprotocol.h>
+#include <gvfsdbus.h>
enum {
MOUNTED,
@@ -51,14 +51,12 @@ struct _GMountTracker
GMutex lock;
GList *mounts;
- DBusConnection *connection;
+ GDBusConnection *connection;
+ GVfsDBusMountTracker *proxy;
};
G_DEFINE_TYPE (GMountTracker, g_mount_tracker, G_TYPE_OBJECT)
-static DBusHandlerResult g_mount_tracker_filter_func (DBusConnection *conn,
- DBusMessage *message,
- gpointer data);
static GObject* g_mount_tracker_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params);
@@ -174,53 +172,41 @@ g_mount_info_apply_prefix (GMountInfo *info,
}
GMountInfo *
-g_mount_info_from_dbus (DBusMessageIter *iter)
+g_mount_info_from_dbus (GVariant *iter)
{
- DBusMessageIter struct_iter;
GMountInfo *info;
GMountSpec *mount_spec;
- dbus_bool_t user_visible;
- char *display_name;
- char *stable_name;
- char *x_content_types;
- char *icon_str;
- char *prefered_filename_encoding;
- char *dbus_id;
- char *obj_path;
- char *fuse_mountpoint;
- char *default_location;
+ gboolean user_visible;
+ const gchar *display_name;
+ const gchar *stable_name;
+ const gchar *x_content_types;
+ const gchar *icon_str;
+ const gchar *prefered_filename_encoding;
+ const gchar *dbus_id;
+ const gchar *obj_path;
+ const gchar *fuse_mountpoint;
+ const gchar *default_location;
GIcon *icon;
+ GVariant *iter_mount_spec;
GError *error;
- if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRUCT)
+ g_variant_get (iter, "(&s&o&s&s&s&s&sb^&ay@(aya{sv})^&ay)",
+ &dbus_id,
+ &obj_path,
+ &display_name,
+ &stable_name,
+ &x_content_types,
+ &icon_str,
+ &prefered_filename_encoding,
+ &user_visible,
+ &fuse_mountpoint,
+ &iter_mount_spec,
+ &default_location);
+
+ mount_spec = g_mount_spec_from_dbus (iter_mount_spec);
+ g_variant_unref (iter_mount_spec);
+ if (mount_spec == NULL)
return NULL;
-
- dbus_message_iter_recurse (iter, &struct_iter);
-
- if (!_g_dbus_message_iter_get_args (&struct_iter, NULL,
- DBUS_TYPE_STRING, &dbus_id,
- DBUS_TYPE_OBJECT_PATH, &obj_path,
- DBUS_TYPE_STRING, &display_name,
- DBUS_TYPE_STRING, &stable_name,
- DBUS_TYPE_STRING, &x_content_types,
- DBUS_TYPE_STRING, &icon_str,
- DBUS_TYPE_STRING, &prefered_filename_encoding,
- DBUS_TYPE_BOOLEAN, &user_visible,
- G_DBUS_TYPE_CSTRING, &fuse_mountpoint,
- 0))
- return NULL;
-
- mount_spec = g_mount_spec_from_dbus (&struct_iter);
- if (mount_spec == NULL) {
- g_free (fuse_mountpoint);
- return NULL;
- }
-
- if (!_g_dbus_message_iter_get_args (&struct_iter, NULL,
- G_DBUS_TYPE_CSTRING, &default_location,
- 0))
- default_location = g_strdup ("");
-
if (icon_str == NULL || strlen (icon_str) == 0)
icon_str = "drive-removable-media";
@@ -244,13 +230,12 @@ g_mount_info_from_dbus (DBusMessageIter *iter)
info->mount_spec = mount_spec;
info->user_visible = user_visible;
info->prefered_filename_encoding = g_strdup (prefered_filename_encoding);
- info->fuse_mountpoint = fuse_mountpoint;
- info->default_location = default_location;
+ info->fuse_mountpoint = g_strdup (fuse_mountpoint);
+ info->default_location = g_strdup (default_location);
return info;
}
-
static void
g_mount_tracker_finalize (GObject *object)
{
@@ -264,21 +249,10 @@ g_mount_tracker_finalize (GObject *object)
(GFunc)g_mount_info_unref, NULL);
g_list_free (tracker->mounts);
- dbus_connection_remove_filter (tracker->connection, g_mount_tracker_filter_func, tracker);
-
-
- dbus_bus_remove_match (tracker->connection,
- "sender='"G_VFS_DBUS_DAEMON_NAME"',"
- "interface='"G_VFS_DBUS_MOUNTTRACKER_INTERFACE"',"
- "member='"G_VFS_DBUS_MOUNTTRACKER_SIGNAL_MOUNTED"'",
- NULL);
- dbus_bus_remove_match (tracker->connection,
- "sender='"G_VFS_DBUS_DAEMON_NAME"',"
- "interface='"G_VFS_DBUS_MOUNTTRACKER_INTERFACE"',"
- "member='"G_VFS_DBUS_MOUNTTRACKER_SIGNAL_UNMOUNTED"'",
- NULL);
-
- dbus_connection_unref (tracker->connection);
+ if (tracker->proxy)
+ g_object_unref (tracker->proxy);
+ if (tracker->connection)
+ g_object_unref (tracker->connection);
if (G_OBJECT_CLASS (g_mount_tracker_parent_class)->finalize)
(*G_OBJECT_CLASS (g_mount_tracker_parent_class)->finalize) (object);
@@ -332,10 +306,10 @@ g_mount_tracker_set_property (GObject *object,
{
case PROP_CONNECTION:
if (tracker->connection)
- dbus_connection_unref (tracker->connection);
+ g_object_unref (tracker->connection);
tracker->connection = NULL;
if (g_value_get_pointer (value))
- tracker->connection = dbus_connection_ref (g_value_get_pointer (value));
+ tracker->connection = g_object_ref (g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -427,115 +401,94 @@ g_mount_tracker_remove_mount (GMountTracker *tracker,
static void
list_mounts_reply (GMountTracker *tracker,
- DBusMessage *reply)
+ GVariant *iter_mounts)
{
- DBusMessageIter iter, array_iter;
GMountInfo *info;
- gboolean b;
-
- b = dbus_message_iter_init (reply, &iter);
- if (b && dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY)
+ GVariantIter iter;
+ GVariant *child;
+
+ g_variant_iter_init (&iter, iter_mounts);
+ while ((child = g_variant_iter_next_value (&iter)))
{
- dbus_message_iter_recurse (&iter, &array_iter);
-
- do
+ info = g_mount_info_from_dbus (child);
+ if (info)
{
- info = g_mount_info_from_dbus (&array_iter);
- if (info)
- {
- g_mount_tracker_add_mount (tracker, info);
- g_mount_info_unref (info);
- }
+ g_mount_tracker_add_mount (tracker, info);
+ g_mount_info_unref (info);
}
- while (dbus_message_iter_next (&array_iter));
- }
- else
- {
- /* list_mounts_reply problem - gvfsd not running? */
+ g_variant_unref (child);
}
}
-static DBusHandlerResult
-g_mount_tracker_filter_func (DBusConnection *conn,
- DBusMessage *message,
- gpointer data)
+static void
+mounted_cb (GVfsDBusMountTracker *object,
+ GVariant *arg_mount,
+ gpointer user_data)
{
- GMountTracker *tracker = data;
+ GMountTracker *tracker = user_data;
GMountInfo *info;
- DBusMessageIter iter;
-
- if (dbus_message_is_signal (message,
- G_VFS_DBUS_MOUNTTRACKER_INTERFACE,
- G_VFS_DBUS_MOUNTTRACKER_SIGNAL_MOUNTED))
+
+ info = g_mount_info_from_dbus (arg_mount);
+ if (info)
{
- dbus_message_iter_init (message, &iter);
- info = g_mount_info_from_dbus (&iter);
-
- if (info)
- {
- g_mount_tracker_add_mount (tracker, info);
- g_mount_info_unref (info);
- }
+ g_mount_tracker_add_mount (tracker, info);
+ g_mount_info_unref (info);
}
- else if (dbus_message_is_signal (message,
- G_VFS_DBUS_MOUNTTRACKER_INTERFACE,
- G_VFS_DBUS_MOUNTTRACKER_SIGNAL_UNMOUNTED))
- {
- dbus_message_iter_init (message, &iter);
- info = g_mount_info_from_dbus (&iter);
+}
- if (info)
- {
- g_mount_tracker_remove_mount (tracker, info);
- g_mount_info_unref (info);
- }
+static void
+unmounted_cb (GVfsDBusMountTracker *object,
+ GVariant *arg_mount,
+ gpointer user_data)
+{
+ GMountTracker *tracker = user_data;
+ GMountInfo *info;
+
+ info = g_mount_info_from_dbus (arg_mount);
+ if (info)
+ {
+ g_mount_tracker_remove_mount (tracker, info);
+ g_mount_info_unref (info);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
}
/* Called after construction when the construct properties (like connection) are set */
static void
init_connection (GMountTracker *tracker)
{
- DBusMessage *message, *reply;
+ GError *error;
+ GVariant *iter_mounts;
if (tracker->connection == NULL)
- tracker->connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
-
- message =
- dbus_message_new_method_call (G_VFS_DBUS_DAEMON_NAME,
- G_VFS_DBUS_MOUNTTRACKER_PATH,
- G_VFS_DBUS_MOUNTTRACKER_INTERFACE,
- G_VFS_DBUS_MOUNTTRACKER_OP_LIST_MOUNTS);
- if (message == NULL)
- _g_dbus_oom ();
-
- dbus_message_set_auto_start (message, TRUE);
-
- reply = dbus_connection_send_with_reply_and_block (tracker->connection, message,
- G_VFS_DBUS_TIMEOUT_MSECS,
- NULL);
- dbus_message_unref (message);
-
- if (reply != NULL)
+ tracker->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+
+ error = NULL;
+ tracker->proxy = gvfs_dbus_mount_tracker_proxy_new_sync (tracker->connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ G_VFS_DBUS_DAEMON_NAME,
+ G_VFS_DBUS_MOUNTTRACKER_PATH,
+ NULL,
+ &error);
+ if (tracker->proxy == NULL)
{
- list_mounts_reply (tracker, reply);
- dbus_message_unref (reply);
+ g_printerr ("Error creating proxy: %s (%s, %d)\n",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ return;
}
-
- dbus_connection_add_filter (tracker->connection, g_mount_tracker_filter_func, tracker, NULL);
-
- dbus_bus_add_match (tracker->connection,
- "sender='"G_VFS_DBUS_DAEMON_NAME"',"
- "interface='"G_VFS_DBUS_MOUNTTRACKER_INTERFACE"',"
- "member='"G_VFS_DBUS_MOUNTTRACKER_SIGNAL_MOUNTED"'",
- NULL);
- dbus_bus_add_match (tracker->connection,
- "sender='"G_VFS_DBUS_DAEMON_NAME"',"
- "interface='"G_VFS_DBUS_MOUNTTRACKER_INTERFACE"',"
- "member='"G_VFS_DBUS_MOUNTTRACKER_SIGNAL_UNMOUNTED"'",
- NULL);
+
+ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (tracker->proxy),
+ G_VFS_DBUS_TIMEOUT_MSECS);
+
+ if (gvfs_dbus_mount_tracker_call_list_mounts_sync (tracker->proxy, &iter_mounts, NULL, NULL))
+ {
+ list_mounts_reply (tracker, iter_mounts);
+ g_variant_unref (iter_mounts);
+ }
+
+ g_signal_connect (tracker->proxy, "mounted", G_CALLBACK (mounted_cb), tracker);
+ g_signal_connect (tracker->proxy, "unmounted", G_CALLBACK (unmounted_cb), tracker);
}
static void
@@ -565,7 +518,7 @@ g_mount_tracker_constructor (GType type,
}
GMountTracker *
-g_mount_tracker_new (DBusConnection *connection)
+g_mount_tracker_new (GDBusConnection *connection)
{
GMountTracker *tracker;
diff --git a/common/gmounttracker.h b/common/gmounttracker.h
index caaab8a6..894bddb3 100644
--- a/common/gmounttracker.h
+++ b/common/gmounttracker.h
@@ -76,9 +76,9 @@ const char *g_mount_info_resolve_path (GMountInfo *info,
void g_mount_info_apply_prefix (GMountInfo *info,
char **path);
-GMountInfo * g_mount_info_from_dbus (DBusMessageIter *iter);
+GMountInfo * g_mount_info_from_dbus (GVariant *iter);
-GMountTracker *g_mount_tracker_new (DBusConnection *connection);
+GMountTracker *g_mount_tracker_new (GDBusConnection *connection);
GList * g_mount_tracker_list_mounts (GMountTracker *tracker);
GMountInfo * g_mount_tracker_find_by_mount_spec (GMountTracker *tracker,
GMountSpec *mount_spec);
diff --git a/common/gvfsdaemonprotocol.c b/common/gvfsdaemonprotocol.c
index b35efcb9..c73aac7d 100644
--- a/common/gvfsdaemonprotocol.c
+++ b/common/gvfsdaemonprotocol.c
@@ -23,48 +23,22 @@
#include <config.h>
#include <glib-object.h>
-#include <dbus/dbus.h>
#include <glib/gi18n-lib.h>
#include <gvfsdaemonprotocol.h>
-#include <gvfsdbusutils.h>
#include <gio/gio.h>
static const char *
get_object_signature (GObject *obj)
{
if (G_IS_ICON (obj))
- {
- return
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING;
- }
- return
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING;
+ return "(us)";
+ return "(u)";
}
-static void
-append_strv (DBusMessageIter *iter, char **strv)
+static GVariant *
+append_object (GObject *obj)
{
- _g_dbus_message_iter_append_args (iter,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &strv, g_strv_length (strv),
- 0);
-}
-
-static void
-append_object (DBusMessageIter *iter, GObject *obj)
-{
- DBusMessageIter obj_struct_iter;
- guint32 v_uint32;
-
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &obj_struct_iter))
- _g_dbus_oom ();
+ GVariant *var;
/* version 1 and 2 are deprecated old themed-icon and file-icon values */
if (G_IS_ICON (obj))
@@ -72,15 +46,7 @@ append_object (DBusMessageIter *iter, GObject *obj)
char *data;
data = g_icon_to_string (G_ICON (obj));
- v_uint32 = 3;
- if (!dbus_message_iter_append_basic (&obj_struct_iter,
- DBUS_TYPE_UINT32, &v_uint32))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_append_basic (&obj_struct_iter,
- DBUS_TYPE_STRING, &data))
- _g_dbus_oom ();
-
+ var = g_variant_new ("(us)", 3, data);
g_free (data);
}
else
@@ -89,14 +55,10 @@ append_object (DBusMessageIter *iter, GObject *obj)
if (obj != NULL)
g_warning ("Unknown attribute object type, ignoring");
- v_uint32 = 0;
- if (!dbus_message_iter_append_basic (&obj_struct_iter,
- DBUS_TYPE_UINT32, &v_uint32))
- _g_dbus_oom ();
+ var = g_variant_new ("(u)", 0);
}
-
- if (!dbus_message_iter_close_container (iter, &obj_struct_iter))
- _g_dbus_oom ();
+
+ return var;
}
void
@@ -135,42 +97,42 @@ _g_dbus_attribute_as_pointer (GFileAttributeType type,
}
}
-const char *
+static const char *
_g_dbus_type_from_file_attribute_type (GFileAttributeType type)
{
- char *dbus_type;
+ const char *dbus_type;
switch (type)
{
case G_FILE_ATTRIBUTE_TYPE_STRING:
- dbus_type = DBUS_TYPE_STRING_AS_STRING;
+ dbus_type = "s";
break;
case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
- dbus_type = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
+ dbus_type = "ay";
break;
case G_FILE_ATTRIBUTE_TYPE_STRINGV:
- dbus_type = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
+ dbus_type = "as";
break;
case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
- dbus_type = DBUS_TYPE_BOOLEAN_AS_STRING;
+ dbus_type = "b";
break;
case G_FILE_ATTRIBUTE_TYPE_UINT32:
- dbus_type = DBUS_TYPE_UINT32_AS_STRING;
+ dbus_type = "u";
break;
case G_FILE_ATTRIBUTE_TYPE_INT32:
- dbus_type = DBUS_TYPE_INT32_AS_STRING;
+ dbus_type = "i";
break;
case G_FILE_ATTRIBUTE_TYPE_UINT64:
- dbus_type = DBUS_TYPE_UINT64_AS_STRING;
+ dbus_type = "t";
break;
case G_FILE_ATTRIBUTE_TYPE_INT64:
- dbus_type = DBUS_TYPE_INT64_AS_STRING;
+ dbus_type = "x";
break;
case G_FILE_ATTRIBUTE_TYPE_OBJECT:
- dbus_type = DBUS_TYPE_STRUCT_AS_STRING;
+ dbus_type = "r";
break;
case G_FILE_ATTRIBUTE_TYPE_INVALID:
- dbus_type = DBUS_TYPE_BYTE_AS_STRING;
+ dbus_type = "ay";
break;
default:
dbus_type = NULL;
@@ -181,114 +143,65 @@ _g_dbus_type_from_file_attribute_type (GFileAttributeType type)
return dbus_type;
}
-void
-_g_dbus_append_file_attribute (DBusMessageIter *iter,
- const char *attribute,
+GVariant *
+_g_dbus_append_file_attribute (const char *attribute,
GFileAttributeStatus status,
GFileAttributeType type,
gpointer value_p)
{
- DBusMessageIter variant_iter, inner_struct_iter;
const char *dbus_type;
- guint32 dbus_status;
+ GVariant *v;
dbus_type = _g_dbus_type_from_file_attribute_type (type);
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &inner_struct_iter))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_append_basic (&inner_struct_iter,
- DBUS_TYPE_STRING,
- &attribute))
- _g_dbus_oom ();
-
- dbus_status = status;
- if (!dbus_message_iter_append_basic (&inner_struct_iter,
- DBUS_TYPE_UINT32,
- &dbus_status))
- _g_dbus_oom ();
-
- if (dbus_type[0] == DBUS_TYPE_STRUCT)
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_TUPLE))
dbus_type = get_object_signature ((GObject *)value_p);
-
- if (!dbus_message_iter_open_container (&inner_struct_iter,
- DBUS_TYPE_VARIANT,
- dbus_type,
- &variant_iter))
- _g_dbus_oom ();
- if (dbus_type[0] == DBUS_TYPE_STRING)
- {
- if (!dbus_message_iter_append_basic (&variant_iter,
- DBUS_TYPE_STRING, &value_p))
- _g_dbus_oom ();
- }
- else if (dbus_type[0] == DBUS_TYPE_ARRAY && dbus_type[1] == DBUS_TYPE_BYTE)
- _g_dbus_message_iter_append_cstring (&variant_iter, (char *)value_p);
- else if (dbus_type[0] == DBUS_TYPE_ARRAY && dbus_type[1] == DBUS_TYPE_STRING)
- append_strv (&variant_iter, (char **)value_p);
- else if (dbus_type[0] == DBUS_TYPE_BYTE)
- {
- char byte = 0;
- if (!dbus_message_iter_append_basic (&variant_iter,
- DBUS_TYPE_BYTE, &byte))
- _g_dbus_oom ();
- }
- else if (dbus_type[0] == DBUS_STRUCT_BEGIN_CHAR)
- append_object (&variant_iter, (GObject *)value_p);
- else if (dbus_type[0] == DBUS_TYPE_BOOLEAN)
- {
- /* dbus bool is uint32, gboolean is just "int", convert */
- dbus_bool_t bool = *(gboolean *)value_p;
- if (!dbus_message_iter_append_basic (&variant_iter,
- dbus_type[0], &bool))
- _g_dbus_oom ();
- }
+ if (g_variant_type_is_tuple (G_VARIANT_TYPE (dbus_type)))
+ v = append_object ((GObject *)value_p);
else
+ if (g_variant_type_is_array (G_VARIANT_TYPE (dbus_type)))
{
- /* All other types have the same size as dbus types */
- if (!dbus_message_iter_append_basic (&variant_iter,
- dbus_type[0], value_p))
- _g_dbus_oom ();
- }
-
- if (!dbus_message_iter_close_container (&inner_struct_iter, &variant_iter))
- _g_dbus_oom ();
+ char *s;
- if (!dbus_message_iter_close_container (iter, &inner_struct_iter))
- _g_dbus_oom ();
+ s = g_strdup_printf ("^%s", dbus_type);
+ v = g_variant_new (s, value_p);
+ g_free (s);
+ }
+ else
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_UINT32))
+ v = g_variant_new (dbus_type, *(guint32 *)value_p);
+ else
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_INT32))
+ v = g_variant_new (dbus_type, *(gint32 *)value_p);
+ else
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_UINT64))
+ v = g_variant_new (dbus_type, *(guint64 *)value_p);
+ else
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_INT64))
+ v = g_variant_new (dbus_type, *(gint64 *)value_p);
+ else
+ if (g_variant_type_equal (G_VARIANT_TYPE (dbus_type), G_VARIANT_TYPE_BOOLEAN))
+ v = g_variant_new (dbus_type, *(gboolean *)value_p);
+ else
+ v = g_variant_new (dbus_type, value_p);
+
+ return g_variant_new ("(suv)",
+ attribute,
+ status,
+ v);
}
-void
-_g_dbus_append_file_info (DBusMessageIter *iter,
- GFileInfo *info)
+GVariant *
+_g_dbus_append_file_info (GFileInfo *info)
{
- DBusMessageIter struct_iter, array_iter;
+ GVariantBuilder builder;
char **attributes;
int i;
- attributes = g_file_info_list_attributes (info, NULL);
-
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &struct_iter))
- _g_dbus_oom ();
-
-
- if (!dbus_message_iter_open_container (&struct_iter,
- DBUS_TYPE_ARRAY,
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_TYPE_VARIANT_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING,
- &array_iter))
- _g_dbus_oom ();
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(suv)"));
+ attributes = g_file_info_list_attributes (info, NULL);
for (i = 0; attributes[i] != NULL; i++)
{
GFileAttributeType type;
@@ -296,323 +209,194 @@ _g_dbus_append_file_info (DBusMessageIter *iter,
gpointer value_p;
if (g_file_info_get_attribute_data (info, attributes[i], &type, &value_p, &status))
- _g_dbus_append_file_attribute (&array_iter, attributes [i], status, type, value_p);
+ g_variant_builder_add_value (&builder,
+ _g_dbus_append_file_attribute (attributes[i], status, type, value_p));
}
-
g_strfreev (attributes);
- if (!dbus_message_iter_close_container (&struct_iter, &array_iter))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_close_container (iter, &struct_iter))
- _g_dbus_oom ();
+ return g_variant_builder_end (&builder);
}
gboolean
-_g_dbus_get_file_attribute (DBusMessageIter *iter,
+_g_dbus_get_file_attribute (GVariant *iter,
gchar **attribute,
GFileAttributeStatus *status,
GFileAttributeType *type,
GDbusAttributeValue *value)
{
+ gboolean res;
char *str;
- char **strs;
- int n_elements;
- DBusMessageIter inner_struct_iter, variant_iter, cstring_iter, obj_iter;
- const gchar *attribute_temp;
- int element_type;
- dbus_uint32_t obj_type, dbus_status;
- dbus_bool_t dbus_bool;
- guint8 byte;
+ guint32 obj_type;
GObject *obj;
+ GVariant *v;
- dbus_message_iter_recurse (iter, &inner_struct_iter);
-
- if (dbus_message_iter_get_arg_type (&inner_struct_iter) != DBUS_TYPE_STRING)
- goto error;
-
- dbus_message_iter_get_basic (&inner_struct_iter, &attribute_temp);
- *attribute = g_strdup (attribute_temp);
-
- dbus_message_iter_next (&inner_struct_iter);
-
- dbus_message_iter_get_basic (&inner_struct_iter, &dbus_status);
- if (status)
- *status = dbus_status;
-
- dbus_message_iter_next (&inner_struct_iter);
-
- if (dbus_message_iter_get_arg_type (&inner_struct_iter) != DBUS_TYPE_VARIANT)
- goto error;
-
- dbus_message_iter_recurse (&inner_struct_iter, &variant_iter);
+ g_variant_get (iter, "(suv)",
+ attribute,
+ status,
+ &v);
- switch (dbus_message_iter_get_arg_type (&variant_iter))
+ res = TRUE;
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
{
- case DBUS_TYPE_STRING:
*type = G_FILE_ATTRIBUTE_TYPE_STRING;
- dbus_message_iter_get_basic (&variant_iter, &str);
- value->ptr = g_strdup (str);
- break;
- case DBUS_TYPE_ARRAY:
- element_type = dbus_message_iter_get_element_type (&variant_iter);
- if (element_type == DBUS_TYPE_BYTE)
- {
- *type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING;
-
- dbus_message_iter_recurse (&variant_iter, &cstring_iter);
- dbus_message_iter_get_fixed_array (&cstring_iter,
- &str, &n_elements);
- value->ptr = g_strndup (str, n_elements);
- }
- else if (element_type == DBUS_TYPE_STRING)
- {
- char **strv;
- int n_elements;
- if (!_g_dbus_message_iter_get_args (&variant_iter, NULL,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &strv, &n_elements,
- 0))
- goto error;
- *type = G_FILE_ATTRIBUTE_TYPE_STRINGV;
- value->ptr = strv;
- }
- else
- goto error;
-
- break;
- case DBUS_TYPE_BYTE:
- dbus_message_iter_get_basic (&variant_iter, &byte);
+ g_variant_get (v, "s", &value->ptr);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTESTRING))
+ {
+ *type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING;
+ g_variant_get (v, "^ay", &value->ptr);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING_ARRAY))
+ {
+ *type = G_FILE_ATTRIBUTE_TYPE_STRINGV;
+ g_variant_get (v, "^as", &value->ptr);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_INVALID;
- break;
- case DBUS_TYPE_BOOLEAN:
- dbus_message_iter_get_basic (&variant_iter, &dbus_bool);
- value->boolean = dbus_bool;
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BOOLEAN))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_BOOLEAN;
- break;
- case DBUS_TYPE_UINT32:
- dbus_message_iter_get_basic (&variant_iter, value);
+ g_variant_get (v, "b", &value->boolean);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_UINT32;
- break;
- case DBUS_TYPE_INT32:
- dbus_message_iter_get_basic (&variant_iter, value);
+ g_variant_get (v, "u", &value->uint32);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_INT32;
- break;
- case DBUS_TYPE_UINT64:
- dbus_message_iter_get_basic (&variant_iter, value);
+ g_variant_get (v, "i", &value->ptr);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_UINT64;
- break;
- case DBUS_TYPE_INT64:
- dbus_message_iter_get_basic (&variant_iter, value);
+ g_variant_get (v, "t", &value->uint64);
+ }
+ else
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_INT64;
- break;
- case DBUS_TYPE_STRUCT:
- dbus_message_iter_recurse (&variant_iter, &obj_iter);
- if (dbus_message_iter_get_arg_type (&obj_iter) != DBUS_TYPE_UINT32)
- goto error;
-
+ g_variant_get (v, "x", &value->ptr);
+ }
+ else
+ if (g_variant_is_container (v))
+ {
*type = G_FILE_ATTRIBUTE_TYPE_OBJECT;
- dbus_message_iter_get_basic (&obj_iter, &obj_type);
- obj = NULL;
-
- dbus_message_iter_next (&obj_iter);
- /* 0 == NULL */
-
- if (obj_type == 1)
- {
- /* Old deprecated G_THEMED_ICON */
- if (_g_dbus_message_iter_get_args (&obj_iter,
- NULL,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
- &strs, &n_elements, 0))
- {
- obj = G_OBJECT (g_themed_icon_new_from_names (strs, n_elements));
- g_strfreev (strs);
- }
- }
- else if (obj_type == 2)
- {
- /* Old deprecated G_FILE_ICON, w/ local file */
- if (_g_dbus_message_iter_get_args (&obj_iter,
- NULL,
- G_DBUS_TYPE_CSTRING, &str,
- 0))
- {
- GFile *file = g_file_new_for_path (str);
- obj = G_OBJECT (g_file_icon_new (file));
- g_free (str);
- }
- }
- else if (obj_type == 3)
- {
- /* serialized G_ICON */
- if (_g_dbus_message_iter_get_args (&obj_iter,
- NULL,
- DBUS_TYPE_STRING, &str,
- 0))
- obj = (GObject *)g_icon_new_for_string (str, NULL);
- }
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE ("(u)")))
+ {
+ g_variant_get (v, "(u)", &obj_type);
+ }
else
- {
- /* NULL (or unsupported) */
- if (obj_type != 0)
- g_warning ("Unsupported object type in file attribute");
- }
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE ("(us)")))
+ {
+ g_variant_get (v, "(u&s)", &obj_type, &str);
+ }
- value->ptr = obj;
- break;
- default:
- goto error;
- }
+ obj = NULL;
- return TRUE;
+ /* obj_type 1 and 2 are deprecated and treated as errors */
+ if (obj_type == 3)
+ {
+ /* serialized G_ICON */
+ obj = (GObject *)g_icon_new_for_string (str, NULL);
+ }
+ else
+ {
+ /* NULL (or unsupported) */
+ if (obj_type != 0)
+ g_warning ("Unsupported object type in file attribute");
+ }
+ value->ptr = obj;
+ }
+ else
+ res = FALSE;
- error:
- return FALSE;
+ g_variant_unref (v);
+
+ return res;
}
GFileInfo *
-_g_dbus_get_file_info (DBusMessageIter *iter,
+_g_dbus_get_file_info (GVariant *iter,
GError **error)
{
GFileInfo *info;
- DBusMessageIter struct_iter, array_iter;
gchar *attribute;
GFileAttributeType type;
GFileAttributeStatus status;
GDbusAttributeValue value;
+ GVariantIter i;
+ GVariant *child;
info = g_file_info_new ();
- if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_STRUCT)
- goto error;
-
- dbus_message_iter_recurse (iter, &struct_iter);
-
- if (dbus_message_iter_get_arg_type (&struct_iter) != DBUS_TYPE_ARRAY)
- goto error;
-
- dbus_message_iter_recurse (&struct_iter, &array_iter);
-
- while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRUCT)
+ g_variant_iter_init (&i, iter);
+ while ((child = g_variant_iter_next_value (&i)))
{
- if (!_g_dbus_get_file_attribute (&array_iter, &attribute, &status, &type, &value))
+ if (!_g_dbus_get_file_attribute (child, &attribute, &status, &type, &value))
goto error;
g_file_info_set_attribute (info, attribute, type, _g_dbus_attribute_as_pointer (type, &value));
if (status)
- g_file_info_set_attribute_status (info, attribute, status);
+ g_file_info_set_attribute_status (info, attribute, status);
g_free (attribute);
_g_dbus_attribute_value_destroy (type, &value);
- dbus_message_iter_next (&array_iter);
+ g_variant_unref (child);
}
- dbus_message_iter_next (iter);
return info;
error:
g_object_unref (info);
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Invalid file info format"));
- dbus_message_iter_next (iter);
return NULL;
}
GFileAttributeInfoList *
-_g_dbus_get_attribute_info_list (DBusMessageIter *iter,
+_g_dbus_get_attribute_info_list (GVariant *iter,
GError **error)
{
GFileAttributeInfoList *list;
- DBusMessageIter array_iter, struct_iter;
+ GVariantIter i;
const char *name;
- dbus_uint32_t type, flags;
+ guint32 type, flags;
- if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_ARRAY ||
- dbus_message_iter_get_element_type (iter) != DBUS_TYPE_STRUCT)
- {
- g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Invalid attribute info list content"));
- return NULL;
- }
-
list = g_file_attribute_info_list_new ();
- dbus_message_iter_recurse (iter, &array_iter);
- while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRUCT)
- {
- dbus_message_iter_recurse (&array_iter, &struct_iter);
-
- if (dbus_message_iter_get_arg_type (&struct_iter) == DBUS_TYPE_STRING)
- {
- dbus_message_iter_get_basic (&struct_iter, &name);
- dbus_message_iter_next (&struct_iter);
-
- if (dbus_message_iter_get_arg_type (&struct_iter) == DBUS_TYPE_UINT32)
- {
- dbus_message_iter_get_basic (&struct_iter, &type);
- dbus_message_iter_next (&struct_iter);
-
- if (dbus_message_iter_get_arg_type (&struct_iter) == DBUS_TYPE_UINT32)
- {
- dbus_message_iter_get_basic (&struct_iter, &flags);
-
- g_file_attribute_info_list_add (list, name, type, flags);
- }
- }
- }
+ g_variant_iter_init (&i, iter);
+ while (g_variant_iter_next (&i, "(&suu)", &name, &type, &flags))
+ g_file_attribute_info_list_add (list, name, type, flags);
- dbus_message_iter_next (&array_iter);
- }
-
return list;
}
-void
-_g_dbus_append_attribute_info_list (DBusMessageIter *iter,
- GFileAttributeInfoList *list)
+GVariant *
+_g_dbus_append_attribute_info_list (GFileAttributeInfoList *list)
{
- DBusMessageIter array_iter, struct_iter;
+ GVariantBuilder builder;
int i;
- dbus_uint32_t dbus_type, dbus_flags;
-
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_ARRAY,
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING,
- &array_iter))
- _g_dbus_oom ();
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(suu)"));
for (i = 0; i < list->n_infos; i++)
- {
- if (!dbus_message_iter_open_container (&array_iter,
- DBUS_TYPE_STRUCT,
- NULL,
- &struct_iter))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_append_basic (&struct_iter,
- DBUS_TYPE_STRING, &list->infos[i].name))
- _g_dbus_oom ();
-
- dbus_type = list->infos[i].type;
- if (!dbus_message_iter_append_basic (&struct_iter,
- DBUS_TYPE_UINT32, &dbus_type))
- _g_dbus_oom ();
-
- dbus_flags = list->infos[i].flags;
- if (!dbus_message_iter_append_basic (&struct_iter,
- DBUS_TYPE_UINT32, &dbus_flags))
- _g_dbus_oom ();
-
- if (!dbus_message_iter_close_container (&array_iter, &struct_iter))
- _g_dbus_oom ();
- }
+ g_variant_builder_add (&builder, "(suu)",
+ list->infos[i].name,
+ list->infos[i].type,
+ list->infos[i].flags);
- if (!dbus_message_iter_close_container (iter, &array_iter))
- _g_dbus_oom ();
+ return g_variant_builder_end (&builder);
}
diff --git a/common/gvfsdaemonprotocol.h b/common/gvfsdaemonprotocol.h
index bc754866..6325e2db 100644
--- a/common/gvfsdaemonprotocol.h
+++ b/common/gvfsdaemonprotocol.h
@@ -186,26 +186,22 @@ void _g_dbus_attribute_value_destroy (GFileAttributeType ty
GDbusAttributeValue *value);
gpointer _g_dbus_attribute_as_pointer (GFileAttributeType type,
GDbusAttributeValue *value);
-const char*_g_dbus_type_from_file_attribute_type (GFileAttributeType type);
-void _g_dbus_append_file_attribute (DBusMessageIter *iter,
- const char *attribute,
+GVariant * _g_dbus_append_file_attribute (const char *attribute,
GFileAttributeStatus status,
GFileAttributeType type,
gpointer value_p);
-void _g_dbus_append_file_info (DBusMessageIter *iter,
- GFileInfo *file_info);
-gboolean _g_dbus_get_file_attribute (DBusMessageIter *iter,
+GVariant * _g_dbus_append_file_info (GFileInfo *file_info);
+gboolean _g_dbus_get_file_attribute (GVariant *iter,
gchar **attribute,
GFileAttributeStatus *status,
GFileAttributeType *type,
GDbusAttributeValue *value);
-GFileInfo *_g_dbus_get_file_info (DBusMessageIter *iter,
+GFileInfo *_g_dbus_get_file_info (GVariant *iter,
GError **error);
-GFileAttributeInfoList *_g_dbus_get_attribute_info_list (DBusMessageIter *iter,
+GFileAttributeInfoList *_g_dbus_get_attribute_info_list (GVariant *iter,
GError **error);
-void _g_dbus_append_attribute_info_list (DBusMessageIter *iter,
- GFileAttributeInfoList *list);
+GVariant * _g_dbus_append_attribute_info_list (GFileAttributeInfoList *list);
G_END_DECLS