1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/authorisation/userpromptservice/inc_private/upslog.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,139 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Print functions used in debug mode
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalComponent
1.26 +*/
1.27 +
1.28 +#ifndef UPSLOG_H
1.29 +#define UPSLOG_H
1.30 +
1.31 +#include <e32debug.h>
1.32 +
1.33 +class TTruncateOverflowHandler16 : public TDes16Overflow
1.34 + {
1.35 + public:
1.36 + virtual void Overflow(TDes16& aDes);
1.37 + };
1.38 +
1.39 +inline void TTruncateOverflowHandler16::Overflow(TDes16&)
1.40 + {
1.41 +
1.42 + }
1.43 +
1.44 +class TTruncateOverflowHandler8 : public TDes8Overflow
1.45 + {
1.46 + public:
1.47 + virtual void Overflow(TDes8& aDes);
1.48 + };
1.49 +
1.50 +inline void TTruncateOverflowHandler8::Overflow(TDes8&)
1.51 + {
1.52 +
1.53 + }
1.54 +
1.55 +namespace UserPromptService
1.56 +{
1.57 +
1.58 +#ifdef _DEBUG
1.59 +
1.60 +#define DEBUG_PRINTF(a) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a);}
1.61 +#define DEBUG_PRINTF2(a, b) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b);}
1.62 +#define DEBUG_PRINTF3(a, b, c) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c);}
1.63 +#define DEBUG_PRINTF4(a, b, c, d) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d);}
1.64 +#define DEBUG_PRINTF5(a, b, c, d, e) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);}
1.65 +
1.66 +#define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; })
1.67 +
1.68 +// UTF-8 overload of the DebufPrintf method. Should be used by default,
1.69 +// since it's cheaper both in CPU cycles and stack space.
1.70 +
1.71 +inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...)
1.72 + {
1.73 + TTruncateOverflowHandler8 overflowHandler8;
1.74 + VA_LIST list;
1.75 + VA_START(list, aFormat);
1.76 +
1.77 + TTime now;
1.78 + now.HomeTime();
1.79 +
1.80 + TBuf8<512> buffer;
1.81 + _LIT8(KUserPromptServiceLogPrefix, "[UPS] ");
1.82 + _LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
1.83 + buffer.Append(KUserPromptServiceLogPrefix);
1.84 + buffer.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
1.85 + buffer.AppendFormatList(aFormat, list, &overflowHandler8);
1.86 + _LIT8(KUserPromptServiceMsgEnd, "\r\n");
1.87 + if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
1.88 + {
1.89 + buffer.Append(KUserPromptServiceMsgEnd);
1.90 + }
1.91 +
1.92 + RDebug::RawPrint(buffer);
1.93 +
1.94 + VA_END(list);
1.95 + }
1.96 +
1.97 +// Unicode DebugPrintf overload
1.98 +inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...)
1.99 + {
1.100 + TTruncateOverflowHandler16 overflowHandler16;
1.101 + VA_LIST list;
1.102 + VA_START(list, aFormat);
1.103 +
1.104 + TTime now;
1.105 + now.HomeTime();
1.106 +
1.107 + TBuf8<256> header;
1.108 + _LIT8(KUserPromptServiceLogPrefix, "[UPS] ");
1.109 + _LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- ");
1.110 + header.Append(KUserPromptServiceLogPrefix);
1.111 + header.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile);
1.112 +
1.113 + TBuf<256> buffer;
1.114 + buffer.Copy(header);
1.115 + buffer.AppendFormatList(aFormat, list , &overflowHandler16);
1.116 + _LIT(KUserPromptServiceMsgEnd, "\r\n");
1.117 + if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length()))
1.118 + {
1.119 + buffer.Append(KUserPromptServiceMsgEnd);
1.120 + }
1.121 +
1.122 + RDebug::RawPrint(buffer);
1.123 +
1.124 + VA_END(list);
1.125 + }
1.126 +
1.127 +#else
1.128 +
1.129 +#define DEBUG_PRINTF(a)
1.130 +#define DEBUG_PRINTF2(a, b)
1.131 +#define DEBUG_PRINTF3(a, b, c)
1.132 +#define DEBUG_PRINTF4(a, b, c, d)
1.133 +#define DEBUG_PRINTF5(a, b, c, d, e)
1.134 +
1.135 +#define DEBUG_CODE_SECTION(a)
1.136 +
1.137 +#endif
1.138 +
1.139 +
1.140 +} // namespace UserPromptService
1.141 +
1.142 +#endif // UPSLOG_H