[virt-tools-list] [virt-viewer 03/20] Register oVirt enums with the glib type system

Christophe Fergeau cfergeau at redhat.com
Wed Jun 13 12:23:11 UTC 2012


---
 configure.ac                    |    5 +++++
 src/Makefile.am                 |   39 +++++++++++++++++++++++++++++++++++++--
 src/ovirt-enum-types.c.template |   39 +++++++++++++++++++++++++++++++++++++++
 src/ovirt-enum-types.h.template |   24 ++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 src/ovirt-enum-types.c.template
 create mode 100644 src/ovirt-enum-types.h.template

diff --git a/configure.ac b/configure.ac
index 59039cf..0c9557a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,11 @@ IT_PROG_INTLTOOL([0.35.0])
 
 
 PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_REQUIRED gthread-2.0 gmodule-export-2.0)
+
+# Setup GLIB_MKENUMS to use glib-mkenums even if GLib is uninstalled.
+GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
+AC_SUBST(GLIB_MKENUMS)
+
 PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED)
 
 AC_ARG_WITH([libvirt],
diff --git a/src/Makefile.am b/src/Makefile.am
index f76024c..356609c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,9 +39,34 @@ COMMON_SOURCES +=						\
 endif
 
 if HAVE_OVIRT
-COMMON_SOURCES +=						\
-	ovirt-rest-call.h ovirt-rest-call.c			\
+EXTRA_DIST +=
+	ovirt-enum-types.h.template	\
+	ovirt-enum-types.c.template	\
+	$(NULL)
+
+BUILT_SOURCES =				\
+	ovirt-enum-types.h		\
+	ovirt-enum-types.c		\
+	$(NULL)
+
+CLEANFILES = $(BUILT_SOURCES)
+
+OVIRT_HEADER_FILES =			\
+	ovirt-rest-call.h		\
+	$(NULL)
+
+COMMON_SOURCES +=			\
+	ovirt-rest-call.c		\
+	$(OVIRT_HEADER_FILES)		\
 	$(NULL)
+
+ovirt-enum-types.h: $(OVIRT_HEADER_FILES) ovirt-enum-types.h.template
+	$(AM_V_GEN) ( $(GLIB_MKENUMS) --template $(srcdir)/ovirt-enum-types.h.template $(OVIRT_HEADER_FILES:%=$(srcdir)/%) ) \
+	    > ovirt-enum-types.h
+
+ovirt-enum-types.c: $(OVIRT_HEADER_FILES) ovirt-enum-types.h ovirt-enum-types.c.template
+	$(AM_V_GEN) ( $(GLIB_MKENUMS) --template $(srcdir)/ovirt-enum-types.c.template $(OVIRT_HEADER_FILES:%=$(srcdir)/%) ) \
+	    > ovirt-enum-types.c
 endif
 
 if HAVE_SPICE_GTK
@@ -82,6 +107,11 @@ virt_viewer_LDFLAGS += $(GTK_VNC_LIBS)
 virt_viewer_CFLAGS += $(GTK_VNC_CFLAGS)
 endif
 if HAVE_OVIRT
+nodist_virt_viewer_SOURCES =		\
+	$(builddir)/ovirt-enum-types.h	\
+	$(builddir)/ovirt-enum-types.c	\
+	$(NULL)
+
 virt_viewer_LDFLAGS += $(OVIRT_LIBS)
 virt_viewer_CFLAGS += $(OVIRT_CFLAGS)
 endif
@@ -118,6 +148,11 @@ remote_viewer_LDFLAGS += $(GTK_VNC_LIBS)
 remote_viewer_CFLAGS += $(GTK_VNC_CFLAGS)
 endif
 if HAVE_OVIRT
+nodist_remote_viewer_SOURCES =		\
+	$(builddir)/ovirt-enum-types.h	\
+	$(builddir)/ovirt-enum-types.c	\
+	$(NULL)
+
 remote_viewer_LDFLAGS += $(OVIRT_LIBS)
 remote_viewer_CFLAGS += $(OVIRT_CFLAGS)
 endif
diff --git a/src/ovirt-enum-types.c.template b/src/ovirt-enum-types.c.template
new file mode 100644
index 0000000..7ab626b
--- /dev/null
+++ b/src/ovirt-enum-types.c.template
@@ -0,0 +1,39 @@
+/*** BEGIN file-header ***/
+#include "ovirt-enum-types.h"
+#include "ovirt-proxy.h"
+#include "ovirt-rest-call.h"
+#include "ovirt-vm-display.h"
+#include "ovirt-vm.h"
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ at enum_name@_get_type (void)
+{
+  static volatile gsize g_define_type_id__volatile = 0;
+
+  if (g_once_init_enter (&g_define_type_id__volatile))
+    {
+      static const G at Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+        { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+        { 0, NULL, NULL }
+      };
+      GType g_define_type_id =
+        g_ at type@_register_static (g_intern_static_string ("@EnumName@"), values);
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+    }
+
+  return g_define_type_id__volatile;
+}
+
+/*** END value-tail ***/
diff --git a/src/ovirt-enum-types.h.template b/src/ovirt-enum-types.h.template
new file mode 100644
index 0000000..54147e1
--- /dev/null
+++ b/src/ovirt-enum-types.h.template
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+#ifndef __OVIRT_ENUM_TYPES_H__
+#define __OVIRT_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name at _get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX at _TYPE_@ENUMSHORT@ (@enum_name at _get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __OVIRT_ENUM_TYPES_H__ */
+/*** END file-tail ***/
-- 
1.7.10.2




More information about the virt-tools-list mailing list