[gom] gom: Add GomError enum as a single unified error domain



commit 063c490d181bfbf958b766e23cd7cf6d3f21544f
Author: Tristan Brindle <t c brindle gmail com>
Date:   Sat Apr 19 00:50:32 2014 +0800

    gom: Add GomError enum as a single unified error domain
    
    Adds GomError as a single error domain replacing GomCommandError,
    GomResourceError etc. The enumerators are taken from the existing
    four error domains used in Gom.
    
    This also adds a gom_error_get_type() function to define a GType
    for GomError, which is necessary for introspection purposes. It
    might be better to use glib-mkenums for this purpose.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728491

 gom/Makefile.include |    2 ++
 gom/gom-error.c      |   45 +++++++++++++++++++++++++++++++++++++++++++++
 gom/gom-error.h      |   44 ++++++++++++++++++++++++++++++++++++++++++++
 gom/gom.h            |    1 +
 4 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/gom/Makefile.include b/gom/Makefile.include
index 302f441..1915c7f 100644
--- a/gom/Makefile.include
+++ b/gom/Makefile.include
@@ -10,6 +10,7 @@ INST_H_FILES += $(top_srcdir)/gom/gom-adapter.h
 INST_H_FILES += $(top_srcdir)/gom/gom-command-builder.h
 INST_H_FILES += $(top_srcdir)/gom/gom-command.h
 INST_H_FILES += $(top_srcdir)/gom/gom-cursor.h
+INST_H_FILES += $(top_srcdir)/gom/gom-error.h
 INST_H_FILES += $(top_srcdir)/gom/gom-filter.h
 INST_H_FILES += $(top_srcdir)/gom/gom-repository.h
 INST_H_FILES += $(top_srcdir)/gom/gom-resource-group.h
@@ -24,6 +25,7 @@ libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-adapter.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-command-builder.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-command.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-cursor.c
+libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-error.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-filter.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-repository.c
 libgom_1_0_la_SOURCES += $(top_srcdir)/gom/gom-resource.c
diff --git a/gom/gom-error.c b/gom/gom-error.c
new file mode 100644
index 0000000..44c78a1
--- /dev/null
+++ b/gom/gom-error.c
@@ -0,0 +1,45 @@
+/* gom-error.c
+ *
+ * Copyright (C) 2014 Christian Hergert <chris dronelabs com>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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 "gom-error.h"
+
+
+G_DEFINE_QUARK("gom-error-quark", gom_error)
+
+GType
+gom_error_get_type (void)
+{
+   static GType g_type = 0;
+   static gsize initialized = FALSE;
+   static const GEnumValue values[] = {
+       { GOM_ERROR_ADAPTER_OPEN, "GOM_ERROR_ADAPTER_OPEN", "ADAPTER_OPEN" },
+       { GOM_ERROR_COMMAND_NO_SQL, "GOM_ERROR_COMMAND_NO_SQL", "COMMAND_NO_SQL" },
+       { GOM_ERROR_COMMAND_SQLITE, "GOM_ERROR_COMMAND_SQLITE", "COMMAND_SQLITE" },
+       { GOM_ERROR_REPOSITORY_EMPTY_RESULT, "GOM_ERROR_REPOSITORY_EMPTY_RESULT",
+           "REPOSITORY_EMPTY_RESULT" },
+       { GOM_ERROR_RESOURCE_CURSOR, "GOM_ERROR_RESOURCE_CURSOR", "RESOURCE_CURSOR" },
+       { 0 }
+   };
+
+   if (g_once_init_enter(&initialized)) {
+      g_type = g_enum_register_static("GomError", values);
+      g_once_init_leave(&initialized, TRUE);
+   }
+
+   return g_type;
+}
diff --git a/gom/gom-error.h b/gom/gom-error.h
new file mode 100644
index 0000000..8f8a404
--- /dev/null
+++ b/gom/gom-error.h
@@ -0,0 +1,44 @@
+/* gom-filter.h
+ *
+ * Copyright (C) 2014 Christian Hergert <chris dronelabs com>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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 GOM_ERROR_H
+#define GOM_ERROR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GOM_ERROR                  (gom_error_quark())
+
+typedef enum _GomError GomError;
+
+enum _GomError
+{
+    GOM_ERROR_ADAPTER_OPEN,
+    GOM_ERROR_COMMAND_NO_SQL,
+    GOM_ERROR_COMMAND_SQLITE,
+    GOM_ERROR_REPOSITORY_EMPTY_RESULT,
+    GOM_ERROR_RESOURCE_CURSOR
+};
+
+GQuark    gom_error_quark    (void) G_GNUC_CONST;
+GType     gom_error_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif
diff --git a/gom/gom.h b/gom/gom.h
index 8c94a4a..35bfb6e 100644
--- a/gom/gom.h
+++ b/gom/gom.h
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
 #include "gom-command.h"
 #include "gom-command-builder.h"
 #include "gom-cursor.h"
+#include "gom-error.h"
 #include "gom-filter.h"
 #include "gom-repository.h"
 #include "gom-resource-group.h"


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