[Spice-devel] [spice-gtk v5 10/23] file-xfer: create helper function to send progress

Jonathon Jongsma jjongsma at redhat.com
Wed Jul 6 15:49:57 UTC 2016


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

On Tue, 2016-07-05 at 15:07 +0200, Victor Toso wrote:
> This is an intermediary step for the following patches to make the
> changes more clear and easy to follow.
> 
> In file_xfer_send_progress(), I've renamed the variable self to
> xfer_task as this is not SpiceFileTransferTask function.
> ---
>  src/channel-main.c | 50 ++++++++++++++++++++++++++++++--------------------
>  1 file changed, 30 insertions(+), 20 deletions(-)
> 
> diff --git a/src/channel-main.c b/src/channel-main.c
> index f02daee..529c36c 100644
> --- a/src/channel-main.c
> +++ b/src/channel-main.c
> @@ -1883,6 +1883,34 @@ static void file_xfer_close_cb(GObject      *object,
>      g_object_unref(self);
>  }
>  
> +static void file_xfer_send_progress(SpiceFileTransferTask *xfer_task)
> +{
> +    goffset read = 0;
> +    goffset total = 0;
> +    GHashTableIter iter;
> +    gpointer key, value;
> +    SpiceMainChannel *channel;
> +
> +    g_return_if_fail(xfer_task != NULL);
> +
> +    if (!xfer_task->progress_callback)
> +        return;
> +
> +    channel = spice_file_transfer_task_get_channel(xfer_task);
> +
> +    /* since the progress_callback does not have a parameter to indicate
> +     * which file the progress is associated with, report progress on all
> +     * current transfers */
> +    g_hash_table_iter_init(&iter, channel->priv->file_xfer_tasks);
> +    while (g_hash_table_iter_next(&iter, &key, &value)) {
> +        SpiceFileTransferTask *t = (SpiceFileTransferTask *)value;
> +        read += t->read_bytes;
> +        total += t->file_size;
> +    }
> +
> +    xfer_task->progress_callback(read, total, xfer_task-
> >progress_callback_data);
> +}
> +
>  static void file_xfer_data_flushed_cb(GObject *source_object,
>                                        GAsyncResult *res,
>                                        gpointer user_data)
> @@ -1897,6 +1925,8 @@ static void file_xfer_data_flushed_cb(GObject
> *source_object,
>          return;
>      }
>  
> +    file_xfer_send_progress(self);
> +
>      if (spice_util_get_debug()) {
>          const GTimeSpan interval = 20 * G_TIME_SPAN_SECOND;
>          gint64 now = g_get_monotonic_time();
> @@ -1910,26 +1940,6 @@ static void file_xfer_data_flushed_cb(GObject
> *source_object,
>          }
>      }
>  
> -    if (self->progress_callback) {
> -        goffset read = 0;
> -        goffset total = 0;
> -        SpiceMainChannel *main_channel = self->channel;
> -        GHashTableIter iter;
> -        gpointer key, value;
> -
> -        /* since the progress_callback does not have a parameter to indicate
> -         * which file the progress is associated with, report progress on all
> -         * current transfers */
> -        g_hash_table_iter_init(&iter, main_channel->priv->file_xfer_tasks);
> -        while (g_hash_table_iter_next(&iter, &key, &value)) {
> -            SpiceFileTransferTask *t = (SpiceFileTransferTask *)value;
> -            read += t->read_bytes;
> -            total += t->file_size;
> -        }
> -
> -        self->progress_callback(read, total, self->progress_callback_data);
> -    }
> -
>      /* Read more data */
>      spice_file_transfer_task_read_async(self, file_xfer_read_async_cb, NULL);
>  }


More information about the Spice-devel mailing list