diff options
author | Not Zed <NotZed@Ximian.com> | 2004-11-18 12:03:55 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-11-18 12:03:55 +0800 |
commit | cc8aa371f56e4fa5f07142954bd350d0b33b6d51 (patch) | |
tree | 22e3a0802b2a4e73dca75973697ed881a2eaecf9 | |
parent | 13e05f5e35983e043f54ceb7d055264da0d3a4c2 (diff) | |
download | gsoc2013-evolution-cc8aa371f56e4fa5f07142954bd350d0b33b6d51.tar.gz gsoc2013-evolution-cc8aa371f56e4fa5f07142954bd350d0b33b6d51.tar.zst gsoc2013-evolution-cc8aa371f56e4fa5f07142954bd350d0b33b6d51.zip |
split out module loadng code. (epl_construct): if we're enabled, and
2004-11-18 Not Zed <NotZed@Ximian.com>
* e-plugin.c (epl_loadmodule): split out module loadng code.
(epl_construct): if we're enabled, and load-on-startup is set,
load the module right away. Not to be abused!
svn path=/trunk/; revision=27939
-rw-r--r-- | e-util/ChangeLog | 6 | ||||
-rw-r--r-- | e-util/e-plugin.c | 67 |
2 files changed, 53 insertions, 20 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 9244442c84..4464929ffd 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,9 @@ +2004-11-18 Not Zed <NotZed@Ximian.com> + + * e-plugin.c (epl_loadmodule): split out module loadng code. + (epl_construct): if we're enabled, and load-on-startup is set, + load the module right away. Not to be abused! + 2004-11-03 Not Zed <NotZed@Ximian.com> * e-plugin.c (e_plugin_list_plugins): added helper api to list all diff --git a/e-util/e-plugin.c b/e-util/e-plugin.c index 0a0688a5cd..d163a8a5ec 100644 --- a/e-util/e-plugin.c +++ b/e-util/e-plugin.c @@ -736,22 +736,15 @@ static void *epl_parent_class; pages. */ -static void * -epl_invoke(EPlugin *ep, const char *name, void *data) +static int +epl_loadmodule(EPlugin *ep) { - EPluginLibFunc cb; - - if (!ep->enabled) { - g_warning("trying to invoke '%s' on disabled plugin '%s'", name, ep->id); - return NULL; - } - if (epl->module == NULL) { EPluginLibEnableFunc enable; if ((epl->module = g_module_open(epl->location, 0)) == NULL) { g_warning("can't load plugin '%s'", g_module_error()); - return NULL; + return -1; } if (g_module_symbol(epl->module, "e_plugin_lib_enable", (void *)&enable)) { @@ -759,11 +752,27 @@ epl_invoke(EPlugin *ep, const char *name, void *data) ep->enabled = FALSE; g_module_close(epl->module); epl->module = NULL; - return NULL; + return -1; } } } + return 0; +} + +static void * +epl_invoke(EPlugin *ep, const char *name, void *data) +{ + EPluginLibFunc cb; + + if (!ep->enabled) { + g_warning("trying to invoke '%s' on disabled plugin '%s'", name, ep->id); + return NULL; + } + + if (epl_loadmodule(ep) != 0) + return NULL; + if (!g_module_symbol(epl->module, name, (void *)&cb)) { g_warning("Cannot resolve symbol '%s' in plugin '%s' (not exported?)", name, epl->location); return NULL; @@ -783,28 +792,46 @@ epl_construct(EPlugin *ep, xmlNodePtr root) if (epl->location == NULL) return -1; + /* If we're enabled, check for the load-on-startup property */ + if (ep->enabled) { + xmlChar *tmp; + + tmp = xmlGetProp(root, "load-on-startup"); + if (tmp) { + xmlFree(tmp); + if (epl_loadmodule(ep) != 0) + return -1; + } + } + return 0; } static void epl_enable(EPlugin *ep, int state) { + EPluginLibEnableFunc enable; + ((EPluginClass *)epl_parent_class)->enable(ep, state); - /* try and unload the module if the plugin will let us */ - /* This may cause more problems than its worth ... so actual module removal disabled for now */ - if (epl->module && !state) { - EPluginLibEnableFunc enable; + /* if we're disabling and it isn't loaded, nothing to do */ + if (!state && epl->module == NULL) + return; - if (g_module_symbol(epl->module, "e_plugin_lib_enable", (void *)&enable)) { - if (enable(epl, FALSE) != 0) - return; - } + /* this will noop if we're disabling since we tested it above */ + if (epl_loadmodule(ep) != 0) + return; + + if (g_module_symbol(epl->module, "e_plugin_lib_enable", (void *)&enable)) { + if (enable(epl, state) != 0) + return; + } #if 0 + if (!state) { g_module_close(epl->module); epl->module = NULL; -#endif } +#endif } static void |