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