[gvfs/wip/oholy/gtask: 55/59] proxy: Port GProxyDrive to GTask
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/oholy/gtask: 55/59] proxy: Port GProxyDrive to GTask
- Date: Tue, 28 Mar 2017 10:33:32 +0000 (UTC)
commit 6e65eb7f7c499b831c166d9b952c2f9eb86bbc9a
Author: Ondrej Holy <oholy redhat com>
Date: Tue Jul 26 11:40:56 2016 +0200
proxy: Port GProxyDrive to GTask
GSimpleAsyncResult is deprecated in favour of GTask and should be replaced.
https://bugzilla.gnome.org/show_bug.cgi?id=747412
monitor/proxy/gproxydrive.c | 348 +++++++++++++++----------------------------
1 files changed, 123 insertions(+), 225 deletions(-)
---
diff --git a/monitor/proxy/gproxydrive.c b/monitor/proxy/gproxydrive.c
index 8cb5e6a..62a16b1 100644
--- a/monitor/proxy/gproxydrive.c
+++ b/monitor/proxy/gproxydrive.c
@@ -522,18 +522,24 @@ g_proxy_drive_get_id (GProxyDrive *drive)
}
typedef struct {
- GProxyDrive *drive;
- 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
cancel_operation_reply_cb (GVfsRemoteVolumeMonitor *proxy,
GAsyncResult *res,
gpointer user_data)
@@ -555,23 +561,15 @@ static void
operation_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);
GVfsRemoteVolumeMonitor *proxy;
+ GProxyDrive *drive = G_PROXY_DRIVE (g_task_get_source_object (task));
G_LOCK (proxy_drive);
- simple = g_simple_async_result_new_error (G_OBJECT (data->drive),
- 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->drive->volume_monitor);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (drive->volume_monitor);
gvfs_remote_volume_monitor_call_cancel_operation (proxy,
data->cancellation_id,
NULL,
@@ -580,6 +578,8 @@ operation_cancelled (GCancellable *cancellable,
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
+
+ g_task_return_error_if_cancelled (task);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -589,7 +589,8 @@ eject_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_drive_eject_finish (proxy,
@@ -597,37 +598,23 @@ eject_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->drive),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
+ error = NULL;
}
else
{
- simple = g_simple_async_result_new (G_OBJECT (data->drive),
- data->callback,
- data->user_data,
- NULL);
+ g_task_return_boolean (task, TRUE);
}
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
- g_proxy_mount_operation_destroy (data->mount_op_id);
- g_object_unref (data->drive);
- 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);
}
@@ -643,44 +630,39 @@ g_proxy_drive_eject_with_operation (GDrive *drive,
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
DBusOp *data;
GVfsRemoteVolumeMonitor *proxy;
+ GTask *task;
G_LOCK (proxy_drive);
+ task = g_task_new (drive, cancellable, callback, user_data);
+
if (g_cancellable_is_cancelled (cancellable))
{
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_error (G_OBJECT (drive),
- 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_drive);
- goto out;
+
+ g_task_return_error_if_cancelled (task);
+ g_object_unref (task);
+ return;
}
data = g_new0 (DBusOp, 1);
- data->drive = g_object_ref (proxy_drive);
- data->callback = callback;
- data->user_data = user_data;
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_drive->volume_monitor);
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 (operation_cancelled),
- data);
+ task);
}
else
{
data->cancellation_id = g_strdup ("");
}
+ g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_drive->volume_monitor);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT); /* 30
minute timeout */
@@ -691,15 +673,12 @@ g_proxy_drive_eject_with_operation (GDrive *drive,
data->mount_op_id,
NULL,
(GAsyncReadyCallback) eject_cb,
- data);
+ task);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), -1);
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
-
- out:
- ;
}
static gboolean
@@ -707,9 +686,9 @@ g_proxy_drive_eject_with_operation_finish (GDrive *drive,
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, drive), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -739,7 +718,8 @@ stop_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_drive_stop_finish (proxy,
@@ -747,37 +727,23 @@ stop_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->drive),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
+ error = NULL;
}
else
{
- simple = g_simple_async_result_new (G_OBJECT (data->drive),
- data->callback,
- data->user_data,
- NULL);
+ g_task_return_boolean (task, TRUE);
}
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
- g_proxy_mount_operation_destroy (data->mount_op_id);
- g_object_unref (data->drive);
- 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);
}
@@ -793,44 +759,39 @@ g_proxy_drive_stop (GDrive *drive,
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
DBusOp *data;
GVfsRemoteVolumeMonitor *proxy;
+ GTask *task;
G_LOCK (proxy_drive);
+ task = g_task_new (drive, cancellable, callback, user_data);
+
if (g_cancellable_is_cancelled (cancellable))
{
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_error (G_OBJECT (drive),
- 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_drive);
- goto out;
+
+ g_task_return_error_if_cancelled (task);
+ g_object_unref (task);
+ return;
}
data = g_new0 (DBusOp, 1);
- data->drive = g_object_ref (proxy_drive);
- data->callback = callback;
- data->user_data = user_data;
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_drive->volume_monitor);
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 (operation_cancelled),
- data);
+ task);
}
else
{
data->cancellation_id = g_strdup ("");
}
+ g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_drive->volume_monitor);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT); /* 30
minute timeout */
@@ -841,15 +802,12 @@ g_proxy_drive_stop (GDrive *drive,
data->mount_op_id,
NULL,
(GAsyncReadyCallback) stop_cb,
- data);
-
+ task);
+
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), -1);
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
-
- out:
- ;
}
static gboolean
@@ -857,72 +815,44 @@ g_proxy_drive_stop_finish (GDrive *drive,
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, drive), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
}
/* ---------------------------------------------------------------------------------------------------- */
-typedef struct {
- GProxyDrive *drive;
- GAsyncReadyCallback callback;
- gpointer user_data;
-
- gchar *cancellation_id;
- GCancellable *cancellable;
- gulong cancelled_handler_id;
-
- const gchar *mount_op_id;
-} DBusStartOp;
-
static void
start_cb (GVfsRemoteVolumeMonitor *proxy,
GAsyncResult *res,
gpointer user_data)
{
- DBusStartOp *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_drive_start_finish (proxy,
- res,
+ gvfs_remote_volume_monitor_call_drive_start_finish (proxy,
+ res,
&error);
-if (data->cancelled_handler_id > 0)
- g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
+ if (data->cancelled_handler_id > 0)
+ 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->drive),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
+ error = NULL;
}
else
{
- simple = g_simple_async_result_new (G_OBJECT (data->drive),
- 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 DBusStartOp */
- g_proxy_mount_operation_destroy (data->mount_op_id);
- g_object_unref (data->drive);
-
- 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);
}
@@ -931,23 +861,15 @@ static void
start_cancelled (GCancellable *cancellable,
gpointer user_data)
{
- DBusStartOp *data = user_data;
- GSimpleAsyncResult *simple;
+ GTask *task = G_TASK (user_data);
+ DBusOp *data = g_task_get_task_data (task);
GVfsRemoteVolumeMonitor *proxy;
+ GProxyDrive *drive = G_PROXY_DRIVE (g_task_get_source_object (task));
G_LOCK (proxy_drive);
- simple = g_simple_async_result_new_error (G_OBJECT (data->drive),
- 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 drive monitor that the op has been cancelled */
- proxy = g_proxy_volume_monitor_get_dbus_proxy (data->drive->volume_monitor);
+ proxy = g_proxy_volume_monitor_get_dbus_proxy (drive->volume_monitor);
gvfs_remote_volume_monitor_call_cancel_operation (proxy,
data->cancellation_id,
NULL,
@@ -956,6 +878,8 @@ start_cancelled (GCancellable *cancellable,
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
+
+ g_task_return_error_if_cancelled (task);
}
static void
@@ -967,38 +891,31 @@ g_proxy_drive_start (GDrive *drive,
gpointer user_data)
{
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
- DBusStartOp *data;
+ DBusOp *data;
GVfsRemoteVolumeMonitor *proxy;
+ GTask *task;
G_LOCK (proxy_drive);
+ task = g_task_new (drive, cancellable, callback, user_data);
+
if (g_cancellable_is_cancelled (cancellable))
{
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_error (G_OBJECT (drive),
- 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_drive);
- goto out;
+
+ g_task_return_error_if_cancelled (task);
+ g_object_unref (task);
+ return;
}
- data = g_new0 (DBusStartOp, 1);
- data->drive = g_object_ref (proxy_drive);
- data->callback = callback;
- data->user_data = user_data;
+ data = g_new0 (DBusOp, 1);
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 (start_cancelled),
- data);
+ task);
}
else
{
@@ -1007,6 +924,8 @@ g_proxy_drive_start (GDrive *drive,
data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_drive->volume_monitor);
+ g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_drive->volume_monitor);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT); /* 30
minute timeout */
@@ -1017,14 +936,12 @@ g_proxy_drive_start (GDrive *drive,
data->mount_op_id,
NULL,
(GAsyncReadyCallback) start_cb,
- data);
+ task);
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), -1);
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
- out:
- ;
}
static gboolean
@@ -1032,9 +949,9 @@ g_proxy_drive_start_finish (GDrive *drive,
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, drive), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1044,43 +961,32 @@ poll_for_media_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_drive_poll_for_media_finish (proxy,
res,
&error);
- 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->drive),
- data->callback,
- data->user_data,
- error);
+ g_task_return_error (task, error);
+ error = NULL;
}
else
{
- simple = g_simple_async_result_new (G_OBJECT (data->drive),
- data->callback,
- data->user_data,
- NULL);
+ g_task_return_boolean (task, TRUE);
}
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
}
- g_object_unref (data->drive);
- g_free (data->cancellation_id);
if (data->cancelled_handler_id > 0)
- g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
- if (data->cancellable != NULL)
- g_object_unref (data->cancellable);
- g_free (data);
+ g_signal_handler_disconnect (g_task_get_cancellable (task), data->cancelled_handler_id);
+
+ g_object_unref (task);
if (error != NULL)
g_error_free (error);
}
@@ -1094,55 +1000,47 @@ g_proxy_drive_poll_for_media (GDrive *drive,
GProxyDrive *proxy_drive = G_PROXY_DRIVE (drive);
DBusOp *data;
GVfsRemoteVolumeMonitor *proxy;
+ GTask *task;
G_LOCK (proxy_drive);
+ task = g_task_new (drive, cancellable, callback, user_data);
+
if (g_cancellable_is_cancelled (cancellable))
{
- GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new_error (G_OBJECT (drive),
- 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_drive);
- goto out;
+
+ g_task_return_error_if_cancelled (task);
+ g_object_unref (task);
+ return;
}
data = g_new0 (DBusOp, 1);
- data->drive = g_object_ref (proxy_drive);
- 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 (operation_cancelled),
- data);
+ task);
}
else
{
data->cancellation_id = g_strdup ("");
}
-
+
+ g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_drive->volume_monitor);
gvfs_remote_volume_monitor_call_drive_poll_for_media (proxy,
proxy_drive->id,
data->cancellation_id,
NULL,
(GAsyncReadyCallback) poll_for_media_cb,
- data);
+ task);
g_object_unref (proxy);
G_UNLOCK (proxy_drive);
- out:
- ;
}
static gboolean
@@ -1150,9 +1048,9 @@ g_proxy_drive_poll_for_media_finish (GDrive *drive,
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, drive), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
}
/* ---------------------------------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]