genericopenlibs/liboil/src/liboildebug.h
changeset 31 ce057bb09d0b
parent 18 47c74d1534e1
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
       
     4  * All rights reserved.
       
     5  *
       
     6  * Redistribution and use in source and binary forms, with or without
       
     7  * modification, are permitted provided that the following conditions
       
     8  * are met:
       
     9  * 1. Redistributions of source code must retain the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer.
       
    11  * 2. Redistributions in binary form must reproduce the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer in the
       
    13  *    documentation and/or other materials provided with the distribution.
       
    14  * 
       
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
       
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
       
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
       
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    25  * POSSIBILITY OF SUCH DAMAGE.
       
    26  */
       
    27 
       
    28 #ifndef _LIBOIL_DEBUG_H_
       
    29 #define _LIBOIL_DEBUG_H_
       
    30 
       
    31 #include <stdarg.h>
       
    32 #include <liboil/liboilutils.h>
       
    33 
       
    34 OIL_BEGIN_DECLS
       
    35 
       
    36 #ifdef OIL_ENABLE_UNSTABLE_API
       
    37 
       
    38 /**
       
    39  * OilDebugPrintFunc:
       
    40  * @level: the debug level
       
    41  * @file: name of the file where the debug message occurs
       
    42  * @func: name of the function where the debug message occurs
       
    43  * @line: line in the file where the debug message occurs
       
    44  * @format: a printf format
       
    45  * @varargs: varargs for the printf format
       
    46  *
       
    47  * Typedef describing functions that can be registered using
       
    48  * oil_debug_set_print_function() so that it is called to
       
    49  * print debugging messages.
       
    50  */
       
    51 typedef void (*OilDebugPrintFunc) (int level, const char *file,
       
    52     const char *func, int line, const char *format, va_list varargs);
       
    53 
       
    54 /**
       
    55  * OilDebugLevel:
       
    56  *
       
    57  * Enumeration describing debug levels in Liboil.
       
    58  */
       
    59 typedef enum {
       
    60   OIL_DEBUG_NONE = 0,
       
    61   OIL_DEBUG_ERROR,
       
    62   OIL_DEBUG_WARNING,
       
    63   OIL_DEBUG_INFO,
       
    64   OIL_DEBUG_DEBUG,
       
    65   OIL_DEBUG_LOG
       
    66 } OilDebugLevel;
       
    67 
       
    68 /**
       
    69  * OIL_ERROR:
       
    70  *
       
    71  * Macro to call OIL_DEBUG_PRINT() with a level of #OIL_DEBUG_ERROR.
       
    72  */
       
    73 #define OIL_ERROR(args...) OIL_DEBUG_PRINT(OIL_DEBUG_ERROR, ##args)
       
    74 /**
       
    75  * OIL_WARNING:
       
    76  *
       
    77  * Macro to call OIL_DEBUG_PRINT() with a level of #OIL_DEBUG_WARNING.
       
    78  */
       
    79 #define OIL_WARNING(args...) OIL_DEBUG_PRINT(OIL_DEBUG_WARNING, ##args)
       
    80 /**
       
    81  * OIL_INFO:
       
    82  *
       
    83  * Macro to call OIL_DEBUG_PRINT() with a level of #OIL_DEBUG_INFO.
       
    84  */
       
    85 #define OIL_INFO(args...) OIL_DEBUG_PRINT(OIL_DEBUG_INFO, ##args)
       
    86 /**
       
    87  * OIL_DEBUG:
       
    88  *
       
    89  * Macro to call OIL_DEBUG_PRINT() with a level of #OIL_DEBUG_DEBUG.
       
    90  */
       
    91 #define OIL_DEBUG(args...) OIL_DEBUG_PRINT(OIL_DEBUG_DEBUG, ##args)
       
    92 /**
       
    93  * OIL_LOG:
       
    94  *
       
    95  * Macro to call OIL_DEBUG_PRINT() with a level of #OIL_DEBUG_LOG.
       
    96  */
       
    97 #define OIL_LOG(args...) OIL_DEBUG_PRINT(OIL_DEBUG_LOG, ##args)
       
    98 
       
    99 /**
       
   100  * OIL_FUNCTION:
       
   101  *
       
   102  * Internal macro that points to __PRETTY_FUNCTION__ or __func__
       
   103  * if the former is not available.
       
   104  */
       
   105 #if defined (__GNUC__) || defined (__PRETTY_FUNCTION__)
       
   106 #define OIL_FUNCTION __PRETTY_FUNCTION__
       
   107 #elif defined(__func__)
       
   108 #define OIL_FUNCTION __func__
       
   109 #else
       
   110 #define OIL_FUNCTION ""
       
   111 #endif
       
   112 
       
   113 /**
       
   114  * OIL_DEBUG_PRINT:
       
   115  * @level:
       
   116  * @...:
       
   117  *
       
   118  * Macro to call oil_debug_print() with the correct values for
       
   119  * the name of the source file, line of source file, and function.
       
   120  */
       
   121 #define OIL_DEBUG_PRINT(level, args...) do { \
       
   122   oil_debug_print((level), __FILE__, OIL_FUNCTION, __LINE__, ##args); \
       
   123 }while(0)
       
   124 
       
   125 IMPORT_C void oil_debug_set_print_function (OilDebugPrintFunc func);
       
   126 IMPORT_C int oil_debug_get_level (void);
       
   127 IMPORT_C void oil_debug_set_level (int level);
       
   128 
       
   129 void _oil_debug_init (void);
       
   130 
       
   131 IMPORT_C void oil_debug_print (int level, const char *file, const char *func,
       
   132     int line, const char *format, ...);
       
   133 
       
   134 #endif
       
   135 
       
   136 OIL_END_DECLS
       
   137 
       
   138 #endif
       
   139