Commit dce1c3b0 authored by winckel's avatar winckel

Added filters read function.

Fixed a pthread issue with XML parser.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4332 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 18633187
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libxml/parser.h>
#include "xml_parse.h" #include "xml_parse.h"
#include "resolvers.h" #include "resolvers.h"
#include "locate_root.h" #include "locate_root.h"
...@@ -76,6 +78,12 @@ int main(int argc, char *argv[]) ...@@ -76,6 +78,12 @@ int main(int argc, char *argv[])
G_LOG_FLAG_FATAL | G_LOG_FLAG_FATAL |
G_LOG_FLAG_RECURSION); G_LOG_FLAG_RECURSION);
/* This initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
/* Initialize the widget set */ /* Initialize the widget set */
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
......
...@@ -662,12 +662,6 @@ int xml_parse_buffer(const char *xml_buffer, const int size) { ...@@ -662,12 +662,6 @@ int xml_parse_buffer(const char *xml_buffer, const int size) {
g_message("Parsing XML definition from buffer ..."); g_message("Parsing XML definition from buffer ...");
/* This initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
doc = xmlReadMemory(xml_buffer, size, NULL, NULL, 0); doc = xmlReadMemory(xml_buffer, size, NULL, NULL, 0);
if (doc == NULL) { if (doc == NULL) {
...@@ -682,12 +676,6 @@ int xml_parse_buffer(const char *xml_buffer, const int size) { ...@@ -682,12 +676,6 @@ int xml_parse_buffer(const char *xml_buffer, const int size) {
int xml_parse_file(const char *filename) { int xml_parse_file(const char *filename) {
xmlDocPtr doc; /* the resulting document tree */ xmlDocPtr doc; /* the resulting document tree */
/* This initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
if (filename == NULL) { if (filename == NULL) {
return -1; return -1;
} }
...@@ -696,7 +684,7 @@ int xml_parse_file(const char *filename) { ...@@ -696,7 +684,7 @@ int xml_parse_file(const char *filename) {
if (doc == NULL) { if (doc == NULL) {
g_warning("Failed to parse %s", filename); g_warning("Failed to parse %s", filename);
// ui_notification_dialog(DIALOG_WARNING, "Failed to parse file %s", filename); // ui_notification_dialog(DIALOG_WARNING, "Failed to parse file \"%s\"", filename);
return RC_FAIL; return RC_FAIL;
} }
...@@ -717,7 +705,7 @@ static int update_filters() { ...@@ -717,7 +705,7 @@ static int update_filters() {
{ {
if (strcmp (types->name, "MESSAGES_ID_MAX") != 0) if (strcmp (types->name, "MESSAGES_ID_MAX") != 0)
{ {
ui_filters_add (FILTER_MESSAGES, types->init_value, types->name); ui_filters_add (FILTER_MESSAGES, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED);
} }
types = types->next; types = types->next;
} }
...@@ -729,7 +717,7 @@ static int update_filters() { ...@@ -729,7 +717,7 @@ static int update_filters() {
types = types->child->child; types = types->child->child;
while (types != NULL) { while (types != NULL) {
ui_filters_add(FILTER_ORIGIN_TASKS, types->init_value, types->name); ui_filters_add(FILTER_ORIGIN_TASKS, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED);
types = types->next; types = types->next;
} }
} }
...@@ -740,7 +728,7 @@ static int update_filters() { ...@@ -740,7 +728,7 @@ static int update_filters() {
types = types->child->child; types = types->child->child;
while (types != NULL) { while (types != NULL) {
ui_filters_add(FILTER_DESTINATION_TASKS, types->init_value, types->name); ui_filters_add(FILTER_DESTINATION_TASKS, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED);
types = types->next; types = types->next;
} }
} }
......
...@@ -2,12 +2,18 @@ ...@@ -2,12 +2,18 @@
#include <stdlib.h> #include <stdlib.h>
#include <glib.h> #include <glib.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "ui_callbacks.h" #include "ui_callbacks.h"
#include "ui_main_screen.h" #include "ui_main_screen.h"
#include "ui_filters.h" #include "ui_filters.h"
#include "ui_tree_view.h"
#include "ui_notif_dlg.h"
#include "rc.h" #include "rc.h"
const uint32_t FILTER_ALLOC_NUMBER = 100; const uint32_t FILTER_ALLOC_NUMBER = 100;
const uint32_t FILTER_ID_UNDEFINED = ~0;
ui_filters_t ui_filters; ui_filters_t ui_filters;
...@@ -35,7 +41,7 @@ static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids, char *n ...@@ -35,7 +41,7 @@ static int ui_init_filter(ui_filter_t *filter, int reset, int clear_ids, char *n
for (item = 0; item < filter->used; item++) for (item = 0; item < filter->used; item++)
{ {
filter->items[item].id = ~0; filter->items[item].id = FILTER_ID_UNDEFINED;
} }
} }
} }
...@@ -54,7 +60,7 @@ int ui_init_filters(int reset, int clear_ids) ...@@ -54,7 +60,7 @@ int ui_init_filters(int reset, int clear_ids)
return (RC_OK); return (RC_OK);
} }
static int ui_search_name(ui_filter_t *filter, char *name) static int ui_search_name(ui_filter_t *filter, const char *name)
{ {
int item; int item;
...@@ -84,7 +90,29 @@ static int ui_search_id(ui_filter_t *filter, uint32_t value) ...@@ -84,7 +90,29 @@ static int ui_search_id(ui_filter_t *filter, uint32_t value)
return (item); return (item);
} }
static int ui_filter_add(ui_filter_t *filter, uint32_t value, char *name) static void ui_filter_set_enabled(uint8_t *enabled, ui_entry_enabled_e entry_enabled, gboolean new)
{
if (entry_enabled == ENTRY_ENABLED_UNDEFINED)
{
if (new)
{
*enabled = TRUE;
}
}
else
{
if (entry_enabled == ENTRY_ENABLED_FALSE)
{
*enabled = FALSE;
}
else
{
*enabled = TRUE;
}
}
}
static int ui_filter_add(ui_filter_t *filter, uint32_t value, const char *name, ui_entry_enabled_e entry_enabled)
{ {
int item = ui_search_name (filter, name); int item = ui_search_name (filter, name);
...@@ -95,33 +123,40 @@ static int ui_filter_add(ui_filter_t *filter, uint32_t value, char *name) ...@@ -95,33 +123,40 @@ static int ui_filter_add(ui_filter_t *filter, uint32_t value, char *name)
filter->allocated += FILTER_ALLOC_NUMBER; filter->allocated += FILTER_ALLOC_NUMBER;
} }
if (value != FILTER_ID_UNDEFINED)
{
filter->items[item].id = value; filter->items[item].id = value;
}
if (item >= filter->used) if (item >= filter->used)
{ {
/* New entry */ /* New entry */
strncpy (filter->items[item].name, name, SIGNAL_NAME_LENGTH); strncpy (filter->items[item].name, name, SIGNAL_NAME_LENGTH);
filter->items[item].enabled = TRUE; ui_filter_set_enabled (&filter->items[item].enabled, entry_enabled, TRUE);
filter->used++; filter->used++;
} }
else
{
ui_filter_set_enabled (&filter->items[item].enabled, entry_enabled, FALSE);
}
return (item); return (item);
} }
void ui_filters_add(ui_filter_e filter, uint32_t value, char *name) void ui_filters_add(ui_filter_e filter, uint32_t value, const char *name, ui_entry_enabled_e entry_enabled)
{ {
switch (filter) switch (filter)
{ {
case FILTER_MESSAGES: case FILTER_MESSAGES:
ui_filter_add (&ui_filters.messages, value, name); ui_filter_add (&ui_filters.messages, value, name, entry_enabled);
break; break;
case FILTER_ORIGIN_TASKS: case FILTER_ORIGIN_TASKS:
ui_filter_add (&ui_filters.origin_tasks, value, name); ui_filter_add (&ui_filters.origin_tasks, value, name, entry_enabled);
break; break;
case FILTER_DESTINATION_TASKS: case FILTER_DESTINATION_TASKS:
ui_filter_add (&ui_filters.destination_tasks, value, name); ui_filter_add (&ui_filters.destination_tasks, value, name, entry_enabled);
break; break;
default: default:
...@@ -130,7 +165,7 @@ void ui_filters_add(ui_filter_e filter, uint32_t value, char *name) ...@@ -130,7 +165,7 @@ void ui_filters_add(ui_filter_e filter, uint32_t value, char *name)
} }
} }
static gboolean ui_item_enabled(ui_filter_t *filter, char *name) static gboolean ui_item_enabled(ui_filter_t *filter, const char *name)
{ {
int item; int item;
...@@ -146,7 +181,7 @@ static gboolean ui_item_enabled(ui_filter_t *filter, char *name) ...@@ -146,7 +181,7 @@ static gboolean ui_item_enabled(ui_filter_t *filter, char *name)
return (FALSE); return (FALSE);
} }
gboolean ui_filters_message_enabled(char *message, char *origin_task, char *destination_task) gboolean ui_filters_message_enabled(const char *message, const char *origin_task, const char *destination_task)
{ {
gboolean result; gboolean result;
...@@ -156,6 +191,128 @@ gboolean ui_filters_message_enabled(char *message, char *origin_task, char *dest ...@@ -156,6 +191,128 @@ gboolean ui_filters_message_enabled(char *message, char *origin_task, char *dest
return result; return result;
} }
static ui_filter_e ui_filter_from_name(const char *name)
{
if (strcmp (name, ui_filters.messages.name) == 0)
{
return FILTER_MESSAGES;
}
if (strcmp (name, ui_filters.origin_tasks.name) == 0)
{
return FILTER_ORIGIN_TASKS;
}
if (strcmp (name, ui_filters.destination_tasks.name) == 0)
{
return FILTER_DESTINATION_TASKS;
}
return FILTER_UNKNOWN;
}
static int xml_parse_filters(xmlDocPtr doc)
{
xmlNode *root_element = NULL;
xmlNode *filter_node = NULL;
xmlNode *cur_node = NULL;
ui_filter_e filter;
int ret = RC_OK;
/* Get the root element node */
root_element = xmlDocGetRootElement (doc);
if (root_element != NULL)
{
/* Search for the start of filters definition */
for (cur_node = root_element; (strcmp ((char *) cur_node->name, "filters") != 0) && (cur_node != NULL);
cur_node = cur_node->next)
;
if (cur_node != NULL)
{
/* Search for filter header */
for (filter_node = cur_node->children; filter_node != NULL;)
{
/* Search for next element node */
for (; (filter_node != NULL) && (filter_node->type != XML_ELEMENT_NODE); filter_node =
filter_node->next)
;
if (filter_node != NULL)
{
filter = ui_filter_from_name ((const char*) filter_node->name);
// g_debug ("Found filter %s %d", filter_node->name, filter);
if (filter == FILTER_UNKNOWN)
{
g_warning("Unknown filter \"%s\"", filter_node->name);
}
else
{
/* Search for entries */
for (cur_node = filter_node->children; cur_node != NULL;)
{
/* Search for next element node */
for (; (cur_node != NULL) && (cur_node->type != XML_ELEMENT_NODE); cur_node =
cur_node->next)
;
if (cur_node != NULL)
{
// g_debug(" Found entry %s %s", cur_node->name, cur_node->properties->children->content);
ui_filters_add (
filter,
FILTER_ID_UNDEFINED,
(const char*) cur_node->name,
cur_node->properties->children->content[0] == '0' ?
ENTRY_ENABLED_FALSE : ENTRY_ENABLED_TRUE);
cur_node = cur_node->next;
}
}
}
filter_node = filter_node->next;
}
}
/* Filters have changed destroy filter menus and update tree view */
ui_destroy_filter_menus ();
ui_tree_view_refilter ();
}
}
/* Free the document */
xmlFreeDoc (doc);
/* Free the global variables that may
* have been allocated by the parser.
*/
xmlCleanupParser ();
g_message("Parsed filters definition");
return ret;
}
int ui_filters_read(const char *file_name)
{
xmlDocPtr doc; /* the resulting document tree */
if (file_name == NULL)
{
g_warning("No name for filters file");
return RC_FAIL;
}
doc = xmlReadFile (file_name, NULL, 0);
if (doc == NULL)
{
g_warning("Failed to parse \"%s\"", file_name);
ui_notification_dialog (DIALOG_WARNING, "Failed to parse file \"%s\"", file_name);
return RC_FAIL;
}
return xml_parse_filters (doc);
}
static void write_filter(FILE *filter_file, ui_filter_t *filter) static void write_filter(FILE *filter_file, ui_filter_t *filter)
{ {
int item; int item;
...@@ -163,16 +320,21 @@ static void write_filter(FILE *filter_file, ui_filter_t *filter) ...@@ -163,16 +320,21 @@ static void write_filter(FILE *filter_file, ui_filter_t *filter)
fprintf (filter_file, " <%s>\n", filter->name); fprintf (filter_file, " <%s>\n", filter->name);
for (item = 0; item < filter->used; item++) for (item = 0; item < filter->used; item++)
{ {
fprintf (filter_file, " <%s enabled=\"%d\"/>\n", filter->items[item].name, filter->items[item].enabled ? 1 : 0); fprintf (filter_file, " <%s enabled=\"%d\"/>\n", filter->items[item].name,
filter->items[item].enabled ? 1 : 0);
} }
fprintf (filter_file, " </%s>\n", filter->name); fprintf (filter_file, " </%s>\n", filter->name);
} }
int ui_write_filters_file(char *file_name) int ui_filters_file_write(const char *file_name)
{ {
FILE *filter_file; FILE *filter_file;
// types_t *types; if (file_name == NULL)
{
g_warning("No name for filters file");
return RC_FAIL;
}
filter_file = fopen (file_name, "w"); filter_file = fopen (file_name, "w");
if (filter_file == NULL) if (filter_file == NULL)
......
...@@ -7,9 +7,14 @@ ...@@ -7,9 +7,14 @@
typedef enum typedef enum
{ {
FILTER_MESSAGES, FILTER_ORIGIN_TASKS, FILTER_DESTINATION_TASKS, FILTER_UNKNOWN, FILTER_MESSAGES, FILTER_ORIGIN_TASKS, FILTER_DESTINATION_TASKS,
} ui_filter_e; } ui_filter_e;
typedef enum
{
ENTRY_ENABLED_FALSE, ENTRY_ENABLED_TRUE, ENTRY_ENABLED_UNDEFINED,
} ui_entry_enabled_e;
typedef struct typedef struct
{ {
uint32_t id; uint32_t id;
...@@ -36,11 +41,13 @@ extern ui_filters_t ui_filters; ...@@ -36,11 +41,13 @@ extern ui_filters_t ui_filters;
int ui_init_filters(int reset, int clear_ids); int ui_init_filters(int reset, int clear_ids);
void ui_filters_add(ui_filter_e filter, uint32_t value, char *name); void ui_filters_add(ui_filter_e filter, uint32_t value, const char *name, ui_entry_enabled_e entry_enabled);
gboolean ui_filters_message_enabled(const char *message, const char *origin_task, const char *destination_task);
gboolean ui_filters_message_enabled(char *message, char *origin_task, char *destination_task); int ui_filters_read(const char *file_name);
int ui_write_filters_file(char *file_name); int ui_filters_file_write(const char *file_name);
void ui_destroy_filter_menus(void); void ui_destroy_filter_menus(void);
......
...@@ -7,12 +7,15 @@ int ui_notification_dialog(dialog_type_t type, const char *fmt, ...) ...@@ -7,12 +7,15 @@ int ui_notification_dialog(dialog_type_t type, const char *fmt, ...)
{ {
va_list args; va_list args;
GtkWidget *dialogbox; GtkWidget *dialogbox;
char buffer[200];
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, args);
dialogbox = gtk_message_dialog_new(GTK_WINDOW(ui_main_data.window), dialogbox = gtk_message_dialog_new(GTK_WINDOW(ui_main_data.window),
GTK_DIALOG_MODAL, type, GTK_DIALOG_MODAL, type,
GTK_BUTTONS_OK, fmt, args); GTK_BUTTONS_OK, "%s", buffer);
gtk_dialog_run(GTK_DIALOG (dialogbox)); gtk_dialog_run(GTK_DIALOG (dialogbox));
......
...@@ -52,7 +52,7 @@ static void ui_change_cursor(gboolean busy) ...@@ -52,7 +52,7 @@ static void ui_change_cursor(gboolean busy)
gdk_window_set_cursor (window, cursor); gdk_window_set_cursor (window, cursor);
gdk_display_sync(display); gdk_display_sync(display);
gdk_cursor_unref (cursor); g_object_unref (cursor);
// gtk_widget_set_sensitive (ui_main_data.window, FALSE); // gtk_widget_set_sensitive (ui_main_data.window, FALSE);
ui_gtk_flush_events(); ui_gtk_flush_events();
} }
...@@ -218,6 +218,7 @@ int ui_filters_open_file_chooser(void) ...@@ -218,6 +218,7 @@ int ui_filters_open_file_chooser(void)
gtk_widget_destroy (filechooser); gtk_widget_destroy (filechooser);
if (accept) if (accept)
{ {
result = ui_filters_read(filename);
g_free (filename); g_free (filename);
} }
...@@ -246,12 +247,9 @@ int ui_filters_save_file_chooser(void) ...@@ -246,12 +247,9 @@ int ui_filters_save_file_chooser(void)
char *filename; char *filename;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
result = ui_filters_file_write(filename);
result = ui_write_filters_file(filename);
g_free (filename); g_free (filename);
} }
gtk_widget_destroy (filechooser); gtk_widget_destroy (filechooser);
return result; return result;
......
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