summaryrefslogtreecommitdiff
path: root/src/glibext/configuration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/configuration.c')
-rw-r--r--src/glibext/configuration.c209
1 files changed, 109 insertions, 100 deletions
diff --git a/src/glibext/configuration.c b/src/glibext/configuration.c
index 7fd9a98..1fa2968 100644
--- a/src/glibext/configuration.c
+++ b/src/glibext/configuration.c
@@ -33,9 +33,9 @@
#include <unistd.h>
+#include "configuration-int.h"
#include "../common/cpp.h"
#include "../common/extstr.h"
-#include "../common/fnv1a.h"
#include "../common/io.h"
#include "../common/xdg.h"
#include "../common/xml.h"
@@ -45,48 +45,6 @@
/* ---------------------------- ELEMENT DE CONFIGURATION ---------------------------- */
-/* Valeurs supportées par les paramètres */
-typedef union _param_value
-{
- bool boolean; /* Valeur booléenne */
- int integer; /* Valeur entière */
- unsigned long ulong; /* Valeur entière positive */
- char *string; /* Chaîne de caractères */
- GdkRGBA color; /* Couleur avec transparence */
-
-} param_value;
-
-/* Configuration générique quelconque (instance) */
-struct _GCfgParam
-{
- GObject parent; /* A laisser en premier */
-
- char *path; /* Chemin d'accès XML */
- fnv64_t hash; /* Empreinte pour accès rapide */
-
- ConfigParamType type; /* Type de valeur */
-
- ConfigParamState cached_state; /* Etat du paramétrage */
-
- param_value def; /* Valeur par défaut */
- bool def_empty; /* Non défini par défaut ? */
- param_value cur; /* Valeur courante */
- bool cur_empty; /* Actuellement non défini ? */
-
-};
-
-/* Configuration générique quelconque (classe) */
-struct _GCfgParamClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- /* Signaux */
-
- void (* modified) (GCfgParam *);
-
-};
-
-
/* Initialise la classe des blocs de données binaires. */
static void g_config_param_class_init(GCfgParamClass *);
@@ -148,31 +106,6 @@ static void g_config_group_load(GCfgGroup *, GGenConfig *, xmlXPathContextPtr);
/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */
-/* Configuration générique quelconque (instance) */
-struct _GGenConfig
-{
- GObject parent; /* A laisser en premier */
-
- char *filename; /* CHemin d'accès complet */
-
- GList *groups; /* Groupes d'éléments non fixés*/
- GList *params; /* Eléments de configuration */
- GRWLock params_access; /* Verrou de protection */
-
-};
-
-/* Configuration générique quelconque (classe) */
-struct _GGenConfigClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- /* Signaux */
-
- void (* modified) (GGenConfig *, GCfgParam *);
-
-};
-
-
/* Initialise la classe des blocs de données binaires. */
static void g_generic_config_class_init(GGenConfigClass *);
@@ -321,51 +254,50 @@ GCfgParam *g_config_param_new(const char *path, ConfigParamType type, ...)
{
GCfgParam *result; /* Structure à retourner */
va_list ap; /* Liste d'arguments */
+ param_value value; /* Valeur par défaut */
- result = g_object_new(G_TYPE_CFG_PARAM, NULL);
-
- result->path = strdup(path);
- result->hash = fnv_64a_hash(path);
-
- result->type = type;
+ result = NULL;
va_start(ap, type);
- switch (result->type)
+ switch (type)
{
case CPT_BOOLEAN:
- result->def.boolean = va_arg(ap, /*bool*/int);
+ value.boolean = va_arg(ap, /*bool*/int);
break;
case CPT_INTEGER:
- result->def.integer = va_arg(ap, int);
+ value.integer = va_arg(ap, int);
break;
case CPT_ULONG:
- result->def.ulong = va_arg(ap, unsigned long);
+ value.ulong = va_arg(ap, unsigned long);
break;
case CPT_STRING:
- result->def.string = va_arg(ap, char *);
- if (result->def.string != NULL)
- result->def.string = strdup(result->def.string);
+ value.string = va_arg(ap, char *);
+ if (value.string != NULL)
+ value.string = strdup(value.string);
break;
case CPT_COLOR:
- result->def.color = *va_arg(ap, GdkRGBA *);
+ value.color = *va_arg(ap, GdkRGBA *);
break;
default:
- g_object_unref(G_OBJECT(result));
- result = NULL;
assert(false);
+ goto quick_exit;
break;
}
va_end(ap);
- g_config_param_reset(result);
+ result = g_object_new(G_TYPE_CFG_PARAM, NULL);
+
+ g_config_param_build(result, path, type, &value);
+
+ quick_exit:
return result;
@@ -374,8 +306,37 @@ GCfgParam *g_config_param_new(const char *path, ConfigParamType type, ...)
/******************************************************************************
* *
-* Paramètres : path = chemin d'accès à un paramètre en guise de clef. *
-* type = type de paramètre à installer. *
+* Paramètres : param = paramètre de configuration à construire. *
+* path = chemin d'accès à un paramètre en guise de clef. *
+* type = type de paramètre à installer. *
+* value = valeur par défaut à appliquer. *
+* *
+* Description : Construit un paramètre de configuration. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_config_param_build(GCfgParam *param, const char *path, ConfigParamType type, const param_value *value)
+{
+ param->path = strdup(path);
+ param->hash = fnv_64a_hash(path);
+
+ param->type = type;
+
+ param->def = *value;
+
+ g_config_param_reset(param);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : path = chemin d'accès à un paramètre en guise de clef. *
+* type = type de paramètre à installer. *
* *
* Description : Crée un paramètre de configuration sans valeur. *
* *
@@ -391,17 +352,38 @@ GCfgParam *g_config_param_new_empty(const char *path, ConfigParamType type)
result = g_object_new(G_TYPE_CFG_PARAM, NULL);
- result->path = strdup(path);
- result->hash = fnv_64a_hash(path);
+ g_config_param_build_empty(result, path, type);
- result->type = type;
+ return result;
- g_config_param_make_empty(result);
+}
- result->def = result->cur;
- result->def_empty = true;
- return result;
+/******************************************************************************
+* *
+* Paramètres : param = paramètre de configuration à construire. *
+* path = chemin d'accès à un paramètre en guise de clef. *
+* type = type de paramètre à installer. *
+* *
+* Description : Construit un paramètre de configuration sans valeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_config_param_build_empty(GCfgParam *param, const char *path, ConfigParamType type)
+{
+ param->path = strdup(path);
+ param->hash = fnv_64a_hash(path);
+
+ param->type = type;
+
+ g_config_param_make_empty(param);
+
+ param->def = param->cur;
+ param->def_empty = true;
}
@@ -645,7 +627,11 @@ const char *g_config_param_get_path(const GCfgParam *param)
ConfigParamType g_config_param_get_ptype(const GCfgParam *param)
{
- return param->type;
+ ConfigParamType result; /* Type de paramètre à renvoyer*/
+
+ result = param->type;
+
+ return result;
}
@@ -892,6 +878,7 @@ void g_config_param_set_value(GCfgParam *param, ...)
case CPT_STRING:
old_string = param->cur.string;
+
param->cur.string = va_arg(ap, char *);
if (param->cur.string != NULL)
param->cur.string = strdup(param->cur.string);
@@ -1261,7 +1248,8 @@ static void g_generic_config_dispose(GGenConfig *config)
static void g_generic_config_finalize(GGenConfig *config)
{
- free(config->filename);
+ if (config->filename != NULL)
+ free(config->filename);
g_rw_lock_clear(&config->params_access);
@@ -1308,21 +1296,42 @@ GGenConfig *g_generic_config_new(void)
GGenConfig *g_generic_config_new_from_file(const char *name)
{
GGenConfig *result; /* Structure à retourner */
- char *suffix; /* Fin du nom de fichier */
result = g_object_new(G_TYPE_GEN_CONFIG, NULL);
+ g_generic_config_build(result, name);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = ensemble de paramètres de configuration à manipuler.*
+* name = désignation de la configuration. *
+* *
+* Description : Crée un gestionnaire configuration générique. *
+* *
+* Retour : Elément mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+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");
- result->filename = get_xdg_config_dir(suffix);
+ config->filename = get_xdg_config_dir(suffix);
free(suffix);
- return result;
-
}