summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-28 21:44:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-28 21:44:27 (GMT)
commita6a88792bc866d8a1d7cabd50a93374da5dd1e7a (patch)
tree748d5a29339f0ccd09b1d5ef691a988c30eb5fca /src
parentcd59150b26173fc4caa44b604d9e0989de331b3d (diff)
Improved the API for configuration and its Python documentation.
Diffstat (limited to 'src')
-rw-r--r--src/glibext/Makefile.am1
-rw-r--r--src/glibext/configuration-int.h121
-rw-r--r--src/glibext/configuration.c209
-rw-r--r--src/glibext/configuration.h2
4 files changed, 232 insertions, 101 deletions
diff --git a/src/glibext/Makefile.am b/src/glibext/Makefile.am
index df05de3..2ab27f0 100644
--- a/src/glibext/Makefile.am
+++ b/src/glibext/Makefile.am
@@ -9,6 +9,7 @@ libglibext_la_SOURCES = \
bufferline.h bufferline.c \
bufferview.h bufferview.c \
chrysamarshal.h chrysamarshal.c \
+ configuration-int.h \
configuration.h configuration.c \
delayed-int.h \
delayed.h delayed.c \
diff --git a/src/glibext/configuration-int.h b/src/glibext/configuration-int.h
new file mode 100644
index 0000000..2ddeb4f
--- /dev/null
+++ b/src/glibext/configuration-int.h
@@ -0,0 +1,121 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * configuration-int.h - accès interne aux éléments de configuration du programme
+ *
+ * Copyright (C) 2020 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GLIBEXT_CONFIGURATION_INT_H
+#define _GLIBEXT_CONFIGURATION_INT_H
+
+
+#include "configuration.h"
+
+
+#include "../common/fnv1a.h"
+
+
+
+/* ---------------------------- 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 *);
+
+};
+
+
+/* Construit un paramètre de configuration. */
+void g_config_param_build(GCfgParam *, const char *, ConfigParamType, const param_value *);
+
+/* Construit un paramètre de configuration sans valeur. */
+void g_config_param_build_empty(GCfgParam *, const char *, ConfigParamType);
+
+
+
+/* ----------------------- 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 *);
+
+};
+
+
+/* Crée un gestionnaire configuration générique. */
+void g_generic_config_build(GGenConfig *, const char *);
+
+
+
+#endif /* _GLIBEXT_CONFIGURATION_INT_H */
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;
-
}
diff --git a/src/glibext/configuration.h b/src/glibext/configuration.h
index 49a289b..afefed1 100644
--- a/src/glibext/configuration.h
+++ b/src/glibext/configuration.h
@@ -52,7 +52,7 @@ typedef enum _ConfigParamType
typedef enum _ConfigParamState
{
CPS_UNDEFINED = (0 << 0), /* Etat non déterminé */
- CPS_CHANGED = (0 << 1), /* Modification utilisateur */
+ CPS_CHANGED = (1 << 0), /* Modification utilisateur */
CPS_DEFAULT = (1 << 1), /* Valeur par défaut */
CPS_EMPTY = (1 << 2) /* Valeur vide */