une double liste chainée est prête à héberger le fsm journal
This commit is contained in:
parent
f7f8c5be98
commit
c46c0c0699
|
@ -45,8 +45,26 @@ enum fsm_measure_type {DATE_RULE_EXEC, RULE_EXEC_NB, OBJECT_NB, ELAPSED_TIME };
|
||||||
typedef struct tool_list {int value; struct tool_list *suiv;} tool_list ;
|
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 data_list {int value; struct data_list *suiv;} data_list ;
|
||||||
typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ;
|
typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ;
|
||||||
typedef struct journal {int value; struct journal *prev;} journal;
|
|
||||||
|
// --------------------------------------------------------------- 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 *l); // initialise
|
||||||
|
void fsm_journal_clear (journal *l); // vide tout le journal
|
||||||
|
int fsm_journal_push_back (journal *l, int event); // ajoute un évènement en fin de journal
|
||||||
|
int fsm_journal_push_front (journal *l, int event); // ajoute un évènement en début de journal
|
||||||
|
int fsm_journal_pop_back (journal *l); // retire un évènement en fin de journal
|
||||||
|
int fsm_journal_pop_front (journal *l); // retire un évènement en début de journal
|
||||||
|
int fsm_journal_length (journal l); // 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 l); // affiche tout le journal
|
||||||
|
void fsm_journal_test();
|
||||||
|
// --------------------------------------------------------------- WIP ------
|
||||||
// ref: sudo cat /var/log/messages
|
// ref: sudo cat /var/log/messages
|
||||||
|
// --------------------------------------------------------------- WIP ------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fsm_init(); // def: fsm/dispatch; call: main;
|
void fsm_init(); // def: fsm/dispatch; call: main;
|
||||||
void fsm_engine_init(); // def: fsm/engine/engine; call main
|
void fsm_engine_init(); // def: fsm/engine/engine; call main
|
||||||
|
@ -96,15 +114,6 @@ void fsm_tools_list_test(); // def: measure/manage; call: measure/manage;
|
||||||
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id);
|
void fsm_rule_trig_measure (int rule_id, int object_id, int measure_id);
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------- WIP ------
|
|
||||||
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 vv);
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------- WIP ------
|
// --------------------------------------------------------------- WIP ------
|
||||||
void fsm_add_data (data_list d, int *p_data, int *p_target);
|
void fsm_add_data (data_list d, int *p_data, int *p_target);
|
||||||
int fsm_get_data (data_list d, int from, int to);
|
int fsm_get_data (data_list d, int from, int to);
|
||||||
|
|
|
@ -29,68 +29,140 @@
|
||||||
#include "../../include/fsm.h"
|
#include "../../include/fsm.h"
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* A journal (a pile) stores chronologically the fsm events */
|
/* A journal stores chronologically the fsm events */
|
||||||
/* during a session run (rules exec, mainly) */
|
/* during a session run (rules exec, mainly) */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int fsm_journal_push (journal **jj, int vv)
|
void fsm_journal_init (journal *jj)
|
||||||
{
|
{
|
||||||
journal *element = malloc (sizeof(journal));
|
jj->first = NULL;
|
||||||
if (!element) exit (EXIT_FAILURE); // Si l'allocation a échoué.
|
jj->last = NULL;
|
||||||
element->value = vv;
|
|
||||||
element->prev = *jj;
|
|
||||||
*jj = element; // Le pointeur pointe sur le dernier élément.
|
|
||||||
return vv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsm_journal_pop (journal **jj)
|
void fsm_journal_clear (journal *jj)
|
||||||
{
|
{
|
||||||
int vv;
|
unit *tmp;
|
||||||
journal *tmp;
|
unit *a_unit = jj->first;
|
||||||
if (!*jj) return -1; // Retourne -1 si le journal est vide.
|
while(a_unit)
|
||||||
tmp = (*jj)->prev;
|
{
|
||||||
vv = (*jj)->value;
|
tmp = a_unit;
|
||||||
free (*jj);
|
a_unit = a_unit->next;
|
||||||
*jj = tmp; // Le pointeur pointe sur le dernier élément.
|
free(tmp);
|
||||||
return vv; // retourne la value retirée du journal.
|
}
|
||||||
|
jj->first = NULL;
|
||||||
|
jj->last = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsm_journal_clear (journal **jj)
|
int fsm_journal_push_back (journal *jj, int event)
|
||||||
{
|
{
|
||||||
journal *tmp;
|
unit *new_unit = malloc (sizeof(unit));
|
||||||
while (*jj)
|
if (! new_unit) exit (EXIT_FAILURE);
|
||||||
{
|
new_unit->event = event;
|
||||||
tmp = (*jj)->prev;
|
new_unit->prev = jj->last;
|
||||||
free (*jj);
|
new_unit->next = NULL;
|
||||||
*jj = tmp;
|
if (jj->last) jj->last->next = new_unit;
|
||||||
}
|
else jj->first = new_unit;
|
||||||
|
jj->last = new_unit;
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsm_journal_length (journal *jj)
|
int fsm_journal_push_front (journal *jj, int event)
|
||||||
{
|
{
|
||||||
int n=0;
|
unit *new_unit = malloc(sizeof(unit));
|
||||||
while (jj)
|
if (! new_unit) exit (EXIT_FAILURE);
|
||||||
{
|
new_unit->event = event;
|
||||||
n++;
|
new_unit->next = jj->first;
|
||||||
jj = jj->prev;
|
new_unit->prev = NULL;
|
||||||
}
|
if (jj->first) jj->first->prev = new_unit;
|
||||||
return n;
|
else jj->last = new_unit;
|
||||||
|
jj->first = new_unit;
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsm_journal_view (journal *jj)
|
int fsm_journal_pop_back (journal *jj)
|
||||||
|
{
|
||||||
|
int event;
|
||||||
|
unit *tmp = jj->last;
|
||||||
|
if (! tmp) return -1;
|
||||||
|
event = tmp->event;
|
||||||
|
jj->last = tmp->prev;
|
||||||
|
if (jj->last) jj->last->next = NULL;
|
||||||
|
else jj->first = NULL;
|
||||||
|
free (tmp);
|
||||||
|
return event; // retourne l'évènement retiré du journal.
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsm_journal_pop_front (journal *jj)
|
||||||
|
{
|
||||||
|
int event;
|
||||||
|
unit *tmp = jj->first;
|
||||||
|
if (! tmp) return -1;
|
||||||
|
event = tmp->event;
|
||||||
|
jj->first = tmp->next;
|
||||||
|
if (jj->first) jj->first->prev = NULL;
|
||||||
|
else jj->last = NULL;
|
||||||
|
free (tmp);
|
||||||
|
return event; // retourne l'évènement retiré du journal.
|
||||||
|
}
|
||||||
|
|
||||||
|
int fsm_journal_length (journal jj)
|
||||||
|
{
|
||||||
|
unit *a_unit = jj.first;
|
||||||
|
int nb = 0;
|
||||||
|
while (a_unit)
|
||||||
|
{
|
||||||
|
nb ++;
|
||||||
|
a_unit = a_unit->next;
|
||||||
|
}
|
||||||
|
return nb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsm_journal_seek (journal *jj, int event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fsm_journal_view (journal jj)
|
||||||
{
|
{
|
||||||
printf ("view journal (n = %d)\n", fsm_journal_length (jj));
|
printf ("view journal (n = %d)\n", fsm_journal_length (jj));
|
||||||
while (jj)
|
unit *a_unit = jj.first;
|
||||||
|
while (a_unit)
|
||||||
{
|
{
|
||||||
printf ("> %d\n", jj->value);
|
printf ("> %d <\n", a_unit->event);
|
||||||
jj = jj->prev;
|
a_unit = a_unit->next;
|
||||||
}
|
}
|
||||||
puts ("------");
|
puts ("------");
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsm_journal_seek (journal *jj, int vv)
|
void fsm_journal_test()
|
||||||
{
|
{
|
||||||
|
journal exemple;
|
||||||
|
|
||||||
|
fsm_journal_init (&exemple);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
printf ("clear list\n"); fsm_journal_clear (&exemple);
|
||||||
|
|
||||||
|
fsm_journal_view (exemple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "../../include/widget.h"
|
#include "../../include/widget.h"
|
||||||
#include "../../include/fsm.h"
|
#include "../../include/fsm.h"
|
||||||
|
#include "../../include/util.h"
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -90,7 +91,8 @@ void on_windows_activation (GtkApplication *app)
|
||||||
widget_design_dialog_window (main_window, dialog_window);
|
widget_design_dialog_window (main_window, dialog_window);
|
||||||
widget_design_text_window (main_window, text_window);
|
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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ static void *get_ZOOM_box()
|
||||||
void *widget_get_space_view(int partition_space_vs_camera)
|
void *widget_get_space_view(int partition_space_vs_camera)
|
||||||
{
|
{
|
||||||
GtkBox *drawbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
|
GtkBox *drawbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
|
||||||
util_gl_setup_glarea (0, GTK_WIDGET (drawbox));
|
// util_gl_setup_glarea (0, GTK_WIDGET (drawbox));
|
||||||
|
|
||||||
GtkBox *camera = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
GtkBox *camera = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2));
|
||||||
gtk_box_append (camera, GTK_WIDGET (get_XYZ_box()));
|
gtk_box_append (camera, GTK_WIDGET (get_XYZ_box()));
|
||||||
|
|
Loading…
Reference in New Issue