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