summaryrefslogtreecommitdiff
path: root/daemon/gvfsjobmove.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2012-06-29 16:26:13 +0200
committerTomas Bzatek <tbzatek@redhat.com>2012-07-31 11:59:37 +0200
commit918cebfd9b96b22179b4685d94e72b6c97090eb3 (patch)
treeeb9e5b61359da95110cc68626b3504d82b22b079 /daemon/gvfsjobmove.c
parent17a008f395c438c0dad394523cc3d62261ceca4a (diff)
downloadgvfs-918cebfd9b96b22179b4685d94e72b6c97090eb3.tar.gz
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/gvfsjobmove.c')
-rw-r--r--daemon/gvfsjobmove.c122
1 files changed, 30 insertions, 92 deletions
diff --git a/daemon/gvfsjobmove.c b/daemon/gvfsjobmove.c
index bac56188..c74f074f 100644
--- a/daemon/gvfsjobmove.c
+++ b/daemon/gvfsjobmove.c
@@ -33,7 +33,7 @@
#include "gvfsjobmove.h"
#include "gvfsdbus.h"
-G_DEFINE_TYPE (GVfsJobMove, g_vfs_job_move, G_VFS_TYPE_JOB_DBUS)
+G_DEFINE_TYPE (GVfsJobMove, g_vfs_job_move, G_VFS_TYPE_JOB_PROGRESS)
static void run (GVfsJob *job);
static gboolean try (GVfsJob *job);
@@ -50,7 +50,6 @@ g_vfs_job_move_finalize (GObject *object)
g_free (job->source);
g_free (job->destination);
- g_free (job->callback_obj_path);
if (G_OBJECT_CLASS (g_vfs_job_move_parent_class)->finalize)
(*G_OBJECT_CLASS (g_vfs_job_move_parent_class)->finalize) (object);
@@ -84,7 +83,8 @@ g_vfs_job_move_new_handle (GVfsDBusMount *object,
GVfsBackend *backend)
{
GVfsJobMove *job;
-
+ GVfsJobProgress *progress_job;
+
g_print ("called Move()\n");
if (g_vfs_backend_invocation_first_handler (object, invocation, backend))
@@ -94,13 +94,15 @@ g_vfs_job_move_new_handle (GVfsDBusMount *object,
"object", object,
"invocation", invocation,
NULL);
+ progress_job = G_VFS_JOB_PROGRESS (job);
job->source = g_strdup (arg_path1_data);
job->destination = g_strdup (arg_path2_data);
job->backend = backend;
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);
+ progress_job->callback_obj_path = g_strdup (arg_progress_obj_path);
+ progress_job->send_progress = progress_job->callback_obj_path != NULL;
g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), G_VFS_JOB (job));
g_object_unref (job);
@@ -108,89 +110,11 @@ g_vfs_job_move_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);
-}
-
-void
-g_vfs_job_move_progress_callback (goffset current_num_bytes,
- goffset total_num_bytes,
- GVfsJob *job)
-{
- GVfsJobDBus *dbus_job = G_VFS_JOB_DBUS (job);
- GVfsJobMove *op_job = G_VFS_JOB_MOVE (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)
{
GVfsJobMove *op_job = G_VFS_JOB_MOVE (job);
+ GVfsJobProgress *progress_job = G_VFS_JOB_PROGRESS (job);
GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
if (class->move == NULL)
@@ -200,31 +124,45 @@ run (GVfsJob *job)
return;
}
+ g_vfs_job_progress_construct_proxy (job);
+
class->move (op_job->backend,
op_job,
op_job->source,
op_job->destination,
op_job->flags,
- (GFileProgressCallback)g_vfs_job_move_progress_callback,
- job);
+ 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)
{
GVfsJobMove *op_job = G_VFS_JOB_MOVE (job);
+ GVfsJobProgress *progress_job = G_VFS_JOB_PROGRESS (job);
GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);
+ gboolean res;
if (class->try_move == NULL)
return FALSE;
- return class->try_move (op_job->backend,
- op_job,
- op_job->source,
- op_job->destination,
- op_job->flags,
- (GFileProgressCallback)g_vfs_job_move_progress_callback,
- job);
+ g_vfs_job_progress_construct_proxy (job);
+
+ res = class->try_move (op_job->backend,
+ op_job,
+ op_job->source,
+ op_job->destination,
+ op_job->flags,
+ 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 */