diff --git a/common/utils/itti_analyzer/libbuffers/socket.c b/common/utils/itti_analyzer/libbuffers/socket.c index 916bee948114cd96574dfd57413a25dfd4fc1965..356c55d45f2a908a3332677f308d4d2605d77e53 100644 --- a/common/utils/itti_analyzer/libbuffers/socket.c +++ b/common/utils/itti_analyzer/libbuffers/socket.c @@ -24,9 +24,14 @@ #include "xml_parse.h" +#define SOCKET_NB_CONNECT_RETRY (5 * 60 * 10) /* About 5 minutes time-out for connecting to peer */ +#define SOCKET_US_BEFORE_CONNECT_RETRY (100 * 1000) /* Retry connection after 100 ms */ + #define SOCKET_NB_SIGNALS_BEFORE_SIGNALLING 10 #define SOCKET_MS_BEFORE_SIGNALLING 100 +gboolean socket_abort_connection = FALSE; + void *socket_thread_fct(void *arg); static ssize_t socket_read_data(socket_data_t *socket_data, void *buffer, size_t size, int flags) @@ -264,6 +269,7 @@ void *socket_thread_fct(void *arg) int ret; struct sockaddr_in si_me; socket_data_t *socket_data; + int retry = SOCKET_NB_CONNECT_RETRY; /* master file descriptor list */ fd_set master_fds; @@ -313,18 +319,24 @@ void *socket_thread_fct(void *arg) tv.tv_sec = 0; tv.tv_usec = 1000 * SOCKET_MS_BEFORE_SIGNALLING; - /* Connecting to remote peer */ - ret = connect(socket_data->sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr_in)); - if (ret < 0) { - g_warning("Failed to connect to peer %s:%d", - socket_data->ip_address, socket_data->port); - ui_pipe_write_message(socket_data->pipe_fd, - UI_PIPE_CONNECTION_FAILED, NULL, 0); - free(socket_data->ip_address); - free(socket_data); - /* Quit the thread */ - pthread_exit(NULL); - } + do { + /* Connecting to remote peer */ + ret = connect(socket_data->sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr_in)); + if ((ret < 0) && ((socket_abort_connection) || (retry < 0))) { + if (retry < 0) { + g_warning("Failed to connect to peer %s:%d", + socket_data->ip_address, socket_data->port); + ui_pipe_write_message(socket_data->pipe_fd, + UI_PIPE_CONNECTION_FAILED, NULL, 0); + } + free(socket_data->ip_address); + free(socket_data); + /* Quit the thread */ + pthread_exit(NULL); + } + usleep(SOCKET_US_BEFORE_CONNECT_RETRY); + retry --; + } while (ret < 0); /* Set the socket as non-blocking */ fcntl(socket_data->sd, F_SETFL, O_NONBLOCK); diff --git a/common/utils/itti_analyzer/libbuffers/socket.h b/common/utils/itti_analyzer/libbuffers/socket.h index d5396660dadf87af58b05a1e6067adc1dc4a0fa1..0e7c0ab1e5b3ecd2d5cdd703450dc18870c9d020 100644 --- a/common/utils/itti_analyzer/libbuffers/socket.h +++ b/common/utils/itti_analyzer/libbuffers/socket.h @@ -21,6 +21,8 @@ typedef struct { GList *signal_list; } socket_data_t; +gboolean socket_abort_connection; + int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port, int pipe_fd); diff --git a/common/utils/itti_analyzer/libui/ui_callbacks.c b/common/utils/itti_analyzer/libui/ui_callbacks.c index d06070cd5802f4a2584c1d2025319fb6e1e24706..486e0e4dfcc83673ebcb65606888b6a69700bb02 100644 --- a/common/utils/itti_analyzer/libui/ui_callbacks.c +++ b/common/utils/itti_analyzer/libui/ui_callbacks.c @@ -511,6 +511,7 @@ static gboolean ui_handle_socket_connection_lost(gint fd) /* Re-enable connect button */ ui_enable_connect_button (); + ui_set_sensitive_save_message_buttons (TRUE); return TRUE; } @@ -605,6 +606,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data) /* Disable the connect button */ ui_disable_connect_button (); + ui_set_sensitive_save_message_buttons (FALSE); ui_callback_signal_clear_list (widget, data); @@ -620,13 +622,12 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data) gboolean ui_callback_on_disconnect(GtkWidget *widget, gpointer data) { - /* We have to retrieve the ip address and port of remote host */ - g_message("Disconnect event occurred"); ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0); ui_enable_connect_button (); + ui_set_sensitive_save_message_buttons (TRUE); return TRUE; } diff --git a/common/utils/itti_analyzer/libui/ui_main_screen.h b/common/utils/itti_analyzer/libui/ui_main_screen.h index c21c6e66f032d36c6a41f36ddbd891c31e660d9b..35fa1cdeb52439006f9935413ed368ad9d36f0a8 100644 --- a/common/utils/itti_analyzer/libui/ui_main_screen.h +++ b/common/utils/itti_analyzer/libui/ui_main_screen.h @@ -25,6 +25,7 @@ typedef struct { GtkToolItem *open_replay_file; GtkToolItem *refresh_replay_file; + GtkToolItem *stop; GtkToolItem *save_replay_file; GtkToolItem *save_replay_file_filtered; diff --git a/common/utils/itti_analyzer/libui/ui_menu_bar.c b/common/utils/itti_analyzer/libui/ui_menu_bar.c index c6647730c7bc8f5f5da33227da53cfe7eb2607f4..4753f2bfb5b41e77ade8960b439488052c147798 100644 --- a/common/utils/itti_analyzer/libui/ui_menu_bar.c +++ b/common/utils/itti_analyzer/libui/ui_menu_bar.c @@ -7,6 +7,7 @@ #include "ui_main_screen.h" #include "ui_menu_bar.h" #include "ui_callbacks.h" +#include "ui_notifications.h" static const guint BUTTON_SPACE = 0; static const guint LABEL_SPACE = 5; @@ -14,12 +15,20 @@ static const guint SEPARATOR_SPACE = 5; void ui_set_sensitive_move_buttons(gboolean enable) { - // gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_clear_button), enable); - // gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_button), enable); gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_last_button), enable); gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_button), enable); } +void ui_set_sensitive_save_message_buttons(gboolean enable) +{ + if (ui_main_data.nb_message_received == 0) + { + enable = FALSE; + } + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.save_replay_file), enable); + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.save_replay_file_filtered), enable); +} + int ui_menu_bar_create(GtkWidget *vbox) { GtkAccelGroup *accel_group; @@ -271,6 +280,15 @@ int ui_toolbar_create(GtkWidget *vbox) G_CALLBACK(ui_callback_on_open_messages), (gpointer) TRUE); } + /* Stop reading messages file */ + { + ui_main_data.stop = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); + gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.stop), "Stop loading messages file"); + + g_signal_connect(G_OBJECT(ui_main_data.stop), "clicked", + ui_progressbar_window_destroy, NULL); + } + /* Button to save messages file */ { ui_main_data.save_replay_file = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE); @@ -369,8 +387,11 @@ int ui_toolbar_create(GtkWidget *vbox) gtk_box_pack_start(GTK_BOX(hbox), messages_label, FALSE, FALSE, LABEL_SPACE); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.open_replay_file), FALSE, FALSE, BUTTON_SPACE); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.refresh_replay_file), FALSE, FALSE, BUTTON_SPACE); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.stop), FALSE, FALSE, BUTTON_SPACE); + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.stop), FALSE); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.save_replay_file), FALSE, FALSE, BUTTON_SPACE); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.save_replay_file_filtered), FALSE, FALSE, BUTTON_SPACE); + ui_set_sensitive_save_message_buttons(FALSE); gtk_box_pack_start(GTK_BOX(hbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL), FALSE, FALSE, SEPARATOR_SPACE); diff --git a/common/utils/itti_analyzer/libui/ui_menu_bar.h b/common/utils/itti_analyzer/libui/ui_menu_bar.h index 529a0674c384907a97ea01a26deb792e264e7e86..f7f1c808b83767e23bb1f52ffd3885701507ae3a 100644 --- a/common/utils/itti_analyzer/libui/ui_menu_bar.h +++ b/common/utils/itti_analyzer/libui/ui_menu_bar.h @@ -3,6 +3,8 @@ void ui_set_sensitive_move_buttons(gboolean enable); +void ui_set_sensitive_save_message_buttons(gboolean enable); + int ui_menu_bar_create(GtkWidget *vbox); int ui_toolbar_create(GtkWidget *vbox); diff --git a/common/utils/itti_analyzer/libui/ui_notifications.c b/common/utils/itti_analyzer/libui/ui_notifications.c index 89e106eb0c9d9e445c5bbe047426416234f93262..31bf7668c0f94b322aa3d160dd4828d6160d8970 100644 --- a/common/utils/itti_analyzer/libui/ui_notifications.c +++ b/common/utils/itti_analyzer/libui/ui_notifications.c @@ -24,6 +24,7 @@ #include "locate_root.h" #include "xml_parse.h" +#include "socket.h" static const itti_message_types_t itti_dump_xml_definition_end = ITTI_DUMP_XML_DEFINITION_END; static const itti_message_types_t itti_dump_message_type_end = ITTI_DUMP_MESSAGE_TYPE_END; @@ -37,6 +38,7 @@ int ui_disable_connect_button(void) /* Disable Connect button and enable disconnect button */ gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.connect), FALSE); gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), TRUE); + socket_abort_connection = FALSE; return RC_OK; } @@ -46,6 +48,7 @@ int ui_enable_connect_button(void) /* Disable Disconnect button and enable connect button */ gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.connect), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), FALSE); + socket_abort_connection = TRUE; ui_set_title (""); return RC_OK; @@ -280,6 +283,10 @@ int ui_messages_read(char *file_name) basename = g_path_get_basename (file_name); ui_set_title ("\"%s\"", basename); } + else + { + result = RC_FAIL; + } ui_progress_bar_terminate (); @@ -377,6 +384,8 @@ int ui_messages_open_file_chooser(void) gtk_widget_destroy (filechooser); if (accept) { + ui_set_sensitive_save_message_buttons (FALSE); + result = ui_messages_read (filename); if (result == RC_OK) { @@ -386,6 +395,8 @@ int ui_messages_open_file_chooser(void) g_free (ui_main_data.messages_file_name); } ui_main_data.messages_file_name = filename; + + ui_set_sensitive_save_message_buttons (TRUE); } else { @@ -572,6 +583,8 @@ int ui_progress_bar_set_fraction(double fraction) g_signal_connect(ui_main_data.progressbar_window, "destroy", ui_progressbar_window_destroy, NULL); gtk_widget_show_all (ui_main_data.progressbar_window); + + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.stop), TRUE); } gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(ui_main_data.progressbar), fraction); @@ -594,6 +607,7 @@ int ui_progress_bar_terminate(void) gtk_widget_destroy (ui_main_data.progressbar_window); ui_main_data.progressbar_window = NULL; } + gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.stop), FALSE); return RC_OK; }