# debug.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: debug.h,v $
    00003  -------------------
    00004  cvs         : $Id: debug.h,v 1.12 2005/01/13 17:30:20 aquamaniac Exp $
    00005  begin       : Thu Nov 28 2002
    00006  copyright   : (C) 2002 by Martin Preuss
    00007  email       : martin@libchipcard.de
    00008
    00009  ***************************************************************************
    00010  *                                                                         *
    00011  *   This library is free software; you can redistribute it and/or         *
    00012  *   modify it under the terms of the GNU Lesser General Public            *
    00013  *   License as published by the Free Software Foundation; either          *
    00014  *   version 2.1 of the License, or (at your option) any later version.    *
    00015  *                                                                         *
    00016  *   This library is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
    00019  *   Lesser General Public License for more details.                       *
    00020  *                                                                         *
    00021  *   You should have received a copy of the GNU Lesser General Public      *
    00022  *   License along with this library; if not, write to the Free Software   *
    00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
    00024  *   MA  02111-1307  USA                                                   *
    00025  *                                                                         *
    00026  ***************************************************************************/
    00027
    00028
    00029 #ifndef GWEN_DEBUG_H
    00030 #define GWEN_DEBUG_H
    00031
    00032 #include <stdio.h>
    00033 #include <gwenhywfar/gwenhywfarapi.h>
    00034 #include <gwenhywfar/logger.h>
    00035 #include <gwenhywfar/error.h>
    00036 #include <gwenhywfar/types.h>
    00037
    00038 #ifdef __cplusplus
    00039 extern "C" {
    00040 #endif
    00041
    00042 #if (defined HAVE_FUNC && (DEBUGMODE>10))
    00043 # define DBG_ENTER fprintf(stderr,"Enter \""__func__"\" \n")
    00044 # define DBG_LEAVE fprintf(stderr,"Leave \""__func__"\" \n")
    00045 #else
    00046 # define DBG_ENTER
    00047 # define DBG_LEAVE
    00048 #endif
    00049
    00050 #define GWEN_MEMORY_DEBUG_MODE_ALL      0
    00051 #define GWEN_MEMORY_DEBUG_MODE_OPEN     1
    00052 #define GWEN_MEMORY_DEBUG_MODE_DETAILED 2
    00053 #define GWEN_MEMORY_DEBUG_MODE_SHORT    3
    00054
    00055 typedef struct GWEN_MEMORY_DEBUG_OBJECT GWEN_MEMORY_DEBUG_OBJECT;
    00056
    00057 GWENHYWFAR_API
    00058 void GWEN_MemoryDebug_Increment(const char *name,
    00059                                 const char *wFile,
    00060                                 int wLine,
    00061                                 int attach);
    00062 GWENHYWFAR_API
    00063 void GWEN_MemoryDebug_Decrement(const char *name,
    00064                                 const char *wFile,
    00065                                 int wLine);
    00066
    00067 GWENHYWFAR_API
    00068 void GWEN_MemoryDebug_Dump(GWEN_TYPE_UINT32 mode);
    00069
    00070 GWENHYWFAR_API
    00071 void GWEN_MemoryDebug_DumpObject(const char *name,
    00072                                  GWEN_TYPE_UINT32 mode);
    00073
    00074 GWENHYWFAR_API
    00075 long int GWEN_MemoryDebug_GetObjectCount(const char *name);
    00076
    00077 GWENHYWFAR_API
    00078 void GWEN_MemoryDebug_CleanUp();
    00079
    00080
    00081 #ifdef GWEN_MEMORY_DEBUG
    00082 # define DBG_MEM_INC(o, attach)\
    00083   GWEN_MemoryDebug_Increment(o, __FILE__, __LINE__, attach)
    00084 # define DBG_MEM_DEC(o)\
    00085   GWEN_MemoryDebug_Decrement(o, __FILE__, __LINE__)
    00086 #else
    00087 # define DBG_MEM_INC(o, attach)
    00088 # define DBG_MEM_DEC(o)
    00089 #endif
    00090
    00091 GWENHYWFAR_API
    00092 GWEN_TYPE_UINT32 GWEN_Debug_Snprintf(char *buffer,
    00093                                      GWEN_TYPE_UINT32 size,
    00094                                      const char *fmt, ...);
    00095
    00096 #ifndef NO_VARIADIC_MACROS
    00097 # define DBG_ERROR(dbg_logger, format, args...) if (1){\
    00098   char dbg_buffer[256]; \
    00099   snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00100   __FILE__":%5d: " format  , __LINE__ , ## args); \
    00101   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00102  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelError, dbg_buffer);};
    00103 #else /* #ifndef NO_VARIADIC_MACROS */
    00104 GWENHYWFAR_API
    00105 void DBG_ERROR(const char *logdomain, const char *format, ...);
    00106 #endif /* #ifndef NO_VARIADIC_MACROS */
    00107
    00108 #define DBG_ERROR_ERR(dbg_logger, dbg_err) {\
    00109  char dbg_buffer[256]; \
    00110  char dbg_errbuff[256]; \
    00111  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00112  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00113  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00114   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00115  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelError, dbg_buffer);};
    00116
    00117 #ifndef NO_VARIADIC_MACROS
    00118 # define DBG_WARN(dbg_logger, format, args...) {\
    00119   char dbg_buffer[256]; \
    00120   snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00121   __FILE__":%5d: " format  , __LINE__ , ## args); \
    00122   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00123  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelWarning, dbg_buffer);};
    00124 #else /* #ifndef NO_VARIADIC_MACROS */
    00125 GWENHYWFAR_API
    00126 void DBG_WARN(const char *logdomain, const char *format, ...);
    00127 #endif /* #ifndef NO_VARIADIC_MACROS */
    00128
    00129 #define DBG_WARN_ERR(dbg_logger, dbg_err) {\
    00130  char dbg_buffer[256]; \
    00131  char dbg_errbuff[256]; \
    00132  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00133  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00134  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00135   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00136  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelWarning, dbg_buffer);};
    00137
    00138
    00139 #ifndef NO_VARIADIC_MACROS
    00140 # define DBG_NOTICE(dbg_logger, format, args...) \
    00141  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelNotice) {\
    00142  char dbg_buffer[256]; \
    00143  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00144  __FILE__":%5d: " format  , __LINE__ , ## args); \
    00145   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00146  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelNotice, dbg_buffer);};
    00147 #else /* #ifndef NO_VARIADIC_MACROS */
    00148 GWENHYWFAR_API
    00149 void DBG_NOTICE(const char *logdomain, const char *format, ...);
    00150 #endif /* #ifndef NO_VARIADIC_MACROS */
    00151
    00152 #define DBG_NOTICE_ERR(dbg_logger, dbg_err) \
    00153  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelNotice) {\
    00154  char dbg_buffer[256]; \
    00155  char dbg_errbuff[256]; \
    00156  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00157  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00158  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00159   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00160  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelNotice, dbg_buffer);};
    00161
    00162
    00163 #ifndef NO_VARIADIC_MACROS
    00164 # define DBG_INFO(dbg_logger, format, args...) \
    00165  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelInfo) {\
    00166   char dbg_buffer[256]; \
    00167  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00168  __FILE__":%5d: " format  , __LINE__ , ## args); \
    00169   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00170  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelInfo, dbg_buffer);};
    00171 #else /* #ifndef NO_VARIADIC_MACROS */
    00172 GWENHYWFAR_API
    00173 void DBG_INFO(const char *logdomain, const char *format, ...);
    00174 #endif /* #ifndef NO_VARIADIC_MACROS */
    00175
    00176 #define DBG_INFO_ERR(dbg_logger, dbg_err) \
    00177  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelInfo) {\
    00178  char dbg_buffer[256]; \
    00179  char dbg_errbuff[256]; \
    00180  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00181  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00182  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00183   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00184  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelInfo, dbg_buffer);};
    00185
    00186
    00187
    00188
    00189 #ifndef DISABLE_DEBUGLOG
    00190
    00191 # ifndef NO_VARIADIC_MACROS
    00192 #  define DBG_DEBUG(dbg_logger, format, args...) \
    00193  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelDebug) {\
    00194  char dbg_buffer[256]; \
    00195  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00196  __FILE__":%5d: " format  , __LINE__ , ## args); \
    00197   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00198  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelDebug, dbg_buffer);};
    00199
    00200 #  define DBG_VERBOUS(dbg_logger, format, args...) \
    00201  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelVerbous) {\
    00202  char dbg_buffer[256]; \
    00203  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00204  __FILE__":%5d: " format  , __LINE__ , ## args); \
    00205   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00206  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelVerbous, dbg_buffer);};
    00207 # endif /* #ifndef NO_VARIADIC_MACROS */
    00208
    00209 # define DBG_DEBUG_ERR(dbg_logger, dbg_err) \
    00210  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelDebug) {\
    00211  char dbg_buffer[256]; \
    00212  char dbg_errbuff[256]; \
    00213  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00214  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00215  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00216   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00217  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelDebug, dbg_buffer);};
    00218
    00219 # define DBG_VERBOUS_ERR(dbg_logger, dbg_err) \
    00220  if (GWEN_Logger_GetLevel(dbg_logger)>=GWEN_LoggerLevelVerbous) {\
    00221  char dbg_buffer[256]; \
    00222  char dbg_errbuff[256]; \
    00223  GWEN_Error_ToString(dbg_err,dbg_errbuff, sizeof(dbg_errbuff)); \
    00224  snprintf(dbg_buffer, sizeof(dbg_buffer)-1,\
    00225  __FILE__":%5d: %s" , __LINE__ , dbg_errbuff); \
    00226   dbg_buffer[sizeof(dbg_buffer)-1]=0; \
    00227  GWEN_Logger_Log(dbg_logger, GWEN_LoggerLevelVerbous, dbg_buffer);};
    00228
    00229
    00230
    00231 #else
    00232
    00233 # ifndef NO_VARIADIC_MACROS
    00234 #  define DBG_DEBUG(dbg_logger, format, args...)
    00235 #  define DBG_VERBOUS(dbg_logger, format, args...)
    00236 # endif /* ifndef NO_VARIADIC_MACROS */
    00237
    00238 # define DBG_DEBUG_ERR(dbg_logger, dbg_err)
    00239 # define DBG_VERBOUS_ERR(dbg_logger, dbg_err)
    00240
    00241 #endif /* DISABLE_DEBUGLOG */
    00242
    00243 #ifdef NO_VARIADIC_MACROS
    00244 GWENHYWFAR_API
    00245 void DBG_DEBUG(const char *logdomain, const char *format, ...);
    00246 GWENHYWFAR_API
    00247 void DBG_VERBOUS(const char *logdomain, const char *format, ...);
    00248 #endif /* #ifdef NO_VARIADIC_MACROS */
    00249
    00250
    00251 #ifdef __cplusplus
    00252 }
    00253 #endif
    00254
    00255
    00256 #endif
    00257
    00258