[libpeas] Add a way to inhibit a plugin loader.



commit 292c139b80b393c553ebab28387f6f63bd628d13
Author: Steve Frécinaux <code istique net>
Date:   Tue Jun 15 12:49:32 2010 +0200

    Add a way to inhibit a plugin loader.
    
    This patch introduces peas_engine_disable_loader(), which allows to
    disable a plugin loader. This can be useful for debugging purpose.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621626

 docs/reference/libpeas-sections.txt |    1 +
 libpeas/peas-engine.c               |   36 +++++++++++++++++++++++++++++++++++
 libpeas/peas-engine.h               |    2 +
 3 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libpeas-sections.txt b/docs/reference/libpeas-sections.txt
index 38af2d6..8a15fad 100644
--- a/docs/reference/libpeas-sections.txt
+++ b/docs/reference/libpeas-sections.txt
@@ -48,6 +48,7 @@ peas_engine_deactivate_plugin
 peas_engine_garbage_collect
 peas_engine_provides_extension
 peas_engine_get_extension
+peas_engine_disable_loader
 <SUBSECTION Standard>
 PEAS_ENGINE
 PEAS_IS_ENGINE
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 8c2dee2..d1caf9f 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -577,6 +577,42 @@ get_plugin_loader (PeasEngine     *engine,
 }
 
 /**
+ * peas_engine_disable_loader:
+ * @engine: A #PeasEngine.
+ * @loader_id: The id of the loader to inhibit.
+ *
+ * Disable a loader, avoiding using the plugins written using the
+ * related language to be loaded. This method must be called before
+ * any plugin relying on the loader @loader_id has been loaded.
+ *
+ * For instance, the following code will prevent any python plugin
+ * from being loaded:
+ * |[
+ * peas_engine_disable_loader (engine, "python");
+ * ]|
+ **/
+void
+peas_engine_disable_loader (PeasEngine  *engine,
+                            const gchar *loader_id)
+{
+  LoaderInfo *loader_info;
+
+  g_return_if_fail (PEAS_IS_ENGINE (engine));
+
+  loader_info = (LoaderInfo *) g_hash_table_lookup (engine->priv->loaders,
+                                                    loader_id);
+  if (loader_info != NULL)
+    {
+      g_warning ("Loader %s cannot be disabled as it is already loaded", loader_id);
+      return;
+    }
+
+  /* By adding a NULL loader, we simulate a failed load attempt, effectively
+   * disabling the loader for further use. */
+  add_loader (engine, loader_id, NULL, NULL);
+}
+
+/**
  * peas_engine_get_plugin_list:
  * @engine: A #PeasEngine.
  *
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index e0ebf04..9bb8dfe 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -68,6 +68,8 @@ PeasEngine       *peas_engine_new                 (const gchar     *app_name,
                                                    const gchar    **search_paths);
 
 /* plugin management */
+void              peas_engine_disable_loader      (PeasEngine      *engine,
+                                                   const gchar     *loader_id);
 void              peas_engine_rescan_plugins      (PeasEngine      *engine);
 const GList      *peas_engine_get_plugin_list     (PeasEngine      *engine);
 gchar           **peas_engine_get_active_plugins  (PeasEngine      *engine);



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