3 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
4 * 2000 Wim Taymans <wtay@chello.be>
6 * gstinterface.c: Interface functions
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * SECTION:gstimplementsinterface
26 * @short_description: Core interface implemented by #GstElement instances that
27 * allows runtime querying of interface availability
28 * @see_also: #GstElement
30 * Provides interface functionality on per instance basis and not per class
31 * basis, which is the case for gobject.
38 #include "gst_private.h"
39 #include "gstinterface.h"
42 gst_implements_interface_class_init (GstImplementsInterfaceClass * ifklass);
44 gst_implements_interface_supported_default (GstImplementsInterface * iface,
48 gst_implements_interface_get_type (void)
50 static volatile gsize gst_interface_type = 0;
52 if (g_once_init_enter (&gst_interface_type)) {
54 static const GTypeInfo gst_interface_info = {
55 sizeof (GstImplementsInterfaceClass),
56 (GBaseInitFunc) gst_implements_interface_class_init,
67 _type = g_type_register_static (G_TYPE_INTERFACE,
68 "GstImplementsInterface", &gst_interface_info, 0);
70 g_type_interface_add_prerequisite (_type, GST_TYPE_ELEMENT);
71 g_once_init_leave (&gst_interface_type, _type);
74 return gst_interface_type;
78 gst_implements_interface_class_init (GstImplementsInterfaceClass * klass)
80 klass->supported = gst_implements_interface_supported_default;
84 gst_implements_interface_supported_default (GstImplementsInterface * interface,
87 /* Well, if someone didn't set the virtual function,
88 * then something is clearly wrong. So big no-no here */
94 * gst_element_implements_interface:
95 * @element: #GstElement to check for the implementation of the interface
96 * @iface_type: (final) type of the interface which we want to be implemented
98 * Test whether the given element implements a certain interface of type
99 * iface_type, and test whether it is supported for this specific instance.
101 * Returns: whether or not the element implements the interface.
105 gst_element_implements_interface (GstElement * element, GType iface_type)
107 g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
109 if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (element), iface_type)) {
110 GstImplementsInterface *iface;
111 GstImplementsInterfaceClass *ifclass;
113 iface = G_TYPE_CHECK_INSTANCE_CAST (G_OBJECT (element),
114 iface_type, GstImplementsInterface);
115 ifclass = GST_IMPLEMENTS_INTERFACE_GET_CLASS (iface);
117 /* element implements iface_type but not GstImplementsInterface, so
118 * just assume the other interface is implemented unconditionally */
122 if (ifclass->supported != NULL &&
123 ifclass->supported (iface, iface_type) == TRUE) {
132 * gst_implements_interface_cast:
133 * @from: the object (any sort) from which to cast to the interface
134 * @type: the interface type to cast to
136 * cast a given object to an interface type, and check whether this
137 * interface is supported for this specific instance.
139 * Returns: (transfer none): a gpointer to the interface type
143 gst_implements_interface_cast (gpointer from, GType iface_type)
145 GstImplementsInterface *iface;
147 /* check cast, give warning+fail if it's invalid */
148 if (!(iface = G_TYPE_CHECK_INSTANCE_CAST (from, iface_type,
149 GstImplementsInterface))) {
153 /* if we're an element, take care that this interface
154 * is actually implemented */
155 if (GST_IS_ELEMENT (from)) {
156 g_return_val_if_fail (gst_element_implements_interface (GST_ELEMENT (from),
164 * gst_implements_interface_check:
165 * @from: the object (any sort) from which to check from for the interface
166 * @type: the interface type to check for
168 * check a given object for an interface implementation, and check
169 * whether this interface is supported for this specific instance.
171 * Returns: whether or not the object implements the given interface
175 gst_implements_interface_check (gpointer from, GType type)
177 /* check cast, return FALSE if it fails, don't give a warning... */
178 if (!G_TYPE_CHECK_INSTANCE_TYPE (from, type)) {
182 /* now, if we're an element (or derivative), is this thing
183 * actually implemented for real? */
184 if (GST_IS_ELEMENT (from)) {
185 if (!gst_element_implements_interface (GST_ELEMENT (from), type)) {