/soc/2013/ankitkv/gobjectification: a9cccad073e9: Static prpls n...

Ankit Vani a at nevitus.org
Tue Aug 6 18:17:36 EDT 2013


Changeset: a9cccad073e9f6db6256e56ee800d4230f6c7536
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-07 03:33 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/a9cccad073e9

Description:

Static prpls now work. Added macro PURPLE_PLUGIN_INIT(plugin-name, query-func, load-func, unload-func).

diffstat:

 configure.ac                        |  40 ++++++++++++++++-------
 libpurple/core.c                    |  11 ++++--
 libpurple/plugins.h                 |  62 ++++++++++++++++++++++++++++--------
 libpurple/protocols/null/nullprpl.c |  14 ++++---
 4 files changed, 90 insertions(+), 37 deletions(-)

diffs (239 lines):

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -1298,31 +1298,43 @@ if test "x$silcincludes" != "xyes" -o "x
 fi
 AC_SUBST(STATIC_PRPLS)
 STATIC_LINK_LIBS=
-extern_init=
+extern_load=
 load_proto=
+extern_unload=
+unload_proto=
 for i in $STATIC_PRPLS ; do
 	dnl Ugly special case for "libsilcpurple.la":
 	dnl ... and Ugly special case for multi-protocol oscar and yahoo
 	if test \( "x$i" = "xoscar" -o "x$i" = "xaim" -o "x$i" = "xicq" \) -a "x$static_oscar" != "xyes"; then
 		STATIC_LINK_LIBS="$STATIC_LINK_LIBS \$(top_builddir)/libpurple/protocols/oscar/liboscar.la"
-		extern_init="$extern_init extern gboolean purple_init_aim_plugin();"
-		extern_init="$extern_init extern gboolean purple_init_icq_plugin();"
-		load_proto="$load_proto purple_init_aim_plugin();"
-		load_proto="$load_proto purple_init_icq_plugin();"
+		extern_load="$extern_load extern gboolean aim_plugin_load();"
+		extern_load="$extern_load extern gboolean icq_plugin_load();"
+		load_proto="$load_proto aim_plugin_load();"
+		load_proto="$load_proto icq_plugin_load();"
+		extern_unload="$extern_unload extern gboolean aim_plugin_unload();"
+		extern_unload="$extern_unload extern gboolean icq_plugin_unload();"
+		unload_proto="$unload_proto aim_plugin_unload();"
+		unload_proto="$unload_proto icq_plugin_unload();"
 	elif test "x$i" = "xyahoo"; then
 		STATIC_LINK_LIBS="$STATIC_LINK_LIBS \$(top_builddir)/libpurple/protocols/yahoo/libymsg.la"
-		extern_init="$extern_init extern gboolean purple_init_yahoo_plugin();"
-		extern_init="$extern_init extern gboolean purple_init_yahoojp_plugin();"
-		load_proto="$load_proto purple_init_yahoo_plugin();"
-		load_proto="$load_proto purple_init_yahoojp_plugin();"
+		extern_load="$extern_load extern gboolean yahoo_plugin_load();"
+		extern_load="$extern_load extern gboolean yahoojp_plugin_load();"
+		load_proto="$load_proto yahoo_plugin_load();"
+		load_proto="$load_proto yahoojp_plugin_load();"
+		extern_unload="$extern_unload extern gboolean yahoo_plugin_unload();"
+		extern_unload="$extern_unload extern gboolean yahoojp_plugin_unload();"
+		unload_proto="$unload_proto yahoo_plugin_unload();"
+		unload_proto="$unload_proto yahoojp_plugin_unload();"
 	else
 		if test "x$i" = "xsilc"; then
 			STATIC_LINK_LIBS="$STATIC_LINK_LIBS \$(top_builddir)/libpurple/protocols/$i/lib${i}purple.la"
 		else
 			STATIC_LINK_LIBS="$STATIC_LINK_LIBS \$(top_builddir)/libpurple/protocols/$i/lib$i.la"
 		fi
-		extern_init="$extern_init extern gboolean purple_init_${i}_plugin();"
-		load_proto="$load_proto purple_init_${i}_plugin();"
+		extern_load="$extern_load extern gboolean ${i}_plugin_load();"
+		load_proto="$load_proto ${i}_plugin_load();"
+		extern_unload="$extern_unload extern gboolean ${i}_plugin_unload();"
+		unload_proto="$unload_proto ${i}_plugin_unload();"
 	fi
 	case $i in
 		bonjour)	static_bonjour=yes ;;
