Use G_DEFINE_INTERFACE

GObject provides us with a nice, safe macro for defining interface
types.
This commit is contained in:
Emmanuele Bassi 2010-10-08 14:47:46 +01:00
parent 8f5d6cb790
commit 9caf11f2d8
5 changed files with 251 additions and 332 deletions

View File

@ -53,18 +53,12 @@
#include "clutter-debug.h" #include "clutter-debug.h"
#include "clutter-private.h" #include "clutter-private.h"
GType typedef ClutterAnimatableIface ClutterAnimatableInterface;
clutter_animatable_get_type (void) 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;
} }
/** /**

View File

@ -96,112 +96,84 @@ static void child_notify (ClutterContainer *container,
ClutterActor *child, ClutterActor *child,
GParamSpec *pspec); GParamSpec *pspec);
typedef ClutterContainerIface ClutterContainerInterface;
G_DEFINE_INTERFACE (ClutterContainer, clutter_container, CLUTTER_TYPE_ACTOR);
static void 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) quark_child_meta =
{ g_quark_from_static_string ("clutter-container-child-data");
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
ClutterContainerIface *iface = g_iface;
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);
/** iface->child_meta_type = G_TYPE_INVALID;
* ClutterContainer::actor-added: iface->create_child_meta = create_child_meta;
* @container: the actor which received the signal iface->destroy_child_meta = destroy_child_meta;
* @actor: the new child that has been added to @container iface->get_child_meta = get_child_meta;
* iface->child_notify = child_notify;
* 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;
} }
/** /**

View File

@ -57,207 +57,183 @@ enum
static guint media_signals[LAST_SIGNAL] = { 0, }; static guint media_signals[LAST_SIGNAL] = { 0, };
typedef ClutterMediaIface ClutterMediaInterface;
G_DEFINE_INTERFACE (ClutterMedia, clutter_media, G_TYPE_OBJECT);
static void 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)) /**
{ * ClutterMedia:uri:
GParamSpec *pspec = NULL; *
* 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: * ClutterMedia:progress:
* *
* The location of a media file, expressed as a valid URI. * The current progress of the playback, as a normalized
* * value between 0.0 and 1.0.
* Since: 0.2 *
*/ * Since: 1.0
pspec = g_param_spec_string ("uri", */
P_("URI"), pspec = g_param_spec_double ("progress",
P_("URI of a media file"), P_("Progress"),
NULL, P_("Current progress of the playback"),
CLUTTER_PARAM_READWRITE); 0.0, 1.0, 0.0,
g_object_interface_install_property (g_iface, pspec); CLUTTER_PARAM_READWRITE);
g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:playing: * ClutterMedia:subtitle-uri:
* *
* Whether the #ClutterMedia actor is playing. * The location of a subtitle file, expressed as a valid URI.
* *
* Since: 0.2 * Since: 1.2
*/ */
pspec = g_param_spec_boolean ("playing", pspec = g_param_spec_string ("subtitle-uri",
P_("Playing"), P_("Subtitle URI"),
P_("Wheter the actor is playing"), P_("URI of a subtitle file"),
FALSE, NULL,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_interface_install_property (g_iface, pspec); g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:progress: * ClutterMedia:subtitle-font-name:
* *
* The current progress of the playback, as a normalized * The font used to display subtitles. The font description has to
* value between 0.0 and 1.0. * follow the same grammar as the one recognized by
* * pango_font_description_from_string().
* Since: 1.0 *
*/ * Since: 1.2
pspec = g_param_spec_double ("progress", */
P_("Progress"), pspec = g_param_spec_string ("subtitle-font-name",
P_("Current progress of the playback"), P_("Subtitle Font Name"),
0.0, 1.0, 0.0, P_("The font used to display subtitles"),
CLUTTER_PARAM_READWRITE); NULL,
g_object_interface_install_property (g_iface, pspec); CLUTTER_PARAM_READWRITE);
g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:subtitle-uri: * ClutterMedia:audio-volume:
* *
* The location of a subtitle file, expressed as a valid URI. * The volume of the audio, as a normalized value between
* * 0.0 and 1.0.
* Since: 1.2 *
*/ * Since: 1.0
pspec = g_param_spec_string ("subtitle-uri", */
P_("Subtitle URI"), pspec = g_param_spec_double ("audio-volume",
P_("URI of a subtitle file"), P_("Audio Volume"),
NULL, P_("The volume of the audio"),
CLUTTER_PARAM_READWRITE); 0.0, 1.0, 0.5,
g_object_interface_install_property (g_iface, pspec); CLUTTER_PARAM_READWRITE);
g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:subtitle-font-name: * ClutterMedia:can-seek:
* *
* The font used to display subtitles. The font description has to * Whether the current stream is seekable.
* follow the same grammar as the one recognized by *
* pango_font_description_from_string(). * Since: 0.2
* */
* Since: 1.2 pspec = g_param_spec_boolean ("can-seek",
*/ P_("Can Seek"),
pspec = g_param_spec_string ("subtitle-font-name", P_("Whether the current stream is seekable"),
P_("Subtitle Font Name"), FALSE,
P_("The font used to display subtitles"), CLUTTER_PARAM_READABLE);
NULL, g_object_interface_install_property (iface, pspec);
CLUTTER_PARAM_READWRITE);
g_object_interface_install_property (g_iface, pspec);
/** /**
* ClutterMedia:audio-volume: * ClutterMedia:buffer-fill:
* *
* The volume of the audio, as a normalized value between * The fill level of the buffer for the current stream,
* 0.0 and 1.0. * as a value between 0.0 and 1.0.
* *
* Since: 1.0 * Since: 1.0
*/ */
pspec = g_param_spec_double ("audio-volume", pspec = g_param_spec_double ("buffer-fill",
P_("Audio Volume"), P_("Buffer Fill"),
P_("The volume of the audio"), P_("The fill level of the buffer"),
0.0, 1.0, 0.5, 0.0, 1.0, 0.0,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READABLE);
g_object_interface_install_property (g_iface, pspec); g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:can-seek: * ClutterMedia:duration:
* *
* Whether the current stream is seekable. * The duration of the current stream, in seconds
* *
* Since: 0.2 * Since: 0.2
*/ */
pspec = g_param_spec_boolean ("can-seek", pspec = g_param_spec_double ("duration",
P_("Can Seek"), P_("Duration"),
P_("Whether the current stream is seekable"), P_("The duration of the stream, in seconds"),
FALSE, 0, G_MAXDOUBLE, 0,
CLUTTER_PARAM_READABLE); CLUTTER_PARAM_READABLE);
g_object_interface_install_property (g_iface, pspec); g_object_interface_install_property (iface, pspec);
/** /**
* ClutterMedia:buffer-fill: * ClutterMedia::eos:
* * @media: the #ClutterMedia instance that received the signal
* The fill level of the buffer for the current stream, *
* as a value between 0.0 and 1.0. * The ::eos signal is emitted each time the media stream ends.
* *
* Since: 1.0 * Since: 0.2
*/ */
pspec = g_param_spec_double ("buffer-fill", media_signals[EOS_SIGNAL] =
P_("Buffer Fill"), g_signal_new (I_("eos"),
P_("The fill level of the buffer"), CLUTTER_TYPE_MEDIA,
0.0, 1.0, 0.0, G_SIGNAL_RUN_LAST,
CLUTTER_PARAM_READABLE); G_STRUCT_OFFSET (ClutterMediaIface, eos),
g_object_interface_install_property (g_iface, pspec); NULL, NULL,
_clutter_marshal_VOID__VOID,
/** G_TYPE_NONE, 0);
* ClutterMedia:duration: /**
* * ClutterMedia::error:
* The duration of the current stream, in seconds * @media: the #ClutterMedia instance that received the signal
* * @error: the #GError
* Since: 0.2 *
*/ * The ::error signal is emitted each time an error occurred.
pspec = g_param_spec_double ("duration", *
P_("Duration"), * Since: 0.2
P_("The duration of the stream, in seconds"), */
0, G_MAXDOUBLE, 0, media_signals[ERROR_SIGNAL] =
CLUTTER_PARAM_READABLE); g_signal_new (I_("error"),
g_object_interface_install_property (g_iface, pspec); CLUTTER_TYPE_MEDIA,
G_SIGNAL_RUN_LAST,
/** G_STRUCT_OFFSET (ClutterMediaIface, error),
* ClutterMedia::eos: NULL, NULL,
* @media: the #ClutterMedia instance that received the signal _clutter_marshal_VOID__BOXED,
* G_TYPE_NONE, 1,
* The ::eos signal is emitted each time the media stream ends. G_TYPE_ERROR);
*
* 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);
}
} }
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: * clutter_media_set_uri:
* @media: a #ClutterMedia * @media: a #ClutterMedia

View File

@ -51,21 +51,13 @@
#include "clutter-private.h" #include "clutter-private.h"
#include "clutter-debug.h" #include "clutter-debug.h"
GType typedef ClutterScriptableIface ClutterScriptableInterface;
clutter_scriptable_get_type (void)
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;
} }
/** /**

View File

@ -8,28 +8,13 @@
#include "clutter-stage-window.h" #include "clutter-stage-window.h"
#include "clutter-private.h" #include "clutter-private.h"
GType typedef ClutterStageWindowIface ClutterStageWindowInterface;
clutter_stage_window_get_type (void)
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 * ClutterActor *