evince r3379 - in trunk: . libdocument



Author: carlosgc
Date: Sat Jan 24 18:10:33 2009
New Revision: 3379
URL: http://svn.gnome.org/viewvc/evince?rev=3379&view=rev

Log:
2009-01-24  Carlos Garcia Campos  <carlosgc gnome org>

	* libdocument/ev-document.h:

	Add EV_DEFINE_INTERFACE macro.

	* libdocument/ev-async-renderer.c:
	* libdocument/ev-document-find.c:
	* libdocument/ev-document-fonts.c:
	* libdocument/ev-document-forms.c:
	* libdocument/ev-document-images.c:
	* libdocument/ev-document-layers.c:
	* libdocument/ev-document-links.c:
	* libdocument/ev-document-security.c:
	* libdocument/ev-document-thumbnails.c:
	* libdocument/ev-document-transition.c:
	* libdocument/ev-document.c:
	* libdocument/ev-file-exporter.c:
	* libdocument/ev-selection.c:

	Use EV_DEFINE_INTERFACE macro to define interfaces in
	libdocument. See bug #568228.

Modified:
   trunk/ChangeLog
   trunk/libdocument/ev-async-renderer.c
   trunk/libdocument/ev-document-find.c
   trunk/libdocument/ev-document-fonts.c
   trunk/libdocument/ev-document-forms.c
   trunk/libdocument/ev-document-images.c
   trunk/libdocument/ev-document-layers.c
   trunk/libdocument/ev-document-links.c
   trunk/libdocument/ev-document-security.c
   trunk/libdocument/ev-document-thumbnails.c
   trunk/libdocument/ev-document-transition.c
   trunk/libdocument/ev-document.c
   trunk/libdocument/ev-document.h
   trunk/libdocument/ev-file-exporter.c
   trunk/libdocument/ev-selection.c

Modified: trunk/libdocument/ev-async-renderer.c
==============================================================================
--- trunk/libdocument/ev-async-renderer.c	(original)
+++ trunk/libdocument/ev-async-renderer.c	Sat Jan 24 18:10:33 2009
@@ -21,8 +21,7 @@
 #include "config.h"
 
 #include "ev-async-renderer.h"
-
-static void ev_async_renderer_class_init (gpointer g_class);
+#include "ev-document.h"
 
 enum
 {
@@ -32,42 +31,26 @@
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-GType
-ev_async_renderer_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvAsyncRendererIface),
-			NULL,
-			NULL,
-			(GClassInitFunc)ev_async_renderer_class_init
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvAsyncRenderer",
-					       &our_info, (GTypeFlags)0);
-	}
-
-	return type;
-}
+EV_DEFINE_INTERFACE (EvAsyncRenderer, ev_async_renderer, 0)
 
 static void
-ev_async_renderer_class_init (gpointer g_class)
+ev_async_renderer_class_init (EvAsyncRendererIface *klass)
 {
-	signals[RENDER_FINISHED] =
-		g_signal_new ("render_finished",
-			      EV_TYPE_ASYNC_RENDERER,
-			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (EvAsyncRendererIface, render_finished),
-			      NULL, NULL,
-			      g_cclosure_marshal_VOID__OBJECT,
-			      G_TYPE_NONE,
-			      1,
-			      GDK_TYPE_PIXBUF);
+	static gboolean initialized = FALSE;
+
+	if (!initialized) {
+		signals[RENDER_FINISHED] =
+			g_signal_new ("render_finished",
+				      EV_TYPE_ASYNC_RENDERER,
+				      G_SIGNAL_RUN_LAST,
+				      G_STRUCT_OFFSET (EvAsyncRendererIface, render_finished),
+				      NULL, NULL,
+				      g_cclosure_marshal_VOID__OBJECT,
+				      G_TYPE_NONE,
+				      1,
+				      GDK_TYPE_PIXBUF);
+		initialized = TRUE;
+	}
 }
 
 void

Modified: trunk/libdocument/ev-document-find.c
==============================================================================
--- trunk/libdocument/ev-document-find.c	(original)
+++ trunk/libdocument/ev-document-find.c	Sat Jan 24 18:10:33 2009
@@ -22,26 +22,11 @@
 
 #include "ev-document-find.h"
 
-GType
-ev_document_find_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvDocumentFindIface),
-			NULL,
-			NULL,
-		};
+EV_DEFINE_INTERFACE (EvDocumentFind, ev_document_find, 0)
 
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentFind",
-					       &our_info, (GTypeFlags)0);
-	}
-
-	return type;
+static void
+ev_document_find_class_init (EvDocumentFindIface *klass)
+{
 }
 
 GList *

Modified: trunk/libdocument/ev-document-fonts.c
==============================================================================
--- trunk/libdocument/ev-document-fonts.c	(original)
+++ trunk/libdocument/ev-document-fonts.c	Sat Jan 24 18:10:33 2009
@@ -25,26 +25,11 @@
 
 #include "ev-document-fonts.h"
 
-GType
-ev_document_fonts_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvDocumentFontsIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentFonts",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentFonts, ev_document_fonts, 0)
 
