diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-01-26 21:37:49 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-01-26 21:37:49 (GMT) |
commit | 262c95e0b088a56e9fd919edc57ad19f85e2e40e (patch) | |
tree | 8510a15924423abb3208610f724d911f2f79b9a6 /src/plugins/pglist.c | |
parent | 0993276d6450919c6d178182c5fd26497b62d5fc (diff) |
Begun to rewrite the whole plugins system.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@461 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/plugins/pglist.c')
-rw-r--r-- | src/plugins/pglist.c | 149 |
1 files changed, 65 insertions, 84 deletions
diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c index 9286085..70fc66a 100644 --- a/src/plugins/pglist.c +++ b/src/plugins/pglist.c @@ -25,6 +25,7 @@ #include "pglist.h" +#include <assert.h> #include <dirent.h> #include <malloc.h> #include <string.h> @@ -37,14 +38,23 @@ #include "../common/extstr.h" +/* Représentation dédiée aux listes de greffons */ +typedef struct _pg_array +{ + PluginAction action; /* Action commune ou PGA_ALL */ + + GPluginModule **plugins; /* Liste de greffons */ + size_t plugins_count; /* Taille de cette liste */ + +} pg_array; /* Propriétés de l'ensemble des greffons */ typedef struct _plugins_list { GObject *ref; /* Référencement global */ - GPluginModule **plugins; /* Liste de greffons */ - size_t plugins_count; /* Taille de cette liste */ + pg_array *all; /* Liste de tous les greffons */ + pg_array sorted[PGA_COUNT]; /* Tri par catégories */ } plugins_list; @@ -75,9 +85,17 @@ void browse_directory_for_plugins(plugins_list *, const char *); bool init_all_plugins(GObject *ref) { + size_t i; /* Boucle de parcours */ + _list.ref = ref; g_object_ref(ref); + for (i = 0; i < PGA_COUNT; i++) + _list.sorted[i].action = PGA_EMPTY; + + _list.sorted[0].action = PGA_ALL; + _list.all = &_list.sorted[0]; + browse_directory_for_plugins(&_list, PACKAGE_SOURCE_DIR "/plugins"); return true; @@ -101,11 +119,11 @@ void exit_all_plugins(void) { size_t i; /* Boucle de parcours */ - for (i = 0; i < _list.plugins_count; i++) - g_object_unref(_list.plugins[i]); + for (i = 0; i < _list.all->plugins_count; i++) + g_object_unref(_list.all->plugins[i]); - if (_list.plugins != NULL) - free(_list.plugins); + for (i = 0; i < PGA_COUNT; i++) + free(_list.sorted[i].plugins); g_object_unref(_list.ref); @@ -199,60 +217,30 @@ void browse_directory_for_plugins(plugins_list *list, const char *dir) /****************************************************************************** * * * Paramètres : action = fonctionnalité recherchée. * -* * -* Description : Founit un greffon offrant le service demandé. * -* * -* Retour : Greffon satisfaisant ou NULL si aucun. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPluginModule *get_one_plugin_for_action(PluginAction action) -{ - GPluginModule *result; /* Greffon à retourner */ - size_t i; /* Boucle de parcours */ - - result = NULL; - - for (i = 0; i < _list.plugins_count; i++) - if (g_plugin_module_get_action(_list.plugins[i]) & action) - { - result = _list.plugins[i]; - break; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : action = fonctionnalité recherchée. * * count = nombre de greffons trouvés. [OUT] * * * * Description : Founit les greffons offrant le service demandé. * * * -* Retour : Liste de greffons correspondants à libérer de la mémoire. * +* Retour : Liste de greffons correspondants issue d'un tri interne. * * * * Remarques : - * * * ******************************************************************************/ -GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count) +const GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count) { - GPluginModule **result; /* Greffon à retourner */ + const GPluginModule **result; /* Greffon à retourner */ size_t i; /* Boucle de parcours */ result = NULL; *count = 0; - for (i = 0; i < _list.plugins_count; i++) - if (g_plugin_module_get_action(_list.plugins[i]) & action) + for (i = 0; i < PGA_COUNT; i++) + if (_list.sorted[i].action == action) { - result = (GPluginModule **)realloc(result, ++(*count) * sizeof(GPluginModule *)); - result[*count - 1] = _list.plugins[i]; + result = (const GPluginModule **)_list.sorted[i].plugins; + *count = _list.sorted[i].plugins_count; + break; } return result; @@ -274,57 +262,50 @@ GPluginModule **get_all_plugins_for_action(PluginAction action, size_t *count) void add_plugin_to_main_list(GPluginModule *plugin) { - plugins_list *list; /* Liste à modifier */ + const plugin_interface *interface; /* Informations à consulter */ + size_t i; /* Boucle de parcours #1 */ + size_t j; /* Boucle de parcours #2 */ - list = &_list; + interface = g_plugin_module_get_interface(plugin); - if (plugin->init != NULL && !plugin->init(plugin, list->ref)) + void add_plugin_into_array(pg_array *array, GPluginModule *pg) { - log_variadic_message(LMT_ERROR, _("Initialization of plugin '%s' failed !"), - plugin->filename); - g_object_unref(G_OBJECT(plugin)); - return; - } + array->plugins = (GPluginModule **)realloc(array->plugins, + ++array->plugins_count * sizeof(GPluginModule)); - list->plugins = (GPluginModule **)realloc(list->plugins, ++list->plugins_count * sizeof(GPluginModule *)); - list->plugins[list->plugins_count - 1] = plugin; + array->plugins[array->plugins_count - 1] = pg; -} + } + /* FIXME : lock */ -/****************************************************************************** -* * -* Paramètres : binary = binaire chargé en mémoire à traiter. * -* action = fonctionnalité recherchée. * -* lock = indique si l'exécution n'est pas celle principale. * -* * -* Description : Opère une action donnée sur un binaire défini. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ + add_plugin_into_array(_list.all, plugin); -void run_plugins_on_binary(GLoadedBinary *binary, PluginAction action, bool lock) -{ - size_t i; /* Boucle de parcours */ + for (i = 0; i < interface->actions_count; i++) + { + if (interface->actions[i] == PGA_ALL) continue; - /* - if (lock) - gdk_threads_enter(); - */ + for (j = 1; j < PGA_COUNT; j++) + { + if (_list.sorted[j].action == interface->actions[i]) + { + add_plugin_into_array(&_list.sorted[j], plugin); + break; + } + + else if (_list.sorted[j].action == PGA_EMPTY) + { + add_plugin_into_array(&_list.sorted[j], plugin); + _list.sorted[j].action = interface->actions[i]; + break; + } - for (i = 0; i < _list.plugins_count; i++) - if (g_plugin_module_get_action(_list.plugins[i]) & action) - g_plugin_module_execute_action_on_binary(_list.plugins[i], binary, action); + } + + assert(j < PGA_COUNT); - /* - if (lock) - { - gdk_flush(); - gdk_threads_leave(); } - */ + + /* FIXME : lock */ } |