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>
31 #include "gst_private.h"
34 #include "gstregistry.h"
36 #include "gstmarshal.h"
37 #include "gstfilter.h"
39 /* Element signals and args */
45 static void gst_registry_class_init (GstRegistryClass *klass);
46 static void gst_registry_init (GstRegistry *registry);
48 static GObjectClass *parent_class = NULL;
49 static guint gst_registry_signals[LAST_SIGNAL] = { 0 };
52 gst_registry_get_type (void)
54 static GType registry_type = 0;
57 static const GTypeInfo registry_info = {
58 sizeof (GstRegistryClass),
61 (GClassInitFunc) gst_registry_class_init,
66 (GInstanceInitFunc) gst_registry_init,
69 registry_type = g_type_register_static (G_TYPE_OBJECT, "GstRegistry",
70 ®istry_info, G_TYPE_FLAG_ABSTRACT);
76 gst_registry_class_init (GstRegistryClass *klass)
78 GObjectClass *gobject_class;
80 gobject_class = (GObjectClass*) klass;
82 parent_class = g_type_class_ref (G_TYPE_OBJECT);
84 gst_registry_signals[PLUGIN_ADDED] =
85 g_signal_new ("plugin_added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
86 G_STRUCT_OFFSET (GstRegistryClass, plugin_added), NULL, NULL,
87 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
90 gobject_class->dispose = NULL;
94 gst_registry_init (GstRegistry *registry)
96 registry->priority = 0;
97 registry->loaded = FALSE;
98 registry->paths = NULL;
103 * @registry: the registry to load
105 * Load the given registry
107 * Returns: TRUE on success.
110 gst_registry_load (GstRegistry *registry)
112 GstRegistryClass *rclass;
114 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
116 rclass = GST_REGISTRY_GET_CLASS (registry);
119 return rclass->load (registry);
125 * gst_registry_is_loaded:
126 * @registry: the registry to check
128 * Check if the given registry is loaded
130 * Returns: TRUE if loaded.
133 gst_registry_is_loaded (GstRegistry *registry)
135 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
137 return registry->loaded;
142 * @registry: the registry to save
144 * Save the contents of the given registry
146 * Returns: TRUE on success
149 gst_registry_save (GstRegistry *registry)
151 GstRegistryClass *rclass;
153 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
155 rclass = GST_REGISTRY_GET_CLASS (registry);
158 return rclass->save (registry);
164 * gst_registry_rebuild:
165 * @registry: the registry to rebuild
167 * Rebuild the given registry
169 * Returns: TRUE on success
172 gst_registry_rebuild (GstRegistry *registry)
174 GstRegistryClass *rclass;
176 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
178 rclass = GST_REGISTRY_GET_CLASS (registry);
181 return rclass->rebuild (registry);
187 * gst_registry_unload:
188 * @registry: the registry to unload
190 * Unload the given registry
192 * Returns: TRUE on success
195 gst_registry_unload (GstRegistry *registry)
197 GstRegistryClass *rclass;
199 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
201 rclass = GST_REGISTRY_GET_CLASS (registry);
204 return rclass->unload (registry);
210 * gst_registry_add_path:
211 * @registry: the registry to add the path to
212 * @path: the path to add to the registry
214 * Add the given path to the registry. The syntax of the
215 * path is specific to the registry. If the path has already been
219 gst_registry_add_path (GstRegistry *registry, const gchar *path)
221 g_return_if_fail (GST_IS_REGISTRY (registry));
222 g_return_if_fail (path != NULL);
224 if (g_list_find_custom (registry->paths, path, (GCompareFunc) strcmp)) {
225 g_warning ("path %s already added to registry", path);
229 registry->paths = g_list_append (registry->paths, g_strdup (path));
233 * gst_registry_get_path_list:
234 * @registry: the registry to get the pathlist of
236 * Get the list of paths for the given registry.
238 * Returns: A Glist of paths as strings. g_list_free after use.
241 gst_registry_get_path_list (GstRegistry *registry)
243 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
245 return g_list_copy (registry->paths);
250 * gst_registry_clear_paths:
251 * @registry: the registry to clear the paths of
253 * Clear the paths of the given registry
256 gst_registry_clear_paths (GstRegistry *registry)
258 g_return_if_fail (GST_IS_REGISTRY (registry));
260 g_list_foreach (registry->paths, (GFunc) g_free, NULL);
261 g_list_free (registry->paths);
263 registry->paths = NULL;
267 * gst_registry_add_plugin:
268 * @registry: the registry to add the plugin to
269 * @plugin: the plugin to add
271 * Add the plugin to the registry. The plugin-added signal
274 * Returns: TRUE on success.
277 gst_registry_add_plugin (GstRegistry *registry, GstPlugin *plugin)
279 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
281 plugin->manager = registry;
282 registry->plugins = g_list_prepend (registry->plugins, plugin);
284 g_signal_emit (G_OBJECT (registry), gst_registry_signals[PLUGIN_ADDED], 0, plugin);
290 * gst_registry_remove_plugin:
291 * @registry: the registry to remove the plugin from
292 * @plugin: the plugin to remove
294 * Remove the plugin from the registry.
297 gst_registry_remove_plugin (GstRegistry *registry, GstPlugin *plugin)
299 g_return_if_fail (GST_IS_REGISTRY (registry));
301 registry->plugins = g_list_remove (registry->plugins, plugin);
305 * gst_registry_plugin_filter:
306 * @registry: registry to query
307 * @filter: the filter to use
308 * @first: only return first match
309 * @user_data: user data passed to the filter function
311 * Runs a filter against all plugins in the registry and returns a GList with
312 * the results. If the first flag is set, only the first match is
313 * returned (as a list with a single object).
315 * Returns: a GList of plugins, g_list_free after use.
318 gst_registry_plugin_filter (GstRegistry *registry,
319 GstPluginFilter filter,
323 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
325 return gst_filter_run (registry->plugins, (GstFilterFunc) filter, first, user_data);
329 * gst_registry_feature_filter:
330 * @registry: registry to query
331 * @filter: the filter to use
332 * @first: only return first match
333 * @user_data: user data passed to the filter function
335 * Runs a filter against all features of the plugins in the registry
336 * and returns a GList with the results.
337 * If the first flag is set, only the first match is
338 * returned (as a list with a single object).
340 * Returns: a GList of plugin features, g_list_free after use.
343 gst_registry_feature_filter (GstRegistry *registry,
344 GstPluginFeatureFilter filter,
348 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
350 return gst_plugin_list_feature_filter (registry->plugins, filter, first, user_data);
354 * gst_registry_find_plugin:
355 * @registry: the registry to search
356 * @name: the plugin name to find
358 * Find the plugin with the given name in the registry.
360 * Returns: The plugin with the given name or NULL if the plugin was not found.
363 gst_registry_find_plugin (GstRegistry *registry, const gchar *name)
366 GstPlugin *result = NULL;
368 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
369 g_return_val_if_fail (name != NULL, NULL);
371 walk = gst_registry_plugin_filter (registry,
372 (GstPluginFilter) gst_plugin_name_filter,
376 result = GST_PLUGIN (walk->data);
384 * gst_registry_find_feature:
385 * @registry: the registry to search
386 * @name: the pluginfeature name to find
387 * @type: the pluginfeature type to find
389 * Find the pluginfeature with the given name and type in the registry.
391 * Returns: The pluginfeature with the given name and type or NULL
392 * if the plugin was not found.
395 gst_registry_find_feature (GstRegistry *registry, const gchar *name, GType type)
397 GstPluginFeature *feature = NULL;
399 GstTypeNameData data;
401 g_return_val_if_fail (GST_IS_REGISTRY (registry), NULL);
402 g_return_val_if_fail (name != NULL, NULL);
407 walk = gst_registry_feature_filter (registry,
408 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
413 feature = GST_PLUGIN_FEATURE (walk->data);
422 * gst_registry_load_plugin:
423 * @registry: the registry to load the plugin from
424 * @plugin: the plugin to load
426 * Bring the plugin from the registry into memory.
428 * Returns: a value indicating the result
431 gst_registry_load_plugin (GstRegistry *registry, GstPlugin *plugin)
433 GstRegistryClass *rclass;
435 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
437 rclass = GST_REGISTRY_GET_CLASS (registry);
439 if (rclass->load_plugin)
440 return rclass->load_plugin (registry, plugin);
442 return GST_REGISTRY_PLUGIN_LOAD_ERROR;
446 * gst_registry_unload_plugin:
447 * @registry: the registry to unload the plugin from
448 * @plugin: the plugin to unload
450 * Unload the plugin from the given registry.
452 * Returns: a value indicating the result
455 gst_registry_unload_plugin (GstRegistry *registry, GstPlugin *plugin)
457 GstRegistryClass *rclass;
459 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
461 rclass = GST_REGISTRY_GET_CLASS (registry);
463 if (rclass->unload_plugin)
464 return rclass->unload_plugin (registry, plugin);
466 return GST_REGISTRY_PLUGIN_LOAD_ERROR;
470 * gst_registry_update_plugin:
471 * @registry: the registry to update
472 * @plugin: the plugin to update
474 * Update the plugin in the given registry.
476 * Returns: a value indicating the result
479 gst_registry_update_plugin (GstRegistry *registry, GstPlugin *plugin)
481 GstRegistryClass *rclass;
483 g_return_val_if_fail (GST_IS_REGISTRY (registry), GST_REGISTRY_PLUGIN_LOAD_ERROR);
485 rclass = GST_REGISTRY_GET_CLASS (registry);
487 if (rclass->update_plugin)
488 return rclass->update_plugin (registry, plugin);
490 return GST_REGISTRY_PLUGIN_LOAD_ERROR;