@@ -1359,8 +1371,10 @@ AM_CONDITIONAL(STATIC_SIMPLE, test "x$st
 AM_CONDITIONAL(STATIC_YAHOO, test "x$static_yahoo" = "xyes")
 AM_CONDITIONAL(STATIC_ZEPHYR, test "x$static_zephyr" = "xyes")
 AC_SUBST(STATIC_LINK_LIBS)
-AC_DEFINE_UNQUOTED(STATIC_PROTO_INIT, $extern_init static void static_proto_init(void) { $load_proto },
-	[Loads static protocol plugin module initialization functions.])
+AC_DEFINE_UNQUOTED(STATIC_PROTO_LOAD, $extern_load static void static_proto_load(void) { $load_proto },
+	[Loads protocols from static protocol plugin modules.])
+AC_DEFINE_UNQUOTED(STATIC_PROTO_UNLOAD, $extern_unload static void static_proto_unload(void) { $unload_proto },
+	[Unloads protocols from static protocol plugin modules.])
 
 AC_ARG_WITH(dynamic_prpls, [AS_HELP_STRING([--with-dynamic-prpls], [specify which protocols to build dynamically])], [DYNAMIC_PRPLS=`echo $withval | $sedpath 's/,/ /g'`])
 if test "x$DYNAMIC_PRPLS" = "xall" ; then
diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -75,7 +75,8 @@ struct PurpleCore
 static PurpleCoreUiOps *_ops  = NULL;
 static PurpleCore      *_core = NULL;
 
-STATIC_PROTO_INIT
+STATIC_PROTO_LOAD
+STATIC_PROTO_UNLOAD
 
 gboolean
 purple_core_init(const char *ui)
@@ -143,14 +144,14 @@ purple_core_init(const char *ui)
 	purple_cmds_init();
 	purple_protocols_init();
 
+	/* Load all static protocols. */
+	static_proto_load();
+
 	/* Since plugins get probed so early we should probably initialize their
 	 * subsystem right away too.
 	 */
 	purple_plugins_init();
 
-	/* Initialize all static protocols. */
-	static_proto_init();
-
 	purple_keyring_init(); /* before accounts */
 	purple_theme_manager_init();
 
@@ -256,6 +257,8 @@ purple_core_quit(void)
 	/* Everything after prefs_uninit must not try to read any prefs */
 	purple_prefs_uninit();
 	purple_plugins_uninit();
+
+	static_proto_unload();	
 	purple_protocols_uninit();
 
 #ifdef HAVE_DBUS
diff --git a/libpurple/plugins.h b/libpurple/plugins.h
--- a/libpurple/plugins.h
+++ b/libpurple/plugins.h
@@ -31,6 +31,7 @@
 
 #ifdef PURPLE_PLUGINS
 #include <gplugin.h>
+#include <gplugin-native.h>
 #else
 #include <glib.h>
 #include <glib-object.h>
@@ -38,20 +39,6 @@
 
 #include "version.h"
 
-/** Returns an ABI version to set in plugins using major and minor versions */
-#define PURPLE_PLUGIN_ABI_VERSION(major,minor) ((major << 16) + minor)
-/** Returns the major version from an ABI version */
-#define PURPLE_PLUGIN_ABI_MAJOR_VERSION(abi)   (abi >> 16)
-/** Returns the minor version from an ABI version */
-#define PURPLE_PLUGIN_ABI_MINOR_VERSION(abi)   (abi & 0xFFFF)
-
-/**
-  * A convenience‎ macro that returns an ABI version using PURPLE_MAJOR_VERSION
-  * and PURPLE_MINOR_VERSION
-  */
-#define PURPLE_ABI_VERSION PURPLE_PLUGIN_ABI_VERSION(PURPLE_MAJOR_VERSION,\
-                                                     PURPLE_MINOR_VERSION)
-
 #ifdef PURPLE_PLUGINS
 
 #define PURPLE_TYPE_PLUGIN             GPLUGIN_TYPE_PLUGIN
@@ -152,6 +139,53 @@ struct _PurplePluginAction {
 	PurplePlugin *plugin;
 };
 
