various doc updates
[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  *
88  * // presumably, we're no longer interested in the potentially-unloaded feature
89  * gst_object_unref (feature);
90  * feature = loaded_feature;
91  * </programlisting>
92  *
93  * Returns: A reference to the loaded feature, or NULL on error.
94  */
95 GstPluginFeature *
96 gst_plugin_feature_load (GstPluginFeature * feature)
97 {
98   GstPlugin *plugin;
99   GstPluginFeature *real_feature;
100
101   g_return_val_if_fail (feature != NULL, FALSE);
102   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
103
104   GST_DEBUG ("loading plugin for feature %p", feature);
105   if (feature->loaded)
106     return feature;
107
108   GST_DEBUG ("loading plugin %s", feature->plugin_name);
109   plugin = gst_plugin_load_by_name (feature->plugin_name);
110   if (!plugin) {
111     g_critical ("Failed to load plugin containing feature '%s'.",
112         GST_PLUGIN_FEATURE_NAME (feature));
113     return NULL;
114   }
115   GST_DEBUG ("loaded plugin %s", feature->plugin_name);
116   gst_object_unref (plugin);
117
118   real_feature =
119       gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
120
121   if (real_feature == NULL) {
122     g_critical
123         ("Loaded plugin containing feature '%s', but feature disappeared.",
124         feature->name);
125   }
126
127   return real_feature;
128 }
129
130 gboolean
131 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
132     GstTypeNameData * data)
133 {
134   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
135       (data->name == NULL
136           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
137 }
138
139 /**
140  * gst_plugin_feature_set_name:
141  * @feature: a feature
142  * @name: the name to set
143  *
144  * Sets the name of a plugin feature. The name uniquely identifies a feature
145  * within all features of the same type. Renaming a plugin feature is not 
146  * allowed. A copy is made of the name so you should free the supplied @name
147  * after calling this function.
148  */
149 void
150 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
151 {
152   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
153   g_return_if_fail (name != NULL);
154
155   if (feature->name) {
156     g_return_if_fail (strcmp (feature->name, name) == 0);
157   } else {
158     feature->name = g_strdup (name);
159   }
160   gst_object_set_name (GST_OBJECT (feature), feature->name);
161 }
162
163 /**
164  * gst_plugin_feature_get_name:
165  * @feature: a feature
166  *
167  * Gets the name of a plugin feature.
168  *
169  * Returns: the name
170  */
171 G_CONST_RETURN gchar *
172 gst_plugin_feature_get_name (GstPluginFeature * feature)
173 {
174   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
175
176   return feature->name;
177 }
178
179 /**
180  * gst_plugin_feature_set_rank:
181  * @feature: feature to rank
182  * @rank: rank value - higher number means more priority rank
183  *
184  * Specifies a rank for a plugin feature, so that autoplugging uses
185  * the most appropriate feature.
186  */
187 void
188 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
189 {
190   g_return_if_fail (feature != NULL);
191   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
192
193   feature->rank = rank;
194 }
195
196 /**
197  * gst_plugin_feature_get rank:
198  * @feature: a feature
199  *
200  * Gets the rank of a plugin feature.
201  *
202  * Returns: The rank of the feature
203  */
204 guint
205 gst_plugin_feature_get_rank (GstPluginFeature * feature)
206 {
207   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
208
209   return feature->rank;
210 }
211
212 /**
213  * gst_plugin_feature_list_free:
214  * @list: list of #GstPluginFeature
215  *
216  * Unrefs each member of @list, then frees the list.
217  */
218 void
219 gst_plugin_feature_list_free (GList * list)
220 {
221   GList *g;
222
223   for (g = list; g; g = g->next) {
224     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
225
226     gst_object_unref (feature);
227   }
228   g_list_free (list);
229 }