2024-10-19 16:05:49 +02:00
|
|
|
/**
|
|
|
|
* @file
|
2024-10-25 17:32:30 +02:00
|
|
|
* FSM (Finite State Machine) header
|
2024-10-19 16:05:49 +02:00
|
|
|
*
|
|
|
|
* This file is part of Gem-graph.
|
|
|
|
*
|
|
|
|
* @cond LICENSE
|
|
|
|
* Copyright © 2021 Libre en Communs <contact@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Adrien Bourmault <neox@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Jean Sirmai <jean@a-lec.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* @endcond
|
|
|
|
*/
|
2024-07-08 22:05:15 +02:00
|
|
|
|
|
|
|
|
2024-07-18 23:51:04 +02:00
|
|
|
#pragma once
|
2024-07-25 05:55:15 +02:00
|
|
|
#include <stdbool.h>
|
2024-08-19 22:53:47 +02:00
|
|
|
#include <stddef.h>
|
2024-09-21 08:47:17 +02:00
|
|
|
#include <string.h>
|
2024-08-20 09:50:20 +02:00
|
|
|
#include <gtk-4.0/gtk/gtk.h>
|
2024-07-08 22:05:15 +02:00
|
|
|
|
2024-09-13 09:38:07 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* J O U R N A L */
|
|
|
|
/******************************************************************************/
|
2024-09-16 21:27:29 +02:00
|
|
|
|
2024-10-27 04:18:58 +01:00
|
|
|
/**
|
|
|
|
* --
|
|
|
|
* J O U R N A L - M E T A - R U L E S
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* ref: sudo cat /var/log/messages
|
|
|
|
*
|
|
|
|
* log structure:
|
|
|
|
* - date
|
|
|
|
* - rank
|
|
|
|
* - file
|
|
|
|
* - function
|
|
|
|
* - value, parameter, description, context,...
|
|
|
|
* (any value that can qualify the event
|
|
|
|
* and provides useful information when reading the log)
|
|
|
|
*
|
|
|
|
* --
|
|
|
|
*
|
|
|
|
* Un seul fsm_add_log() par fonction
|
|
|
|
* ? sauf si cette fonction génère plusieurs autres fonctions d'intérêt ?
|
|
|
|
*
|
|
|
|
* S'il y a deux fsm_add_log() (begin / end) dans une fonction,
|
|
|
|
* ils doivent avoir la même étiquette (les mêmes valeurs) : SEVERITY & SOURCE
|
|
|
|
*/
|
2024-09-19 07:14:05 +02:00
|
|
|
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* Conforms to canonical log levels: FATAL, ERROR, WARN, INFO, DEBUG, TRACE
|
|
|
|
*
|
|
|
|
* https://betterstack.com/community/guides/logging/logging-best-practices/
|
|
|
|
* https://en.wikipedia.org/wiki/Syslog
|
2024-10-27 04:18:58 +01:00
|
|
|
*
|
|
|
|
* @see fsm_add_log())
|
2024-10-20 01:05:12 +02:00
|
|
|
*/
|
2024-10-27 04:18:58 +01:00
|
|
|
enum fsm_enum_log_severity {
|
2024-10-20 01:05:12 +02:00
|
|
|
FATAL, /**< (or CRITICAL) an unrecoverable failure that prevents the whole
|
|
|
|
* application from doing any further useful work */
|
2024-10-27 04:18:58 +01:00
|
|
|
ERROR, /**< a condition that hinders the execution of a specific
|
2024-10-20 01:05:12 +02:00
|
|
|
* operation within an application and is unrecoverable */
|
|
|
|
WARN, /**< something unexpected has occurred, but the application can
|
|
|
|
* continue to function normally for the time being */
|
|
|
|
INFO, /**< (or MESSAGE) a significant event occurs while the system is
|
|
|
|
* operating normally */
|
|
|
|
DEBUG, /**< a description of system states in sufficient detail to give
|
|
|
|
* developers clues as to the cause of an error */
|
|
|
|
TRACE /**< provides a systematic overview of code execution but comes at
|
|
|
|
* a cost in terms of performance */
|
|
|
|
};
|
2024-09-20 05:27:36 +02:00
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* arbitrary values that can help the logging filter work more efficiently
|
2024-10-27 04:18:58 +01:00
|
|
|
*
|
|
|
|
* @see fsm_add_log())
|
2024-10-20 01:05:12 +02:00
|
|
|
*/
|
2024-10-27 04:18:58 +01:00
|
|
|
enum fsm_enum_log_source {
|
|
|
|
SOURCE, /**< must each element of this enumeration be commented (enhanced) ? */
|
|
|
|
TARGET, /**< let's observe first how the enumeration structures and evolves on usage */
|
|
|
|
LOG, FSM, PREFER,
|
2024-09-21 08:47:17 +02:00
|
|
|
MAIN, APP, WIDGETS, SIGNAL,
|
2024-10-27 04:18:58 +01:00
|
|
|
WINDOW, /**< MAIN_WINDOW || DIALOG_WINDOW || MODAL_WINDOW || TEXT_WINDOW */
|
|
|
|
DIALOG_WINDOW, MODAL_WINDOW, TEXT_WINDOW,
|
|
|
|
AUTO_NOTIFICATION,
|
|
|
|
TOPBAR, /**< LEFT || CENTER || RIGHT */
|
|
|
|
TOPBAR_LEFT, TOPBAR_CENTER, TOPBAR_RIGHT,
|
|
|
|
PAGE, /**< SYNTH_PAGE || STATE_PAGE || RULES_PAGE || MEASURES_PAGE || RESULTS_PAGE
|
|
|
|
* \n RULES_PAGE == USER TREE versus SELECTED (vertical separation)*/
|
2024-09-20 05:27:36 +02:00
|
|
|
SYNTH_PAGE, STATE_PAGE, RULES_PAGE, MEASURES_PAGE, RESULTS_PAGE,
|
2024-10-25 17:32:30 +02:00
|
|
|
SYNTH_GLAREA, SYNTH_ALL_RESULTS,
|
2024-09-24 11:58:48 +02:00
|
|
|
SYNTH_TIME_DEP_RESULTS, SYNTH_TIME_INDEP_RESULTS,
|
2024-09-20 05:27:36 +02:00
|
|
|
STATE_TOP, STATE_BOTTOM, STATE_GLAREA, STATE_CAMERA,
|
2024-09-22 15:30:00 +02:00
|
|
|
RULE_GEOMETRY, RULE_GLAREA, RULE_CAMERA,
|
|
|
|
RULE_ALGEBRA, RULE_CONDITION, RULE_ASSIGN, RULE_ID,
|
|
|
|
RULES_TREE, RULES_COMPARE, RULES_USE,
|
2024-09-20 05:27:36 +02:00
|
|
|
MEASURES_TOOLS, MEASURES__ACTIVITY, MEASURES__DISPLAY,
|
2024-09-22 22:47:52 +02:00
|
|
|
RESULTS, TIME_DEP_RESULTS, TIME_INDEP_RESULTS,
|
2024-09-20 06:47:56 +02:00
|
|
|
WIDGET, BUTTON, SCROLL, GLAREA, TEXT, LABEL, TREE, SLIDER, EXPANDER, ENTRY,
|
2024-10-25 17:32:30 +02:00
|
|
|
ON_SWITCH_STATE_RULES_DATA,
|
2024-09-20 06:47:56 +02:00
|
|
|
SLIDER_X, SLIDER_Y, SLIDER_Z,
|
|
|
|
SLIDER_A, SLIDER_B, SLIDER_C,
|
2024-09-19 07:14:05 +02:00
|
|
|
};
|
|
|
|
|
2024-10-27 04:18:58 +01:00
|
|
|
#define LOG_MAX_LENGTH 255 /**< arbitrary */
|
2024-10-14 15:52:00 +02:00
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
2024-10-27 04:18:58 +01:00
|
|
|
* structure of a log element
|
|
|
|
*
|
|
|
|
* @callergraph
|
|
|
|
* @see fsm_add_log()
|
|
|
|
* @see fsm_add_log_event()
|
2024-10-20 01:05:12 +02:00
|
|
|
*/
|
2024-10-27 04:18:58 +01:00
|
|
|
typedef struct fsm_log_struct_unit
|
2024-09-30 15:32:57 +02:00
|
|
|
{
|
2024-10-20 01:05:12 +02:00
|
|
|
long yy_dd_mm; /**< * date of the event reported in the log */
|
|
|
|
long usec; /**< * with microseconds precision */
|
|
|
|
const char *file_source; /**< * emitter file */
|
|
|
|
const char *function_source; /**< * emitter function */
|
|
|
|
const char *string_value; /**< * any event descriptors */
|
2024-10-27 04:18:58 +01:00
|
|
|
struct fsm_log_struct_unit *prev; /**< * chained list */
|
|
|
|
struct fsm_log_struct_unit *next; /**< * chained list */
|
2024-09-30 15:32:57 +02:00
|
|
|
}
|
2024-10-27 04:18:58 +01:00
|
|
|
fsm_log_struct_unit;
|
2024-10-14 15:52:00 +02:00
|
|
|
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/**
|
|
|
|
* required to initialise a double-chained list
|
2024-10-27 04:18:58 +01:00
|
|
|
* @see use in src/fsm/dispatch/fsm_add_log()
|
|
|
|
* @see use in src/log/fsm_init_log()
|
2024-10-20 01:05:12 +02:00
|
|
|
*/
|
2024-09-30 15:32:57 +02:00
|
|
|
typedef struct {
|
2024-10-27 04:18:58 +01:00
|
|
|
fsm_log_struct_unit *first; /**< * required */
|
|
|
|
fsm_log_struct_unit *last; /**< * required */
|
2024-09-30 15:32:57 +02:00
|
|
|
}
|
2024-10-27 04:18:58 +01:00
|
|
|
fsm_log_struct;
|
|
|
|
|
|
|
|
void fsm_publish_log (fsm_log_struct jj); // def: src/journal call: fsm/dispatch
|
|
|
|
void fsm_init_log (fsm_log_struct *jj); // def: src/journal call: fsm/dispatch
|
|
|
|
void fsm_add_log_event (fsm_log_struct *jj, // def: src/journal call: fsm/dispatch
|
|
|
|
const char *file_source,
|
|
|
|
const char *function_source,
|
|
|
|
const char *string_value);
|
|
|
|
void fsm_clear_log (fsm_log_struct *jj, // def: src/journal call: none
|
|
|
|
const char *file_source,
|
|
|
|
const char *function_source,
|
|
|
|
const char *string_value);
|
|
|
|
long fsm_pop_back_log (fsm_log_struct *jj, // def: src/journal call: none
|
|
|
|
const char *file_source,
|
|
|
|
const char *function_source,
|
|
|
|
const char *string_value);
|
|
|
|
int fsm_length_log (fsm_log_struct jj); // def: src/journal call: none
|
|
|
|
void fsm_seek_log (fsm_log_struct jj, // def: src/journal call: none
|
|
|
|
long usec,
|
|
|
|
const char *file_source,
|
|
|
|
const char *function_source,
|
|
|
|
const char *string_value);
|
2024-09-16 16:23:45 +02:00
|
|
|
|
2024-09-22 22:47:52 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
2024-09-30 15:32:57 +02:00
|
|
|
//
|
|
|
|
|
2024-10-27 04:18:58 +01:00
|
|
|
void fsm_log_publication_request(); // def: fsm/dispatch call: main;
|
|
|
|
void fsm_add_log (int severity,
|
|
|
|
int source,
|
|
|
|
const char *file_source,
|
|
|
|
const char *function_source,
|
|
|
|
const char *string_value);
|
2024-09-16 19:50:59 +02:00
|
|
|
// def: fsm/dispatch call: widget/dispatch;
|
2024-09-22 22:47:52 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
2024-09-10 22:37:31 +02:00
|
|
|
|
|
|
|
|
2024-09-30 15:32:57 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* S T A T E M A C H I N E */
|
|
|
|
/******************************************************************************/
|
|
|
|
// called by widgets through signal functions
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/** phantom documentation */
|
2024-09-30 15:32:57 +02:00
|
|
|
enum fsm_enum_exec_edit { EXEC, EDIT };
|
2024-10-20 01:05:12 +02:00
|
|
|
|
|
|
|
/** phantom documentation */
|
2024-09-30 15:32:57 +02:00
|
|
|
enum fsm_enum_state_rules_data { SYNTH, STATE, RULES, DATA };
|
2024-10-20 01:05:12 +02:00
|
|
|
|
|
|
|
/** phantom documentation */
|
2024-09-30 15:32:57 +02:00
|
|
|
enum fsm_enum_store_restore_reset { STORE, RESTORE, RESET };
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/** phantom documentation */
|
2024-09-30 15:32:57 +02:00
|
|
|
enum fsm_enum_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME };
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
#define n_rules 128 /**< arbitrary */
|
|
|
|
#define n_objects 32 /**< arbitrary too, */
|
|
|
|
#define n_situations 128 /**< and so on... */
|
2024-10-14 15:52:00 +02:00
|
|
|
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/** phantom documentation */
|
2024-10-14 15:52:00 +02:00
|
|
|
typedef struct fsm_struct_list_tool {
|
|
|
|
int value; /**< *value phantom documentation */
|
|
|
|
struct fsm_struct_list_tool *suiv; /**< *suiv phantom documentation */
|
|
|
|
} fsm_struct_list_tool ;
|
|
|
|
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/** phantom documentation */
|
2024-10-14 15:52:00 +02:00
|
|
|
typedef struct fsm_struct_list_data {
|
|
|
|
int value; /**< *value phantom documentation */
|
|
|
|
struct fsm_struct_list_data *suiv; /**< *suiv phantom documentation */
|
|
|
|
|
|
|
|
} fsm_struct_list_data ;
|
|
|
|
|
|
|
|
|
2024-10-20 01:05:12 +02:00
|
|
|
/** phantom documentation */
|
2024-10-14 15:52:00 +02:00
|
|
|
typedef struct fsm_struct_list_disp {
|
|
|
|
int value; /**< *value phantom documentation */
|
|
|
|
struct fsm_struct_list_disp *suiv; /**< *suiv phantom documentation */
|
|
|
|
} fsm_struct_list_disp ;
|
2024-09-30 15:32:57 +02:00
|
|
|
|
|
|
|
|
2024-08-28 06:19:06 +02:00
|
|
|
|
2024-09-30 18:12:50 +02:00
|
|
|
void fsm_init (char *message); // def: fsm/dispatch; call: main;
|
|
|
|
void fsm_list_init_preferences(); // def: fsm/preferences/manager; call: fsm/dispatch;
|
|
|
|
void fsm_list_init_measures(); // def: fsm/measure/manager; call: fsm/dispatch;
|
|
|
|
void fsm_list_init_results(); // def: fsm/results/manager; call: fsm/dispatch;
|
|
|
|
void fsm_list_init_displayables(); // def: fsm/preferences/manager; call: fsm/dispatch;
|
2024-07-24 23:07:14 +02:00
|
|
|
|
2024-09-30 18:12:50 +02:00
|
|
|
int fsm_get_exec_edit(); // def: fsm/disfpatch; call: signal;
|
2024-08-21 23:19:27 +02:00
|
|
|
// 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
|
|
|
|
2024-08-21 23:19:27 +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
|
|
|
|
2024-09-30 15:32:57 +02:00
|
|
|
void fsm_set_store_restore_reset (int choice, int value);// def: prefer; call: signal;
|
2024-07-20 19:04:08 +02:00
|
|
|
|
2024-10-27 04:18:58 +01:00
|
|
|
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;
|
2024-07-27 12:34:32 +02:00
|
|
|
|
2024-09-30 18:12:50 +02:00
|
|
|
void fsm_add_measure (char *measure_name); // def: fsm/measure/manager;
|
2024-08-27 15:07:16 +02:00
|
|
|
// call: widget/measure/dispatch;
|
2024-09-30 18:12:50 +02:00
|
|
|
void fsm_add_result (char *result_name); // def: fsm/results/manager; call: - - -
|
|
|
|
void fsm_add_displayable (char *displayable_name);// def: fsm/preferences/manager; call: fsm/preferences/manager;
|
2024-08-20 09:32:20 +02:00
|
|
|
|
2024-09-30 18:12:50 +02:00
|
|
|
void fsm_reset_all_situations_values (int value); // def: fsm/preferences/manager; call: signal;
|
2024-08-20 09:32:20 +02:00
|
|
|
|
2024-08-29 08:21:22 +02:00
|
|
|
// --------------------------------------------------------------- WIP ------
|
|
|
|
// def: measure/tool_list call: measure/tool_list (about the following functions...)
|
2024-10-20 01:05:12 +02:00
|
|
|
void fsm_tools_list_insert (fsm_struct_list_tool **tl, int value);
|
|
|
|
int fsm_tools_list_pop (fsm_struct_list_tool **tl);
|
|
|
|
int fsm_tools_list_length (fsm_struct_list_tool *tl);
|
|
|
|
void fsm_tools_list_clear (fsm_struct_list_tool **tl);
|
|
|
|
void fsm_tools_list_view (fsm_struct_list_tool *tl);
|
|
|
|
void fsm_tools_list_test(); // def: measures/manager; call: measures/manager;
|
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);
|
|
|
|
|
|
|
|
|
2024-08-30 15:14:01 +02:00
|
|
|
// --------------------------------------------------------------- WIP ------
|
2024-10-20 01:05:12 +02:00
|
|
|
// @see fsm/measures/data_list/
|
2024-09-30 15:32:57 +02:00
|
|
|
void fsm_add_data (fsm_struct_list_data d, int *p_data, int *p_target);
|
|
|
|
int fsm_get_data (fsm_struct_list_data d, int from, int to);
|
|
|
|
void fsm_remove_data (fsm_struct_list_data d, int *p_data);
|
2024-08-31 09:12:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------- WIP ------
|
2024-09-30 18:12:50 +02:00
|
|
|
/*void fsm_disp_add_chart (fsm_struct_list_disp d, int *p_chart);
|
2024-09-30 15:32:57 +02:00
|
|
|
int fsm_disp_get_chart (fsm_struct_list_disp d, int from, int to);
|
2024-09-30 18:12:50 +02:00
|
|
|
void fsm_disp_remove_chart (fsm_struct_list_disp d, int *p_chart);*/
|
2024-08-31 09:12:59 +02:00
|
|
|
|