From ab26fbf217460c766111850bf40725e5e65a5533 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sat, 24 Jan 2009 18:10:33 +0000 Subject: [PATCH] Add EV_DEFINE_INTERFACE macro. 2009-01-24 Carlos Garcia Campos * 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. svn path=/trunk/; revision=3379 --- ChangeLog | 23 ++++++++++++ libdocument/ev-async-renderer.c | 53 ++++++++++------------------ libdocument/ev-document-find.c | 23 +++--------- libdocument/ev-document-fonts.c | 23 +++--------- libdocument/ev-document-forms.c | 21 +++-------- libdocument/ev-document-images.c | 21 +++-------- libdocument/ev-document-layers.c | 22 +++--------- libdocument/ev-document-links.c | 21 +++-------- libdocument/ev-document-security.c | 23 +++--------- libdocument/ev-document-thumbnails.c | 24 +++---------- libdocument/ev-document-transition.c | 21 +++-------- libdocument/ev-document.c | 30 ++-------------- libdocument/ev-document.h | 32 ++++++++++++++++- libdocument/ev-file-exporter.c | 23 +++--------- libdocument/ev-selection.c | 31 ++-------------- 15 files changed, 119 insertions(+), 272 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ea1dadc..6edefe13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2009-01-24 Carlos Garcia Campos + + * 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. + 2009-01-24 Carlos Garcia Campos * libdocument/ev-document.[ch]: diff --git a/libdocument/ev-async-renderer.c b/libdocument/ev-async-renderer.c index f0ffce48..5ff9e3ed 100644 --- a/libdocument/ev-async-renderer.c +++ b/libdocument/ev-async-renderer.c @@ -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 @@ enum 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 diff --git a/libdocument/ev-document-find.c b/libdocument/ev-document-find.c index 59b8755a..bba5ea3d 100644 --- a/libdocument/ev-document-find.c +++ b/libdocument/ev-document-find.c @@ -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 * diff --git a/libdocument/ev-document-fonts.c b/libdocument/ev-document-fonts.c index 929c21df..d53a86fe 100644 --- a/libdocument/ev-document-fonts.c +++ b/libdocument/ev-document-fonts.c @@ -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, - }; +EV_DEFINE_INTERFACE (EvDocumentFonts, ev_document_fonts, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentFonts", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_fonts_class_init (EvDocumentFontsIface *klass) +{ } double diff --git a/libdocument/ev-document-forms.c b/libdocument/ev-document-forms.c index d5d9c709..6d702a3f 100644 --- a/libdocument/ev-document-forms.c +++ b/libdocument/ev-document-forms.c @@ -21,24 +21,11 @@ #include #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, - }; +EV_DEFINE_INTERFACE (EvDocumentForms, ev_document_forms, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentForms", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_forms_class_init (EvDocumentFormsIface *klass) +{ } GList * diff --git a/libdocument/ev-document-images.c b/libdocument/ev-document-images.c index 874a24da..1754ded2 100644 --- a/libdocument/ev-document-images.c +++ b/libdocument/ev-document-images.c @@ -21,24 +21,11 @@ #include #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, - }; +EV_DEFINE_INTERFACE (EvDocumentImages, ev_document_images, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentImages", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_images_class_init (EvDocumentImagesIface *klass) +{ } GList * diff --git a/libdocument/ev-document-layers.c b/libdocument/ev-document-layers.c index f203565e..909dbdaa 100644 --- a/libdocument/ev-document-layers.c +++ b/libdocument/ev-document-layers.c @@ -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, - }; +EV_DEFINE_INTERFACE (EvDocumentLayers, ev_document_layers, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentLayers", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_layers_class_init (EvDocumentLayersIface *klass) +{ } gboolean diff --git a/libdocument/ev-document-links.c b/libdocument/ev-document-links.c index c7170963..d74804b0 100644 --- a/libdocument/ev-document-links.c +++ b/libdocument/ev-document-links.c @@ -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, - }; +EV_DEFINE_INTERFACE (EvDocumentLinks, ev_document_links, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentLinks", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_links_class_init (EvDocumentLinksIface *klass) +{ } gboolean diff --git a/libdocument/ev-document-security.c b/libdocument/ev-document-security.c index 49ded873..1e9ed8ba 100644 --- a/libdocument/ev-document-security.c +++ b/libdocument/ev-document-security.c @@ -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 diff --git a/libdocument/ev-document-thumbnails.c b/libdocument/ev-document-thumbnails.c index 2e73af62..d51302ac 100644 --- a/libdocument/ev-document-thumbnails.c +++ b/libdocument/ev-document-thumbnails.c @@ -20,27 +20,13 @@ #include #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, - }; +EV_DEFINE_INTERFACE (EvDocumentThumbnails, ev_document_thumbnails, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentThumbnails", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_thumbnails_class_init (EvDocumentThumbnailsIface *klass) +{ } GdkPixbuf * diff --git a/libdocument/ev-document-transition.c b/libdocument/ev-document-transition.c index c8d136a2..495b1b96 100644 --- a/libdocument/ev-document-transition.c +++ b/libdocument/ev-document-transition.c @@ -21,24 +21,11 @@ #include #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, - }; +EV_DEFINE_INTERFACE (EvDocumentTransition, ev_document_transition, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocumentTransition", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_document_transition_class_init (EvDocumentTransitionIface *klass) +{ } gdouble diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c index 163f2e26..aa7d1d2e 100644 --- a/libdocument/ev-document.c +++ b/libdocument/ev-document.c @@ -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 @@ ev_document_error_quark (void) } static void -ev_document_class_init (gpointer g_class) +ev_document_class_init (EvDocumentIface *klass) { } diff --git a/libdocument/ev-document.h b/libdocument/ev-document.h index e07e3a22..7cb6d847 100644 --- a/libdocument/ev-document.h +++ b/libdocument/ev-document.h @@ -234,8 +234,38 @@ type_name##_get_type (void) } \ 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 t_n ## _default_init, and the interface + * structure to have the name TN ## Interface. + */ +#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 */ diff --git a/libdocument/ev-file-exporter.c b/libdocument/ev-file-exporter.c index c74869fc..43f563bf 100644 --- a/libdocument/ev-file-exporter.c +++ b/libdocument/ev-file-exporter.c @@ -22,26 +22,13 @@ #include #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, - }; +EV_DEFINE_INTERFACE (EvFileExporter, ev_file_exporter, 0) - type = g_type_register_static (G_TYPE_INTERFACE, - "EvFileExporter", - &our_info, (GTypeFlags)0); - } - - return type; +static void +ev_file_exporter_class_init (EvFileExporterIface *klass) +{ } void diff --git a/libdocument/ev-selection.c b/libdocument/ev-selection.c index 9a7336c6..c19ac2a3 100644 --- a/libdocument/ev-selection.c +++ b/libdocument/ev-selection.c @@ -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, -- 2.43.5