From e5e674b1949995279756d4ee76414006d20af494 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 11 Sep 2024 10:23:07 +0200 Subject: [PATCH] WIP: fsm_journal_init (&glogos, "start fsm_init()") in fsm/dispatch --- include/fsm.h | 22 ++++++------- src/fsm/dispatch.c | 14 ++++++--- src/fsm/journal.c | 73 ++++++++++++++++++++++--------------------- src/main.c | 5 +-- src/widget/dispatch.c | 2 +- 5 files changed, 63 insertions(+), 53 deletions(-) diff --git a/include/fsm.h b/include/fsm.h index 27e7950..70b4783 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -47,21 +47,21 @@ typedef struct data_list {int value; struct data_list *suiv;} data_list ; typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ; // --------------------------------------------------------------- WIP ------ -void fsm_get_time(); +void fsm_get_time(char *message); // --------------------------------------------------------------- WIP ------ typedef struct unit {int event; struct unit *prev; struct unit *next;} unit; typedef struct {unit *first; unit *last;} journal; // structure d'accès au journal -void fsm_journal_init (journal *jj); // initialise -void fsm_journal_clear (journal *jj); // vide tout le journal -int fsm_journal_push_back (journal *jj, int event); // ajoute un évènement en fin de journal -int fsm_journal_push_front (journal *jj, int event); // ajoute un évènement en début de journal -int fsm_journal_pop_back (journal *jj); // retire un évènement en fin de journal -int fsm_journal_pop_front (journal *jj); // retire un évènement en début de journal -int fsm_journal_length (journal jj); // nombre d'évènements dans le journal -void fsm_journal_seek (journal jj, int event); // recherche un évènement dans le journal -void fsm_journal_view (journal jj); // affiche tout le journal -void fsm_journal_test(); +void fsm_journal_init (journal *jj, char *message); // initialise +void fsm_journal_clear (journal *jj, char *message); // vide tout le journal +int fsm_journal_push_back (journal *jj, int event, char *message); // ajoute un évènement en fin de journal +int fsm_journal_push_front (journal *jj, int event, char *message); // ajoute un évènement en début de journal +int fsm_journal_pop_back (journal *jj, char *message); // retire un évènement en fin de journal +int fsm_journal_pop_front (journal *jj, char *message); // retire un évènement en début de journal +int fsm_journal_length (journal jj, char *message); // nombre d'évènements dans le journal +void fsm_journal_seek (journal jj, int event, char *message); // recherche un évènement dans le journal +void fsm_journal_view (journal jj, char *message); // affiche tout le journal +void fsm_journal_test(char *message); // --------------------------------------------------------------- WIP ------ // ref: sudo cat /var/log/messages // --------------------------------------------------------------- WIP ------ diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index 6fe475d..ca45b47 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -54,13 +54,19 @@ /******************************************************************************/ /* F S M I N I T */ /******************************************************************************/ +// --------------------------------------------------------------- WIP ------ +journal glogos; // gg_logs, should be, but 'glogos' is funny 2024-09-11 void fsm_init() { - fsm_measures_list_init(); - fsm_results_list_init(); - fsm_displayable_list_init(); - fsm_preferences_init(); + fsm_journal_init (&glogos, "start fsm_init()"); + + fsm_measures_list_init(); fsm_journal_push_front (&glogos, 1, "measures"); + fsm_results_list_init(); fsm_journal_push_front (&glogos, 2, "results"); + fsm_displayable_list_init(); fsm_journal_push_front (&glogos, 3, "display"); + fsm_preferences_init(); fsm_journal_push_front (&glogos, 4, "prefer"); + + fsm_journal_length (glogos, "end fsm_init()"); } diff --git a/src/fsm/journal.c b/src/fsm/journal.c index 384ac72..cb29445 100644 --- a/src/fsm/journal.c +++ b/src/fsm/journal.c @@ -36,28 +36,29 @@ /******************************************************************************/ -void fsm_get_time() +void fsm_get_time (char *message) { struct timeval tv; gettimeofday(&tv, NULL); - printf(" Seconds since Jan. 1, 1970: %ld\n", tv.tv_sec); - + printf(" Seconds since Jan. 1, 1970: %ld %s\n", tv.tv_sec, message); +/* time_t current_time = time(NULL); // Check if the time retrieval was successful if (current_time == ((time_t)-1)) printf("Error getting current time.\n"); // Convert to local time format and print - printf(" Current timestamp: %ld\n", current_time); + printf(" Current timestamp: %ld %s\n", current_time, message); printf(" Current time: %s", ctime(¤t_time)); +*/ } -void fsm_journal_init (journal *jj) +void fsm_journal_init (journal *jj, char *message) { jj->first = NULL; jj->last = NULL; - fsm_get_time(); + fsm_get_time (message); } -void fsm_journal_clear (journal *jj) +void fsm_journal_clear (journal *jj, char *message) { unit *tmp; unit *a_unit = jj->first; @@ -71,7 +72,7 @@ void fsm_journal_clear (journal *jj) jj->last = NULL; } -int fsm_journal_push_back (journal *jj, int event) +int fsm_journal_push_back (journal *jj, int event, char *message) { unit *new_unit = malloc (sizeof(unit)); if (! new_unit) exit (EXIT_FAILURE); @@ -84,7 +85,7 @@ int fsm_journal_push_back (journal *jj, int event) return event; } -int fsm_journal_push_front (journal *jj, int event) +int fsm_journal_push_front (journal *jj, int event, char *message) { unit *new_unit = malloc(sizeof(unit)); if (! new_unit) exit (EXIT_FAILURE); @@ -97,7 +98,7 @@ int fsm_journal_push_front (journal *jj, int event) return event; } -int fsm_journal_pop_back (journal *jj) +int fsm_journal_pop_back (journal *jj, char *message) { int event; unit *tmp = jj->last; @@ -110,7 +111,7 @@ int fsm_journal_pop_back (journal *jj) return event; // retourne l'évènement retiré du journal. } -int fsm_journal_pop_front (journal *jj) +int fsm_journal_pop_front (journal *jj, char *message) { int event; unit *tmp = jj->first; @@ -123,7 +124,7 @@ int fsm_journal_pop_front (journal *jj) return event; // retourne l'évènement retiré du journal. } -int fsm_journal_length (journal jj) +int fsm_journal_length (journal jj, char *message) { unit *a_unit = jj.first; int nb = 0; @@ -132,10 +133,12 @@ int fsm_journal_length (journal jj) nb ++; a_unit = a_unit->next; } + printf (" fsm_journal_length (n = %d) %s\n", nb, ""); + fsm_get_time (message); return nb; } -void fsm_journal_seek (journal jj, int event) +void fsm_journal_seek (journal jj, int event, char *message) { unit *a_unit = jj.first; int nb = 0; @@ -146,12 +149,12 @@ void fsm_journal_seek (journal jj, int event) } if (nb > 0) printf ("> event %d found %d times in journal\n", event, nb); else printf ("> event %d not found in journal\n", event); - fsm_get_time(); + fsm_get_time (message); } -void fsm_journal_view (journal jj) +void fsm_journal_view (journal jj, char *message) { - printf ("view journal (n = %d)\n", fsm_journal_length (jj)); + printf ("view journal (n = %d)\n", fsm_journal_length (jj, message)); unit *a_unit = jj.first; while (a_unit) { @@ -161,35 +164,35 @@ void fsm_journal_view (journal jj) puts ("------"); } -void fsm_journal_test() +void fsm_journal_test(char *message) // call: widget/dispatch { journal exemple; - fsm_journal_init (&exemple); + fsm_journal_init (&exemple, message); - printf ("push front > %d\n", fsm_journal_push_front (&exemple, 10)); - printf ("push back > %d\n", fsm_journal_push_back (&exemple, 100)); - printf ("push back > %d\n", fsm_journal_push_back (&exemple, 1000)); - printf ("push front > %d\n", fsm_journal_push_front (&exemple, 1)); + printf ("push front > %d\n", fsm_journal_push_front (&exemple, 10, "")); + printf ("push back > %d\n", fsm_journal_push_back (&exemple, 100, "")); + printf ("push back > %d\n", fsm_journal_push_back (&exemple, 1000, "")); + printf ("push front > %d\n", fsm_journal_push_front (&exemple, 1, "")); - fsm_journal_view (exemple); - fsm_journal_seek (exemple, 2); + fsm_journal_view (exemple, ""); + fsm_journal_seek (exemple, 2, ""); - printf ("pop back > %d\n", fsm_journal_pop_back (&exemple)); - printf ("pop back > %d\n", fsm_journal_pop_back (&exemple)); - printf ("pop back > %d\n", fsm_journal_pop_back (&exemple)); - printf ("push back > %d\n", fsm_journal_push_back (&exemple, 2)); + printf ("pop back > %d\n", fsm_journal_pop_back (&exemple, "")); + printf ("pop back > %d\n", fsm_journal_pop_back (&exemple, "")); + printf ("pop back > %d\n", fsm_journal_pop_back (&exemple, "")); + printf ("push back > %d\n", fsm_journal_push_back (&exemple, 2, "")); - fsm_journal_view (exemple); + fsm_journal_view (exemple, ""); - printf ("push back > %d\n", fsm_journal_push_back (&exemple, 3)); - printf ("push front > %d\n", fsm_journal_push_front (&exemple, 0)); + printf ("push back > %d\n", fsm_journal_push_back (&exemple, 3, "")); + printf ("push front > %d\n", fsm_journal_push_front (&exemple, 0, "")); - fsm_journal_view (exemple); - fsm_journal_seek (exemple, 2); + fsm_journal_view (exemple, ""); + fsm_journal_seek (exemple, 2, ""); - printf ("clear list\n"); fsm_journal_clear (&exemple); + printf ("clear list\n"); fsm_journal_clear (&exemple, ""); - fsm_journal_view (exemple); + fsm_journal_view (exemple, message); } diff --git a/src/main.c b/src/main.c index b2e0e4e..0582b86 100644 --- a/src/main.c +++ b/src/main.c @@ -132,9 +132,10 @@ int main (int argc, char **argv) { - fsm_init (); // fsm = finite state machine (see : src/fsm/dispatch.c) + fsm_init (); // def: src/fsm/dispatch.c fsm = finite state machine - GtkApplication *app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS); + GtkApplication *app = gtk_application_new ("org.gem-graph", + G_APPLICATION_DEFAULT_FLAGS); g_signal_connect (app, "startup", G_CALLBACK (on_windows_startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL); // ! WARNING ! 'on_windows_activation()' diff --git a/src/widget/dispatch.c b/src/widget/dispatch.c index b33f4f1..c37f571 100644 --- a/src/widget/dispatch.c +++ b/src/widget/dispatch.c @@ -92,7 +92,7 @@ void on_windows_activation (GtkApplication *app) widget_design_text_window (main_window, text_window); // ------------------------------------------------------------------------ util_trigger_test(); // then go to util/tests.c and change if (0) to if (1)... - fsm_journal_test(); + if (0) fsm_journal_test("<> fsm_journal_test() in widget / dispatch");