[libpeas] Import the C plugin loader into libpeas



commit 8f7533c40910312d4c89512e15a66286ce2bca81
Author: Garrett Regier <garrettregier gmail com>
Date:   Sun Aug 28 00:01:18 2011 -0700

    Import the C plugin loader into libpeas

 configure.ac                                  |    1 -
 libpeas/Makefile.am                           |    6 +++-
 libpeas/peas-engine.c                         |   12 +++++++++-
 {loaders/c => libpeas}/peas-plugin-loader-c.c |   28 ++++++++++++++----------
 {loaders/c => libpeas}/peas-plugin-loader-c.h |   13 ++++-------
 loaders/Makefile.am                           |    2 +-
 loaders/c/Makefile.am                         |   22 -------------------
 tests/libpeas/engine.c                        |    3 +-
 tests/libpeas/extension-c.c                   |    1 -
 9 files changed, 38 insertions(+), 50 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 56eb2d4..ef56d5e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -477,7 +477,6 @@ docs/reference/version.xml
 libpeas/Makefile
 libpeas-gtk/Makefile
 loaders/Makefile
-loaders/c/Makefile
 loaders/gjs/Makefile
 loaders/python/Makefile
 loaders/seed/Makefile
diff --git a/libpeas/Makefile.am b/libpeas/Makefile.am
index 3bc5159..de67252 100644
--- a/libpeas/Makefile.am
+++ b/libpeas/Makefile.am
@@ -38,7 +38,8 @@ NOINST_H_FILES =			\
 	peas-i18n.h			\
 	peas-introspection.h		\
 	peas-plugin-info-priv.h		\
-	peas-plugin-loader.h
+	peas-plugin-loader.h		\
+	peas-plugin-loader-c.h
 
 C_FILES =				\
 	peas-activatable.c		\
@@ -55,7 +56,8 @@ C_FILES =				\
 	peas-introspection.c		\
 	peas-object-module.c		\
 	peas-plugin-info.c		\
-	peas-plugin-loader.c
+	peas-plugin-loader.c		\
+	peas-plugin-loader-c.c
 
 BUILT_SOURCES = \
 	peas-marshal.c			\
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 774fa26..de21fbf 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -31,6 +31,7 @@
 #include "peas-engine-priv.h"
 #include "peas-plugin-info-priv.h"
 #include "peas-plugin-loader.h"
+#include "peas-plugin-loader-c.h"
 #include "peas-object-module.h"
 #include "peas-extension.h"
 #include "peas-dirs.h"
