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 | #ifdef HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | #include "gst_private.h" |
---|
27 | #include <glib.h> |
---|
28 | #include <sys/types.h> |
---|
29 | #include <sys/stat.h> |
---|
30 | #ifdef HAVE_UNISTD_H |
---|
31 | #include <unistd.h> |
---|
32 | #endif |
---|
33 | #include <errno.h> |
---|
34 | #include <stdio.h> |
---|
35 | #include <string.h> |
---|
36 | |
---|
37 | |
---|
38 | #include "gstinfo.h" |
---|
39 | #include "gstregistry.h" |
---|
40 | #include "gstregistrypool.h" |
---|
41 | #include "gstmarshal.h" |
---|
42 | #include "gstfilter.h" |
---|
43 | |
---|
44 | /* Element signals and args */ |
---|
45 | enum |
---|
46 | { |
---|
47 | PLUGIN_ADDED, |
---|
48 | LAST_SIGNAL |
---|
49 | }; |
---|
50 | |
---|
51 | static void gst_registry_class_init (GstRegistryClass * klass); |
---|
52 | static void gst_registry_init (GstRegistry * registry); |
---|
53 | |
---|
54 | static GObjectClass *parent_class = NULL; |
---|
55 | static guint gst_registry_signals[LAST_SIGNAL] = { 0 }; |
---|
56 | |
---|
57 | GType |
---|
58 | gst_registry_get_type (void) |
---|
59 | { |
---|
60 | static GType registry_type = 0; |
---|
61 | |
---|
62 | if (!registry_type) { |
---|
63 | static const GTypeInfo registry_info = { |
---|
64 | sizeof (GstRegistryClass), |
---|
65 | NULL, |
---|
66 | NULL, |
---|
67 | (GClassInitFunc) gst_registry_class_init, |
---|
68 | NULL, |
---|
69 | NULL, |
---|
70 | sizeof (GstRegistry), |
---|
71 | 0, |
---|
72 | (GInstanceInitFunc) gst_registry_init, |
---|
73 | NULL |
---|
74 | }; |
---|
75 | |
---|
76 | registry_type = g_type_register_static (G_TYPE_OBJECT, "GstRegistry", |
---|
77 | ®istry_info, G_TYPE_FLAG_ABSTRACT); |
---|
78 | } |
---|
79 | return registry_type; |
---|
80 | } |
---|
81 | |
---|
82 | static void |
---|
83 | gst_registry_class_init (GstRegistryClass * klass) |
---|
84 | { |
---|
85 | GObjectClass *gobject_class; |
---|
86 | |
---|
87 | gobject_class = (GObjectClass *) klass; |
---|
88 | |
---|
89 | parent_class = g_type_class_ref (G_TYPE_OBJECT); |
---|
90 | |
---|
91 | gst_registry_signals[PLUGIN_ADDED] = |
---|
92 | g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass), |
---|
93 | G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL, |
---|
94 | NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); |
---|
95 | |
---|
96 | gobject_class->dispose = NULL; |
---|
97 | } |
---|
98 | |
---|
99 | static void |
---|
100 | gst_registry_init (GstRegistry * registry) |
---|
101 | { |
---|
102 | registry->priority = 0; |
---|
103 | registry->loaded = FALSE; |
---|
104 | registry->paths = NULL; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * gst_registry_load: |
---|
109 | * @registry: the registry to load |
---|
110 | * |
---|
111 | * Load the given registry |
---|
112 | * |
---|
113 | * Returns: TRUE on success. |
---|
114 | */ |
---|
115 | gboolean |
---|
116 | gst_registry_load (GstRegistry * registry) |
---|
117 | { |
---|
118 | GstRegistryClass *rclass; |
---|
119 | |
---|
120 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
121 | |
---|
122 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
123 | |
---|
124 | if (rclass->load) |
---|
125 | return rclass->load (registry); |
---|
126 | |
---|
127 | return FALSE; |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * gst_registry_is_loaded: |
---|
132 | * @registry: the registry to check |
---|
133 | * |
---|
134 | * Check if the given registry is loaded |
---|
135 | * |
---|
136 | * Returns: TRUE if loaded. |
---|
137 | */ |
---|
138 | gboolean |
---|
139 | gst_registry_is_loaded (GstRegistry * registry) |
---|
140 | { |
---|
141 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
142 | |
---|
143 | return registry->loaded; |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * gst_registry_save: |
---|
148 | * @registry: the registry to save |
---|
149 | * |
---|
150 | * Save the contents of the given registry |
---|
151 | * |
---|
152 | * Returns: TRUE on success |
---|
153 | */ |
---|
154 | gboolean |
---|
155 | gst_registry_save (GstRegistry * registry) |
---|
156 | { |
---|
157 | GstRegistryClass *rclass; |
---|
158 | |
---|
159 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
160 | |
---|
161 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
162 | |
---|
163 | if (rclass->save) |
---|
164 | return rclass->save (registry); |
---|
165 | |
---|
166 | return FALSE; |
---|
167 | } |
---|
168 | |
---|
169 | /** |
---|
170 | * gst_registry_rebuild: |
---|
171 | * @registry: the registry to rebuild |
---|
172 | * |
---|
173 | * Rebuild the given registry |
---|
174 | * |
---|
175 | * Returns: TRUE on success |
---|
176 | */ |
---|
177 | gboolean |
---|
178 | gst_registry_rebuild (GstRegistry * registry) |
---|
179 | { |
---|
180 | GstRegistryClass *rclass; |
---|
181 | |
---|
182 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
183 | |
---|
184 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
185 | |
---|
186 | if (rclass->rebuild) |
---|
187 | return rclass->rebuild (registry); |
---|
188 | |
---|
189 | return FALSE; |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * gst_registry_unload: |
---|
194 | * @registry: the registry to unload |
---|
195 | * |
---|
196 | * Unload the given registry |
---|
197 | * |
---|
198 | * Returns: TRUE on success |
---|
199 | */ |
---|
200 | gboolean |
---|
201 | gst_registry_unload (GstRegistry * registry) |
---|
202 | { |
---|
203 | GstRegistryClass *rclass; |
---|
204 | |
---|
205 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
206 | |
---|
207 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
208 | |
---|
209 | if (rclass->unload) |
---|
210 | return rclass->unload (registry); |
---|
211 | |
---|
212 | return FALSE; |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * gst_registry_add_path: |
---|
217 | * @registry: the registry to add the path to |
---|
218 | * @path: the path to add to the registry |
---|
219 | * |
---|
220 | * Add the given path to the registry. The syntax of the |
---|
221 | * path is specific to the registry. If the path has already been |
---|
222 | * added, do nothing. |
---|
223 | */ |
---|
224 | void |
---|
225 | gst_registry_add_path (GstRegistry * registry, const gchar * path) |
---|
226 | { |
---|
227 | g_return_if_fail (GST_IS_REGISTRY (registry)); |
---|
228 | g_return_if_fail (path != NULL); |
---|
229 | |
---|
230 | if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp)) { |
---|
231 | g_warning ("path %s already added to registry", path); |
---|
232 | return; |
---|
233 | } |
---|
234 | |
---|
235 | registry->paths = g_list_append (registry->paths, g_strdup (path)); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * gst_registry_get_path_list: |
---|
240 | * @registry: the registry to get the pathlist of |
---|
241 | * |
---|
242 | * Get the list of paths for the given registry. |
---|
243 | * |
---|
244 | * Returns: A Glist of paths as strings. g_list_free after use. |
---|
245 | */ |
---|
246 | GList * |
---|
247 | gst_registry_get_path_list (GstRegistry * registry) |
---|
248 | { |
---|
249 | g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); |
---|
250 | |
---|
251 | return g_list_copy (registry->paths); |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | /** |
---|
256 | * gst_registry_clear_paths: |
---|
257 | * @registry: the registry to clear the paths of |
---|
258 | * |
---|
259 | * Clear the paths of the given registry |
---|
260 | */ |
---|
261 | void |
---|
262 | gst_registry_clear_paths (GstRegistry * registry) |
---|
263 | { |
---|
264 | g_return_if_fail (GST_IS_REGISTRY (registry)); |
---|
265 | |
---|
266 | g_list_foreach (registry->paths, (GFunc) g_free, NULL); |
---|
267 | g_list_free (registry->paths); |
---|
268 | |
---|
269 | registry->paths = NULL; |
---|
270 | } |
---|
271 | |
---|
272 | /** |
---|
273 | * gst_registry_add_plugin: |
---|
274 | * @registry: the registry to add the plugin to |
---|
275 | * @plugin: the plugin to add |
---|
276 | * |
---|
277 | * Add the plugin to the registry. The plugin-added signal will be emitted. |
---|
278 | * |
---|
279 | * Returns: TRUE on success. |
---|
280 | */ |
---|
281 | gboolean |
---|
282 | gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin) |
---|
283 | { |
---|
284 | g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE); |
---|
285 | if (gst_registry_pool_find_plugin (gst_plugin_get_name (plugin))) { |
---|
286 | GST_WARNING_OBJECT (registry, "Not adding plugin %s, " |
---|
287 | "because a plugin with same name already exists", |
---|
288 | gst_plugin_get_name (plugin)); |
---|
289 | return FALSE; |
---|
290 | } |
---|
291 | |
---|
292 | plugin->manager = registry; |
---|
293 | registry->plugins = g_list_prepend (registry->plugins, plugin); |
---|
294 | |
---|
295 | GST_DEBUG ("emitting plugin-added for filename %s", plugin->filename); |
---|
296 | g_signal_emit (G_OBJECT (registry), gst_registry_signals[PLUGIN_ADDED], 0, |
---|
297 | plugin); |
---|
298 | |
---|
299 | return TRUE; |
---|
300 | } |
---|
301 | |
---|
302 | /** |
---|
303 | * gst_registry_remove_plugin: |
---|
304 | * @registry: the registry to remove the plugin from |
---|
305 | * @plugin: the plugin to remove |
---|
306 | * |
---|
307 | * Remove the plugin from the registry. |
---|
308 | */ |
---|
309 | void |
---|
310 | gst_registry_remove_plugin (GstRegistry * registry, GstPlugin * plugin) |
---|
311 | { |
---|
312 | g_return_if_fail (GST_IS_REGISTRY (registry)); |
---|
313 | |
---|
314 | registry->plugins = g_list_remove (registry->plugins, plugin); |
---|
315 | } |
---|
316 | |
---|
317 | /** |
---|
318 | * gst_registry_plugin_filter: |
---|
319 | * @registry: registry to query |
---|
320 | * @filter: the filter to use |
---|
321 | * @first: only return first match |
---|
322 | * @user_data: user data passed to the filter function |
---|
323 | * |
---|
324 | * Runs a filter against all plugins in the registry and returns a GList with |
---|
325 | * the results. If the first flag is set, only the first match is |
---|
326 | * returned (as a list with a single object). |
---|
327 | * |
---|
328 | * Returns: a GList of plugins, g_list_free after use. |
---|
329 | */ |
---|
330 | GList * |
---|
331 | gst_registry_plugin_filter (GstRegistry * registry, |
---|
332 | GstPluginFilter filter, gboolean first, gpointer user_data) |
---|
333 | { |
---|
334 | g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); |
---|
335 | |
---|
336 | return gst_filter_run (registry->plugins, (GstFilterFunc) filter, first, |
---|
337 | user_data); |
---|
338 | } |
---|
339 | |
---|
340 | /** |
---|
341 | * gst_registry_feature_filter: |
---|
342 | * @registry: registry to query |
---|
343 | * @filter: the filter to use |
---|
344 | * @first: only return first match |
---|
345 | * @user_data: user data passed to the filter function |
---|
346 | * |
---|
347 | * Runs a filter against all features of the plugins in the registry |
---|
348 | * and returns a GList with the results. |
---|
349 | * If the first flag is set, only the first match is |
---|
350 | * returned (as a list with a single object). |
---|
351 | * |
---|
352 | * Returns: a GList of plugin features, g_list_free after use. |
---|
353 | */ |
---|
354 | GList * |
---|
355 | gst_registry_feature_filter (GstRegistry * registry, |
---|
356 | GstPluginFeatureFilter filter, gboolean first, gpointer user_data) |
---|
357 | { |
---|
358 | g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); |
---|
359 | |
---|
360 | return gst_plugin_list_feature_filter (registry->plugins, filter, first, |
---|
361 | user_data); |
---|
362 | } |
---|
363 | |
---|
364 | /** |
---|
365 | * gst_registry_find_plugin: |
---|
366 | * @registry: the registry to search |
---|
367 | * @name: the plugin name to find |
---|
368 | * |
---|
369 | * Find the plugin with the given name in the registry. |
---|
370 | * |
---|
371 | * Returns: The plugin with the given name or NULL if the plugin was not found. |
---|
372 | */ |
---|
373 | GstPlugin * |
---|
374 | gst_registry_find_plugin (GstRegistry * registry, const gchar * name) |
---|
375 | { |
---|
376 | GList *walk; |
---|
377 | GstPlugin *result = NULL; |
---|
378 | |
---|
379 | g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); |
---|
380 | g_return_val_if_fail (name != NULL, NULL); |
---|
381 | |
---|
382 | walk = gst_registry_plugin_filter (registry, |
---|
383 | (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name); |
---|
384 | if (walk) |
---|
385 | result = GST_PLUGIN (walk->data); |
---|
386 | |
---|
387 | g_list_free (walk); |
---|
388 | |
---|
389 | return result; |
---|
390 | } |
---|
391 | |
---|
392 | /** |
---|
393 | * gst_registry_find_feature: |
---|
394 | * @registry: the registry to search |
---|
395 | * @name: the pluginfeature name to find |
---|
396 | * @type: the pluginfeature type to find |
---|
397 | * |
---|
398 | * Find the pluginfeature with the given name and type in the registry. |
---|
399 | * |
---|
400 | * Returns: The pluginfeature with the given name and type or NULL |
---|
401 | * if the plugin was not found. |
---|
402 | */ |
---|
403 | GstPluginFeature * |
---|
404 | gst_registry_find_feature (GstRegistry * registry, const gchar * name, |
---|
405 | GType type) |
---|
406 | { |
---|
407 | GstPluginFeature *feature = NULL; |
---|
408 | GList *walk; |
---|
409 | GstTypeNameData data; |
---|
410 | |
---|
411 | g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL); |
---|
412 | g_return_val_if_fail (name != NULL, NULL); |
---|
413 | |
---|
414 | data.name = name; |
---|
415 | data.type = type; |
---|
416 | |
---|
417 | walk = gst_registry_feature_filter (registry, |
---|
418 | (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter, |
---|
419 | TRUE, &data); |
---|
420 | |
---|
421 | if (walk) |
---|
422 | feature = GST_PLUGIN_FEATURE (walk->data); |
---|
423 | |
---|
424 | g_list_free (walk); |
---|
425 | |
---|
426 | return feature; |
---|
427 | } |
---|
428 | |
---|
429 | |
---|
430 | /** |
---|
431 | * gst_registry_load_plugin: |
---|
432 | * @registry: the registry to load the plugin from |
---|
433 | * @plugin: the plugin to load |
---|
434 | * |
---|
435 | * Bring the plugin from the registry into memory. |
---|
436 | * |
---|
437 | * Returns: a value indicating the result |
---|
438 | */ |
---|
439 | GstRegistryReturn |
---|
440 | gst_registry_load_plugin (GstRegistry * registry, GstPlugin * plugin) |
---|
441 | { |
---|
442 | GstRegistryClass *rclass; |
---|
443 | |
---|
444 | g_return_val_if_fail (GST_IS_REGISTRY (registry), |
---|
445 | GST_REGISTRY_PLUGIN_LOAD_ERROR); |
---|
446 | |
---|
447 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
448 | |
---|
449 | if (rclass->load_plugin) |
---|
450 | return rclass->load_plugin (registry, plugin); |
---|
451 | |
---|
452 | return GST_REGISTRY_PLUGIN_LOAD_ERROR; |
---|
453 | } |
---|
454 | |
---|
455 | /** |
---|
456 | * gst_registry_unload_plugin: |
---|
457 | * @registry: the registry to unload the plugin from |
---|
458 | * @plugin: the plugin to unload |
---|
459 | * |
---|
460 | * Unload the plugin from the given registry. |
---|
461 | * |
---|
462 | * Returns: a value indicating the result |
---|
463 | */ |
---|
464 | GstRegistryReturn |
---|
465 | gst_registry_unload_plugin (GstRegistry * registry, GstPlugin * plugin) |
---|
466 | { |
---|
467 | GstRegistryClass *rclass; |
---|
468 | |
---|
469 | g_return_val_if_fail (GST_IS_REGISTRY (registry), |
---|
470 | GST_REGISTRY_PLUGIN_LOAD_ERROR); |
---|
471 | |
---|
472 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
473 | |
---|
474 | if (rclass->unload_plugin) |
---|
475 | return rclass->unload_plugin (registry, plugin); |
---|
476 | |
---|
477 | return GST_REGISTRY_PLUGIN_LOAD_ERROR; |
---|
478 | } |
---|
479 | |
---|
480 | /** |
---|
481 | * gst_registry_update_plugin: |
---|
482 | * @registry: the registry to update |
---|
483 | * @plugin: the plugin to update |
---|
484 | * |
---|
485 | * Update the plugin in the given registry. |
---|
486 | * |
---|
487 | * Returns: a value indicating the result |
---|
488 | */ |
---|
489 | GstRegistryReturn |
---|
490 | gst_registry_update_plugin (GstRegistry * registry, GstPlugin * plugin) |
---|
491 | { |
---|
492 | GstRegistryClass *rclass; |
---|
493 | |
---|
494 | g_return_val_if_fail (GST_IS_REGISTRY (registry), |
---|
495 | GST_REGISTRY_PLUGIN_LOAD_ERROR); |
---|
496 | |
---|
497 | rclass = GST_REGISTRY_GET_CLASS (registry); |
---|
498 | |
---|
499 | if (rclass->update_plugin) |
---|
500 | return rclass->update_plugin (registry, plugin); |
---|
501 | |
---|
502 | return GST_REGISTRY_PLUGIN_LOAD_ERROR; |
---|
503 | } |
---|