00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef LIB_LOGGER_H
00036 #define LIB_LOGGER_H
00037
00038 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00039 #define SYMBIAN
00040 #endif
00041
00042
00043
00044 #include <e32def.h>
00045
00046
00047
00048
00049 typedef enum TLibTraceMessageType
00050 {
00051 ELibTraceTypeInfo = 1,
00052 ELibTraceTypeMinor = 2,
00053 ELibTraceTypeMajor = 4,
00054 ELibTraceTypeCritical = 8
00055 }TLibTraceMessageType;
00056
00057
00058
00059
00060
00061 #define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
00062
00063
00064
00065 #define LOG_FILE_NAME_LINE __FILE__, __LINE__
00066
00067 #ifdef __cplusplus
00068 extern "C" {
00069 #endif
00070
00079 IMPORT_C int LibTracer(TLibTraceMessageType aLogMessageType,
00080 char *aFileName,
00081 int aLine,
00082 char *aFormat,
00083 ...);
00084
00094 IMPORT_C int LibTracerMarkerList(TLibTraceMessageType aLogMessageType,
00095 char *aFileName,
00096 int aLine,
00097 char *aFormat,
00098 VA_LIST* aMarkerList);
00099
00110 IMPORT_C int LibTracerPartialHexDump(TLibTraceMessageType aLogMessageType,
00111 char *aFileName,
00112 int aLine,
00113 char *aMessage,
00114 char *aStr,
00115 int aStrLen);
00116
00127 IMPORT_C int LibTracerHexDump(TLibTraceMessageType aLogMessageType,
00128 char *aFileName,
00129 int aLine,
00130 char *aMessage,
00131 char *aFormat,
00132 ...);
00133
00144 IMPORT_C int LibTracerHexDumpMarkerList(TLibTraceMessageType aLogMessageType,
00145 char *aFileName,
00146 int aLine,
00147 char *aMessage,
00148 char *aFormat,
00149 VA_LIST* aMarkerList);
00150
00157 IMPORT_C int LibLineExecTracer(char *aFileName, int aLine);
00158
00166 IMPORT_C int LibMessageTracer(TLibTraceMessageType aLogMessageType,
00167 char *aFormat,
00168 VA_LIST* aMarkerList);
00169
00178 IMPORT_C int LibHexDumpMessagePartTracer(TLibTraceMessageType aLogMessageType,
00179 char* aMessage,
00180 char *aFormat,
00181 VA_LIST* aMarkerList);
00182
00183
00184 #ifdef __cplusplus
00185 }
00186 #endif
00187
00188
00189
00190
00191
00192 #if defined(_DEBUG)
00193
00194
00195 #ifdef __cplusplus
00196
00197 class CLogger
00198 {
00199 public:
00200 CLogger(char* aFileName, int aLine) : iFileName ( aFileName ), iLine ( aLine) {}
00201 inline int Tracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
00202 {
00203 int len = 0;
00204 if ( LOG_BITS & aLogMessageType )
00205 {
00206 VA_LIST marker;
00207 VA_START(marker, aFormat);
00208 len = LibTracerMarkerList(aLogMessageType, iFileName, iLine, aFormat, &marker);
00209 VA_END(marker);
00210 }
00211 return len;
00212 }
00213 inline int Dump(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
00214 {
00215 int len = 0;
00216 if ( LOG_BITS & aLogMessageType )
00217 {
00218 VA_LIST marker;
00219 VA_START(marker, aFormat);
00220 len = LibTracerHexDumpMarkerList(aLogMessageType, iFileName, iLine, aMessage, aFormat, &marker);
00221 VA_END(marker);
00222 }
00223 return len;
00224 }
00225
00226 private:
00227 char* iFileName;
00228 int iLine;
00229 };
00230
00231 #else // __cplusplus
00232
00233 static int LibcTracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
00234 {
00235 int len = 0;
00236 if ( LOG_BITS & aLogMessageType )
00237 {
00238 VA_LIST marker;
00239 VA_START(marker, aFormat);
00240 len = LibMessageTracer(aLogMessageType, aFormat, &marker);
00241 VA_END(marker);
00242 }
00243 return len;
00244 }
00245
00246 static int LibHexTracer(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
00247 {
00248 int len = 0;
00249 if ( LOG_BITS & aLogMessageType )
00250 {
00251 VA_LIST marker;
00252 VA_START(marker, aFormat);
00253 len = LibHexDumpMessagePartTracer(aLogMessageType, aMessage, aFormat, &marker);
00254 VA_END(marker);
00255 }
00256 return len;
00257 }
00258
00259 #endif
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 #ifdef __cplusplus
00270 #define LIB_TRACE CLogger(LOG_FILE_NAME_LINE).Tracer
00271 #else
00272 #define LIB_TRACE LibLineExecTracer(LOG_FILE_NAME_LINE); \
00273 LibcTracer
00274 #endif
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 #ifdef __cplusplus
00286 #define LIB_TRACE_DUMP CLogger(LOG_FILE_NAME_LINE).Dump
00287 #else
00288 #define LIB_TRACE_DUMP LibLineExecTracer(LOG_FILE_NAME_LINE); \
00289 LibHexTracer
00290 #endif
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 #define LIB_TRACE_DUMP_LEN(messageType, message, dumpString, dumpStringLen) \
00303 { \
00304 if ( LOG_BITS & messageType ) \
00305 { \
00306 LibTracerPartialHexDump(messageType, \
00307 LOG_FILE_NAME_LINE, \
00308 message, \
00309 dumpString, \
00310 dumpStringLen); \
00311 } \
00312 }
00313
00314 #else
00315
00316
00317
00318
00319
00320
00321 #ifdef __cplusplus
00322 inline TInt LibTracerDummy(...)
00323 {
00324 return 0;
00325 }
00326 #else
00327 static TInt LibTracerDummy(TLibTraceMessageType aLogMessageType, ...)
00328 {
00329 return 0;
00330 }
00331 #endif
00332
00333 #define LIB_TRACE 0 & LibTracerDummy
00334
00335 #define LIB_TRACE_DUMP 0 & LibTracerDummy
00336
00337 #define LIB_TRACE_DUMP_LEN 0 & LibTracerDummy
00338
00339
00340 #endif
00341
00342
00343
00344 #endif
00345
00346
00347