[gnome-logs] query: turn into simply strv



commit d916516ebf9707896ad03193f0bf111c287e4b54
Author: Lars Uebernickel <lars uebernic de>
Date:   Sat Feb 14 19:42:03 2015 +0100

    query: turn into simply strv

 src/gl-eventviewlist.c |   43 +++++++++++-------------
 src/gl-journal.c       |   83 ++++++++++++-----------------------------------
 src/gl-journal.h       |    9 +----
 3 files changed, 43 insertions(+), 92 deletions(-)
---
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index e1a6366..15cafc9 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -393,29 +393,26 @@ static void
 gl_event_view_list_add_listbox_important (GlEventViewList *view)
 {
     /* Alert or emergency priority. */
-    const GlJournalQuery query = { (gchar*[5]){ "PRIORITY=0",
-                                                "PRIORITY=1",
-                                                "PRIORITY=2",
-                                                "PRIORITY=3",
-                                                NULL } };
+    const gchar * query[] = { "PRIORITY=0", "PRIORITY=1", "PRIORITY=2", "PRIORITY=3", NULL };
+
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
     priv->current_row_style = GL_EVENT_VIEW_ROW_STYLE_CMDLINE;
 
-    gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+    gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
 }
 
 static void
 gl_event_view_list_add_listbox_all (GlEventViewList *view)
 {
-    const GlJournalQuery query = { NULL };
+    const gchar *query[] = { NULL };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
     priv->current_row_style = GL_EVENT_VIEW_ROW_STYLE_CMDLINE;
 
-    gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+    gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
 }
 
 static void
@@ -439,23 +436,23 @@ gl_event_view_list_add_listbox_applications (GlEventViewList *view)
         uid_str = g_strdup_printf ("_UID=%d", uid);
 
         {
-            GlJournalQuery query = { (gchar *[5]){ "_TRANSPORT=journal",
-                                                   "_TRANSPORT=stdout",
-                                                   "_TRANSPORT=syslog",
-                                                   uid_str, NULL } };
+            const gchar *query[] = { "_TRANSPORT=journal",
+                                     "_TRANSPORT=stdout",
+                                     "_TRANSPORT=syslog",
+                                     uid_str, NULL };
 
-            gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+            gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
         }
 
         g_free (uid_str);
     }
     else
     {
-        GlJournalQuery query = { (gchar *[4]){ "_TRANSPORT=journal",
-                                               "_TRANSPORT=stdout",
-                                               "_TRANSPORT=syslog", NULL } };
+        const gchar *query[] = { "_TRANSPORT=journal",
+                                 "_TRANSPORT=stdout",
+                                 "_TRANSPORT=syslog", NULL };
 
-        gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+        gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
     }
 
     g_object_unref (creds);
@@ -464,37 +461,37 @@ gl_event_view_list_add_listbox_applications (GlEventViewList *view)
 static void
 gl_event_view_list_add_listbox_system (GlEventViewList *view)
 {
-    GlJournalQuery query = { (gchar *[2]){ "_TRANSPORT=kernel", NULL } };
+    const gchar *query[] = { "_TRANSPORT=kernel", NULL };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
     priv->current_row_style = GL_EVENT_VIEW_ROW_STYLE_SIMPLE;
 
-    gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+    gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
 }
 
 static void
 gl_event_view_list_add_listbox_hardware (GlEventViewList *view)
 {
-    GlJournalQuery query = { (gchar *[3]){ "_TRANSPORT=kernel", "_KERNEL_DEVICE", NULL } };
+    const gchar *query[] = { "_TRANSPORT=kernel", "_KERNEL_DEVICE", NULL };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
     priv->current_row_style = GL_EVENT_VIEW_ROW_STYLE_SIMPLE;
 
-    gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+    gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
 }
 
 static void
 gl_event_view_list_add_listbox_security (GlEventViewList *view)
 {
-    const GlJournalQuery query = { (gchar *[2]){ "_AUDIT_SESSION", NULL } };
+    const gchar *query[] = { "_AUDIT_SESSION", NULL };
     GlEventViewListPrivate *priv;
 
     priv = gl_event_view_list_get_instance_private (view);
     priv->current_row_style = GL_EVENT_VIEW_ROW_STYLE_CMDLINE;
 
-    gl_journal_query_async (priv->journal, &query, NULL, query_ready, view);
+    gl_journal_query_async (priv->journal, query, NULL, query_ready, view);
 }
 
 static void
diff --git a/src/gl-journal.c b/src/gl-journal.c
index f44cae6..0191e7c 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -310,58 +310,21 @@ out:
     return NULL;
 }
 
