[grilo] core: Add API to get plugins from registry



commit 6985175a7c980dbcd19000619879b1386936b806
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Wed May 4 10:29:19 2011 +0000

    core: Add API to get plugins from registry
    
    Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>

 doc/grilo/grilo-sections.txt |    3 ++
 src/grl-plugin-registry.c    |   65 ++++++++++++++++++++++++++++++++++++++++--
 src/grl-plugin-registry.h    |    7 ++++
 src/grl-plugin.c             |   36 +++++++++++++++++++++++
 src/grl-plugin.h             |    2 +
 tools/grilo-test-ui/main.c   |   27 +++++++----------
 6 files changed, 121 insertions(+), 19 deletions(-)
---
diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index c619462..0fe16be 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -37,6 +37,7 @@ grl_plugin_get_filename
 grl_plugin_get_rank
 grl_plugin_get_info_keys
 grl_plugin_get_info
+grl_plugin_get_sources
 <SUBSECTION Standard>
 GRL_PLUGIN
 GRL_IS_PLUGIN
@@ -222,6 +223,8 @@ grl_plugin_registry_unregister_source
 grl_plugin_registry_lookup_source
 grl_plugin_registry_get_sources
 grl_plugin_registry_get_sources_by_operations
+grl_plugin_registry_lookup_plugin
+grl_plugin_registry_get_plugins
 grl_plugin_registry_register_metadata_key
 grl_plugin_registry_register_metadata_key_full
 grl_plugin_registry_register_metadata_key_relation
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index f7fc635..0f4c1f9 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -157,7 +157,7 @@ grl_plugin_registry_init (GrlPluginRegistry *registry)
   registry->priv->configs =
     g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   registry->priv->plugins =
-    g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
+    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   registry->priv->sources =
     g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
   registry->priv->related_keys =
@@ -408,10 +408,9 @@ grl_plugin_registry_preload_plugin (GrlPluginRegistry *registry,
     }
 
     g_hash_table_insert (registry->priv->plugins,
-                         (gchar *) grl_plugin_get_id (plugin),
+                         id,
                          g_object_ref (plugin));
   }
-  g_free (id);
   return plugin;
 }
 
