omxilvideocomps/omxil3gpmuxer/src/log.h
changeset 0 5d29cba61097
equal deleted inserted replaced
-1:000000000000 0:5d29cba61097
       
     1 /*
       
     2 * Copyright (c) 2004-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 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __SWI_LOG_H__
       
    20 #define __SWI_LOG_H__
       
    21 
       
    22 #include <e32debug.h>
       
    23 namespace DSD
       
    24 {
       
    25 
       
    26 #ifdef _DEBUG
       
    27 
       
    28 #ifdef _OMXIL_COMMON_DEBUG_TRACING_ON
       
    29 
       
    30 
       
    31 
       
    32 class TTruncateOverflowHandler16 : public TDes16Overflow
       
    33 	{
       
    34 	public:
       
    35 		virtual void Overflow( TDes16& aDes );
       
    36 	};
       
    37 	
       
    38 inline void TTruncateOverflowHandler16::Overflow( TDes16& aDes)
       
    39 	{
       
    40 	_LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated");
       
    41 	if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() )
       
    42      	aDes.Append(KErrOverflowMsg);
       
    43 	}
       
    44 	
       
    45 class TTruncateOverflowHandler8 : public TDes8Overflow
       
    46 	{
       
    47 	public:
       
    48 		virtual void Overflow( TDes8& aDes );
       
    49 	};
       
    50 	
       
    51 inline void TTruncateOverflowHandler8::Overflow( TDes8& aDes)
       
    52 	{
       
    53     _LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated");
       
    54 	if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() )
       
    55      	aDes.Append(KErrOverflowMsg);
       
    56 	}
       
    57 
       
    58 #define DEBUG_PRINTF(a) {DSD::DebugPrintf(__LINE__, __FILE__, a);}
       
    59 #define DEBUG_PRINTF2(a, b) {DSD::DebugPrintf(__LINE__, __FILE__, a, b);}
       
    60 #define DEBUG_PRINTF3(a, b, c) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c);}
       
    61 #define DEBUG_PRINTF4(a, b, c, d) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d);}
       
    62 #define DEBUG_PRINTF5(a, b, c, d, e) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);}
       
    63 
       
    64 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) 
       
    65 
       
    66 // UTF-8 overload of the DebufPrintf method. Should be used by default,
       
    67 // since it's cheaper both in CPU cycles and stack space.
       
    68 
       
    69 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...)
       
    70 	{
       
    71 	TTruncateOverflowHandler8 overflowHandler8;
       
    72 	VA_LIST list;
       
    73 	VA_START(list, aFormat);
       
    74 	
       
    75 	TTime now;
       
    76 	now.HomeTime();
       
    77 	
       
    78 	TBuf8<1024> buffer;
       
    79 	_LIT8(KSwiLogPrefix, "[3gpmuxer] ");
       
    80 	_LIT8(KSwiLineFileFormat, "TID[%d] : [%s:%d] -- ");
       
    81 	buffer.Append(KSwiLogPrefix);
       
    82 	RThread thread;
       
    83 	TUint threadId = thread.Id();
       
    84 	thread.Close();
       
    85 	RProcess proc;
       
    86 	TFileName fName = proc.FileName();
       
    87 	proc.Close();
       
    88 	buffer.AppendFormat(KSwiLineFileFormat, threadId, aFile, aLine);
       
    89 	buffer.AppendFormatList(aFormat, list ,&overflowHandler8 );
       
    90 	buffer.Append(_L8("\r\n"));
       
    91 	
       
    92 	RDebug::RawPrint(buffer);
       
    93 	
       
    94 	VA_END(list);
       
    95 	}
       
    96 	
       
    97 // Unicode DebufPrintf overload
       
    98 
       
    99 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...)
       
   100 	{
       
   101 	TTruncateOverflowHandler16 overflowHandler16;
       
   102 	VA_LIST list;
       
   103 	VA_START(list, aFormat);
       
   104 	
       
   105 	TTime now;
       
   106 	now.HomeTime();
       
   107 	
       
   108 	TBuf8<256> header;
       
   109 	_LIT8(KSwiLogPrefix, "[3gpmuxer] ");
       
   110 	_LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
       
   111 	header.Append(KSwiLogPrefix);
       
   112 	header.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile);
       
   113 	
       
   114 	TBuf<1024> buffer;
       
   115 	buffer.Copy(header);
       
   116 	buffer.AppendFormatList(aFormat, list ,&overflowHandler16);
       
   117 	buffer.Append(_L("\r\n"));
       
   118 	
       
   119 	RDebug::RawPrint(buffer);
       
   120 	
       
   121 	VA_END(list);
       
   122 	}
       
   123 #else
       
   124 
       
   125 #define DEBUG_PRINTF(a)
       
   126 #define DEBUG_PRINTF2(a, b)
       
   127 #define DEBUG_PRINTF3(a, b, c)
       
   128 #define DEBUG_PRINTF4(a, b, c, d)
       
   129 #define DEBUG_PRINTF5(a, b, c, d, e)
       
   130 
       
   131 #define DEBUG_CODE_SECTION(a)
       
   132 
       
   133 #endif
       
   134 
       
   135 #else
       
   136 
       
   137 #define DEBUG_PRINTF(a)
       
   138 #define DEBUG_PRINTF2(a, b)
       
   139 #define DEBUG_PRINTF3(a, b, c)
       
   140 #define DEBUG_PRINTF4(a, b, c, d)
       
   141 #define DEBUG_PRINTF5(a, b, c, d, e)
       
   142 
       
   143 #define DEBUG_CODE_SECTION(a)
       
   144 
       
   145 #endif
       
   146 
       
   147 
       
   148 } // namespace DSD
       
   149 
       
   150 #endif // __SWI_LOG_H__