From ef48cff3d0c5cb5553f140267724388951d92444 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 30 Mar 2012 22:01:55 +0200 Subject: [PATCH] childproxy: make get_child_by_name virtual Allows implementations to use custom name->object mappings. --- gst/gstchildproxy.c | 57 ++++++++++++++++++++++++++++++++++------------------- gst/gstchildproxy.h | 4 +++- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/gst/gstchildproxy.c b/gst/gstchildproxy.c index 4965e7f..f7e077e 100644 --- a/gst/gstchildproxy.c +++ b/gst/gstchildproxy.c @@ -39,9 +39,7 @@ * "child1" and "child2" implement the #GstChildProxy interface. */ /* FIXME-0.11: - * it would be nice to make gst_child_proxy_get_child_by_name virtual too and - * use GObject instead of GstObject. We could eventually provide the current - * implementation as a default if children are GstObjects. + * it would be nice to use GObject instead of GstObject. * This change would allow to propose the interface for inclusion with * glib/gobject. IMHO this is useful for GtkContainer and compound widgets too. */ @@ -61,22 +59,9 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; -/** - * gst_child_proxy_get_child_by_name: - * @parent: the parent object to get the child from - * @name: the childs name - * - * Looks up a child element by the given name. - * - * Implementors can use #GstObject together with gst_object_get_name() - * - * Returns: (transfer full): the child object or %NULL if not found. Unref - * after usage. - * - * MT safe. - */ -GstObject * -gst_child_proxy_get_child_by_name (GstChildProxy * parent, const gchar * name) +static GstObject * +gst_child_proxy_default_get_child_by_name (GstChildProxy * parent, + const gchar * name) { guint count, i; GstObject *object, *result; @@ -113,6 +98,30 @@ gst_child_proxy_get_child_by_name (GstChildProxy * parent, const gchar * name) return result; } + +/** + * gst_child_proxy_get_child_by_name: + * @parent: the parent object to get the child from + * @name: the childs name + * + * Looks up a child element by the given name. + * + * Implementors can use #GstObject together with gst_object_get_name() + * + * Returns: (transfer full): the child object or %NULL if not found. Unref + * after usage. + * + * MT safe. + */ +GstObject * +gst_child_proxy_get_child_by_name (GstChildProxy * parent, const gchar * name) +{ + g_return_val_if_fail (GST_IS_CHILD_PROXY (parent), 0); + + return (GST_CHILD_PROXY_GET_INTERFACE (parent)->get_child_by_name (parent, + name)); +} + /** * gst_child_proxy_get_child_by_index: * @parent: the parent object to get the child from @@ -468,6 +477,14 @@ gst_child_proxy_child_removed (GstObject * object, GstObject * child) /* gobject methods */ static void +gst_child_proxy_class_init (gpointer g_class, gpointer class_data) +{ + GstChildProxyInterface *iface = (GstChildProxyInterface *) g_class; + + iface->get_child_by_name = gst_child_proxy_default_get_child_by_name; +} + +static void gst_child_proxy_base_init (gpointer g_class) { static gboolean initialized = FALSE; @@ -515,7 +532,7 @@ gst_child_proxy_get_type (void) sizeof (GstChildProxyInterface), gst_child_proxy_base_init, /* base_init */ NULL, /* base_finalize */ - NULL, /* class_init */ + gst_child_proxy_class_init, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ 0, diff --git a/gst/gstchildproxy.h b/gst/gstchildproxy.h index fda5ce7..b2227ad 100644 --- a/gst/gstchildproxy.h +++ b/gst/gstchildproxy.h @@ -44,7 +44,8 @@ typedef struct _GstChildProxyInterface GstChildProxyInterface; /** * GstChildProxyInterface: * @parent: parent interface type. - * @get_child_by_index: virtual method to fetch the child + * @get_child_by_name: virtual method to fetch the child by name + * @get_child_by_index: virtual method to fetch the child by index * @get_children_count: virtual method to get the children count * * #GstChildProxy interface. @@ -54,6 +55,7 @@ struct _GstChildProxyInterface GTypeInterface parent; /* methods */ + GstObject * (*get_child_by_name) (GstChildProxy * parent, const gchar * name); GstObject * (*get_child_by_index) (GstChildProxy * parent, guint index); guint (*get_children_count) (GstChildProxy * parent); /*< private >*/ -- 2.7.4