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