2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpluginfeature.c: Abstract base class for all plugin features
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.
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.
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.
23 #include "gst_private.h"
25 #include "gstpluginfeature.h"
26 #include "gstplugin.h"
27 #include "gstregistry.h"
32 static void gst_plugin_feature_class_init (GstPluginFeatureClass * klass);
33 static void gst_plugin_feature_init (GstPluginFeature * feature);
35 static GObjectClass *parent_class = NULL;
37 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
40 gst_plugin_feature_get_type (void)
42 static GType plugin_feature_type = 0;
44 if (!plugin_feature_type) {
45 static const GTypeInfo plugin_feature_info = {
46 sizeof (GObjectClass),
49 (GClassInitFunc) gst_plugin_feature_class_init,
54 (GInstanceInitFunc) gst_plugin_feature_init,
59 g_type_register_static (G_TYPE_OBJECT, "GstPluginFeature",
60 &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
62 return plugin_feature_type;
66 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
68 GObjectClass *gobject_class;
70 gobject_class = (GObjectClass *) klass;
72 parent_class = g_type_class_ref (G_TYPE_OBJECT);
76 gst_plugin_feature_init (GstPluginFeature * feature)
78 feature->manager = NULL;
82 * gst_plugin_feature_ensure_loaded:
83 * @feature: the plugin feature to check
85 * Check if the plugin containing the feature is loaded,
86 * if not, the plugin will be loaded.
88 * Returns: a boolean indicating the feature is loaded.
91 gst_plugin_feature_ensure_loaded (GstPluginFeature * feature)
95 g_return_val_if_fail (feature != NULL, FALSE);
96 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
98 plugin = (GstPlugin *) (feature->manager);
100 if (plugin && !gst_plugin_is_loaded (plugin)) {
101 #ifndef GST_DISABLE_REGISTRY
102 if (GST_IS_REGISTRY (plugin->manager)) {
103 GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING,
104 "loading plugin %s for feature", plugin->desc.name);
106 if (gst_registry_load_plugin (GST_REGISTRY (plugin->manager),
107 plugin) != GST_REGISTRY_OK)
110 #endif /* GST_DISABLE_REGISTRY */
117 * gst_plugin_feature_unload_thyself:
118 * @feature: the plugin feature to check
120 * Unload the given feature. This will decrease the refcount
121 * in the plugin and will eventually unload the plugin
124 gst_plugin_feature_unload_thyself (GstPluginFeature * feature)
126 GstPluginFeatureClass *oclass;
128 g_return_if_fail (feature != NULL);
129 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
131 oclass = GST_PLUGIN_FEATURE_GET_CLASS (feature);
133 if (oclass->unload_thyself)
134 oclass->unload_thyself (feature);
138 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
139 GstTypeNameData * data)
141 return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
143 || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
147 * gst_plugin_feature_set_rank:
148 * @feature: feature to rank
149 * @rank: rank value - higher number means more priority rank
151 * Specifies a rank for a plugin feature, so that autoplugging uses
152 * the most appropriate feature.
155 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
157 g_return_if_fail (feature != NULL);
158 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
160 feature->rank = rank;
164 * gst_plugin_feature_set_name:
165 * @feature: a feature
166 * @name: the name to set
168 * Sets the name of a plugin feature. The name uniquely identifies a feature
169 * within all features of the same type. Renaming a plugin feature is not
173 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
175 g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
176 g_return_if_fail (name != NULL);
179 g_return_if_fail (strcmp (feature->name, name) == 0);
181 feature->name = g_strdup (name);
186 * gst_plugin_feature_get rank:
187 * @feature: a feature
189 * Gets the rank of a plugin feature.
191 * Returns: The rank of the feature
194 gst_plugin_feature_get_rank (GstPluginFeature * feature)
196 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
198 return feature->rank;
202 * gst_plugin_feature_get_name:
203 * @feature: a feature
205 * Gets the name of a plugin feature.
209 G_CONST_RETURN gchar *
210 gst_plugin_feature_get_name (GstPluginFeature * feature)
212 g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
214 return feature->name;