Commit 8d61307c authored by Cedric Roux's avatar Cedric Roux
Browse files

- Started to convert debug points to use glib log API

- Moved common stuff to common/

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4239 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent f482a03e
AM_CFLAGS = \ AM_CFLAGS = \
@ADD_CFLAGS@ \ @ADD_CFLAGS@ \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \ -I$(top_srcdir)/libparser \
-I$(top_srcdir)/libresolver \ -I$(top_srcdir)/libresolver \
-I$(top_srcdir)/libbuffers \ -I$(top_srcdir)/libbuffers \
......
...@@ -16,10 +16,76 @@ ...@@ -16,10 +16,76 @@
int debug_buffers = 1; int debug_buffers = 1;
int debug_parser = 0; int debug_parser = 0;
static void
console_log_handler(const char *log_domain, GLogLevelFlags log_level,
const char *message, gpointer user_data)
{
time_t curr;
struct tm *today;
const char *level;
switch(log_level & G_LOG_LEVEL_MASK) {
case G_LOG_LEVEL_ERROR:
level = "Err ";
break;
case G_LOG_LEVEL_CRITICAL:
level = "Crit";
break;
case G_LOG_LEVEL_WARNING:
level = "Warn";
break;
case G_LOG_LEVEL_MESSAGE:
level = "Msg ";
break;
case G_LOG_LEVEL_INFO:
level = "Info";
break;
case G_LOG_LEVEL_DEBUG:
level = "Dbg ";
break;
default:
fprintf(stderr, "unknown log_level %u\n", log_level);
level = NULL;
g_assert_not_reached();
}
/* create a "timestamp" */
time(&curr);
today = localtime(&curr);
fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
today->tm_hour, today->tm_min, today->tm_sec,
log_domain != NULL ? log_domain : "",
level, message);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret = 0; int ret = 0;
GLogLevelFlags log_flags;
log_flags = (GLogLevelFlags)
(G_LOG_LEVEL_ERROR |
G_LOG_LEVEL_CRITICAL |
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_INFO |
G_LOG_LEVEL_DEBUG |
G_LOG_FLAG_FATAL |
G_LOG_FLAG_RECURSION);
if (!g_thread_supported())
g_thread_init(NULL);
/* Secure gtk */
gdk_threads_init();
/* Initialize the widget set */
gtk_init(&argc, &argv);
g_log_set_handler(NULL, log_flags, console_log_handler, NULL);
CHECK_FCT(ui_gtk_initialize(argc, argv)); CHECK_FCT(ui_gtk_initialize(argc, argv));
return ret; return ret;
......
AM_CFLAGS = \ AM_CFLAGS = \
@ADD_CFLAGS@ \ @ADD_CFLAGS@ \
-I$(top_srcdir) \ -I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \ -I$(top_srcdir)/libparser \
-I$(top_srcdir)/libui -I$(top_srcdir)/libui
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../rc.h" #include <glib.h>
#include "rc.h"
#include "buffers.h" #include "buffers.h"
extern int debug_buffers; extern int debug_buffers;
...@@ -57,7 +59,7 @@ int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value) ...@@ -57,7 +59,7 @@ int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value)
return -1; return -1;
if (buffer->size_bytes < ((offset >> 3) + size)) { if (buffer->size_bytes < ((offset >> 3) + size)) {
printf("Not enough data to fetch\n"); g_debug("Not enough data to fetch");
return -1; return -1;
} }
...@@ -190,8 +192,8 @@ int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get) ...@@ -190,8 +192,8 @@ int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get)
return -1; return -1;
underflow = (buffer->size_bytes >= ((offset + to_get) / 8)) ? 0 : -1; underflow = (buffer->size_bytes >= ((offset + to_get) / 8)) ? 0 : -1;
if (underflow && debug_buffers) if (underflow && debug_buffers)
printf("Detected Underflow offset %u, to_get %u, buffer size %u\n", g_debug("Detected Underflow offset %u, to_get %u, buffer size %u\n",
offset, to_get, buffer->size_bytes); offset, to_get, buffer->size_bytes);
return underflow; return underflow;
} }
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "../rc.h" #include <glib.h>
#include "rc.h"
#include "buffers.h" #include "buffers.h"
#include "file.h" #include "file.h"
...@@ -22,7 +24,7 @@ int file_read_dump(buffer_t **buffer, const char *filename) ...@@ -22,7 +24,7 @@ int file_read_dump(buffer_t **buffer, const char *filename)
return RC_BAD_PARAM; return RC_BAD_PARAM;
if ((fd = open(filename, O_RDONLY)) == -1) { if ((fd = open(filename, O_RDONLY)) == -1) {
fprintf(stderr, "Cannot open %s for reading, returned %d:%s\n", g_debug("Cannot open %s for reading, returned %d:%s\n",
filename, errno, strerror(errno)); filename, errno, strerror(errno));
return RC_FAIL; return RC_FAIL;
} }
...@@ -33,7 +35,7 @@ int file_read_dump(buffer_t **buffer, const char *filename) ...@@ -33,7 +35,7 @@ int file_read_dump(buffer_t **buffer, const char *filename)
current_read = read(fd, data, READ_BUFFER_SIZE); current_read = read(fd, data, READ_BUFFER_SIZE);
if (current_read == -1) if (current_read == -1)
{ {
fprintf(stderr, "Failed to read data from file, returned %d:%s\n", g_debug("Failed to read data from file, returned %d:%s\n",
errno, strerror(errno)); errno, strerror(errno));
return RC_FAIL; return RC_FAIL;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "../rc.h" #include "rc.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "ui_notifications.h" #include "ui_notifications.h"
......
AM_CFLAGS = \ AM_CFLAGS = \
@ADD_CFLAGS@ \ @ADD_CFLAGS@ \
-I$(top_srcdir) \ -I$(top_srcdir)/common \
-I$(top_srcdir)/libbuffers \ -I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libui -I$(top_srcdir)/libui
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "../rc.h" #include "rc.h"
#include "field_type.h" #include "field_type.h"
#include "buffers.h" #include "buffers.h"
......
#include "../rc.h" #include "rc.h"
#include "types.h" #include "types.h"
#ifndef XML_PARSE_H_ #ifndef XML_PARSE_H_
......
AM_CFLAGS = \ AM_CFLAGS = \
@ADD_CFLAGS@ \ @ADD_CFLAGS@ \
-I$(top_srcdir) \ -I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \ -I$(top_srcdir)/libparser \
-I$(top_srcdir)/libbuffers -I$(top_srcdir)/libbuffers
......
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../rc.h" #include <glib.h>
#include "rc.h"
#include "types.h" #include "types.h"
#include "locate_root.h" #include "locate_root.h"
...@@ -13,15 +15,15 @@ int locate_root(const char *root_name, types_t *head, types_t **root) { ...@@ -13,15 +15,15 @@ int locate_root(const char *root_name, types_t *head, types_t **root) {
* This element is the entry for other sub-types. * This element is the entry for other sub-types.
*/ */
if (!root_name || (strlen (root_name) == 0)) { if (!root_name || (strlen (root_name) == 0)) {
printf ("FATAL: no root element name provided\n"); g_warning("FATAL: no root element name provided");
return -1; return -1;
} }
if (!head) { if (!head) {
printf ("Empty list detected\n"); g_warning("Empty list detected");
return -1; return -1;
} }
if (!root) { if (!root) {
printf ("NULL root reference\n"); g_warning("NULL root reference");
return -1; return -1;
} }
...@@ -44,11 +46,11 @@ int locate_type(const char *type_name, types_t *head, types_t **type) { ...@@ -44,11 +46,11 @@ int locate_type(const char *type_name, types_t *head, types_t **type) {
* This element is the entry for other sub-types. * This element is the entry for other sub-types.
*/ */
if (!type_name) { if (!type_name) {
printf ("FATAL: no root element name provided\n"); g_warning("FATAL: no root element name provided");
return RC_BAD_PARAM; return RC_BAD_PARAM;
} }
if (!head) { if (!head) {
printf ("Empty list detected\n"); g_warning("Empty list detected");
return RC_BAD_PARAM; return RC_BAD_PARAM;
} }
......
#include <stdio.h>
#include <string.h>
#include "types.h"
int resolve_typedefs(types_t **head)
{
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
return -1;
}
for (next_type = head; next_type; next_type = next_type->next)
{
/* Only resolve typedef */
if (next_type->type != TYPE_TYPEDEF)
continue;
printf("Trying to resolve typedef %s\n", next_type->name);
}
return 0;
}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <glib.h>
#include "types.h" #include "types.h"
#include "resolvers.h" #include "resolvers.h"
...@@ -17,7 +19,7 @@ int search_id(types_t *head, types_t **found, int id) ...@@ -17,7 +19,7 @@ int search_id(types_t *head, types_t **found, int id)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -37,7 +39,7 @@ int search_file(types_t *head, types_t **found, int file_id) ...@@ -37,7 +39,7 @@ int search_file(types_t *head, types_t **found, int file_id)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -59,7 +61,7 @@ int resolve_typedefs(types_t **head) ...@@ -59,7 +61,7 @@ int resolve_typedefs(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -86,7 +88,7 @@ int resolve_struct(types_t **head) ...@@ -86,7 +88,7 @@ int resolve_struct(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -144,7 +146,7 @@ int resolve_union(types_t **head) ...@@ -144,7 +146,7 @@ int resolve_union(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -194,7 +196,7 @@ int resolve_pointer_type(types_t **head) ...@@ -194,7 +196,7 @@ int resolve_pointer_type(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -221,7 +223,7 @@ int resolve_reference(types_t **head) ...@@ -221,7 +223,7 @@ int resolve_reference(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -248,7 +250,7 @@ int resolve_field(types_t **head) ...@@ -248,7 +250,7 @@ int resolve_field(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -275,7 +277,7 @@ int resolve_array(types_t **head) ...@@ -275,7 +277,7 @@ int resolve_array(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
...@@ -302,7 +304,7 @@ int resolve_file(types_t **head) ...@@ -302,7 +304,7 @@ int resolve_file(types_t **head)
types_t *next_type; types_t *next_type;
if (!head) { if (!head) {
printf("Empty list detected\n"); g_warning("Empty list detected");
return RESOLV_LIST_EMPTY; return RESOLV_LIST_EMPTY;
} }
......
AM_CFLAGS = \ AM_CFLAGS = \
@ADD_CFLAGS@ \ @ADD_CFLAGS@ \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libbuffers \ -I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libparser -I$(top_srcdir)/libparser
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "../rc.h" #include "rc.h"
#include "ui_main_screen.h" #include "ui_main_screen.h"
#include "ui_callbacks.h" #include "ui_callbacks.h"
...@@ -16,7 +16,7 @@ gboolean ui_callback_on_open(GtkWidget *widget, ...@@ -16,7 +16,7 @@ gboolean ui_callback_on_open(GtkWidget *widget,
GdkEvent *event, GdkEvent *event,
gpointer data) gpointer data)
{ {
g_print ("Open event occurred\n"); g_debug("Open event occurred");
CHECK_FCT(ui_file_chooser()); CHECK_FCT(ui_file_chooser());
return TRUE; return TRUE;
} }
...@@ -61,7 +61,7 @@ ui_callback_on_select_signal(GtkTreeSelection *selection, ...@@ -61,7 +61,7 @@ ui_callback_on_select_signal(GtkTreeSelection *selection,
} }
else else
{ {
g_print ("%s is going to be unselected.\n", name); g_debug("%s is going to be unselected", name);
} }
g_free(name); g_free(name);
...@@ -77,7 +77,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget, ...@@ -77,7 +77,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget,
uint16_t port; uint16_t port;
const char *ip; const char *ip;
g_print ("Connect event occurred\n"); 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.portentry)));
ip = gtk_entry_get_text(GTK_ENTRY(ui_main_data.ipentry)); ip = gtk_entry_get_text(GTK_ENTRY(ui_main_data.ipentry));
...@@ -94,7 +94,7 @@ gboolean ui_callback_on_disconnect(GtkWidget *widget, ...@@ -94,7 +94,7 @@ gboolean ui_callback_on_disconnect(GtkWidget *widget,
{ {
/* We have to retrieve the ip address and port of remote host */ /* We have to retrieve the ip address and port of remote host */
g_print ("Disconnect event occurred\n"); g_debug("Disconnect event occurred");
ui_interface.socket_disconnect(); ui_interface.socket_disconnect();
return TRUE; return TRUE;
} }
...@@ -104,8 +104,7 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget, ...@@ -104,8 +104,7 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget,
gpointer data) gpointer data)
{ {
/* We have to retrieve the ip address and port of remote host */ /* We have to retrieve the ip address and port of remote host */
g_debug("List selection event occurred");
g_print ("List selection event occurred\n");
return TRUE; return TRUE;
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "../rc.h" #include "rc.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "ui_main_screen.h" #include "ui_main_screen.h"
...@@ -26,20 +26,8 @@ int ui_gtk_initialize(int argc, char *argv[]) ...@@ -26,20 +26,8 @@ int ui_gtk_initialize(int argc, char *argv[])
memset(&ui_main_data, 0, sizeof(ui_main_data_t)); memset(&ui_main_data, 0, sizeof(ui_main_data_t));
if (!g_thread_supported())
g_thread_init(NULL);
/* Secure gtk */
gdk_threads_init();
/* Obtain gtk's global lock */
gdk_threads_enter();