diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2025-01-12 14:23:01 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2025-01-12 14:23:01 (GMT) |
commit | baa854bfcc969022a00617b58a661e37f345cab5 (patch) | |
tree | 093d3ace4c2e1ad8fa37ce5e08723f768fffbada /src/plugins/plugin.c | |
parent | 0fdba5bd3e2c9ed913619990dbda7925867e46c5 (diff) |
Rewrite the plugin system.
Diffstat (limited to 'src/plugins/plugin.c')
-rw-r--r-- | src/plugins/plugin.c | 970 |
1 files changed, 200 insertions, 770 deletions
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 75cf4e0..c537bc3 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -30,7 +30,6 @@ #include <libgen.h> #include <malloc.h> #include <stdarg.h> -#include <stdbool.h> #include <stdio.h> #include <string.h> @@ -38,6 +37,7 @@ #include "dt.h" #include "pglist.h" #include "plugin-int.h" +#include "../common/compiler.h" #include "../common/extstr.h" #include "../common/pathname.h" #include "../common/xdg.h" @@ -56,19 +56,12 @@ static void g_plugin_module_dispose(GPluginModule *); /* Procède à la libération totale de la mémoire. */ static void g_plugin_module_finalize(GPluginModule *); -/* Initialise la classe des greffons d'extension. */ -static void g_plugin_module_init_gclass(GPluginModuleClass *, GModule *); - -/* Fournit le nom brut associé au greffon. */ -static char *_g_plugin_module_get_modname(const GPluginModule *); - /* Indique le type défini pour un greffon. */ G_DEFINE_TYPE(GPluginModule, g_plugin_module, G_TYPE_OBJECT); - /****************************************************************************** * * * Paramètres : class = classe à initialiser. * @@ -84,16 +77,17 @@ G_DEFINE_TYPE(GPluginModule, g_plugin_module, G_TYPE_OBJECT); static void g_plugin_module_class_init(GPluginModuleClass *class) { GObjectClass *object; /* Autre version de la classe */ - GPluginModuleClass *plugin; /* Version parente de la classe*/ object = G_OBJECT_CLASS(class); object->dispose = (GObjectFinalizeFunc/* ! */)g_plugin_module_dispose; object->finalize = (GObjectFinalizeFunc)g_plugin_module_finalize; - plugin = G_PLUGIN_MODULE_CLASS(class); + class->get_filename = NULL; + class->get_modname = NULL; - plugin->get_modname = (pg_get_modname_fc)_g_plugin_module_get_modname; + class->enable = NULL; + class->disable = NULL; } @@ -112,7 +106,17 @@ static void g_plugin_module_class_init(GPluginModuleClass *class) static void g_plugin_module_init(GPluginModule *plugin) { - //plugin->config = NULL; + plugin->name = NULL; + plugin->desc = NULL; + plugin->version = NULL; + plugin->url = NULL; + + plugin->required = NULL; + plugin->required_count = 0; + + plugin->flags = PSF_NONE; + + plugin->dependencies = NULL; } @@ -131,58 +135,35 @@ static void g_plugin_module_init(GPluginModule *plugin) static void g_plugin_module_dispose(GPluginModule *plugin) { - const plugin_interface *pg_iface; /* Définition du greffon */ size_t i; /* Boucle de parcours */ GPluginModule *dependency; /* Module nécessaire */ GPluginModuleClass *class; /* Classe de l'instance active */ - pg_iface = g_plugin_module_get_interface(plugin); + lock_plugin_list_for_reading(); - if (pg_iface != NULL) + for (i = 0; i < plugin->required_count; i++) { - lock_plugin_list_for_reading(); + dependency = get_plugin_by_name(plugin->required[i], NULL); - for (i = 0; i < pg_iface->required_count; i++) + /* Si le chargement a bien été complet avant la sortie... */ + if (dependency != NULL) { - dependency = get_plugin_by_name(pg_iface->required[i], NULL); + /* Un coup pour l'appel à get_plugin_by_name(). */ + unref_object(dependency); - /* Si le chargement a bien été complet avant la sortie... */ - if (dependency != NULL) - { - /* Un coup pour l'appel à get_plugin_by_name(). */ - g_object_unref(G_OBJECT(dependency)); - - /* Un coup pour la dépendance */ - g_object_unref(G_OBJECT(dependency)); - - } + /* Un coup pour la dépendance */ + unref_object(dependency); } - unlock_plugin_list_for_reading(); - } - class = G_PLUGIN_MODULE_GET_CLASS(plugin); + unlock_plugin_list_for_reading(); - if (class->exit != NULL) - class->exit(plugin); - - /* - if (plugin->config != NULL) - { - g_generic_config_write(plugin->config); - - g_clear_object(&plugin->config); + class = G_PLUGIN_MODULE_GET_CLASS(plugin); - } - */ - - if (plugin->module != NULL) - { - g_module_close(plugin->module); - plugin->module = NULL; - } + if (class->disable != NULL) + class->disable(plugin); G_OBJECT_CLASS(g_plugin_module_parent_class)->dispose(G_OBJECT(plugin)); @@ -203,7 +184,25 @@ static void g_plugin_module_dispose(GPluginModule *plugin) static void g_plugin_module_finalize(GPluginModule *plugin) { - free(plugin->filename); + size_t i; /* Boucle de parcours */ + + if (plugin->name != NULL) + free(plugin->name); + + if (plugin->desc != NULL) + free(plugin->desc); + + if (plugin->version != NULL) + free(plugin->version); + + if (plugin->url != NULL) + free(plugin->url); + + for (i = 0; i < plugin->required_count; i++) + free(plugin->required[i]); + + if (plugin->required != NULL) + free(plugin->required); if (plugin->dependencies != NULL) delete_bit_field(plugin->dependencies); @@ -215,627 +214,173 @@ static void g_plugin_module_finalize(GPluginModule *plugin) /****************************************************************************** * * -* Paramètres : filename = nom du fichier à charger. * +* Paramètres : plugin = instance à initialiser pleinement. * +* name = nom du greffon pour référence, principalement. * +* desc = présentation éventuelle à destination humaine. * +* version = indication de version éventuelle. * +* url = référence vers une ressource en ligne. * +* required = liste de dépendances éventuelles ou NULL. * +* count = taille de cette liste. * * * -* Description : Crée un module pour un greffon donné. * +* Description : Met en place un greffon. * * * -* Retour : Adresse de la structure mise en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GPluginModule *g_plugin_module_new(const gchar *filename) +bool g_plugin_module_create(GPluginModule *plugin, const char *name, const char *desc, const char *version, const char *url, const char * const *required, size_t count) { - GPluginModule *result; /* Structure à retourner */ - GModule *module; /* Abstration de manipulation */ - pg_set_self_fc set_self; /* Copie du greffon */ - const plugin_interface *interface; /* Déclaration d'interfaçage */ - plugin_abi_version_t current; /* Version de l'ABI actuelle */ - bool valid; /* Statut de validité */ - size_t i; /* Boucle de parcours */ - uint32_t action; /* Identifiant d'une action */ - uint32_t category; /* Catégorie principale */ - uint32_t sub; /* Sous-catégorie visée */ - GType gtype; /* Nouveau type de greffon */ - - module = g_module_open(filename, G_MODULE_BIND_LAZY); - if (module == NULL) - { - log_variadic_message(LMT_ERROR, - _("Error while loading the plugin candidate '%s' : %s"), - filename, g_module_error()); - goto bad_module; - } - - -#define load_plugin_symbol(mod, sym, dest) \ - ({ \ - bool __result; \ - if (!g_module_symbol(mod, sym, (gpointer *)dest)) \ - { \ - log_variadic_message(LMT_ERROR, \ - _("No '%s' entry in plugin candidate '%s'"), \ - sym, filename); \ - __result = false; \ - } \ - else __result = true; \ - __result; \ - }) - - - /* Récupération de la version d'ABI */ - - if (!load_plugin_symbol(module, "chrysalide_plugin_set_self", &set_self)) - goto no_self_setter; - - if (!load_plugin_symbol(module, "_chrysalide_plugin", &interface)) - goto no_interface; - - current = CURRENT_ABI_VERSION; - - if (current != interface->abi_version) - goto wrong_abi; - - /* Localisation des différents points d'entrée déclarés */ - + bool result; /* Bilan à retourner */ + size_t i; /* Boucle de parcours #1 */ + size_t k; /* Boucle de parcours #2 */ -#define check_plugin_symbol(mod, sym) \ - ({ \ - bool __result; \ - __result = g_module_symbol(mod, sym, (gpointer []) { NULL }); \ - if (!__result) \ - log_variadic_message(LMT_ERROR, \ - _("No '%s' entry in plugin candidate '%s'"), \ - sym, filename); \ - __result; \ - }) + /* Validations préalables */ + assert(name != NULL); - valid = true; + result = (name != NULL); - for (i = 0; i < interface->actions_count && valid; i++) + if (result && plugin->abi_version != CURRENT_ABI_VERSION) { - action = interface->actions[i]; - category = MASK_PLUGIN_CATEGORY(action); - sub = MASK_PLUGIN_SUB_CATEGORY(action); - - switch (category) - { - case DPC_BASIC: - - switch (sub) - { - case DPS_NONE: - break; - - case DPS_PG_MANAGEMENT: - - switch (action) - { - case PGA_PLUGIN_INIT: - valid = check_plugin_symbol(module, "chrysalide_plugin_init"); - break; - - case PGA_PLUGIN_LOADED: - valid = check_plugin_symbol(module, "chrysalide_plugin_manage"); - break; - - case PGA_PLUGIN_EXIT: - valid = check_plugin_symbol(module, "chrysalide_plugin_exit"); - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; - - } - - break; - - case DPS_CORE_MANAGEMENT: - - switch (action) - { - case PGA_NATIVE_PLUGINS_LOADED: - case PGA_ALL_PLUGINS_LOADED: - valid = check_plugin_symbol(module, "chrysalide_plugin_on_plugins_loaded"); - break; - - case PGA_TYPE_BUILDING: - valid = check_plugin_symbol(module, "chrysalide_plugin_build_type_instance"); - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; - - } - - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); - break; - - } - - break; - -#if 0 - - case DPC_GUI: - - switch (sub) - { - case DPS_SETUP: - - switch (action) - { - case PGA_GUI_THEME: - valid = check_plugin_symbol(module, "chrysalide_plugin_include_theme"); - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; - - } - - break; - - case DPS_RUNNING: - - switch (action) - { - case PGA_PANEL_CREATION: - valid = check_plugin_symbol(module, "chrysalide_plugin_on_panel_creation"); - break; - - case PGA_PANEL_DOCKING: - valid = check_plugin_symbol(module, "chrysalide_plugin_on_panel_docking"); - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; - - } - - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); - break; - - } - - break; - - case DPC_BINARY_PROCESSING: - - switch (sub) - { - case DPS_CONTENT: - - switch (action) - { - case PGA_CONTENT_EXPLORER: - case PGA_CONTENT_RESOLVER: - valid = check_plugin_symbol(module, "chrysalide_plugin_handle_binary_content"); - break; + result = false; - case PGA_CONTENT_ANALYZED: - valid = check_plugin_symbol(module, "chrysalide_plugin_handle_loaded_content"); - break; + log_variadic_message(LMT_ERROR, _("ABI mismatch detected: %08x (plugin) vs %08x (core)"), + plugin->abi_version, CURRENT_ABI_VERSION); - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; - - } - - break; - - case DPS_FORMAT: - - switch (action) - { - case PGA_FORMAT_ANALYSIS_STARTED: - case PGA_FORMAT_ANALYSIS_ENDED: - case PGA_FORMAT_POST_ANALYSIS_STARTED: - case PGA_FORMAT_POST_ANALYSIS_ENDED: - valid = check_plugin_symbol(module, "chrysalide_plugin_handle_binary_format_analysis"); - break; - - case PGA_FORMAT_PRELOAD: - valid = check_plugin_symbol(module, "chrysalide_plugin_preload_binary_format"); - break; + } - case PGA_FORMAT_ATTACH_DEBUG: - valid = check_plugin_symbol(module, "chrysalide_plugin_attach_debug"); - break; + /* Mémorisation des informations */ - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - interface->actions[i], filename); - break; + if (result) + { + plugin->name = strdup(name); - } + if (desc != NULL) + plugin->desc = strdup(desc); - break; + if (version != NULL) + plugin->version = strdup(version); - case DPS_DISASSEMBLY: - valid = check_plugin_symbol(module, "chrysalide_plugin_process_disassembly_event"); - break; + if (url != NULL) + plugin->url = strdup(url); - case DPS_DETECTION: - valid = check_plugin_symbol(module, "chrysalide_plugin_detect_external_tools"); - break; + if (count > 0) + { + plugin->required = malloc(count * sizeof(char *)); + plugin->required_count = 0; - default: - log_variadic_message(LMT_WARNING, - _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); + for (i = 0; i < count; i++) + { + for (k = 0; k < plugin->required_count; k++) + if (strcmp(required[i], plugin->required[k]) == 0) break; - } + if (k < plugin->required_count) + continue; -#endif + plugin->required[plugin->required_count++] = strdup(required[i]); - break; + } - default: - log_variadic_message(LMT_WARNING, - _("Unknown category '0x%02x' in plugin '%s'..."), category, filename); - break; + plugin->required = realloc(plugin->required, plugin->required_count * sizeof(char *)); } } - if (!valid) - goto missing_feature; - - gtype = build_dynamic_type(G_TYPE_PLUGIN_MODULE, interface->gtp_name, - (GClassInitFunc)g_plugin_module_init_gclass, module, NULL); - - if (gtype == G_TYPE_INVALID) - goto no_instance; - - result = g_object_new(gtype, NULL); - - result->filename = strdup(filename); - result->module = module; - - result->interface = interface; - - set_self(result); - return result; - no_self_setter: - - log_variadic_message(LMT_ERROR, _("Self pointer setter is missing for plugin '%s'"), filename); - goto bad_plugin; - - no_interface: - - log_variadic_message(LMT_ERROR, _("Main interface is missing for plugin '%s'"), filename); - goto bad_plugin; - - wrong_abi: - - log_variadic_message(LMT_ERROR, _("ABI mismatch detected! Plugin '%s' rejected"), filename); - goto bad_plugin; - - missing_feature: - - log_variadic_message(LMT_ERROR, _("An expected feature is missing for plugin '%s'"), filename); - goto bad_plugin; - - no_instance: - - log_variadic_message(LMT_ERROR, _("Unabled to create an instance of plugin '%s'"), filename); - - bad_plugin: - - g_module_close(module); - - bad_module: - - return NULL; - } /****************************************************************************** * * -* Paramètres : class = classe à initialiser. * -* module = module représentant le greffon chargé en mémoire. * +* Paramètres : plugin = greffon à consulter. * * * -* Description : Initialise la classe des greffons d'extension. * +* Description : Indique le nom associé à un greffon. * * * -* Retour : - * +* Retour : Désignation interne de l'extension, pour référence(s). * * * * Remarques : - * * * ******************************************************************************/ -static void g_plugin_module_init_gclass(GPluginModuleClass *class, GModule *module) +const char *g_plugin_module_get_name(const GPluginModule *plugin) { - const plugin_interface *interface; /* Déclaration d'interfaçage */ - size_t i; /* Boucle de parcours */ - uint32_t action; /* Identifiant d'une action */ - uint32_t category; /* Catégorie principale */ - uint32_t sub; /* Sous-catégorie visée */ - - -#undef load_plugin_symbol - -#define load_plugin_symbol(mod, sym, dest) \ - ({ \ - bool __result; \ - __result = g_module_symbol(mod, sym, (gpointer *)dest); \ - assert(__result); \ - __result; \ - }) - - - load_plugin_symbol(module, "_chrysalide_plugin", &interface); - - for (i = 0; i < interface->actions_count; i++) - { - action = interface->actions[i]; - category = MASK_PLUGIN_CATEGORY(action); - sub = MASK_PLUGIN_SUB_CATEGORY(action); - - switch (category) - { - case DPC_BASIC: - - switch (sub) - { - case DPS_NONE: - break; - - case DPS_PG_MANAGEMENT: - - switch (action) - { - case PGA_PLUGIN_INIT: - load_plugin_symbol(module, "chrysalide_plugin_init", &class->init); - break; - - case PGA_PLUGIN_LOADED: - load_plugin_symbol(module, "chrysalide_plugin_manage", &class->manage); - break; - - case PGA_PLUGIN_EXIT: - load_plugin_symbol(module, "chrysalide_plugin_exit", &class->exit); - break; - - default: - assert(false); - break; - - } - - break; - - case DPS_CORE_MANAGEMENT: - - switch (action) - { - case PGA_NATIVE_PLUGINS_LOADED: - case PGA_ALL_PLUGINS_LOADED: - load_plugin_symbol(module, "chrysalide_plugin_on_plugins_loaded", - &class->plugins_loaded); - break; - - case PGA_TYPE_BUILDING: - load_plugin_symbol(module, "chrysalide_plugin_build_type_instance", - &class->build_instance); - break; - - default: - assert(false); - break; - - } - - break; - - default: - assert(false); - break; - - } - - break; -#if 0 - case DPC_GUI: - - switch (sub) - { - case DPS_SETUP: - - switch (action) - { - case PGA_GUI_THEME: -#ifdef INCLUDE_GTK_SUPPORT - load_plugin_symbol(module, "chrysalide_plugin_include_theme", - &class->include_theme); -#endif - break; - - default: - assert(false); - break; - - } - - break; - - case DPS_RUNNING: - - switch (action) - { - case PGA_PANEL_CREATION: -#ifdef INCLUDE_GTK_SUPPORT - load_plugin_symbol(module, "chrysalide_plugin_on_panel_creation", - &class->notify_panel); -#endif - break; - - case PGA_PANEL_DOCKING: -#ifdef INCLUDE_GTK_SUPPORT - load_plugin_symbol(module, "chrysalide_plugin_on_panel_docking", - &class->notify_docking); -#endif - break; - - default: - assert(false); - break; - - } - - break; + const char *result; /* Valeur finale à renvoyer */ - default: - assert(false); - break; - - } - - break; - - case DPC_BINARY_PROCESSING: - - switch (sub) - { - case DPS_CONTENT: - - switch (action) - { - case PGA_CONTENT_EXPLORER: - case PGA_CONTENT_RESOLVER: - load_plugin_symbol(module, "chrysalide_plugin_handle_binary_content", - &class->handle_content); - break; - - case PGA_CONTENT_ANALYZED: - load_plugin_symbol(module, "chrysalide_plugin_handle_loaded_content", - &class->handle_loaded); - break; - - default: - assert(false); - break; - - } - - break; - - case DPS_FORMAT: + result = plugin->name; - switch (action) - { - case PGA_FORMAT_ANALYSIS_STARTED: - case PGA_FORMAT_ANALYSIS_ENDED: - case PGA_FORMAT_POST_ANALYSIS_STARTED: - case PGA_FORMAT_POST_ANALYSIS_ENDED: - load_plugin_symbol(module, "chrysalide_plugin_handle_binary_format_analysis", - &class->handle_fmt_analysis); - break; - - case PGA_FORMAT_PRELOAD: - load_plugin_symbol(module, "chrysalide_plugin_preload_binary_format", &class->preload_format); - break; - - case PGA_FORMAT_ATTACH_DEBUG: - load_plugin_symbol(module, "chrysalide_plugin_attach_debug", &class->attach_debug); - break; + return result; - default: - assert(false); - break; +} - } - break; +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* * +* Description : Fournit une description fonctionnelle d'un greffon. * +* * +* Retour : Description textuelle associée à une extension ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ - case DPS_DISASSEMBLY: - load_plugin_symbol(module, "chrysalide_plugin_process_disassembly_event", &class->process_disass); - break; +const char *g_plugin_module_get_desc(const GPluginModule *plugin) +{ + const char *result; /* Valeur finale à renvoyer */ - case DPS_DETECTION: - load_plugin_symbol(module, "chrysalide_plugin_detect_external_tools", &class->detect); - break; + result = plugin->desc; - default: - assert(false); - break; + return result; - } +} -#endif - break; +/****************************************************************************** +* * +* Paramètres : plugin = greffon à consulter. * +* * +* Description : Fournit la version d'un greffon et de ses fonctionnalités. * +* * +* Retour : Version sous forme de chaîne de caractères ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ - default: - assert(false); - break; +const char *g_plugin_module_get_version(const GPluginModule *plugin) +{ + const char *result; /* Valeur finale à renvoyer */ - } + result = plugin->version; - } + return result; } /****************************************************************************** * * -* Paramètres : plugin = greffon à valider. * +* Paramètres : plugin = greffon à consulter. * * * -* Description : Fournit le nom brut associé au greffon. * +* Description : Fournit l'URL des ressources en ligne liées à un greffon. * * * -* Retour : Désignation brute du greffon. * +* Retour : URL de renvoi associée à une extension ou NULL. * * * * Remarques : - * * * ******************************************************************************/ -char *g_plugin_module_get_modname(const GPluginModule *plugin) +const char *g_plugin_module_get_url(const GPluginModule *plugin) { - char *result; /* Désignation brute à renvoyer*/ - GPluginModuleClass *class; /* Classe de l'instance active */ - - class = G_PLUGIN_MODULE_GET_CLASS(plugin); - - result = class->get_modname(plugin); + const char *result; /* Valeur finale à renvoyer */ - /** - * Tente une opération de la dernière chance. - * - * Dans le cas d'un module Python, la fonction de classe peut ne pas - * trouver de support si l'extension Python n'est pas au point. - */ - if (result == NULL && class->get_modname != _g_plugin_module_get_modname) - result = _g_plugin_module_get_modname(plugin); + result = plugin->url; return result; @@ -844,41 +389,24 @@ char *g_plugin_module_get_modname(const GPluginModule *plugin) /****************************************************************************** * * -* Paramètres : plugin = greffon à valider. * +* Paramètres : plugin = greffon à consulter. * +* count = taille de la liste fournie. [OUT] * * * -* Description : Fournit le nom brut associé au greffon. * +* Description : Fournit la liste des dépendances d'un greffon donné. * * * -* Retour : Désignation brute du greffon. * +* Retour : Liste des noms d'extensions requises pour une extension. * * * * Remarques : - * * * ******************************************************************************/ -static char *_g_plugin_module_get_modname(const GPluginModule *plugin) +const char * const *g_plugin_module_get_requirements(const GPluginModule *plugin, size_t *count) { - char *result; /* Désignation brute à renvoyer*/ - char *path; /* Chemin à traiter */ - char *filename; /* Nom de bibliothèque partagée*/ - size_t length; /* Taille du nom */ - - path = strdup(g_plugin_module_get_filename(G_PLUGIN_MODULE(plugin))); - - filename = basename(path); - - if (strncmp(filename, "lib", 3) == 0) - filename += 3; - - length = strlen(filename); - - if (length >= 3) - { - if (strncmp(&filename[length - 3], ".so", 3) == 0) - filename[length - 3] = '\0'; - } + const char * const *result; /* Valeur finale à renvoyer */ - result = strdup(filename); + result = CONST_ARRAY_CAST(plugin->required, char); - free(path); + *count = plugin->required_count; return result; @@ -889,7 +417,7 @@ static char *_g_plugin_module_get_modname(const GPluginModule *plugin) * * * Paramètres : plugin = greffon à consulter. * * * -* Description : Indique le fichier contenant le greffon manipulé. * +* Description : Pointe le fichier contenant le greffon manipulé. * * * * Retour : Chemin d'accès au greffon. * * * @@ -897,28 +425,42 @@ static char *_g_plugin_module_get_modname(const GPluginModule *plugin) * * ******************************************************************************/ -const char *g_plugin_module_get_filename(const GPluginModule *plugin) +char *g_plugin_module_get_filename(const GPluginModule *plugin) { - return plugin->filename; + char *result; /* Chemin d'accès à renvoyer */ + GPluginModuleClass *class; /* Classe de l'instance active */ + + class = G_PLUGIN_MODULE_GET_CLASS(plugin); + + result = class->get_filename(plugin); + + return result; } /****************************************************************************** * * -* Paramètres : plugin = greffon à consulter. * +* Paramètres : plugin = greffon à valider. * * * -* Description : Fournit la description du greffon dans son intégralité. * +* Description : Fournit le nom brut associé au greffon. * * * -* Retour : Interfaçage renseigné. * +* Retour : Désignation brute du greffon. * * * * Remarques : - * * * ******************************************************************************/ -const plugin_interface *g_plugin_module_get_interface(const GPluginModule *plugin) +char *g_plugin_module_get_modname(const GPluginModule *plugin) { - return plugin->interface; + char *result; /* Désignation brute à renvoyer*/ + GPluginModuleClass *class; /* Classe de l'instance active */ + + class = G_PLUGIN_MODULE_GET_CLASS(plugin); + + result = class->get_modname(plugin); + + return result; } @@ -979,7 +521,6 @@ void g_plugin_module_override_flags(GPluginModule *plugin, PluginStatusFlags fla bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule **list, size_t count) { bool result; /* Bilan à faire remonter */ - const plugin_interface *pg_iface; /* Définition du greffon */ bitfield_t *new; /* Nouvelle définition */ size_t i; /* Boucle de parcours */ GPluginModule *dependency; /* Module nécessaire */ @@ -997,15 +538,13 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * if ((plugin->flags & (PSF_UNKNOW_DEP | PSF_DEP_LOOP)) == 0) { - pg_iface = g_plugin_module_get_interface(plugin); - /* Collecte des dépendances */ new = dup_bit_field(plugin->dependencies); - for (i = 0; i < pg_iface->required_count; i++) + for (i = 0; i < plugin->required_count; i++) { - dependency = get_plugin_by_name(pg_iface->required[i], &index); + dependency = get_plugin_by_name(plugin->required[i], &index); if (dependency == NULL) plugin->flags |= PSF_UNKNOW_DEP; @@ -1023,7 +562,7 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * */ if (test_in_bit_field(plugin->dependencies, index)) - g_object_unref(G_OBJECT(dependency)); + unref_object(dependency); } @@ -1041,13 +580,14 @@ bool g_plugin_module_resolve_dependencies(GPluginModule *plugin, GPluginModule * /* Vérification sanitaire */ - dependency = get_plugin_by_name(pg_iface->name, &index); + dependency = get_plugin_by_name(plugin->name, &index); assert(dependency != NULL); + assert(dependency == plugin); if (test_in_bit_field(plugin->dependencies, index)) plugin->flags |= PSF_DEP_LOOP; - g_object_unref(G_OBJECT(dependency)); + unref_object(dependency); } @@ -1075,12 +615,12 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co { bool result; /* Bilan à retourner */ PluginStatusFlags flags; /* Fanions de greffon */ - const plugin_interface *pg_iface; /* Définition du greffon */ size_t i; /* Boucle de parcours */ GPluginModule *dependency; /* Module nécessaire */ + char *filename; /* Chemin d'accès au greffon */ GPluginModuleClass *class; /* Classe de l'instance active */ - //GGenConfig *config; /* Configuration à charger */ - char *dir; /* Répertoire modifiable */ + char *tmp; /* Chaîne modifiable */ + char *dir; /* Pointeur vers répertoire */ /* Si un essai précédent a déjà échoué ou réussi... */ @@ -1092,40 +632,41 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co /* Chargement des dépendances */ - pg_iface = g_plugin_module_get_interface(plugin); - result = true; - for (i = 0; i < pg_iface->required_count && result; i++) + filename = g_plugin_module_get_filename(plugin); + + for (i = 0; i < plugin->required_count && result; i++) { - dependency = get_plugin_by_name(pg_iface->required[i], NULL); + dependency = get_plugin_by_name(plugin->required[i], NULL); assert(dependency != NULL); result = g_plugin_module_load(dependency, list, count); - g_object_unref(G_OBJECT(dependency)); + unref_object(dependency); } if (!result) { - log_variadic_message(LMT_ERROR, - _("Some dependencies failed to load for plugin '%s'"), plugin->filename); + log_variadic_message(LMT_ERROR, _("Some dependencies failed to load for plugin '%s'"), filename); + + plugin->flags |= PSF_FAILURE; goto failure; + } /* Chargement du greffon courant */ class = G_PLUGIN_MODULE_GET_CLASS(plugin); - if (class->init != NULL) + if (class->enable != NULL) { - result = class->init(plugin); + result = class->enable(plugin); if (!result) { - log_variadic_message(LMT_ERROR, - _("Plugin '%s' failed to load itself..."), plugin->filename); + log_variadic_message(LMT_ERROR, _("Plugin '%s' failed to load itself..."), filename); plugin->flags |= PSF_FAILURE; goto failure; @@ -1134,39 +675,23 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co } - g_plugin_module_create_config(plugin); - - result = g_plugin_module_manage(plugin, PGA_PLUGIN_LOADED); + /* Message de bilan */ - if (!result) - { - log_variadic_message(LMT_ERROR, - _("Plugin '%s' failed to complete loading..."), plugin->filename); - - plugin->flags |= PSF_FAILURE; - goto failure; - - } - - /* - config = g_plugin_module_get_config(plugin); - g_generic_config_read(config); - g_object_unref(G_OBJECT(config)); - */ - - dir = strdup(plugin->filename); - dir = dirname(dir); + tmp = strdup(filename); + dir = dirname(tmp); log_variadic_message(LMT_PROCESS, _("Loaded the '<b>%s</b>' file as plugin from the '<b>%s</b>' directory"), - strrchr(plugin->filename, G_DIR_SEPARATOR) + 1, dir); + strrchr(filename, G_DIR_SEPARATOR) + 1, dir); - free(dir); + free(tmp); plugin->flags |= PSF_LOADED; failure: + free(filename); + return result; } @@ -1227,31 +752,6 @@ char *g_plugin_module_build_config_filename(const GPluginModule *plugin, const c /****************************************************************************** * * -* Paramètres : plugin = greffon à compléter. * -* * -* Description : Met en place la configuration dédiée au greffon. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_plugin_module_create_config(GPluginModule *plugin) -{ - char *filename; /* Chemin d'accès particulier */ - - filename = g_plugin_module_build_config_filename(plugin, "config.xml", false); - - //plugin->config = g_generic_config_new_from_file(filename); - - free(filename); - -} - - -/****************************************************************************** -* * * Paramètres : plugin = greffon à consulter. * * * * Description : Fournit la configuration mise en place pour le greffon. * @@ -1295,11 +795,11 @@ void g_plugin_module_log_simple_message(const GPluginModule *plugin, LogMessageT size_t len; /* Taille tampon disponible */ char *buffer; /* Tampon du msg reconstitué */ - len = 4 + strlen(plugin->interface->name) + 6 + strlen(msg) + 1; + len = 4 + strlen(plugin->name) + 6 + strlen(msg) + 1; buffer = calloc(len, sizeof(char)); strcpy(buffer, "<i>["); - strcat(buffer, plugin->interface->name); + strcat(buffer, plugin->name); strcat(buffer, "]</i> "); strcat(buffer, msg); @@ -1345,80 +845,12 @@ void g_plugin_module_log_variadic_message(const GPluginModule *plugin, LogMessag } -/****************************************************************************** -* * -* Paramètres : plugin = greffon à manipuler. * -* action = type d'action attendue. * -* * -* Description : Encadre une étape de la vie d'un greffon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_plugin_module_manage(GPluginModule *plugin, PluginAction action) -{ - bool result; /* Bilan à faire remonter */ - GPluginModuleClass *class; /* Classe de l'instance active */ - const plugin_interface *pg_iface; /* Informations à consulter */ - size_t i; /* Boucle de parcours */ - bool handle_action; /* Action supportée ? */ - - class = G_PLUGIN_MODULE_GET_CLASS(plugin); - - if (class->manage == NULL) - result = true; - - else - { - handle_action = false; - - pg_iface = g_plugin_module_get_interface(plugin); - - for (i = 0; i < pg_iface->actions_count; i++) - if (pg_iface->actions[i] == PGA_PLUGIN_LOADED) - { - handle_action = true; - break; - } - - if (handle_action) - result = class->manage(plugin/*, action*/); - else - result = true; - - } - - return result; - -} -/****************************************************************************** -* * -* Paramètres : plugin = greffon à manipuler. * -* action = type d'action attendue. * -* unused = variable non utilisé pour l'usage de __VA_ARGS__. * -* * -* Description : Accompagne la fin du chargement des modules. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_plugin_module_notify_plugins_loaded(GPluginModule *plugin, PluginAction action, void *unused) -{ - GPluginModuleClass *class; /* Classe de l'instance active */ - class = G_PLUGIN_MODULE_GET_CLASS(plugin); - class->plugins_loaded(plugin, action); -} +#if 0 /****************************************************************************** @@ -1450,8 +882,6 @@ gpointer g_plugin_module_build_type_instance(GPluginModule *plugin, PluginAction -#if 0 - #ifdef INCLUDE_GTK_SUPPORT |