[gnome-logs/wip/field-length: 3/4] Add GlJournalError enum
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/field-length: 3/4] Add GlJournalError enum
- Date: Wed, 23 Oct 2013 19:56:48 +0000 (UTC)
commit 24c427b3d9416f275fb90dc1de08da0a952c27ed
Author: David King <davidk gnome org>
Date: Wed Oct 23 18:53:26 2013 +0100
Add GlJournalError enum
src/gl-journal.c | 25 +++++++++++++++++++++++--
src/gl-journal.h | 19 +++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 998440e..114fdfc 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -31,6 +31,12 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (GlJournal, gl_journal, G_TYPE_OBJECT)
+GQuark
+gl_journal_error_quark (void)
+{
+ return g_quark_from_static_string ("gl-journal-error-quark");
+}
+
static gboolean
on_journal_changed (gint fd,
GIOCondition condition,
@@ -153,10 +159,25 @@ gl_journal_get_data (GlJournal *self,
if (ret < 0)
{
- /* TODO: Use custom GError enumeration. */
- g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
+ gint code;
+
+ switch (-ret)
+ {
+ case ENOENT:
+ code = GL_JOURNAL_ERROR_NO_FIELD;
+ break;
+ case EADDRNOTAVAIL:
+ code = GL_JOURNAL_ERROR_INVALID_POINTER;
+ break;
+ default:
+ code = GL_JOURNAL_ERROR_FAILED;
+ break;
+ }
+
+ g_set_error (error, GL_JOURNAL_ERROR, code,
"Unable to get field ā%sā from systemd journal: %s",
field, g_strerror (-ret));
+
return NULL;
}
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 86febf5..e5e0b06 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -24,6 +24,25 @@
G_BEGIN_DECLS
+/*
+ * GlJournalError:
+ * @GL_JOURNAL_ERROR_NO_FIELD: the requested field was not found in the current
+ * journal entry
+ * @GL_JOURNAL_ERROR_INVALID_POINTER: the pointer to the current journal entry
+ * is not valid
+ * @GL_JOURNAL_ERROR_FAILED: unknown failure
+ */
+typedef enum
+{
+ GL_JOURNAL_ERROR_NO_FIELD,
+ GL_JOURNAL_ERROR_INVALID_POINTER,
+ GL_JOURNAL_ERROR_FAILED
+} GlJournalError;
+
+#define GL_JOURNAL_ERROR gl_journal_error_quark ()
+
+GQuark gl_journal_error_quark (void);
+
typedef struct
{
gsize n_results;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]