-static GlJournalQuery *
-gl_journal_query_copy (const GlJournalQuery *source)
-{
-    GlJournalQuery *result;
-    guint n_matches = 0;
-    gchar **matches;
-    guint i;
-
-    result = g_slice_new (GlJournalQuery);
-
-    if (source->matches)
-    {
-        n_matches = g_strv_length (source->matches);
-    }
-
-    /* Remember the trailing NULL. */
-    matches = g_new (gchar *, n_matches + 1);
-
-    for (i = 0; i < n_matches; i++)
-    {
-        matches[i] = g_strdup (source->matches[i]);
-    }
-
-    matches[n_matches] = NULL;
-
-    result->matches = matches;
-
-    return result;
-}
-
-static void
-gl_journal_query_free (GlJournalQuery *query)
-{
-    g_strfreev (query->matches);
-    g_slice_free (GlJournalQuery, query);
-}
-
 void
 gl_journal_query_async (GlJournal *self,
-                        const GlJournalQuery *query,
+                        const gchar * const *query,
                         GCancellable *cancellable,
                         GAsyncReadyCallback callback,
                         gpointer user_data)
 {
     GTask *task;
-    GlJournalQuery *data;
+    gchar **data;
     GList *results;
 
-    data = gl_journal_query_copy (query);
+    data = g_strdupv ((gchar **) query);
 
     task = g_task_new (self, cancellable, callback, user_data);
-    g_task_set_task_data (task, data, (GDestroyNotify) gl_journal_query_free);
+    g_task_set_task_data (task, data, (GDestroyNotify) g_strfreev);
 
     results = gl_journal_query (self, query);
     g_task_return_pointer (task, results, (GDestroyNotify) gl_journal_results_free);
@@ -391,22 +354,22 @@ gl_journal_query_finish (GlJournal *self,
  * Returns: %TRUE if the current log entry contains all fields in @query
  */
 static gboolean
-gl_journal_query_match (sd_journal           *journal,
-                        const GlJournalQuery *query)
+gl_journal_query_match (sd_journal          *journal,
+                        const gchar * const *query)
 {
   gint i;
 
-  for (i = 0; query->matches[i]; i++)
+  for (i = 0; query[i]; i++)
   {
       int r;
       const void *data;
       size_t len;
 
       /* don't check fields that match on a value */
-      if (strchr (query->matches[i], '='))
+      if (strchr (query[i], '='))
           continue;
 
-      r = sd_journal_get_data (journal, query->matches[i], &data, &len);
+      r = sd_journal_get_data (journal, query[i], &data, &len);
 
       if (r == -ENOENT) /* field doesn't exist */
           return FALSE;
@@ -419,7 +382,8 @@ gl_journal_query_match (sd_journal           *journal,
 }
 
 GList *
-gl_journal_query (GlJournal *self, const GlJournalQuery *query)
+gl_journal_query (GlJournal           *self,
+                  const gchar * const *query)
 {
     GlJournalPrivate *priv;
     sd_journal *journal;
@@ -433,24 +397,19 @@ gl_journal_query (GlJournal *self, const GlJournalQuery *query)
     priv = gl_journal_get_instance_private (self);
     journal = priv->journal;
 
-    if (query->matches)
-    {
-        const gchar *match;
 
-        for (i = 0, match = query->matches[i]; match;
-             match = query->matches[++i])
-        {
-            /* don't add fields of which we only want to check existance */
-            if (strchr (match, '=') == NULL)
-                continue;
+    for (i = 0; query[i]; i++)
+    {
+        /* don't add fields of which we only want to check existance */
+        if (strchr (query[i], '=') == NULL)
+            continue;
 
-            ret = sd_journal_add_match (journal, match, 0);
+        ret = sd_journal_add_match (journal, query[i], 0);
 
-            if (ret < 0)
-            {
-                g_warning ("Error adding match '%s': %s", match,
-                           g_strerror (-ret));
-            }
+        if (ret < 0)
+        {
+            g_warning ("Error adding match '%s': %s", query[i],
+                       g_strerror (-ret));
         }
     }
 
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 840cc28..e286247 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -44,11 +44,6 @@ GQuark gl_journal_error_quark (void);
 
 typedef struct
 {
-    gchar **matches;
-} GlJournalQuery;
-
-typedef struct
-{
     /*< private >*/
     guint ref_count;
 
@@ -81,9 +76,9 @@ typedef struct
 
 GType gl_journal_result_get_type (void);
 GType gl_journal_get_type (void);
-void gl_journal_query_async (GlJournal *self, const GlJournalQuery *query, GCancellable *cancellable, 
GAsyncReadyCallback callback, gpointer user_data);
+void gl_journal_query_async (GlJournal *self, const gchar * const *query, GCancellable *cancellable, 
GAsyncReadyCallback callback, gpointer user_data);
 GList * gl_journal_query_finish (GlJournal *self, GAsyncResult *res, GError **error);
-GList * gl_journal_query (GlJournal *self, const GlJournalQuery *query);
+GList * gl_journal_query (GlJournal *self, const gchar * const *query);
 GlJournalResult * gl_journal_result_ref (GlJournalResult *result);
 void gl_journal_result_unref (GlJournalResult *result);
 void gl_journal_results_free (GList *results);


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