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.
38 extern gboolean _gst_registry_auto_load;
39 static gint num_features = 0;
40 static gint num_plugins = 0;
43 plugin_added_func (GstRegistry *registry, GstPlugin *plugin, gpointer user_data)
45 g_print ("added plugin %s with %d feature(s)\n", plugin->desc.name,
48 num_features += plugin->numfeatures;
53 spawn_all_in_dir(const char *dirname)
55 char *argv[2] = { NULL, NULL };
59 /* g_print("spawning all in %s\n", dirname); */
61 dir = g_dir_open (dirname, 0, NULL);
62 if (dir == NULL) return;
64 while( (file = g_dir_read_name (dir)) ){
65 argv[0] = g_build_filename(dirname, file, NULL);
66 g_print("running %s\n",argv[0]);
67 g_spawn_sync (NULL, argv, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL, NULL, NULL, NULL, NULL, NULL);
73 int main (int argc,char *argv[])
76 GList *path_spill = NULL; /* used for path spill from failing registries */
78 setlocale(LC_ALL, "");
81 _gst_registry_auto_load = FALSE;
82 gst_init (&argc, &argv);
84 registries = gst_registry_pool_list ();
85 registries = g_list_reverse (registries);
88 GstRegistry *registry = GST_REGISTRY (registries->data);
97 /* add spilled paths to this registry;
98 * since they're spilled they probably weren't loaded correctly
99 * so we should give a lower priority registry the chance to do them */
100 for (iter = path_spill; iter; iter = iter->next)
102 g_print ("added path %s to %s \n",
103 (const char *) iter->data, registry->name);
104 gst_registry_add_path (registry, (const gchar *) iter->data);
106 g_list_free (path_spill);
110 g_signal_connect (G_OBJECT (registry), "plugin_added",
111 G_CALLBACK (plugin_added_func), NULL);
113 if (registry->flags & GST_REGISTRY_WRITABLE) {
115 g_object_get (registry, "location", &location, NULL);
116 g_print ("rebuilding %s (%s)\n", registry->name, location);
118 gst_registry_rebuild (registry);
119 gst_registry_save (registry);
122 g_print ("trying to load %s\n", registry->name);
123 if (!gst_registry_load (registry))
125 g_print ("error loading %s\n", registry->name);
126 /* move over paths from this registry to the next one */
127 path_spill = g_list_concat (path_spill,
128 gst_registry_get_path_list (registry));
129 g_assert (path_spill != NULL);
131 /* also move over paths if the registry wasn't writable
132 * FIXME: we should check if the paths that were loaded from this
133 registry get removed from the path_list so we only try to
134 spill paths that could not be registered */
135 path_spill = g_list_concat (path_spill,
136 gst_registry_get_path_list (registry));
139 dir_list = gst_registry_get_path_list(registry);
140 for(iter = dir_list; iter; iter = iter->next) {
141 dir = g_build_filename((const char *)iter->data, "register-scripts", NULL);
142 spawn_all_in_dir(dir);
145 g_list_free(dir_list);
147 registries = g_list_next (registries);
150 g_print ("loaded %d plugins with %d features\n", num_plugins, num_features);