2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gst-register.c: Plugin subsystem for loading elements, types, and libs
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.
40 #include "gst/gst-i18n-app.h"
42 static gint num_features = 0;
43 static gint num_plugins = 0;
46 plugin_added_func (GstRegistry * registry, GstPlugin * plugin,
49 g_print (_("Added plugin %s with %d %s.\n"), plugin->desc.name,
51 ngettext ("feature", "features", plugin->numfeatures));
53 num_features += plugin->numfeatures;
58 spawn_all_in_dir (const char *dirname)
60 char *argv[2] = { NULL, NULL };
64 /* g_print("spawning all in %s\n", dirname); */
66 dir = g_dir_open (dirname, 0, NULL);
70 while ((file = g_dir_read_name (dir))) {
71 argv[0] = g_build_filename (dirname, file, NULL);
72 g_print ("running %s\n", argv[0]);
73 g_spawn_sync (NULL, argv, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL, NULL,
74 NULL, NULL, NULL, NULL);
81 main (int argc, char *argv[])
84 GList *path_spill = NULL; /* used for path spill from failing registries */
86 #ifdef GETTEXT_PACKAGE
87 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
88 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
89 textdomain (GETTEXT_PACKAGE);
93 _gst_registry_auto_load = FALSE;
94 gst_init (&argc, &argv);
96 registries = gst_registry_pool_list ();
97 registries = g_list_reverse (registries);
100 GstRegistry *registry = GST_REGISTRY (registries->data);
108 /* add spilled paths to this registry;
109 * since they're spilled they probably weren't loaded correctly
110 * so we should give a lower priority registry the chance to do them */
111 for (iter = path_spill; iter; iter = iter->next) {
112 g_print (_("Added path %s to %s \n"),
113 (const char *) iter->data, registry->name);
114 gst_registry_add_path (registry, (const gchar *) iter->data);
116 g_list_free (path_spill);
120 g_signal_connect (G_OBJECT (registry), "plugin_added",
121 G_CALLBACK (plugin_added_func), NULL);
123 if (registry->flags & GST_REGISTRY_WRITABLE) {
126 g_object_get (registry, "location", &location, NULL);
127 g_print (_("Rebuilding %s (%s) ...\n"), registry->name, location);
129 gst_registry_rebuild (registry);
130 gst_registry_save (registry);
132 g_print (_("Trying to load %s ...\n"), registry->name);
133 if (!gst_registry_load (registry)) {
134 g_print (_("Error loading %s\n"), registry->name);
135 /* move over paths from this registry to the next one */
136 path_spill = g_list_concat (path_spill,
137 gst_registry_get_path_list (registry));
138 /* this assertion triggers for a non-readable/writable user registry,
140 /* g_assert (path_spill != NULL); */
142 /* also move over paths if the registry wasn't writable
143 * FIXME: we should check if the paths that were loaded from this
144 registry get removed from the path_list so we only try to
145 spill paths that could not be registered */
146 /* Until that is done, don't spill paths when registry is not writable
147 (e.g. case of user running gst-register and sysreg not writable) */
150 path_spill = g_list_concat (path_spill,
151 gst_registry_get_path_list (registry));
155 dir_list = gst_registry_get_path_list (registry);
156 for (iter = dir_list; iter; iter = iter->next) {
158 g_build_filename ((const char *) iter->data, "register-scripts",
160 spawn_all_in_dir (dir);
163 g_list_free (dir_list);
165 registries = g_list_next (registries);
168 g_print (_("Loaded %d plugins with %d %s.\n"), num_plugins, num_features,
169 ngettext ("feature", "features", num_features));