os/security/authorisation/userpromptservice/inc_private/upslog.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Print functions used in debug mode 
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file 
sl@0
    22
 @internalComponent 
sl@0
    23
*/
sl@0
    24
 
sl@0
    25
#ifndef UPSLOG_H
sl@0
    26
#define UPSLOG_H
sl@0
    27
sl@0
    28
#include <e32debug.h>
sl@0
    29
sl@0
    30
class TTruncateOverflowHandler16 : public TDes16Overflow
sl@0
    31
	{
sl@0
    32
	public:
sl@0
    33
		virtual void Overflow(TDes16& aDes);
sl@0
    34
	};
sl@0
    35
	
sl@0
    36
inline void TTruncateOverflowHandler16::Overflow(TDes16&)
sl@0
    37
	{
sl@0
    38
sl@0
    39
	}
sl@0
    40
	
sl@0
    41
class TTruncateOverflowHandler8 : public TDes8Overflow
sl@0
    42
	{
sl@0
    43
	public:
sl@0
    44
		virtual void Overflow(TDes8& aDes);
sl@0
    45
	};
sl@0
    46
	
sl@0
    47
inline void TTruncateOverflowHandler8::Overflow(TDes8&)
sl@0
    48
	{
sl@0
    49
   
sl@0
    50
	}
sl@0
    51
sl@0
    52
namespace UserPromptService
sl@0
    53
{
sl@0
    54
sl@0
    55
#ifdef _DEBUG
sl@0
    56
sl@0
    57
#define DEBUG_PRINTF(a) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a);}
sl@0
    58
#define DEBUG_PRINTF2(a, b) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b);}
sl@0
    59
#define DEBUG_PRINTF3(a, b, c) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c);}
sl@0
    60
#define DEBUG_PRINTF4(a, b, c, d) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d);}
sl@0
    61
#define DEBUG_PRINTF5(a, b, c, d, e) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);}
sl@0
    62
sl@0
    63
#define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) 
sl@0
    64
sl@0
    65
// UTF-8 overload of the DebufPrintf method. Should be used by default,
sl@0
    66
// since it's cheaper both in CPU cycles and stack space.
sl@0
    67
sl@0
    68
inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...)
sl@0
    69
	{
sl@0
    70
	TTruncateOverflowHandler8 overflowHandler8;
sl@0
    71
	VA_LIST list;
sl@0
    72
	VA_START(list, aFormat);
sl@0
    73
	
sl@0
    74
	TTime now;
sl@0
    75
	now.HomeTime();
sl@0
    76
	
sl@0
    77
	TBuf8<512> buffer;
sl@0
    78
	_LIT8(KUserPromptServiceLogPrefix, "[UPS] ");
sl@0
    79
	_LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
sl@0
    80
	buffer.Append(KUserPromptServiceLogPrefix);
sl@0
    81
	buffer.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
sl@0
    82
	buffer.AppendFormatList(aFormat, list, &overflowHandler8);
sl@0
    83
	_LIT8(KUserPromptServiceMsgEnd, "\r\n");
sl@0
    84
	if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
sl@0
    85
		{
sl@0
    86
		buffer.Append(KUserPromptServiceMsgEnd);
sl@0
    87
		}
sl@0
    88
	
sl@0
    89
	RDebug::RawPrint(buffer);
sl@0
    90
	
sl@0
    91
	VA_END(list);
sl@0
    92
	}
sl@0
    93
	
sl@0
    94
// Unicode DebugPrintf overload
sl@0
    95
inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...)
sl@0
    96
	{
sl@0
    97
	TTruncateOverflowHandler16 overflowHandler16;
sl@0
    98
	VA_LIST list;
sl@0
    99
	VA_START(list, aFormat);
sl@0
   100
	
sl@0
   101
	TTime now;
sl@0
   102
	now.HomeTime();
sl@0
   103
	
sl@0
   104
	TBuf8<256> header;
sl@0
   105
	_LIT8(KUserPromptServiceLogPrefix, "[UPS] ");
sl@0
   106
	_LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
sl@0
   107
	header.Append(KUserPromptServiceLogPrefix);
sl@0
   108
	header.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
sl@0
   109
	
sl@0
   110
	TBuf<256> buffer;
sl@0
   111
	buffer.Copy(header);
sl@0
   112
	buffer.AppendFormatList(aFormat, list , &overflowHandler16);
sl@0
   113
	_LIT(KUserPromptServiceMsgEnd, "\r\n");
sl@0
   114
	if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
sl@0
   115
		{
sl@0
   116
		buffer.Append(KUserPromptServiceMsgEnd);
sl@0
   117
		}
sl@0
   118
	
sl@0
   119
	RDebug::RawPrint(buffer);
sl@0
   120
	
sl@0
   121
	VA_END(list);
sl@0
   122
	}
sl@0
   123
sl@0
   124
#else
sl@0
   125
sl@0
   126
#define DEBUG_PRINTF(a)
sl@0
   127
#define DEBUG_PRINTF2(a, b)
sl@0
   128
#define DEBUG_PRINTF3(a, b, c)
sl@0
   129
#define DEBUG_PRINTF4(a, b, c, d)
sl@0
   130
#define DEBUG_PRINTF5(a, b, c, d, e)
sl@0
   131
sl@0
   132
#define DEBUG_CODE_SECTION(a)
sl@0
   133
sl@0
   134
#endif
sl@0
   135
sl@0
   136
sl@0
   137
} // namespace UserPromptService
sl@0
   138
sl@0
   139
#endif // UPSLOG_H