[at-spi2-core] Clean up enums



commit a12d7458110c57e183916255d701b1e0d7c070e1
Author: Mike Gorse <mgorse novell com>
Date:   Tue May 24 16:24:09 2011 -0500

    Clean up enums
    
    Use glib-enums to generate GTypes for enums, and modify enum definitions so
    that they will be marked as bitflags where appropriate.  This helps with
    introspection and allows functions that take flags to be prototyped as such
    rather than being marked as taking a gint.

 atspi/Makefile.am                 |   15 +++++++++++++-
 atspi/atspi-accessible.c          |    2 +-
 atspi/atspi-constants.h           |   16 +++++++-------
 atspi/atspi-enum-types.c.template |   39 +++++++++++++++++++++++++++++++++++++
 atspi/atspi-enum-types.h.template |   27 +++++++++++++++++++++++++
 atspi/atspi-registry.c            |    3 +-
 atspi/atspi-registry.h            |    3 +-
 atspi/atspi-types.h               |    6 ++--
 configure.ac                      |    2 +
 9 files changed, 98 insertions(+), 15 deletions(-)
---
diff --git a/atspi/Makefile.am b/atspi/Makefile.am
index 8a26430..4d38ee4 100644
--- a/atspi/Makefile.am
+++ b/atspi/Makefile.am
@@ -48,6 +48,7 @@ atspi-gmain.h \
 	atspi-value.h
 
 libatspi_la_SOURCES =		\
+	$(BUILT_SOURCES) \
 	$(libatspiinclude_HEADERS) \
 	atspi.h	\
 	atspi-accessible.c \
@@ -102,13 +103,25 @@ libatspi_la_SOURCES =		\
 	atspi-value.c \
 	atspi-value.h
 
-#BUILT_SOURCES = atspi-constants.h
+BUILT_SOURCES = \
+	atspi-enum-types.c \
+	atspi-enum-types.h
 
 #CLEANFILES = atspi-constants.h
 
 #atspi-constants.h: $(top_srcdir)/xml/spec.xml $(top_srcdir)/tools/c-constants-gen.py
 #	python $(top_srcdir)/tools/c-constants-gen.py Atspi $(top_srcdir)/xml/spec.xml atspi-constants
 
+ENUM_TYPES = \
+	atspi-constants.h \
+	atspi-types.h
+
+atspi-enum-types.h: atspi-enum-types.h.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template atspi-enum-types.h.template $(ENUM_TYPES)) > $@
+
+atspi-enum-types.c: atspi-enum-types.c.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template atspi-enum-types.c.template $(ENUM_TYPES)) > $@
+
 if HAVE_INTROSPECTION
 INTROSPECTION_FILES = $(libatspi_la_SOURCES)
 
diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c
index 90acb55..6784607 100644
--- a/atspi/atspi-accessible.c
+++ b/atspi/atspi-accessible.c
@@ -1376,7 +1376,7 @@ atspi_accessible_new (AtspiApplication *app, const gchar *path)
  *
  * @accessible: The #AtspiAccessible to operate on.  Must be the desktop or
  *             the root of an application.
- * @mask: (type int): An #AtspiCache specifying a bit mask of the types of data to cache.
+ * @mask: An #AtspiCache specifying a bit mask of the types of data to cache.
  *
  * Sets the type of data to cache for accessibles.
  * If this is not set for an application or is reset to ATSPI_CACHE_UNDEFINED,
