summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2016-08-11 13:08:34 -0500
committerJonathon Jongsma <jjongsma@redhat.com>2016-08-31 15:35:59 -0500
commit5cdaa75f6947b4c7f638f3ccaa519f512e54b75f (patch)
tree43de01e7ea0aa8a8433a64b1f3642d5da860eeaf
parente2b383ec7f3ef0eb86aef361ed9c8f20dc807433 (diff)
Add ability to get sizes from SpiceFileTransferTask
If a client is handling multiple SpiceFileTransferTasks at one time, it's not currently possible to provide a single overall progress to the user. The only information that the client can get is the percentage progress. This patch adds two new properties: - total-bytes: the size of the file transfer task in bytes - transferred-bytes: the number of bytes already transferred This allows a client UI to calculate the combined progress for all ongoing transfer tasks and present it to the user. Two convenience functions were added to retrieve these values: - spice_file_transfer_task_get_total_bytes() - spice_file_transfer_task_get_transferred_bytes()
-rw-r--r--src/channel-main.c4
-rw-r--r--src/map-file2
-rw-r--r--src/spice-file-transfer-task-priv.h2
-rw-r--r--src/spice-file-transfer-task.c48
-rw-r--r--src/spice-file-transfer-task.h2
-rw-r--r--src/spice-glib-sym-file2
6 files changed, 52 insertions, 8 deletions
diff --git a/src/channel-main.c b/src/channel-main.c
index 1ea0f71..419b0c2 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -2976,8 +2976,8 @@ static void file_transfer_operation_task_finished(SpiceFileTransferTask *xfer_ta
* remaining bytes from transfer-size in order to keep the coherence of
* the information we provide to the user (total-sent and transfer-size)
* in the progress-callback */
- guint64 file_size = spice_file_transfer_task_get_file_size(xfer_task);
- guint64 bytes_read = spice_file_transfer_task_get_bytes_read(xfer_task);
+ guint64 file_size = spice_file_transfer_task_get_total_bytes(xfer_task);
+ guint64 bytes_read = spice_file_transfer_task_get_transferred_bytes(xfer_task);
xfer_op->stats.transfer_size -= (file_size - bytes_read);
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
xfer_op->stats.cancelled++;
diff --git a/src/map-file b/src/map-file
index 8618f6e..3d92153 100644
--- a/src/map-file
+++ b/src/map-file
@@ -37,6 +37,8 @@ spice_display_set_grab_keys;
spice_file_transfer_task_cancel;
spice_file_transfer_task_get_filename;
spice_file_transfer_task_get_progress;
+spice_file_transfer_task_get_total_bytes;
+spice_file_transfer_task_get_transferred_bytes;
spice_file_transfer_task_get_type;
spice_get_option_group;
spice_gl_scanout_free;
diff --git a/src/spice-file-transfer-task-priv.h b/src/spice-file-transfer-task-priv.h
index a7b58d8..253b3c5 100644
--- a/src/spice-file-transfer-task-priv.h
+++ b/src/spice-file-transfer-task-priv.h
@@ -50,8 +50,6 @@ gssize spice_file_transfer_task_read_finish(SpiceFileTransferTask *self,
GAsyncResult *result,
char **buffer,
GError **error);
-guint64 spice_file_transfer_task_get_file_size(SpiceFileTransferTask *self);
-guint64 spice_file_transfer_task_get_bytes_read(SpiceFileTransferTask *self);
gboolean spice_file_transfer_task_is_completed(SpiceFileTransferTask *self);
G_END_DECLS
diff --git a/src/spice-file-transfer-task.c b/src/spice-file-transfer-task.c
index 3be130c..aa9d95b 100644
--- a/src/spice-file-transfer-task.c
+++ b/src/spice-file-transfer-task.c
@@ -73,6 +73,8 @@ enum {
PROP_TASK_CHANNEL,
PROP_TASK_CANCELLABLE,
PROP_TASK_FILE,
+ PROP_TASK_TOTAL_BYTES,
+ PROP_TASK_TRANSFERRED_BYTES,
PROP_TASK_PROGRESS,
};
@@ -152,6 +154,7 @@ static void spice_file_transfer_task_query_info_cb(GObject *obj,
/* SpiceFileTransferTask's init is done, handshake for file-transfer will
* start soon. First "progress" can be emitted ~ 0% */
+ g_object_notify(G_OBJECT(self), "total-bytes");
g_object_notify(G_OBJECT(self), "progress");
g_task_return_pointer(task, info, g_object_unref);
@@ -349,15 +352,13 @@ GCancellable *spice_file_transfer_task_get_cancellable(SpiceFileTransferTask *se
return self->cancellable;
}
-G_GNUC_INTERNAL
-guint64 spice_file_transfer_task_get_file_size(SpiceFileTransferTask *self)
+guint64 spice_file_transfer_task_get_total_bytes(SpiceFileTransferTask *self)
{
g_return_val_if_fail(self != NULL, 0);
return self->file_size;
}
-G_GNUC_INTERNAL
-guint64 spice_file_transfer_task_get_bytes_read(SpiceFileTransferTask *self)
+guint64 spice_file_transfer_task_get_transferred_bytes(SpiceFileTransferTask *self)
{
g_return_val_if_fail(self != NULL, 0);
return self->read_bytes;
@@ -445,6 +446,7 @@ void spice_file_transfer_task_read_async(SpiceFileTransferTask *self,
* data that was already sent. To notify the 100% (completed), channel-main
* should call read-async when it expects EOF. */
g_object_notify(G_OBJECT(self), "progress");
+ g_object_notify(G_OBJECT(self), "transferred-bytes");
task = g_task_new(self, self->cancellable, callback, userdata);
@@ -570,6 +572,12 @@ spice_file_transfer_task_get_property(GObject *object,
case PROP_TASK_FILE:
g_value_set_object(value, self->file);
break;
+ case PROP_TASK_TOTAL_BYTES:
+ g_value_set_uint64(value, spice_file_transfer_task_get_total_bytes(self));
+ break;
+ case PROP_TASK_TRANSFERRED_BYTES:
+ g_value_set_uint64(value, spice_file_transfer_task_get_transferred_bytes(self));
+ break;
case PROP_TASK_PROGRESS:
g_value_set_double(value, spice_file_transfer_task_get_progress(self));
break;
@@ -714,6 +722,38 @@ spice_file_transfer_task_class_init(SpiceFileTransferTaskClass *klass)
G_PARAM_STATIC_STRINGS));
/**
+ * SpiceFileTransferTask:total-bytes:
+ *
+ * The total size in bytes of this file transfer.
+ *
+ * Since: 0.33
+ **/
+ g_object_class_install_property(object_class, PROP_TASK_TOTAL_BYTES,
+ g_param_spec_uint64("total-bytes",
+ "Total bytes",
+ "The size in bytes of the file transferred",
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+
+ /**
+ * SpiceFileTransferTask:transferred-bytes:
+ *
+ * The number of bytes that have been transferred so far.
+ *
+ * Since: 0.33
+ **/
+ g_object_class_install_property(object_class, PROP_TASK_TRANSFERRED_BYTES,
+ g_param_spec_uint64("transferred-bytes",
+ "Transferred bytes",
+ "The number of bytes transferred",
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+
+ /**
* SpiceFileTransferTask:progress:
*
* The current state of the file transfer. This value indicates a
diff --git a/src/spice-file-transfer-task.h b/src/spice-file-transfer-task.h
index 4f179fb..d04f0ef 100644
--- a/src/spice-file-transfer-task.h
+++ b/src/spice-file-transfer-task.h
@@ -43,6 +43,8 @@ GType spice_file_transfer_task_get_type(void) G_GNUC_CONST;
char* spice_file_transfer_task_get_filename(SpiceFileTransferTask *self);
void spice_file_transfer_task_cancel(SpiceFileTransferTask *self);
+guint64 spice_file_transfer_task_get_total_bytes(SpiceFileTransferTask *self);
+guint64 spice_file_transfer_task_get_transferred_bytes(SpiceFileTransferTask *self);
double spice_file_transfer_task_get_progress(SpiceFileTransferTask *self);
G_END_DECLS
diff --git a/src/spice-glib-sym-file b/src/spice-glib-sym-file
index 7d2af60..473c5ca 100644
--- a/src/spice-glib-sym-file
+++ b/src/spice-glib-sym-file
@@ -26,6 +26,8 @@ spice_display_gl_draw_done
spice_file_transfer_task_cancel
spice_file_transfer_task_get_filename
spice_file_transfer_task_get_progress
+spice_file_transfer_task_get_total_bytes
+spice_file_transfer_task_get_transferred_bytes
spice_file_transfer_task_get_type
spice_get_option_group
spice_gl_scanout_free