Added a time-out of about 5 minutes to socket connection.
Added control of sensitivity to some buttons. Added a stop button for messages load. git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4943 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
@@ -24,9 +24,14 @@
|
|||||||
|
|
||||||
#include "xml_parse.h"
|
#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_NB_SIGNALS_BEFORE_SIGNALLING 10
|
||||||
#define SOCKET_MS_BEFORE_SIGNALLING 100
|
#define SOCKET_MS_BEFORE_SIGNALLING 100
|
||||||
|
|
||||||
|
gboolean socket_abort_connection = FALSE;
|
||||||
|
|
||||||
void *socket_thread_fct(void *arg);
|
void *socket_thread_fct(void *arg);
|
||||||
|
|
||||||
static ssize_t socket_read_data(socket_data_t *socket_data, void *buffer, size_t size, int flags)
|
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;
|
int ret;
|
||||||
struct sockaddr_in si_me;
|
struct sockaddr_in si_me;
|
||||||
socket_data_t *socket_data;
|
socket_data_t *socket_data;
|
||||||
|
int retry = SOCKET_NB_CONNECT_RETRY;
|
||||||
|
|
||||||
/* master file descriptor list */
|
/* master file descriptor list */
|
||||||
fd_set master_fds;
|
fd_set master_fds;
|
||||||
@@ -313,18 +319,24 @@ void *socket_thread_fct(void *arg)
|
|||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 1000 * SOCKET_MS_BEFORE_SIGNALLING;
|
tv.tv_usec = 1000 * SOCKET_MS_BEFORE_SIGNALLING;
|
||||||
|
|
||||||
/* Connecting to remote peer */
|
do {
|
||||||
ret = connect(socket_data->sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr_in));
|
/* Connecting to remote peer */
|
||||||
if (ret < 0) {
|
ret = connect(socket_data->sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr_in));
|
||||||
g_warning("Failed to connect to peer %s:%d",
|
if ((ret < 0) && ((socket_abort_connection) || (retry < 0))) {
|
||||||
socket_data->ip_address, socket_data->port);
|
if (retry < 0) {
|
||||||
ui_pipe_write_message(socket_data->pipe_fd,
|
g_warning("Failed to connect to peer %s:%d",
|
||||||
UI_PIPE_CONNECTION_FAILED, NULL, 0);
|
socket_data->ip_address, socket_data->port);
|
||||||
free(socket_data->ip_address);
|
ui_pipe_write_message(socket_data->pipe_fd,
|
||||||
free(socket_data);
|
UI_PIPE_CONNECTION_FAILED, NULL, 0);
|
||||||
/* Quit the thread */
|
}
|
||||||
pthread_exit(NULL);
|
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 */
|
/* Set the socket as non-blocking */
|
||||||
fcntl(socket_data->sd, F_SETFL, O_NONBLOCK);
|
fcntl(socket_data->sd, F_SETFL, O_NONBLOCK);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ typedef struct {
|
|||||||
GList *signal_list;
|
GList *signal_list;
|
||||||
} socket_data_t;
|
} socket_data_t;
|
||||||
|
|
||||||
|
gboolean socket_abort_connection;
|
||||||
|
|
||||||
int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port,
|
int socket_connect_to_remote_host(const char *remote_ip, const uint16_t port,
|
||||||
int pipe_fd);
|
int pipe_fd);
|
||||||
|
|
||||||
|
|||||||
@@ -511,6 +511,7 @@ static gboolean ui_handle_socket_connection_lost(gint fd)
|
|||||||
|
|
||||||
/* Re-enable connect button */
|
/* Re-enable connect button */
|
||||||
ui_enable_connect_button ();
|
ui_enable_connect_button ();
|
||||||
|
ui_set_sensitive_save_message_buttons (TRUE);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,6 +606,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
|
|||||||
|
|
||||||
/* Disable the connect button */
|
/* Disable the connect button */
|
||||||
ui_disable_connect_button ();
|
ui_disable_connect_button ();
|
||||||
|
ui_set_sensitive_save_message_buttons (FALSE);
|
||||||
|
|
||||||
ui_callback_signal_clear_list (widget, data);
|
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)
|
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");
|
g_message("Disconnect event occurred");
|
||||||
|
|
||||||
ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
|
ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
|
||||||
|
|
||||||
ui_enable_connect_button ();
|
ui_enable_connect_button ();
|
||||||
|
ui_set_sensitive_save_message_buttons (TRUE);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ typedef struct {
|
|||||||
|
|
||||||
GtkToolItem *open_replay_file;
|
GtkToolItem *open_replay_file;
|
||||||
GtkToolItem *refresh_replay_file;
|
GtkToolItem *refresh_replay_file;
|
||||||
|
GtkToolItem *stop;
|
||||||
GtkToolItem *save_replay_file;
|
GtkToolItem *save_replay_file;
|
||||||
GtkToolItem *save_replay_file_filtered;
|
GtkToolItem *save_replay_file_filtered;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "ui_main_screen.h"
|
#include "ui_main_screen.h"
|
||||||
#include "ui_menu_bar.h"
|
#include "ui_menu_bar.h"
|
||||||
#include "ui_callbacks.h"
|
#include "ui_callbacks.h"
|
||||||
|
#include "ui_notifications.h"
|
||||||
|
|
||||||
static const guint BUTTON_SPACE = 0;
|
static const guint BUTTON_SPACE = 0;
|
||||||
static const guint LABEL_SPACE = 5;
|
static const guint LABEL_SPACE = 5;
|
||||||
@@ -14,12 +15,20 @@ static const guint SEPARATOR_SPACE = 5;
|
|||||||
|
|
||||||
void ui_set_sensitive_move_buttons(gboolean enable)
|
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_last_button), enable);
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_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)
|
int ui_menu_bar_create(GtkWidget *vbox)
|
||||||
{
|
{
|
||||||
GtkAccelGroup *accel_group;
|
GtkAccelGroup *accel_group;
|
||||||
@@ -271,6 +280,15 @@ int ui_toolbar_create(GtkWidget *vbox)
|
|||||||
G_CALLBACK(ui_callback_on_open_messages), (gpointer) TRUE);
|
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 */
|
/* Button to save messages file */
|
||||||
{
|
{
|
||||||
ui_main_data.save_replay_file = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
|
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), 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.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.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), FALSE, FALSE, BUTTON_SPACE);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(ui_main_data.save_replay_file_filtered), 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);
|
gtk_box_pack_start(GTK_BOX(hbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL), FALSE, FALSE, SEPARATOR_SPACE);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
void ui_set_sensitive_move_buttons(gboolean enable);
|
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_menu_bar_create(GtkWidget *vbox);
|
||||||
|
|
||||||
int ui_toolbar_create(GtkWidget *vbox);
|
int ui_toolbar_create(GtkWidget *vbox);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "locate_root.h"
|
#include "locate_root.h"
|
||||||
#include "xml_parse.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_xml_definition_end = ITTI_DUMP_XML_DEFINITION_END;
|
||||||
static const itti_message_types_t itti_dump_message_type_end = ITTI_DUMP_MESSAGE_TYPE_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 */
|
/* 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.connect), FALSE);
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), TRUE);
|
gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), TRUE);
|
||||||
|
socket_abort_connection = FALSE;
|
||||||
|
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,7 @@ int ui_enable_connect_button(void)
|
|||||||
/* Disable Disconnect button and enable connect button */
|
/* 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.connect), TRUE);
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), FALSE);
|
gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), FALSE);
|
||||||
|
socket_abort_connection = TRUE;
|
||||||
ui_set_title ("");
|
ui_set_title ("");
|
||||||
|
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
@@ -280,6 +283,10 @@ int ui_messages_read(char *file_name)
|
|||||||
basename = g_path_get_basename (file_name);
|
basename = g_path_get_basename (file_name);
|
||||||
ui_set_title ("\"%s\"", basename);
|
ui_set_title ("\"%s\"", basename);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = RC_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
ui_progress_bar_terminate ();
|
ui_progress_bar_terminate ();
|
||||||
|
|
||||||
@@ -377,6 +384,8 @@ int ui_messages_open_file_chooser(void)
|
|||||||
gtk_widget_destroy (filechooser);
|
gtk_widget_destroy (filechooser);
|
||||||
if (accept)
|
if (accept)
|
||||||
{
|
{
|
||||||
|
ui_set_sensitive_save_message_buttons (FALSE);
|
||||||
|
|
||||||
result = ui_messages_read (filename);
|
result = ui_messages_read (filename);
|
||||||
if (result == RC_OK)
|
if (result == RC_OK)
|
||||||
{
|
{
|
||||||
@@ -386,6 +395,8 @@ int ui_messages_open_file_chooser(void)
|
|||||||
g_free (ui_main_data.messages_file_name);
|
g_free (ui_main_data.messages_file_name);
|
||||||
}
|
}
|
||||||
ui_main_data.messages_file_name = filename;
|
ui_main_data.messages_file_name = filename;
|
||||||
|
|
||||||
|
ui_set_sensitive_save_message_buttons (TRUE);
|
||||||
}
|
}
|
||||||
else
|
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);
|
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_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);
|
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);
|
gtk_widget_destroy (ui_main_data.progressbar_window);
|
||||||
ui_main_data.progressbar_window = NULL;
|
ui_main_data.progressbar_window = NULL;
|
||||||
}
|
}
|
||||||
|
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.stop), FALSE);
|
||||||
|
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user