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