Apply TmaxWindow's log style
authorjaehoon01.jeong <jaehoon01.jeong@samsung.com>
Tue, 10 Mar 2015 13:33:50 +0000 (22:33 +0900)
committerTaekyun Kim <tkq.kim@samsung.com>
Fri, 19 Jun 2015 09:06:39 +0000 (18:06 +0900)
    - usage
    - must be declare 'DECLARE_DEBUG_CHANNEL(module_name);' at ahead of files
        "Syntax of the DEBUGCH variable:\n"
         "  DEBUGCH=[class]+xxx,[class]-yyy,...\n\n"
         "Example: DEBUGCH=+all,warn-heap\n"
         "    turns on all messages except warning heap messages\n"
         "Available message classes: err, warn, fixme, trace\n";

Change-Id: Iaeb88a81c9884481216a13c929f9b12b7806ae3f

src/Makefile.am
src/compositor.c
src/debug_ch.c [new file with mode: 0644]
src/debug_ch.h [new file with mode: 0644]
src/input.c
src/log.c [new file with mode: 0644]
src/modules/input_libinput.c
src/shell.c
src/surface.c

index a857d2a..2bd5cf0 100644 (file)
@@ -7,16 +7,18 @@ module_LTLIBRARIES =
 lib_LTLIBRARIES += libpepper.la
 libpepper_la_CFLAGS = $(PEPPER_CFLAGS) -DMODULEDIR='"$(moduledir)"'
 libpepper_la_LIBADD = $(PEPPER_LIBS)
-libpepper_la_SOURCES = pepper.h                        \
-                      pepper_internal.h        \
-                      common.h                 \
-                      common.c                 \
-                      compositor.c             \
-                      output.c                 \
-                      input.c                  \
-                      client.c                 \
-                      shell.c                  \
-                      surface.c
+libpepper_la_SOURCES = pepper.h                 \
+                       pepper_internal.h        \
+                       common.h                 \
+                       common.c                 \
+                       compositor.c             \
+                       output.c                 \
+                       input.c                  \
+                       client.c                 \
+                       shell.c                  \
+                       surface.c                \
+                       debug_ch.c               \
+                       log.c
 
 # input module library
 module_LTLIBRARIES += input_libinput.la
index a3b83c6..00f6472 100644 (file)
@@ -1,4 +1,7 @@
 #include "pepper_internal.h"
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(compositor);
 
 extern const struct wl_surface_interface surface_implementation;
 
@@ -23,12 +26,12 @@ compositor_create_surface(struct wl_client   *client,
     pepper_compositor_t *compositor = wl_resource_get_user_data(resource);
     pepper_surface_t    *surface;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     surface = (pepper_surface_t *)pepper_calloc(1, sizeof(pepper_surface_t));
     if (!surface)
     {
-        PEPPER_ERROR("%s Surface memory allocation failed\n", __FUNCTION__);
+        ERR("Surface memory allocation failed\n");
         wl_resource_post_no_memory(resource);
     }
 
@@ -36,7 +39,7 @@ compositor_create_surface(struct wl_client   *client,
                                            wl_resource_get_version(resource), id);
     if (!surface->resource)
     {
-        PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__);
+        ERR("wl_resource_create failed\n");
         pepper_free(surface);
         wl_resource_post_no_memory(resource);
         return ;
@@ -50,7 +53,7 @@ compositor_create_region(struct wl_client   *client,
                          struct wl_resource *resource,
                          uint32_t            id)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static const struct wl_compositor_interface compositor_interface =
@@ -68,17 +71,17 @@ bind_compositor(struct wl_client *client,
     pepper_compositor_t *compositor = (pepper_compositor_t *)data;
     struct wl_resource  *resource;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     resource = wl_resource_create(client, &wl_compositor_interface, version, id);
     if (!resource)
     {
-        PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__);
+        ERR("wl_resource_create failed\n");
 
         wl_client_post_no_memory(client);
         return;
     }
-    PEPPER_TRACE("%s wl_resource_create success\n", __FUNCTION__);
+    TRACE("wl_resource_create success\n");
 
     wl_resource_set_implementation(resource, &compositor_interface, compositor, NULL);
 }
