[gnome-logs] query: remove n_results



commit e59fb9db72b93ba6f7e537b4b5408db1c0b0270e
Author: Lars Uebernickel <lars uebernic de>
Date:   Sat Feb 14 19:41:59 2015 +0100

    query: remove n_results
    
    It was always set to -1 in practice. As we want to move GlJournal to a
    iterator-style API, having this field doesn't make sense.
    
    Also removes some dead code as a result of this.

 src/gl-eventviewlist.c |   20 +++-----
 src/gl-journal.c       |  125 +++++++++++++++--------------------------------
 src/gl-journal.h       |    1 -
 3 files changed, 47 insertions(+), 99 deletions(-)
---
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index 8c33cba..e1a6366 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -51,7 +51,6 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GlEventViewList, gl_event_view_list, GTK_TYPE_BOX)
 
-static const gssize N_RESULTS = -1;
 static const gssize N_RESULTS_IDLE = 25;
 static const gchar DESKTOP_SCHEMA[] = "org.gnome.desktop.interface";
 static const gchar SETTINGS_SCHEMA[] = "org.gnome.Logs";
@@ -394,8 +393,7 @@ static void
 gl_event_view_list_add_listbox_important (GlEventViewList *view)
 {
     /* Alert or emergency priority. */
-    const GlJournalQuery query = { N_RESULTS,
-                                   (gchar*[5]){ "PRIORITY=0",
+    const GlJournalQuery query = { (gchar*[5]){ "PRIORITY=0",
                                                 "PRIORITY=1",
                                                 "PRIORITY=2",
                                                 "PRIORITY=3",
@@ -411,7 +409,7 @@ gl_event_view_list_add_listbox_important (GlEventViewList *view)
 static void
 gl_event_view_list_add_listbox_all (GlEventViewList *view)
 {
-    const GlJournalQuery query = { N_RESULTS, NULL };
+    const GlJournalQuery query = { NULL };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
@@ -441,8 +439,7 @@ gl_event_view_list_add_listbox_applications (GlEventViewList *view)
         uid_str = g_strdup_printf ("_UID=%d", uid);
 
         {
-            GlJournalQuery query = { N_RESULTS,
-                                     (gchar *[5]){ "_TRANSPORT=journal",
+            GlJournalQuery query = { (gchar *[5]){ "_TRANSPORT=journal",
                                                    "_TRANSPORT=stdout",
                                                    "_TRANSPORT=syslog",
                                                    uid_str, NULL } };
@@ -454,8 +451,7 @@ gl_event_view_list_add_listbox_applications (GlEventViewList *view)
     }
     else
     {
-        GlJournalQuery query = { N_RESULTS,
-                                 (gchar *[4]){ "_TRANSPORT=journal",
+        GlJournalQuery query = { (gchar *[4]){ "_TRANSPORT=journal",
                                                "_TRANSPORT=stdout",
                                                "_TRANSPORT=syslog", NULL } };
 
@@ -468,8 +464,7 @@ gl_event_view_list_add_listbox_applications (GlEventViewList *view)
 static void
 gl_event_view_list_add_listbox_system (GlEventViewList *view)
 {
-    GlJournalQuery query = { N_RESULTS,
-                             (gchar *[2]){ "_TRANSPORT=kernel", NULL } };
+    GlJournalQuery query = { (gchar *[2]){ "_TRANSPORT=kernel", NULL } };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
@@ -481,8 +476,7 @@ gl_event_view_list_add_listbox_system (GlEventViewList *view)
 static void
 gl_event_view_list_add_listbox_hardware (GlEventViewList *view)
 {
-    GlJournalQuery query = { N_RESULTS,
-                             (gchar *[3]){ "_TRANSPORT=kernel", "_KERNEL_DEVICE", NULL } };
+    GlJournalQuery query = { (gchar *[3]){ "_TRANSPORT=kernel", "_KERNEL_DEVICE", NULL } };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
@@ -494,7 +488,7 @@ gl_event_view_list_add_listbox_hardware (GlEventViewList *view)
 static void
 gl_event_view_list_add_listbox_security (GlEventViewList *view)
 {
-    const GlJournalQuery query = { N_RESULTS, (gchar *[2]){ "_AUDIT_SESSION", NULL } };
+    const GlJournalQuery query = { (gchar *[2]){ "_AUDIT_SESSION", NULL } };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 83170d8..f44cae6 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -336,7 +336,6 @@ gl_journal_query_copy (const GlJournalQuery *source)
     matches[n_matches] = NULL;
 
     result->matches = matches;
-    result->n_results = source->n_results;
 
     return result;
 }
@@ -455,110 +454,66 @@ gl_journal_query (GlJournal *self, const GlJournalQuery *query)
         }
     }
 
-    if (query->n_results == -1)
-    {
-        /* Take events from this boot only. */
-        sd_id128_t boot_id;
-        gchar boot_string[33];
-        gchar *match_string;
-
-        ret = sd_id128_get_boot (&boot_id);
-
-        if (ret < 0)
-        {
-            g_warning ("Error getting boot ID of running kernel: %s",
-                       g_strerror (-ret));
-        }
-
-        sd_id128_to_string (boot_id, boot_string);
+    /* Take events from this boot only. */
+    sd_id128_t boot_id;
+    gchar boot_string[33];
+    gchar *match_string;
 
-        match_string = g_strconcat ("_BOOT_ID=", boot_string, NULL);
+    ret = sd_id128_get_boot (&boot_id);
 
-        ret = sd_journal_add_match (journal, match_string, 0);
-
-        if (ret < 0)
-        {
-            g_warning ("Error adding match '%s': %s", match_string,
-                       g_strerror (-ret));
-        }
-
-        g_free (match_string);
-
-        ret = sd_journal_seek_head (journal);
+    if (ret < 0)
+    {
+        g_warning ("Error getting boot ID of running kernel: %s",
+                   g_strerror (-ret));
+    }
 
-        if (ret < 0)
-        {
-            g_warning ("Error seeking to start of systemd journal: %s",
-                       g_strerror (-ret));
-        }
+    sd_id128_to_string (boot_id, boot_string);
 
-        do
-        {
-            GlJournalResult *result;
+    match_string = g_strconcat ("_BOOT_ID=", boot_string, NULL);
 
-            ret = sd_journal_next (journal);
+    ret = sd_journal_add_match (journal, match_string, 0);
 
-            if (ret < 0)
-            {
-                g_warning ("Error setting cursor to next position in systemd journal: %s",
-                           g_strerror (-ret));
-                break;
-            }
-            else if (ret == 0)
-            {
-                g_debug ("End of systemd journal reached");
-                break;
-            }
+    if (ret < 0)
+    {
+        g_warning ("Error adding match '%s': %s", match_string,
+                   g_strerror (-ret));
+    }
 
-            if (!gl_journal_query_match (journal, query))
-                continue;
+    g_free (match_string);
 
-            result = _gl_journal_query_result (self);
+    ret = sd_journal_seek_head (journal);
 
-            results = g_list_prepend (results, result);
-        } while (TRUE);
+    if (ret < 0)
+    {
+        g_warning ("Error seeking to start of systemd journal: %s",
+                   g_strerror (-ret));
     }
-    else
+
+    do
     {
-        /* Take the given number of events from the end of the journal
-         * backwards. */
-        ret = sd_journal_seek_tail (journal);
+        GlJournalResult *result;
+
+        ret = sd_journal_next (journal);
 
         if (ret < 0)
         {
-            g_warning ("Error seeking to end of systemd journal: %s",
+            g_warning ("Error setting cursor to next position in systemd journal: %s",
                        g_strerror (-ret));
+            break;
         }
-
-        for (i = 0; i < query->n_results; i++)
+        else if (ret == 0)
         {
-            GlJournalResult *result;
-
-            ret = sd_journal_previous (journal);
-
-            if (ret < 0)
-            {
-                g_warning ("Error setting cursor to end of systemd journal: %s",
-                           g_strerror (-ret));
-                break;
-            }
-            else if (ret == 0)
-            {
-                g_debug ("End of systemd journal reached");
-                break;
-            }
-
-            if (!gl_journal_query_match (journal, query))
-                continue;
-
-            result = _gl_journal_query_result (self);
+            g_debug ("End of systemd journal reached");
+            break;
+        }
 
-            results = g_list_prepend (results, result);
+        if (!gl_journal_query_match (journal, query))
             continue;
-        }
 
-        results = g_list_reverse (results);
-    }
+        result = _gl_journal_query_result (self);
+
+        results = g_list_prepend (results, result);
+    } while (TRUE);
 
     sd_journal_flush_matches (journal);
 
diff --git a/src/gl-journal.h b/src/gl-journal.h
index f4210b5..840cc28 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -44,7 +44,6 @@ GQuark gl_journal_error_quark (void);
 
 typedef struct
 {
-    gssize n_results;
     gchar **matches;
 } GlJournalQuery;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]