+/** Returns an ABI version to set in plugins using major and minor versions */
+#define PURPLE_PLUGIN_ABI_VERSION(major,minor) ((major << 16) + minor)
+/** Returns the major version from an ABI version */
+#define PURPLE_PLUGIN_ABI_MAJOR_VERSION(abi)   (abi >> 16)
+/** Returns the minor version from an ABI version */
+#define PURPLE_PLUGIN_ABI_MINOR_VERSION(abi)   (abi & 0xFFFF)
+
+/**
+  * A convenience‎ macro that returns an ABI version using PURPLE_MAJOR_VERSION
+  * and PURPLE_MINOR_VERSION
+  */
+#define PURPLE_ABI_VERSION PURPLE_PLUGIN_ABI_VERSION(PURPLE_MAJOR_VERSION,\
+                                                     PURPLE_MINOR_VERSION)
+
+/**
+ * Handles the initialization of modules.
+ */
+#if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL)
+#define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \
+	PurplePluginInfo * pluginname##_plugin_query(void); \
+	PurplePluginInfo * pluginname##_plugin_query(void) { \
+		return pluginquery(); \
+	} \
+	gboolean pluginname##_plugin_load(void); \
+	gboolean pluginname##_plugin_load(void) { \
+		return pluginload(NULL); \
+	} \
+	gboolean pluginname##_plugin_unload(void); \
+	gboolean pluginname##_plugin_unload(void) { \
+		return pluginunload(NULL); \
+	}
+#else /* PURPLE_PLUGINS  && !PURPLE_STATIC_PRPL */
+#define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \
+	G_MODULE_EXPORT GPluginPluginInfo *gplugin_plugin_query(void); \
+	G_MODULE_EXPORT GPluginPluginInfo *gplugin_plugin_query(void) { \
+		return GPLUGIN_PLUGIN_INFO(pluginquery()); \
+	} \
+	G_MODULE_EXPORT gboolean gplugin_plugin_load(GPluginNativePlugin *); \
+	G_MODULE_EXPORT gboolean gplugin_plugin_load(GPluginNativePlugin *p) { \
+		return pluginload(PURPLE_PLUGIN(p)); \
+	} \
+	G_MODULE_EXPORT gboolean gplugin_plugin_unload(GPluginNativePlugin *); \
+	G_MODULE_EXPORT gboolean gplugin_plugin_unload(GPluginNativePlugin *p) { \
+		return pluginunload(PURPLE_PLUGIN(p)); \
+	}
+#endif
+
 G_BEGIN_DECLS
 
 /**************************************************************************/
diff --git a/libpurple/protocols/null/nullprpl.c b/libpurple/protocols/null/nullprpl.c
--- a/libpurple/protocols/null/nullprpl.c
+++ b/libpurple/protocols/null/nullprpl.c
@@ -1134,8 +1134,8 @@ static PurplePluginProtocolInfo prpl_inf
   NULL                                 /* get_public_alias */
 };
 
-G_MODULE_EXPORT PurplePluginInfo *
-gplugin_plugin_query(void)
+static PurplePluginInfo *
+plugin_query(void)
 {
   return purple_plugin_info_new(
     "id",           NULLPRPL_ID,
@@ -1150,8 +1150,8 @@ gplugin_plugin_query(void)
   );
 }
 
-G_MODULE_EXPORT gboolean
-gplugin_plugin_load(PurplePlugin *plugin)
+static gboolean
+plugin_load(PurplePlugin *plugin)
 {
   /* see accountopt.h for information about user splits and protocol options */
   PurpleAccountUserSplit *split = purple_account_user_split_new(
@@ -1192,8 +1192,8 @@ gplugin_plugin_load(PurplePlugin *plugin
   return TRUE;
 }
 
-G_MODULE_EXPORT gboolean
-gplugin_plugin_unload(PurplePlugin *plugin)
+static gboolean
+plugin_unload(PurplePlugin *plugin)
 {
   purple_debug_info("nullprpl", "shutting down\n");
 
@@ -1202,3 +1202,5 @@ gplugin_plugin_unload(PurplePlugin *plug
 
   return TRUE;
 }
+
+PURPLE_PLUGIN_INIT(null, plugin_query, plugin_load, plugin_unload);



More information about the Commits mailing list