Commit 46ae17e7 authored by winckel's avatar winckel

Changed windows title when connecting to socket.

Fixed some issue with operations interlocking.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4944 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 49b4149b
...@@ -319,15 +319,16 @@ void *socket_thread_fct(void *arg) ...@@ -319,15 +319,16 @@ 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;
ui_set_title ("connecting to %s:%d ...", socket_data->ip_address, socket_data->port);
do { do {
/* Connecting to remote peer */ /* Connecting to remote peer */
ret = connect(socket_data->sd, (struct sockaddr *)&si_me, sizeof(struct sockaddr_in)); ret = connect(socket_data->sd, (struct sockaddr *) &si_me, sizeof(struct sockaddr_in));
if ((ret < 0) && ((socket_abort_connection) || (retry < 0))) { if (ret < 0) {
if ((socket_abort_connection) || (retry < 0)) {
if (retry < 0) { if (retry < 0) {
g_warning("Failed to connect to peer %s:%d", g_warning("Failed to connect to peer %s:%d", socket_data->ip_address, socket_data->port);
socket_data->ip_address, socket_data->port); ui_pipe_write_message(socket_data->pipe_fd, UI_PIPE_CONNECTION_FAILED, NULL, 0);
ui_pipe_write_message(socket_data->pipe_fd,
UI_PIPE_CONNECTION_FAILED, NULL, 0);
} }
free(socket_data->ip_address); free(socket_data->ip_address);
free(socket_data); free(socket_data);
...@@ -335,9 +336,12 @@ void *socket_thread_fct(void *arg) ...@@ -335,9 +336,12 @@ void *socket_thread_fct(void *arg)
pthread_exit(NULL); pthread_exit(NULL);
} }
usleep(SOCKET_US_BEFORE_CONNECT_RETRY); usleep(SOCKET_US_BEFORE_CONNECT_RETRY);
retry --; retry--;
}
} while (ret < 0); } while (ret < 0);
ui_set_title ("%s:%d", socket_data->ip_address, socket_data->port);
/* 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);
......
...@@ -44,11 +44,11 @@ gboolean ui_callback_on_open_messages(GtkWidget *widget, gpointer data) ...@@ -44,11 +44,11 @@ gboolean ui_callback_on_open_messages(GtkWidget *widget, gpointer data)
operation_running = TRUE; operation_running = TRUE;
if (refresh && (ui_main_data.messages_file_name != NULL)) if (refresh && (ui_main_data.messages_file_name != NULL))
{ {
CHECK_FCT(ui_messages_read (ui_main_data.messages_file_name)); ui_messages_read (ui_main_data.messages_file_name);
} }
else else
{ {
CHECK_FCT(ui_messages_open_file_chooser()); ui_messages_open_file_chooser ();
} }
operation_running = FALSE; operation_running = FALSE;
} }
...@@ -65,7 +65,7 @@ gboolean ui_callback_on_save_messages(GtkWidget *widget, gpointer data) ...@@ -65,7 +65,7 @@ gboolean ui_callback_on_save_messages(GtkWidget *widget, gpointer data)
if (operation_running == FALSE) if (operation_running == FALSE)
{ {
operation_running = TRUE; operation_running = TRUE;
CHECK_FCT(ui_messages_save_file_chooser(filtered)); ui_messages_save_file_chooser(filtered);
operation_running = FALSE; operation_running = FALSE;
} }
...@@ -111,12 +111,11 @@ gboolean ui_callback_on_open_filters(GtkWidget *widget, gpointer data) ...@@ -111,12 +111,11 @@ gboolean ui_callback_on_open_filters(GtkWidget *widget, gpointer data)
operation_running = TRUE; operation_running = TRUE;
if (refresh && (ui_main_data.filters_file_name != NULL)) if (refresh && (ui_main_data.filters_file_name != NULL))
{ {
ui_filters_read (ui_main_data.filters_file_name);
CHECK_FCT(ui_filters_read (ui_main_data.filters_file_name));
} }
else else
{ {
CHECK_FCT(ui_filters_open_file_chooser()); ui_filters_open_file_chooser ();
} }
operation_running = FALSE; operation_running = FALSE;
} }
...@@ -130,7 +129,7 @@ gboolean ui_callback_on_save_filters(GtkWidget *widget, gpointer data) ...@@ -130,7 +129,7 @@ gboolean ui_callback_on_save_filters(GtkWidget *widget, gpointer data)
{ {
operation_running = TRUE; operation_running = TRUE;
g_message("Save filters event occurred"); g_message("Save filters event occurred");
CHECK_FCT(ui_filters_save_file_chooser()); ui_filters_save_file_chooser();
operation_running = FALSE; operation_running = FALSE;
} }
...@@ -484,34 +483,22 @@ static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_le ...@@ -484,34 +483,22 @@ static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_le
static gboolean ui_handle_socket_connection_failed(gint fd) static gboolean ui_handle_socket_connection_failed(gint fd)
{ {
GtkWidget *dialogbox; ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "connect", "Failed to connect to provided host/ip address");
dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"Failed to connect to provided host/ip address");
gtk_dialog_run (GTK_DIALOG(dialogbox));
gtk_widget_destroy (dialogbox);
/* Re-enable connect button */ /* Re-enable connect button */
ui_enable_connect_button (); ui_enable_connect_button ();
operation_running = FALSE;
return TRUE; return TRUE;
} }
static gboolean ui_handle_socket_connection_lost(gint fd) static gboolean ui_handle_socket_connection_lost(gint fd)
{ {
GtkWidget *dialogbox; ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "Connect", "Connection with remote host has been lost");
dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"Connection with remote host has been lost");
gtk_dialog_run (GTK_DIALOG(dialogbox));
gtk_widget_destroy (dialogbox);
/* Re-enable connect button */ /* Re-enable connect button */
ui_enable_connect_button (); ui_enable_connect_button ();
ui_set_sensitive_save_message_buttons (TRUE); operation_running = FALSE;
return TRUE; return TRUE;
} }
...@@ -590,16 +577,20 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data) ...@@ -590,16 +577,20 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
if (strlen (ip) == 0) if (strlen (ip) == 0)
{ {
ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "Connect", "Empty host ip address"); ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "Connect", "Empty host ip address");
return FALSE; return FALSE;
} }
if (port == 0) if (port == 0)
{ {
ui_notification_dialog (GTK_MESSAGE_WARNING, FALSE, "Connect", "Invalid host port value"); ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "Connect", "Invalid host port value");
return FALSE; return FALSE;
} }
if (operation_running == FALSE)
{
operation_running = TRUE;
ui_pipe_new (pipe_fd, ui_pipe_callback, NULL); ui_pipe_new (pipe_fd, ui_pipe_callback, NULL);
memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2); memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
...@@ -613,9 +604,10 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data) ...@@ -613,9 +604,10 @@ gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0) if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0)
{ {
ui_enable_connect_button (); ui_enable_connect_button ();
operation_running = FALSE;
return FALSE; return FALSE;
} }
ui_set_title ("%s:%d", ip, port); }
return TRUE; return TRUE;
} }
...@@ -627,7 +619,8 @@ gboolean ui_callback_on_disconnect(GtkWidget *widget, gpointer data) ...@@ -627,7 +619,8 @@ gboolean ui_callback_on_disconnect(GtkWidget *widget, gpointer data)
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); operation_running = FALSE;
return TRUE; return TRUE;
} }
......
...@@ -160,6 +160,7 @@ void ui_set_title(const char *fmt, ...) ...@@ -160,6 +160,7 @@ void ui_set_title(const char *fmt, ...)
vsnprintf (buffer, sizeof(buffer), fmt, args); vsnprintf (buffer, sizeof(buffer), fmt, args);
snprintf (title, sizeof(title), "%s %s", name, buffer); snprintf (title, sizeof(title), "%s %s", name, buffer);
va_end (args);
gtk_window_set_title (GTK_WINDOW(ui_main_data.window), title); gtk_window_set_title (GTK_WINDOW(ui_main_data.window), title);
} }
...@@ -190,7 +191,6 @@ int ui_gtk_initialize(int argc, char *argv[]) ...@@ -190,7 +191,6 @@ int ui_gtk_initialize(int argc, char *argv[])
CHECK_FCT(ui_menu_bar_create(vbox)); CHECK_FCT(ui_menu_bar_create(vbox));
CHECK_FCT(ui_toolbar_create(vbox)); CHECK_FCT(ui_toolbar_create(vbox));
// CHECK_FCT(ui_tree_view_create(ui_main_data.window, vbox));
CHECK_FCT(ui_notebook_create(vbox)); CHECK_FCT(ui_notebook_create(vbox));
gtk_container_add (GTK_CONTAINER(ui_main_data.window), vbox); gtk_container_add (GTK_CONTAINER(ui_main_data.window), vbox);
......
...@@ -49,6 +49,7 @@ int ui_enable_connect_button(void) ...@@ -49,6 +49,7 @@ int ui_enable_connect_button(void)
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; socket_abort_connection = TRUE;
ui_set_sensitive_save_message_buttons (TRUE);
ui_set_title (""); ui_set_title ("");
return RC_OK; return RC_OK;
...@@ -365,7 +366,7 @@ int ui_messages_open_file_chooser(void) ...@@ -365,7 +366,7 @@ int ui_messages_open_file_chooser(void)
int result = RC_OK; int result = RC_OK;
GtkWidget *filechooser; GtkWidget *filechooser;
gboolean accept; gboolean response_accept;
char *filename; char *filename;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window), filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window),
...@@ -375,14 +376,14 @@ int ui_messages_open_file_chooser(void) ...@@ -375,14 +376,14 @@ int ui_messages_open_file_chooser(void)
gtk_filter_add (filechooser, "All files", "*"); gtk_filter_add (filechooser, "All files", "*");
/* Process the response */ /* Process the response */
accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT; response_accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT;
if (accept) if (response_accept)
{ {
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
} }
gtk_widget_destroy (filechooser); gtk_widget_destroy (filechooser);
if (accept) if (response_accept)
{ {
ui_set_sensitive_save_message_buttons (FALSE); ui_set_sensitive_save_message_buttons (FALSE);
...@@ -468,7 +469,7 @@ int ui_filters_open_file_chooser(void) ...@@ -468,7 +469,7 @@ int ui_filters_open_file_chooser(void)
{ {
int result = RC_OK; int result = RC_OK;
GtkWidget *filechooser; GtkWidget *filechooser;
gboolean accept; gboolean response_accept;
char *filename; char *filename;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window), filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window),
...@@ -478,14 +479,14 @@ int ui_filters_open_file_chooser(void) ...@@ -478,14 +479,14 @@ int ui_filters_open_file_chooser(void)
gtk_filter_add (filechooser, "All files", "*"); gtk_filter_add (filechooser, "All files", "*");
/* Process the response */ /* Process the response */
accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT; response_accept = gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT;
if (accept) if (response_accept)
{ {
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
} }
gtk_widget_destroy (filechooser); gtk_widget_destroy (filechooser);
if (accept) if (response_accept)
{ {
result = ui_filters_read (filename); result = ui_filters_read (filename);
if (result == RC_OK) if (result == RC_OK)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment