childproxy: make get_child_by_name virtual

Allows implementations to use custom name->object mappings.
This commit is contained in:
Stefan Sauer 2012-03-30 22:01:55 +02:00
parent bd625b8152
commit ef48cff3d0
2 changed files with 40 additions and 21 deletions

View file

@ -39,9 +39,7 @@
* "child1" and "child2" implement the #GstChildProxy interface. * "child1" and "child2" implement the #GstChildProxy interface.
*/ */
/* FIXME-0.11: /* FIXME-0.11:
* it would be nice to make gst_child_proxy_get_child_by_name virtual too and * it would be nice to use GObject instead of GstObject.
* use GObject instead of GstObject. We could eventually provide the current
* implementation as a default if children are GstObjects.
* This change would allow to propose the interface for inclusion with * This change would allow to propose the interface for inclusion with
* glib/gobject. IMHO this is useful for GtkContainer and compound widgets too. * glib/gobject. IMHO this is useful for GtkContainer and compound widgets too.
*/ */
@ -61,22 +59,9 @@ enum
static guint signals[LAST_SIGNAL] = { 0 }; static guint signals[LAST_SIGNAL] = { 0 };
/** static GstObject *
* gst_child_proxy_get_child_by_name: gst_child_proxy_default_get_child_by_name (GstChildProxy * parent,
* @parent: the parent object to get the child from const gchar * name)
* @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)
{ {
guint count, i; guint count, i;
GstObject *object, *result; GstObject *object, *result;
@ -113,6 +98,30 @@ gst_child_proxy_get_child_by_name (GstChildProxy * parent, const gchar * name)
return result; 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: * gst_child_proxy_get_child_by_index:
* @parent: the parent object to get the child from * @parent: the parent object to get the child from
@ -467,6 +476,14 @@ gst_child_proxy_child_removed (GstObject * object, GstObject * child)
/* gobject methods */ /* 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 static void
gst_child_proxy_base_init (gpointer g_class) gst_child_proxy_base_init (gpointer g_class)
{ {
@ -515,7 +532,7 @@ gst_child_proxy_get_type (void)
sizeof (GstChildProxyInterface), sizeof (GstChildProxyInterface),
gst_child_proxy_base_init, /* base_init */ gst_child_proxy_base_init, /* base_init */
NULL, /* base_finalize */ NULL, /* base_finalize */
NULL, /* class_init */ gst_child_proxy_class_init, /* class_init */
NULL, /* class_finalize */ NULL, /* class_finalize */
NULL, /* class_data */ NULL, /* class_data */
0, 0,

View file

@ -44,7 +44,8 @@ typedef struct _GstChildProxyInterface GstChildProxyInterface;
/** /**
* GstChildProxyInterface: * GstChildProxyInterface:
* @parent: parent interface type. * @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 * @get_children_count: virtual method to get the children count
* *
* #GstChildProxy interface. * #GstChildProxy interface.
@ -54,6 +55,7 @@ struct _GstChildProxyInterface
GTypeInterface parent; GTypeInterface parent;
/* methods */ /* methods */
GstObject * (*get_child_by_name) (GstChildProxy * parent, const gchar * name);
GstObject * (*get_child_by_index) (GstChildProxy * parent, guint index); GstObject * (*get_child_by_index) (GstChildProxy * parent, guint index);
guint (*get_children_count) (GstChildProxy * parent); guint (*get_children_count) (GstChildProxy * parent);
/*< private >*/ /*< private >*/