diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2012-07-31 11:58:09 +0200 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2012-07-31 11:58:09 +0200 |
commit | 622a5c0d167556188c38fcde40a42a0dfad9c625 (patch) | |
tree | 04f27be7f2a54779e17029ede2554e39c3464aa0 /daemon/gvfsjobmove.c | |
parent | a494b809eaf82994108bfbbe5d950fed1a0a8c7c (diff) | |
download | gvfs-622a5c0d167556188c38fcde40a42a0dfad9c625.tar.gz |
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 'daemon/gvfsjobmove.c')
-rw-r--r-- | daemon/gvfsjobmove.c | 172 |
1 files changed, 99 insertions, 73 deletions
diff --git a/daemon/gvfsjobmove.c b/daemon/gvfsjobmove.c index da940123..bac56188 100644 --- a/daemon/gvfsjobmove.c +++ b/daemon/gvfsjobmove.c @@ -29,19 +29,17 @@ #include <sys/un.h> #include <glib.h> -#include <dbus/dbus.h> #include <glib/gi18n.h> #include "gvfsjobmove.h" -#include "gvfsdbusutils.h" -#include "gvfsdaemonprotocol.h" +#include "gvfsdbus.h" G_DEFINE_TYPE (GVfsJobMove, g_vfs_job_move, G_VFS_TYPE_JOB_DBUS) static void run (GVfsJob *job); static gboolean try (GVfsJob *job); -static DBusMessage *create_reply (GVfsJob *job, - DBusConnection *connection, - DBusMessage *message); +static void create_reply (GVfsJob *job, + GVfsDBusMount *object, + GDBusMethodInvocation *invocation); static void g_vfs_job_move_finalize (GObject *object) @@ -76,85 +74,117 @@ g_vfs_job_move_init (GVfsJobMove *job) { } -GVfsJob * -g_vfs_job_move_new (DBusConnection *connection, - DBusMessage *message, - GVfsBackend *backend) +gboolean +g_vfs_job_move_new_handle (GVfsDBusMount *object, + GDBusMethodInvocation *invocation, + const gchar *arg_path1_data, + const gchar *arg_path2_data, + guint arg_flags, + const gchar *arg_progress_obj_path, + GVfsBackend *backend) { GVfsJobMove *job; - DBusMessage *reply; - DBusError derror; - int path1_len, path2_len; - const char *path1_data, *path2_data, *callback_obj_path; - dbus_uint32_t flags; - dbus_error_init (&derror); - if (!dbus_message_get_args (message, &derror, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &path1_data, &path1_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &path2_data, &path2_len, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_OBJECT_PATH, &callback_obj_path, - 0)) - { - reply = dbus_message_new_error (message, - derror.name, - derror.message); - dbus_error_free (&derror); - - dbus_connection_send (connection, reply, NULL); - dbus_message_unref (reply); - return NULL; - } + g_print ("called Move()\n"); + if (g_vfs_backend_invocation_first_handler (object, invocation, backend)) + return TRUE; + job = g_object_new (G_VFS_TYPE_JOB_MOVE, - "message", message, - "connection", connection, - NULL); + "object", object, + "invocation", invocation, + NULL); - job->source = g_strndup (path1_data, path1_len); - job->destination = g_strndup (path2_data, path2_len); + job->source = g_strdup (arg_path1_data); + job->destination = g_strdup (arg_path2_data); job->backend = backend; - job->flags = flags; - if (strcmp (callback_obj_path, "/org/gtk/vfs/void") != 0) - job->callback_obj_path = g_strdup (callback_obj_path); + job->flags = arg_flags; + if (strcmp (arg_progress_obj_path, "/org/gtk/vfs/void") != 0) + job->callback_obj_path = g_strdup (arg_progress_obj_path); + + g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), G_VFS_JOB (job)); + g_object_unref (job); + + return TRUE; +} + +typedef struct { + goffset current_num_bytes; + goffset total_num_bytes; +} ProgressCallbackData; + +static void +progress_cb (GVfsDBusProgress *proxy, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + + g_print ("progress_cb\n"); - return G_VFS_JOB (job); + if (! gvfs_dbus_progress_call_progress_finish (proxy, res, &error)) + { + g_warning ("progress_cb: %s (%s, %d)\n", error->message, g_quark_to_string (error->domain), error->code); + g_error_free (error); + } } -void +static void +progress_proxy_new_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + ProgressCallbackData *data = user_data; + GVfsDBusProgress *proxy; + GError *error = NULL; + + g_print ("progress_proxy_new_cb\n"); + + proxy = gvfs_dbus_progress_proxy_new_finish (res, &error); + if (proxy == NULL) + { + g_warning ("progress_proxy_new_cb: %s (%s, %d)\n", error->message, g_quark_to_string (error->domain), error->code); + g_error_free (error); + goto out; + } + + gvfs_dbus_progress_call_progress (proxy, + data->current_num_bytes, + data->total_num_bytes, + NULL, + (GAsyncReadyCallback) progress_cb, + NULL); + g_object_unref (proxy); + + out: + g_free (data); +} + +void g_vfs_job_move_progress_callback (goffset current_num_bytes, - goffset total_num_bytes, - GVfsJob *job) + goffset total_num_bytes, + GVfsJob *job) { GVfsJobDBus *dbus_job = G_VFS_JOB_DBUS (job); GVfsJobMove *op_job = G_VFS_JOB_MOVE (job); - dbus_uint64_t current_dbus, total_dbus; - DBusMessage *message; + ProgressCallbackData *data; g_debug ("progress_callback %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT "\n", current_num_bytes, total_num_bytes); if (op_job->callback_obj_path == NULL) return; - message = - dbus_message_new_method_call (dbus_message_get_sender (dbus_job->message), - op_job->callback_obj_path, - G_VFS_DBUS_PROGRESS_INTERFACE, - G_VFS_DBUS_PROGRESS_OP_PROGRESS); - dbus_message_set_no_reply (message, TRUE); - - current_dbus = current_num_bytes; - total_dbus = total_num_bytes; - dbus_message_append_args (message, - DBUS_TYPE_UINT64, ¤t_dbus, - DBUS_TYPE_UINT64, &total_dbus, - 0); - - /* Queues reply (threadsafely), actually sends it in mainloop */ - dbus_connection_send (dbus_job->connection, message, NULL); - dbus_message_unref (message); + data = g_new0 (ProgressCallbackData, 1); + data->current_num_bytes = current_num_bytes; + data->total_num_bytes = total_num_bytes; + + gvfs_dbus_progress_proxy_new (g_dbus_method_invocation_get_connection (dbus_job->invocation), + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + g_dbus_method_invocation_get_sender (dbus_job->invocation), + op_job->callback_obj_path, + NULL, + progress_proxy_new_cb, + data); } static void @@ -198,14 +228,10 @@ try (GVfsJob *job) } /* Might be called on an i/o thread */ -static DBusMessage * +static void create_reply (GVfsJob *job, - DBusConnection *connection, - DBusMessage *message) + GVfsDBusMount *object, + GDBusMethodInvocation *invocation) { - DBusMessage *reply; - - reply = dbus_message_new_method_return (message); - - return reply; + gvfs_dbus_mount_complete_move (object, invocation); } |