From 9caf11f2d8f7120830da9f10a694ccc8f30ebee1 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 8 Oct 2010 14:47:46 +0100 Subject: [PATCH] Use G_DEFINE_INTERFACE GObject provides us with a nice, safe macro for defining interface types. --- clutter/clutter-animatable.c | 16 +- clutter/clutter-container.c | 172 +++++++--------- clutter/clutter-media.c | 348 +++++++++++++++------------------ clutter/clutter-scriptable.c | 20 +- clutter/clutter-stage-window.c | 27 +-- 5 files changed, 251 insertions(+), 332 deletions(-) diff --git a/clutter/clutter-animatable.c b/clutter/clutter-animatable.c index be8437df1..cbf459794 100644 --- a/clutter/clutter-animatable.c +++ b/clutter/clutter-animatable.c @@ -53,18 +53,12 @@ #include "clutter-debug.h" #include "clutter-private.h" -GType -clutter_animatable_get_type (void) +typedef ClutterAnimatableIface ClutterAnimatableInterface; +G_DEFINE_INTERFACE (ClutterAnimatable, clutter_animatable, G_TYPE_OBJECT); + +static void +clutter_animatable_default_init (ClutterAnimatableInterface *iface) { - static GType a_type = 0; - - if (G_UNLIKELY (a_type == 0)) - a_type = g_type_register_static_simple (G_TYPE_INTERFACE, - I_("ClutterAnimatable"), - sizeof (ClutterAnimatableIface), - NULL, 0, NULL, 0); - - return a_type; } /** diff --git a/clutter/clutter-container.c b/clutter/clutter-container.c index 6a11221e2..b1a0cf33c 100644 --- a/clutter/clutter-container.c +++ b/clutter/clutter-container.c @@ -96,112 +96,84 @@ static void child_notify (ClutterContainer *container, ClutterActor *child, GParamSpec *pspec); +typedef ClutterContainerIface ClutterContainerInterface; + +G_DEFINE_INTERFACE (ClutterContainer, clutter_container, CLUTTER_TYPE_ACTOR); + static void -clutter_container_base_init (gpointer g_iface) +clutter_container_default_init (ClutterContainerInterface *iface) { - static gboolean initialised = FALSE; + GType iface_type = G_TYPE_FROM_INTERFACE (iface); - if (!initialised) - { - GType iface_type = G_TYPE_FROM_INTERFACE (g_iface); - ClutterContainerIface *iface = g_iface; + quark_child_meta = + g_quark_from_static_string ("clutter-container-child-data"); - initialised = TRUE; + /** + * ClutterContainer::actor-added: + * @container: the actor which received the signal + * @actor: the new child that has been added to @container + * + * The ::actor-added signal is emitted each time an actor + * has been added to @container. + * + * Since: 0.4 + */ + container_signals[ACTOR_ADDED] = + g_signal_new (I_("actor-added"), + iface_type, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (ClutterContainerIface, actor_added), + NULL, NULL, + _clutter_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + CLUTTER_TYPE_ACTOR); + /** + * ClutterContainer::actor-removed: + * @container: the actor which received the signal + * @actor: the child that has been removed from @container + * + * The ::actor-removed signal is emitted each time an actor + * is removed from @container. + * + * Since: 0.4 + */ + container_signals[ACTOR_REMOVED] = + g_signal_new (I_("actor-removed"), + iface_type, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (ClutterContainerIface, actor_removed), + NULL, NULL, + _clutter_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + CLUTTER_TYPE_ACTOR); - quark_child_meta = - g_quark_from_static_string ("clutter-container-child-data"); + /** + * ClutterContainer::child-notify: + * @container: the container which received the signal + * @actor: the child that has had a property set + * @pspec: the #GParamSpec of the property set + * + * The ::child-notify signal is emitted each time a property is + * being set through the clutter_container_child_set() and + * clutter_container_child_set_property() calls. + * + * Since: 0.8 + */ + container_signals[CHILD_NOTIFY] = + g_signal_new (I_("child-notify"), + iface_type, + G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, + G_STRUCT_OFFSET (ClutterContainerIface, child_notify), + NULL, NULL, + _clutter_marshal_VOID__OBJECT_PARAM, + G_TYPE_NONE, 2, + CLUTTER_TYPE_ACTOR, G_TYPE_PARAM); - /** - * ClutterContainer::actor-added: - * @container: the actor which received the signal - * @actor: the new child that has been added to @container - * - * The ::actor-added signal is emitted each time an actor - * has been added to @container. - * - * Since: 0.4 - */ - container_signals[ACTOR_ADDED] = - g_signal_new (I_("actor-added"), - iface_type, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ClutterContainerIface, actor_added), - NULL, NULL, - _clutter_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - CLUTTER_TYPE_ACTOR); - /** - * ClutterContainer::actor-removed: - * @container: the actor which received the signal - * @actor: the child that has been removed from @container - * - * The ::actor-removed signal is emitted each time an actor - * is removed from @container. - * - * Since: 0.4 - */ - container_signals[ACTOR_REMOVED] = - g_signal_new (I_("actor-removed"), - iface_type, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ClutterContainerIface, actor_removed), - NULL, NULL, - _clutter_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - CLUTTER_TYPE_ACTOR); - - /** - * ClutterContainer::child-notify: - * @container: the container which received the signal - * @actor: the child that has had a property set - * @pspec: the #GParamSpec of the property set - * - * The ::child-notify signal is emitted each time a property is - * being set through the clutter_container_child_set() and - * clutter_container_child_set_property() calls. - * - * Since: 0.8 - */ - container_signals[CHILD_NOTIFY] = - g_signal_new (I_("child-notify"), - iface_type, - G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, - G_STRUCT_OFFSET (ClutterContainerIface, child_notify), - NULL, NULL, - _clutter_marshal_VOID__OBJECT_PARAM, - G_TYPE_NONE, 2, - CLUTTER_TYPE_ACTOR, G_TYPE_PARAM); - - iface->child_meta_type = G_TYPE_INVALID; - iface->create_child_meta = create_child_meta; - iface->destroy_child_meta = destroy_child_meta; - iface->get_child_meta = get_child_meta; - iface->child_notify = child_notify; - } -} - -GType -clutter_container_get_type (void) -{ - static GType container_type = 0; - - if (G_UNLIKELY (!container_type)) - { - const GTypeInfo container_info = - { - sizeof (ClutterContainerIface), - clutter_container_base_init, - NULL, /* iface_base_finalize */ - }; - - container_type = g_type_register_static (G_TYPE_INTERFACE, - I_("ClutterContainer"), - &container_info, 0); - - g_type_interface_add_prerequisite (container_type, G_TYPE_OBJECT); - } - - return container_type; + iface->child_meta_type = G_TYPE_INVALID; + iface->create_child_meta = create_child_meta; + iface->destroy_child_meta = destroy_child_meta; + iface->get_child_meta = get_child_meta; + iface->child_notify = child_notify; } /** diff --git a/clutter/clutter-media.c b/clutter/clutter-media.c index 15c027b0c..676478151 100644 --- a/clutter/clutter-media.c +++ b/clutter/clutter-media.c @@ -57,207 +57,183 @@ enum static guint media_signals[LAST_SIGNAL] = { 0, }; +typedef ClutterMediaIface ClutterMediaInterface; + +G_DEFINE_INTERFACE (ClutterMedia, clutter_media, G_TYPE_OBJECT); + static void -clutter_media_base_init (gpointer g_iface) +clutter_media_default_init (ClutterMediaInterface *iface) { - static gboolean was_initialized = FALSE; + GParamSpec *pspec = NULL; - if (G_UNLIKELY (!was_initialized)) - { - GParamSpec *pspec = NULL; + /** + * ClutterMedia:uri: + * + * The location of a media file, expressed as a valid URI. + * + * Since: 0.2 + */ + pspec = g_param_spec_string ("uri", + P_("URI"), + P_("URI of a media file"), + NULL, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - was_initialized = TRUE; + /** + * ClutterMedia:playing: + * + * Whether the #ClutterMedia actor is playing. + * + * Since: 0.2 + */ + pspec = g_param_spec_boolean ("playing", + P_("Playing"), + P_("Wheter the actor is playing"), + FALSE, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:uri: - * - * The location of a media file, expressed as a valid URI. - * - * Since: 0.2 - */ - pspec = g_param_spec_string ("uri", - P_("URI"), - P_("URI of a media file"), - NULL, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:progress: + * + * The current progress of the playback, as a normalized + * value between 0.0 and 1.0. + * + * Since: 1.0 + */ + pspec = g_param_spec_double ("progress", + P_("Progress"), + P_("Current progress of the playback"), + 0.0, 1.0, 0.0, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:playing: - * - * Whether the #ClutterMedia actor is playing. - * - * Since: 0.2 - */ - pspec = g_param_spec_boolean ("playing", - P_("Playing"), - P_("Wheter the actor is playing"), - FALSE, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:subtitle-uri: + * + * The location of a subtitle file, expressed as a valid URI. + * + * Since: 1.2 + */ + pspec = g_param_spec_string ("subtitle-uri", + P_("Subtitle URI"), + P_("URI of a subtitle file"), + NULL, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:progress: - * - * The current progress of the playback, as a normalized - * value between 0.0 and 1.0. - * - * Since: 1.0 - */ - pspec = g_param_spec_double ("progress", - P_("Progress"), - P_("Current progress of the playback"), - 0.0, 1.0, 0.0, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:subtitle-font-name: + * + * The font used to display subtitles. The font description has to + * follow the same grammar as the one recognized by + * pango_font_description_from_string(). + * + * Since: 1.2 + */ + pspec = g_param_spec_string ("subtitle-font-name", + P_("Subtitle Font Name"), + P_("The font used to display subtitles"), + NULL, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:subtitle-uri: - * - * The location of a subtitle file, expressed as a valid URI. - * - * Since: 1.2 - */ - pspec = g_param_spec_string ("subtitle-uri", - P_("Subtitle URI"), - P_("URI of a subtitle file"), - NULL, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:audio-volume: + * + * The volume of the audio, as a normalized value between + * 0.0 and 1.0. + * + * Since: 1.0 + */ + pspec = g_param_spec_double ("audio-volume", + P_("Audio Volume"), + P_("The volume of the audio"), + 0.0, 1.0, 0.5, + CLUTTER_PARAM_READWRITE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:subtitle-font-name: - * - * The font used to display subtitles. The font description has to - * follow the same grammar as the one recognized by - * pango_font_description_from_string(). - * - * Since: 1.2 - */ - pspec = g_param_spec_string ("subtitle-font-name", - P_("Subtitle Font Name"), - P_("The font used to display subtitles"), - NULL, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:can-seek: + * + * Whether the current stream is seekable. + * + * Since: 0.2 + */ + pspec = g_param_spec_boolean ("can-seek", + P_("Can Seek"), + P_("Whether the current stream is seekable"), + FALSE, + CLUTTER_PARAM_READABLE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:audio-volume: - * - * The volume of the audio, as a normalized value between - * 0.0 and 1.0. - * - * Since: 1.0 - */ - pspec = g_param_spec_double ("audio-volume", - P_("Audio Volume"), - P_("The volume of the audio"), - 0.0, 1.0, 0.5, - CLUTTER_PARAM_READWRITE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:buffer-fill: + * + * The fill level of the buffer for the current stream, + * as a value between 0.0 and 1.0. + * + * Since: 1.0 + */ + pspec = g_param_spec_double ("buffer-fill", + P_("Buffer Fill"), + P_("The fill level of the buffer"), + 0.0, 1.0, 0.0, + CLUTTER_PARAM_READABLE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:can-seek: - * - * Whether the current stream is seekable. - * - * Since: 0.2 - */ - pspec = g_param_spec_boolean ("can-seek", - P_("Can Seek"), - P_("Whether the current stream is seekable"), - FALSE, - CLUTTER_PARAM_READABLE); - g_object_interface_install_property (g_iface, pspec); + /** + * ClutterMedia:duration: + * + * The duration of the current stream, in seconds + * + * Since: 0.2 + */ + pspec = g_param_spec_double ("duration", + P_("Duration"), + P_("The duration of the stream, in seconds"), + 0, G_MAXDOUBLE, 0, + CLUTTER_PARAM_READABLE); + g_object_interface_install_property (iface, pspec); - /** - * ClutterMedia:buffer-fill: - * - * The fill level of the buffer for the current stream, - * as a value between 0.0 and 1.0. - * - * Since: 1.0 - */ - pspec = g_param_spec_double ("buffer-fill", - P_("Buffer Fill"), - P_("The fill level of the buffer"), - 0.0, 1.0, 0.0, - CLUTTER_PARAM_READABLE); - g_object_interface_install_property (g_iface, pspec); - - /** - * ClutterMedia:duration: - * - * The duration of the current stream, in seconds - * - * Since: 0.2 - */ - pspec = g_param_spec_double ("duration", - P_("Duration"), - P_("The duration of the stream, in seconds"), - 0, G_MAXDOUBLE, 0, - CLUTTER_PARAM_READABLE); - g_object_interface_install_property (g_iface, pspec); - - /** - * ClutterMedia::eos: - * @media: the #ClutterMedia instance that received the signal - * - * The ::eos signal is emitted each time the media stream ends. - * - * Since: 0.2 - */ - media_signals[EOS_SIGNAL] = - g_signal_new ("eos", - CLUTTER_TYPE_MEDIA, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ClutterMediaIface, eos), - NULL, NULL, - _clutter_marshal_VOID__VOID, - G_TYPE_NONE, 0); - /** - * ClutterMedia::error: - * @media: the #ClutterMedia instance that received the signal - * @error: the #GError - * - * The ::error signal is emitted each time an error occurred. - * - * Since: 0.2 - */ - media_signals[ERROR_SIGNAL] = - g_signal_new ("error", - CLUTTER_TYPE_MEDIA, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ClutterMediaIface, error), - NULL, NULL, - _clutter_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - } + /** + * ClutterMedia::eos: + * @media: the #ClutterMedia instance that received the signal + * + * The ::eos signal is emitted each time the media stream ends. + * + * Since: 0.2 + */ + media_signals[EOS_SIGNAL] = + g_signal_new (I_("eos"), + CLUTTER_TYPE_MEDIA, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ClutterMediaIface, eos), + NULL, NULL, + _clutter_marshal_VOID__VOID, + G_TYPE_NONE, 0); + /** + * ClutterMedia::error: + * @media: the #ClutterMedia instance that received the signal + * @error: the #GError + * + * The ::error signal is emitted each time an error occurred. + * + * Since: 0.2 + */ + media_signals[ERROR_SIGNAL] = + g_signal_new (I_("error"), + CLUTTER_TYPE_MEDIA, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ClutterMediaIface, error), + NULL, NULL, + _clutter_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + G_TYPE_ERROR); } -GType -clutter_media_get_type (void) -{ - static GType media_type = 0; - - if (G_UNLIKELY (media_type == 0)) - { - const GTypeInfo media_info = { - sizeof (ClutterMediaIface), /* class size */ - clutter_media_base_init, /* base_init */ - NULL, /* base_finalize */ - }; - - media_type = g_type_register_static (G_TYPE_INTERFACE, - I_("ClutterMedia"), - &media_info, 0); - } - - return media_type; -} - /** * clutter_media_set_uri: * @media: a #ClutterMedia diff --git a/clutter/clutter-scriptable.c b/clutter/clutter-scriptable.c index f90f84263..082aebade 100644 --- a/clutter/clutter-scriptable.c +++ b/clutter/clutter-scriptable.c @@ -51,21 +51,13 @@ #include "clutter-private.h" #include "clutter-debug.h" -GType -clutter_scriptable_get_type (void) +typedef ClutterScriptableIface ClutterScriptableInterface; + +G_DEFINE_INTERFACE (ClutterScriptable, clutter_scriptable, G_TYPE_OBJECT); + +static void +clutter_scriptable_default_init (ClutterScriptableInterface *iface) { - static GType scriptable_type = 0; - - if (G_UNLIKELY (scriptable_type == 0)) - { - scriptable_type = - g_type_register_static_simple (G_TYPE_INTERFACE, - I_("ClutterScriptable"), - sizeof (ClutterScriptableIface), - NULL, 0, NULL, 0); - } - - return scriptable_type; } /** diff --git a/clutter/clutter-stage-window.c b/clutter/clutter-stage-window.c index 8a8ac42bb..c704854ea 100644 --- a/clutter/clutter-stage-window.c +++ b/clutter/clutter-stage-window.c @@ -8,28 +8,13 @@ #include "clutter-stage-window.h" #include "clutter-private.h" -GType -clutter_stage_window_get_type (void) +typedef ClutterStageWindowIface ClutterStageWindowInterface; + +G_DEFINE_INTERFACE (ClutterStageWindow, clutter_stage_window, G_TYPE_OBJECT); + +static void +clutter_stage_window_default_init (ClutterStageWindowInterface *iface) { - static GType stage_window_type = 0; - - if (G_UNLIKELY (stage_window_type == 0)) - { - const GTypeInfo stage_window_info = { - sizeof (ClutterStageWindowIface), - NULL, - NULL, - }; - - stage_window_type = - g_type_register_static (G_TYPE_INTERFACE, I_("ClutterStageWindow"), - &stage_window_info, 0); - - g_type_interface_add_prerequisite (stage_window_type, - G_TYPE_OBJECT); - } - - return stage_window_type; } ClutterActor *