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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
 }
-- 
2.7.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]