Mercurial > audlegacy
changeset 2797:f0c1c8b22c88 trunk
[svn] - first attempt at an plugin API2 loader. this is entirely implemented inside the plugin2 namespace, so please respect that if you go editing this ;p
author | nenolod |
---|---|
date | Thu, 24 May 2007 03:27:54 -0700 |
parents | e9af66a1be74 |
children | 7144a4e5e978 |
files | ChangeLog src/audacious/build_stamp.c src/audacious/plugin.h src/audacious/pluginenum.c |
diffstat | 4 files changed, 132 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu May 24 02:03:17 2007 -0700 +++ b/ChangeLog Thu May 24 03:27:54 2007 -0700 @@ -1,3 +1,11 @@ +2007-05-24 09:03:17 +0000 William Pitcock <nenolod@sacredspiral.co.uk> + revision [4618] + - add functions for defining the v2 plugin header + + trunk/src/audacious/plugin.h | 34 +++++++++++++++++++++++++++++++--- + 1 file changed, 31 insertions(+), 3 deletions(-) + + 2007-05-24 08:48:28 +0000 William Pitcock <nenolod@sacredspiral.co.uk> revision [4616] - chase r4614.
--- a/src/audacious/build_stamp.c Thu May 24 02:03:17 2007 -0700 +++ b/src/audacious/build_stamp.c Thu May 24 03:27:54 2007 -0700 @@ -1,2 +1,2 @@ #include <glib.h> -const gchar *svn_stamp = "20070524-4616"; +const gchar *svn_stamp = "20070524-4618";
--- a/src/audacious/plugin.h Thu May 24 02:03:17 2007 -0700 +++ b/src/audacious/plugin.h Thu May 24 03:27:54 2007 -0700 @@ -39,6 +39,7 @@ #include "audacious/vfs.h" #include "audacious/titlestring.h" +#define PLUGIN(x) ((Plugin *)(x)) #define INPUT_PLUGIN(x) ((InputPlugin *)(x)) #define OUTPUT_PLUGIN(x) ((OutputPlugin *)(x)) #define EFFECT_PLUGIN(x) ((EffectPlugin *)(x))
--- a/src/audacious/pluginenum.c Thu May 24 02:03:17 2007 -0700 +++ b/src/audacious/pluginenum.c Thu May 24 03:27:54 2007 -0700 @@ -190,6 +190,96 @@ lowlevel_list = g_list_append(lowlevel_list, p); } +/*******************************************************************/ + +static void +plugin2_dispose(GModule *module, const gchar *str, ...) +{ + gchar buf[4096]; + va_list va; + + va_start(va, str); + vsnprintf(buf, 4096, str, va); + va_end(va); + + g_print("*** %s\n", buf); + g_module_close(module); +} + +void +plugin2_process(PluginHeader *header, GModule *module, const gchar *filename) +{ + InputPlugin **ip_iter; + OutputPlugin **op_iter; + EffectPlugin **ep_iter; + GeneralPlugin **gp_iter; + VisPlugin **vp_iter; + + if (header->magic != PLUGIN_MAGIC) + return plugin2_dispose(module, "plugin <%s> discarded, invalid module magic", filename); + + if (header->api_version != __AUDACIOUS_PLUGIN_API__) + return plugin2_dispose(module, "plugin <%s> discarded, wanting API version %d, we implement API version %d", + filename, header->api_version, __AUDACIOUS_PLUGIN_API__); + + if (header->init) + header->init(); + + header->priv_assoc = g_new0(Plugin, 1); + header->priv_assoc->handle = module; + header->priv_assoc->filename = g_strdup(filename); + + for (ip_iter = header->ip_list; *ip_iter != NULL; ip_iter++) + { + g_print("plugin2 '%s' provides InputPlugin <%p>", filename, *ip_iter); + input_plugin_init(PLUGIN(*ip_iter)); + } + + for (op_iter = header->op_list; *op_iter != NULL; op_iter++) + { + g_print("plugin2 '%s' provides OutputPlugin <%p>", filename, *op_iter); + output_plugin_init(PLUGIN(*op_iter)); + } + + for (ep_iter = header->ep_list; *ep_iter != NULL; ep_iter++) + { + g_print("plugin2 '%s' provides EffectPlugin <%p>", filename, *ep_iter); + effect_plugin_init(PLUGIN(*ep_iter)); + } + + for (gp_iter = header->gp_list; *gp_iter != NULL; gp_iter++) + { + g_print("plugin2 '%s' provides GeneralPlugin <%p>", filename, *gp_iter); + general_plugin_init(PLUGIN(*gp_iter)); + } + + for (vp_iter = header->vp_list; *vp_iter != NULL; vp_iter++) + { + g_print("plugin2 '%s' provides VisPlugin <%p>", filename, *vp_iter); + vis_plugin_init(PLUGIN(*vp_iter)); + } +} + +void +plugin2_unload(PluginHeader *header) +{ + GModule *module; + + g_return_if_fail(header->priv_assoc != NULL); + + module = header->priv_assoc->handle; + + g_free(header->priv_assoc->filename); + g_free(header->priv_assoc); + + if (header->fini) + header->fini(); + + g_module_close(module); +} + +/******************************************************************/ + /* FIXME: Placed here (hopefully) temporarily - descender */ typedef struct { @@ -226,6 +316,20 @@ return; } + /* v2 plugin loading */ + if (g_module_symbol(module, "get_plugin_info", &func)) + { + PluginHeader *(*header_func_p)() = func; + PluginHeader *header; + + /* this should never happen. */ + g_return_if_fail((header = header_func_p()) != NULL); + + plugin2_process(header, module, filename); + return; + } + + /* v1 plugin loading */ for (type = plugin_types; type->name; type++) { if (g_module_symbol(module, type->id, &func)) { @@ -403,7 +507,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(ip->handle); + + if (ip->handle) + g_module_close(ip->handle); } if (ip_data.input_list != NULL) @@ -420,7 +526,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(op->handle); + + if (op->handle) + g_module_close(op->handle); } if (op_data.output_list != NULL) @@ -437,7 +545,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(ep->handle); + + if (ep->handle) + g_module_close(ep->handle); } if (ep_data.effect_list != NULL) @@ -454,7 +564,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(gp->handle); + + if (gp->handle) + g_module_close(gp->handle); } if (gp_data.general_list != NULL) @@ -471,7 +583,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(vp->handle); + + if (vp->handle) + g_module_close(vp->handle); } if (vp_data.vis_list != NULL) @@ -488,7 +602,9 @@ while (g_main_context_iteration(NULL, FALSE)); GDK_THREADS_ENTER(); } - g_module_close(lp->handle); + + if (lp->handle) + g_module_close(lp->handle); } if (lowlevel_list != NULL)