[gnome-logs/wip/gl-journal: 3/14] Split off journal to new GlJournal object
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/gl-journal: 3/14] Split off journal to new GlJournal object
- Date: Thu, 3 Oct 2013 12:56:23 +0000 (UTC)
commit 8953cd7d202c789477285b37808db87194154aba
Author: David King <davidk gnome org>
Date: Wed Oct 2 14:38:36 2013 +0100
Split off journal to new GlJournal object
Makefile.am | 2 +
src/gl-eventview.c | 100 ++++------------------------------
src/gl-journal.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gl-journal.h | 48 ++++++++++++++++
4 files changed, 212 insertions(+), 89 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0eb2c36..5a9bcdd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ gnome_logs_SOURCES = \
src/gl-categorylist.c \
src/gl-eventtoolbar.c \
src/gl-eventview.c \
+ src/gl-journal.c \
src/gl-main.c \
src/gl-window.c
@@ -44,6 +45,7 @@ noinst_gnome_logs_headers = \
src/gl-categorylist.h \
src/gl-eventtoolbar.h \
src/gl-eventview.h \
+ src/gl-journal.h \
src/gl-window.h
nodist_gnome_logs_headers = \
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 2ce1629..719af5f 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -25,6 +25,7 @@
#include "gl-enums.h"
#include "gl-eventtoolbar.h"
+#include "gl-journal.h"
enum
{
@@ -36,9 +37,7 @@ enum
typedef struct
{
- sd_journal *journal;
- gint fd;
- guint source_id;
+ GlJournal *journal;
GlEventViewFilter filter;
GtkListBox *active_listbox;
GlEventViewMode mode;
@@ -78,7 +77,7 @@ listbox_search_filter_func (GtkListBoxRow *row,
goto out;
}
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
ret = sd_journal_seek_cursor (journal, cursor);
@@ -163,7 +162,7 @@ on_listbox_row_activated (GtkListBox *listbox,
GtkWidget *toplevel;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
cursor = g_object_get_data (G_OBJECT (row), "cursor");
if (cursor == NULL)
@@ -405,49 +404,12 @@ on_notify_mode (GlEventView *view,
}
}
-static gboolean
-on_journal_changed (gint fd,
- GIOCondition condition,
- GlEventView *view)
-{
- gint ret;
- GlEventViewPrivate *priv = gl_event_view_get_instance_private (view);
-
- ret = sd_journal_process (priv->journal);
-
- switch (ret)
- {
- case SD_JOURNAL_NOP:
- g_debug ("Journal change was a no-op");
- break;
- case SD_JOURNAL_APPEND:
- g_debug ("New journal entries added");
- break;
- case SD_JOURNAL_INVALIDATE:
- g_debug ("Journal files added or removed");
- break;
- default:
- g_warning ("Error processing events from systemd journal: %s",
- g_strerror (-ret));
- break;
- }
-
- return G_SOURCE_CONTINUE;
-}
-
static void
gl_event_view_finalize (GObject *object)
{
GlEventView *view = GL_EVENT_VIEW (object);
GlEventViewPrivate *priv = gl_event_view_get_instance_private (view);
- g_source_remove (priv->source_id);
-
- if (priv->journal)
- {
- sd_journal_close (priv->journal);
- }
-
g_clear_pointer (&priv->search_text, g_free);
}
@@ -969,7 +931,7 @@ gl_event_view_add_listbox_important (GlEventView *view)
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
/* Alert or emergency priority. */
ret = sd_journal_add_match (journal, "PRIORITY=0", 0);
@@ -1053,7 +1015,7 @@ gl_event_view_add_listbox_applications (GlEventView *view)
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
/* Allow all _TRANSPORT != kernel. */
ret = sd_journal_add_match (journal, "_TRANSPORT=journal", 0);
@@ -1125,7 +1087,7 @@ gl_event_view_add_listbox_system (GlEventView *view)
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
ret = sd_journal_add_match (journal, "_TRANSPORT=kernel", 0);
@@ -1180,7 +1142,7 @@ gl_event_view_add_listbox_hardware (GlEventView *view)
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
ret = sd_journal_add_match (journal, "_TRANSPORT=kernel", 0);
@@ -1235,7 +1197,7 @@ gl_event_view_add_listbox_security (GlEventView *view)
GtkWidget *scrolled;
priv = gl_event_view_get_instance_private (view);
- journal = priv->journal;
+ journal = gl_journal_get_journal (priv->journal);
ret = sd_journal_seek_tail (journal);
@@ -1308,49 +1270,9 @@ gl_event_view_init (GlEventView *view)
gtk_list_box_set_filter_func (GTK_LIST_BOX (listbox),
(GtkListBoxFilterFunc)listbox_search_filter_func,
view, NULL);
- ret = sd_journal_open (&journal, 0);
- priv->journal = journal;
- if (ret < 0)
- {
- g_critical ("Error opening systemd journal: %s", g_strerror (-ret));
- }
-
- ret = sd_journal_get_fd (journal);
-
- if (ret < 0)
- {
- g_warning ("Error getting polling fd from systemd journal: %s",
- g_strerror (-ret));
- }
-
- priv->fd = ret;
- ret = sd_journal_get_events (journal);
-
- if (ret < 0)
- {
- g_warning ("Error getting poll events from systemd journal: %s",
- g_strerror (-ret));
- }
-
- priv->source_id = g_unix_fd_add (priv->fd, ret,
- (GUnixFDSourceFunc) on_journal_changed,
- view);
- ret = sd_journal_reliable_fd (journal);
-
- if (ret < 0)
- {
- g_warning ("Error checking reliability of systemd journal poll fd: %s",
- g_strerror (-ret));
- }
- else if (ret == 0)
- {
- g_debug ("Latency expected while polling for systemd journal activity");
- }
- else
- {
- g_debug ("Immediate wakeups expected for systemd journal activity");
- }
+ priv->journal = gl_journal_new ();
+ journal = gl_journal_get_journal (priv->journal);
ret = sd_journal_seek_tail (journal);
diff --git a/src/gl-journal.c b/src/gl-journal.c
new file mode 100644
index 0000000..26bf9f4
--- /dev/null
+++ b/src/gl-journal.c
@@ -0,0 +1,151 @@
+/*
+ * GNOME Logs - View and search logs
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gl-journal.h"
+
+#include <glib-unix.h>
+
+typedef struct
+{
+ sd_journal *journal;
+ gint fd;
+ guint source_id;
+} GlJournalPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GlJournal, gl_journal, G_TYPE_OBJECT)
+
+static gboolean
+on_journal_changed (gint fd,
+ GIOCondition condition,
+ GlJournal *self)
+{
+ gint ret;
+ GlJournalPrivate *priv = gl_journal_get_instance_private (self);
+
+ ret = sd_journal_process (priv->journal);
+
+ switch (ret)
+ {
+ case SD_JOURNAL_NOP:
+ g_debug ("Journal change was a no-op");
+ break;
+ case SD_JOURNAL_APPEND:
+ g_debug ("New journal entries added");
+ break;
+ case SD_JOURNAL_INVALIDATE:
+ g_debug ("Journal files added or removed");
+ break;
+ default:
+ g_warning ("Error processing events from systemd journal: %s",
+ g_strerror (-ret));
+ break;
+ }
+
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+gl_journal_finalize (GObject *object)
+{
+ GlJournal *journal = GL_JOURNAL (object);
+ GlJournalPrivate *priv = gl_journal_get_instance_private (journal);
+
+ g_source_remove (priv->source_id);
+ g_clear_pointer (&priv->journal, sd_journal_close);
+}
+
+static void
+gl_journal_class_init (GlJournalClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = gl_journal_finalize;
+}
+
+static void
+gl_journal_init (GlJournal *self)
+{
+ GlJournalPrivate *priv;
+ sd_journal *journal;
+ gint ret;
+
+ priv = gl_journal_get_instance_private (self);
+
+ ret = sd_journal_open (&journal, 0);
+ priv->journal = journal;
+
+ if (ret < 0)
+ {
+ g_critical ("Error opening systemd journal: %s", g_strerror (-ret));
+ }
+
+ ret = sd_journal_get_fd (journal);
+
+ if (ret < 0)
+ {
+ g_warning ("Error getting polling fd from systemd journal: %s",
+ g_strerror (-ret));
+ }
+
+ priv->fd = ret;
+ ret = sd_journal_get_events (journal);
+
+ if (ret < 0)
+ {
+ g_warning ("Error getting poll events from systemd journal: %s",
+ g_strerror (-ret));
+ }
+
+ priv->source_id = g_unix_fd_add (priv->fd, ret,
+ (GUnixFDSourceFunc) on_journal_changed,
+ self);
+ ret = sd_journal_reliable_fd (journal);
+
+ if (ret < 0)
+ {
+ g_warning ("Error checking reliability of systemd journal poll fd: %s",
+ g_strerror (-ret));
+ }
+ else if (ret == 0)
+ {
+ g_debug ("Latency expected while polling for systemd journal activity");
+ }
+ else
+ {
+ g_debug ("Immediate wakeups expected for systemd journal activity");
+ }
+
+}
+
+sd_journal *
+gl_journal_get_journal (GlJournal *self)
+{
+ GlJournalPrivate *priv;
+
+ g_return_val_if_fail (GL_JOURNAL (self), NULL);
+
+ priv = gl_journal_get_instance_private (self);
+
+ return priv->journal;
+}
+
+GlJournal *
+gl_journal_new (void)
+{
+ return g_object_new (GL_TYPE_JOURNAL, NULL);
+}
diff --git a/src/gl-journal.h b/src/gl-journal.h
new file mode 100644
index 0000000..3c54706
--- /dev/null
+++ b/src/gl-journal.h
@@ -0,0 +1,48 @@
+/*
+ * GNOME Logs - View and search logs
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GL_JOURNAL_H_
+#define GL_JOURNAL_H_
+
+#include <glib-object.h>
+#include <systemd/sd-journal.h>
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+ /*< private >*/
+ GObject parent_instance;
+} GlJournal;
+
+typedef struct
+{
+ /*< private >*/
+ GObjectClass parent_class;
+} GlJournalClass;
+
+#define GL_TYPE_JOURNAL (gl_journal_get_type ())
+#define GL_JOURNAL(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_JOURNAL, GlJournal))
+
+GType gl_journal_get_type (void);
+sd_journal * gl_journal_get_journal (GlJournal *self);
+GlJournal * gl_journal_new (void);
+
+G_END_DECLS
+
+#endif /* GL_JOURNAL_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]