fix doc build fix autogen
[platform/upstream/gstreamer.git] / gst / gstregistrypool.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstregistry.c: handle registry
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 <string.h>
24
25 #include "gst_private.h"
26
27 #include "gstinfo.h"
28 #include "gstregistrypool.h"
29 #include "gstlog.h"
30 #include "gstfilter.h"
31
32 /* list of registries in the pool */
33 static GList *_gst_registry_pool = NULL;
34 /* list of plugins without a registry, like statically linked
35  * plugins */
36 static GList *_gst_registry_pool_plugins = NULL;
37
38 /**
39  * gst_registry_pool_list:
40  *
41  * Get a list of all registries in the pool
42  *
43  * Returns: a Glist of GstRegistries, g_list_free after use.
44  */
45 GList*
46 gst_registry_pool_list (void)
47 {
48   return g_list_copy (_gst_registry_pool);
49 }
50
51 #ifndef GST_DISABLE_REGISTRY
52 static gint
53 gst_registry_compare_func (gconstpointer a, gconstpointer b)
54 {
55   return GST_REGISTRY (a)->priority - GST_REGISTRY (b)->priority;
56 }
57
58 /**
59  * gst_registry_pool_add:
60  * @registry: the registry to add
61  * @priority: the priority of the registry
62  *
63  * Add the registry to the pool with the given priority.
64  */
65 void
66 gst_registry_pool_add (GstRegistry *registry, guint priority)
67 {
68   g_return_if_fail (GST_IS_REGISTRY (registry));
69
70   registry->priority = priority;
71
72   _gst_registry_pool = g_list_insert_sorted (_gst_registry_pool, registry, gst_registry_compare_func);
73 }
74
75 /**
76  * gst_registry_pool_remove:
77  * @registry: the registry to remove
78  *
79  * Remove the registry from the pool.
80  */
81 void
82 gst_registry_pool_remove (GstRegistry *registry)
83 {
84   g_return_if_fail (GST_IS_REGISTRY (registry));
85
86   _gst_registry_pool = g_list_remove (_gst_registry_pool, registry);
87 }
88 #endif /* GST_DISABLE_REGISTRY */
89
90 /**
91  * gst_registry_pool_add_plugin:
92  * @plugin: the plugin to add
93  *
94  * Add the plugin to the global pool of plugins.
95  */
96 void
97 gst_registry_pool_add_plugin (GstPlugin *plugin)
98 {
99   _gst_registry_pool_plugins = g_list_prepend (_gst_registry_pool_plugins, plugin);
100 }
101
102 #ifndef GST_DISABLE_REGISTRY
103 static void
104 _registry_load_func (GstRegistry *registry, gpointer user_data)
105 {
106   if (!(registry->flags & GST_REGISTRY_DELAYED_LOADING)) {
107     gst_registry_load (registry);
108   }
109 }
110 #endif /* GST_DISABLE_REGISTRY */
111
112 /**
113  * gst_registry_pool_load_all:
114  *
115  * Load all the registries in the pool. Registries with the
116  * GST_REGISTRY_DELAYED_LOADING will not be loaded.
117  */
118 void
119 gst_registry_pool_load_all (void)
120 {
121 #ifndef GST_DISABLE_REGISTRY
122   g_list_foreach (_gst_registry_pool, (GFunc) _registry_load_func, NULL);
123 #endif /* GST_DISABLE_REGISTRY */
124 }
125
126 /**
127  * gst_registry_pool_plugin_list:
128  *
129  * Get a list of all plugins in the pool.
130  * 
131  * Returns: a GList of plugins, g_list_free after use.
132  */
133 GList*
134 gst_registry_pool_plugin_list (void)
135 {
136   return gst_registry_pool_plugin_filter (NULL, FALSE, NULL);
137 }
138
139 /**
140  * gst_registry_pool_plugin_filter:
141  * @filter: the filter to use
142  * @first: only return first match
143  * @user_data: user data passed to the filter function
144  *
145  * Runs a filter against all plugins in all registries and returns a GList with
146  * the results. If the first flag is set, only the first match is 
147  * returned (as a list with a single object).
148  *
149  * Returns: a GList of plugins, g_list_free after use.
150  */
151 GList*
152 gst_registry_pool_plugin_filter (GstPluginFilter filter, gboolean first, gpointer user_data)
153 {
154   GList *result = NULL;
155   GList *walk, *temp;
156   
157 #ifndef GST_DISABLE_REGISTRY
158   walk = _gst_registry_pool;
159
160   while (walk) {
161     GstRegistry *registry = GST_REGISTRY (walk->data);
162
163     temp = gst_registry_plugin_filter (registry, filter, first, user_data);
164     if (temp && first)
165       return temp;
166
167     result = g_list_concat (result, temp);
168     
169     walk = g_list_next (walk);
170   }
171 #endif /* GST_DISABLE_REGISTRY */
172
173   temp = gst_filter_run (_gst_registry_pool_plugins, (GstFilterFunc) filter, first, user_data);
174
175   result = g_list_concat (result, temp);
176
177   return result;
178 }
179
180 /**
181  * gst_registry_pool_feature_list:
182  * @type: the type of the features to list.
183  *
184  * Get a list of all pluginfeatures of the given type in the pool.
185  * 
186  * Returns: a GList of pluginfeatures, g_list_free after use.
187  */
188 GList*
189 gst_registry_pool_feature_list (GType type)
190 {
191   GstTypeNameData data;
192
193   data.name = NULL;
194   data.type = type;
195
196   return gst_registry_pool_feature_filter (
197                   (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter, 
198                   FALSE,
199                   &data);
200 }
201
202 /**
203  * gst_registry_pool_feature_filter:
204  * @filter: the filter to apply to the feature list
205  * @first: return the first matching feature
206  * @user_data: data passed to the filter function
207  *
208  * Apply the filter function to all features and return a list
209  * of those features that satisfy the filter. If the first flag
210  * is TRUE, only the first match is returned in a GList with
211  * one element.
212  * 
213  * Returns: a GList of pluginfeatures, g_list_free after use.
214  */
215 GList*
216 gst_registry_pool_feature_filter (GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
217 {
218   GList *result = NULL;
219   GList *walk, *temp;
220   
221 #ifndef GST_DISABLE_REGISTRY
222   walk = _gst_registry_pool;
223
224   while (walk) {
225     GstRegistry *registry = GST_REGISTRY (walk->data);
226
227     temp = gst_registry_feature_filter (registry, filter, first, user_data);
228     if (temp && first)
229       return temp;
230
231     result = g_list_concat (result, temp);
232     
233     walk = g_list_next (walk);
234   }
235 #endif /* GST_DISABLE_REGISTRY */
236
237   temp = gst_plugin_list_feature_filter (_gst_registry_pool_plugins, filter, first, user_data);
238
239   result = g_list_concat (result, temp);
240
241   return result;
242 }
243
244 /**
245  * gst_registry_pool_find_plugin:
246  * @name: the name of the plugin to find
247  *
248  * Get the named plugin from the registry pool
249  * 
250  * Returns: The plugin with the given name or NULL if the plugin 
251  * was not found.
252  */
253 GstPlugin*
254 gst_registry_pool_find_plugin (const gchar *name)
255 {
256   GstPlugin *result = NULL;
257   GList *walk;
258
259   g_return_val_if_fail (name != NULL, NULL);
260   
261   walk = gst_registry_pool_plugin_filter ((GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
262
263   if (walk)
264     result = GST_PLUGIN (walk->data);
265
266   g_list_free (walk);
267   
268   return result;
269 }
270
271 /**
272  * gst_registry_pool_find_feature:
273  * @name: the name of the pluginfeature to find
274  * @type: the type of the pluginfeature to find
275  *
276  * Get the pluginfeature with the given name and type from the pool of
277  * registries.
278  * 
279  * Returns: A pluginfeature with the given name and type or NULL if the feature
280  * was not found.
281  */
282 GstPluginFeature*
283 gst_registry_pool_find_feature (const gchar *name, GType type)
284 {
285   GstPluginFeature *result = NULL;
286   GList *walk;
287   GstTypeNameData data;
288
289   g_return_val_if_fail (name != NULL, NULL);
290
291   data.type = type;
292   data.name = name;
293
294   walk = gst_registry_pool_feature_filter ((GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
295                                            TRUE, &data);
296   
297   if (walk) 
298     result = GST_PLUGIN_FEATURE (walk->data);
299
300   g_list_free (walk);
301
302   return result;
303 }
304
305 /**
306  * gst_registry_pool_get_prefered:
307  * @flags: The flags for the prefered registry
308  *
309  * Get the prefered registry with the given flags
310  * 
311  * Returns: The registry with the flags.
312  */
313 GstRegistry*
314 gst_registry_pool_get_prefered (GstRegistryFlags flags)
315 {
316 #ifndef GST_DISABLE_REGISTRY
317   GList *walk = _gst_registry_pool;
318
319   while (walk) {
320     GstRegistry *registry = GST_REGISTRY (walk->data);
321
322     if (registry->flags & flags)
323       return registry;
324     
325     walk = g_list_next (walk);
326   }
327 #endif /* GST_DISABLE_REGISTRY */
328   return NULL;
329 }