gem-graph-client/include/fsm.h

248 lines
12 KiB
C
Raw Normal View History

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Gem-graph client *
* Finite state machine header *
2024-07-08 22:05:15 +02:00
* *
* Copyright © 2021 Libre en Communs <contact@a-lec.org> *
* Copyright © 2024 Jean Sirmai <jean@a-lec.org> *
2024-07-08 22:05:15 +02:00
* *
* This file is part of Gem-graph. *
2024-07-08 22:05:15 +02:00
* *
* This program is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Affero General Public License *
* as publishedby the Free Software Foundation, *
* either version 3 of the License, or (at your option) any later version. *
2024-07-08 22:05:15 +02:00
* *
* 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. *
2024-07-08 22:05:15 +02:00
* *
* 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/>. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2024-07-08 22:05:15 +02:00
#pragma once
#include <stdbool.h>
#include <stddef.h>
2024-08-20 09:50:20 +02:00
#include <gtk-4.0/gtk/gtk.h>
2024-07-08 22:05:15 +02:00
/******************************************************************************/
/* S T A T E M A C H I N E */
/******************************************************************************/
// called by widgets through signal functions
2024-07-08 22:05:15 +02:00
enum fsm_select_EXEC_EDIT { EXEC, EDIT };
enum fsm_select_STATE_RULES_DATA { SYNTH, STATE, RULES, DATA };
enum fsm_select_STORE_RESTORE_RESET { STORE, RESTORE, RESET };
2024-07-08 22:05:15 +02:00
enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME };
#define n_rules 128 // arbitrary
#define n_objects 32 // arbitrary too,
#define n_situations 128 // and so on...
2024-07-24 23:07:14 +02:00
typedef struct tool_list {int value; struct tool_list *suiv;} tool_list ;
typedef struct data_list {int value; struct data_list *suiv;} data_list ;
typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ;
/******************************************************************************/
/* J O U R N A L */
/******************************************************************************/
2024-09-19 07:14:05 +02:00
enum severity {CRITICAL, ERROR, WARNING, INFO, MESSAGE, DEBUG, SPEW};
// ****************** - SEVERITY - ****************************************/
//
2024-09-16 16:23:45 +02:00
// CRITICAL ERROR WARNING INFO MESSAGE DEBUG SPEW (see: fsm.h)
// 0 1 2 3 4 5 6 (fsm_journal_event)
#define CRITICAL 0 // THE HIGHER THE PRIORITY, THE LOWER THE INDEX
#define ERROR 1
#define WARNING 2
#define MESSAGE 3
#define INFO 4
#define DEBUG 5
#define SPEW 6 // THE_LOWER THE PRIORITY, THE HIGHER THE INDEX
/* * * * * * * - F I L T E R S - * * * * * * *
* This list is duplicated in both /fsm.h and /fsm/dispatch *
* *
*
* MAIN, FSM_INIT (in fsm/dispatch) & WINDOW ACTIVATION (in widget/dispatch) 0
* MAIN_WINDOW DIALOG_WINDOW MODAL_WINDOW 10 11 12
*
* TOPBAR TOPBAR_LEFT TOPBAR_RIGHT TOPBAR_CENTER 20 21 22 23
*
* SYNTH_PAGE STATE_PAGE RULES_PAGE RESULTS_PAGE 30 31 32 33
* SYNTH_GLAREA SYNTH_ALL_RESULTS 34 35
* SYNTH_TIME_DEP_RESULTS SYNTH_TIME_INDEP_RESULTS 36 37
*
* STATE_PAGE STATE_TOP STATE_BOTTOM 40 41 42
* STATE_GLAREA STATE_CAMERA 43 44
*
* RULES_PAGE RULE_GLAREA RULE_CAMERA 50 51 52
* RULES_TREE RULES_COMPARE RULES_USE 53 54 55
*
* MEASURES_PAGE _TOOLS _ACTIVITY _DISPLAY 60 61 62 63
* TIME_DEP_RESULTS TIME_INDEP_RESULTS 64 65
*
* WIDGET BUTTON SCROLL GLAREA TEXT LABEL 70 71 72 73 74 75
*
* AUTO_NOTIFICATION 80
*
* FSM 90
* *
* This list is duplicated in both /fsm.h and /fsm/dispatch *
* * * * * * * - F I L T E R S - * * * * * * */
2024-09-19 07:14:05 +02:00
/* * * * * - M E T A R U L E S J O U R N A L - * * * *
*
* Un seul fsm_journal_event() par fonction
* sauf si elle génère plusieurs autres fonctions d'intérêt (à surveiller)
*
* S'il y a deux fsm_journal_event() (begin / end) dans une fonction
* ils doivent avoir la même étiquette : MESSAGE, SOURCE, TARGET
*
* * * * * - M E T A R U L E S J O U R N A L - * * * */
enum source {
SOURCE, MAIN, APP, WIDGETS, MAIN_4, MAIN_5, MAIN_6, MAIN_7, MAIN_8, MAIN_9,
MAIN_WINDOW, DIALOG_WINDOW, MODAL_WINDOW, TEXT_WINDOW, AUTO_NOTIFICATION,
W_15, W_16, W_17, W_18, W_19,
TOPBAR, TOPBAR_LEFT, TOPBAR_RIGHT, TOPBAR_CENTER,
TB_24, TB_25, TB_26, TB_27, TB_28, TB_29,
SYNTH_PAGE, SY_31, SY_32, SY_33, SY_34, SY_35, SY_36, SY_37, SY_38, SY_39,
STATE_PAGE, ST_41, ST_42, ST_43, ST_44, ST_45, ST_46, ST_47, ST_48, ST_49,
RULES_PAGE, RL_51, RL_52, RL_53, RL_54, RL_55, RL_56, RL_57, RL_58, RL_59,
MEASURES_PAGE, MP_61, MP_62, MP_63, MP_64, MP_65, MP_66, MP_67, MP_68, MP_69,
RESULTS_PAGE, RS_71, RS_72, RS_73, RS_74, RS_75, RS_76, RS_77, RS_78, RS_79,
};
enum target {JOURNAL, FSM}; // INFO, SOURCE, TARGET
#define SOURCE 0
#define TARGET 0
#define JOURNAL 0
#define MAIN 0
2024-09-19 07:14:05 +02:00
#define APP 0
#define WIDGETS 0
#define FSM 0
#define AUTO_NOTIFICATION 0
#define MAIN_WINDOW 10
#define DIALOG_WINDOW 11
#define MODAL_WINDOW 12
2024-09-19 07:14:05 +02:00
#define TEXT_WINDOW 13
#define TOPBAR 20
#define TOPBAR_LEFT 21
#define TOPBAR_RIGHT 22
2024-09-19 07:14:05 +02:00
#define TOPBAR_CENTER 23
2024-09-19 07:14:05 +02:00
#define SYNTH_PAGE 50
#define STATE_PAGE 60
#define RULES_PAGE 70
#define MEASURES_PAGE 80
#define RESULTS_PAGE 90
2024-09-19 07:14:05 +02:00
#define BUTTON 101
#define SCROLL 102
#define GLAREA 103
#define TEXT 104
#define LABEL 105
#define JOURNAL_DATE_MAX_LENGTH 255
2024-09-16 16:23:45 +02:00
typedef struct unit {long yy_dd_mm;
long usec;
char *message;
struct unit *prev;
struct unit *next;} unit; // journal unit structure
typedef struct {unit *first; unit *last;} journal; // journal unit access structure
void fsm_journal_init (journal *jj); // init from main
void fsm_journal_push (char *message); // def: fsm/dispatch
// call: any call that does not have
// the log address
void fsm_journal_clear (journal *jj, char *message); // empty the journal
void fsm_journal_push_front (journal *jj, char *message); // add an évènement at the journal front
long fsm_journal_pop_back (journal *jj, char *message); // remove an évènement at the journal end
int fsm_journal_length (journal jj); // journal length
void fsm_journal_seek (journal jj, long usec, char *message); // seek for an évènement in the journal
void fsm_journal_publish (journal jj); // display the journal
void fsm_journal_test (char *message);
2024-09-16 16:23:45 +02:00
// --------------------------------------------------------------- WIP ------
// ref: sudo cat /var/log/messages
// journal fsm_get_journal(); // def: fsm/dispatch call: fsm/prefer/fsm_store_restore_reset()
2024-09-16 08:06:08 +02:00
void fsm_journal_publication_request (); // def: fsm/dispatch call: main;
2024-09-19 07:14:05 +02:00
void fsm_journal_event (char *message, int priority, int widget, int action);
// def: fsm/dispatch call: widget/dispatch;
// --------------------------------------------------------------- WIP ------
2024-09-16 16:23:45 +02:00
void fsm_init (char *message); // def: fsm/dispatch; call: main;
2024-09-02 18:50:47 +02:00
void fsm_engine_init(); // def: fsm/engine/engine; call main
2024-09-16 16:23:45 +02:00
void fsm_preferences_list_init(); // def: fsm/prefer; call: fsm/dispatch;
void fsm_measures_list_init(); // def: fsm/measure/manage.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;
2024-07-24 23:07:14 +02:00
int fsm_get_exec_edit(); // def: fsm/dispatch; call: signal;
// widget/state/dispatch;
// widget/rules/selected/dispatch;
int fsm_get_state_rules_data(); // def: fsm/dispatch; call: signal;
2024-07-24 23:07:14 +02:00
void fsm_set_exec_edit (int value);// def: fsm/dispatch; call: signal;
void fsm_set_state_rules_data (int value); // def: fsm/dispatch; call: signal;
2024-07-19 00:17:19 +02:00
void fsm_store_restore_reset (int choice, int value);// def: prefer; call: signal;
bool fsm_get_preferences_state(); // def: fsm/dispatch; call: - - -
2024-09-16 16:23:45 +02:00
void fsm_set_preferences_modified (bool value); // def: fsm/dispatch;
// call: signal; fsm/prefer;
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;
void fsm_reset_all_situations_transparencies_at_value (int value); // provisoire...
// def: fsm/prefer; call: signal;
2024-08-29 08:21:22 +02:00
void fsm_msg (int choice, int value, char *string, int sub_automaton);
// def: fsm/dispatch; call: fsm/dispatch;
// fsm/measure;
// fsm/result;
2024-08-29 08:21:22 +02:00
// --------------------------------------------------------------- WIP ------
// def: measure/tool_list call: measure/tool_list (about the following functions...)
void fsm_tools_list_insert (tool_list **tl, int value);
int fsm_tools_list_pop (tool_list **tl);
int fsm_tools_list_length (tool_list *tl);
void fsm_tools_list_clear (tool_list **tl);
void fsm_tools_list_view (tool_list *tl);
void fsm_tools_list_test(); // def: measure/manage; call: measure/manage;
2024-08-29 08:21:22 +02:00
// def: fsm/measure/manage/; call: rule exec
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id);
// --------------------------------------------------------------- WIP ------
void fsm_add_data (data_list d, int *p_data, int *p_target);
int fsm_get_data (data_list d, int from, int to);
void fsm_remove_data (data_list d, int *p_data);
// --------------------------------------------------------------- WIP ------
void fsm_disp_add_chart (disp_list d, int *p_chart);
int fsm_disp_get_chart (disp_list d, int from, int to);
void fsm_disp_remove_chart (disp_list d, int *p_chart);