remove
[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
35 static GObjectClass *parent_class = NULL;
36
37 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
38
39 GType
40 gst_plugin_feature_get_type (void)
41 {
42   static GType plugin_feature_type = 0;
43
44   if (!plugin_feature_type) {
45     static const GTypeInfo plugin_feature_info = {
46       sizeof (GObjectClass),
47       NULL,
48       NULL,
49       (GClassInitFunc) gst_plugin_feature_class_init,
50       NULL,
51       NULL,
52       sizeof (GObject),
53       0,
54       (GInstanceInitFunc) gst_plugin_feature_init,
55       NULL
56     };
57
58     plugin_feature_type =
59         g_type_register_static (G_TYPE_OBJECT, "GstPluginFeature",
60         &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
61   }
62   return plugin_feature_type;
63 }
64
65 static void
66 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
67 {
68   GObjectClass *gobject_class;
69
70   gobject_class = (GObjectClass *) klass;
71
72   parent_class = g_type_class_ref (G_TYPE_OBJECT);
73 }
74
75 static void
76 gst_plugin_feature_init (GstPluginFeature * feature)
77 {
78   feature->plugin = NULL;
79 }
80
81 /**
82  * gst_plugin_feature_load:
83  * @feature: the plugin feature to check
84  *
85  * Check if the plugin containing the feature is loaded,
86  * if not, the plugin will be loaded.
87  *
88  * Returns: The new feature
89  */
90 GstPluginFeature *
91 gst_plugin_feature_load (GstPluginFeature * feature)
92 {
93   GstPlugin *plugin;
94   GstPluginFeature *real_feature;
95
96   g_return_val_if_fail (feature != NULL, FALSE);
97   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
98
99   plugin = gst_plugin_load (feature->plugin);
100   if (!plugin) {
101     g_critical ("Failed to load plugin containing feature '%s'.",
102         GST_PLUGIN_FEATURE_NAME (feature));
103     return NULL;
104   }
105   if (plugin == feature->plugin) {
106     return feature;
107   }
108
109   real_feature = gst_plugin_find_feature_by_name (plugin, feature->name);
110
111   if (real_feature == NULL) {
112     g_critical
113         ("Loaded plugin containing feature '%s', but feature disappeared.",
114         feature->name);
115     return NULL;
116   }
117
118   return real_feature;
119 }
120
121 gboolean
122 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
123     GstTypeNameData * data)
124 {
125   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
126       (data->name == NULL
127           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
128 }
129
130 /**
131  * gst_plugin_feature_set_name:
132  * @feature: a feature
133  * @name: the name to set
134  *
135  * Sets the name of a plugin feature. The name uniquely identifies a feature
136  * within all features of the same type. Renaming a plugin feature is not 
137  * allowed. A copy is made of the name so you should free the supplied @name
138  * after calling this function.
139  */
140 void
141 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
142 {
143   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
144   g_return_if_fail (name != NULL);
145
146   if (feature->name) {
147     g_return_if_fail (strcmp (feature->name, name) == 0);
148   } else {
149     feature->name = g_strdup (name);
150   }
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 }