2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstregistry.c: handle registry
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.
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.
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.
24 #include <sys/types.h>
32 #include "gstregistry.h"
34 #include "gstmarshal.h"
36 #define CLASS(registry) GST_REGISTRY_CLASS (G_OBJECT_GET_CLASS (registry))
38 /* Element signals and args */
45 static GList *_gst_registry_pool = NULL;
46 static GList *_gst_registry_pool_plugins = NULL;
48 static void gst_registry_class_init (GstRegistryClass *klass);
49 static void gst_registry_init (GstRegistry *registry);
51 static GObjectClass *parent_class = NULL;
52 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
55 gst_registry_get_type (void)
57 static GType registry_type = 0;
60 static const GTypeInfo registry_info = {
61 sizeof (GstRegistryClass),
64 (GClassInitFunc) gst_registry_class_init,
69 (GInstanceInitFunc) gst_registry_init,
72 registry_type = g_type_register_static (G_TYPE_OBJECT, "GstRegistry",
73 ®istry_info, G_TYPE_FLAG_ABSTRACT);
79 gst_registry_class_init (GstRegistryClass *klass)
81 GObjectClass *gobject_class;
83 gobject_class = (GObjectClass*) klass;
85 parent_class = g_type_class_ref (G_TYPE_OBJECT);
87 gst_registry_signals[PLUGIN_ADDED] =
88 g_signal_new ("plugin_added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
89 G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL, NULL,
90 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
93 gobject_class->dispose = NULL;
97 gst_registry_init (GstRegistry *registry)
99 registry->priority = 0;
100 registry->loaded = FALSE;
101 registry->paths = NULL;
106 * @registry: the registry to load
108 * Load the given registry
110 * Returns: TRUE on success.
113 gst_registry_load (GstRegistry *registry)
115 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
117 if (CLASS (registry)->load)
118 return CLASS (registry)->load (registry);
124 * gst_registry_is_loaded:
125 * @registry: the registry to check
127 * Check if the given registry is loaded
129 * Returns: TRUE if loaded.
132 gst_registry_is_loaded (GstRegistry *registry)
134 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
136 return registry->loaded;
141 * @registry: the registry to save
143 * Save the contents of the given registry
145 * Returns: TRUE on success
148 gst_registry_save (GstRegistry *registry)
150 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
152 if (CLASS (registry)->save)
153 return CLASS (registry)->save (registry);
159 * gst_registry_rebuild:
160 * @registry: the registry to rebuild
162 * Rebuild the given registry
164 * Returns: TRUE on success
167 gst_registry_rebuild (GstRegistry *registry)
169 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
171 if (CLASS (registry)->rebuild)
172 return CLASS (registry)->rebuild (registry);
178 * gst_registry_unload:
179 * @registry: the registry to unload
181 * Unload the given registry
183 * Returns: TRUE on success
186 gst_registry_unload (GstRegistry *registry)
188 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
190 if (CLASS (registry)->unload)
191 return CLASS (registry)->unload (registry);
197 * gst_registry_add_path:
198 * @registry: the registry to add the path to
199 * @path: the path to add to the registry
201 * Add the given path to the registry. The syntax of the
202 * path is specific to the registry. If the path has already been
206 gst_registry_add_path (GstRegistry *registry, const gchar *path)
210 g_return_if_fail (GST_IS_REGISTRY (registry));
211 g_return_if_fail (path != NULL);
215 if (strcmp (l->data, path) == 0)
221 registry->paths = g_list_append (registry->paths, g_strdup (path));
225 * gst_registry_get_path_list:
226 * @registry: the registry to get the pathlist of
228 * Get the list of paths for the given registry.
230 * Returns: A Glist of paths as strings. g_list_free after use.
233 gst_registry_get_path_list (GstRegistry *registry)
235 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
237 return g_list_copy (registry->paths);
242 free_list_strings_func (gpointer data, gpointer user_data)
248 * gst_registry_clear_paths:
249 * @registry: the registry to clear the paths of
251 * Clear the paths of the given registry
254 gst_registry_clear_paths (GstRegistry *registry)
256 g_return_if_fail (GST_IS_REGISTRY (registry));
258 g_list_foreach (registry->paths, free_list_strings_func, NULL);
259 g_list_free (registry->paths);
261 registry->paths = NULL;
265 * gst_registry_add_plugin:
266 * @registry: the registry to add the plugin to
267 * @plugin: the plugin to add
269 * Add the plugin to the registry. The plugin-added signal
272 * Returns: TRUE on success.
275 gst_registry_add_plugin (GstRegistry *registry, GstPlugin *plugin)
277 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
279 plugin->manager = registry;
280 registry->plugins = g_list_prepend (registry->plugins, plugin);
282 g_signal_emit (G_OBJECT (registry), gst_registry_signals[PLUGIN_ADDED], 0, plugin);
288 * gst_registry_remove_plugin:
289 * @registry: the registry to remove the plugin from
290 * @plugin: the plugin to remove
292 * Remove the plugin from the registry.
295 gst_registry_remove_plugin (GstRegistry *registry, GstPlugin *plugin)
297 g_return_if_fail (GST_IS_REGISTRY (registry));
299 registry->plugins = g_list_remove (registry->plugins, plugin);
302 static GstPluginFeature*
303 gst_plugin_list_find_feature (GList *plugins, const gchar *name, GType type)
305 GstPluginFeature *feature = NULL;
308 GstPlugin *plugin = (GstPlugin *) (plugins->data);
310 feature = gst_plugin_find_feature (plugin, name, type);
314 plugins = g_list_next (plugins);
320 gst_plugin_list_find_plugin (GList *plugins, const gchar *name)
323 GstPlugin *plugin = (GstPlugin *) (plugins->data);
325 if (plugin->name && !strcmp (plugin->name, name))
328 plugins = g_list_next (plugins);
334 * gst_registry_find_plugin:
335 * @registry: the registry to search
336 * @name: the plugin name to find
338 * Find the plugin with the given name in the registry.
340 * Returns: The plugin with the given name or NULL if the plugin was not found.
343 gst_registry_find_plugin (GstRegistry *registry, const gchar *name)
345 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
346 g_return_val_if_fail (name != NULL, NULL);
348 return gst_plugin_list_find_plugin (registry->plugins, name);
352 * gst_registry_find_feature:
353 * @registry: the registry to search
354 * @name: the pluginfeature name to find
355 * @type: the pluginfeature type to find
357 * Find the pluginfeature with the given name and type in the registry.
359 * Returns: The pluginfeature with the given name and type or NULL
360 * if the plugin was not found.
363 gst_registry_find_feature (GstRegistry *registry, const gchar *name, GType type)
365 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
366 g_return_val_if_fail (name != NULL, NULL);
368 return gst_plugin_list_find_feature (registry->plugins, name, type);
373 * gst_registry_load_plugin:
374 * @registry: the registry to load the plugin from
375 * @plugin: the plugin to load
377 * Bring the plugin from the registry into memory.
379 * Returns: a value indicating the result
382 gst_registry_load_plugin (GstRegistry *registry, GstPlugin *plugin)
384 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
386 if (CLASS (registry)->load_plugin)
387 return CLASS (registry)->load_plugin (registry, plugin);
389 return GST_REGISTRY_PLUGIN_LOAD_ERROR;
393 * gst_registry_unload_plugin:
394 * @registry: the registry to unload the plugin from
395 * @plugin: the plugin to unload
397 * Unload the plugin from the given registry.
399 * Returns: a value indicating the result
402 gst_registry_unload_plugin (GstRegistry *registry, GstPlugin *plugin)
404 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
406 if (CLASS (registry)->unload_plugin)
407 return CLASS (registry)->unload_plugin (registry, plugin);
409 return GST_REGISTRY_PLUGIN_LOAD_ERROR;
413 * gst_registry_update_plugin:
414 * @registry: the registry to update
415 * @plugin: the plugin to update
417 * Update the plugin in the given registry.
419 * Returns: a value indicating the result
422 gst_registry_update_plugin (GstRegistry *registry, GstPlugin *plugin)
424 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
426 if (CLASS (registry)->update_plugin)
427 return CLASS (registry)->update_plugin (registry, plugin);
429 return GST_REGISTRY_PLUGIN_LOAD_ERROR;
433 * gst_registry_pool_list:
435 * Get a list of all registries in the pool
437 * Returns: a Glist of GstRegistries, g_list_free after use.
440 gst_registry_pool_list (void)
442 return g_list_copy (_gst_registry_pool);
446 gst_registry_compare_func (gconstpointer a, gconstpointer b)
448 return GST_REGISTRY (a)->priority - GST_REGISTRY (b)->priority;
452 * gst_registry_pool_add:
453 * @registry: the registry to add
454 * @priority: the priority of the registry
456 * Add the registry to the pool with the given priority.
459 gst_registry_pool_add (GstRegistry *registry, guint priority)
461 g_return_if_fail (GST_IS_REGISTRY (registry));
463 registry->priority = priority;
465 _gst_registry_pool = g_list_insert_sorted (_gst_registry_pool, registry, gst_registry_compare_func);
469 * gst_registry_pool_remove:
470 * @registry: the registry to remove
472 * Remove the registry from the pool.
475 gst_registry_pool_remove (GstRegistry *registry)
477 g_return_if_fail (GST_IS_REGISTRY (registry));
479 _gst_registry_pool = g_list_remove (_gst_registry_pool, registry);
483 * gst_registry_pool_add_plugin:
484 * @plugin: the plugin to add
486 * Add the plugin to the global pool of plugins.
489 gst_registry_pool_add_plugin (GstPlugin *plugin)
491 _gst_registry_pool_plugins = g_list_prepend (_gst_registry_pool_plugins, plugin);
496 * gst_registry_pool_load_all:
498 * Load all the registries in the pool. Registries with the
499 * GST_REGISTRY_DELAYED_LOADING will not be loaded.
502 gst_registry_pool_load_all (void)
504 GList *walk = _gst_registry_pool;
507 GstRegistry *registry = GST_REGISTRY (walk->data);
509 if (registry->flags & GST_REGISTRY_READABLE &&
510 !(registry->flags & GST_REGISTRY_DELAYED_LOADING)) {
511 gst_registry_load (registry);
514 walk = g_list_next (walk);
519 * gst_registry_pool_plugin_list:
521 * Get a list of all plugins in the pool.
523 * Returns: a GList of plugins, g_list_free after use.
526 gst_registry_pool_plugin_list (void)
528 GList *result = NULL;
529 GList *walk = _gst_registry_pool;
532 GstRegistry *registry = GST_REGISTRY (walk->data);
534 /* FIXME only include highest priority plugins */
535 result = g_list_concat (result, g_list_copy (registry->plugins));
537 walk = g_list_next (walk);
544 * gst_registry_pool_feature_list:
545 * @type: the type of the features to list.
547 * Get a list of all pluginfeatures of the given type in the pool.
549 * Returns: a GList of pluginfeatures, g_list_free after use.
552 gst_registry_pool_feature_list (GType type)
554 GList *result = NULL;
555 GList *plugins = gst_registry_pool_plugin_list ();
558 GstPlugin *plugin = GST_PLUGIN (plugins->data);
559 GList *features = plugin->features;
562 GstPluginFeature *feature = GST_PLUGIN_FEATURE (features->data);
564 if (type == 0 || G_OBJECT_TYPE (feature) == type) {
565 result = g_list_prepend (result, feature);
567 features = g_list_next (features);
569 plugins = g_list_next (plugins);
571 result = g_list_reverse (result);
577 * gst_registry_pool_find_plugin:
578 * @name: the name of the plugin to find
580 * Get the named plugin from the registry pool
582 * Returns: The plugin with the given name or NULL if the plugin
586 gst_registry_pool_find_plugin (const gchar *name)
588 GstPlugin *result = NULL;
591 result = gst_plugin_list_find_plugin (_gst_registry_pool_plugins, name);
595 walk = _gst_registry_pool;
598 GstRegistry *registry = GST_REGISTRY (walk->data);
600 /* FIXME only include highest priority plugins */
601 result = gst_registry_find_plugin (registry, name);
605 walk = g_list_next (walk);
611 * gst_registry_pool_find_feature:
612 * @name: the name of the pluginfeature to find
613 * @type: the type of the pluginfeature to find
615 * Get the pluginfeature with the given name and type from the pool of
618 * Returns: A pluginfeature with the given name and type or NULL if the feature
622 gst_registry_pool_find_feature (const gchar *name, GType type)
624 GstPluginFeature *result = NULL;
627 result = gst_plugin_list_find_feature (_gst_registry_pool_plugins, name, type);
631 walk = _gst_registry_pool;
634 GstRegistry *registry = GST_REGISTRY (walk->data);
636 /* FIXME only include highest priority plugins */
637 result = gst_registry_find_feature (registry, name, type);
641 walk = g_list_next (walk);
647 * gst_registry_pool_get_prefered:
648 * @flags: The flags for the prefered registry
650 * Get the prefered registry with the given flags
652 * Returns: The registry with the flags.
655 gst_registry_pool_get_prefered (GstRegistryFlags flags)
657 GList *walk = _gst_registry_pool;
660 GstRegistry *registry = GST_REGISTRY (walk->data);
662 if (registry->flags & flags)
665 walk = g_list_next (walk);