don't break docs build
[platform/upstream/gstreamer.git] / gst / gstpluginfeature.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstpluginfeature.c: Abstract base class for all plugin features
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 /**
23  * SECTION:gstpluginfeature
24  * @short_description: Base class for contents of a GstPlugin
25  * @see_also: #GstPlugin
26  *
27  * This is a base class for anything that can be added to a #GstPlugin.
28  */
29
30 #include "gst_private.h"
31
32 #include "gstpluginfeature.h"
33 #include "gstplugin.h"
34 #include "gstregistry.h"
35 #include "gstinfo.h"
36
37 #include <string.h>
38
39 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
40 static void gst_plugin_feature_init (GstPluginFeature * feature);
41 static void gst_plugin_feature_finalize (GObject * object);
42
43 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
44
45 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
46 GstObjectClass *parent_class = NULL;
47
48 static void
49 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
50 {
51   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
52
53   G_OBJECT_CLASS (klass)->finalize =
54       GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
55 }
56
57 static void
58 gst_plugin_feature_init (GstPluginFeature * feature)
59 {
60
61 }
62
63 static void
64 gst_plugin_feature_finalize (GObject * object)
65 {
66   GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
67
68   GST_DEBUG ("finalizing feature %p", feature);
69   g_free (feature->name);
70   g_free (feature->plugin_name);
71
72   G_OBJECT_CLASS (parent_class)->finalize (object);
73 }
74
75 /**
76  * gst_plugin_feature_load:
77  * @feature: the plugin feature to check
78  *
79  * Loads the plugin containing @feature if it's not already loaded. @feature is
80  * unaffected; use the return value instead.
81  *
82  * Normally this function is used like this:
83  *
84  * <programlisting>
85  * GstPluginFeature *loaded_feature;
86  * loaded_feature = gst_plugin_feature_load (feature);
87  * // presumably, we're no longer interested in the potentially-unloaded feature
88  * gst_object_unref (feature);
89  * feature = loaded_feature;
90  * </programlisting>
91  *
92  * Returns: A reference to the loaded feature, or NULL on error.
93  */
94 GstPluginFeature *
95 gst_plugin_feature_load (GstPluginFeature * feature)
96 {
97   GstPlugin *plugin;
98   GstPluginFeature *real_feature;
99
100   g_return_val_if_fail (feature != NULL, FALSE);
101   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
102
103   GST_DEBUG ("loading plugin for feature %p", feature);
104   if (feature->loaded)
105     return feature;
106
107   GST_DEBUG ("loading plugin %s", feature->plugin_name);
108   plugin = gst_plugin_load_by_name (feature->plugin_name);
109   if (!plugin) {
110     g_critical ("Failed to load plugin containing feature '%s'.",
111         GST_PLUGIN_FEATURE_NAME (feature));
112     return NULL;
113   }
114   GST_DEBUG ("loaded plugin %s", feature->plugin_name);
115   gst_object_unref (plugin);
116
117   real_feature =
118       gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
119
120   if (real_feature == NULL) {
121     g_critical
122         ("Loaded plugin containing feature '%s', but feature disappeared.",
123         feature->name);
124   }
125
126   return real_feature;
127 }
128
129 gboolean
130 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
131     GstTypeNameData * data)
132 {
133   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
134       (data->name == NULL
135           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
136 }
137
138 /**
139  * gst_plugin_feature_set_name:
140  * @feature: a feature
141  * @name: the name to set
142  *
143  * Sets the name of a plugin feature. The name uniquely identifies a feature
144  * within all features of the same type. Renaming a plugin feature is not 
145  * allowed. A copy is made of the name so you should free the supplied @name
146  * after calling this function.
147  */
148 void
149 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
150 {
151   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
152   g_return_if_fail (name != NULL);
153
154   if (feature->name) {
155     g_return_if_fail (strcmp (feature->name, name) == 0);
156   } else {
157     feature->name = g_strdup (name);
158   }
159   gst_object_set_name (GST_OBJECT (feature), feature->name);
160 }
161
162 /**
163  * gst_plugin_feature_get_name:
164  * @feature: a feature
165  *
166  * Gets the name of a plugin feature.
167  *
168  * Returns: the name
169  */
170 G_CONST_RETURN gchar *
171 gst_plugin_feature_get_name (GstPluginFeature * feature)
172 {
173   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
174
175   return feature->name;
176 }
177
178 /**
179  * gst_plugin_feature_set_rank:
180  * @feature: feature to rank
181  * @rank: rank value - higher number means more priority rank
182  *
183  * Specifies a rank for a plugin feature, so that autoplugging uses
184  * the most appropriate feature.
185  */
186 void
187 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
188 {
189   g_return_if_fail (feature != NULL);
190   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
191
192   feature->rank = rank;
193 }
194
195 /**
196  * gst_plugin_feature_get rank:
197  * @feature: a feature
198  *
199  * Gets the rank of a plugin feature.
200  *
201  * Returns: The rank of the feature
202  */
203 guint
204 gst_plugin_feature_get_rank (GstPluginFeature * feature)
205 {
206   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
207
208   return feature->rank;
209 }
210
211 /**
212  * gst_plugin_feature_list_free:
213  * @list: list of #GstPluginFeature
214  *
215  * Unrefs each member of @list, then frees the list.
216  */
217 void
218 gst_plugin_feature_list_free (GList * list)
219 {
220   GList *g;
221
222   for (g = list; g; g = g->next) {
223     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
224
225     gst_object_unref (feature);
226   }
227   g_list_free (list);
228 }