@@ -634,6 +635,13 @@ get_plugin_loader (PeasEngine     *engine,
   if (loader_info->loader != NULL)
     return loader_info->loader;
 
+  /* Create the default C plugin loader. */
+  if (g_ascii_strcasecmp (info->loader, "C") == 0)
+    {
+      loader_info->loader = peas_plugin_loader_c_new ();
+      return loader_info->loader;
+    }
+
   /* We need to ensure we use the lowercase loader_id */
   loader_id = g_ascii_strdown (info->loader, -1);
 
@@ -697,7 +705,9 @@ peas_engine_enable_loader (PeasEngine  *engine,
   if (g_hash_table_lookup_extended (loaders, loader_id, NULL, NULL))
     return;
 
-  /* The loader is loaded in get_plugin_loader() */
+  /* We do not load the plugin loader immediately and instead
+   * load it in get_plugin_loader() so that it is loaded lazily.
+   */
   g_hash_table_insert (loaders, g_strdup (loader_id), g_new0 (LoaderInfo, 1));
 }
 
diff --git a/loaders/c/peas-plugin-loader-c.c b/libpeas/peas-plugin-loader-c.c
similarity index 94%
rename from loaders/c/peas-plugin-loader-c.c
rename to libpeas/peas-plugin-loader-c.c
index e361578..a82971f 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/libpeas/peas-plugin-loader-c.c
@@ -24,11 +24,11 @@
 #endif
 
 #include <string.h>
-#include <gmodule.h>
 
 #include "peas-plugin-loader-c.h"
-#include <libpeas/peas-object-module.h>
-#include <libpeas/peas-extension-base.h>
+
+#include "peas-extension-base.h"
+#include "peas-object-module.h"
 
 struct _PeasPluginLoaderCPrivate {
   GHashTable *loaded_plugins;
@@ -36,14 +36,6 @@ struct _PeasPluginLoaderCPrivate {
 
 G_DEFINE_TYPE (PeasPluginLoaderC, peas_plugin_loader_c, PEAS_TYPE_PLUGIN_LOADER);
 
-G_MODULE_EXPORT void
-peas_register_types (PeasObjectModule *module)
-{
-  peas_object_module_register_extension_type (module,
-                                              PEAS_TYPE_PLUGIN_LOADER,
-                                              PEAS_TYPE_PLUGIN_LOADER_C);
-}
-
 static gboolean
 peas_plugin_loader_c_load (PeasPluginLoader *loader,
                            PeasPluginInfo   *info)
@@ -71,7 +63,6 @@ peas_plugin_loader_c_load (PeasPluginLoader *loader,
 
   if (!g_type_module_use (G_TYPE_MODULE (module)))
     {
-      g_warning ("Could not load plugin module: '%s'", module_name);
       g_object_unref (module);
       g_hash_table_remove (cloader->priv->loaded_plugins, module_name);
       return FALSE;
@@ -207,3 +198,16 @@ peas_plugin_loader_c_class_init (PeasPluginLoaderCClass *klass)
 
   g_type_class_add_private (object_class, sizeof (PeasPluginLoaderCPrivate));
 }
+
+/**
+ * peas_plugin_loader_c_new:
+ *
+ * Return a new instance of #PeasPluginLoaderC.
+ *
+ * Returns: a new instance of #PeasPluginLoaderC.
+ */
+PeasPluginLoader *
+peas_plugin_loader_c_new (void)
+{
+  return PEAS_PLUGIN_LOADER (g_object_new (PEAS_TYPE_PLUGIN_LOADER_C, NULL));
+}
diff --git a/loaders/c/peas-plugin-loader-c.h b/libpeas/peas-plugin-loader-c.h
similarity index 82%
rename from loaders/c/peas-plugin-loader-c.h
rename to libpeas/peas-plugin-loader-c.h
index 8dba503..5877e36 100644
--- a/loaders/c/peas-plugin-loader-c.h
+++ b/libpeas/peas-plugin-loader-c.h
@@ -22,16 +22,15 @@
 #ifndef __PEAS_PLUGIN_LOADER_C_H__
 #define __PEAS_PLUGIN_LOADER_C_H__
 
-#include <libpeas/peas-plugin-loader.h>
-#include <libpeas/peas-object-module.h>
+#include "peas-plugin-loader.h"
 
 G_BEGIN_DECLS
 
 #define PEAS_TYPE_PLUGIN_LOADER_C            (peas_plugin_loader_c_get_type ())
 #define PEAS_PLUGIN_LOADER_C(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), PEAS_TYPE_PLUGIN_LOADER_C, PeasPluginLoaderC))
 #define PEAS_PLUGIN_LOADER_C_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PEAS_TYPE_PLUGIN_LOADER_C, PeasPluginLoaderCClass))
-#define PEAS_PLUGIN_IS_LOADER_C(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_PLUGIN_LOADER_C))
-#define PEAS_PLUGIN_IS_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_PLUGIN_LOADER_C))
+#define PEAS_IS_PLUGIN_LOADER_C(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PEAS_TYPE_PLUGIN_LOADER_C))
+#define PEAS_IS_PLUGIN_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_PLUGIN_LOADER_C))
 #define PEAS_PLUGIN_LOADER_C_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), PEAS_TYPE_PLUGIN_LOADER_C, PeasPluginLoaderCClass))
 
 typedef struct _PeasPluginLoaderC         PeasPluginLoaderC;
@@ -48,10 +47,8 @@ struct _PeasPluginLoaderCClass {
   PeasPluginLoaderClass parent_class;
 };
 
-GType                    peas_plugin_loader_c_get_type (void) G_GNUC_CONST;
-
-/* All the loaders must implement this function */
-G_MODULE_EXPORT void     peas_register_types           (PeasObjectModule *module);
+GType             peas_plugin_loader_c_get_type    (void) G_GNUC_CONST;
+PeasPluginLoader *peas_plugin_loader_c_new         (void);
 
 G_END_DECLS
 
diff --git a/loaders/Makefile.am b/loaders/Makefile.am
index f7832ae..8de15e7 100644
--- a/loaders/Makefile.am
+++ b/loaders/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = c
+SUBDIRS =
 
 if ENABLE_GJS
 SUBDIRS += gjs
diff --git a/tests/libpeas/engine.c b/tests/libpeas/engine.c
index a920cc6..33875ad 100644
--- a/tests/libpeas/engine.c
+++ b/tests/libpeas/engine.c
@@ -225,7 +225,6 @@ test_engine_not_loadable_plugin (PeasEngine *engine)
 
   testing_util_push_log_hook ("*libnot-loadable.so: cannot open shared "
                               "object file: No such file or directory");
-  testing_util_push_log_hook ("Could not load plugin module: 'not-loadable'");
   testing_util_push_log_hook ("Error loading plugin 'not-loadable'");
 
   info = peas_engine_get_plugin_info (engine, "not-loadable");
@@ -362,7 +361,7 @@ test_engine_nonexistent_loader (PeasEngine *engine)
   GError *error = NULL;
   PeasPluginInfo *info;
 
-  testing_util_push_log_hook ("Could not find loader 'does-not-exist'*");
+  testing_util_push_log_hook ("Could not find loader 'does-not-exist' for*");
 
   info = peas_engine_get_plugin_info (engine, "nonexistent-loader");
   peas_engine_enable_loader (engine, "does-not-exist");
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
index 43d4687..04af781 100644
--- a/tests/libpeas/extension-c.c
+++ b/tests/libpeas/extension-c.c
@@ -54,7 +54,6 @@ test_extension_c_nonexistent (PeasEngine *engine)
   PeasPluginInfo *info;
 
   testing_util_push_log_hook ("*extension-c-nonexistent*No such file*");
-  testing_util_push_log_hook ("Could not load*'extension-c-nonexistent'");
   testing_util_push_log_hook ("Error loading plugin 'extension-c-nonexistent'");
 
   info = peas_engine_get_plugin_info (engine, "extension-c-nonexistent");



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