summaryrefslogtreecommitdiff
path: root/daemon/gvfsjobpull.c
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 /daemon/gvfsjobpull.c
parenta494b809eaf82994108bfbbe5d950fed1a0a8c7c (diff)
downloadgvfs-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/gvfsjobpull.c')
-rw-r--r--daemon/gvfsjobpull.c185
1 files changed, 105 insertions, 80 deletions
diff --git a/daemon/gvfsjobpull.c b/daemon/gvfsjobpull.c
index 0a3347ae..3dda992c 100644
--- a/daemon/gvfsjobpull.c
+++ b/daemon/gvfsjobpull.c
@@ -29,19 +29,17 @@
#include <sys/un.h>
#include <glib.h>
-#include <dbus/dbus.h>
#include <glib/gi18n.h>
#include "gvfsjobpull.h"
-#include "gvfsdbusutils.h"
-#include "gvfsdaemonprotocol.h"
+#include "gvfsdbus.h"
G_DEFINE_TYPE (GVfsJobPull, g_vfs_job_pull, 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_pull_finalize (GObject *object)
@@ -76,92 +74,123 @@ g_vfs_job_pull_init (GVfsJobPull *job)
{
}
-GVfsJob *
-g_vfs_job_pull_new (DBusConnection *connection,
- DBusMessage *message,
- GVfsBackend *backend)
+gboolean
+g_vfs_job_pull_new_handle (GVfsDBusMount *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_path_data,
+ const gchar *arg_local_path,
+ gboolean arg_send_progress,
+ guint arg_flags,
+ const gchar *arg_progress_obj_path,
+ gboolean arg_remove_source,
+ GVfsBackend *backend)
{
GVfsJobPull *job;
- DBusMessage *reply;
- DBusError derror;
- int path1_len, path2_len;
- const char *path1_data, *path2_data, *callback_obj_path;
- dbus_uint32_t flags;
- dbus_bool_t remove_source, send_progress;
-
- 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_BOOLEAN, &send_progress,
- DBUS_TYPE_UINT32, &flags,
- DBUS_TYPE_OBJECT_PATH, &callback_obj_path,
- DBUS_TYPE_BOOLEAN, &remove_source,
- 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 Pull()\n");
+ if (g_vfs_backend_invocation_first_handler (object, invocation, backend))
+ return TRUE;
+
job = g_object_new (G_VFS_TYPE_JOB_PULL,
- "message", message,
- "connection", connection,
- NULL);
+ "object", object,
+ "invocation", invocation,
+ NULL);
- job->source = g_strndup (path1_data, path1_len);
- job->local_path = g_strndup (path2_data, path2_len);
+ job->source = g_strdup (arg_path_data);
+ job->local_path = g_strdup (arg_local_path);
job->backend = backend;
- job->flags = flags;
- job->send_progress = send_progress;
- job->remove_source = remove_source;
- g_debug ("Remove Source: %s\n", remove_source ? "true" : "false");
- if (strcmp (callback_obj_path, "/org/gtk/vfs/void") != 0)
- job->callback_obj_path = g_strdup (callback_obj_path);
-
- return G_VFS_JOB (job);
+ job->flags = arg_flags;
+ 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);
+
+ 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");
+
+ 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)
+ 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);
- 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, &current_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
@@ -207,14 +236,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_pull (object, invocation);
}