[Spice-devel] [spice-gtk v2] file-transfer: Move initializations to _task_new()

Jonathon Jongsma jjongsma at redhat.com
Tue Aug 9 16:35:14 UTC 2016


Acked-by: Jonathon Jongsma <jjongsma at redhat.com>


On Sat, 2016-08-06 at 15:15 +0200, Victor Toso wrote:
> This was a request introduced at f6b3b697093a16de to be done after
> moving the SpiceFileTransferTask code to its own file.
> ---
>  src/spice-file-transfer-task.c | 40 ++++++++++++++++++++++--------
> ----------
>  1 file changed, 22 insertions(+), 18 deletions(-)
> 
> diff --git a/src/spice-file-transfer-task.c b/src/spice-file-
> transfer-task.c
> index 70c6419..e7f50da 100644
> --- a/src/spice-file-transfer-task.c
> +++ b/src/spice-file-transfer-task.c
> @@ -88,16 +88,34 @@ static guint task_signals[LAST_TASK_SIGNAL];
>  
> *********************************************************************
> *********/
>  
>  static SpiceFileTransferTask *
> -spice_file_transfer_task_new(SpiceMainChannel *channel, GFile *file,
> GCancellable *cancellable)
> +spice_file_transfer_task_new(SpiceMainChannel *channel,
> +                             GFile *file,
> +                             GFileCopyFlags flags,
> +                             GCancellable *cancellable)
>  {
>      static uint32_t xfer_id = 1;    /* Used to identify task id */
> +    GCancellable *task_cancellable = cancellable;
> +    SpiceFileTransferTask *self;
> +
> +    /* if a cancellable object was not provided for the overall
> operation,
> +     * create a separate object for each file so that they can be
> cancelled
> +     * separately  */
> +    if (!task_cancellable)
> +        task_cancellable = g_cancellable_new();
>  
> -    return g_object_new(SPICE_TYPE_FILE_TRANSFER_TASK,
> +    self = g_object_new(SPICE_TYPE_FILE_TRANSFER_TASK,
>                          "id", xfer_id++,
>                          "file", file,
>                          "channel", channel,
> -                        "cancellable", cancellable,
> +                        "cancellable", task_cancellable,
>                          NULL);
> +    self->flags = flags;
> +
> +    /* if we created a GCancellable above, unref it */
> +    if (!cancellable)
> +        g_object_unref(task_cancellable);
> +
> +    return self;
>  }
>  
>  static void spice_file_transfer_task_query_info_cb(GObject *obj,
> @@ -366,24 +384,10 @@ GHashTable
> *spice_file_transfer_task_create_tasks(GFile **files,
>      for (i = 0; files[i] != NULL &&
> !g_cancellable_is_cancelled(cancellable); i++) {
>          SpiceFileTransferTask *xfer_task;
>          guint32 task_id;
> -        GCancellable *task_cancellable = cancellable;
> -
> -        /* if a cancellable object was not provided for the overall
> operation,
> -         * create a separate object for each file so that they can
> be cancelled
> -         * separately  */
> -        if (!task_cancellable)
> -            task_cancellable = g_cancellable_new();
> -
> -        /* FIXME: Move the xfer-task initialization to
> spice_file_transfer_task_new() */
> -        xfer_task = spice_file_transfer_task_new(channel, files[i],
> task_cancellable);
> -        xfer_task->flags = flags;
>  
> +        xfer_task = spice_file_transfer_task_new(channel, files[i],
> flags, cancellable);
>          task_id = spice_file_transfer_task_get_id(xfer_task);
>          g_hash_table_insert(xfer_ht, GUINT_TO_POINTER(task_id),
> g_object_ref(xfer_task));
> -
> -        /* if we created a per-task cancellable above, unref it */
> -        if (!cancellable)
> -            g_object_unref(task_cancellable);
>      }
>      return xfer_ht;
>  }


More information about the Spice-devel mailing list