[PATCH 1/2] registry: add grl_plugin_registry_load_default() method



From: Lionel Landwerlin <lionel g landwerlin linux intel com>

The purpose of this new method is to provide an helper to load a given
set of plugins using the command line or an environment variable. It
is useful for debugging.

Signed-off-by: Lionel Landwerlin <lionel g landwerlin linux intel com>
---
 src/grilo.c                |   27 +++++++++++++++----
 src/grl-plugin-registry.c  |   62 ++++++++++++++++++++++++++++++++++++++++++++
 src/grl-plugin-registry.h  |    7 +++++
 tools/grilo-test-ui/main.c |    4 +-
 4 files changed, 92 insertions(+), 8 deletions(-)

diff --git a/src/grilo.c b/src/grilo.c
index 8b3f80b..d74c116 100644
--- a/src/grilo.c
+++ b/src/grilo.c
@@ -43,6 +43,7 @@
 
 static gboolean grl_initialized = FALSE;
 static const gchar *plugin_path = NULL;
+static const gchar *default_plugin_list = NULL;
 
 /**
  * grl_init:
@@ -60,8 +61,8 @@ grl_init (gint *argc,
   GOptionContext *ctx;
   GOptionGroup *group;
   GrlPluginRegistry *registry;
-  gchar **plugin_dir;
-  gchar **plugin_dirs_split;
+  gchar **split_element;
+  gchar **split_list;
 
   if (grl_initialized) {
     GRL_DEBUG ("already initialized grl");
@@ -108,11 +109,23 @@ grl_init (gint *argc,
     plugin_path = GRL_PLUGIN_PATH_DEFAULT;
   }
 
-  plugin_dirs_split = g_strsplit (plugin_path, ":", 0);
-  for (plugin_dir = plugin_dirs_split; *plugin_dir; plugin_dir++) {
-    grl_plugin_registry_add_directory (registry, *plugin_dir);
+  split_list = g_strsplit (plugin_path, ":", 0);
+  for (split_element = split_list; *split_element; split_element++) {
+    grl_plugin_registry_add_directory (registry, *split_element);
+  }
+  g_strfreev (split_list);
+
+  if (!default_plugin_list) {
+    default_plugin_list = g_getenv (GRL_DEFAULT_PLUGINS_VAR);
+  }
+
+  if (default_plugin_list) {
+    split_list = g_strsplit (default_plugin_list, ",", 0);
+    for (split_element = split_list; *split_element; split_element++) {
+      grl_plugin_registry_add_default_plugin (registry, *split_element);
+    }
+    g_strfreev (split_list);
   }
-  g_strfreev (plugin_dirs_split);
 
   grl_initialized = TRUE;
 }
@@ -138,6 +151,8 @@ grl_init_get_option_group (void)
   static const GOptionEntry grl_args[] = {
     { "grl-plugin-path", 0, 0, G_OPTION_ARG_STRING, &plugin_path,
       "Colon-separated paths containing plugins", NULL },
+    { "grl-default-plugins", 0, 0, G_OPTION_ARG_STRING, &default_plugin_list,
+      "Colon-separated ids of plugins to load in default case", NULL },
     { NULL }
   };
 
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index f713cd4..6d9a883 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -70,6 +70,7 @@ struct _GrlPluginRegistryPrivate {
   GParamSpecPool *system_keys;
   GHashTable *ranks;
   GSList *plugins_dir;
+  GSList *default_plugins;
 };
 
 static void grl_plugin_registry_setup_ranks (GrlPluginRegistry *registry);
@@ -450,6 +451,28 @@ grl_plugin_registry_add_directory (GrlPluginRegistry *registry,
 }
 
 /**
+ * grl_plugin_registry_add_default_plugin:
+ * @registry: the registry instance
+ * @plugin_id: a plugin id
+ *
+ * Set this plugin id as part of default set of plugins to load.
+ *
+ * Since: 0.1.16
+ **/
+void
+grl_plugin_registry_add_default_plugin (GrlPluginRegistry *registry,
+                                        const gchar *plugin_id)
+{
+  g_return_if_fail (GRL_IS_PLUGIN_REGISTRY (registry));
+  g_return_if_fail (plugin_id);
+
+  /* Use append instead of prepend so plugins are loaded in the same order as
+     they were added */
+  registry->priv->default_plugins = g_slist_append (registry->priv->default_plugins,
+                                                    g_strdup (plugin_id));
+}
+
+/**
  * grl_plugin_registry_load:
  * @registry: the registry instance
  * @path: the path to the so file
@@ -634,6 +657,45 @@ grl_plugin_registry_load_directory (GrlPluginRegistry *registry,
 }
 
 /**
+ * grl_plugin_registry_default:
+ * @registry: the registry instance
+ * @error: error return location or @NULL to ignore
+ *
+ * Load all the modules available in the default directory path or a
+ * list of default plugins given either using
+ * --grl-default-plugins=plugin1,plugin2,... or through the
+ * environment variable %GRL_DEFAULT_PLUGINS.
+ *
+ * Returns: %FALSE% if all the configured plugin paths are invalid,
+ * %TRUE% otherwise.
+ *
+ * Since: 0.1.16
+ */
+gboolean
+grl_plugin_registry_load_default (GrlPluginRegistry *registry,
+                                  GError **error)
+{
+  GSList *plugin;
+
+  g_return_val_if_fail (GRL_IS_PLUGIN_REGISTRY (registry), TRUE);
+
+  if (registry->priv->default_plugins) {
+    for (plugin = registry->priv->default_plugins;
+         plugin;
+         plugin = g_slist_next (plugin)) {
+      if (!grl_plugin_registry_load_by_id (registry,
+                                           (const gchar *) plugin->data,
+                                           error))
+        return FALSE;
+    }
+  } else {
+    return grl_plugin_registry_load_all (registry, error);
+  }
+
+  return TRUE;
+}
+
+/**
  * grl_plugin_registry_load_all:
  * @registry: the registry instance
  * @error: error return location or @NULL to ignore
diff --git a/src/grl-plugin-registry.h b/src/grl-plugin-registry.h
index acbbc8b..3d951f5 100644
--- a/src/grl-plugin-registry.h
+++ b/src/grl-plugin-registry.h
@@ -38,6 +38,7 @@
 
 #define GRL_PLUGIN_PATH_VAR "GRL_PLUGIN_PATH"
 #define GRL_PLUGIN_RANKS_VAR "GRL_PLUGIN_RANKS"
+#define GRL_DEFAULT_PLUGINS_VAR "GRL_DEFAULT_PLUGINS"
 
 /* Macros */
 
