From 105394bcc19b3565c6b77d38625d8813596d0c1b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Wed, 4 Oct 2017 20:36:48 +0200 Subject: Updated and improved the plugin system. --- ChangeLog | 13 +++++++++++++ plugins/elf/core.c | 4 ++-- src/plugins/pglist.c | 16 ++++++++++++++++ src/plugins/plugin-def.h | 2 +- src/plugins/plugin.c | 40 +++++++++++++++++++++++++++++++++------- src/plugins/plugin.h | 5 ++++- 6 files changed, 69 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 420972c..f5950db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +17-10-04 Cyrille Bagard + + * plugins/elf/core.c: + Register proper dependencies for the ELF support. + + * src/plugins/pglist.c: + * src/plugins/plugin-def.h: + Update and improve the plugin system. + + * src/plugins/plugin.c: + * src/plugins/plugin.h: + Fix many mistakes in the plugin system. + 17-10-01 Cyrille Bagard * configure.ac: diff --git a/plugins/elf/core.c b/plugins/elf/core.c index 5e2e19c..fde6be1 100644 --- a/plugins/elf/core.c +++ b/plugins/elf/core.c @@ -33,8 +33,8 @@ -DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("elf", "Add suport for the ELF format", "0.1.0", - PGA_PLUGIN_INIT); +DEFINE_CHRYSALIDE_PLUGIN("elf", "Add suport for the ELF format", "0.1.0", + RL("PyChrysalide"), AL(PGA_PLUGIN_INIT)); diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c index 54c8784..2010cda 100644 --- a/src/plugins/pglist.c +++ b/src/plugins/pglist.c @@ -306,6 +306,22 @@ void load_remaning_plugins(void) } while (changed); + for (i = 0; i < _pg_count; i++) + { + flags = g_plugin_module_get_flags(_pg_list[i]); + + if (flags & PSF_UNKNOW_DEP) + log_variadic_message(LMT_ERROR, + _("There is (at least) one unknown dependency in the plugin '%s'"), + g_plugin_module_get_filename(_pg_list[i])); + + else if (flags & PSF_DEP_LOOP) + log_variadic_message(LMT_ERROR, + _("There is a dependency loop in the plugin '%s'"), + g_plugin_module_get_filename(_pg_list[i])); + + } + /* Effectue les chargements possibles */ for (i = 0; i < _pg_count; i++) diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h index e5d06c3..ed09e91 100644 --- a/src/plugins/plugin-def.h +++ b/src/plugins/plugin-def.h @@ -302,7 +302,7 @@ typedef struct _plugin_interface #define AL(...) BUILD_PG_LIST(.actions, ((plugin_action_t []){ __VA_ARGS__ })) -#define RL(...) BUILD_PG_LIST(.required, ((char *[]){ __VA_ARGS__ })) +#define RL(...) BUILD_PG_LIST(.required, ((const char *[]){ __VA_ARGS__ })) #define DEFINE_CHRYSALIDE_PLUGIN(n, d, v, r, a) \ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index f12c1f6..a57cb6f 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -336,6 +336,25 @@ GPluginModule *g_plugin_module_new(const gchar *filename) * * * Paramètres : plugin = greffon à consulter. * * * +* Description : Indique le fichier contenant le greffon manipulé. * +* * +* Retour : Chemin d'accès au greffon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_plugin_module_get_filename(const GPluginModule *plugin) +{ + return plugin->filename; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* * * Description : Fournit la description du greffon dans son intégralité. * * * * Retour : Interfaçage renseigné. * @@ -403,7 +422,7 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * assert(count == get_bit_field_size(plugin->dependencies)); #endif - if ((plugin->flags & (PSF_UNKNOW_DEP | PSF_DEP_LOOP)) != 0) + if ((plugin->flags & (PSF_UNKNOW_DEP | PSF_DEP_LOOP)) == 0) { pg_iface = g_plugin_module_get_interface(plugin); @@ -420,9 +439,10 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * else { + set_in_bit_field(new, index, 1); or_bit_field(new, dependency->dependencies); - g_object_ref(G_OBJECT(dependency)); + g_object_unref(G_OBJECT(dependency)); } @@ -446,7 +466,7 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * if (test_in_bit_field(plugin->dependencies, index)) plugin->flags |= PSF_DEP_LOOP; - g_object_ref(G_OBJECT(dependency)); + g_object_unref(G_OBJECT(dependency)); } @@ -483,9 +503,7 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co flags = g_plugin_module_get_flags(plugin); - assert((flags & BROKEN_PLUGIN_STATUS) == 0); - - if (flags & PSF_FAILURE) return false; + if (flags & BROKEN_PLUGIN_STATUS) return false; if (flags & PSF_LOADED) return true; @@ -498,14 +516,17 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co for (i = 0; i < pg_iface->required_count && result; i++) { dependency = get_plugin_by_name(pg_iface->required[i], NULL); + assert(dependency != NULL); result = g_plugin_module_load(dependency, list, count); + g_object_unref(G_OBJECT(dependency)); + } if (!result) log_variadic_message(LMT_ERROR, - _("Some dependencies failed to load for Plugin '%s'"), plugin->filename); + _("Some dependencies failed to load for plugin '%s'"), plugin->filename); /* Chargement du greffon courant */ @@ -516,9 +537,14 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co result = plugin->init(plugin); if (!result) + { log_variadic_message(LMT_ERROR, _("Plugin '%s' failed to load itself..."), plugin->filename); + plugin->flags |= PSF_FAILURE; + + } + } if (result) diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index 6d783b7..78dcaa6 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -51,7 +51,7 @@ typedef enum _PluginStatusFlags PSF_UNKNOW_DEP = (1 << 0), /* Dépendance non trouvée */ PSF_DEP_LOOP = (1 << 1), /* Dépendances circulaires */ PSF_FAILURE = (1 << 2), /* Erreur au chargement */ - PSF_LOADED = (1 << 2) /* Greffon intégré au système */ + PSF_LOADED = (1 << 3) /* Greffon intégré au système */ } PluginStatusFlags; @@ -73,6 +73,9 @@ GType g_plugin_module_get_type(void); /* Crée un module pour un greffon donné. */ GPluginModule *g_plugin_module_new(const gchar *); +/* Indique le fichier contenant le greffon manipulé. */ +const char *g_plugin_module_get_filename(const GPluginModule *); + /* Fournit la description du greffon dans son intégralité. */ const plugin_interface *g_plugin_module_get_interface(const GPluginModule *); -- cgit v0.11.2-87-g4458