[gvfs/wip/oholy/gtask: 24/30] proxy: Port GProxyVolume to GTask
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/oholy/gtask: 24/30] proxy: Port GProxyVolume to GTask
- Date: Fri, 18 Nov 2016 08:38:36 +0000 (UTC)
commit 3f2fa6e4479221e98056460bd4cf58fc5cdfe611
Author: Ondrej Holy <oholy redhat com>
Date: Mon Jul 25 16:09:06 2016 +0200
proxy: Port GProxyVolume to GTask
GSimpleAsyncResult is deprecated in favour of GTask and should be replaced.
https://bugzilla.gnome.org/show_bug.cgi?id=747412
monitor/proxy/gproxyvolume.c | 129 +++++++++++++++--------------------------
1 files changed, 47 insertions(+), 82 deletions(-)
---
diff --git a/monitor/proxy/gproxyvolume.c b/monitor/proxy/gproxyvolume.c
index fc24f15..3180528 100644
--- a/monitor/proxy/gproxyvolume.c
+++ b/monitor/proxy/gproxyvolume.c
@@ -746,23 +746,30 @@ g_proxy_volume_enumerate_identifiers (GVolume *volume)
}
typedef struct {
- GProxyVolume *volume;
- GAsyncReadyCallback callback;
- gpointer user_data;
-
gchar *cancellation_id;
- GCancellable *cancellable;
gulong cancelled_handler_id;
const gchar *mount_op_id;
} DBusOp;
static void
+dbus_op_free (DBusOp *data)
+{
+ g_free (data->cancellation_id);
+
+ if (data->mount_op_id)
+ g_proxy_mount_operation_destroy (data->mount_op_id);
+
+ g_free (data);
+}
+
+static void
mount_cb (GVfsRemoteVolumeMonitor *proxy,
GAsyncResult *res,
gpointer user_data)
{
- DBusOp *data = user_data;
+ GTask *task = G_TASK (user_data);
+ DBusOp *data = g_task_get_task_data (task);
GError *error = NULL;
gvfs_remote_volume_monitor_call_volume_mount_finish (proxy,
@@ -770,60 +777,39 @@ mount_cb (GVfsRemoteVolumeMonitor *proxy,
&error);
if (data->cancelled_handler_id > 0)
- g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
+ g_signal_handler_disconnect (g_task_get_cancellable (task), data->cancelled_handler_id);
- if (!g_cancellable_is_cancelled (data->cancellable))
+ if (!g_cancellable_is_cancelled (g_task_get_cancellable (task)))
{
- GSimpleAsyncResult *simple;
-
if (error != NULL)
{
g_dbus_error_strip_remote_error (error);
- simple = g_simple_async_result_new_from_error (G_OBJECT (data->volume),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
+ error = NULL;
}
else
{
- simple = g_simple_async_result_new (G_OBJECT (data->volume),
- data->callback,
- data->user_data,
- NULL);
+ g_task_return_boolean (task, TRUE);
}
- g_simple_async_result_complete_in_idle (simple);
- g_object_unref (simple);
}
- /* free DBusOp */
- g_proxy_mount_operation_destroy (data->mount_op_id);
- g_object_unref (data->volume);
-
- g_free (data->cancellation_id);
- if (data->cancellable != NULL)
- g_object_unref (data->cancellable);
-
- g_free (data);
+ g_object_unref (task);
if (error != NULL)
g_error_free (error);
}
-typedef struct
-{
- GProxyVolume *enclosing_volume;
- GAsyncReadyCallback callback;
- gpointer user_data;
-} ForeignMountOp;
-
static void
mount_foreign_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- ForeignMountOp *data = user_data;
- data->callback (G_OBJECT (data->enclosing_volume), res, data->user_data);
- g_object_unref (data->enclosing_volume);
- g_free (data);
+ GTask *task = G_TASK (user_data);
+ GError *error = NULL;
+
+ if (g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error))
+ g_task_return_boolean (task, TRUE);
+ else
+ g_task_return_error (task, error);
}
static void
@@ -848,23 +834,15 @@ static void
mount_cancelled (GCancellable *cancellable,
gpointer user_data)
{
- DBusOp *data = user_data;
- GSimpleAsyncResult *simple;
+ GTask *task = G_TASK (user_data);
+ DBusOp *data = g_task_get_task_data (task);
+ GProxyVolume *volume = G_PROXY_VOLUME (g_task_get_source_object (task));
GVfsRemoteVolumeMonitor *proxy;
G_LOCK (proxy_volume);
- simple = g_simple_async_result_new_error (G_OBJECT (data->volume),
- data->callback,
- data->user_data,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Operation was cancelled"));
- g_simple_async_result_complete_in_idle (simple);
- g_object_unref (simple);
-
/* Now tell the remote volume monitor that the op has been cancelled */
- proxy = g_proxy_volume_monitor_get_dbus_proxy (data->volume->volume_monitor);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (volume->volume_monitor);
gvfs_remote_volume_monitor_call_cancel_operation (proxy,
data->cancellation_id,
NULL,
@@ -873,6 +851,8 @@ mount_cancelled (GCancellable *cancellable,
g_object_unref (proxy);
G_UNLOCK (proxy_volume);
+
+ g_task_return_error_if_cancelled (task);
}
static void
@@ -884,19 +864,16 @@ g_proxy_volume_mount (GVolume *volume,
gpointer user_data)
{
GProxyVolume *proxy_volume = G_PROXY_VOLUME (volume);
+ GTask *task;
+
+ task = g_task_new (volume, cancellable, callback, user_data);
G_LOCK (proxy_volume);
if (proxy_volume->activation_uri != NULL &&
!proxy_volume->always_call_mount)
{
- ForeignMountOp *data;
GFile *root;
- data = g_new0 (ForeignMountOp, 1);
- data->enclosing_volume = g_object_ref (volume);
- data->callback = callback;
- data->user_data = user_data;
-
root = g_file_new_for_uri (proxy_volume->activation_uri);
G_UNLOCK (proxy_volume);
@@ -906,7 +883,7 @@ g_proxy_volume_mount (GVolume *volume,
mount_operation,
cancellable,
mount_foreign_callback,
- data);
+ task);
g_object_unref (root);
}
@@ -917,31 +894,20 @@ g_proxy_volume_mount (GVolume *volume,
if (g_cancellable_is_cancelled (cancellable))
{
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_error (G_OBJECT (volume),
- callback,
- user_data,
- G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("Operation was cancelled"));
- g_simple_async_result_complete_in_idle (simple);
- g_object_unref (simple);
G_UNLOCK (proxy_volume);
- goto out;
+ g_task_return_error_if_cancelled (task);
+ g_object_unref (task);
+ return;
}
data = g_new0 (DBusOp, 1);
- data->volume = g_object_ref (volume);
- data->callback = callback;
- data->user_data = user_data;
if (cancellable != NULL)
{
data->cancellation_id = g_strdup_printf ("%p", cancellable);
- data->cancellable = g_object_ref (cancellable);
- data->cancelled_handler_id = g_signal_connect (data->cancellable,
+ data->cancelled_handler_id = g_signal_connect (cancellable,
"cancelled",
G_CALLBACK (mount_cancelled),
- data);
+ task);
}
else
{
@@ -950,6 +916,8 @@ g_proxy_volume_mount (GVolume *volume,
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_volume->volume_monitor);
+ g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_volume->volume_monitor);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT); /* 30
minute timeout */
@@ -960,16 +928,13 @@ g_proxy_volume_mount (GVolume *volume,
data->mount_op_id,
NULL,
(GAsyncReadyCallback) mount_cb,
- data);
+ task);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), -1);
g_object_unref (proxy);
G_UNLOCK (proxy_volume);
}
-
- out:
- ;
}
static gboolean
@@ -977,9 +942,9 @@ g_proxy_volume_mount_finish (GVolume *volume,
GAsyncResult *result,
GError **error)
{
- if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
- return FALSE;
- return TRUE;
+ g_return_val_if_fail (g_task_is_valid (result, volume), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
}
static GFile *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]