os/ossrv/genericopenlibs/openenvcore/liblogger/inc/liblogger.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * Name        : LibLogger.h
    16 * Part of     : LIBC/logger
    17 * Contained MRT library code tracing macros and class definition.
    18 * Version     : 1.0
    19 */
    20 
    21 
    22 
    23 #ifndef LIB_LOGGER_H
    24 #define LIB_LOGGER_H
    25 
    26 //  INCLUDES
    27 
    28 #include <e32def.h>
    29 
    30 // DATA TYPES
    31 
    32 /* Log message type (Info/Minor/Major/Critical) */
    33 typedef enum TLibTraceMessageType
    34 {
    35 	ELibTraceTypeInfo = 1,
    36 	ELibTraceTypeMinor = 2,
    37 	ELibTraceTypeMajor = 4,
    38 	ELibTraceTypeCritical = 8
    39 }TLibTraceMessageType;
    40 
    41 // MACROS
    42 
    43 // only logging for critical/major
    44 //#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor | ELibTraceTypeInfo )
    45 #define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
    46 
    47 /* this macro will be used for file and line no.
    48  */
    49 #define LOG_FILE_NAME_LINE __FILE__, __LINE__
    50 
    51 #ifdef __cplusplus
    52 extern "C" {
    53 #endif
    54 /*
    55  * Message logging interface
    56  */
    57 IMPORT_C int LibTracer(TLibTraceMessageType aLogMessageType,
    58 							char *aFileName,
    59 							int aLine,
    60 							char *aFormat,
    61 							...);
    62 
    63 /*
    64  * Message logging interface
    65  */
    66 IMPORT_C int LibTracerMarkerList(TLibTraceMessageType aLogMessageType,
    67 							char *aFileName,
    68 							int aLine,
    69 							char *aFormat,
    70 							VA_LIST* aMarkerList);
    71 
    72 /*
    73  * dumping the message in hex format of specific length
    74  */
    75 IMPORT_C int LibTracerPartialHexDump(TLibTraceMessageType aLogMessageType,
    76                             char *aFileName,
    77 							int aLine,
    78 							char *aMessage,
    79 							char *aStr,
    80 							int aStrLen);
    81 
    82 /*
    83  * dumping the message in hex format
    84  */
    85 IMPORT_C int LibTracerHexDump(TLibTraceMessageType aLogMessageType,
    86                             char *aFileName,
    87 							int aLine,
    88 							char *aMessage,
    89 							char *aFormat,
    90 							...);
    91 
    92 /*
    93  * dumping the message in hex format
    94  */
    95 IMPORT_C int LibTracerHexDumpMarkerList(TLibTraceMessageType aLogMessageType,
    96                             char *aFileName,
    97 							int aLine,
    98 							char *aMessage,
    99 							char *aFormat,
   100 							VA_LIST* aMarkerList);
   101 
   102 /*
   103  * Only logs filename and line no with timestamp
   104  */
   105 IMPORT_C int LibLineExecTracer(char *aFileName, int aLine);
   106 
   107 /*
   108  * Only logging/trace message without timestamp
   109  */
   110 IMPORT_C int LibMessageTracer(TLibTraceMessageType aLogMessageType,
   111 							char *aFormat,
   112 							VA_LIST* aMarkerList);
   113 
   114 /*
   115  * Only logging/trace message without timestamp
   116  */
   117 IMPORT_C int LibHexDumpMessagePartTracer(TLibTraceMessageType aLogMessageType,
   118 							char* aMessage,
   119 							char *aFormat,
   120 							VA_LIST* aMarkerList);
   121 
   122 
   123 #ifdef __cplusplus
   124 }
   125 #endif
   126 
   127 // We are unable to compile the component using non-variadic macros from command line.
   128 // throwing error "badly punctuated parameter list in `#define'"
   129 
   130 
   131 #if defined(_DEBUG)
   132 //#pragma message("LibC Trace - ENABLE.")
   133 
   134 #ifdef __cplusplus
   135 // C++ source code
   136 class CLogger // codescanner::missingcclass
   137     {
   138     public:
   139     CLogger(char* aFileName, int aLine) : iFileName ( aFileName ), iLine ( aLine) {}
   140     inline int Tracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
   141         {
   142         int len = 0;
   143         if ( LOG_BITS & aLogMessageType )
   144             {
   145             VA_LIST marker;
   146             VA_START(marker, aFormat);
   147             len = LibTracerMarkerList(aLogMessageType, iFileName, iLine, aFormat, &marker);
   148             VA_END(marker);
   149             }
   150         return len;
   151         }
   152     inline int Dump(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
   153         {
   154         int len = 0;
   155         if ( LOG_BITS & aLogMessageType )
   156             {
   157             VA_LIST marker;
   158             VA_START(marker, aFormat);
   159             len = LibTracerHexDumpMarkerList(aLogMessageType, iFileName, iLine, aMessage, aFormat, &marker);
   160             VA_END(marker);
   161             }
   162         return len;
   163         }
   164 
   165     private:
   166     char* iFileName;
   167     int iLine;
   168     };
   169 
   170 #else // __cplusplus
   171 // C souce code.
   172 static int LibcTracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
   173     {
   174     int len = 0;
   175     if ( LOG_BITS & aLogMessageType )
   176         {
   177         VA_LIST marker;
   178         VA_START(marker, aFormat);
   179         len = LibMessageTracer(aLogMessageType, aFormat, &marker);
   180         VA_END(marker);
   181         }
   182     return len;
   183     }
   184 
   185 static int LibHexTracer(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
   186     {
   187     int len = 0;
   188     if ( LOG_BITS & aLogMessageType )
   189         {
   190         VA_LIST marker;
   191         VA_START(marker, aFormat);
   192         len = LibHexDumpMessagePartTracer(aLogMessageType, aMessage, aFormat, &marker);
   193         VA_END(marker);
   194         }
   195     return len;
   196     }
   197 #endif // __cplusplus
   198 
   199 /*
   200  * usage : LIB_TRACE(
   201  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   202  *          format,
   203  *          args);
   204  * Remark : Similar to printf except the first additional parameter for message type.
   205  */
   206 
   207 #ifdef __cplusplus
   208 #define LIB_TRACE CLogger(LOG_FILE_NAME_LINE).Tracer
   209 #else
   210 #define LIB_TRACE LibLineExecTracer(LOG_FILE_NAME_LINE); \
   211                    LibcTracer
   212 #endif
   213 
   214 
   215 /*
   216  * usage : LIB_TRACE_DUMP(
   217  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   218  *          message, // user wants to add any message before dump, (i.e. TCP message)
   219  *          format,
   220  *          args);
   221  */
   222 
   223 #ifdef __cplusplus
   224 #define LIB_TRACE_DUMP CLogger(LOG_FILE_NAME_LINE).Dump
   225 #else
   226 #define LIB_TRACE_DUMP LibLineExecTracer(LOG_FILE_NAME_LINE); \
   227                     LibHexTracer
   228 #endif
   229 
   230 
   231 /*
   232  * usage : LIB_TRACE_DUMP_LEN(
   233  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   234  *          message, // user wants to add any message before dump, (i.e. TCP message)
   235  *          dumpstring,
   236  *          stringlength);
   237  */
   238 
   239 
   240 #define LIB_TRACE_DUMP_LEN(messageType, message, dumpString, dumpStringLen) \
   241     { \
   242     if ( LOG_BITS & messageType ) \
   243         { \
   244 	    LibTracerPartialHexDump(messageType, \
   245 	                    LOG_FILE_NAME_LINE, \
   246 					    message, \
   247 						dumpString, \
   248 						dumpStringLen); \
   249         } \
   250     }
   251 
   252 #else
   253 // compilation message
   254 //#pragma message("LibC Trace - DISABLE.")
   255 // Release mode, nothing.
   256 
   257 /* Release */
   258 
   259 #ifdef __cplusplus
   260 inline TInt LibTracerDummy(...)
   261         {
   262         return 0;
   263         }
   264 #else
   265 static TInt LibTracerDummy(TLibTraceMessageType aLogMessageType, ...)
   266         {
   267         return 0;
   268         }
   269 #endif
   270 
   271 #define LIB_TRACE        0 & LibTracerDummy
   272 
   273 #define LIB_TRACE_DUMP 0 & LibTracerDummy
   274 
   275 #define LIB_TRACE_DUMP_LEN 0 & LibTracerDummy
   276 
   277 #endif // _DEBUG
   278 
   279 
   280 #endif //LIB_LOGGER_H
   281 
   282 
   283 // End of file