From 07cbfe9fcb174b8580f13d954d534c34e5de68a6 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 29 Aug 2024 08:21:22 +0200 Subject: [PATCH] introduction of the fsm journal --- include/fsm.h | 26 +++++-- journal.c | 101 ++++++++++++++++++++++++++ src/fsm/dispatch.c | 16 ++-- src/fsm/journal.c | 101 ++++++++++++++++++++++++++ src/fsm/measure/manage.c | 28 +++++-- src/fsm/result.c | 2 +- src/widget/rules/tree_tools/compare.c | 9 ++- 7 files changed, 257 insertions(+), 26 deletions(-) create mode 100644 journal.c create mode 100644 src/fsm/journal.c diff --git a/include/fsm.h b/include/fsm.h index 22416a0..890b3e4 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -81,16 +81,30 @@ void fsm_reset_all_situations_transparencies_at_value (int value); // provisoire // def: fsm/prefer; call: signal; -void fsm_debug_msg (int choice, int value, char *string, int sub_automaton); +void fsm_msg (int choice, int value, char *string, int sub_automaton); // def: fsm/dispatch; call: fsm/dispatch; // fsm/measure; // fsm/result; -// --------------------------------------------------------------- WIP -// def: measure/tool_list call measure/tool_list (about the following functions...) +// --------------------------------------------------------------- WIP ------ +// def: measure/tool_list call: measure/tool_list (about the following functions...) void fsm_tools_sort_list_insert (tool_list **tl, int value); int fsm_tools_sort_list_pop (tool_list **tl); -int fsm_tools_sort_list_length (tool_list *tl); +int fsm_tools_sort_list_length (tool_list *tl); void fsm_tools_sort_list_clear (tool_list **tl); -void fsm_tools_sort_list_view (tool_list *tl); -void fsm_tools_sort_list_test(); // def: measure/manage; call measure/manage; +void fsm_tools_sort_list_view (tool_list *tl); +void fsm_tools_sort_list_test(); // def: measure/manage; call: measure/manage; + +// def: fsm/measure/manage/; call: rule exec +void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id); + + +// --------------------------------------------------------------- WIP ------ +typedef struct journal {int value; struct journal *prev;} journal; // structure d'un élément + +int fsm_journal_push (journal **jj, int v_value); +int fsm_journal_pop (journal **jj); +void fsm_journal_clear (journal **jj); +int fsm_journal_length (journal *jj); +void fsm_journal_view (journal *jj); +void fsm_journal_seek (journal *jj, int v_value); diff --git a/journal.c b/journal.c new file mode 100644 index 0000000..295dffb --- /dev/null +++ b/journal.c @@ -0,0 +1,101 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* State machine / Measures * +* * +* 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" + +/******************************************************************************/ +/* A journal (a pile) stores chronologically the fsm events */ +/* during a session run (rules exec, mainly) */ +/******************************************************************************/ + + + +int fsm_journal_push (journal **jj, int vv) +{ + journal *element = malloc (sizeof(journal)); + if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué. + element->value = vv; + element->prev = *jj; + *jj = element; // Le pointeur pointe sur le dernier élément. + return vv; +} + +int fsm_journal_pop (journal **jj) +{ + int vv; + journal *tmp; + if (!*jj) return -1; // Retourne -1 si le journal est vide. + tmp = (*jj)->prev; + vv = (*jj)->value; + free (*jj); + *jj = tmp; // Le pointeur pointe sur le dernier élément. + return vv; // retourne la value retirée du journal. +} + + +void fsm_journal_clear (journal **jj) +{ + journal *tmp; + while (*jj) + { + tmp = (*jj)->prev; + free (*jj); + *jj = tmp; + } +} + +int fsm_journal_length (journal *jj) +{ + int n=0; + while (jj) + { + n++; + jj = jj->prev; + } + return n; +} + +void fsm_journal_view (journal *jj) +{ + printf ("view journal (n = %d)\n", fsm_journal_length (jj)); + while (jj) + { + printf ("> %d\n", jj->value); + jj = jj->prev; + } + puts ("------"); +} + +void fsm_journal_seek (journal *jj, int value) +{ + +} diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index 939013c..28eaa5f 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -97,7 +97,7 @@ int fsm_get_state_rules_data() {return choice_STATE_RULES_DATA;} void fsm_set_exec_edit (int choice) { if (choice_EXEC_EDIT != choice) { - fsm_debug_msg (choice, 0, "", 0); // EXEC_EDIT is sub_automaton 0 + fsm_msg (choice, 0, "", 0); // EXEC_EDIT is sub_automaton 0 choice_EXEC_EDIT = choice; } } @@ -105,7 +105,7 @@ void fsm_set_exec_edit (int choice) void fsm_set_state_rules_data (int choice) { if (choice_STATE_RULES_DATA != choice) { - fsm_debug_msg (choice, 0, "", 1); // STATE_RULES_DATA is sub_automaton 1 + fsm_msg (choice, 0, "", 1); // STATE_RULES_DATA is sub_automaton 1 choice_STATE_RULES_DATA = choice; } } @@ -118,29 +118,29 @@ void fsm_set_state_rules_data (int choice) static char *tab_0 [] = { "EXEC", "EDIT" }; static char *tab_1 [] = { "SYNTH", "STATE", "RULES", "DATA" }; -void fsm_debug_msg (int choice, int value, char *string, int sub_automaton) +void fsm_msg (int choice, int value, char *string, int sub_automaton) { switch (sub_automaton) { // sub_automaton 0 is EXEC_EDIT and // sub_automaton 1 is STATE_RULES_DATA // sub_automaton 2 is MEASURE - case (0) : printf ("switch %5s x %5s > %5s x %5s\n", + case (0) : printf ("fsm/dispatch.message | switch %5s x %5s > %5s x %5s\n", tab_0 [choice_EXEC_EDIT], tab_1 [choice_STATE_RULES_DATA], tab_0 [choice], tab_1 [choice_STATE_RULES_DATA]); break; - case (1) : printf ("switch %5s x %5s > %5s x %5s\n", + case (1) : printf ("fsm/dispatch.message | switch %5s x %5s > %5s x %5s\n", tab_0 [choice_EXEC_EDIT], tab_1 [choice_STATE_RULES_DATA], tab_0 [choice_EXEC_EDIT], tab_1 [choice]); break; - case (2) : printf ("fsm <> %s\n", string); + case (2) : printf ("fsm/dispatch.message | %s\n", string); break; - case (3) : printf ("fsm debug <> %2d\n", choice); + case (3) : printf ("fsm/dispatch.message | %2d\n", choice); break; - default : printf ("default in fsm/dispatch.fsm_debug_msg()\n"); + default : printf ("default in fsm/dispatch.fsm_msg()\n"); } } diff --git a/src/fsm/journal.c b/src/fsm/journal.c new file mode 100644 index 0000000..a0890fb --- /dev/null +++ b/src/fsm/journal.c @@ -0,0 +1,101 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* Finite State Machine / Journal * +* * +* 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" + +/******************************************************************************/ +/* A journal (a pile) stores chronologically the fsm events */ +/* during a session run (rules exec, mainly) */ +/******************************************************************************/ + + + +int fsm_journal_push (journal **jj, int vv) +{ + journal *element = malloc (sizeof(journal)); + if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué. + element->value = vv; + element->prev = *jj; + *jj = element; // Le pointeur pointe sur le dernier élément. + return vv; +} + +int fsm_journal_pop (journal **jj) +{ + int vv; + journal *tmp; + if (!*jj) return -1; // Retourne -1 si le journal est vide. + tmp = (*jj)->prev; + vv = (*jj)->value; + free (*jj); + *jj = tmp; // Le pointeur pointe sur le dernier élément. + return vv; // retourne la value retirée du journal. +} + + +void fsm_journal_clear (journal **jj) +{ + journal *tmp; + while (*jj) + { + tmp = (*jj)->prev; + free (*jj); + *jj = tmp; + } +} + +int fsm_journal_length (journal *jj) +{ + int n=0; + while (jj) + { + n++; + jj = jj->prev; + } + return n; +} + +void fsm_journal_view (journal *jj) +{ + printf ("view journal (n = %d)\n", fsm_journal_length (jj)); + while (jj) + { + printf ("> %d\n", jj->value); + jj = jj->prev; + } + puts ("------"); +} + +void fsm_journal_seek (journal *jj, int value) +{ + +} diff --git a/src/fsm/measure/manage.c b/src/fsm/measure/manage.c index def9352..f3c6119 100644 --- a/src/fsm/measure/manage.c +++ b/src/fsm/measure/manage.c @@ -33,7 +33,7 @@ #include "../../../include/fsm.h" /******************************************************************************/ -/* F R O M M E A S U R E M E N T S T O P R E S E N T A T I O N S */ +/* F R O M M E A S U R E M E N T S T O P R E S E N T A T I O N S */ /* */ /* How should the sequence */ /* from measurements to results presentation */ @@ -46,17 +46,18 @@ /* (3) display (plot) the results and adjust the appearance of the tables */ /* - - - */ /* */ -/* As a result, three lists at least */ +/* As a consequence, three lists at least */ /* must be created and maintained : */ /* */ /* (1) a mesurement tools list (see : fsm/measure/tool_list.c) */ /* which should mention if the tool is 'active' or 'inactive' */ -/* NB each rule ou rues-tree edition may change some items of this list */ +/* NB each rule ou rules-tree edition may change some items of that list */ /* */ /* (2) a data flows list (see : fsm/measure/flow_list.c) */ -/* on which some operations should be performed : */ +/* (it could either be named : fsm/measure/data_list.c) */ +/* on which some operations could be performed : */ /* ex : filter, concat, inverse, scale, correlate, etc. */ -/* NB each data flow should be maintained in a 'displayable form' */ +/* NB each data flow should be available in a 'displayable form' */ /* */ /* (3) a displayed data list (see : fsm/measure/disp_list.c) */ /* NB some data may be displayed simultaneously in different pages */ @@ -64,10 +65,23 @@ /* */ /* NB these three lists should be stored in the XML model */ /* and restored at the beginning of a new session */ +/* - - - */ +/* */ +/* (4) a journal (a pile) stores chronologically the fsm events */ +/* during a session run (rules exec, mainly) */ +/* - - - */ +/* */ +/* When a rule is adequately tagged, it triggers a measure : */ +/* fsm_rule_trig_measure (rule_id, object_id, measure_id) {...} */ +/* */ +/* The measurement is then taken and the result stored. */ +/* */ /******************************************************************************/ -void fsm_add_measure (char *measure_name) {fsm_debug_msg (2, 0, measure_name, 2);} +void fsm_add_measure (char *measure_name) {fsm_msg (2, 0, measure_name, 2);} -void fsm_measures_list_init() {if (1) fsm_tools_sort_list_test();} +void fsm_measures_list_init() {if (0) fsm_tools_sort_list_test();} + +void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id) {} diff --git a/src/fsm/result.c b/src/fsm/result.c index 8aa37f7..d17c461 100644 --- a/src/fsm/result.c +++ b/src/fsm/result.c @@ -74,6 +74,6 @@ void fsm_add_result (char *result_name) void fsm_results_list_init () { - fsm_debug_msg (0,0, "fsm_results_list_init()", 2); // sub_automaton 2 + fsm_msg (0,0, "src/fsm/result.c fsm_results_list_init()", 2); // sub_automaton 2 } diff --git a/src/widget/rules/tree_tools/compare.c b/src/widget/rules/tree_tools/compare.c index b5f11b7..4671479 100644 --- a/src/widget/rules/tree_tools/compare.c +++ b/src/widget/rules/tree_tools/compare.c @@ -171,7 +171,8 @@ void *widget_get_an_impression_of_what_a_rules_comparator_could_be(){ push(&stack_b, GTK_WIDGET (gtk_picture_new_for_filename ("/home/jean/Gem-Graph/gem-graph-client/data/image/folic acid.png"))); - printf(" --------- \n");//%d\n", *stack_b->arr[0]); + printf(" ---------\ + widget/rules/tree_tools/compare.c widget_get_an_impression_of_...()\n");//%d\n", *stack_b->arr[0]); // peek(&stack_b); // gtk_box_append (compare_left, peek(&stack_b)); @@ -209,12 +210,12 @@ static GtkWidget *do_rtfd (Stack stack) // TODO // it works !!! >>> GIcon *hello_dream = G_ICON (image_insuline); // GtkWidget *widget_insuline = GTK_WIDGET (image_insuline); - if (image_insuline_storage_type == GTK_IMAGE_ICON_NAME) - printf("insuline image now at : %p storage_type : %s\n", + if (0 && image_insuline_storage_type == GTK_IMAGE_ICON_NAME) + printf("src/widget/rules/tree_tools/compare.c do_rtfd() insuline image now at : %p storage_type : %s\n", &image_insuline, "GTK_IMAGE_ICON_NAME"); - push_images_onto_stack (stack); // totalement inutile ici + push_images_onto_stack (stack); // totalement inutile ici // peek (NULL); // idem + Erreur de segmentation // free_intlist (NULL); // idem // add_to_mylist (0); // idem