diff --git a/atspi/atspi-constants.h b/atspi/atspi-constants.h
index d69a84d..4b857d7 100644
--- a/atspi/atspi-constants.h
+++ b/atspi/atspi-constants.h
@@ -761,14 +761,14 @@ typedef enum {
 
 typedef enum
 {
-     ATSPI_CACHE_NONE     = 0x0000,
-     ATSPI_CACHE_PARENT   = 0x0001,
-  ATSPI_CACHE_CHILDREN    = 0x0002,
-  ATSPI_CACHE_NAME        = 0x0004,
-  ATSPI_CACHE_DESCRIPTION = 0x0008,
-  ATSPI_CACHE_STATES      = 0x0010,
-  ATSPI_CACHE_ROLE        = 0x0020,
-  ATSPI_CACHE_INTERFACES  = 0x0040,
+     ATSPI_CACHE_NONE     = 0,
+     ATSPI_CACHE_PARENT   = 1 << 0,
+  ATSPI_CACHE_CHILDREN    = 1 << 1,
+  ATSPI_CACHE_NAME        = 1 << 2,
+  ATSPI_CACHE_DESCRIPTION = 1 << 3,
+  ATSPI_CACHE_STATES      = 1 << 4,
+  ATSPI_CACHE_ROLE        = 1 << 5,
+  ATSPI_CACHE_INTERFACES  = 1 << 6,
   ATSPI_CACHE_ALL         = 0x3fffffff,
   ATSPI_CACHE_UNDEFINED   = 0x40000000
 } AtspiCache;
diff --git a/atspi/atspi-enum-types.c.template b/atspi/atspi-enum-types.c.template
new file mode 100644
index 0000000..cd92f99
--- /dev/null
+++ b/atspi/atspi-enum-types.c.template
@@ -0,0 +1,39 @@
+/*** BEGIN file-header ***/
+#include "atspi-enum-types.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+#include "@filename@"
+
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ enum_name@_get_type (void)
+{
+	static GType the_type = 0;
+	
+	if (the_type == 0)
+	{
+		static const G Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+			{ @VALUENAME@,
+			  "@VALUENAME@",
+			  "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+			{ 0, NULL, NULL }
+		};
+		the_type = g_ type@_register_static (
+				g_intern_static_string ("@EnumName@"),
+				values);
+	}
+	return the_type;
+}
+
+/*** END value-tail ***/
diff --git a/atspi/atspi-enum-types.h.template b/atspi/atspi-enum-types.h.template
new file mode 100644
index 0000000..bd297b5
--- /dev/null
+++ b/atspi/atspi-enum-types.h.template
@@ -0,0 +1,27 @@
+/*** BEGIN file-header ***/
+#ifndef __ATSPI_ENUM_TYPES_H__
+#define __ATSPI_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* Enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+/*** BEGIN enumeration-production ***/
+#define ATSPI_TYPE_ ENUMSHORT@	(@enum_name _get_type())
+GType @enum_name _get_type	(void) G_GNUC_CONST;
+
+/*** END enumeration-production ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __ATSPI_ENUM_TYPES_H__ */
+/*** END file-tail ***/
+
diff --git a/atspi/atspi-registry.c b/atspi/atspi-registry.c
index 9856be3..51392d0 100644
--- a/atspi/atspi-registry.c
+++ b/atspi/atspi-registry.c
@@ -119,7 +119,8 @@ atspi_register_keystroke_listener (AtspiDeviceListener  *listener,
 					 GArray             *key_set,
 					 AtspiKeyMaskType         modmask,
 					 AtspiKeyEventMask        event_types,
-					 gint sync_type, GError **error)
+					 AtspiKeyListenerSyncType sync_type,
+                                         GError **error)
 {
   GArray *d_key_set;
   gchar *path = _atspi_device_listener_get_path (listener);
diff --git a/atspi/atspi-registry.h b/atspi/atspi-registry.h
index 03086dc..f8bf42f 100644
--- a/atspi/atspi-registry.h
+++ b/atspi/atspi-registry.h
@@ -42,7 +42,8 @@ atspi_register_keystroke_listener (AtspiDeviceListener  *listener,
 					 GArray *key_set,
 					 AtspiKeyMaskType         modmask,
 					 AtspiKeyEventMask        event_types,
-					 gint sync_type, GError **error);
+					 AtspiKeyListenerSyncType sync_type,
+                                         GError **error);
 
 gboolean
 atspi_deregister_keystroke_listener (AtspiDeviceListener *listener,
diff --git a/atspi/atspi-types.h b/atspi/atspi-types.h
index e56f93f..4e8dc1a 100644
--- a/atspi/atspi-types.h
+++ b/atspi/atspi-types.h
@@ -143,8 +143,8 @@ typedef struct _AtspiKeySet
  **/
 typedef enum {
   ATSPI_KEYLISTENER_NOSYNC = 0,
-  ATSPI_KEYLISTENER_SYNCHRONOUS = 1,
-  ATSPI_KEYLISTENER_CANCONSUME = 2,
-  ATSPI_KEYLISTENER_ALL_WINDOWS = 4
+  ATSPI_KEYLISTENER_SYNCHRONOUS = 1 << 0,
+  ATSPI_KEYLISTENER_CANCONSUME = 1 << 1,
+  ATSPI_KEYLISTENER_ALL_WINDOWS = 1 << 2
 } AtspiKeyListenerSyncType;
 #endif	/* _ATSPI_TYPES_H_ */
diff --git a/configure.ac b/configure.ac
index b3374be..fc0c93d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,6 +171,8 @@ else
 fi
 AC_SUBST(DBUS_SERVICES_DIR)
 
+AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
+
 GOBJECT_INTROSPECTION_CHECK([0.9.6])
 
 AC_SUBST(LIBTOOL_EXPORT_OPTIONS)



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