epoc32/include/liblogger.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 liblogger.h
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.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 * All rights reserved.
       
    20 * Redistribution and use in source and binary forms, with or without
       
    21 * modification, are permitted provided that the following conditions are met:
       
    22 * Redistributions of source code must retain the above copyright notice, this
       
    23 * list of conditions and the following disclaimer.
       
    24 * Redistributions in binary form must reproduce the above copyright notice,
       
    25 * this list of conditions and the following disclaimer in the documentation
       
    26 * and/or other materials provided with the distribution.
       
    27 * Neither the name of the <ORGANIZATION> nor the names of its contributors
       
    28 * may be used to endorse or promote products derived from this software
       
    29 * without specific prior written permission.
       
    30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
       
    31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    33 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
       
    34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
       
    35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
       
    37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
       
    38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    40 *
       
    41 */
       
    42 
       
    43 
       
    44 
       
    45 #ifndef LIB_LOGGER_H
       
    46 #define LIB_LOGGER_H
       
    47 
       
    48 //  INCLUDES
       
    49 
       
    50 #include <e32def.h>
       
    51 
       
    52 // DATA TYPES
       
    53 
       
    54 /* Log message type (Info/Minor/Major/Critical) */
       
    55 typedef enum TLibTraceMessageType
       
    56 {
       
    57 	ELibTraceTypeInfo = 1,
       
    58 	ELibTraceTypeMinor = 2,
       
    59 	ELibTraceTypeMajor = 4,
       
    60 	ELibTraceTypeCritical = 8
       
    61 }TLibTraceMessageType;
       
    62 
       
    63 // MACROS
       
    64 
       
    65 // only logging for critical/major
       
    66 //#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor | ELibTraceTypeInfo )
       
    67 #define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
       
    68 
       
    69 /* this macro will be used for file and line no.
       
    70  */
       
    71 #define LOG_FILE_NAME_LINE __FILE__, __LINE__
       
    72 
       
    73 #ifdef __cplusplus
       
    74 extern "C" {
       
    75 #endif
       
    76 /*
       
    77  * Message logging interface
       
    78  */
       
    79 IMPORT_C int LibTracer(TLibTraceMessageType aLogMessageType,
       
    80 							char *aFileName,
       
    81 							int aLine,
       
    82 							char *aFormat,
       
    83 							...);
       
    84 
       
    85 /*
       
    86  * Message logging interface
       
    87  */
       
    88 IMPORT_C int LibTracerMarkerList(TLibTraceMessageType aLogMessageType,
       
    89 							char *aFileName,
       
    90 							int aLine,
       
    91 							char *aFormat,
       
    92 							VA_LIST* aMarkerList);
       
    93 
       
    94 /*
       
    95  * dumping the message in hex format of specific length
       
    96  */
       
    97 IMPORT_C int LibTracerPartialHexDump(TLibTraceMessageType aLogMessageType,
       
    98                             char *aFileName,
       
    99 							int aLine,
       
   100 							char *aMessage,
       
   101 							char *aStr,
       
   102 							int aStrLen);
       
   103 
       
   104 /*
       
   105  * dumping the message in hex format
       
   106  */
       
   107 IMPORT_C int LibTracerHexDump(TLibTraceMessageType aLogMessageType,
       
   108                             char *aFileName,
       
   109 							int aLine,
       
   110 							char *aMessage,
       
   111 							char *aFormat,
       
   112 							...);
       
   113 
       
   114 /*
       
   115  * dumping the message in hex format
       
   116  */
       
   117 IMPORT_C int LibTracerHexDumpMarkerList(TLibTraceMessageType aLogMessageType,
       
   118                             char *aFileName,
       
   119 							int aLine,
       
   120 							char *aMessage,
       
   121 							char *aFormat,
       
   122 							VA_LIST* aMarkerList);
       
   123 
       
   124 /*
       
   125  * Only logs filename and line no with timestamp
       
   126  */
       
   127 IMPORT_C int LibLineExecTracer(char *aFileName, int aLine);
       
   128 
       
   129 /*
       
   130  * Only logging/trace message without timestamp
       
   131  */
       
   132 IMPORT_C int LibMessageTracer(TLibTraceMessageType aLogMessageType,
       
   133 							char *aFormat,
       
   134 							VA_LIST* aMarkerList);
       
   135 
       
   136 /*
       
   137  * Only logging/trace message without timestamp
       
   138  */
       
   139 IMPORT_C int LibHexDumpMessagePartTracer(TLibTraceMessageType aLogMessageType,
       
   140 							char* aMessage,
       
   141 							char *aFormat,
       
   142 							VA_LIST* aMarkerList);
       
   143 
       
   144 
       
   145 #ifdef __cplusplus
       
   146 }
       
   147 #endif
       
   148 
       
   149 // We are unable to compile the component using non-variadic macros from command line.
       
   150 // throwing error "badly punctuated parameter list in `#define'"
       
   151 
       
   152 
       
   153 #if defined(_DEBUG)
       
   154 //#pragma message("LibC Trace - ENABLE.")
       
   155 
       
   156 #ifdef __cplusplus
       
   157 // C++ source code
       
   158 class CLogger
       
   159     {
       
   160     public:
       
   161     CLogger(char* aFileName, int aLine) : iFileName ( aFileName ), iLine ( aLine) {}
       
   162     inline int Tracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
       
   163         {
       
   164         int len = 0;
       
   165         if ( LOG_BITS & aLogMessageType )
       
   166             {
       
   167             VA_LIST marker;
       
   168             VA_START(marker, aFormat);
       
   169             len = LibTracerMarkerList(aLogMessageType, iFileName, iLine, aFormat, &marker);
       
   170             VA_END(marker);
       
   171             }
       
   172         return len;
       
   173         }
       
   174     inline int Dump(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
       
   175         {
       
   176         int len = 0;
       
   177         if ( LOG_BITS & aLogMessageType )
       
   178             {
       
   179             VA_LIST marker;
       
   180             VA_START(marker, aFormat);
       
   181             len = LibTracerHexDumpMarkerList(aLogMessageType, iFileName, iLine, aMessage, aFormat, &marker);
       
   182             VA_END(marker);
       
   183             }
       
   184         return len;
       
   185         }
       
   186 
       
   187     private:
       
   188     char* iFileName;
       
   189     int iLine;
       
   190     };
       
   191 
       
   192 #else // __cplusplus
       
   193 // C souce code.
       
   194 static int LibcTracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
       
   195     {
       
   196     int len = 0;
       
   197     if ( LOG_BITS & aLogMessageType )
       
   198         {
       
   199         VA_LIST marker;
       
   200         VA_START(marker, aFormat);
       
   201         len = LibMessageTracer(aLogMessageType, aFormat, &marker);
       
   202         VA_END(marker);
       
   203         }
       
   204     return len;
       
   205     }
       
   206 
       
   207 static int LibHexTracer(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
       
   208     {
       
   209     int len = 0;
       
   210     if ( LOG_BITS & aLogMessageType )
       
   211         {
       
   212         VA_LIST marker;
       
   213         VA_START(marker, aFormat);
       
   214         len = LibHexDumpMessagePartTracer(aLogMessageType, aMessage, aFormat, &marker);
       
   215         VA_END(marker);
       
   216         }
       
   217     return len;
       
   218     }
       
   219 #endif // __cplusplus
       
   220 
       
   221 /*
       
   222  * usage : LIB_TRACE(
       
   223  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
       
   224  *          format,
       
   225  *          args);
       
   226  * Remark : Similar to printf except the first additional parameter for message type.
       
   227  */
       
   228 
       
   229 #ifdef __cplusplus
       
   230 #define LIB_TRACE CLogger(LOG_FILE_NAME_LINE).Tracer
       
   231 #else
       
   232 #define LIB_TRACE LibLineExecTracer(LOG_FILE_NAME_LINE); \
       
   233                    LibcTracer
       
   234 #endif
       
   235 
       
   236 
       
   237 /*
       
   238  * usage : LIB_TRACE_DUMP(
       
   239  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
       
   240  *          message, // user wants to add any message before dump, (i.e. TCP message)
       
   241  *          format,
       
   242  *          args);
       
   243  */
       
   244 
       
   245 #ifdef __cplusplus
       
   246 #define LIB_TRACE_DUMP CLogger(LOG_FILE_NAME_LINE).Dump
       
   247 #else
       
   248 #define LIB_TRACE_DUMP LibLineExecTracer(LOG_FILE_NAME_LINE); \
       
   249                     LibHexTracer
       
   250 #endif
       
   251 
       
   252 
       
   253 /*
       
   254  * usage : LIB_TRACE_DUMP_LEN(
       
   255  *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
       
   256  *          message, // user wants to add any message before dump, (i.e. TCP message)
       
   257  *          dumpstring,
       
   258  *          stringlength);
       
   259  */
       
   260 
       
   261 
       
   262 #define LIB_TRACE_DUMP_LEN(messageType, message, dumpString, dumpStringLen) \
       
   263     { \
       
   264     if ( LOG_BITS & messageType ) \
       
   265         { \
       
   266 	    LibTracerPartialHexDump(messageType, \
       
   267 	                    LOG_FILE_NAME_LINE, \
       
   268 					    message, \
       
   269 						dumpString, \
       
   270 						dumpStringLen); \
       
   271         } \
       
   272     }
       
   273 
       
   274 #else
       
   275 // compilation message
       
   276 //#pragma message("LibC Trace - DISABLE.")
       
   277 // Release mode, nothing.
       
   278 
       
   279 /* Release */
       
   280 
       
   281 #ifdef __cplusplus
       
   282 inline TInt LibTracerDummy(...)
       
   283         {
       
   284         return 0;
       
   285         }
       
   286 #else
       
   287 static TInt LibTracerDummy(TLibTraceMessageType aLogMessageType, ...)
       
   288         {
       
   289         return 0;
       
   290         }
       
   291 #endif
       
   292 
       
   293 #define LIB_TRACE        0 & LibTracerDummy
       
   294 
       
   295 #define LIB_TRACE_DUMP 0 & LibTracerDummy
       
   296 
       
   297 #define LIB_TRACE_DUMP_LEN 0 & LibTracerDummy
       
   298 
       
   299 #endif // _DEBUG
       
   300 
       
   301 
       
   302 #endif //LIB_LOGGER_H
       
   303 
       
   304 
       
   305 // End of file