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.
28 #include "gstinterface.h"
32 gst_implements_interface_class_init (GstImplementsInterfaceClass *ifklass);
34 gst_implements_interface_supported_default (GstImplementsInterface *iface,
38 gst_implements_interface_get_type (void)
40 static GType gst_interface_type = 0;
42 if (!gst_interface_type) {
43 static const GTypeInfo gst_interface_info = {
44 sizeof (GstImplementsInterfaceClass),
45 (GBaseInitFunc) gst_implements_interface_class_init,
56 gst_interface_type = g_type_register_static (G_TYPE_INTERFACE,
57 "GstImplementsInterface",
58 &gst_interface_info, 0);
60 g_type_interface_add_prerequisite (gst_interface_type,
64 return gst_interface_type;
68 gst_implements_interface_class_init (GstImplementsInterfaceClass *klass)
70 klass->supported = gst_implements_interface_supported_default;
74 gst_implements_interface_supported_default (GstImplementsInterface *interface,
77 /* Well, if someone didn't set the virtual function,
78 * then something is clearly wrong. So big no-no here */
84 * gst_element_implements_interface:
85 * @element: #GstElement to check for the implementation of the interface
86 * @iface_type: (final) type of the interface which we want to be implemented
88 * Test whether the given element implements a certain interface of type
89 * iface_type, and test whether it is supported for this specific instance.
93 gst_element_implements_interface (GstElement *element,
96 if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (element),
98 GstImplementsInterface *iface;
99 GstImplementsInterfaceClass *ifclass;
101 iface = G_TYPE_CHECK_INSTANCE_CAST (G_OBJECT (element),
102 iface_type, GstImplementsInterface);
103 ifclass = GST_IMPLEMENTS_INTERFACE_GET_CLASS (iface);
105 if (ifclass->supported != NULL &&
106 ifclass->supported (iface, iface_type) == TRUE) {
115 * gst_implements_interface_cast:
116 * @from: the object (any sort) from which to cast to the interface
117 * @type: the interface type to cast to
119 * cast a given object to an interface type, and check whether this
120 * interface is supported for this specific instance.
124 gst_implements_interface_cast (gpointer from,
127 GstImplementsInterface *iface;
129 /* check cast, give warning+fail if it's invalid */
130 if (!(iface = G_TYPE_CHECK_INSTANCE_CAST (from, iface_type,
131 GstImplementsInterface))) {
135 /* if we're an element, take care that this interface
136 * is actually implemented */
137 if (GST_IS_ELEMENT (from)) {
138 g_return_val_if_fail (
139 gst_element_implements_interface (GST_ELEMENT (from), iface_type),
147 * gst_implements_interface_cast:
148 * @from: the object (any sort) from which to check from for the interface
149 * @type: the interface type to check for
151 * check a given object for an interface implementation, and check
152 * whether this interface is supported for this specific instance.
156 gst_implements_interface_check (gpointer from,
159 GstImplementsInterface *iface;
161 /* check cast, return FALSE if it fails, don't give a warning... */
162 if (!G_TYPE_CHECK_INSTANCE_TYPE (from, type)) {
166 iface = G_TYPE_CHECK_INSTANCE_CAST (from, type, GstImplementsInterface);
168 /* now, if we're an element (or derivative), is this thing
169 * actually implemented for real? */
170 if (GST_IS_ELEMENT (from)) {
171 if (!gst_element_implements_interface (GST_ELEMENT (from), type)) {