@@ -1105,6 +1104,66 @@ grl_plugin_registry_get_sources_by_operations (GrlPluginRegistry *registry,
 }
 
 /**
+ * grl_plugin_registry_lookup_plugin:
+ * @registry: the registry instance
+ * @plugin_id: the id of a plugin
+ *
+ * This function will search and retrieve a plugin given its identifier.
+ *
+ * Returns: (transfer none): The plugin found
+ **/
+GrlPlugin *
+grl_plugin_registry_lookup_plugin (GrlPluginRegistry *registry,
+                                   const gchar *plugin_id)
+{
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), NULL);
+  g_return_val_if_fail (plugin_id, NULL);
+
+  return (GrlPlugin *) g_hash_table_lookup (registry->priv->plugins,
+                                            plugin_id);
+}
+
+/**
+ * grl_plugin_registry_get_plugins:
+ * @registry: the registry instance
+ * @only_loaded: whether the returned list shall include only loaded plugins
+ *
+ * This function will return all the available plugins in the @registry.
+ *
+ * If @only_loaded is %TRUE, the plugin list will contain only plugins that are
+ * loaded.
+ *
+ * Returns: (element-type Grl.Plugin) (transfer container): a #GList of
+ * available #GrlPlugin<!-- -->s. The content of the list should not be modified
+ * or freed. Use g_list_free() when done using the list.
+ **/
+GList *
+grl_plugin_registry_get_plugins (GrlPluginRegistry *registry,
+                                 gboolean only_loaded)
+{
+  GList *plugin_list = NULL;
+  GHashTableIter iter;
+  GrlPlugin *current_plugin;
+  gboolean is_loaded;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), NULL);
+
+  if (only_loaded) {
+    g_hash_table_iter_init (&iter, registry->priv->plugins);
+    while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &current_plugin)) {
+      g_object_get (current_plugin, "loaded", &is_loaded, NULL);
+      if (is_loaded) {
+        plugin_list = g_list_prepend (plugin_list, current_plugin);
+      }
+    }
+  } else {
+    plugin_list = g_hash_table_get_keys (registry->priv->plugins);
+  }
+
+  return plugin_list;
+}
+
+/**
  * grl_plugin_registry_unload:
  * @registry: the registry instance
  * @plugin_id: the identifier of the plugin
diff --git a/src/grl-plugin-registry.h b/src/grl-plugin-registry.h
index 637bbc5..8b8e890 100644
--- a/src/grl-plugin-registry.h
+++ b/src/grl-plugin-registry.h
@@ -223,6 +223,13 @@ GList *grl_plugin_registry_get_sources_by_operations (GrlPluginRegistry *registr
                                                                 GrlSupportedOps ops,
                                                                 gboolean ranked);
 
+GrlPlugin *grl_plugin_registry_lookup_plugin (GrlPluginRegistry *registry,
+                                              const gchar *plugin_id);
+
+GList *grl_plugin_registry_get_plugins (GrlPluginRegistry *registry,
+                                        gboolean only_loaded);
+
+
 GrlKeyID grl_plugin_registry_register_metadata_key (GrlPluginRegistry *registry,
                                                     GParamSpec *param_spec,
                                                     GError **error);
diff --git a/src/grl-plugin.c b/src/grl-plugin.c
index f10b073..4f70a63 100644
--- a/src/grl-plugin.c
+++ b/src/grl-plugin.c
@@ -492,3 +492,39 @@ grl_plugin_set_info (GrlPlugin *plugin,
                        g_strdup (key),
                        g_strdup (value));
 }
+
+/**
+ * grl_plugin_get_sources:
+ * @plugin: a plugin
+ *
+ * Gets the sources belonging to @plugin.
+ *
+ * Returns: (transfer container) (element-type Grl.Source): a #GList of
+ * #GrlSource<!-- -->s. The content of the list should not be modified or
+ * freed. Use g_list_free() when done using the list.
+ **/
+GList *
+grl_plugin_get_sources (GrlPlugin *plugin)
+{
+  GrlPluginRegistry *registry;
+  GList *all_sources;
+  GList *plugin_sources = NULL;
+  GList *sources_iter;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN (plugin), NULL);
+
+  registry = grl_plugin_registry_get_default ();
+  all_sources = grl_plugin_registry_get_sources (registry, FALSE);
+
+  for (sources_iter = all_sources;
+       sources_iter;
+       sources_iter = g_list_next (sources_iter)) {
+    if (grl_source_get_plugin (GRL_SOURCE (sources_iter->data)) == plugin) {
+      plugin_sources = g_list_prepend (plugin_sources, sources_iter->data);
+    }
+  }
+
+  g_list_free (all_sources);
+
+  return plugin_sources;
+}
diff --git a/src/grl-plugin.h b/src/grl-plugin.h
index 3fd8370..2b135b8 100644
--- a/src/grl-plugin.h
+++ b/src/grl-plugin.h
@@ -130,6 +130,8 @@ GList *grl_plugin_get_info_keys (GrlPlugin *plugin);
 const gchar *grl_plugin_get_info (GrlPlugin *plugin,
                                   const gchar *key);
 
+GList *grl_plugin_get_sources (GrlPlugin *plugin);
+
 G_END_DECLS
 
 #endif /* _GRL_PLUGIN_H_ */
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index c30e87e..b46ef63 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -2150,7 +2150,8 @@ load_plugins (void)
 static void
 shutdown_plugins (void)
 {
-  GList *sources = NULL;
+  GList *plugins;
+  GList *plugin_iter;
   GrlPluginRegistry *registry;
 
   /* Cancel previous operation, if any */
@@ -2167,21 +2168,15 @@ shutdown_plugins (void)
 				   NULL);
 
   /* Shut down the plugins now */
-  sources = grl_plugin_registry_get_sources (registry, FALSE);
-  while (sources) {
-    const gchar *plugin_id;
-    GrlPlugin *plugin;
-    GrlSource *source;
-
-    source = GRL_SOURCE (sources->data);
-    plugin = grl_source_get_plugin (source);
-    plugin_id = grl_plugin_get_id (plugin);
-    grl_plugin_registry_unload (registry, plugin_id, NULL);
-
-    g_list_free (sources);
-    sources = grl_plugin_registry_get_sources (registry, FALSE);
-  }
-  g_list_free (sources);
+  plugins = grl_plugin_registry_get_plugins (registry, TRUE);
+  for (plugin_iter = plugins;
+       plugin_iter;
+       plugin_iter = g_list_next (plugin_iter)) {
+    grl_plugin_registry_unload (registry,
+                                grl_plugin_get_id (GRL_PLUGIN (plugin_iter->data)),
+                                NULL);
+  }
+  g_list_free (plugins);
 
   /* Re-enable "source-removed" handler */
   g_signal_handlers_unblock_by_func (G_OBJECT (registry), source_removed_cb,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]