Er, plugins actually use gst_element_factory_set_rank(). Add a define to call gst_pl...
[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 static void             gst_plugin_feature_class_init           (GstPluginFeatureClass *klass);
31 static void             gst_plugin_feature_init                 (GstPluginFeature *feature);
32
33 static GObjectClass *parent_class = NULL;
34 /* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */
35
36 GType
37 gst_plugin_feature_get_type (void)
38 {
39   static GType plugin_feature_type = 0;
40
41   if (!plugin_feature_type) {
42     static const GTypeInfo plugin_feature_info = {
43       sizeof (GObjectClass),
44       NULL,
45       NULL,
46       (GClassInitFunc) gst_plugin_feature_class_init,
47       NULL,
48       NULL,
49       sizeof (GObject),
50       32,
51       (GInstanceInitFunc) gst_plugin_feature_init,
52       NULL
53     };
54     plugin_feature_type = g_type_register_static (G_TYPE_OBJECT, "GstPluginFeature", 
55                                                   &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
56   }
57   return plugin_feature_type;
58 }
59
60 static void
61 gst_plugin_feature_class_init (GstPluginFeatureClass *klass)
62 {
63   GObjectClass *gobject_class;
64
65   gobject_class = (GObjectClass*) klass;
66
67   parent_class = g_type_class_ref (G_TYPE_OBJECT);
68 }
69
70 static void
71 gst_plugin_feature_init (GstPluginFeature *feature)
72 {
73   feature->manager = NULL;
74 }
75
76 /**
77  * gst_plugin_feature_ensure_loaded:
78  * @feature: the plugin feature to check
79  *
80  * Check if the plugin containing the feature is loaded,
81  * if not, the plugin will be loaded.
82  *
83  * Returns: a boolean indicating the feature is loaded.
84  */
85 gboolean
86 gst_plugin_feature_ensure_loaded (GstPluginFeature *feature)
87 {
88   GstPlugin *plugin;
89   
90   g_return_val_if_fail (feature != NULL, FALSE);
91   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
92
93   plugin = (GstPlugin *) (feature->manager);
94
95   if (plugin && !gst_plugin_is_loaded (plugin)) {
96 #ifndef GST_DISABLE_REGISTRY 
97     if (GST_IS_REGISTRY (plugin->manager)) {
98       GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, 
99                  "loading plugin %s for feature", plugin->name);
100
101       if (gst_registry_load_plugin (GST_REGISTRY (plugin->manager), plugin) != GST_REGISTRY_OK)
102         return FALSE;
103     }
104     else
105 #endif /* GST_DISABLE_REGISTRY */
106       return FALSE;
107   }
108   return TRUE;
109 }
110
111 /**
112  * gst_plugin_feature_unload_thyself:
113  * @feature: the plugin feature to check
114  *
115  * Unload the given feature. This will decrease the refcount
116  * in the plugin and will eventually unload the plugin
117  */
118 void
119 gst_plugin_feature_unload_thyself (GstPluginFeature *feature)
120 {
121   GstPluginFeatureClass *oclass; 
122
123   g_return_if_fail (feature != NULL);
124   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
125   
126   oclass = GST_PLUGIN_FEATURE_GET_CLASS (feature);
127
128   if (oclass->unload_thyself)
129     oclass->unload_thyself (feature);
130 }
131
132 gboolean
133 gst_plugin_feature_type_name_filter (GstPluginFeature *feature,
134                                      GstTypeNameData *data)
135 {
136   return ((data->type == 0    || data->type == G_OBJECT_TYPE (feature)) &&
137           (data->name == NULL || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
138 }
139
140 /**
141  * gst_plugin_feature_set_rank:
142  * @feature: feature to rank
143  * @rank: rank value - higher number means more priority rank
144  *
145  * Specifies a rank for a plugin feature, so that autoplugging uses
146  * the most appropriate feature.
147  */
148 void
149 gst_plugin_feature_set_rank (GstPluginFeature *feature, guint16 rank)
150 {
151   g_return_if_fail (feature != NULL);
152   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
153
154   feature->rank = rank;
155 }
156