summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2015-09-11 11:46:22 -0500
committerJonathon Jongsma <jjongsma@redhat.com>2015-10-09 10:26:19 -0500
commit113093dd00a1cf10f6d3c3589b7589a184cec081 (patch)
treee8763849b4b8120a2d77eac804fcbef1a4019f2c
parent9c47d3a39277144b8f3c04113d3a8672af2ed357 (diff)
Fix progress monitoring in spice_main_file_copy_async
spice_main_file_copy_async() allows you to pass a NULL-terminated array of files to transfer to the guest. It also allows you to pass a progress_callback function to monitor the progress of the transfer, but this progress callback is called separately for each file that is transferred, and there are no parameters that allow the caller to determine which file a given callback corresponds to. This makes it very difficult to monitor the progress. To make this more usable, I've changed it so that the progress callback doesn't simply report the number of bytes read and total size of the current file. Instead, we add up the status of all current transfers and report that value to the callback.
-rw-r--r--src/channel-main.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/channel-main.c b/src/channel-main.c
index 688b486..b16898d 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -1788,9 +1788,25 @@ static void file_xfer_data_flushed_cb(GObject *source_object,
}
}
- if (task->progress_callback)
- task->progress_callback(task->read_bytes, task->file_size,
- task->progress_callback_data);
+ if (task->progress_callback) {
+ goffset read = 0;
+ goffset total = 0;
+ SpiceMainChannel *main_channel = task->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)) {
+ SpiceFileXferTask *t = (SpiceFileXferTask *)value;
+ read += t->read_bytes;
+ total += t->file_size;
+ }
+
+ task->progress_callback(read, total, task->progress_callback_data);
+ }
/* Read more data */
file_xfer_continue_read(task);
@@ -3018,7 +3034,11 @@ static void file_xfer_send_start_msg_async(SpiceMainChannel *channel,
* setting this to a #GFileProgressCallback function. @progress_callback_data
* will be passed to this function. It is guaranteed that this callback will
* be called after all data has been transferred with the total number of bytes
- * copied during the operation.
+ * copied during the operation. Note that before release 0.31, progress_callback
+ * was broken since it only provided status for a single file transfer, but did
+ * not provide a way to determine which file it referred to. In release 0.31,
+ * this behavior was changed so that progress_callback provides the status of
+ * all ongoing file transfers.
*
* When the operation is finished, callback will be called. You can then call
* spice_main_file_copy_finish() to get the result of the operation.