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

- 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 = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libresolver \
-I$(top_srcdir)/libbuffers \
......
......@@ -16,10 +16,76 @@
int debug_buffers = 1;
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 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));
return ret;
......
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libui
......
......@@ -3,7 +3,9 @@
#include <stdio.h>
#include <string.h>
#include "../rc.h"
#include <glib.h>
#include "rc.h"
#include "buffers.h"
extern int debug_buffers;
......@@ -57,7 +59,7 @@ int buffer_fetch(buffer_t *buffer, uint32_t offset, int size, void *value)
return -1;
if (buffer->size_bytes < ((offset >> 3) + size)) {
printf("Not enough data to fetch\n");
g_debug("Not enough data to fetch");
return -1;
}
......@@ -190,8 +192,8 @@ int buffer_has_enouch_data(buffer_t *buffer, uint32_t offset, uint32_t to_get)
return -1;
underflow = (buffer->size_bytes >= ((offset + to_get) / 8)) ? 0 : -1;
if (underflow && debug_buffers)
printf("Detected Underflow offset %u, to_get %u, buffer size %u\n",
offset, to_get, buffer->size_bytes);
g_debug("Detected Underflow offset %u, to_get %u, buffer size %u\n",
offset, to_get, buffer->size_bytes);
return underflow;
}
......
......@@ -5,7 +5,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "../rc.h"
#include <glib.h>
#include "rc.h"
#include "buffers.h"
#include "file.h"
......@@ -22,7 +24,7 @@ int file_read_dump(buffer_t **buffer, const char *filename)
return RC_BAD_PARAM;
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));
return RC_FAIL;
}
......@@ -33,7 +35,7 @@ int file_read_dump(buffer_t **buffer, const char *filename)
current_read = read(fd, data, READ_BUFFER_SIZE);
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));
return RC_FAIL;
}
......
......@@ -8,7 +8,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_interface.h"
#include "ui_notifications.h"
......
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libui
......
......@@ -3,7 +3,7 @@
#include <assert.h>
#include <string.h>
#include "../rc.h"
#include "rc.h"
#include "field_type.h"
#include "buffers.h"
......
#include "../rc.h"
#include "rc.h"
#include "types.h"
#ifndef XML_PARSE_H_
......
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir) \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libparser \
-I$(top_srcdir)/libbuffers
......
#include <stdio.h>
#include <string.h>
#include "../rc.h"
#include <glib.h>
#include "rc.h"
#include "types.h"
#include "locate_root.h"
......@@ -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.
*/
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;
}
if (!head) {
printf ("Empty list detected\n");
g_warning("Empty list detected");
return -1;
}
if (!root) {
printf ("NULL root reference\n");
g_warning("NULL root reference");
return -1;
}
......@@ -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.
*/
if (!type_name) {
printf ("FATAL: no root element name provided\n");
g_warning("FATAL: no root element name provided");
return RC_BAD_PARAM;
}
if (!head) {
printf ("Empty list detected\n");
g_warning("Empty list detected");
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 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "types.h"
#include "resolvers.h"
......@@ -17,7 +19,7 @@ int search_id(types_t *head, types_t **found, int id)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -37,7 +39,7 @@ int search_file(types_t *head, types_t **found, int file_id)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -59,7 +61,7 @@ int resolve_typedefs(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -86,7 +88,7 @@ int resolve_struct(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -144,7 +146,7 @@ int resolve_union(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -194,7 +196,7 @@ int resolve_pointer_type(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -221,7 +223,7 @@ int resolve_reference(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -248,7 +250,7 @@ int resolve_field(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -275,7 +277,7 @@ int resolve_array(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......@@ -302,7 +304,7 @@ int resolve_file(types_t **head)
types_t *next_type;
if (!head) {
printf("Empty list detected\n");
g_warning("Empty list detected");
return RESOLV_LIST_EMPTY;
}
......
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/common \
-I$(top_srcdir)/libbuffers \
-I$(top_srcdir)/libparser
......
......@@ -3,7 +3,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_main_screen.h"
#include "ui_callbacks.h"
......@@ -16,7 +16,7 @@ gboolean ui_callback_on_open(GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
g_print ("Open event occurred\n");
g_debug("Open event occurred");
CHECK_FCT(ui_file_chooser());
return TRUE;
}
......@@ -61,7 +61,7 @@ ui_callback_on_select_signal(GtkTreeSelection *selection,
}
else
{
g_print ("%s is going to be unselected.\n", name);
g_debug("%s is going to be unselected", name);
}
g_free(name);
......@@ -77,7 +77,7 @@ gboolean ui_callback_on_connect(GtkWidget *widget,
uint16_t port;
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)));
ip = gtk_entry_get_text(GTK_ENTRY(ui_main_data.ipentry));
......@@ -94,7 +94,7 @@ gboolean ui_callback_on_disconnect(GtkWidget *widget,
{
/* 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();
return TRUE;
}
......@@ -104,8 +104,7 @@ gboolean ui_callback_on_tree_view_select(GtkWidget *widget,
gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
g_print ("List selection event occurred\n");
g_debug("List selection event occurred");
return TRUE;
}
......@@ -9,7 +9,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_interface.h"
#include "ui_main_screen.h"
......@@ -26,20 +26,8 @@ int ui_gtk_initialize(int argc, char *argv[])
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();
/* Initialize the widget set */
gtk_init(&argc, &argv);
/* Create the main window */
ui_main_data.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
ui_main_data.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
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);
......
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_main_screen.h"
#include "ui_menu_bar.h"
#include "ui_callbacks.h"
......
......@@ -6,7 +6,7 @@
#include <stdint.h>
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_notebook.h"
#include "ui_tree_view.h"
......
......@@ -4,7 +4,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_interface.h"
#include "ui_main_screen.h"
......
......@@ -2,7 +2,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_main_screen.h"
#include "ui_menu_bar.h"
......
......@@ -3,7 +3,7 @@
#include <gtk/gtk.h>
#include "../rc.h"
#include "rc.h"
#include "ui_main_screen.h"
#include "ui_tree_view.h"
......
This diff is collapsed.
#include <errno.h>
#include <string.h>
#ifndef RC_H_
#define RC_H_
#define RC_OK 0
#define RC_FAIL -1
#define RC_BAD_PARAM -2
#define RC_NULL_POINTER -3
#define CHECK_FCT(fCT) \
do { \
int rET; \
if ((rET = fCT) != RC_OK) { \
fprintf(stderr, #fCT" has failed (%s:%d)\n", __FILE__, __LINE__); \
return rET; \
} \
} while(0)
#define CHECK_FCT_POSIX(fCT) \
do { \
if (fCT == -1) { \
fprintf(stderr, #fCT" has failed (%d:%s) (%s:%d)\n", errno, \
strerror(errno), __FILE__, __LINE__); \
return RC_FAIL; \
} \
} while(0)
#define CHECK_FCT_DO(fCT, dO) \
do { \
int rET; \
if ((rET = fCT) != RC_OK) { \
fprintf(stderr, #fCT" has returned %d (%s:%d)\n", rET, __FILE__, __LINE__); \
dO; \
} \
} while(0)
#define CHECK_BUFFER(bUFFER) \
do { \
if ((bUFFER) == NULL) { \
fprintf(stderr, #bUFFER" is NULL (%s:%d)\n", __FILE__, __LINE__); \
return RC_NULL_POINTER; \
} \
} while(0)
#endif /* RC_H_ */
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