introduction of the fsm journal

This commit is contained in:
Jean Sirmai 2024-08-29 08:21:22 +02:00
parent 6877d4fea2
commit 07cbfe9fcb
Signed by: jean
GPG Key ID: FB3115C340E057E3
7 changed files with 257 additions and 26 deletions

View File

@ -81,16 +81,30 @@ void fsm_reset_all_situations_transparencies_at_value (int value); // provisoire
// def: fsm/prefer; call: signal; // 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; // def: fsm/dispatch; call: fsm/dispatch;
// fsm/measure; // fsm/measure;
// fsm/result; // fsm/result;
// --------------------------------------------------------------- WIP // --------------------------------------------------------------- WIP ------
// def: measure/tool_list call measure/tool_list (about the following functions...) // def: measure/tool_list call: measure/tool_list (about the following functions...)
void fsm_tools_sort_list_insert (tool_list **tl, int value); 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_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_clear (tool_list **tl);
void fsm_tools_sort_list_view (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_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);

101
journal.c Normal file
View File

@ -0,0 +1,101 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Gem-graph client *
* *
* State machine / Measures *
* *
* Copyright © 2024 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Adrien Bourmault <neox@a-lec.org> *
* Copyright © 2024 Jean Sirmai <jean@a-lec.org> *
* *
* 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 <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#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)
{
}

View File

@ -97,7 +97,7 @@ int fsm_get_state_rules_data() {return choice_STATE_RULES_DATA;}
void fsm_set_exec_edit (int choice) void fsm_set_exec_edit (int choice)
{ {
if (choice_EXEC_EDIT != 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; choice_EXEC_EDIT = choice;
} }
} }
@ -105,7 +105,7 @@ void fsm_set_exec_edit (int choice)
void fsm_set_state_rules_data (int choice) void fsm_set_state_rules_data (int choice)
{ {
if (choice_STATE_RULES_DATA != 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; 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_0 [] = { "EXEC", "EDIT" };
static char *tab_1 [] = { "SYNTH", "STATE", "RULES", "DATA" }; 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 switch (sub_automaton) { // sub_automaton 0 is EXEC_EDIT and
// sub_automaton 1 is STATE_RULES_DATA // sub_automaton 1 is STATE_RULES_DATA
// sub_automaton 2 is MEASURE // 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_EXEC_EDIT], tab_1 [choice_STATE_RULES_DATA],
tab_0 [choice], tab_1 [choice_STATE_RULES_DATA]); tab_0 [choice], tab_1 [choice_STATE_RULES_DATA]);
break; 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_STATE_RULES_DATA],
tab_0 [choice_EXEC_EDIT], tab_1 [choice]); tab_0 [choice_EXEC_EDIT], tab_1 [choice]);
break; break;
case (2) : printf ("fsm <> %s\n", string); case (2) : printf ("fsm/dispatch.message | %s\n", string);
break; break;
case (3) : printf ("fsm debug <> %2d\n", choice); case (3) : printf ("fsm/dispatch.message | %2d\n", choice);
break; break;
default : printf ("default in fsm/dispatch.fsm_debug_msg()\n"); default : printf ("default in fsm/dispatch.fsm_msg()\n");
} }
} }

101
src/fsm/journal.c Normal file
View File

@ -0,0 +1,101 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Gem-graph client *
* *
* Finite State Machine / Journal *
* *
* Copyright © 2024 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Adrien Bourmault <neox@a-lec.org> *
* Copyright © 2024 Jean Sirmai <jean@a-lec.org> *
* *
* 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 <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#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)
{
}

View File

@ -33,7 +33,7 @@
#include "../../../include/fsm.h" #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 */ /* How should the sequence */
/* from measurements to results presentation */ /* from measurements to results presentation */
@ -46,17 +46,18 @@
/* (3) display (plot) the results and adjust the appearance of the tables */ /* (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 : */ /* must be created and maintained : */
/* */ /* */
/* (1) a mesurement tools list (see : fsm/measure/tool_list.c) */ /* (1) a mesurement tools list (see : fsm/measure/tool_list.c) */
/* which should mention if the tool is 'active' or 'inactive' */ /* 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) */ /* (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. */ /* 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) */ /* (3) a displayed data list (see : fsm/measure/disp_list.c) */
/* NB some data may be displayed simultaneously in different pages */ /* 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 */ /* NB these three lists should be stored in the XML model */
/* and restored at the beginning of a new session */ /* 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) {}

View File

@ -74,6 +74,6 @@ void fsm_add_result (char *result_name)
void fsm_results_list_init () 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
} }

View File

@ -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 push(&stack_b, GTK_WIDGET (gtk_picture_new_for_filename
("/home/jean/Gem-Graph/gem-graph-client/data/image/folic acid.png"))); ("/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); // peek(&stack_b);
// gtk_box_append (compare_left, 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); // it works !!! >>> GIcon *hello_dream = G_ICON (image_insuline);
// //
GtkWidget *widget_insuline = GTK_WIDGET (image_insuline); GtkWidget *widget_insuline = GTK_WIDGET (image_insuline);
if (image_insuline_storage_type == GTK_IMAGE_ICON_NAME) if (0 && image_insuline_storage_type == GTK_IMAGE_ICON_NAME)
printf("insuline image now at : %p storage_type : %s\n", 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"); &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 // peek (NULL); // idem + Erreur de segmentation
// free_intlist (NULL); // idem // free_intlist (NULL); // idem
// add_to_mylist (0); // idem // add_to_mylist (0); // idem