check/Makefile.am: re-enable tests now that leaks are plugged
[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 #include "gst_private.h"
24
25 #include "gstpluginfeature.h"
26 #include "gstplugin.h"
27 #include "gstregistry.h"
28 #include "gstinfo.h"
29
30 #include <string.h>
31
32 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
33 static void gst_plugin_feature_init (GstPluginFeature * feature);
34 static void gst_plugin_feature_finalize (GObject * object);
35
36 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
37
38 G_DEFINE_ABSTRACT_TYPE (GstPluginFeature, gst_plugin_feature, GST_TYPE_OBJECT);
39 GstObjectClass *parent_class = NULL;
40
41 static void
42 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
43 {
44   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
45
46   G_OBJECT_CLASS (klass)->finalize =
47       GST_DEBUG_FUNCPTR (gst_plugin_feature_finalize);
48 }
49
50 static void
51 gst_plugin_feature_init (GstPluginFeature * feature)
52 {
53
54 }
55
56 static void
57 gst_plugin_feature_finalize (GObject * object)
58 {
59   GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
60
61   GST_DEBUG ("finalizing feature %p", feature);
62   g_free (feature->name);
63   g_free (feature->plugin_name);
64
65   G_OBJECT_CLASS (parent_class)->finalize (object);
66 }
67
68 /**
69  * gst_plugin_feature_load:
70  * @feature: the plugin feature to check
71  *
72  * Check if the plugin containing the feature is loaded,
73  * if not, the plugin will be loaded.
74  *
75  * Returns: The new feature
76  */
77 GstPluginFeature *
78 gst_plugin_feature_load (GstPluginFeature * feature)
79 {
80   GstPlugin *plugin;
81   GstPluginFeature *real_feature;
82
83   g_return_val_if_fail (feature != NULL, FALSE);
84   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
85
86   GST_DEBUG ("loading plugin for feature %p", feature);
87   if (feature->loaded)
88     return feature;
89
90   GST_DEBUG ("loading plugin %s", feature->plugin_name);
91   plugin = gst_plugin_load_by_name (feature->plugin_name);
92   if (!plugin) {
93     g_critical ("Failed to load plugin containing feature '%s'.",
94         GST_PLUGIN_FEATURE_NAME (feature));
95     return NULL;
96   }
97   GST_DEBUG ("loaded plugin %s", feature->plugin_name);
98   gst_object_unref (plugin);
99
100   real_feature =
101       gst_registry_lookup_feature (gst_registry_get_default (), feature->name);
102
103   if (real_feature == NULL) {
104     g_critical
105         ("Loaded plugin containing feature '%s', but feature disappeared.",
106         feature->name);
107   }
108   gst_object_unref (feature);
109
110   return real_feature;
111 }
112
113 gboolean
114 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
115     GstTypeNameData * data)
116 {
117   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
118       (data->name == NULL
119           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
120 }
121
122 /**
123  * gst_plugin_feature_set_name:
124  * @feature: a feature
125  * @name: the name to set
126  *
127  * Sets the name of a plugin feature. The name uniquely identifies a feature
128  * within all features of the same type. Renaming a plugin feature is not 
129  * allowed. A copy is made of the name so you should free the supplied @name
130  * after calling this function.
131  */
132 void
133 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
134 {
135   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
136   g_return_if_fail (name != NULL);
137
138   if (feature->name) {
139     g_return_if_fail (strcmp (feature->name, name) == 0);
140   } else {
141     feature->name = g_strdup (name);
142   }
143   gst_object_set_name (GST_OBJECT (feature), feature->name);
144 }
145
146 /**
147  * gst_plugin_feature_get_name:
148  * @feature: a feature
149  *
150  * Gets the name of a plugin feature.
151  *
152  * Returns: the name
153  */
154 G_CONST_RETURN gchar *
155 gst_plugin_feature_get_name (GstPluginFeature * feature)
156 {
157   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
158
159   return feature->name;
160 }
161
162 /**
163  * gst_plugin_feature_set_rank:
164  * @feature: feature to rank
165  * @rank: rank value - higher number means more priority rank
166  *
167  * Specifies a rank for a plugin feature, so that autoplugging uses
168  * the most appropriate feature.
169  */
170 void
171 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
172 {
173   g_return_if_fail (feature != NULL);
174   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
175
176   feature->rank = rank;
177 }
178
179 /**
180  * gst_plugin_feature_get rank:
181  * @feature: a feature
182  *
183  * Gets the rank of a plugin feature.
184  *
185  * Returns: The rank of the feature
186  */
187 guint
188 gst_plugin_feature_get_rank (GstPluginFeature * feature)
189 {
190   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
191
192   return feature->rank;
193 }
194
195 void
196 gst_plugin_feature_list_free (GList * list)
197 {
198   GList *g;
199
200   for (g = list; g; g = g->next) {
201     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
202
203     gst_object_unref (feature);
204   }
205   g_list_free (list);
206 }