Commit d9c939dc authored by winckel's avatar winckel

Added filters files.

Added line options.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4318 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 0680e22f
...@@ -47,6 +47,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level, ...@@ -47,6 +47,7 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
fprintf(stderr, "unknown log_level %u\n", log_level); fprintf(stderr, "unknown log_level %u\n", log_level);
level = NULL; level = NULL;
g_assert_not_reached(); g_assert_not_reached();
break;
} }
/* create a "timestamp" */ /* create a "timestamp" */
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui_interface.h" #include "ui_interface.h"
#include "ui_notif_dlg.h" #include "ui_notif_dlg.h"
#include "ui_filters.h"
#include "../libresolver/locate_root.h" #include "../libresolver/locate_root.h"
#include "../libresolver/resolvers.h" #include "../libresolver/resolvers.h"
...@@ -702,6 +703,47 @@ int xml_parse_file(const char *filename) { ...@@ -702,6 +703,47 @@ int xml_parse_file(const char *filename) {
return xml_parse_doc(doc); return xml_parse_doc(doc);
} }
static int update_filters() {
types_t *types;
ui_init_filters(FALSE, TRUE);
types = messages_id_enum;
if (types != NULL)
{
types = types->child;
while (types != NULL) {
ui_filters_add(FILTER_MESSAGES, types->init_value, types->name);
types = types->next;
}
}
types = origin_task_id_type;
if (types != NULL)
{
types = types->child->child;
while (types != NULL) {
ui_filters_add(FILTER_ORIGIN_TASKS, types->init_value, types->name);
types = types->next;
}
}
types = destination_task_id_type;
if (types != NULL)
{
types = types->child->child;
while (types != NULL) {
ui_filters_add(FILTER_DESTINATION_TASKS, types->init_value, types->name);
types = types->next;
}
}
return RC_OK;
}
static int xml_parse_doc(xmlDocPtr doc) { static int xml_parse_doc(xmlDocPtr doc) {
xmlNode *root_element = NULL; xmlNode *root_element = NULL;
types_t *head = NULL; types_t *head = NULL;
...@@ -740,6 +782,7 @@ static int xml_parse_doc(xmlDocPtr doc) { ...@@ -740,6 +782,7 @@ static int xml_parse_doc(xmlDocPtr doc) {
CHECK_FCT(locate_type("originTaskId", head, &origin_task_id_type)); CHECK_FCT(locate_type("originTaskId", head, &origin_task_id_type));
CHECK_FCT(locate_type("destinationTaskId", head, &destination_task_id_type)); CHECK_FCT(locate_type("destinationTaskId", head, &destination_task_id_type));
// root->type_hr_display(root, 0); // root->type_hr_display(root, 0);
update_filters();
if (dissect_file != NULL) { if (dissect_file != NULL) {
root->type_file_print (root, 0, dissect_file); root->type_file_print (root, 0, dissect_file);
} }
......
...@@ -17,4 +17,5 @@ libui_la_SOURCES = \ ...@@ -17,4 +17,5 @@ libui_la_SOURCES = \
ui_notifications.c ui_notifications.h \ ui_notifications.c ui_notifications.h \
ui_notif_dlg.c ui_notif_dlg.h \ ui_notif_dlg.c ui_notif_dlg.h \
ui_interface.c ui_interface.h \ ui_interface.c ui_interface.h \
ui_notebook.c ui_notebook.h ui_notebook.c ui_notebook.h \
ui_filters.c ui_filters.h
\ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui_notifications.h" #include "ui_notifications.h"
#include "ui_tree_view.h" #include "ui_tree_view.h"
#include "ui_signal_dissect_view.h" #include "ui_signal_dissect_view.h"
#include "ui_filters.h"
#include "types.h" #include "types.h"
#include "locate_root.h" #include "locate_root.h"
...@@ -236,8 +237,8 @@ gboolean ui_callback_on_connect(GtkWidget *widget, GdkEvent *event, gpointer dat ...@@ -236,8 +237,8 @@ gboolean ui_callback_on_connect(GtkWidget *widget, GdkEvent *event, gpointer dat
g_debug("Connect event occurred"); g_debug("Connect event occurred");
port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.portentry))); port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.port_entry)));
ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ipentry)); ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ip_entry));
if ((ip == NULL) || (port == 0)) if ((ip == NULL) || (port == 0))
{ {
...@@ -315,20 +316,92 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget, GdkEvent *event, gpo ...@@ -315,20 +316,92 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget, GdkEvent *event, gpo
return TRUE; return TRUE;
} }
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget, GdkEvent *event, gpointer data) static gboolean ui_callback_on_menu_item_selected(GtkWidget *widget, gpointer data)
{ {
g_debug("ui_callback_on_tree_column_header_click_signal\n"); ui_filter_item_t *filter_entry = data;
// g_debug("ui_callback_on_menu_item_selected occurred %x %x %s", widget, data, filter_entry->name);
filter_entry->enabled = ~filter_entry->enabled;
return TRUE; return TRUE;
} }
gboolean ui_callback_on_tree_column_header_click_from(GtkWidget *widget, GdkEvent *event, gpointer data) static void ui_create_filter_menu(GtkWidget **menu, ui_filter_t *filter)
{ {
g_debug("ui_callback_on_tree_column_header_click_from\n"); GtkWidget *menu_items;
return TRUE; int item;
gpointer data;
*menu = gtk_menu_new ();
for (item = 0; item < filter->used; item++)
{
/* Create a new menu-item with a name */
menu_items = gtk_check_menu_item_new_with_label (filter->items[item].name);
/* Add it to the menu. */
gtk_menu_shell_append (GTK_MENU_SHELL (*menu), menu_items);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_items), filter->items[item].enabled);
/* Connect function to be called when the menu item is selected */
data = &filter->items[item];
//g_debug("ui_create_filter_menu %x %x", menu_items, data);
g_signal_connect(G_OBJECT (menu_items), "activate", G_CALLBACK(ui_callback_on_menu_item_selected), data);
/* Show the widget */
gtk_widget_show (menu_items);
}
}
static void ui_destroy_filter_menu(GtkWidget **menu, ui_filter_t *filter)
{
/* TODO destroy menu items ? */
gtk_widget_destroy (*menu);
*menu = NULL;
} }
gboolean ui_callback_on_tree_column_header_click_to(GtkWidget *widget, GdkEvent *event, gpointer data) void ui_destroy_filter_menus()
{ {
g_debug("ui_callback_on_tree_column_header_click_to\n"); ui_destroy_filter_menu (&ui_main_data.menu_filter_messages, &ui_filters.messages);
ui_destroy_filter_menu (&ui_main_data.menu_filter_origin_tasks, &ui_filters.origin_tasks);
ui_destroy_filter_menu (&ui_main_data.menu_filter_destination_tasks, &ui_filters.destination_tasks);
}
static void ui_show_filter_menu(GtkWidget **menu, ui_filter_t *filter)
{
if (*menu == NULL)
{
ui_create_filter_menu (menu, filter);
}
gtk_menu_popup (GTK_MENU (*menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
}
gboolean ui_callback_on_tree_column_header_click(GtkWidget *widget, gpointer data)
{
col_type_e col = (col_type_e) data;
g_debug("ui_callback_on_tree_column_header_click %x", col);
switch (col)
{
case COL_SIGNAL:
ui_show_filter_menu (&ui_main_data.menu_filter_messages, &ui_filters.messages);
break;
case COL_FROM_TASK:
ui_show_filter_menu (&ui_main_data.menu_filter_origin_tasks, &ui_filters.origin_tasks);
break;
case COL_TO_TASK:
ui_show_filter_menu (&ui_main_data.menu_filter_destination_tasks, &ui_filters.destination_tasks);
break;
default:
g_warning("Unknown column filter %d in call to ui_callback_on_tree_column_header_click", col);
return FALSE;
}
return TRUE; return TRUE;
} }
...@@ -61,16 +61,6 @@ gboolean ui_callback_signal_clear_list(GtkWidget *widget, ...@@ -61,16 +61,6 @@ gboolean ui_callback_signal_clear_list(GtkWidget *widget,
gboolean ui_pipe_callback(gint source, gpointer user_data); gboolean ui_pipe_callback(gint source, gpointer user_data);
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget, gboolean ui_callback_on_tree_column_header_click(GtkWidget *widget,
GdkEvent *event, gpointer data);
gpointer data);
gboolean ui_callback_on_tree_column_header_click_from(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_tree_column_header_click_to(GtkWidget *widget,
GdkEvent *event,
gpointer data);
#endif /* UI_CALLBACKS_H_ */ #endif /* UI_CALLBACKS_H_ */
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include "ui_filters.h"
#include "rc.h"
const uint32_t FILTER_ALLOC_NUMBER = 100;
ui_filters_t ui_filters;
static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids)
{
if (filter->items == NULL)
{
/* Allocate some filter entries */
filter->items = malloc (FILTER_ALLOC_NUMBER * sizeof(ui_filter_item_t));
filter->allocated = FILTER_ALLOC_NUMBER;
}
if (reset)
{
/* Reset number of used filter entries */
filter->used = 0;
}
else
{
if (clear_ids)
{
/* Clear entries IDs */
int item;
for (item = 0; item < filter->used; item++)
{
filter->items[item].id = ~0;
}
}
}
return (RC_OK);
}
int ui_init_filters(int reset, int clear_ids)
{
ui_init_filter (&ui_filters.messages, reset, clear_ids);
ui_init_filter (&ui_filters.origin_tasks, reset, clear_ids);
ui_init_filter (&ui_filters.destination_tasks, reset, clear_ids);
return (RC_OK);
}
static int ui_search_name(ui_filter_t *filter, char *name)
{
int item;
for (item = 0; item < filter->used; item++)
{
if (strncmp (name, filter->items[item].name, SIGNAL_NAME_LENGTH) == 0)
{
return (item);
}
}
return (item);
}
static int ui_filter_add(ui_filter_t *filter, uint32_t value, char *name)
{
int item = ui_search_name (filter, name);
if (item >= filter->allocated)
{
/* Increase number of filter entries */
filter->items = realloc (filter->items, (filter->allocated + FILTER_ALLOC_NUMBER) * sizeof(ui_filter_item_t));
filter->allocated += FILTER_ALLOC_NUMBER;
}
filter->items[item].id = value;
if (item >= filter->used)
{
/* New entry */
strncpy(filter->items[item].name, name, SIGNAL_NAME_LENGTH);
filter->items[item].enabled = TRUE;
filter->used++;
}
return (item);
}
void ui_filters_add(ui_filter_e filter, uint32_t value, char *name)
{
switch (filter)
{
case FILTER_MESSAGES:
ui_filter_add (&ui_filters.messages, value, name);
break;
case FILTER_ORIGIN_TASKS:
ui_filter_add (&ui_filters.origin_tasks, value, name);
break;
case FILTER_DESTINATION_TASKS:
ui_filter_add (&ui_filters.destination_tasks, value, name);
break;
default:
g_error("unknown filter type %d", filter);
break;
}
}
static void parse_filters(void)
{
}
static int write_filters_file(void)
{
char *filter_file_name = "./filters.xml";
FILE *filter_file;
// types_t *types;
filter_file = fopen (filter_file_name, "w");
if (filter_file == NULL)
{
g_warning("Failed to open file \"%s\": %s", filter_file_name, g_strerror (errno));
return RC_FAIL;
}
fprintf (filter_file, "<filters>\n");
/* types = messages_id_enum;
if (types != NULL)
{
types = types->child;
}
fprintf (filter_file, " <messages>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </messages>\n");
types = origin_task_id_type;
if (types != NULL)
{
types = types->child->child;
}
fprintf (filter_file, " <origin_tasks>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </origin_tasks>\n");
types = destination_task_id_type;
if (types != NULL)
{
types = types->child->child;
}
fprintf (filter_file, " <destination_tasks>\n");
while (types != NULL) {
fprintf (filter_file, " %s=\"1\"\n", types->name);
types = types->next;
}
fprintf (filter_file, " </destination_tasks>\n");
*/
fprintf (filter_file, "</filters>\n");
fclose (filter_file);
return RC_OK;
}
#ifndef UI_FILTERS_H_
#define UI_FILTERS_H_
#include <stdint.h>
#include "itti_types.h"
typedef enum
{
FILTER_MESSAGES, FILTER_ORIGIN_TASKS, FILTER_DESTINATION_TASKS,
} ui_filter_e;
typedef struct
{
uint32_t id;
char name[SIGNAL_NAME_LENGTH];
uint8_t enabled;
} ui_filter_item_t;
typedef struct
{
uint32_t allocated;
uint32_t used;
ui_filter_item_t *items;
} ui_filter_t;
typedef struct
{
ui_filter_t messages;
ui_filter_t origin_tasks;
ui_filter_t destination_tasks;
} ui_filters_t;
extern ui_filters_t ui_filters;
int ui_init_filters(int reset, int clear_ids);
void ui_filters_add(ui_filter_e filter, uint32_t value, char *name);
#endif /* UI_FILTERS_H_ */
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
...@@ -17,17 +19,73 @@ ...@@ -17,17 +19,73 @@
#include "ui_tree_view.h" #include "ui_tree_view.h"
#include "ui_notebook.h" #include "ui_notebook.h"
#include "ui_notifications.h" #include "ui_notifications.h"
#include "ui_filters.h"
ui_main_data_t ui_main_data; ui_main_data_t ui_main_data;
static void ui_help(void)
{
printf ("Usage: itti_analyser [options]\n\n"
"Options:\n"
" -f FILTERS read filters from FILTERS file\n"
" -h display this help and exit\n"
" -i IP set ip address to IP\n"
" -m MESSAGES read messages from MESSAGES file\n"
" -p PORT set port to PORT\n");
}
static void ui_gtk_parse_arg(int argc, char *argv[])
{
char c;
while ((c = getopt (argc, argv, "f:hi:m:p:")) != -1)
{
switch (c)
{
case 'f':
ui_main_data.filters_file_name = optarg;
break;
case 'h':
ui_help();
exit(0);
break;
case 'i':
ui_main_data.ip_entry_init = optarg;
break;
case 'm':
ui_main_data.messages_file_name = optarg;
break;
case 'p':
ui_main_data.port_entry_init = optarg;
break;
default:
ui_help ();
exit (-1);
break;
}
}
}
int ui_gtk_initialize(int argc, char *argv[]) int ui_gtk_initialize(int argc, char *argv[])
{ {
GtkWidget *vbox; GtkWidget *vbox;
memset(&ui_main_data, 0, sizeof(ui_main_data_t)); memset(&ui_main_data, 0, sizeof(ui_main_data_t));
/* Set some default initialization value */
ui_main_data.ip_entry_init = "127.0.0.1";
ui_main_data.port_entry_init = "10007";
ui_gtk_parse_arg(argc, argv);
/* Create the main window */ /* Create the main window */
ui_main_data.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); ui_main_data.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
ui_init_filters(TRUE, FALSE);
gtk_window_set_position(GTK_WINDOW(ui_main_data.window), GTK_WIN_POS_CENTER); gtk_window_set_position(GTK_WINDOW(ui_main_data.window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(ui_main_data.window), 1024, 800); gtk_window_set_default_size(GTK_WINDOW(ui_main_data.window), 1024, 800);
...@@ -52,5 +110,17 @@ int ui_gtk_initialize(int argc, char *argv[]) ...@@ -52,5 +110,17 @@ int ui_gtk_initialize(int argc, char *argv[])
/* Show the application window */ /* Show the application window */
gtk_widget_show_all (ui_main_data.window); gtk_widget_show_all (ui_main_data.window);
/* Read filters file */
if (ui_main_data.filters_file_name != NULL)
{
// ui_filters_read(ui_main_data.filters_file_name);
}
/* Read messages file */
if (ui_main_data.messages_file_name != NULL)
{
ui_messages_read(ui_main_data.messages_file_name);
}
return RC_OK; return RC_OK;
} }
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
typedef struct { typedef struct {
GtkWidget *window; GtkWidget *window;
GtkWidget *ipentry; GtkWidget *ip_entry;
GtkWidget *portentry; char *ip_entry_init;
GtkWidget *port_entry;
char *port_entry_init;
GtkWidget *progressbar; GtkWidget *progressbar;
GtkWidget *signalslist; GtkWidget *signalslist;
...@@ -33,6 +35,13 @@ typedef struct { ...@@ -33,6 +35,13 @@ typedef struct {
/* Nb of messages received */ /* Nb of messages received */
guint nb_message_received; guint nb_message_received;
char *filters_file_name;
char *messages_file_name;
GtkWidget *menu_filter_messages;
GtkWidget *menu_filter_origin_tasks;
GtkWidget *menu_filter_destination_tasks;
int pipe_fd[2]; int pipe_fd[2];
} ui_main_data_t; } ui_main_data_t;
......
...@@ -25,6 +25,8 @@ int ui_menu_bar_create(GtkWidget *vbox) ...@@ -25,6 +25,8 @@ int ui_menu_bar_create(GtkWidget *vbox)
GtkWidget *save_filters; GtkWidget *save_filters;
GtkWidget *quit; GtkWidget *quit;
GtkWidget *about; GtkWidget *about;
GtkWidget *separator1;
GtkWidget *separator2;
if (!vbox) if (!vbox)
return RC_BAD_PARAM; return RC_BAD_PARAM;
...@@ -40,14 +42,18 @@ int ui_menu_bar_create(GtkWidget *vbox) ...@@ -40,14 +42,18 @@ int ui_menu_bar_create(GtkWidget *vbox)
open_filters = gtk_menu_item_new_with_label("Open filters file"); open_filters = gtk_menu_item_new_with_label("Open filters file");
save_filters = gtk_menu_item_new_with_label("Save filters file"); save_filters = gtk_menu_item_new_with_label("Save filters file");
quit = gtk_menu_item_new_with_label("Quit"); quit = gtk_menu_item_new_with_label("Quit");
separator1 = gtk_menu_item_new();
separator2 = gtk_menu_item_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file); gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_messages); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_messages);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_messages); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_messages);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), separator1);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_filters); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_filters);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_filters); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_filters);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), separator2);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit); gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
/* Create the Help submenu */ /* Create the Help submenu */
...@@ -241,21 +247,21 @@ int ui_toolbar_create(GtkWidget *vbox) ...@@ -241,21 +247,21 @@ int ui_toolbar_create(GtkWidget *vbox)
iplabel = gtk_label_new("ip:"); iplabel = gtk_label_new("ip:");
portlabel = gtk_label_new("port:"); portlabel = gtk_label_new("port:");
ui_main_data.ipentry = gtk_entry_new(); ui_main_data.ip_entry = gtk_entry_new();
/* Width of 15 characters for port number (ipv4 address) */ /* Width of 15 characters for port number (ipv4 address) */
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.ipentry), 15); gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.ip_entry), 15);
gtk_entry_set_text(GTK_ENTRY(ui_main_data.ipentry), "127.0.0.1"); gtk_entry_set_text(GTK_ENTRY(ui_main_data.ip_entry), ui_main_data.ip_entry_init);
ui_main_data.portentry = gtk_entry_new(); ui_main_data.port_entry = gtk_entry_new();
/* Width of 5 characters for port number (uint16_t) */ /* Width of 5 characters for port number (uint16_t) */
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.portentry), 5); gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.port_entry), 5);
gtk_entry_set_text(GTK_ENTRY(ui_main_data.portentry), "10007"); gtk_entry_set_text(GTK_ENTRY(ui_main_data.port_entry), ui_main_data.port_entry_init);
gtk_box_pack_start(GTK_BOX(hbox), toolbar, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), toolbar, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox), iplabel, FALSE, FALSE, 2); gtk_box_pack_start(GTK_BOX(hbox), iplabel, FALSE, FALSE, 2);
gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.ipentry, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.ip_entry, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(hbox), portlabel, FALSE, FALSE, 2); gtk_box_pack_start(GTK_BOX(hbox), portlabel, FALSE, FALSE, 2);
gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.portentry, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), ui_main_data.port_entry, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
return RC_OK; return RC_OK;
......
...@@ -34,119 +34,126 @@ int ui_enable_connect_button(void) ...@@ -34,119 +34,126 @@ int ui_enable_connect_button(void)
return RC_OK; return RC_OK;
} }
int ui_messages_open_file_chooser(void) int ui_messages_read(char *filename)
{ {
GtkWidget *filechooser;
int result = RC_OK; int result = RC_OK;
int source;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window), int read_data = 0;
GTK_FILE_CHOOSER_ACTION_OPEN, void *input_data = NULL;
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, size_t input_data_length = 0;
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, int read_messages = 0;
NULL);
source = open (filename, O_RDONLY);
/* Process the response */ if (source < 0)
if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
{ {
char *filename; g_warning( "Failed to open file \"%s\": %s", filename, g_strerror (errno));
int source; result = RC_FAIL;
int read_data = 0; }
void *input_data = NULL; else
size_t input_data_length = 0; {
int read_messages = 0; itti_socket_header_t message_header;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); ui_callback_signal_clear_list (NULL, NULL, NULL);
source = open (filename, O_RDONLY); do
if (source < 0)
{
g_warning ("Failed to open file \"%s\": %s", filename, g_strerror (errno));
result = RC_FAIL;
}
else
{ {
itti_socket_header_t message_header; read_data = read (source, &message_header, sizeof(itti_socket_header_t));
ui_callback_signal_clear_list(NULL, NULL, NULL); if (read_data == -1)
{
g_warning("Failed to read from file \"%s\": %s", filename, g_strerror (errno));
result = RC_FAIL;
break;
}
do if (read_data > 0)
{ {
read_data = read (source, &message_header, sizeof(itti_socket_header_t)); input_data_length = message_header.message_size - sizeof(itti_socket_header_t);
if (read_data == -1) // g_debug ("%x, %x ,%x\n", message_header.message_type, message_header.message_size, input_data_length);
{
g_warning ("Failed to read from file \"%s\": %s", filename, g_strerror (errno));
result = RC_FAIL;
break;
}
if (read_data > 0) /* Checking for non-header part */
if (input_data_length > 0)
{ {
input_data_length = message_header.message_size - sizeof(itti_socket_header_t); input_data = malloc (input_data_length);
// g_debug ("%x, %x ,%x\n", message_header.message_type, message_header.message_size, input_data_length); if (read (source, input_data, input_data_length) < 0)
/* Checking for non-header part */
if (input_data_length > 0)
{ {
input_data = malloc (input_data_length); g_warning("Failed to read from file \"%s\": %s", filename, g_strerror (errno));
result = RC_FAIL;
if (read (source, input_data, input_data_length) < 0) break;
{
g_warning ("Failed to read from file \"%s\": %s", filename, g_strerror (errno));
result = RC_FAIL;
break;
}
} }
}
switch (message_header.message_type) switch (message_header.message_type)
{
case ITTI_DUMP_MESSAGE_TYPE:
{ {
case ITTI_DUMP_MESSAGE_TYPE: itti_signal_header_t *itti_signal_header = input_data;
buffer_t *buffer;
/* Create the new buffer */
if (buffer_new_from_data (&buffer, input_data + sizeof(itti_signal_header_t),
input_data_length - sizeof(itti_signal_header_t), 0) != RC_OK)
{ {
itti_signal_header_t *itti_signal_header = input_data; g_error("Failed to create new buffer");
buffer_t *buffer; g_assert_not_reached ();
/* Create the new buffer */
if (buffer_new_from_data (&buffer, input_data + sizeof(itti_signal_header_t),
input_data_length - sizeof(itti_signal_header_t), 0) != RC_OK)
{
g_error ("Failed to create new buffer");
g_assert_not_reached ();
}
buffer->message_number = itti_signal_header->message_number;
ui_signal_add_to_list (buffer, NULL);
read_messages ++;
break;
} }
case ITTI_DUMP_XML_DEFINITION: buffer->message_number = itti_signal_header->message_number;
xml_parse_buffer (input_data, input_data_length);
break;
case ITTI_STATISTIC_MESSAGE_TYPE: ui_signal_add_to_list (buffer, NULL);
default: read_messages++;
g_debug ("Received unknow (or not implemented) message from socket type: %d", break;
message_header.message_type);
break;
} }
free (input_data); case ITTI_DUMP_XML_DEFINITION:
xml_parse_buffer (input_data, input_data_length);
break;
case ITTI_STATISTIC_MESSAGE_TYPE:
default:
g_debug("Received unknow (or not implemented) message from socket type: %d", message_header.message_type);
break;
} }
} while (read_data > 0);
if (read_messages > 0) free (input_data);
{
/* Enable buttons to move in the list of signals */
ui_set_sensitive_move_buttons(TRUE);
} }
} while (read_data > 0);
g_debug ("Read %d messages from file \"%s\"\n", read_messages, filename); if (read_messages > 0)
{
close (source); /* Enable buttons to move in the list of signals */
ui_set_sensitive_move_buttons (TRUE);
} }
g_debug("Read %d messages from file \"%s\"\n", read_messages, filename);
close (source);
}
return result;
}
int ui_messages_open_file_chooser(void)
{
GtkWidget *filechooser;
int result = RC_OK;
filechooser = gtk_file_chooser_dialog_new ("Select file", GTK_WINDOW (ui_main_data.window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
/* Process the response */
if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT)
{
char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
result = ui_messages_read(filename);
g_free (filename); g_free (filename);
} }
......
...@@ -5,6 +5,8 @@ int ui_disable_connect_button(void); ...@@ -5,6 +5,8 @@ int ui_disable_connect_button(void);
int ui_enable_connect_button(void); int ui_enable_connect_button(void);
int ui_messages_read(char *filename);
int ui_messages_open_file_chooser(void); int ui_messages_open_file_chooser(void);
int ui_filters_open_file_chooser(void); int ui_filters_open_file_chooser(void);
......
...@@ -29,19 +29,19 @@ ui_tree_view_init_list(GtkWidget *list) ...@@ -29,19 +29,19 @@ ui_tree_view_init_list(GtkWidget *list)
"Signal", renderer, "text", COL_SIGNAL, NULL); "Signal", renderer, "text", COL_SIGNAL, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
g_signal_connect(G_OBJECT(column), "clicked", g_signal_connect(G_OBJECT(column), "clicked",
G_CALLBACK(ui_callback_on_tree_column_header_click_signal), NULL); G_CALLBACK(ui_callback_on_tree_column_header_click), (gpointer) COL_SIGNAL);
column = gtk_tree_view_column_new_with_attributes( column = gtk_tree_view_column_new_with_attributes(
"From", renderer, "text", COL_FROM_TASK, NULL); "From", renderer, "text", COL_FROM_TASK, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
g_signal_connect(G_OBJECT(column), "clicked", g_signal_connect(G_OBJECT(column), "clicked",
G_CALLBACK(ui_callback_on_tree_column_header_click_from), NULL); G_CALLBACK(ui_callback_on_tree_column_header_click), (gpointer) COL_FROM_TASK);
column = gtk_tree_view_column_new_with_attributes( column = gtk_tree_view_column_new_with_attributes(
"To", renderer, "text", COL_TO_TASK, NULL); "To", renderer, "text", COL_TO_TASK, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
g_signal_connect(G_OBJECT(column), "clicked", g_signal_connect(G_OBJECT(column), "clicked",
G_CALLBACK(ui_callback_on_tree_column_header_click_to), NULL); G_CALLBACK(ui_callback_on_tree_column_header_click), (gpointer) COL_TO_TASK);
store = gtk_list_store_new(NUM_COLS, store = gtk_list_store_new(NUM_COLS,
G_TYPE_STRING, G_TYPE_STRING,
...@@ -95,6 +95,7 @@ void ui_tree_view_destroy_list(GtkWidget *list) ...@@ -95,6 +95,7 @@ void ui_tree_view_destroy_list(GtkWidget *list)
/* Reset number of messages */ /* Reset number of messages */
ui_main_data.nb_message_received = 0; ui_main_data.nb_message_received = 0;
ui_main_data.path_last = NULL;
} }
int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox) int ui_tree_view_create(GtkWidget *window, GtkWidget *vbox)
......
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