[Spice-devel] [spice-gtk][PATCH v2] Added INFO messages about a file transfer
Pavel Grunt
pgrunt at redhat.com
Wed Sep 17 03:10:06 PDT 2014
When a file transfer starts / finishes an information message is printed (in INFO log level).
Also INFO messages about the transfer progress are printed.
---
gtk/channel-main.c | 23 +++++++++++++++++++++++
gtk/spice-widget.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index 021fa83..7a59613 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -70,6 +70,7 @@ typedef struct SpiceFileXferTask {
char buffer[FILE_XFER_CHUNK_SIZE];
uint64_t read_bytes;
uint64_t file_size;
+ GDateTime *start_time;
GError *error;
} SpiceFileXferTask;
@@ -1538,6 +1539,7 @@ static void file_xfer_task_free(SpiceFileXferTask *task)
g_clear_object(&task->channel);
g_clear_object(&task->file);
g_clear_object(&task->file_stream);
+ g_date_time_unref(task->start_time);
g_free(task);
}
@@ -1548,6 +1550,9 @@ static void file_xfer_close_cb(GObject *object,
{
GSimpleAsyncResult *res;
SpiceFileXferTask *task;
+ GDateTime *end;
+ char *basename;
+ double seconds;
GError *error = NULL;
task = user_data;
@@ -1572,6 +1577,17 @@ static void file_xfer_close_cb(GObject *object,
g_simple_async_result_take_error(res, task->error);
g_simple_async_result_set_op_res_gboolean(res, FALSE);
} else {
+ end = g_date_time_new_now_local();
+ seconds = (double) g_date_time_difference(end, task->start_time) / 1000000.0;
+ g_date_time_unref(end);
+ basename = g_file_get_basename(task->file);
+ if (basename != NULL) {
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO,
+ "transferred file %s of %.2f kB size in %.2f seconds (%.1f MB/s)",
+ basename, task->file_size / 1000.0, seconds,
+ (task->file_size/1000000.0)/seconds);
+ g_free(basename);
+ }
g_simple_async_result_set_op_res_gboolean(res, TRUE);
}
g_simple_async_result_complete_in_idle(res);
@@ -2739,6 +2755,7 @@ static void file_xfer_send_start_msg_async(SpiceMainChannel *channel,
{
SpiceMainChannelPrivate *c = channel->priv;
SpiceFileXferTask *task;
+ char *basename;
static uint32_t xfer_id; /* Used to identify task id */
task = g_malloc0(sizeof(SpiceFileXferTask));
@@ -2751,7 +2768,13 @@ static void file_xfer_send_start_msg_async(SpiceMainChannel *channel,
task->progress_callback_data = progress_callback_data;
task->callback = callback;
task->user_data = user_data;
+ task->start_time = g_date_time_new_now_local();
+ basename = g_file_get_basename(task->file);
+ if (basename != NULL) {
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "transfer of file %s has started", basename);
+ g_free(basename);
+ }
CHANNEL_DEBUG(task->channel, "Insert a xfer task:%d to task list", task->id);
g_hash_table_insert(c->file_xfer_tasks, GUINT_TO_POINTER(task->id), task);
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 1220030..39434ff 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -473,6 +473,41 @@ static gboolean grab_broken(SpiceDisplay *self, GdkEventGrabBroken *event,
return false;
}
+static void file_progress_callback(goffset current_num_bytes,
+ goffset total_num_bytes,
+ gpointer user_data)
+{
+ GDateTime *now;
+ GTimeSpan diff;
+ const GTimeSpan interval = 20000000;/* microseconds */
+ GDateTime **last_time = user_data;
+
+ g_return_if_fail(last_time != NULL);
+
+ if (current_num_bytes == total_num_bytes) {
+ g_date_time_unref(*last_time);
+ g_free(last_time);
+ last_time = NULL;
+ return;
+ }
+
+ now = g_date_time_new_now_local();
+ diff = g_date_time_difference(now, *last_time);
+
+ if (diff < interval) {
+ g_date_time_unref(now);
+ return;
+ }
+
+ g_date_time_unref(*last_time);
+ *last_time = now;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "transferred %.2f%%",
+ 100.0 * current_num_bytes / total_num_bytes );
+
+
+}
+
static void drag_data_received_callback(SpiceDisplay *self,
GdkDragContext *drag_context,
gint x,
@@ -488,6 +523,7 @@ static void drag_data_received_callback(SpiceDisplay *self,
SpiceDisplayPrivate *d = self->priv;
int i = 0;
GFile **files;
+ GDateTime **progress_cb_time;
/* We get a buf like:
* file:///root/a.txt\r\nfile:///root/b.txt\r\n
@@ -504,8 +540,12 @@ static void drag_data_received_callback(SpiceDisplay *self,
}
g_strfreev(file_urls);
- spice_main_file_copy_async(d->main, files, 0, NULL, NULL,
- NULL, NULL, NULL);
+ progress_cb_time = g_malloc0(sizeof(GDateTime *));
+ *progress_cb_time = g_date_time_new_now_local();
+
+ spice_main_file_copy_async(d->main, files, 0, NULL,
+ (file_progress_callback), progress_cb_time,
+ NULL, NULL);
for (i = 0; i < n_files; i++) {
g_object_unref(files[i]);
}
--
1.9.3
More information about the Spice-devel
mailing list