-	return type;
+static void
+ev_document_fonts_class_init (EvDocumentFontsIface *klass)
+{
 }
 
 double

Modified: trunk/libdocument/ev-document-forms.c
==============================================================================
--- trunk/libdocument/ev-document-forms.c	(original)
+++ trunk/libdocument/ev-document-forms.c	Sat Jan 24 18:10:33 2009
@@ -21,24 +21,11 @@
 #include <config.h>
 #include "ev-document-forms.h"
 
-GType
-ev_document_forms_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		const GTypeInfo our_info = {
-			sizeof (EvDocumentFormsIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentForms",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentForms, ev_document_forms, 0)
 
-	return type;
+static void
+ev_document_forms_class_init (EvDocumentFormsIface *klass)
+{
 }
 
 GList *

Modified: trunk/libdocument/ev-document-images.c
==============================================================================
--- trunk/libdocument/ev-document-images.c	(original)
+++ trunk/libdocument/ev-document-images.c	Sat Jan 24 18:10:33 2009
@@ -21,24 +21,11 @@
 #include <config.h>
 #include "ev-document-images.h"
 
-GType
-ev_document_images_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		const GTypeInfo our_info = {
-			sizeof (EvDocumentImagesIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentImages",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentImages, ev_document_images, 0)
 
-	return type;
+static void
+ev_document_images_class_init (EvDocumentImagesIface *klass)
+{
 }
 
 GList *

Modified: trunk/libdocument/ev-document-layers.c
==============================================================================
--- trunk/libdocument/ev-document-layers.c	(original)
+++ trunk/libdocument/ev-document-layers.c	Sat Jan 24 18:10:33 2009
@@ -21,25 +21,13 @@
 #include "config.h"
 
 #include "ev-document-layers.h"
+#include "ev-document.h"
 
-GType
-ev_document_layers_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		const GTypeInfo our_info = {
-			sizeof (EvDocumentLayersIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentLayers",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentLayers, ev_document_layers, 0)
 
-	return type;
+static void
+ev_document_layers_class_init (EvDocumentLayersIface *klass)
+{
 }
 
 gboolean

Modified: trunk/libdocument/ev-document-links.c
==============================================================================
--- trunk/libdocument/ev-document-links.c	(original)
+++ trunk/libdocument/ev-document-links.c	Sat Jan 24 18:10:33 2009
@@ -25,24 +25,11 @@
 
 #include "ev-document-links.h"
 
-GType
-ev_document_links_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		const GTypeInfo our_info = {
-			sizeof (EvDocumentLinksIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentLinks",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentLinks, ev_document_links, 0)
 
-	return type;
+static void
+ev_document_links_class_init (EvDocumentLinksIface *klass)
+{
 }
 
 gboolean

Modified: trunk/libdocument/ev-document-security.c
==============================================================================
--- trunk/libdocument/ev-document-security.c	(original)
+++ trunk/libdocument/ev-document-security.c	Sat Jan 24 18:10:33 2009
@@ -25,26 +25,11 @@
 
 #include "ev-document-security.h"
 
-GType
-ev_document_security_get_type (void)
-{
-	static GType type = 0;
-	
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvDocumentSecurityIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentSecurity",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentSecurity, ev_document_security, 0)
 
-	return type;
+static void
+ev_document_security_class_init (EvDocumentSecurityIface *klass)
+{
 }
 
 gboolean

Modified: trunk/libdocument/ev-document-thumbnails.c
==============================================================================
--- trunk/libdocument/ev-document-thumbnails.c	(original)
+++ trunk/libdocument/ev-document-thumbnails.c	Sat Jan 24 18:10:33 2009
@@ -20,27 +20,13 @@
 
 #include <config.h>
 #include "ev-document-thumbnails.h"
+#include "ev-document.h"
 
-GType
-ev_document_thumbnails_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvDocumentThumbnailsIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentThumbnails",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentThumbnails, ev_document_thumbnails, 0)
 
-	return type;
+static void
+ev_document_thumbnails_class_init (EvDocumentThumbnailsIface *klass)
+{
 }
 
 GdkPixbuf *

Modified: trunk/libdocument/ev-document-transition.c
==============================================================================
--- trunk/libdocument/ev-document-transition.c	(original)
+++ trunk/libdocument/ev-document-transition.c	Sat Jan 24 18:10:33 2009
@@ -21,24 +21,11 @@
 #include <config.h>
 #include "ev-document-transition.h"
 
-GType
-ev_document_transition_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		const GTypeInfo our_info = {
-			sizeof (EvDocumentTransitionIface),
-			NULL,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocumentTransition",
-					       &our_info, (GTypeFlags)0);
-	}
+EV_DEFINE_INTERFACE (EvDocumentTransition, ev_document_transition, 0)
 
-	return type;
+static void
+ev_document_transition_class_init (EvDocumentTransitionIface *klass)
+{
 }
 
 gdouble

Modified: trunk/libdocument/ev-document.c
==============================================================================
--- trunk/libdocument/ev-document.c	(original)
+++ trunk/libdocument/ev-document.c	Sat Jan 24 18:10:33 2009
@@ -22,36 +22,10 @@
 
 #include "ev-document.h"
 
-static void ev_document_class_init (gpointer g_class);
-
-
 GMutex *ev_doc_mutex = NULL;
 GMutex *ev_fc_mutex = NULL;
 
-GType
-ev_document_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvDocumentIface),
-			NULL,
-			NULL,
-			(GClassInitFunc)ev_document_class_init
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvDocument",
-					       &our_info, (GTypeFlags)0);
-		
-		g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
-	}
-
-	return type;
-}
+EV_DEFINE_INTERFACE (EvDocument, ev_document, G_TYPE_OBJECT)
 
 GQuark
 ev_document_error_quark (void)
@@ -64,7 +38,7 @@
 }
 
 static void
-ev_document_class_init (gpointer g_class)
+ev_document_class_init (EvDocumentIface *klass)
 {
 }
 

Modified: trunk/libdocument/ev-document.h
==============================================================================
--- trunk/libdocument/ev-document.h	(original)
+++ trunk/libdocument/ev-document.h	Sat Jan 24 18:10:33 2009
@@ -234,8 +234,38 @@
 	}                                                                             \
 	return g_define_type_id__volatile;                                            \
 }
- 
 
+/* A convenience macro for GTypeInterface definitions, which declares
+ * a default vtable initialization function and defines a *_get_type()
+ * function.
+ *
+ * The macro expects the interface initialization function to have the
+ * name <literal>t_n ## _default_init</literal>, and the interface
+ * structure to have the name <literal>TN ## Interface</literal>.
+ */
+#define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)	                             \
+static void     type_name##_class_init        (TypeName##Iface *klass);                      \
+                                                                                             \
+GType                                                                                        \
+type_name##_get_type (void)                                                                  \
+{                                                                                            \
+        static volatile gsize g_define_type_id__volatile = 0;                                \
+	if (g_once_init_enter (&g_define_type_id__volatile)) {                               \
+		GType g_define_type_id =                                                     \
+		    g_type_register_static_simple (G_TYPE_INTERFACE,                         \
+		                                   g_intern_static_string (#TypeName),       \
+		                                   sizeof (TypeName##Iface),                 \
+		                                   (GClassInitFunc)type_name##_class_init,   \
+		                                   0,                                        \
+		                                   (GInstanceInitFunc)NULL,                  \
+						   (GTypeFlags) 0);                          \
+		if (TYPE_PREREQ)                                                             \
+			g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
+		g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
+	}                                                                                    \
+	return g_define_type_id__volatile;                                                   \
+}
+		
 G_END_DECLS
 
 #endif /* EV_DOCUMENT_H */

Modified: trunk/libdocument/ev-file-exporter.c
==============================================================================
--- trunk/libdocument/ev-file-exporter.c	(original)
+++ trunk/libdocument/ev-file-exporter.c	Sat Jan 24 18:10:33 2009
@@ -22,26 +22,13 @@
 
 #include <config.h>
 #include "ev-file-exporter.h"
+#include "ev-document.h"
 
-GType
-ev_file_exporter_get_type (void)
-{
-        static GType type = 0;
-
-        if (G_UNLIKELY (type == 0)) {
-                const GTypeInfo our_info =
-                {
-                        sizeof (EvFileExporterIface),
-                        NULL,
-                        NULL,
-                };
-
-                type = g_type_register_static (G_TYPE_INTERFACE,
-                                               "EvFileExporter",
-                                               &our_info, (GTypeFlags)0);
-        }
+EV_DEFINE_INTERFACE (EvFileExporter, ev_file_exporter, 0)
 
-        return type;
+static void
+ev_file_exporter_class_init (EvFileExporterIface *klass)
+{
 }
 
 void

Modified: trunk/libdocument/ev-selection.c
==============================================================================
--- trunk/libdocument/ev-selection.c	(original)
+++ trunk/libdocument/ev-selection.c	Sat Jan 24 18:10:33 2009
@@ -22,40 +22,13 @@
 
 #include "ev-selection.h"
 
-static void ev_selection_base_init (gpointer g_class);
-
-GType
-ev_selection_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0))
-	{
-		const GTypeInfo our_info =
-		{
-			sizeof (EvSelectionIface),
-			ev_selection_base_init,
-			NULL,
-		};
-
-		type = g_type_register_static (G_TYPE_INTERFACE,
-					       "EvSelection",
-					       &our_info, (GTypeFlags)0);
-	}
-
-	return type;
-}
+EV_DEFINE_INTERFACE (EvSelection, ev_selection, 0)
 
 static void
-ev_selection_base_init (gpointer g_class)
+ev_selection_class_init (EvSelectionIface *klass)
 {
-	static gboolean initialized = FALSE;
-
-	if (!initialized) {
-	}
 }
 
-
 void
 ev_selection_render_selection (EvSelection      *selection,
 			       EvRenderContext  *rc,



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