1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/liblogger/inc/liblogger.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,283 @@
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 "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.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 +*/
1.23 +
1.24 +
1.25 +
1.26 +#ifndef LIB_LOGGER_H
1.27 +#define LIB_LOGGER_H
1.28 +
1.29 +// INCLUDES
1.30 +
1.31 +#include <e32def.h>
1.32 +
1.33 +// DATA TYPES
1.34 +
1.35 +/* Log message type (Info/Minor/Major/Critical) */
1.36 +typedef enum TLibTraceMessageType
1.37 +{
1.38 + ELibTraceTypeInfo = 1,
1.39 + ELibTraceTypeMinor = 2,
1.40 + ELibTraceTypeMajor = 4,
1.41 + ELibTraceTypeCritical = 8
1.42 +}TLibTraceMessageType;
1.43 +
1.44 +// MACROS
1.45 +
1.46 +// only logging for critical/major
1.47 +//#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor | ELibTraceTypeInfo )
1.48 +#define LOG_BITS ( ELibTraceTypeCritical | ELibTraceTypeMajor )
1.49 +
1.50 +/* this macro will be used for file and line no.
1.51 + */
1.52 +#define LOG_FILE_NAME_LINE __FILE__, __LINE__
1.53 +
1.54 +#ifdef __cplusplus
1.55 +extern "C" {
1.56 +#endif
1.57 +/*
1.58 + * Message logging interface
1.59 + */
1.60 +IMPORT_C int LibTracer(TLibTraceMessageType aLogMessageType,
1.61 + char *aFileName,
1.62 + int aLine,
1.63 + char *aFormat,
1.64 + ...);
1.65 +
1.66 +/*
1.67 + * Message logging interface
1.68 + */
1.69 +IMPORT_C int LibTracerMarkerList(TLibTraceMessageType aLogMessageType,
1.70 + char *aFileName,
1.71 + int aLine,
1.72 + char *aFormat,
1.73 + VA_LIST* aMarkerList);
1.74 +
1.75 +/*
1.76 + * dumping the message in hex format of specific length
1.77 + */
1.78 +IMPORT_C int LibTracerPartialHexDump(TLibTraceMessageType aLogMessageType,
1.79 + char *aFileName,
1.80 + int aLine,
1.81 + char *aMessage,
1.82 + char *aStr,
1.83 + int aStrLen);
1.84 +
1.85 +/*
1.86 + * dumping the message in hex format
1.87 + */
1.88 +IMPORT_C int LibTracerHexDump(TLibTraceMessageType aLogMessageType,
1.89 + char *aFileName,
1.90 + int aLine,
1.91 + char *aMessage,
1.92 + char *aFormat,
1.93 + ...);
1.94 +
1.95 +/*
1.96 + * dumping the message in hex format
1.97 + */
1.98 +IMPORT_C int LibTracerHexDumpMarkerList(TLibTraceMessageType aLogMessageType,
1.99 + char *aFileName,
1.100 + int aLine,
1.101 + char *aMessage,
1.102 + char *aFormat,
1.103 + VA_LIST* aMarkerList);
1.104 +
1.105 +/*
1.106 + * Only logs filename and line no with timestamp
1.107 + */
1.108 +IMPORT_C int LibLineExecTracer(char *aFileName, int aLine);
1.109 +
1.110 +/*
1.111 + * Only logging/trace message without timestamp
1.112 + */
1.113 +IMPORT_C int LibMessageTracer(TLibTraceMessageType aLogMessageType,
1.114 + char *aFormat,
1.115 + VA_LIST* aMarkerList);
1.116 +
1.117 +/*
1.118 + * Only logging/trace message without timestamp
1.119 + */
1.120 +IMPORT_C int LibHexDumpMessagePartTracer(TLibTraceMessageType aLogMessageType,
1.121 + char* aMessage,
1.122 + char *aFormat,
1.123 + VA_LIST* aMarkerList);
1.124 +
1.125 +
1.126 +#ifdef __cplusplus
1.127 +}
1.128 +#endif
1.129 +
1.130 +// We are unable to compile the component using non-variadic macros from command line.
1.131 +// throwing error "badly punctuated parameter list in `#define'"
1.132 +
1.133 +
1.134 +#if defined(_DEBUG)
1.135 +//#pragma message("LibC Trace - ENABLE.")
1.136 +
1.137 +#ifdef __cplusplus
1.138 +// C++ source code
1.139 +class CLogger // codescanner::missingcclass
1.140 + {
1.141 + public:
1.142 + CLogger(char* aFileName, int aLine) : iFileName ( aFileName ), iLine ( aLine) {}
1.143 + inline int Tracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
1.144 + {
1.145 + int len = 0;
1.146 + if ( LOG_BITS & aLogMessageType )
1.147 + {
1.148 + VA_LIST marker;
1.149 + VA_START(marker, aFormat);
1.150 + len = LibTracerMarkerList(aLogMessageType, iFileName, iLine, aFormat, &marker);
1.151 + VA_END(marker);
1.152 + }
1.153 + return len;
1.154 + }
1.155 + inline int Dump(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
1.156 + {
1.157 + int len = 0;
1.158 + if ( LOG_BITS & aLogMessageType )
1.159 + {
1.160 + VA_LIST marker;
1.161 + VA_START(marker, aFormat);
1.162 + len = LibTracerHexDumpMarkerList(aLogMessageType, iFileName, iLine, aMessage, aFormat, &marker);
1.163 + VA_END(marker);
1.164 + }
1.165 + return len;
1.166 + }
1.167 +
1.168 + private:
1.169 + char* iFileName;
1.170 + int iLine;
1.171 + };
1.172 +
1.173 +#else // __cplusplus
1.174 +// C souce code.
1.175 +static int LibcTracer(TLibTraceMessageType aLogMessageType, char* aFormat, ...)
1.176 + {
1.177 + int len = 0;
1.178 + if ( LOG_BITS & aLogMessageType )
1.179 + {
1.180 + VA_LIST marker;
1.181 + VA_START(marker, aFormat);
1.182 + len = LibMessageTracer(aLogMessageType, aFormat, &marker);
1.183 + VA_END(marker);
1.184 + }
1.185 + return len;
1.186 + }
1.187 +
1.188 +static int LibHexTracer(TLibTraceMessageType aLogMessageType, char* aMessage, char* aFormat, ...)
1.189 + {
1.190 + int len = 0;
1.191 + if ( LOG_BITS & aLogMessageType )
1.192 + {
1.193 + VA_LIST marker;
1.194 + VA_START(marker, aFormat);
1.195 + len = LibHexDumpMessagePartTracer(aLogMessageType, aMessage, aFormat, &marker);
1.196 + VA_END(marker);
1.197 + }
1.198 + return len;
1.199 + }
1.200 +#endif // __cplusplus
1.201 +
1.202 +/*
1.203 + * usage : LIB_TRACE(
1.204 + * <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
1.205 + * format,
1.206 + * args);
1.207 + * Remark : Similar to printf except the first additional parameter for message type.
1.208 + */
1.209 +
1.210 +#ifdef __cplusplus
1.211 +#define LIB_TRACE CLogger(LOG_FILE_NAME_LINE).Tracer
1.212 +#else
1.213 +#define LIB_TRACE LibLineExecTracer(LOG_FILE_NAME_LINE); \
1.214 + LibcTracer
1.215 +#endif
1.216 +
1.217 +
1.218 +/*
1.219 + * usage : LIB_TRACE_DUMP(
1.220 + * <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
1.221 + * message, // user wants to add any message before dump, (i.e. TCP message)
1.222 + * format,
1.223 + * args);
1.224 + */
1.225 +
1.226 +#ifdef __cplusplus
1.227 +#define LIB_TRACE_DUMP CLogger(LOG_FILE_NAME_LINE).Dump
1.228 +#else
1.229 +#define LIB_TRACE_DUMP LibLineExecTracer(LOG_FILE_NAME_LINE); \
1.230 + LibHexTracer
1.231 +#endif
1.232 +
1.233 +
1.234 +/*
1.235 + * usage : LIB_TRACE_DUMP_LEN(
1.236 + * <messagetype>{ELibTraceTypeInfo|ELibTraceTypeMinor|ELibTraceTypeMajor|ELibTraceTypeCritical},
1.237 + * message, // user wants to add any message before dump, (i.e. TCP message)
1.238 + * dumpstring,
1.239 + * stringlength);
1.240 + */
1.241 +
1.242 +
1.243 +#define LIB_TRACE_DUMP_LEN(messageType, message, dumpString, dumpStringLen) \
1.244 + { \
1.245 + if ( LOG_BITS & messageType ) \
1.246 + { \
1.247 + LibTracerPartialHexDump(messageType, \
1.248 + LOG_FILE_NAME_LINE, \
1.249 + message, \
1.250 + dumpString, \
1.251 + dumpStringLen); \
1.252 + } \
1.253 + }
1.254 +
1.255 +#else
1.256 +// compilation message
1.257 +//#pragma message("LibC Trace - DISABLE.")
1.258 +// Release mode, nothing.
1.259 +
1.260 +/* Release */
1.261 +
1.262 +#ifdef __cplusplus
1.263 +inline TInt LibTracerDummy(...)
1.264 + {
1.265 + return 0;
1.266 + }
1.267 +#else
1.268 +static TInt LibTracerDummy(TLibTraceMessageType aLogMessageType, ...)
1.269 + {
1.270 + return 0;
1.271 + }
1.272 +#endif
1.273 +
1.274 +#define LIB_TRACE 0 & LibTracerDummy
1.275 +
1.276 +#define LIB_TRACE_DUMP 0 & LibTracerDummy
1.277 +
1.278 +#define LIB_TRACE_DUMP_LEN 0 & LibTracerDummy
1.279 +
1.280 +#endif // _DEBUG
1.281 +
1.282 +
1.283 +#endif //LIB_LOGGER_H
1.284 +
1.285 +
1.286 +// End of file