@@ -92,6 +95,9 @@ pepper_compositor_create(const char *socket_name,
 {
     pepper_compositor_t *compositor = NULL;
 
+
+    pepper_log_init(NULL);  /* log filename, NULL is stderr */
+
     compositor = (pepper_compositor_t *)pepper_calloc(1, sizeof (pepper_compositor_t));
 
     if (!compositor)
@@ -101,13 +107,13 @@ pepper_compositor_create(const char *socket_name,
 
     if (!compositor->display)
     {
-        PEPPER_ERROR("Failed to create wayland display object.\n");
+        ERR("Failed to create wayland display object.\n");
         goto error;
     }
 
     if (wl_display_add_socket(compositor->display, socket_name) != 0)
     {
-        PEPPER_ERROR("Failed to add socket display = %p socket_name = %s\n",
+        ERR("Failed to add socket display = %p socket_name = %s\n",
                      compositor->display, socket_name);
         goto error;
     }
diff --git a/src/debug_ch.c b/src/debug_ch.c
new file mode 100644 (file)
index 0000000..f054b79
--- /dev/null
@@ -0,0 +1,504 @@
+/**
+ * @file        debug_ch.c
+ * @brief       Management of the debugging channels
+ *
+ * @author
+ * @date
+ * @attention
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+#include <unistd.h>
+#include <features.h>
+# include <sys/types.h>
+# include <sys/utsname.h>
+
+#include "debug_ch.h"
+
+#if defined(__thumb__) && !defined(__thumb2__)
+#  define  __ATOMIC_SWITCH_TO_ARM \
+            "adr r3, 5f\n" \
+            "bx  r3\n" \
+            ".align\n" \
+            ".arm\n" \
+            "5:\n"
+/* note: the leading \n below is intentional */
+#  define __ATOMIC_SWITCH_TO_THUMB \
+            "\n" \
+            "adr r3, 6f\n" \
+            "bx  r3\n" \
+            ".thumb" \
+            "6:\n"
+
+#  define __ATOMIC_CLOBBERS   "r3"  /* list of clobbered registers */
+
+#  warning Rebuilding this source file in ARM mode is highly recommended for performance!!
+
+#else
+#  define  __ATOMIC_SWITCH_TO_ARM   /* nothing */
+#  define  __ATOMIC_SWITCH_TO_THUMB /* nothing */
+#  define  __ATOMIC_CLOBBERS        /* nothing */
+#endif
+
+
+static inline int
+interlocked_xchg_add( int *dest, int incr )
+{
+#if defined (__i386__) || defined (__x86_64__)
+    int ret;
+    __asm__ __volatile__( "lock; xaddl %0,(%1)"
+                          : "=r" (ret)
+                          : "r" (dest), "0" (incr)
+                          : "memory" );
+    return ret;
+#elif defined (__arm__)
+    int ret, tmp, status;
+    do {
+        __asm__ __volatile__ (
+            __ATOMIC_SWITCH_TO_ARM
+            "ldrex %0, [%4]\n"
+            "add %1, %0, #1\n"
+            "strex %2, %1, [%4]"
+            __ATOMIC_SWITCH_TO_THUMB
+            : "=&r" (ret), "=&r" (tmp), "=&r" (status), "+m"(*dest)
+            : "r" (dest)
+            : __ATOMIC_CLOBBERS "cc");
+    } while (__builtin_expect(status != 0, 0));
+    return ret;
+#else
+#       warning "unknown platform!!"
+#endif
+}
+
+
+static const char * const debug_classes[] = {"fixme", "err", "warn", "trace", "info"};
+
+#define MAX_DEBUG_OPTIONS 256
+
+/*
+static unsigned char default_flags = (1 << __DBCL_ERR) | (1 << __DBCL_FIXME) | (1 << __DBCL_INFO);
+*/
+static unsigned char default_flags = (1 << __DBCL_ERR)  | (1 << __DBCL_INFO);
+static int nb_debug_options = -1;
+static struct _debug_channel debug_options[MAX_DEBUG_OPTIONS];
+
+static void
+debug_init(void);
+
+static int
+cmp_name(const void *p1, const void *p2)
+{
+    const char *name = p1;
+    const struct _debug_channel *chan = p2;
+    return strcmp( name, chan->name );
+}
+
+/* get the flags to use for a given channel, possibly setting them too in case of lazy init */
+unsigned char
+_dbg_get_channel_flags( struct _debug_channel *channel )
+{
+    if (nb_debug_options == -1)
+        debug_init();
+
+    if(nb_debug_options)
+    {
+        struct _debug_channel *opt;
+
+        /* first check for multi channel */
+        opt = bsearch( channel->multiname,
+                       debug_options,
+                       nb_debug_options,
+                       sizeof(debug_options[0]), cmp_name );
+        if (opt)
+            return opt->flags;
+
+        opt = bsearch( channel->name,
+                       debug_options,
+                       nb_debug_options,
+                       sizeof(debug_options[0]), cmp_name );
+        if (opt)
+            return opt->flags;
+    }
+
+    /* no option for this channel */
+    if (channel->flags & (1 << __DBCL_INIT))
+        channel->flags = default_flags;
+
+    return default_flags;
+}
+
+/* set the flags to use for a given channel; return 0 if the channel is not available to set */
+int
+_dbg_set_channel_flags(struct _debug_channel *channel,
+                       unsigned char          set,
+                       unsigned char          clear )
+{
+    if (nb_debug_options == -1)
+        debug_init();
+
+    if (nb_debug_options)
+    {
+        struct _debug_channel *opt;
+
+        /* first set for multi channel */
+        opt = bsearch( channel->multiname,
+                       debug_options,
+                       nb_debug_options,
+                       sizeof(debug_options[0]), cmp_name );
+        if (opt)
+        {
+            opt->flags = (opt->flags & ~clear) | set;
+            return 1;
+        }
+
+        opt = bsearch( channel->name,
+                       debug_options,
+                       nb_debug_options,
+                       sizeof(debug_options[0]), cmp_name );
+        if (opt)
+        {
+            opt->flags = (opt->flags & ~clear) | set;
+            return 1;
+        }
+    }
+    return 0;
+}
+
+/* add a new debug option at the end of the option list */
+static void
+add_option( const char *name, unsigned char set, unsigned char clear )
+{
+    int min = 0, max = nb_debug_options - 1, pos, res;
+
+    if (!name[0])  /* "all" option */
+    {
+        default_flags = (default_flags & ~clear) | set;
+        return;
+    }
+
+    if (strlen(name) >= sizeof(debug_options[0].name))
+        return;
+
+    while (min <= max)
+    {
+        pos = (min + max) / 2;
+        res = strcmp( name, debug_options[pos].name );
+        if (!res)
+        {
+            debug_options[pos].flags = (debug_options[pos].flags & ~clear) | set;
+            return;
+        }
+        if (res < 0)
+            max = pos - 1;
+        else
+            min = pos + 1;
+    }
+    if (nb_debug_options >= MAX_DEBUG_OPTIONS)
+        return;
+
+    pos = min;
+    if (pos < nb_debug_options)
+    {
+        memmove( &debug_options[pos + 1],
+                 &debug_options[pos],
+                 (nb_debug_options - pos) * sizeof(debug_options[0]) );
+    }
+
+    strcpy( debug_options[pos].name, name );
+    debug_options[pos].flags = (default_flags & ~clear) | set;
+    nb_debug_options++;
+}
+
+/* parse a set of debugging option specifications and add them to the option list */
+static void
+parse_options( const char *str )
+{
+    char *opt, *next, *options;
+    unsigned int i;
+
+    if (!(options = strdup(str)))
+        return;
+    for (opt = options; opt; opt = next)
+    {
+        const char *p;
+        unsigned char set = 0, clear = 0;
+
+        if ((next = strchr( opt, ',' )))
+            *next++ = 0;
+
+        p = opt + strcspn( opt, "+-" );
+        if (!p[0])
+            p = opt;  /* assume it's a debug channel name */
+
+        if (p > opt)
+        {
+            for (i = 0; i < sizeof(debug_classes)/sizeof(debug_classes[0]); i++)
+            {
+                int len = strlen(debug_classes[i]);
+                if (len != (p - opt))
+                    continue;
+                if (!memcmp( opt, debug_classes[i], len ))  /* found it */
+                {
+                    if (*p == '+')
+                        set |= 1 << i;
+                    else
+                        clear |= 1 << i;
+                    break;
+                }
+            }
+            if (i == sizeof(debug_classes)/sizeof(debug_classes[0])) /* bad class name, skip it */
+                continue;
+        }
+        else
+        {
+            if (*p == '-')
+                clear = ~0;
+            else
+                set = ~0;
+        }
+        if (*p == '+' || *p == '-')
+            p++;
+        if (!p[0])
+            continue;
+
+        if (!strcmp( p, "all" ))
+            default_flags = (default_flags & ~clear) | set;
+        else
+            add_option( p, set, clear );
+    }
+    free( options );
+}
+
+/* print the usage message */
+static void
+debug_usage(void)
+{
+    static const char usage[] =
+        "Syntax of the DEBUGCH variable:\n"
+        "  DEBUGCH=[class]+xxx,[class]-yyy,...\n\n"
+        "Example: DEBUGCH=+all,warn-heap\n"
+        "    turns on all messages except warning heap messages\n"
+        "Available message classes: err, warn, fixme, trace\n";
+    const int ret = write( 2, usage, sizeof(usage) - 1 );
+    assert(ret >= 0);
+    exit(1);
+}
+
+/* initialize all options at startup */
+static void
+debug_init(void)
+{
+    char *debug = NULL;
+    FILE *fp = NULL;
+    char *tmp = NULL;
+
+    if (nb_debug_options != -1)
+        return;  /* already initialized */
+
+    nb_debug_options = 0;
+
+    fp= fopen("DEBUGCH", "r");
+    if( fp == NULL)
+    {
+        debug = getenv("DEBUGCH");
+    }
+    else
+    {
+        if ((tmp= (char *)malloc(1024 + 1)) == NULL)
+        {
+            fclose(fp);
+            return;
+        }
+
+        fseek(fp, 0, SEEK_SET);
+        const char* str = fgets(tmp, 1024, fp);
+        if (str)
+        {
+            tmp[strlen(tmp)-1] = 0;
+            debug = tmp;
+        }
+
+        fclose(fp);
+    }
+
+    if( debug != NULL )
+    {
+        if (!strcmp( debug, "help" ))
+            debug_usage();
+        parse_options( debug );
+    }
+
+    if( tmp != NULL )
+    {
+        free(tmp);
+    }
+}
+
+/* allocate some tmp string space */
+/* FIXME: this is not 100% thread-safe */
+char *
+get_dbg_temp_buffer( size_t size )
+{
+    static char *list[32];
+    static int pos;
+    char *ret;
+    int idx;
+
+    idx = interlocked_xchg_add( &pos, 1 ) % (sizeof(list)/sizeof(list[0]));
+
+    if ((ret = realloc( list[idx], size )))
+        list[idx] = ret;
+
+    return ret;
+}
+
+/* release unused part of the buffer */
+void
+release_dbg_temp_buffer( char *buffer, size_t size )
+{
+    /* don't bother doing anything */
+    (void)( buffer );
+    (void)( size );
+}
+
+/* jjh */
+static FILE* logfile = NULL;
+void
+dbg_set_logfile(const char* filename)
+{
+    if (filename)
+        logfile = fopen(filename, "a");
+
+    if (logfile == NULL)
+        logfile = stderr;
+    else
+        setvbuf(logfile, NULL, _IOLBF, 256);     /* block buffered -> line buffered */
+}
+
+static int
+dbg_vprintf( const char *format, va_list args )
+{
+#if 0
+    int ret = vfprintf( stdout, format, args );
+    fflush(stdout);
+#else
+    int ret = vfprintf( logfile, format, args );
+    fflush(logfile);
+#endif
+    return ret;
+}
+
+int dbg_printf( const char *format, ... )
+{
+    int ret;
+    va_list valist;
+
+    /* lock */
+
+    va_start(valist, format);
+    ret = dbg_vprintf( format, valist );
+    va_end(valist);
+
+    /* unlock */
+
+    return ret;
+}
+
+int
+dbg_printf_nonewline( const char *format, ... )
+{
+    int ret;
+    va_list valist;
+
+    va_start(valist, format);
+    ret = dbg_vprintf( format, valist );
+    va_end(valist);
+
+    return ret;
+}
+
+/* printf with temp buffer allocation */
+const char *
+dbg_sprintf( const char *format, ... )
+{
+    static const int max_size = 200;
+    char *ret;
+    int len;
+    va_list valist;
+
+    va_start(valist, format);
+    ret = get_dbg_temp_buffer( max_size );
+    len = vsnprintf( ret, max_size, format, valist );
+    if (len == -1 || len >= max_size)
+        ret[max_size-1] = 0;
+    else
+        release_dbg_temp_buffer( ret, len + 1 );
+    va_end(valist);
+    return ret;
+}
+
+/* default implementation of dbg_vlog */
+static int
+dbg_vlog(enum _debug_class      cls,
+         struct _debug_channel *channel,
+         const char            *func,
+         const char            *format,
+         va_list                args )
+{
+    int ret = 0;
+
+    if (cls < sizeof(debug_classes)/sizeof(debug_classes[0]))
+    {
+        (void)(channel);
+        (void)(func);
+        /* to print debug class, channel */
+        ret += dbg_printf_nonewline("[%s:%s"
+                                    , debug_classes[cls] , channel->name);
+
+        if (*channel->multiname)
+            ret += dbg_printf_nonewline(":%s]", channel->multiname);
+        else
+            ret += dbg_printf_nonewline("]");
+    }
+    if (format)
+    {
+        ret += dbg_vprintf( format, args );
+    }
+    return ret;
+}
+
+int
+dbg_log(enum _debug_class      cls,
+        struct _debug_channel *channel,
+        const char            *func,
+        const char            *format,
+        ... )
+{
+    int ret;
+    va_list valist;
+
+    if (!(_dbg_get_channel_flags( channel ) & (1 << cls)))
+        return -1;
+
+    va_start(valist, format);
+    ret = dbg_vlog( cls, channel, func, format, valist );
+    va_end(valist);
+
+    return ret;
+}
+
+void
+assert_fail(char *exp, const char *file, int line)
+{
+    fprintf(stderr, "[%s][%d] Assert(%s) failed \n"
+            , file, line, exp);
+    fprintf(stdout, "[%s][%d] Assert(%s) failed \n"
+            , file, line, exp);
+    exit(0);
+}
+
+/* end of debug_ch.c */
diff --git a/src/debug_ch.h b/src/debug_ch.h
new file mode 100644 (file)
index 0000000..b62c23e
--- /dev/null
@@ -0,0 +1,143 @@
+/**
+ * @file       debug_ch.h
+ * @brief      Management of the debugging channels
+ *
+ * @author
+ * @date
+ * @attention
+ */
+
+#ifndef __DEBUGCHANNEL_H
+#define __DEBUGCHANNEL_H
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum _debug_class
+{
+       __DBCL_FIXME,
+       __DBCL_ERR,
+       __DBCL_WARN,
+       __DBCL_TRACE,
+       __DBCL_INFO,
+
+       __DBCL_INIT = 7  /* lazy init flag */
+};
+
+struct _debug_channel
+{
+       unsigned char flags;
+       char name[15];
+       char multiname[15];
+};
+
+#ifndef NO_DEBUG
+#define __GET_DEBUGGING_FIXME(dbch) ((dbch)->flags & (1 << __DBCL_FIXME))
+#define __GET_DEBUGGING_ERR(dbch)   ((dbch)->flags & (1 << __DBCL_ERR))
+#define __GET_DEBUGGING_WARN(dbch)  ((dbch)->flags & (1 << __DBCL_WARN))
+#define __GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __DBCL_TRACE))
+#define __GET_DEBUGGING_INFO(dbch)  ((dbch)->flags & (1 << __DBCL_INFO))
+#else
+#define __GET_DEBUGGING_FIXME(dbch) 0
+#define __GET_DEBUGGING_ERR(dbch)   0
+#define __GET_DEBUGGING_WARN(dbch)  0
+#define __GET_DEBUGGING_TRACE(dbch) 0
+#define __GET_DEBUGGING_INFO(dbch)  0
+#endif
+
+#define __GET_DEBUGGING(dbcl,dbch)  __GET_DEBUGGING##dbcl(dbch)
+
+#define __IS_DEBUG_ON(dbcl,dbch) \
+       (__GET_DEBUGGING##dbcl(dbch) && \
+        (_dbg_get_channel_flags(dbch) & (1 << __DBCL##dbcl)))
+
+#define __DPRINTF(dbcl,dbch) \
+       (!__GET_DEBUGGING(dbcl,(dbch)) || \
+        (dbg_log(__DBCL##dbcl,(dbch),__FILE__, \
+                                  "[%s:%d] ", __FUNCTION__, __LINE__) == -1)) ? \
+(void)0 : (void)dbg_printf
+
+extern unsigned char
+_dbg_get_channel_flags( struct _debug_channel *channel );
+extern int
+_dbg_set_channel_flags( struct _debug_channel *channel,
+                        unsigned char set,
+                        unsigned char clear );
+
+extern const char *
+dbg_sprintf( const char *format, ... );
+
+extern int
+dbg_printf( const char *format, ... );
+
+extern int
+dbg_printf_nonewline( const char *format, ... );
+
+extern int
+dbg_log( enum _debug_class cls,
+         struct _debug_channel *ch,
+         const char *func,
+        const char *format,
+         ... );
+
+extern char *
+get_dbg_temp_buffer( size_t size );
+
+extern void
+release_dbg_temp_buffer( char *buffer, size_t size );
+
+#ifndef TRACE
+#define TRACE                 __DPRINTF(_TRACE,_dbch___default)
+#define TRACE_(ch)            __DPRINTF(_TRACE,&_dbch_##ch)
+#endif
+#define TRACE_ON(ch)          __IS_DEBUG_ON(_TRACE,&_dbch_##ch)
+
+#ifndef WARN
+#define WARN                  __DPRINTF(_WARN,_dbch___default)
+#define WARN_(ch)             __DPRINTF(_WARN,&_dbch_##ch)
+#endif
+#define WARN_ON(ch)           __IS_DEBUG_ON(_WARN,&_dbch_##ch)
+
+#ifndef FIXME
+#define FIXME                 __DPRINTF(_FIXME,_dbch___default)
+#define FIXME_(ch)            __DPRINTF(_FIXME,&_dbch_##ch)
+#endif
+#define FIXME_ON(ch)          __IS_DEBUG_ON(_FIXME,&_dbch_##ch)
+
+#define ERR                   __DPRINTF(_ERR,_dbch___default)
+#define ERR_(ch)              __DPRINTF(_ERR,&_dbch_##ch)
+#define ERR_ON(ch)            __IS_DEBUG_ON(_ERR,&_dbch_##ch)
+
+#ifndef INFO
+#define INFO                  __DPRINTF(_INFO,_dbch___default)
+#define INFO_(ch)             __DPRINTF(_INFO,&_dbch_##ch)
+#endif
+#define INFO_ON(ch)           __IS_DEBUG_ON(_INFO,&_dbch_##ch)
+
+#define DECLARE_DEBUG_CHANNEL(ch) \
+       static struct _debug_channel _dbch_##ch = { ~0, #ch, ""}; \
+static struct _debug_channel * const _dbch___default = &_dbch_##ch
+#define DEFAULT_DEBUG_CHANNEL(ch) \
+       static struct _debug_channel _dbch_##ch = { ~0, #ch, ""}; \
+static struct _debug_channel * const _dbch___default = &_dbch_##ch
+
+#define MULTI_DEBUG_CHANNEL(ch, chm) \
+       static struct _debug_channel _dbch_##ch = { ~0, #ch , #chm}; \
+static struct _debug_channel * const _dbch___default = &_dbch_##ch
+
+#define DPRINTF               dbg_printf
+#define MESSAGE               dbg_printf
+
+void assert_fail(char *exp, const char *file, int line);
+
+#define ASSERT(exp) if (exp) ;                                      \
+       else assert_fail( (char *)#exp, __FILE__, __LINE__ )
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __DEBUGCHANNEL_H */
index 0b4ebea..8802816 100644 (file)
@@ -1,5 +1,8 @@
 #include <dlfcn.h>
 #include "pepper_internal.h"
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(input);
 
 #define PATH_MAX_LEN 128
 int
@@ -62,28 +65,28 @@ pepper_seat_create()
     seat = (pepper_seat_t *)pepper_calloc(1, sizeof(pepper_seat_t));
     if (!seat)
     {
-        PEPPER_ERROR("%s Memory allocation failed\n", __FUNCTION__);
+        ERR("Memory allocation failed\n");
         goto err;
     }
 
     pointer = (pepper_pointer_t *)pepper_calloc(1, sizeof(pepper_pointer_t));
     if (!pointer)
     {
-        PEPPER_ERROR("%s Memory allocation failed\n", __FUNCTION__);
+        ERR("Memory allocation failed\n");
         goto err;
     }
 
     keyboard = (pepper_keyboard_t *)pepper_calloc(1, sizeof(pepper_keyboard_t));
     if (!keyboard)
     {
-        PEPPER_ERROR("%s Memory allocation failed\n", __FUNCTION__);
+        ERR("Memory allocation failed\n");
         goto err;
     }
 
     touch = (pepper_touch_t *)pepper_calloc(1, sizeof(pepper_touch_t));
     if (!touch)
     {
-        PEPPER_ERROR("%s Memory allocation failed\n", __FUNCTION__);
+        ERR("Memory allocation failed\n");
         goto err;
     }
 
@@ -110,28 +113,28 @@ static void
 pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial,
                    struct wl_resource *surface_resource, int32_t x, int32_t y)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
     /* TODO: */
 }
 
 static void
 pointer_release(struct wl_client *client, struct wl_resource *resource)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
     wl_resource_destroy(resource);
 }
 
 static void
 keyboard_release(struct wl_client *client, struct wl_resource *resource)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
     wl_resource_destroy(resource);
 }
 
 static void
 touch_release(struct wl_client *client, struct wl_resource *resource)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
     wl_resource_destroy(resource);
 }
 
@@ -157,7 +160,7 @@ seat_get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_
     pepper_seat_t       *seat = wl_resource_get_user_data(resource);
     pepper_pointer_t    *pointer = seat->pointer;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     pointer->resource = wl_resource_create(client, &wl_pointer_interface,
                                            wl_resource_get_version(resource), id);
@@ -178,7 +181,7 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32
     pepper_seat_t       *seat = wl_resource_get_user_data(resource);
     pepper_keyboard_t   *keyboard = seat->keyboard;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     keyboard->resource = wl_resource_create(client, &wl_keyboard_interface,
                                             wl_resource_get_version(resource), id);
@@ -199,7 +202,7 @@ seat_get_touch(struct wl_client *client, struct wl_resource *resource, uint32_t
     pepper_seat_t   *seat = wl_resource_get_user_data(resource);
     pepper_touch_t  *touch = seat->touch;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     touch->resource = wl_resource_create(client, &wl_touch_interface,
                                          wl_resource_get_version(resource), id);
@@ -227,7 +230,7 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
     pepper_seat_t           *seat = (pepper_seat_t *)data;
     enum wl_seat_capability caps = 0;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     seat->resource = wl_resource_create(client, &wl_seat_interface,
                                         (version < 4) ? version : 4, id);
diff --git a/src/log.c b/src/log.c
new file mode 100644 (file)
index 0000000..37401a2
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+#include <wayland-util.h>
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(libwayland);
+
+static void
+pepper_wayland_log_func(const char* format, va_list args)
+{
+#if 0
+    fprintf(stderr, "libwayland: ");
+    vfprintf(stderr, format, args);
+#else
+    ERR(format, args);
+#endif
+}
+
+void
+pepper_log_init(const char* filename)
+{
+    wl_log_set_handler_server(pepper_wayland_log_func);
+    dbg_set_logfile(filename);
+}
index 98612df..1807c69 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "common.h"
 #include "pepper_internal.h"
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(input);
 
 static int
 get_event_fd(void *data)
@@ -93,7 +96,7 @@ get_next_event(pepper_input_event_t *event, void *data)
         set_input_event_data_touch(event, li_event, type);
         break;
     default:
-        PEPPER_ERROR("%s Undefined event type!!\n", __FUNCTION__);
+        ERR("Undefined event type!!\n");
         return -1;
     }
 
@@ -128,19 +131,19 @@ module_init(pepper_compositor_t *compositor)
     struct udev     *udev;
     struct libinput *li;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     udev = udev_new();
     if (!udev)
     {
-        PEPPER_ERROR("%s udev_new failed\n", __FUNCTION__);
+        ERR("udev_new failed\n");
         goto err;
     }
 
     li = libinput_udev_create_context(&libinput_interface, NULL/* user_data */, udev);
     if (!li)
     {
-        PEPPER_ERROR("%s libinput_udev_create_context failed\n", __FUNCTION__);
+        ERR("libinput_udev_create_context failed\n");
         goto err;
     }
 
index b77e375..23bca5d 100644 (file)
@@ -1,4 +1,7 @@
 #include "pepper_internal.h"
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(shell);
 
 /* shell surface interface */
 static void
@@ -8,7 +11,7 @@ shell_surface_pong(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -19,7 +22,7 @@ shell_surface_move(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -31,7 +34,7 @@ shell_surface_resize(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -40,7 +43,7 @@ shell_surface_set_toplevel(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 
@@ -55,7 +58,7 @@ shell_surface_set_transient(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -67,7 +70,7 @@ shell_surface_set_fullscreen(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -82,7 +85,7 @@ shell_surface_set_popup(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -92,7 +95,7 @@ shell_surface_set_maximized(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 
@@ -103,7 +106,7 @@ shell_surface_set_title(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -113,7 +116,7 @@ shell_surface_set_class(struct wl_client   *client,
 {
     pepper_shell_surface_t *shsurface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static const struct wl_shell_surface_interface pepper_shell_surface_implementation =
@@ -141,13 +144,13 @@ shell_get_shell_surface(struct wl_client   *client,
     pepper_surface_t       *surface    = wl_resource_get_user_data(surface_resource);
     pepper_shell_surface_t *shsurface;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     shsurface = (pepper_shell_surface_t *)pepper_calloc(1, sizeof(pepper_shell_surface_t));
 
     if (!shsurface)
     {
-        PEPPER_ERROR("%s Shell surface memory allocation failed\n", __FUNCTION__);
+        ERR("Shell surface memory allocation failed\n");
         wl_client_post_no_memory(client);
         return ;
     }
@@ -156,7 +159,7 @@ shell_get_shell_surface(struct wl_client   *client,
                                              wl_resource_get_version(resource), id);
     if (!shsurface->resource)
     {
-        PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__);
+        ERR("wl_resource_create failed\n");
         pepper_free(shsurface);
         wl_client_post_no_memory(client);
         return ;
@@ -178,12 +181,12 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
     pepper_compositor_t *compositor = (pepper_compositor_t *)data;
     struct wl_resource  *resource;
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     resource = wl_resource_create(client, &wl_shell_interface, version, id);
     if (!resource)
     {
-        PEPPER_ERROR("%s wl_resource_create failed\n", __FUNCTION__);
+        ERR("wl_resource_create failed\n");
 
         wl_client_post_no_memory(client);
         return;
index 87d166f..64435a0 100644 (file)
@@ -1,4 +1,7 @@
 #include "pepper_internal.h"
+#include "debug_ch.h"
+
+DECLARE_DEBUG_CHANNEL(surface);
 
 void *
 pepper_surface_get_buffer(pepper_surface_t *surface)
@@ -10,7 +13,7 @@ pepper_surface_get_buffer(pepper_surface_t *surface)
 static void
 surface_destroy(struct wl_client *client, struct wl_resource *resource)
 {
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 
     wl_resource_destroy(resource);
 }
@@ -24,7 +27,7 @@ surface_attach(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -37,7 +40,7 @@ surface_damage(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -47,7 +50,7 @@ surface_frame(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -57,7 +60,7 @@ surface_set_opaque_region(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -67,7 +70,7 @@ surface_set_input_region(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -75,7 +78,7 @@ surface_commit(struct wl_client *client, struct wl_resource *resource)
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -85,7 +88,7 @@ surface_set_buffer_transform(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 static void
@@ -95,7 +98,7 @@ surface_set_buffer_scale(struct wl_client   *client,
 {
     pepper_surface_t *surface = wl_resource_get_user_data(resource);
 
-    PEPPER_TRACE("%s\n", __FUNCTION__);
+    TRACE("enter\n");
 }
 
 const struct wl_surface_interface surface_implementation =