summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-31 11:40:42 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-31 11:40:42 (GMT)
commit8965133f188c817cbdf4fcf9d1f1b60462bbfe7d (patch)
tree96193fdbcb692790bb2ffe4de7b2020b0dbf528d /src
parent93e9ab125bced1374c7d4a03e5bd11a0dc1b2968 (diff)
Offered a custom configuration facility to each plugin.
Diffstat (limited to 'src')
-rw-r--r--src/glibext/configuration.c22
-rw-r--r--src/plugins/pglist.c2
-rw-r--r--src/plugins/pglist.h4
-rw-r--r--src/plugins/plugin-def.h9
-rw-r--r--src/plugins/plugin-int.h7
-rw-r--r--src/plugins/plugin.c184
-rw-r--r--src/plugins/plugin.h7
7 files changed, 198 insertions, 37 deletions
diff --git a/src/glibext/configuration.c b/src/glibext/configuration.c
index 1fa2968..8746bfd 100644
--- a/src/glibext/configuration.c
+++ b/src/glibext/configuration.c
@@ -1323,14 +1323,21 @@ void g_generic_config_build(GGenConfig *config, const char *name)
{
char *suffix; /* Fin du nom de fichier */
- suffix = strdup("chrysalide");
- suffix = stradd(suffix, G_DIR_SEPARATOR_S);
- suffix = stradd(suffix, name);
- suffix = stradd(suffix, ".xml");
+ if (g_path_is_absolute(name))
+ config->filename = strdup(name);
- config->filename = get_xdg_config_dir(suffix);
+ else
+ {
+ suffix = strdup("chrysalide");
+ suffix = stradd(suffix, G_DIR_SEPARATOR_S);
+ suffix = stradd(suffix, name);
+ suffix = stradd(suffix, ".xml");
+
+ config->filename = get_xdg_config_dir(suffix);
- free(suffix);
+ free(suffix);
+
+ }
}
@@ -1468,7 +1475,8 @@ bool g_generic_config_write(GGenConfig *config)
g_generic_config_runlock(config);
- save_xml_file(xdoc, config->filename);
+ if (result)
+ result = save_xml_file(xdoc, config->filename);
close_xml_file(xdoc, context);
diff --git a/src/plugins/pglist.c b/src/plugins/pglist.c
index ffcda63..c1d96ed 100644
--- a/src/plugins/pglist.c
+++ b/src/plugins/pglist.c
@@ -472,7 +472,7 @@ void load_remaning_plugins(void)
notify_native_plugins_loaded();
- notify_plugins_loaded();
+ notify_all_plugins_loaded();
}
diff --git a/src/plugins/pglist.h b/src/plugins/pglist.h
index d6c539d..a380844 100644
--- a/src/plugins/pglist.h
+++ b/src/plugins/pglist.h
@@ -110,8 +110,8 @@ GPluginModule **get_all_plugins_for_action(PluginAction, size_t *);
#define notify_native_plugins_loaded() \
process_all_plugins_for(PGA_NATIVE_PLUGINS_LOADED, g_plugin_module_notify_plugins_loaded, NULL)
-#define notify_plugins_loaded() \
- process_all_plugins_for(PGA_PLUGINS_LOADED, g_plugin_module_notify_plugins_loaded, NULL)
+#define notify_all_plugins_loaded() \
+ process_all_plugins_for(PGA_ALL_PLUGINS_LOADED, g_plugin_module_notify_plugins_loaded, NULL)
#define build_type_instance(t) \
process_plugins_while_null(PGA_TYPE_BUILDING, g_plugin_module_build_type_instance, t)
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
index 0c25a7a..1118140 100644
--- a/src/plugins/plugin-def.h
+++ b/src/plugins/plugin-def.h
@@ -113,8 +113,11 @@ typedef enum _PluginAction
/* Chargement */
PGA_PLUGIN_INIT = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(0),
+ /* Chargement des paramètres */
+ PGA_PLUGIN_LOADED = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(1),
+
/* Déchargement */
- PGA_PLUGIN_EXIT = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(1),
+ PGA_PLUGIN_EXIT = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(2),
/**
* DPC_BASIC | DPS_CORE_MANAGEMENT
@@ -124,10 +127,10 @@ typedef enum _PluginAction
PGA_NATIVE_PLUGINS_LOADED = DPC_BASIC | DPS_CORE_MANAGEMENT | DEFINE_PLUGIN_ACTION(0),
/* Fin du chargement de tous greffons */
- PGA_PLUGINS_LOADED = DPC_BASIC | DPS_CORE_MANAGEMENT | DEFINE_PLUGIN_ACTION(1),
+ PGA_ALL_PLUGINS_LOADED = DPC_BASIC | DPS_CORE_MANAGEMENT | DEFINE_PLUGIN_ACTION(1),
/* Mise en place de type à partir de code externe */
- PGA_TYPE_BUILDING = DPC_BASIC | DPS_CORE_MANAGEMENT | DEFINE_PLUGIN_ACTION(2),
+ PGA_TYPE_BUILDING = DPC_BASIC | DPS_CORE_MANAGEMENT | DEFINE_PLUGIN_ACTION(2),
/**
* DPC_GUI | DPS_SETUP
diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h
index 98a07bb..88e0fbb 100644
--- a/src/plugins/plugin-int.h
+++ b/src/plugins/plugin-int.h
@@ -96,6 +96,8 @@ struct _GPluginModule
bitfield_t *dependencies; /* Cartographie des dépendances*/
+ GGenConfig *config; /* Configuration dédiée */
+
};
@@ -105,6 +107,7 @@ struct _GPluginModuleClass
GObjectClass parent; /* A laisser en premier */
pg_management_fc init; /* Procédure d'initialisation */
+ pg_management_fc manage; /* Etape dans la vie du greffon*/
pg_management_fc exit; /* Procédure d'extinction */
pg_plugins_loaded_fc plugins_loaded; /* Fin des chargements */
@@ -130,5 +133,9 @@ struct _GPluginModuleClass
};
+/* Met en place la configuration dédiée au greffon. */
+void g_plugin_module_create_config(GPluginModule *);
+
+
#endif /* _PLUGINS_PLUGIN_INT_H */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 23ef34c..e563817 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -112,6 +112,7 @@ static void g_plugin_module_class_init(GPluginModuleClass *class)
static void g_plugin_module_init(GPluginModule *plugin)
{
+ plugin->config = NULL;
}
@@ -167,6 +168,14 @@ static void g_plugin_module_dispose(GPluginModule *plugin)
if (class->exit != NULL)
class->exit(plugin);
+ if (plugin->config != NULL)
+ {
+ g_generic_config_write(plugin->config);
+
+ g_clear_object(&plugin->config);
+
+ }
+
if (plugin->module != NULL)
{
g_module_close(plugin->module);
@@ -306,6 +315,10 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
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;
@@ -325,7 +338,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
switch (action)
{
case PGA_NATIVE_PLUGINS_LOADED:
- case PGA_PLUGINS_LOADED:
+ case PGA_ALL_PLUGINS_LOADED:
valid = check_plugin_symbol(module, "chrysalide_plugin_on_plugins_loaded");
break;
@@ -600,6 +613,10 @@ static void g_plugin_module_init_gclass(GPluginModuleClass *class, GModule *modu
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;
@@ -617,7 +634,7 @@ static void g_plugin_module_init_gclass(GPluginModuleClass *class, GModule *modu
switch (action)
{
case PGA_NATIVE_PLUGINS_LOADED:
- case PGA_PLUGINS_LOADED:
+ case PGA_ALL_PLUGINS_LOADED:
load_plugin_symbol(module, "chrysalide_plugin_on_plugins_loaded",
&class->plugins_loaded);
break;
@@ -1039,6 +1056,7 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co
size_t i; /* Boucle de parcours */
GPluginModule *dependency; /* Module nécessaire */
GPluginModuleClass *class; /* Classe de l'instance active */
+ GGenConfig *config; /* Configuration à charger */
char *dir; /* Répertoire modifiable */
/* Si un essai précédent a déjà échoué ou réussi... */
@@ -1067,47 +1085,63 @@ bool g_plugin_module_load(GPluginModule *plugin, GPluginModule **list, size_t co
}
if (!result)
+ {
log_variadic_message(LMT_ERROR,
_("Some dependencies failed to load for plugin '%s'"), plugin->filename);
+ goto failure;
+ }
/* Chargement du greffon courant */
- if (result)
+ class = G_PLUGIN_MODULE_GET_CLASS(plugin);
+
+ if (class->init != NULL)
{
- class = G_PLUGIN_MODULE_GET_CLASS(plugin);
+ result = class->init(plugin);
- if (class->init != NULL)
+ if (!result)
{
- result = class->init(plugin);
+ log_variadic_message(LMT_ERROR,
+ _("Plugin '%s' failed to load itself..."), plugin->filename);
- if (!result)
- {
- log_variadic_message(LMT_ERROR,
- _("Plugin '%s' failed to load itself..."), plugin->filename);
-
- plugin->flags |= PSF_FAILURE;
-
- }
+ plugin->flags |= PSF_FAILURE;
+ goto failure;
}
- if (result)
- {
- dir = strdup(plugin->filename);
- dir = dirname(dir);
+ }
- 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);
+ g_plugin_module_create_config(plugin);
- free(dir);
+ result = g_plugin_module_manage(plugin, PGA_PLUGIN_LOADED);
- plugin->flags |= PSF_LOADED;
+ 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);
+
+ 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);
+
+ free(dir);
+
+ plugin->flags |= PSF_LOADED;
+
+ failure:
+
return result;
}
@@ -1168,6 +1202,57 @@ 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. *
+* *
+* Retour : Configuration dédiée à l'extension. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GGenConfig *g_plugin_module_get_config(const GPluginModule *plugin)
+{
+ GGenConfig *result; /* Configuration à faire suivre*/
+
+ result = plugin->config;
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : plugin = greffon à consulter. *
* msg = message à faire apparaître à l'écran. *
* *
@@ -1238,6 +1323,57 @@ 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. *
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index fc54aee..ff456b3 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -35,6 +35,7 @@
#include "../format/format.h"
#include "../format/known.h"
#include "../format/preload.h"
+#include "../glibext/configuration.h"
#include "../gtkext/gtkstatusstack.h"
#include "../gui/panel.h"
@@ -100,12 +101,18 @@ bool g_plugin_module_load(GPluginModule *, GPluginModule **, size_t);
/* Construit le nom d'un fichier de configuration du greffon. */
char *g_plugin_module_build_config_filename(const GPluginModule *, const char *, bool);
+/* Fournit la configuration mise en place pour le greffon. */
+GGenConfig *g_plugin_module_get_config(const GPluginModule *);
+
/* Présente dans le journal un message simple. */
void g_plugin_module_log_simple_message(const GPluginModule *, LogMessageType, const char *);
/* Présente dans le journal un message complexe. */
void g_plugin_module_log_variadic_message(const GPluginModule *, LogMessageType, const char *, ...);
+/* Encadre une étape de la vie d'un greffon. */
+bool g_plugin_module_manage(GPluginModule *, PluginAction);
+
/* Accompagne la fin du chargement des modules natifs. */
void g_plugin_module_notify_plugins_loaded(GPluginModule *, PluginAction, void *);