src/fsm/log/oper.c fsm_add_log_event() fixing a bug
The bug was caused by pointers to local variables sended to fsm_add_log(). malloc() are now realized in fsm_add_log_event(). + cleaning (checking that the sentence "This file is part of Gem-graph." is systematicaly added to legal mentions.)
This commit is contained in:
parent
78ebd86cb5
commit
bb89a2f03c
|
@ -67,6 +67,8 @@
|
|||
*
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -173,7 +175,7 @@ enum fsm_enum_log_source {
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Structure of a log unit.
|
||||
* A log unit must include the followings:
|
||||
*
|
||||
* @callergraph
|
||||
* @see fsm_log_struct
|
||||
|
@ -182,9 +184,9 @@ typedef struct fsm_log_unit_struct
|
|||
{
|
||||
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 */
|
||||
char *file_source; /**< * emitter file */
|
||||
char *function_source; /**< * emitter function */
|
||||
char *string_value; /**< * any event descriptors */
|
||||
struct fsm_log_unit_struct *prev; /**< * chained list */
|
||||
struct fsm_log_unit_struct *next; /**< * chained list */
|
||||
}
|
||||
|
@ -220,31 +222,31 @@ void fsm_publish_log (fsm_log_struct jj);
|
|||
void fsm_clear_log (fsm_log_struct *jj);
|
||||
|
||||
void fsm_add_log_event (fsm_log_struct *jj,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value);
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value);
|
||||
|
||||
int fsm_get_log_length(fsm_log_struct jj);
|
||||
void fsm_seek_log (fsm_log_struct jj,
|
||||
long usec,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value);
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value);
|
||||
long fsm_remove_log (fsm_log_struct *jj,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value);
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value);
|
||||
|
||||
void fsm_add_log (int severity,
|
||||
int source,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value);
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value);
|
||||
|
||||
void fsm_relay_init_log();
|
||||
void fsm_relay_close_log();
|
||||
|
||||
void fsm_init (const char *initial_message_from_main);
|
||||
void fsm_close (const char *final_message_from_main);
|
||||
void fsm_init (char *initial_message_from_main);
|
||||
void fsm_close (char *final_message_from_main);
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
* Widgets hierarchy header of the Gem-graph client;
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
* About code organization, see src/readme.dox
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -138,7 +140,7 @@ static void fsm_structures_close()
|
|||
*
|
||||
* @param *initial_info_from_main
|
||||
*/
|
||||
void fsm_init (const char *initial_info_from_main)
|
||||
void fsm_init (char *initial_info_from_main)
|
||||
{
|
||||
fsm_relay_init_log();
|
||||
|
||||
|
@ -179,7 +181,7 @@ void fsm_init (const char *initial_info_from_main)
|
|||
*
|
||||
* @param *closing_info_from_main
|
||||
*/
|
||||
void fsm_close (const char *closing_info_from_main)
|
||||
void fsm_close (char *closing_info_from_main)
|
||||
{
|
||||
fsm_add_log (INFO, FSM, "fsm/control", "fsm closing", "has began");
|
||||
fsm_structures_close();
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
* utility remains to evaluate in the case of a log list.
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -45,9 +47,9 @@
|
|||
* @returns the removed event date microseconds
|
||||
*/
|
||||
long fsm_remove_log (fsm_log_struct *jj,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value)
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value)
|
||||
{
|
||||
long usec;
|
||||
fsm_log_unit_struct *tmp = jj->last;
|
||||
|
@ -96,9 +98,9 @@ int fsm_get_log_length (fsm_log_struct jj)
|
|||
*/
|
||||
void fsm_seek_log (fsm_log_struct jj,
|
||||
long usec,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value)
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value)
|
||||
{
|
||||
fsm_log_unit_struct *a_unit = jj.first;
|
||||
int nb = 0;
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
* -# the two relay functions that init and publish the log before closing it.
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -92,9 +94,9 @@ static fsm_log_struct gg_logs;
|
|||
*/
|
||||
void fsm_add_log (int severity,
|
||||
int source,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value)
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value)
|
||||
{
|
||||
if
|
||||
(
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
* It will be printed in chronological order in a file.
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -41,6 +43,9 @@
|
|||
#include <glib.h>
|
||||
#include "../../../include/fsm.h"
|
||||
|
||||
static int string_1_size = 40;
|
||||
static int string_2_size = 40;
|
||||
static int string_3_size = 40;
|
||||
|
||||
/**
|
||||
* Inits the log: a double chained list.
|
||||
|
@ -95,25 +100,33 @@ void fsm_clear_log (fsm_log_struct *jj)
|
|||
* @param *string_value
|
||||
*/
|
||||
void fsm_add_log_event (fsm_log_struct *jj,
|
||||
const char *file_source,
|
||||
const char *function_source,
|
||||
const char *string_value)
|
||||
char *file_source,
|
||||
char *function_source,
|
||||
char *string_value)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
|
||||
fsm_log_unit_struct *new_unit = malloc (sizeof(fsm_log_unit_struct));
|
||||
if (! new_unit) exit (EXIT_FAILURE);
|
||||
|
||||
new_unit->yy_dd_mm = tv.tv_sec;
|
||||
new_unit->usec = tv.tv_usec;
|
||||
new_unit->file_source = file_source;
|
||||
new_unit->function_source = function_source;
|
||||
new_unit->string_value = string_value;
|
||||
|
||||
new_unit->file_source = malloc(string_1_size * sizeof(char));
|
||||
new_unit->function_source = malloc(string_2_size * sizeof(char));
|
||||
new_unit->string_value = malloc(string_3_size * sizeof(char));
|
||||
|
||||
strncpy (new_unit->file_source, file_source, string_1_size - 1);
|
||||
strncpy (new_unit->function_source, function_source, string_2_size - 1);
|
||||
strncpy (new_unit->string_value, string_value, string_3_size - 1);
|
||||
|
||||
new_unit->next = jj->first;
|
||||
new_unit->prev = NULL;
|
||||
|
||||
if (jj->first) jj->first->prev = new_unit;
|
||||
else jj->last = new_unit;
|
||||
|
||||
jj->first = new_unit;
|
||||
}
|
||||
|
||||
|
@ -124,6 +137,7 @@ void fsm_add_log_event (fsm_log_struct *jj,
|
|||
* Publishes all the logs chronologically (using the g_lib function: g_message)
|
||||
*
|
||||
* Today, simply printed in the console; TODO: print in a file
|
||||
* NB string_3_size = 40 (this name can't be used for formatting in g_message()
|
||||
*
|
||||
* @since 2024-09
|
||||
*
|
||||
|
@ -137,13 +151,14 @@ void fsm_publish_log (fsm_log_struct jj)
|
|||
while (a_unit)
|
||||
{
|
||||
strftime(buf, sizeof(buf), "%D %T", localtime(&a_unit->yy_dd_mm));
|
||||
g_message ("%s + %-6ld %6d %-32s %-38s %-50s",
|
||||
g_message ("%s + %-6ld %6d %-28s %-32s %-40s",
|
||||
buf,
|
||||
a_unit->usec,
|
||||
nb,
|
||||
a_unit->file_source,
|
||||
a_unit->function_source,
|
||||
a_unit->string_value);
|
||||
free (a_unit->string_value);
|
||||
a_unit = a_unit->prev;
|
||||
nb ++;
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
* Main file of the Gem-graph client; contains only the main() function.
|
||||
*
|
||||
* The main() function
|
||||
* - **initialise**
|
||||
* - **initialises**
|
||||
* -# the log,
|
||||
* -# the finite state machine (fsm),
|
||||
* -# the application,
|
||||
* -# the windows and
|
||||
*
|
||||
* - **close** all the elements it opened in reverse order
|
||||
* - **closes** all the elements it opened in reverse order
|
||||
* before ending the program execution
|
||||
* .
|
||||
*
|
||||
|
@ -19,6 +19,8 @@
|
|||
* About code organization, see src/readme.dox
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
* Gem-graph-client quick documentation (NB see also the Manual)
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
/**
|
||||
* @file
|
||||
* Gem-graph client Main Window designer.
|
||||
* Gem-graph client Main window designer.
|
||||
*
|
||||
* Initiates, designs and frees the Gem-graph client main window.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -32,16 +34,15 @@
|
|||
#include "../../../include/fsm.h"
|
||||
|
||||
/**
|
||||
* @brief Main Window design()
|
||||
* @brief Main window design()
|
||||
*
|
||||
* @param *main_window
|
||||
* @param *app
|
||||
*/
|
||||
void widget_get_main_window (GtkWindow *main_window,
|
||||
GtkApplication *app)
|
||||
void widget_get_main_window (GtkWindow *main_window, GtkApplication *app)
|
||||
{
|
||||
fsm_add_log (INFO, TOPBAR, "widget/main_window/design",
|
||||
"> main window", "has began");
|
||||
"main window", "start of design");
|
||||
|
||||
GtkWidget *topbar = GTK_WIDGET (gtk_header_bar_new ());
|
||||
|
||||
|
@ -49,11 +50,14 @@ void widget_get_main_window (GtkWindow *main_window,
|
|||
gtk_header_bar_set_title_widget (GTK_HEADER_BAR (topbar),
|
||||
gtk_label_new (title));
|
||||
|
||||
gtk_window_set_child (main_window,
|
||||
GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("./docs/showcase/E coli (Goodsell).png")));
|
||||
GtkWidget *e_coli = GTK_WIDGET (gtk_picture_new_for_filename
|
||||
("./docs/showcase/E coli (Goodsell).png"));
|
||||
|
||||
gtk_window_set_child (main_window, e_coli);
|
||||
|
||||
// g_object_unref (e_coli);
|
||||
|
||||
fsm_add_log (INFO, TOPBAR, "widget/main_window/design",
|
||||
"> main window", "has ended");
|
||||
"main window", "ready for presentation");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
/**
|
||||
* @file
|
||||
* Gem-graph client Widgets general manager.
|
||||
* Gem-graph client manager for all widgets.
|
||||
*
|
||||
* Initiates, designs and frees all the Gem-graph client windows.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @cond LICENSE
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* 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>
|
||||
|
@ -31,12 +33,13 @@
|
|||
#include "../../include/widget.h"
|
||||
#include "../../include/fsm.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static GtkWindow *main_window;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Main Window new(app) and present()
|
||||
* @brief 1) creates a new main window 2) presents this window
|
||||
*
|
||||
* NB > on_windows_activation() is in: widget/manager NOT in: src/signal
|
||||
*
|
||||
|
@ -62,10 +65,37 @@ void on_windows_activation (GtkApplication *app)
|
|||
// g_application_activate (G_APPLICATION (app)); < how ? > in main is
|
||||
// g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL);
|
||||
|
||||
// https://docs.gtk.org/gobject/method.Object.unref.html
|
||||
// https://www.cs.hunter.cuny.edu/~sweiss/course_materials/csci493.70/lecture_notes/GTK_memory_mngmt.pdf
|
||||
// Objects are reference counted in GTK.
|
||||
|
||||
//GtkWidget * widget = gtk_fixed_new();
|
||||
//g_object_ref(widget);
|
||||
//g_object_ref_sink(widget); // remove floating reference, and own this object ourselves
|
||||
//g_object_unref(widget);
|
||||
//gtk_widget_destroy(widget);
|
||||
|
||||
|
||||
main_window = GTK_WINDOW (gtk_application_window_new (app));
|
||||
|
||||
int window_int_id = gtk_application_window_get_id (GTK_APPLICATION_WINDOW (main_window));
|
||||
char window_char_id[40];
|
||||
sprintf(window_char_id, "%d", window_int_id);
|
||||
|
||||
//printf ("gtk_application_window_id = %s = %d\n", window_char_id, window_int_id);
|
||||
|
||||
fsm_add_log (INFO, WIDGETS, "widget/manager", "gtk_application_window_get_id",
|
||||
window_char_id);//"sprintf(window_id,...) << fails. Why ?");
|
||||
|
||||
//printf ("gtk_application_window_get_id (main_window) = %d\n",
|
||||
//gtk_application_window_get_id (GTK_APPLICATION_WINDOW (main_window)));
|
||||
|
||||
widget_get_main_window (main_window, app);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (main_window));
|
||||
|
||||
// g_object_unref (main_window); TODO get the closing signal of the main window
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// For the breakdown between pages, see signal > switch_state_rules_data()
|
||||
|
||||
|
@ -77,7 +107,6 @@ void on_windows_activation (GtkApplication *app)
|
|||
// is selected in: widget/topbar/left window_design_topbar_left()
|
||||
// until it is defined in the fsm (2024-09)
|
||||
// ------------------------------------------------------------------------
|
||||
// widget_design_main_window (main_window, app); // def: widget/...
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -89,6 +118,6 @@ void on_windows_activation (GtkApplication *app)
|
|||
g_signal_connect (act_b, "activate", G_CALLBACK (action_b), app2);*/
|
||||
|
||||
fsm_add_log (INFO, WIDGETS, "widget/manager", "windows activation()",
|
||||
"has ended 🧐️ | 👉️ a new session can be launched");
|
||||
"has ended 🧐️ | 👉️ a new session starts");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue