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. --- Changes from v2 - reworded commit message per Victor's comment src/channel-main.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/channel-main.c b/src/channel-main.c index 2af9e64..8bf1354 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. -- 2.1.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel