summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--logview/logview-log.c10
-rw-r--r--logview/logview-log.h1
-rw-r--r--logview/logview-window.c40
-rw-r--r--logview/tests/test-reader.c2
4 files changed, 43 insertions, 10 deletions
diff --git a/logview/logview-log.c b/logview/logview-log.c
index 602f78a7..407f49c3 100644
--- a/logview/logview-log.c
+++ b/logview/logview-log.c
@@ -78,6 +78,7 @@ typedef struct {
GError *err;
const char **lines;
GSList *new_days;
+ GCancellable *cancellable;
LogviewNewLinesCallback callback;
gpointer user_data;
} NewLinesJob;
@@ -253,6 +254,8 @@ new_lines_job_done (gpointer data)
job->callback (job->log, job->lines, job->new_days, job->err, job->user_data);
}
+ g_clear_object (&job->cancellable);
+
g_slist_foreach (job->new_days, (GFunc) logview_utils_day_free, NULL);
g_slist_free (job->new_days);
@@ -290,7 +293,7 @@ do_read_new_lines (GIOSchedulerJob *io_job,
g_ptr_array_remove_index (lines, lines->len - 1);
while ((line = g_data_input_stream_read_line (log->priv->stream, NULL,
- NULL, &err)) != NULL)
+ job->cancellable, &err)) != NULL)
{
g_ptr_array_add (lines, (gpointer) line);
}
@@ -800,6 +803,7 @@ log_setup_load (LogviewLog *log, LogviewCreateCallback callback,
void
logview_log_read_new_lines (LogviewLog *log,
+ GCancellable *cancellable,
LogviewNewLinesCallback callback,
gpointer user_data)
{
@@ -809,6 +813,7 @@ logview_log_read_new_lines (LogviewLog *log,
job = g_slice_new0 (NewLinesJob);
job->callback = callback;
job->user_data = user_data;
+ job->cancellable = (cancellable != NULL) ? g_object_ref (cancellable) : NULL;
job->log = g_object_ref (log);
job->err = NULL;
job->lines = NULL;
@@ -817,7 +822,8 @@ logview_log_read_new_lines (LogviewLog *log,
/* push the fetching job into another thread */
g_io_scheduler_push_job (do_read_new_lines,
job,
- NULL, 0, NULL);
+ NULL, 0,
+ job->cancellable);
}
void
diff --git a/logview/logview-log.h b/logview/logview-log.h
index 6e69ad84..4f81af14 100644
--- a/logview/logview-log.h
+++ b/logview/logview-log.h
@@ -90,6 +90,7 @@ void logview_log_create_from_gfile (GFile *file,
LogviewCreateCallback callback,
gpointer user_data);
void logview_log_read_new_lines (LogviewLog *log,
+ GCancellable *cancellable,
LogviewNewLinesCallback callback,
gpointer user_data);
diff --git a/logview/logview-window.c b/logview/logview-window.c
index bc3f8a4e..3634e1d2 100644
--- a/logview/logview-window.c
+++ b/logview/logview-window.c
@@ -67,6 +67,8 @@ struct _LogviewWindowPrivate {
gulong monitor_id;
guint search_timeout_id;
+ GCancellable *read_cancellable;
+
guint filter_merge_id;
GList *active_filters;
gboolean matches_only;
@@ -919,12 +921,29 @@ loglist_day_cleared_cb (LogviewLoglist *loglist,
}
static void
+logview_window_schedule_log_read (LogviewWindow *window,
+ LogviewLog *log)
+{
+ if (window->priv->read_cancellable != NULL) {
+ g_cancellable_cancel (window->priv->read_cancellable);
+ g_clear_object (&window->priv->read_cancellable);
+ }
+
+ window->priv->read_cancellable = g_cancellable_new ();
+ logview_log_read_new_lines (log,
+ window->priv->read_cancellable,
+ (LogviewNewLinesCallback) read_new_lines_cb,
+ window);
+}
+
+static void
log_monitor_changed_cb (LogviewLog *log,
gpointer user_data)
{
+ LogviewWindow *window = user_data;
+
/* reschedule a read */
- logview_log_read_new_lines (log, (LogviewNewLinesCallback) read_new_lines_cb,
- user_data);
+ logview_window_schedule_log_read (window, log);
}
static void
@@ -960,10 +979,12 @@ read_new_lines_cb (LogviewLog *log,
gsize len;
if (error != NULL) {
- primary = g_strdup_printf (_("Can't read from \"%s\""),
- logview_log_get_display_name (log));
- logview_window_add_error (window, primary, error->message);
- g_free (primary);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ primary = g_strdup_printf (_("Can't read from \"%s\""),
+ logview_log_get_display_name (log));
+ logview_window_add_error (window, primary, error->message);
+ g_free (primary);
+ }
return;
}
@@ -1065,7 +1086,7 @@ active_log_changed_cb (LogviewManager *manager,
if (lines == NULL || logview_log_has_new_lines (log)) {
/* read the new lines */
- logview_log_read_new_lines (log, (LogviewNewLinesCallback) read_new_lines_cb, window);
+ logview_window_schedule_log_read (window, log);
} else {
/* start now monitoring the log for changes */
window->priv->monitor_id = g_signal_connect (log, "log-changed",
@@ -1237,6 +1258,11 @@ logview_window_finalize (GObject *object)
{
LogviewWindow *logview = LOGVIEW_WINDOW (object);
+ if (logview->priv->read_cancellable != NULL) {
+ g_cancellable_cancel (logview->priv->read_cancellable);
+ g_clear_object (&logview->priv->read_cancellable);
+ }
+
g_object_unref (logview->priv->ui_manager);
G_OBJECT_CLASS (logview_window_parent_class)->finalize (object);
}
diff --git a/logview/tests/test-reader.c b/logview/tests/test-reader.c
index 75da422e..b9ef5d40 100644
--- a/logview/tests/test-reader.c
+++ b/logview/tests/test-reader.c
@@ -47,7 +47,7 @@ callback (LogviewLog *log,
{
g_print ("callback! err %p, log %p\n", error, log);
- logview_log_read_new_lines (log, new_lines_cb, NULL);
+ logview_log_read_new_lines (log, NULL, new_lines_cb, NULL);
}
int main (int argc, char **argv)