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