[ekiga] Gave some steroids to the plugin loader



commit 38b4cc81bd5520852a69d560ef5be4df41e7bb6e
Author: Julien Puydt <jpuydt gnome org>
Date:   Thu Jun 18 21:19:21 2009 +0200

    Gave some steroids to the plugin loader
    
    It now parses directories recursively

 configure.ac                      |   10 +++++
 lib/engine/plugin/Makefile.am     |    4 ++-
 lib/engine/plugin/plugin-core.cpp |   72 ++++++++++++++++++++++++++++++++-----
 3 files changed, 76 insertions(+), 10 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 84df1b0..feaaeb6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -818,6 +818,16 @@ else
 fi
 
 dnl ###########################################################################
+dnl  Plugin support
+dnl ###########################################################################
+
+PLUGINS_LIBTOOL_FLAGS="-module -avoid-version"
+AC_SUBST(PLUGINS_LIBTOOL_FLAGS)
+
+PLUGINDIR='${libdir}/ekiga/plugins'
+AC_SUBST(PLUGINDIR)
+
+dnl ###########################################################################
 dnl  Output the different Makefiles
 dnl ###########################################################################
 AC_OUTPUT(
diff --git a/lib/engine/plugin/Makefile.am b/lib/engine/plugin/Makefile.am
index 86f7cf7..a00059b 100644
--- a/lib/engine/plugin/Makefile.am
+++ b/lib/engine/plugin/Makefile.am
@@ -5,6 +5,7 @@ plugin_dir = $(top_srcdir)/lib/engine/plugin
 AM_CPPFLAGS = $(SIGC_CFLAGS) $(GLIB_CFLAGS)
 
 INCLUDES = \
+	-DEKIGA_PLUGIN_DIR=\"$(PLUGINDIR)\"		\
 	-I$(top_srcdir)/lib/gmconf	 		\
 	-I$(top_srcdir)/lib/engine/framework
 
@@ -12,4 +13,5 @@ libplugin_la_SOURCES = \
 	$(plugin_dir)/plugin-core.h			\
 	$(plugin_dir)/plugin-core.cpp
 
-libplugin_la_LDFLAGS = -export-dynamic -no-undefined $(SIGC_LIBS) $(GLIB_LIBS)
+libplugin_la_LDFLAGS = -export-dynamic -no-undefined
+libplugin_la_LDFLAGS = $(SIGC_LIBS) $(GLIB_LIBS)
\ No newline at end of file
diff --git a/lib/engine/plugin/plugin-core.cpp b/lib/engine/plugin/plugin-core.cpp
index c86f757..5dfd2a6 100644
--- a/lib/engine/plugin/plugin-core.cpp
+++ b/lib/engine/plugin/plugin-core.cpp
@@ -59,19 +59,15 @@
 // which can be compiled with :
 // gcc -o hello.so hello.cpp -shared -export-dynamic -I$(PATH_TO_EKIGA_SOURCES)/lib/engine/framework `pkg-config --cflags sigc++-2.0`
 
-void
-plugin_init (Ekiga::KickStart& kickstart)
+static void
+plugin_parse_file (Ekiga::KickStart& kickstart,
+		   const gchar* filename)
 {
 #if DEBUG
-  std::cout << "Trying to load the ekiga test plugin... ";
+  std::cout << "Trying to load " << filename << "... ";
 #endif
-  gchar* filename = g_build_filename (g_get_tmp_dir (),
-				      "ekiga_test",
-				      NULL);
   GModule* plugin = g_module_open (filename, G_MODULE_BIND_LOCAL);
 
-  g_free (filename);
-
   if (plugin != 0) {
 
 #if DEBUG
@@ -82,7 +78,7 @@ plugin_init (Ekiga::KickStart& kickstart)
     if (g_module_symbol (plugin, "ekiga_plugin_init", &init_func)) {
 
 #if DEBUG
-      std::cout << "valid, running:" << std::endl;
+      std::cout << "valid" << std::endl;
 #endif
       g_module_make_resident (plugin);
       ((void (*)(Ekiga::KickStart&))init_func) (kickstart);
@@ -100,3 +96,61 @@ plugin_init (Ekiga::KickStart& kickstart)
 #endif
   }
 }
+
+static void
+plugin_parse_directory (Ekiga::KickStart& kickstart,
+			const gchar* path)
+{
+  g_return_if_fail (path != NULL);
+
+  GError* error = NULL;
+  GDir* directory = g_dir_open (path, 0, &error);
+
+#if DEBUG
+  std::cout << "Trying to load plugins in " << path << "... ";
+#endif
+
+  if (directory != NULL) {
+
+#if DEBUG
+    std::cout << "open succeeded" << std::endl;
+#endif
+    const gchar* name = g_dir_read_name (directory);
+
+    while (name) {
+
+      gchar* filename = g_build_filename (path, name, NULL);
+      /* There is something to say here : it is unsafe to test then decide
+       * what to do, because things could have changed between the time we
+       * test and the time we act. But I think it's good enough for the
+       * purpose of this code. If I'm wrong, report as a bug.
+       * (Snark, 20090618)
+       */
+      if (g_file_test (name, G_FILE_TEST_IS_DIR)) {
+
+	plugin_parse_directory (kickstart, filename);
+      } else {
+
+	if (g_str_has_suffix (filename, G_MODULE_SUFFIX))
+	  plugin_parse_file (kickstart, filename);
+      }
+      g_free (filename);
+      name = g_dir_read_name (directory);
+    }
+
+    g_dir_close (directory);
+  } else {
+
+#if DEBUG
+    std::cout << "failure: " << error->message << std::endl;
+#endif
+    g_error_free (error);
+  }
+}
+
+void
+plugin_init (Ekiga::KickStart& kickstart)
+{
+  plugin_parse_directory (kickstart,
+			  EKIGA_PLUGIN_DIR);
+}



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