authorisation/userpromptservice/inc_private/upslog.h
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     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 the License "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 * Print functions used in debug mode 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @internalComponent 
       
    23 */
       
    24  
       
    25 #ifndef UPSLOG_H
       
    26 #define UPSLOG_H
       
    27 
       
    28 #include <e32debug.h>
       
    29 
       
    30 class TTruncateOverflowHandler16 : public TDes16Overflow
       
    31 	{
       
    32 	public:
       
    33 		virtual void Overflow(TDes16& aDes);
       
    34 	};
       
    35 	
       
    36 inline void TTruncateOverflowHandler16::Overflow(TDes16&)
       
    37 	{
       
    38 
       
    39 	}
       
    40 	
       
    41 class TTruncateOverflowHandler8 : public TDes8Overflow
       
    42 	{
       
    43 	public:
       
    44 		virtual void Overflow(TDes8& aDes);
       
    45 	};
       
    46 	
       
    47 inline void TTruncateOverflowHandler8::Overflow(TDes8&)
       
    48 	{
       
    49    
       
    50 	}
       
    51 
       
    52 namespace UserPromptService
       
    53 {
       
    54 
       
    55 #ifdef _DEBUG
       
    56 
       
    57 #define DEBUG_PRINTF(a) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a);}
       
    58 #define DEBUG_PRINTF2(a, b) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b);}
       
    59 #define DEBUG_PRINTF3(a, b, c) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c);}
       
    60 #define DEBUG_PRINTF4(a, b, c, d) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d);}
       
    61 #define DEBUG_PRINTF5(a, b, c, d, e) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);}
       
    62 
       
    63 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) 
       
    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 	VA_START(list, aFormat);
       
    73 	
       
    74 	TTime now;
       
    75 	now.HomeTime();
       
    76 	
       
    77 	TBuf8<512> buffer;
       
    78 	_LIT8(KUserPromptServiceLogPrefix, "[UPS] ");
       
    79 	_LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
       
    80 	buffer.Append(KUserPromptServiceLogPrefix);
       
    81 	buffer.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
       
    82 	buffer.AppendFormatList(aFormat, list, &overflowHandler8);
       
    83 	_LIT8(KUserPromptServiceMsgEnd, "\r\n");
       
    84 	if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
       
    85 		{
       
    86 		buffer.Append(KUserPromptServiceMsgEnd);
       
    87 		}
       
    88 	
       
    89 	RDebug::RawPrint(buffer);
       
    90 	
       
    91 	VA_END(list);
       
    92 	}
       
    93 	
       
    94 // Unicode DebugPrintf overload
       
    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(KUserPromptServiceLogPrefix, "[UPS] ");
       
   106 	_LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
       
   107 	header.Append(KUserPromptServiceLogPrefix);
       
   108 	header.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
       
   109 	
       
   110 	TBuf<256> buffer;
       
   111 	buffer.Copy(header);
       
   112 	buffer.AppendFormatList(aFormat, list , &overflowHandler16);
       
   113 	_LIT(KUserPromptServiceMsgEnd, "\r\n");
       
   114 	if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
       
   115 		{
       
   116 		buffer.Append(KUserPromptServiceMsgEnd);
       
   117 		}
       
   118 	
       
   119 	RDebug::RawPrint(buffer);
       
   120 	
       
   121 	VA_END(list);
       
   122 	}
       
   123 
       
   124 #else
       
   125 
       
   126 #define DEBUG_PRINTF(a)
       
   127 #define DEBUG_PRINTF2(a, b)
       
   128 #define DEBUG_PRINTF3(a, b, c)
       
   129 #define DEBUG_PRINTF4(a, b, c, d)
       
   130 #define DEBUG_PRINTF5(a, b, c, d, e)
       
   131 
       
   132 #define DEBUG_CODE_SECTION(a)
       
   133 
       
   134 #endif
       
   135 
       
   136 
       
   137 } // namespace UserPromptService
       
   138 
       
   139 #endif // UPSLOG_H