diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2012-06-29 16:26:13 +0200 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2012-07-31 11:59:37 +0200 |
commit | 918cebfd9b96b22179b4685d94e72b6c97090eb3 (patch) | |
tree | eb9e5b61359da95110cc68626b3504d82b22b079 /daemon/gvfsjobpull.c | |
parent | 17a008f395c438c0dad394523cc3d62261ceca4a (diff) |
gdbus: Make copy progress work
...by turning sync copy calls async and running mainloop for progress
interface skeleton be able to process incoming calls.
Also, new class GVfsJobProgress has been introduced mostly for code sharing.
Diffstat (limited to 'daemon/gvfsjobpull.c')
-rw-r--r-- | daemon/gvfsjobpull.c | 126 |
1 files changed, 31 insertions, 95 deletions
diff --git a/daemon/gvfsjobpull.c b/daemon/gvfsjobpull.c index 3dda992c..843d6f65 100644 --- a/daemon/gvfsjobpull.c +++ b/daemon/gvfsjobpull.c @@ -33,7 +33,7 @@ #include "gvfsjobpull.h" #include "gvfsdbus.h" -G_DEFINE_TYPE (GVfsJobPull, g_vfs_job_pull, G_VFS_TYPE_JOB_DBUS) +G_DEFINE_TYPE (GVfsJobPull, g_vfs_job_pull, G_VFS_TYPE_JOB_PROGRESS) static void run (GVfsJob *job); static gboolean try (GVfsJob *job); @@ -50,7 +50,6 @@ g_vfs_job_pull_finalize (GObject *object) g_free (job->local_path); g_free (job->source); - g_free (job->callback_obj_path); if (G_OBJECT_CLASS (g_vfs_job_pull_parent_class)->finalize) (*G_OBJECT_CLASS (g_vfs_job_pull_parent_class)->finalize) (object); @@ -86,7 +85,8 @@ g_vfs_job_pull_new_handle (GVfsDBusMount *object, GVfsBackend *backend) { GVfsJobPull *job; - + GVfsJobProgress *progress_job; + g_print ("called Pull()\n"); if (g_vfs_backend_invocation_first_handler (object, invocation, backend)) @@ -96,16 +96,17 @@ g_vfs_job_pull_new_handle (GVfsDBusMount *object, "object", object, "invocation", invocation, NULL); + progress_job = G_VFS_JOB_PROGRESS (job); job->source = g_strdup (arg_path_data); job->local_path = g_strdup (arg_local_path); job->backend = backend; job->flags = arg_flags; - job->send_progress = arg_send_progress; + progress_job->send_progress = arg_send_progress; job->remove_source = arg_remove_source; g_debug ("Remove Source: %s\n", arg_remove_source ? "true" : "false"); if (strcmp (arg_progress_obj_path, "/org/gtk/vfs/void") != 0) - job->callback_obj_path = g_strdup (arg_progress_obj_path); + progress_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); @@ -113,90 +114,11 @@ g_vfs_job_pull_new_handle (GVfsDBusMount *object, 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"); - - 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); - } -} - -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); -} - -static void -progress_callback (goffset current_num_bytes, - goffset total_num_bytes, - gpointer user_data) -{ - GVfsJob *job = G_VFS_JOB (user_data); - GVfsJobDBus *dbus_job = G_VFS_JOB_DBUS (job); - GVfsJobPull *op_job = G_VFS_JOB_PULL (job); - 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; - - 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 run (GVfsJob *job) { GVfsJobPull *op_job = G_VFS_JOB_PULL (job); + GVfsJobProgress *progress_job = G_VFS_JOB_PROGRESS (job); GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend); if (class->pull == NULL) @@ -206,33 +128,47 @@ run (GVfsJob *job) return; } + g_vfs_job_progress_construct_proxy (job); + class->pull (op_job->backend, op_job, op_job->source, op_job->local_path, op_job->flags, op_job->remove_source, - op_job->send_progress ? progress_callback : NULL, - op_job->send_progress ? job : NULL); + progress_job->send_progress ? g_vfs_job_progress_callback : NULL, + progress_job->send_progress ? job : NULL); + + if (progress_job->progress_proxy) + g_clear_object (&progress_job->progress_proxy); } static gboolean try (GVfsJob *job) { GVfsJobPull *op_job = G_VFS_JOB_PULL (job); + GVfsJobProgress *progress_job = G_VFS_JOB_PROGRESS (job); GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend); + gboolean res; if (class->try_pull == NULL) return FALSE; - return class->try_pull (op_job->backend, - op_job, - op_job->source, - op_job->local_path, - op_job->flags, - op_job->remove_source, - op_job->send_progress ? progress_callback : NULL, - op_job->send_progress ? job : NULL); + g_vfs_job_progress_construct_proxy (job); + + res = class->try_pull (op_job->backend, + op_job, + op_job->source, + op_job->local_path, + op_job->flags, + op_job->remove_source, + progress_job->send_progress ? g_vfs_job_progress_callback : NULL, + progress_job->send_progress ? job : NULL); + + if (progress_job->progress_proxy) + g_clear_object (&progress_job->progress_proxy); + + return res; } /* Might be called on an i/o thread */ |