Files
openairinterface5g/common/utils/itti_analyzer/libui/ui_callbacks.c
T
winckel 0680e22f91 Added buttons, menu items and calback functions to open and save messages files.
Added menu items and calback functions to open and save filters files.
By default, the signal list tree view show the last received signals, this can be stop by selecting manually another signal (not the last one).
Removed the "new" button, the signals list is cleared before each new aquisition or when opening a messages file becausethe signal list may not be compatible between to list of signals!
Enabled column header clicks and created callback functions to display and modify column filters.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4316 818b1a75-f10b-46b9-bf7c-635c3b92a50f
2013-11-04 14:12:16 +00:00

335 lines
9.7 KiB
C

#include <stdlib.h>
#include <stdint.h>
#include <gtk/gtk.h>
#include "rc.h"
#include "socket.h"
#include "ui_notif_dlg.h"
#include "ui_main_screen.h"
#include "ui_menu_bar.h"
#include "ui_callbacks.h"
#include "ui_interface.h"
#include "ui_notifications.h"
#include "ui_tree_view.h"
#include "ui_signal_dissect_view.h"
#include "types.h"
#include "locate_root.h"
#include "xml_parse.h"
static gboolean ui_handle_socket_connection_failed(gint fd);
gboolean ui_callback_on_open_messages(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Open replay event occurred");
CHECK_FCT(ui_messages_open_file_chooser());
return TRUE;
}
gboolean ui_callback_on_save_messages(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Save replay event occurred");
// CHECK_FCT(ui_file_chooser());
return TRUE;
}
gboolean ui_callback_on_open_filters(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Open filters event occurred");
CHECK_FCT(ui_filters_open_file_chooser());
return TRUE;
}
gboolean ui_callback_on_save_filters(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Save filters event occurred");
CHECK_FCT(ui_filters_save_file_chooser());
return TRUE;
}
gboolean ui_callback_on_about(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return TRUE;
}
gboolean ui_callback_on_select_signal(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
gboolean path_currently_selected, gpointer user_data)
{
ui_text_view_t *text_view;
GtkTreeIter iter;
text_view = (ui_text_view_t *) user_data;
g_assert(text_view != NULL);
if (gtk_tree_model_get_iter (model, &iter, path))
{
GValue buffer_store = G_VALUE_INIT;
gpointer buffer;
gtk_tree_model_get_value (model, &iter, COL_BUFFER, &buffer_store);
buffer = g_value_get_pointer (&buffer_store);
if (!path_currently_selected)
{
/* Clear the view */
CHECK_FCT_DO(ui_signal_dissect_clear_view(text_view), return FALSE);
/* Dissect the signal */
CHECK_FCT_DO(dissect_signal((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
}
}
return TRUE;
}
void ui_signal_add_to_list(gpointer data, gpointer user_data)
{
buffer_t *signal_buffer;
GtkTreePath *path;
GtkTreeViewColumn *focus_column;
gtk_tree_view_get_cursor (GTK_TREE_VIEW(ui_main_data.signalslist), &path, &focus_column);
signal_buffer = (buffer_t *) data;
get_message_id (root, signal_buffer, &signal_buffer->message_id);
ui_tree_view_new_signal_ind (signal_buffer->message_number, message_id_to_string (signal_buffer->message_id),
get_origin_task_id (signal_buffer), get_destination_task_id (signal_buffer), data);
/* Increment number of messages */
ui_main_data.nb_message_received++;
/* Check if no signal was selected in the list or if it was the last signal */
if ((ui_main_data.path_last == NULL) || (gtk_tree_path_compare(ui_main_data.path_last, path) == 0))
{
/* Advance to the new last signal */
ui_callback_signal_go_to_last (NULL, NULL, NULL);
}
}
static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_length)
{
pipe_new_signals_list_message_t *signal_list_message;
/* Enable buttons to move in the list of signals */
ui_set_sensitive_move_buttons (TRUE);
signal_list_message = (pipe_new_signals_list_message_t *) data;
g_assert(signal_list_message != NULL);
g_assert(signal_list_message->signal_list != NULL);
g_list_foreach (signal_list_message->signal_list, ui_signal_add_to_list, NULL);
/* Free the list but not user data associated with each element */
g_list_free (signal_list_message->signal_list);
/* Free the message */
free (signal_list_message);
return TRUE;
}
static gboolean ui_handle_socket_connection_failed(gint fd)
{
GtkWidget *dialogbox;
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 */
ui_enable_connect_button ();
return TRUE;
}
static gboolean ui_handle_socket_connection_lost(gint fd)
{
GtkWidget *dialogbox;
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 */
ui_enable_connect_button ();
return TRUE;
}
static gboolean ui_handle_socket_xml_definition(gint fd, void *data, size_t data_length)
{
pipe_xml_definition_message_t *xml_definition_message;
xml_definition_message = (pipe_xml_definition_message_t *) data;
g_assert(xml_definition_message != NULL);
g_assert(data_length == sizeof(pipe_xml_definition_message_t));
xml_parse_buffer (xml_definition_message->xml_definition, xml_definition_message->xml_definition_length);
free (data);
return TRUE;
}
gboolean ui_pipe_callback(gint source, gpointer user_data)
{
void *input_data = NULL;
size_t input_data_length = 0;
pipe_input_header_t input_header;
/* Read the header */
if (read (source, &input_header, sizeof(input_header)) < 0)
{
g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
return FALSE;
}
input_data_length = input_header.message_size - sizeof(input_header);
/* Checking for non-header part */
if (input_data_length > 0)
{
input_data = malloc (input_data_length);
if (read (source, input_data, input_data_length) < 0)
{
g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
return FALSE;
}
}
switch (input_header.message_type)
{
case UI_PIPE_CONNECTION_FAILED:
return ui_handle_socket_connection_failed (source);
case UI_PIPE_XML_DEFINITION:
return ui_handle_socket_xml_definition (source, input_data, input_data_length);
case UI_PIPE_CONNECTION_LOST:
return ui_handle_socket_connection_lost (source);
case UI_PIPE_UPDATE_SIGNAL_LIST:
return ui_handle_update_signal_list (source, input_data, input_data_length);
default:
g_debug("[gui] Unhandled message type %u", input_header.message_type);
g_assert_not_reached();
}
return FALSE;
}
gboolean ui_callback_on_connect(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
const char *ip;
uint16_t port;
int pipe_fd[2];
g_debug("Connect event occurred");
port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.portentry)));
ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ipentry));
if ((ip == NULL) || (port == 0))
{
g_warning("NULL parameter given for ip address or port = 0");
/* TODO: add dialog box here */
return FALSE;
}
ui_pipe_new (pipe_fd, ui_pipe_callback, NULL);
memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
/* Disable the connect button */
ui_disable_connect_button ();
ui_callback_signal_clear_list (widget, event, data);
if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0)
{
ui_enable_connect_button ();
return FALSE;
}
return TRUE;
}
gboolean ui_callback_on_disconnect(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
g_debug("Disconnect event occurred");
ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
ui_enable_connect_button ();
return TRUE;
}
gboolean ui_callback_signal_go_to(GtkWidget *widget, GdkEvent *event, gpointer data)
{
ui_tree_view_select_row (ui_main_data.nb_message_received / 2, NULL);
return TRUE;
}
gboolean ui_callback_signal_go_to_first(GtkWidget *widget, GdkEvent *event, gpointer data)
{
ui_tree_view_select_row (0, NULL);
return TRUE;
}
gboolean ui_callback_signal_go_to_last(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GtkTreePath *path;
ui_tree_view_select_row (ui_main_data.nb_message_received - 1, &path);
ui_main_data.path_last = path;
return TRUE;
}
gboolean ui_callback_signal_clear_list(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* Disable buttons to move in the list of signals */
ui_set_sensitive_move_buttons (FALSE);
/* Clear list of signals */
ui_tree_view_destroy_list (ui_main_data.signalslist);
return TRUE;
}
gboolean ui_callback_on_tree_view_select(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
g_debug("List selection event occurred");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_signal\n");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_from(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_from\n");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_to(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_to\n");
return TRUE;
}