00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COMMON_TRACE_H
00021 #define COMMON_TRACE_H
00022
00023 #ifdef TRACE_LEVEL
00024 #define HAVE_TRACE
00025 #include <stdio.h>
00026
00027
00028 #define TRACE_FLOW 0x0000001
00029 #define TRACE_ERROR 0x0000002
00030 #define TRACE_INFO 0x0000004
00031
00032
00033 #ifdef TRACE_HOME
00034 unsigned trace_level = TRACE_LEVEL;
00035 #else
00036 extern unsigned trace_level;
00037 #endif
00038 #endif
00039
00040
00041
00042 #ifdef HAVE_TRACE
00043
00044 #define TRACE_STRING(level, msg, str) \
00045 do { \
00046 if (level & trace_level) { \
00047 printf("[DEBUG] %40s (%4d) %s%s %s\n", \
00048 __FILE__, __LINE__, \
00049 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00050 (msg != NULL) ? msg : "MISSING MESSAGE", \
00051 (str != NULL) ? str : "(null)"); \
00052 } \
00053 } while(0)
00054
00055
00056 #define TRACE_NUMBER(level, msg, num) \
00057 do { \
00058 if (level & trace_level) { \
00059 printf("[DEBUG] %40s (%4d) %s%s %lu\n", \
00060 __FILE__, __LINE__, \
00061 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00062 (msg != NULL) ? msg : "MISSING MESSAGE", \
00063 (unsigned long int)(num)); \
00064 } \
00065 } while(0)
00066
00067
00068 #define TRACE_SNUMBER(level, msg, num) \
00069 do { \
00070 if (level & trace_level) { \
00071 printf("[DEBUG] %40s (%4d) %s%s %ld\n", \
00072 __FILE__, __LINE__, \
00073 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00074 (msg != NULL) ? msg : "MISSING MESSAGE", \
00075 (long int)(num)); \
00076 } \
00077 } while(0)
00078
00079
00080 #define TRACE_LNUMBER(level, msg, num) \
00081 do { \
00082 if (level & trace_level) { \
00083 printf("[DEBUG] %40s (%4d) %s%s %llu\n", \
00084 __FILE__, __LINE__, \
00085 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00086 (msg != NULL) ? msg : "MISSING MESSAGE", \
00087 (unsigned long long int)(num)); \
00088 } \
00089 } while(0)
00090
00091
00092 #define TRACE_SLNUMBER(level, msg, num) \
00093 do { \
00094 if (level & trace_level) { \
00095 printf("[DEBUG] %40s (%4d) %s%s %lld\n", \
00096 __FILE__, __LINE__, \
00097 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00098 (msg != NULL) ? msg : "MISSING MESSAGE", \
00099 (long long int)(num)); \
00100 } \
00101 } while(0)
00102
00103
00104 #define TRACE_DOUBLE(level, msg, num) \
00105 do { \
00106 if (level & trace_level) { \
00107 printf("[DEBUG] %40s (%4d) %s%s %e\n", \
00108 __FILE__, __LINE__, \
00109 (level == TRACE_ERROR) ? "ERROR-> " : "", \
00110 (msg != NULL) ? msg : "MISSING MESSAGE", \
00111 (double)(num)); \
00112 } \
00113 } while(0)
00114
00115
00116 #define TRACE_ASSERT(expression) expression ? : printf("ASSERTION FAILED\n")
00117 #else
00118
00119
00120 #define TRACE_STRING(level, msg, str)
00121 #define TRACE_NUMBER(level, msg, num)
00122 #define TRACE_SNUMBER(level, msg, num)
00123 #define TRACE_LNUMBER(level, msg, num)
00124 #define TRACE_SLNUMBER(level, msg, num)
00125 #define TRACE_DOUBLE(level, msg, num)
00126 #endif
00127
00128
00129
00130 #define TRACE_FLOW_STRING(msg, str) TRACE_STRING(TRACE_FLOW, msg, str)
00131 #define TRACE_ERROR_STRING(msg, str) TRACE_STRING(TRACE_ERROR, msg, str)
00132 #define TRACE_INFO_STRING(msg, str) TRACE_STRING(TRACE_INFO, msg, str)
00133
00134
00135 #define TRACE_FLOW_NUMBER(msg, num) TRACE_NUMBER(TRACE_FLOW, msg, num)
00136 #define TRACE_ERROR_NUMBER(msg, num) TRACE_NUMBER(TRACE_ERROR, msg, num)
00137 #define TRACE_INFO_NUMBER(msg, num) TRACE_NUMBER(TRACE_INFO, msg, num)
00138
00139
00140 #define TRACE_FLOW_SNUMBER(msg, num) TRACE_SNUMBER(TRACE_FLOW, msg, num)
00141 #define TRACE_ERROR_SNUMBER(msg, num) TRACE_SNUMBER(TRACE_ERROR, msg, num)
00142 #define TRACE_INFO_SNUMBER(msg, num) TRACE_SNUMBER(TRACE_INFO, msg, num)
00143
00144
00145 #define TRACE_FLOW_LNUMBER(msg, num) TRACE_LNUMBER(TRACE_FLOW, msg, num)
00146 #define TRACE_ERROR_LNUMBER(msg, num) TRACE_LNUMBER(TRACE_ERROR, msg, num)
00147 #define TRACE_INFO_LNUMBER(msg, num) TRACE_LNUMBER(TRACE_INFO, msg, num)
00148
00149
00150 #define TRACE_FLOW_SLNUMBER(msg, num) TRACE_SLNUMBER(TRACE_FLOW, msg, num)
00151 #define TRACE_ERROR_SLNUMBER(msg, num) TRACE_SLNUMBER(TRACE_ERROR, msg, num)
00152 #define TRACE_INFO_SLNUMBER(msg, num) TRACE_SLNUMBER(TRACE_INFO, msg, num)
00153
00154
00155 #define TRACE_FLOW_DOUBLE(msg, num) TRACE_DOUBLE(TRACE_FLOW, msg, num)
00156 #define TRACE_ERROR_DOUBLE(msg, num) TRACE_DOUBLE(TRACE_ERROR, msg, num)
00157 #define TRACE_INFO_DOUBLE(msg, num) TRACE_DOUBLE(TRACE_INFO, msg, num)
00158
00159 #endif