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