[Spice-devel] [spice-gtk v4 11/24] file-xfer: create helper function to send progress

Victor Toso victortoso at redhat.com
Thu Jun 23 17:37:43 UTC 2016


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 e57ee73..5e23acb 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -1884,6 +1884,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)
@@ -1898,6 +1926,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();
@@ -1911,26 +1941,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);
 }
-- 
2.7.4



More information about the Spice-devel mailing list