liblogger.h

Go to the documentation of this file.
00001 /*
00002  * =============================================================================
00003  *  Name        : LibLogger.h
00004  *  Part of     : stdlibs/liblogger
00005  *  Description : Contained MRT library code tracing macros and class definition.
00006  *  Version     : 1.0
00007  *
00008  * Copyright © 2006 Nokia Corporation
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are met:
00013  * Redistributions of source code must retain the above copyright notice, this
00014  * list of conditions and the following disclaimer.
00015  * Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  * Neither the name of the <ORGANIZATION> nor the names of its contributors
00019  * may be used to endorse or promote products derived from this software
00020  * without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 //  INCLUDES
00044 #include <e32def.h>
00045 
00046 // DATA TYPES
00047 
00048 /* Log message type (Info/Minor/Major/Critical) */
00049 typedef enum TLibTraceMessageType
00050 {
00051         ELibTraceTypeInfo = 1,
00052         ELibTraceTypeMinor = 2,
00053         ELibTraceTypeMajor = 4,
00054         ELibTraceTypeCritical = 8
00055 }TLibTraceMessageType;
00056 
00057 // MACROS
00058 
00059 // only logging for critical/major
00060 //#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor | ELibTraceTypeInfo )
00061 #define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
00062 
00063 /* this macro will be used for file and line no.
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 // We are unable to compile the component using non-variadic macros from command line.
00189 // throwing error "badly punctuated parameter list in `#define'"
00190 
00191 
00192 #if defined(_DEBUG)
00193 //#pragma message("LibC Trace - ENABLE.")
00194 
00195 #ifdef __cplusplus
00196 // C++ source code
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 // C souce code.
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 // __cplusplus
00259 #endif
00260 
00261 /*
00262  * usage : LIB_TRACE(
00263  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
00264  *          format,
00265  *          args);
00266  * Remark : Similar to printf except the first additional parameter for message type.
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  * usage : LIB_TRACE_DUMP(
00279  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
00280  *          message, // user wants to add any message before dump, (i.e. TCP message)
00281  *          format,
00282  *          args);
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  * usage : LIB_TRACE_DUMP_LEN(
00295  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
00296  *          message, // user wants to add any message before dump, (i.e. TCP message)
00297  *          dumpstring,
00298  *          stringlength);
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 // compilation message
00316 //#pragma message("LibC Trace - DISABLE.")
00317 // Release mode, nothing.
00318 
00319 /* Release */
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 // _DEBUG
00340 #endif
00341 
00342 
00343 //LIB_LOGGER_H
00344 #endif
00345 
00346 
00347 // End of file

Copyright © Nokia Corporation 2001-2008
Back to top