Commit d9c939dc authored by winckel's avatar winckel
Browse files

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,
fprintf(stderr, "unknown log_level %u\n", log_level);
level = NULL;
g_assert_not_reached();
break;
}
/* create a "timestamp" */
......
......@@ -10,6 +10,7 @@
#include "ui_interface.h"
#include "ui_notif_dlg.h"
#include "ui_filters.h"
#include "../libresolver/locate_root.h"
#include "../libresolver/resolvers.h"
......@@ -702,6 +703,47 @@ int xml_parse_file(const char *filename) {
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) {
xmlNode *root_element = NULL;
types_t *head = NULL;
......@@ -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("destinationTaskId", head, &destination_task_id_type));
// root->type_hr_display(root, 0);
update_filters();
if (dissect_file != NULL) {
root->type_file_print (root, 0, dissect_file);
}
......
......@@ -17,4 +17,5 @@ libui_la_SOURCES = \
ui_notifications.c ui_notifications.h \
ui_notif_dlg.c ui_notif_dlg.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 @@
#include "ui_notifications.h"
#include "ui_tree_view.h"
#include "ui_signal_dissect_view.h"
#include "ui_filters.h"
#include "types.h"
#include "locate_root.h"
......@@ -236,8 +237,8 @@ gboolean ui_callback_on_connect(GtkWidget *widget, GdkEvent *event, gpointer dat
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));
port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.port_entry)));
ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ip_entry));
if ((ip == NULL) || (port == 0))
{
......@@ -315,20 +316,92 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget, GdkEvent *event, gpo
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;
}
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");
return TRUE;
GtkWidget *menu_items;
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;
}
......@@ -61,16 +61,6 @@ gboolean ui_callback_signal_clear_list(GtkWidget *widget,
gboolean ui_pipe_callback(gint source, gpointer user_data);
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget,
GdkEvent *event,
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);
gboolean ui_callback_on_tree_column_header_click(GtkWidget *widget,
gpointer data);
#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 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>
......@@ -17,17 +19,73 @@
#include "ui_tree_view.h"
#include "ui_notebook.h"
#include "ui_notifications.h"
#include "ui_filters.h"
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[])
{
GtkWidget *vbox;
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 */
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_default_size(GTK_WINDOW(ui_main_data.window), 1024, 800);
......@@ -52,5 +110,17 @@ int ui_gtk_initialize(int argc, char *argv[])
/* Show the application 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;
}
......@@ -5,8 +5,10 @@
typedef struct {
GtkWidget *window;
GtkWidget *ipentry;
GtkWidget *portentry;
GtkWidget *ip_entry;
char *ip_entry_init;
GtkWidget *port_entry;
char *port_entry_init;
GtkWidget *progressbar;
GtkWidget *signalslist;
......@@ -33,6 +35,13 @@ typedef struct {
/* Nb of messages 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];
} ui_main_data_t;
......
......@@ -25,6 +25,8 @@ int ui_menu_bar_create(GtkWidget *vbox)
GtkWidget *save_filters;
GtkWidget *quit;
GtkWidget *about;
GtkWidget *separator1;
GtkWidget *separator2;
if (!vbox)
return RC_BAD_PARAM;
......@@ -40,14 +42,18 @@ int ui_menu_bar_create(GtkWidget *vbox)
open_filters = gtk_menu_item_new_with_label("Open filters file");
save_filters = gtk_menu_item_new_with_label("Save filters file");
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_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), 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), save_filters);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), separator2);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
/* Create the Help submenu */
......@@ -241,21 +247,21 @@ int ui_toolbar_create(GtkWidget *vbox)
iplabel = gtk_label_new("ip:");
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) */
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.ipentry), 15);
gtk_entry_set_text(GTK_ENTRY(ui_main_data.ipentry), "127.0.0.1");
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.ip_entry), 15);
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) */
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.portentry), 5);
gtk_entry_set_text(GTK_ENTRY(ui_main_data.portentry), "10007");
gtk_entry_set_width_chars(GTK_ENTRY(ui_main_data.port_entry), 5);
gtk_entry_set_text(GTK_ENTRY(ui_main_data.port_entry), ui_main_data.port_entry_init);