@@ -205,6 +206,9 @@ GrlPluginRegistry *grl_plugin_registry_get_default (void);
 void grl_plugin_registry_add_directory (GrlPluginRegistry *registry,
                                         const gchar *path);
 
+void grl_plugin_registry_add_default_plugin (GrlPluginRegistry *registry,
+                                             const gchar *plugin_id);
+
 gboolean grl_plugin_registry_load (GrlPluginRegistry *registry,
                                    const gchar *path,
                                    GError **error);
@@ -217,6 +221,9 @@ gboolean grl_plugin_registry_unload (GrlPluginRegistry *registry,
                                      const gchar *plugin_id,
                                      GError **error);
 
+gboolean grl_plugin_registry_load_default (GrlPluginRegistry *registry,
+                                           GError **error);
+
 gboolean grl_plugin_registry_load_all (GrlPluginRegistry *registry,
                                        GError **error);
 
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index b21a0d7..f1e6864 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -1988,7 +1988,7 @@ load_plugins (void)
 		    G_CALLBACK (source_added_cb), NULL);
   g_signal_connect (registry, "source-removed",
 		    G_CALLBACK (source_removed_cb), NULL);
-  if (!grl_plugin_registry_load_all (registry, NULL)) {
+  if (!grl_plugin_registry_load_default (registry, NULL)) {
     g_error ("Failed to load plugins.");
   }
 }
@@ -2044,7 +2044,7 @@ load_all_plugins ()
 
   registry = grl_plugin_registry_get_default ();
 
-  grl_plugin_registry_load_all (registry, NULL);
+  grl_plugin_registry_load_default (registry, NULL);
 }
 
 static void
-- 
1.7.5.4



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