epoc32/include/liblogger.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/liblogger.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,305 +0,0 @@
     1.4 -/*
     1.5 -* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 -* All rights reserved.
     1.7 -* This component and the accompanying materials are made available
     1.8 -* 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
     1.9 -* which accompanies this distribution, and is available
    1.10 -* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 -*
    1.12 -* Initial Contributors:
    1.13 -* Nokia Corporation - initial contribution.
    1.14 -*
    1.15 -* Contributors:
    1.16 -*
    1.17 -* Description:
    1.18 -* Name        : LibLogger.h
    1.19 -* Part of     : LIBC/logger
    1.20 -* Contained MRT library code tracing macros and class definition.
    1.21 -* Version     : 1.0
    1.22 -* All rights reserved.
    1.23 -* Redistribution and use in source and binary forms, with or without
    1.24 -* modification, are permitted provided that the following conditions are met:
    1.25 -* Redistributions of source code must retain the above copyright notice, this
    1.26 -* list of conditions and the following disclaimer.
    1.27 -* Redistributions in binary form must reproduce the above copyright notice,
    1.28 -* this list of conditions and the following disclaimer in the documentation
    1.29 -* and/or other materials provided with the distribution.
    1.30 -* Neither the name of the <ORGANIZATION> nor the names of its contributors
    1.31 -* may be used to endorse or promote products derived from this software
    1.32 -* without specific prior written permission.
    1.33 -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.34 -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.35 -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    1.36 -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
    1.37 -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.38 -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.39 -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    1.40 -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.41 -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.42 -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.43 -*
    1.44 -*/
    1.45 -
    1.46 -
    1.47 -
    1.48 -#ifndef LIB_LOGGER_H
    1.49 -#define LIB_LOGGER_H
    1.50 -
    1.51 -//  INCLUDES
    1.52 -
    1.53 -#include <e32def.h>
    1.54 -
    1.55 -// DATA TYPES
    1.56 -
    1.57 -/* Log message type (Info/Minor/Major/Critical) */
    1.58 -typedef enum TLibTraceMessageType
    1.59 -{
    1.60 -	ELibTraceTypeInfo = 1,
    1.61 -	ELibTraceTypeMinor = 2,
    1.62 -	ELibTraceTypeMajor = 4,
    1.63 -	ELibTraceTypeCritical = 8
    1.64 -}TLibTraceMessageType;
    1.65 -
    1.66 -// MACROS
    1.67 -
    1.68 -// only logging for critical/major
    1.69 -//#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor | ELibTraceTypeInfo )
    1.70 -#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
    1.71 -
    1.72 -/* this macro will be used for file and line no.
    1.73 - */
    1.74 -#define LOG_FILE_NAME_LINE __FILE__, __LINE__
    1.75 -
    1.76 -#ifdef __cplusplus
    1.77 -extern "C" {
    1.78 -#endif
    1.79 -/*
    1.80 - * Message logging interface
    1.81 - */
    1.82 -IMPORT_C int LibTracer(TLibTraceMessageType aLogMessageType,
    1.83 -							char *aFileName,
    1.84 -							int aLine,
    1.85 -							char *aFormat,
    1.86 -							...);
    1.87 -
    1.88 -/*
    1.89 - * Message logging interface
    1.90 - */
    1.91 -IMPORT_C int LibTracerMarkerList(TLibTraceMessageType aLogMessageType,
    1.92 -							char *aFileName,
    1.93 -							int aLine,
    1.94 -							char *aFormat,
    1.95 -							VA_LIST* aMarkerList);
    1.96 -
    1.97 -/*
    1.98 - * dumping the message in hex format of specific length
    1.99 - */
   1.100 -IMPORT_C int LibTracerPartialHexDump(TLibTraceMessageType aLogMessageType,
   1.101 -                            char *aFileName,
   1.102 -							int aLine,
   1.103 -							char *aMessage,
   1.104 -							char *aStr,
   1.105 -							int aStrLen);
   1.106 -
   1.107 -/*
   1.108 - * dumping the message in hex format
   1.109 - */
   1.110 -IMPORT_C int LibTracerHexDump(TLibTraceMessageType aLogMessageType,
   1.111 -                            char *aFileName,
   1.112 -							int aLine,
   1.113 -							char *aMessage,
   1.114 -							char *aFormat,
   1.115 -							...);
   1.116 -
   1.117 -/*
   1.118 - * dumping the message in hex format
   1.119 - */
   1.120 -IMPORT_C int LibTracerHexDumpMarkerList(TLibTraceMessageType aLogMessageType,
   1.121 -                            char *aFileName,
   1.122 -							int aLine,
   1.123 -							char *aMessage,
   1.124 -							char *aFormat,
   1.125 -							VA_LIST* aMarkerList);
   1.126 -
   1.127 -/*
   1.128 - * Only logs filename and line no with timestamp
   1.129 - */
   1.130 -IMPORT_C int LibLineExecTracer(char *aFileName, int aLine);
   1.131 -
   1.132 -/*
   1.133 - * Only logging/trace message without timestamp
   1.134 - */
   1.135 -IMPORT_C int LibMessageTracer(TLibTraceMessageType aLogMessageType,
   1.136 -							char *aFormat,
   1.137 -							VA_LIST* aMarkerList);
   1.138 -
   1.139 -/*
   1.140 - * Only logging/trace message without timestamp
   1.141 - */
   1.142 -IMPORT_C int LibHexDumpMessagePartTracer(TLibTraceMessageType aLogMessageType,
   1.143 -							char* aMessage,
   1.144 -							char *aFormat,
   1.145 -							VA_LIST* aMarkerList);
   1.146 -
   1.147 -
   1.148 -#ifdef __cplusplus
   1.149 -}
   1.150 -#endif
   1.151 -
   1.152 -// We are unable to compile the component using non-variadic macros from command line.
   1.153 -// throwing error "badly punctuated parameter list in `#define'"
   1.154 -
   1.155 -
   1.156 -#if defined(_DEBUG)
   1.157 -//#pragma message("LibC Trace - ENABLE.")
   1.158 -
   1.159 -#ifdef __cplusplus
   1.160 -// C++ source code
   1.161 -class CLogger
   1.162 -    {
   1.163 -    public:
   1.164 -    CLogger(char* aFileName, int aLine) : iFileName ( aFileName ), iLine ( aLine) {}
   1.165 -    inline int Tracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
   1.166 -        {
   1.167 -        int len = 0;
   1.168 -        if ( LOG_BITS & aLogMessageType )
   1.169 -            {
   1.170 -            VA_LIST marker;
   1.171 -            VA_START(marker, aFormat);
   1.172 -            len = LibTracerMarkerList(aLogMessageType, iFileName, iLine, aFormat, &marker);
   1.173 -            VA_END(marker);
   1.174 -            }
   1.175 -        return len;
   1.176 -        }
   1.177 -    inline int Dump(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
   1.178 -        {
   1.179 -        int len = 0;
   1.180 -        if ( LOG_BITS & aLogMessageType )
   1.181 -            {
   1.182 -            VA_LIST marker;
   1.183 -            VA_START(marker, aFormat);
   1.184 -            len = LibTracerHexDumpMarkerList(aLogMessageType, iFileName, iLine, aMessage, aFormat, &marker);
   1.185 -            VA_END(marker);
   1.186 -            }
   1.187 -        return len;
   1.188 -        }
   1.189 -
   1.190 -    private:
   1.191 -    char* iFileName;
   1.192 -    int iLine;
   1.193 -    };
   1.194 -
   1.195 -#else // __cplusplus
   1.196 -// C souce code.
   1.197 -static int LibcTracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
   1.198 -    {
   1.199 -    int len = 0;
   1.200 -    if ( LOG_BITS & aLogMessageType )
   1.201 -        {
   1.202 -        VA_LIST marker;
   1.203 -        VA_START(marker, aFormat);
   1.204 -        len = LibMessageTracer(aLogMessageType, aFormat, &marker);
   1.205 -        VA_END(marker);
   1.206 -        }
   1.207 -    return len;
   1.208 -    }
   1.209 -
   1.210 -static int LibHexTracer(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
   1.211 -    {
   1.212 -    int len = 0;
   1.213 -    if ( LOG_BITS & aLogMessageType )
   1.214 -        {
   1.215 -        VA_LIST marker;
   1.216 -        VA_START(marker, aFormat);
   1.217 -        len = LibHexDumpMessagePartTracer(aLogMessageType, aMessage, aFormat, &marker);
   1.218 -        VA_END(marker);
   1.219 -        }
   1.220 -    return len;
   1.221 -    }
   1.222 -#endif // __cplusplus
   1.223 -
   1.224 -/*
   1.225 - * usage : LIB_TRACE(
   1.226 - *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   1.227 - *          format,
   1.228 - *          args);
   1.229 - * Remark : Similar to printf except the first additional parameter for message type.
   1.230 - */
   1.231 -
   1.232 -#ifdef __cplusplus
   1.233 -#define LIB_TRACE CLogger(LOG_FILE_NAME_LINE).Tracer
   1.234 -#else
   1.235 -#define LIB_TRACE LibLineExecTracer(LOG_FILE_NAME_LINE); \
   1.236 -                   LibcTracer
   1.237 -#endif
   1.238 -
   1.239 -
   1.240 -/*
   1.241 - * usage : LIB_TRACE_DUMP(
   1.242 - *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   1.243 - *          message, // user wants to add any message before dump, (i.e. TCP message)
   1.244 - *          format,
   1.245 - *          args);
   1.246 - */
   1.247 -
   1.248 -#ifdef __cplusplus
   1.249 -#define LIB_TRACE_DUMP CLogger(LOG_FILE_NAME_LINE).Dump
   1.250 -#else
   1.251 -#define LIB_TRACE_DUMP LibLineExecTracer(LOG_FILE_NAME_LINE); \
   1.252 -                    LibHexTracer
   1.253 -#endif
   1.254 -
   1.255 -
   1.256 -/*
   1.257 - * usage : LIB_TRACE_DUMP_LEN(
   1.258 - *          <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
   1.259 - *          message, // user wants to add any message before dump, (i.e. TCP message)
   1.260 - *          dumpstring,
   1.261 - *          stringlength);
   1.262 - */
   1.263 -
   1.264 -
   1.265 -#define LIB_TRACE_DUMP_LEN(messageType, message, dumpString, dumpStringLen) \
   1.266 -    { \
   1.267 -    if ( LOG_BITS & messageType ) \
   1.268 -        { \
   1.269 -	    LibTracerPartialHexDump(messageType, \
   1.270 -	                    LOG_FILE_NAME_LINE, \
   1.271 -					    message, \
   1.272 -						dumpString, \
   1.273 -						dumpStringLen); \
   1.274 -        } \
   1.275 -    }
   1.276 -
   1.277 -#else
   1.278 -// compilation message
   1.279 -//#pragma message("LibC Trace - DISABLE.")
   1.280 -// Release mode, nothing.
   1.281 -
   1.282 -/* Release */
   1.283 -
   1.284 -#ifdef __cplusplus
   1.285 -inline TInt LibTracerDummy(...)
   1.286 -        {
   1.287 -        return 0;
   1.288 -        }
   1.289 -#else
   1.290 -static TInt LibTracerDummy(TLibTraceMessageType aLogMessageType, ...)
   1.291 -        {
   1.292 -        return 0;
   1.293 -        }
   1.294 -#endif
   1.295 -
   1.296 -#define LIB_TRACE        0 & LibTracerDummy
   1.297 -
   1.298 -#define LIB_TRACE_DUMP 0 & LibTracerDummy
   1.299 -
   1.300 -#define LIB_TRACE_DUMP_LEN 0 & LibTracerDummy
   1.301 -
   1.302 -#endif // _DEBUG
   1.303 -
   1.304 -
   1.305 -#endif //LIB_LOGGER_H
   1.306 -
   1.307 -
   1.308 -// End of file