[telepathy-gabble/master] Probe for plugins in $(libdir)/telepathy/gabble-0

Will Thompson will.thompson at collabora.co.uk
Fri Nov 27 08:31:34 PST 2009


---
 src/Makefile.am     |    5 ++-
 src/gabble.c        |    3 ++
 src/plugin-loader.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/plugin-loader.h |   25 ++++++++++++++
 4 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 src/plugin-loader.c
 create mode 100644 src/plugin-loader.h

diff --git a/src/Makefile.am b/src/Makefile.am
index b886994..578c853 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -102,6 +102,8 @@ libgabble_convenience_la_SOURCES = \
     olpc-gadget-manager.c \
     olpc-view.h \
     olpc-view.c \
+    plugin-loader.h \
+    plugin-loader.c \
     presence.h \
     presence.c \
     presence-cache.h \
@@ -170,7 +172,8 @@ AM_CFLAGS = $(ERROR_CFLAGS) -I$(top_srcdir) -I$(top_builddir) \
 	    @HANDLE_LEAK_DEBUG_CFLAGS@ @TP_GLIB_CFLAGS@ \
 	    @SOUP_CFLAGS@ @UUID_CFLAGS@ @GMODULE_CFLAGS@ \
 	    -I $(top_srcdir)/lib -I $(top_builddir)/lib \
-	    -DG_LOG_DOMAIN=\"gabble\"
+	    -DG_LOG_DOMAIN=\"gabble\" \
+	    -DPLUGIN_DIR=\"$(libdir)/telepathy/gabble-0\"
 
 ALL_LIBS =  @DBUS_LIBS@ @GLIB_LIBS@ @WOCKY_LIBS@ @TP_GLIB_LIBS@ \
 	    @SOUP_LIBS@ @UUID_LIBS@ @GMODULE_LIBS@
diff --git a/src/gabble.c b/src/gabble.c
index 992d12e..b8c5c2a 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -32,6 +32,7 @@
 
 #include "debug.h"
 #include "connection-manager.h"
+#include "plugin-loader.h"
 
 static TpBaseConnectionManager *
 construct_cm (void)
@@ -140,6 +141,8 @@ gabble_main (int argc,
     tp_debug_set_persistent (TRUE);
 #endif
 
+  gabble_plugin_loader_load ();
+
   out = tp_run_connection_manager ("telepathy-gabble", VERSION,
       construct_cm, argc, argv);
 
diff --git a/src/plugin-loader.c b/src/plugin-loader.c
new file mode 100644
index 0000000..87db329
--- /dev/null
+++ b/src/plugin-loader.c
@@ -0,0 +1,92 @@
+/*
+ * plugin-loader.c — plugin support for telepathy-gabble
+ * Copyright © 2009 Collabora Ltd.
+ * Copyright © 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "plugin-loader.h"
+
+#include <glib.h>
+#include <gmodule.h>
+
+#define DEBUG_FLAG GABBLE_DEBUG_PLUGINS
+#include "debug.h"
+
+#ifdef ENABLE_PLUGINS
+void
+gabble_plugin_loader_load (void)
+{
+  GError *error = NULL;
+  GDir *d;
+  const gchar *file;
+
+  if (!g_module_supported ())
+    {
+      DEBUG ("modules aren't supported on this platform.");
+      return;
+    }
+
+  d = g_dir_open (PLUGIN_DIR, 0, &error);
+
+  if (d == NULL)
+    {
+      DEBUG ("%s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  while ((file = g_dir_read_name (d)) != NULL)
+    {
+      GModule *m;
+      gchar *path;
+
+      if (!g_str_has_suffix (file, G_MODULE_SUFFIX))
+        continue;
+
+      path = g_build_filename (PLUGIN_DIR, file, NULL);
+      m = g_module_open (path, G_MODULE_BIND_LOCAL);
+
+      if (m == NULL)
+        {
+          const gchar *e = g_module_error ();
+
+          /* the errors often seem to be prefixed by the filename */
+          if (g_str_has_prefix (e, path))
+            DEBUG ("%s", e);
+          else
+            DEBUG ("%s: %s", path, e);
+        }
+      else
+        {
+          g_module_close (m);
+        }
+
+      g_free (path);
+    }
+
+  g_dir_close (d);
+}
+
+#else /* ! ENABLE_PLUGINS */
+
+void
+gabble_plugin_loader_load (void)
+{
+  DEBUG ("built without plugin support");
+}
+
+#endif
diff --git a/src/plugin-loader.h b/src/plugin-loader.h
new file mode 100644
index 0000000..990e6c5
--- /dev/null
+++ b/src/plugin-loader.h
@@ -0,0 +1,25 @@
+/*
+ * plugin-loader.h — plugin support for telepathy-gabble
+ * Copyright © 2009 Collabora Ltd.
+ * Copyright © 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#ifndef __PLUGIN_LOADER_H__
+#define __PLUGIN_LOADER_H__
+
+void gabble_plugin_loader_load (void);
+
+#endif /* #ifndef __PLUGIN_LOADER_H__ */
-- 
1.5.6.5




More information about the telepathy-commits mailing list