source: trunk/third/gstreamer/gst/gstinterface.c @ 21005

Revision 21005, 4.9 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/* GStreamer
2 *
3 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
4 *                    2000 Wim Taymans <wtay@chello.be>
5 *
6 * gstinterface.c: Interface functions
7 *
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.
12 *
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.
17 *
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.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "gst_private.h"
29#include "gstinterface.h"
30
31static void
32gst_implements_interface_class_init (GstImplementsInterfaceClass * ifklass);
33static gboolean
34gst_implements_interface_supported_default (GstImplementsInterface * iface,
35    GType iface_type);
36
37GType
38gst_implements_interface_get_type (void)
39{
40  static GType gst_interface_type = 0;
41
42  if (!gst_interface_type) {
43    static const GTypeInfo gst_interface_info = {
44      sizeof (GstImplementsInterfaceClass),
45      (GBaseInitFunc) gst_implements_interface_class_init,
46      NULL,
47      NULL,
48      NULL,
49      NULL,
50      0,
51      0,
52      NULL,
53      NULL
54    };
55
56    gst_interface_type = g_type_register_static (G_TYPE_INTERFACE,
57        "GstImplementsInterface", &gst_interface_info, 0);
58
59    g_type_interface_add_prerequisite (gst_interface_type, GST_TYPE_ELEMENT);
60  }
61
62  return gst_interface_type;
63}
64
65static void
66gst_implements_interface_class_init (GstImplementsInterfaceClass * klass)
67{
68  klass->supported = gst_implements_interface_supported_default;
69}
70
71static gboolean
72gst_implements_interface_supported_default (GstImplementsInterface * interface,
73    GType iface_type)
74{
75  /* Well, if someone didn't set the virtual function,
76   * then something is clearly wrong. So big no-no here */
77
78  return FALSE;
79}
80
81/**
82 * gst_element_implements_interface:
83 * @element: #GstElement to check for the implementation of the interface
84 * @iface_type: (final) type of the interface which we want to be implemented
85 *
86 * Test whether the given element implements a certain interface of type
87 * iface_type, and test whether it is supported for this specific instance.
88 *
89 * Returns: whether or not the element implements the interface.
90 */
91
92gboolean
93gst_element_implements_interface (GstElement * element, GType iface_type)
94{
95  if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (element), iface_type)) {
96    GstImplementsInterface *iface;
97    GstImplementsInterfaceClass *ifclass;
98
99    iface = G_TYPE_CHECK_INSTANCE_CAST (G_OBJECT (element),
100        iface_type, GstImplementsInterface);
101    ifclass = GST_IMPLEMENTS_INTERFACE_GET_CLASS (iface);
102
103    if (ifclass->supported != NULL &&
104        ifclass->supported (iface, iface_type) == TRUE) {
105      return TRUE;
106    }
107  }
108
109  return FALSE;
110}
111
112/**
113 * gst_implements_interface_cast:
114 * @from: the object (any sort) from which to cast to the interface
115 * @type: the interface type to cast to
116 *
117 * cast a given object to an interface type, and check whether this
118 * interface is supported for this specific instance.
119 *
120 * Returns: a gpointer to the interface type
121 */
122
123gpointer
124gst_implements_interface_cast (gpointer from, GType iface_type)
125{
126  GstImplementsInterface *iface;
127
128  /* check cast, give warning+fail if it's invalid */
129  if (!(iface = G_TYPE_CHECK_INSTANCE_CAST (from, iface_type,
130              GstImplementsInterface))) {
131    return NULL;
132  }
133
134  /* if we're an element, take care that this interface
135   * is actually implemented */
136  if (GST_IS_ELEMENT (from)) {
137    g_return_val_if_fail (gst_element_implements_interface (GST_ELEMENT (from),
138            iface_type), NULL);
139  }
140
141  return iface;
142}
143
144/**
145 * gst_implements_interface_check:
146 * @from: the object (any sort) from which to check from for the interface
147 * @type: the interface type to check for
148 *
149 * check a given object for an interface implementation, and check
150 * whether this interface is supported for this specific instance.
151 *
152 * Returns: whether or not the object implements the given interface
153 */
154
155gboolean
156gst_implements_interface_check (gpointer from, GType type)
157{
158  GstImplementsInterface *iface;
159
160  /* check cast, return FALSE if it fails, don't give a warning... */
161  if (!G_TYPE_CHECK_INSTANCE_TYPE (from, type)) {
162    return FALSE;
163  }
164
165  iface = G_TYPE_CHECK_INSTANCE_CAST (from, type, GstImplementsInterface);
166
167  /* now, if we're an element (or derivative), is this thing
168   * actually implemented for real? */
169  if (GST_IS_ELEMENT (from)) {
170    if (!gst_element_implements_interface (GST_ELEMENT (from), type)) {
171      return FALSE;
172    }
173  }
174
175  return TRUE;
176}
Note: See TracBrowser for help on using the repository browser.