From 9e0ef7d28fef771eee0b5e649ef687c1652c0ba6 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 27 Aug 2024 15:07:16 +0200 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20de=20measure/list.c=20et=20de?= =?UTF-8?q?=20measure/manage.c=20=20(+=20struct=20m=5Fpile=20in=20fsm.h)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fsm.h | 17 ++- include/util.h | 8 +- src/fsm/measure/list.c | 154 ++++++++++++++++++++++++ src/fsm/{measure.c => measure/manage.c} | 17 +-- src/util/pile.c | 1 + src/util/tests.c | 7 +- 6 files changed, 176 insertions(+), 28 deletions(-) create mode 100644 src/fsm/measure/list.c rename src/fsm/{measure.c => measure/manage.c} (92%) diff --git a/include/fsm.h b/include/fsm.h index 183e7e7..493aa37 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -44,14 +44,14 @@ enum fsm_select_STORE_RESTORE_RESET { STORE, RESTORE, RESET }; enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME }; -typedef struct pile // 1er essai : measures (2024-08-26) +typedef struct m_pile // 1er essai : measures (2024-08-26) { int value; // to replace int measure_type; - int *at_rule; // réserve un emplacement pour stocker une adresse mémoire. + int *p_rule; // réserve un emplacement pour stocker une adresse mémoire. // at_rule = &rule; < écrira l'adresse de rule dans cet emplacement. - struct pile *prev; -} pile; + struct m_pile *prev; +} m_pile; #define n_rules 128 // arbitrary #define n_objects 32 // arbitrary too, @@ -59,7 +59,7 @@ typedef struct pile // 1er essai : measures (2024-08-26) void fsm_init(); // def: fsm/dispatch; call: main; void fsm_preferences_init(); // def: fsm/prefer; call: fsm/dispatch; -void fsm_measures_list_init(); // def: fsm/measure; call: fsm/dispatch; +void fsm_measures_list_init(); // def: fsm/measure/list.c; call: fsm/dispatch; void fsm_results_list_init(); // def: fsm/results; call: fsm/dispatch; void fsm_displayable_list_init(); // def: fsm/prefer; call: fsm/dispatch; @@ -77,7 +77,8 @@ bool fsm_get_preferences_state(); // def: fsm/dispatch; call: - - - void fsm_set_preferences_state (bool value); // def: fsm/dispatch; call: signal; // fsm/prefer; -void fsm_add_measure (char *measure_name); // def: fsm/measure; call: widget/measure/dispatch; +void fsm_add_measure (char *measure_name); // def: fsm/measure/manage.c; + // call: widget/measure/dispatch; void fsm_add_result (char *result_name); // def: fsm/result; call: - - - void fsm_add_displayable (char *displayable_name);// def: fsm/prefer; call: fsm/prefer; @@ -90,3 +91,7 @@ void fsm_debug_msg (int choice, int value, char *string, int sub_automaton); // fsm/measure; // fsm/result; +int fsm_pile_push (m_pile **p, int val); // def: measure/list call measure/list +int fsm_pile_pop (m_pile **p); // def: measure/list call measure/list +void fsm_pile_view (m_pile *p); // def: measure/list call measure/list +int fsm_pile_length (m_pile *p); // def: measure/list call measure/list diff --git a/include/util.h b/include/util.h index b66e04f..735095e 100644 --- a/include/util.h +++ b/include/util.h @@ -51,12 +51,7 @@ char *util_read_file (char *filename); // Est bien sûr autorisé tout ce qui concerne les logiciels gratuits, freewares et évaluation. //------------------------------------------------------------------------------ -// typedef struct pile {int value; struct pile *prev;} pile; // structure d'un élément -// LE TYPE 'pile' EST REDÉFINI DANS fsm.h ET UTILISÉ DANS fsm/measure.c - -// 2024-08-26 J'avais - trop vite ! - imaginé des piles ou listes génériques, mais -// en fait, chaque structure sera très typée et très spécifique -// (des règles, groupes de règles, objets, dates, durées, etc.) +typedef struct pile {int value; struct pile *prev;} pile; // structure d'un élément void util_pile_clear (pile **); // vide toute la pile void util_pile_view (pile *); // affiche la pile en commençant par le sommet @@ -88,6 +83,7 @@ int util_sorted_list_length (slist *sl); // renvoie le nombre d'él //------------------------------------------------------------------------------ +void util_trigger_test(); // def: util/tests.c calls: ... void util_pile_test(); // called in fsm/measure.c void util_double_list_test(); // " " void util_sorted_list_test(); // " " diff --git a/src/fsm/measure/list.c b/src/fsm/measure/list.c new file mode 100644 index 0000000..fe40123 --- /dev/null +++ b/src/fsm/measure/list.c @@ -0,0 +1,154 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* State machine * +* * +* Copyright © 2024 Libre en Communs * +* Copyright © 2024 Adrien Bourmault * +* Copyright © 2024 Jean Sirmai * +* * +* This file is part of Gem-graph. * +* * +* This program is free software: you can redistribute it and/or modify it * +* under the terms of the GNU Affero General Public License * +* as published by the Free Software Foundation, * +* either version 3 of the License, * +* or (at your option) any later version. * +* * +* This program 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 Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with this program. If not, see . * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include +#include +#include +#include "../../../include/fsm.h" +#include "../../../include/util.h" + +/******************************************************************************/ +/* */ +/* FFFFFFFFFFF SSSSS MM MM */ +/* FF SSS SS MMMM MMMM */ +/* FF SS MM MM MM MM */ +/* FFFFFFF SS MM MM MM MM */ +/* FF SS MM MM MM */ +/* FF SSS MM MM */ +/* FF SS SSS MM MM */ +/* FF SSSSSS MM MM */ +/* */ +/******************************************************************************/ + + +/******************************************************************************/ +/* Each state of the finite state machine (fsm) must be */ +/* - saved at the end of a work session and */ +/* - reread (available) at the start of a new session. */ +/* */ +/* No state of the fsm should be defined in another module. */ +/* No fsm transition needs to be executed in another module. */ +/******************************************************************************/ + + +/******************************************************************************/ +/* M E A S U R E M E N T S */ +/******************************************************************************/ +// An editable list of measurements is defined and maintained here. +// Each possible measurement can be activated or silenced. + +// The measures relate to +// - the number of occurrences of a rule or group of rules, +// - the number of objects or situations before/after the rule was applied, +// - the time (date) of the event, +// - the time elapsed between two events, +// - the occurrence of events C between events A and B +// - (non limitative, maybe) < pattern recognition tools ? + +// When a list of measurements is established, it is possible to evaluate +// if the results of a measurement are correlated with some other results. + +//------------------------------------------------------------------------------ + +// structure de données : chaque "item" comportera : + +// - identifiant (clé) (+/- pointeur vers : date de création, auteur,...) + +// - type de mesure +// les 6 items suivants peuvent documenter l'ensemble de toutes les valeurs +// à recueillir pour documenter tous les types de mesure possibles; +// tous ces items ne doivent pas être simultanément complétés +// mais, si un tableau etait utilisé, il y aurait peu de place perdue; + +// - pointeur vers le premier groupe de règles (une au moins) +// - pointeur vers un second groupe de règles (une au moins) +// - pointeur vers des objets ou situations (un au moins) +// - pointeur vers un ensemble d'évènements intercurrents +// - date de l'évènement +// - durée entre deux évènements + +// - mesure active ? + / - +// - pointeur vers une liste de mesures similaires +// - pointeur vers des données, des représentations de données ? + + +void fsm_measures_list_init () +{ + m_pile *exemple = NULL; // doit être initialisée à NULL + printf ("fsm push > %d\n", fsm_pile_push (&exemple, 4)); + fsm_pile_view (exemple); + printf ("fsm pop > %d\n", fsm_pile_pop (&exemple)); + fsm_pile_view (exemple); + +} + +int fsm_pile_push (m_pile **p, int val) +{ + m_pile *element = malloc (sizeof(m_pile)); + if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué. + element->value = val; + element->prev = *p; + *p = element; // Le pointeur pointe sur le dernier élément. + return val; +} + +int fsm_pile_pop (m_pile **p) +{ + int Val; + m_pile *tmp; + if (!*p) return -1; // Retourne -1 si la pile est vide. + tmp = (*p)->prev; + Val = (*p)->value; + free (*p); + *p = tmp; // Le pointeur pointe sur le dernier élément. + return Val; // Retourne la value soutirée de la pile. +} + +int fsm_pile_length (m_pile *p) +{ + int n=0; + while (p) + { + n++; + p = p->prev; + } + return n; +} + +void fsm_pile_view (m_pile *p) +{ + printf ("fsm view pile (n = %d)\n", fsm_pile_length (p)); + while (p) + { + printf ("fsm > %d\n", p->value); + p = p->prev; + } + puts ("------"); +} + diff --git a/src/fsm/measure.c b/src/fsm/measure/manage.c similarity index 92% rename from src/fsm/measure.c rename to src/fsm/measure/manage.c index c63dc72..ee70788 100644 --- a/src/fsm/measure.c +++ b/src/fsm/measure/manage.c @@ -30,8 +30,8 @@ #include #include #include -#include "../../include/fsm.h" -#include "../../include/util.h" +#include "../../../include/fsm.h" +#include "../../../include/util.h" /******************************************************************************/ /* */ @@ -100,17 +100,4 @@ void fsm_add_measure (char *measure_name) {fsm_debug_msg (2, 0, measure_name, 2);} -void fsm_measures_list_init () -{ - fsm_debug_msg (0,0, "fsm_measures_list_init()", 2); // sub_automaton 2 - if (0) util_pile_test(); - if (0) util_double_list_test(); - if (0) util_sorted_list_test(); - pile *exemple = NULL; // doit être initialisée à NULL - printf ("push > %d\n", util_pile_push (&exemple, 4)); - util_pile_view (exemple); - printf ("pop > %d\n", util_pile_pop (&exemple)); - util_pile_view (exemple); - -} diff --git a/src/util/pile.c b/src/util/pile.c index fb11bd4..bf696eb 100644 --- a/src/util/pile.c +++ b/src/util/pile.c @@ -87,3 +87,4 @@ void util_pile_view (pile *p) puts ("------"); } + diff --git a/src/util/tests.c b/src/util/tests.c index 6272d5b..e660b0b 100644 --- a/src/util/tests.c +++ b/src/util/tests.c @@ -30,7 +30,12 @@ #include "../../include/util.h" - +void util_trigger_test () +{ + if (0) util_pile_test(); + if (0) util_double_list_test(); + if (0) util_sorted_list_test(); +} void util_pile_test() {