gst-indent run on core
[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       32,
54       (GInstanceInitFunc) gst_plugin_feature_init,
55       NULL
56     };
57     plugin_feature_type =
58         g_type_register_static (G_TYPE_OBJECT, "GstPluginFeature",
59         &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
60   }
61   return plugin_feature_type;
62 }
63
64 static void
65 gst_plugin_feature_class_init (GstPluginFeatureClass * klass)
66 {
67   GObjectClass *gobject_class;
68
69   gobject_class = (GObjectClass *) klass;
70
71   parent_class = g_type_class_ref (G_TYPE_OBJECT);
72 }
73
74 static void
75 gst_plugin_feature_init (GstPluginFeature * feature)
76 {
77   feature->manager = NULL;
78 }
79
80 /**
81  * gst_plugin_feature_ensure_loaded:
82  * @feature: the plugin feature to check
83  *
84  * Check if the plugin containing the feature is loaded,
85  * if not, the plugin will be loaded.
86  *
87  * Returns: a boolean indicating the feature is loaded.
88  */
89 gboolean
90 gst_plugin_feature_ensure_loaded (GstPluginFeature * feature)
91 {
92   GstPlugin *plugin;
93
94   g_return_val_if_fail (feature != NULL, FALSE);
95   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);
96
97   plugin = (GstPlugin *) (feature->manager);
98
99   if (plugin && !gst_plugin_is_loaded (plugin)) {
100 #ifndef GST_DISABLE_REGISTRY
101     if (GST_IS_REGISTRY (plugin->manager)) {
102       GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING,
103           "loading plugin %s for feature", plugin->desc.name);
104
105       if (gst_registry_load_plugin (GST_REGISTRY (plugin->manager),
106               plugin) != GST_REGISTRY_OK)
107         return FALSE;
108     } else
109 #endif /* GST_DISABLE_REGISTRY */
110       return FALSE;
111   }
112   return TRUE;
113 }
114
115 /**
116  * gst_plugin_feature_unload_thyself:
117  * @feature: the plugin feature to check
118  *
119  * Unload the given feature. This will decrease the refcount
120  * in the plugin and will eventually unload the plugin
121  */
122 void
123 gst_plugin_feature_unload_thyself (GstPluginFeature * feature)
124 {
125   GstPluginFeatureClass *oclass;
126
127   g_return_if_fail (feature != NULL);
128   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
129
130   oclass = GST_PLUGIN_FEATURE_GET_CLASS (feature);
131
132   if (oclass->unload_thyself)
133     oclass->unload_thyself (feature);
134 }
135
136 gboolean
137 gst_plugin_feature_type_name_filter (GstPluginFeature * feature,
138     GstTypeNameData * data)
139 {
140   return ((data->type == 0 || data->type == G_OBJECT_TYPE (feature)) &&
141       (data->name == NULL
142           || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
143 }
144
145 /**
146  * gst_plugin_feature_set_rank:
147  * @feature: feature to rank
148  * @rank: rank value - higher number means more priority rank
149  *
150  * Specifies a rank for a plugin feature, so that autoplugging uses
151  * the most appropriate feature.
152  */
153 void
154 gst_plugin_feature_set_rank (GstPluginFeature * feature, guint rank)
155 {
156   g_return_if_fail (feature != NULL);
157   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
158
159   feature->rank = rank;
160 }
161
162 /**
163  * gst_plugin_feature_set_name:
164  * @feature: a feature
165  * @name: the name to set
166  *
167  * Sets the name of a plugin feature. The name uniquely identifies a feature
168  * within all features of the same type. Renaming a plugin feature is not 
169  * allowed.
170  */
171 void
172 gst_plugin_feature_set_name (GstPluginFeature * feature, const gchar * name)
173 {
174   g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
175   g_return_if_fail (name != NULL);
176
177   if (feature->name) {
178     g_return_if_fail (strcmp (feature->name, name) == 0);
179   } else {
180     feature->name = g_strdup (name);
181   }
182 }
183
184 /**
185  * gst_plugin_feature_get rank:
186  * @feature: a feature
187  *
188  * Gets the rank of a plugin feature.
189  *
190  * Returns: The rank of the feature
191  */
192 guint
193 gst_plugin_feature_get_rank (GstPluginFeature * feature)
194 {
195   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
196
197   return feature->rank;
198 }
199
200 /**
201  * gst_plugin_feature_get_name:
202  * @feature: a feature
203  *
204  * Gets the name of a plugin feature.
205  *
206  * Returns: the name
207  */
208 G_CONST_RETURN gchar *
209 gst_plugin_feature_get_name (GstPluginFeature * feature)
210 {
211   g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
212
213   return feature->name;
214 }