sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Print functions used in debug mode sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #ifndef UPSLOG_H sl@0: #define UPSLOG_H sl@0: sl@0: #include sl@0: sl@0: class TTruncateOverflowHandler16 : public TDes16Overflow sl@0: { sl@0: public: sl@0: virtual void Overflow(TDes16& aDes); sl@0: }; sl@0: sl@0: inline void TTruncateOverflowHandler16::Overflow(TDes16&) sl@0: { sl@0: sl@0: } sl@0: sl@0: class TTruncateOverflowHandler8 : public TDes8Overflow sl@0: { sl@0: public: sl@0: virtual void Overflow(TDes8& aDes); sl@0: }; sl@0: sl@0: inline void TTruncateOverflowHandler8::Overflow(TDes8&) sl@0: { sl@0: sl@0: } sl@0: sl@0: namespace UserPromptService sl@0: { sl@0: sl@0: #ifdef _DEBUG sl@0: sl@0: #define DEBUG_PRINTF(a) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a);} sl@0: #define DEBUG_PRINTF2(a, b) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b);} sl@0: #define DEBUG_PRINTF3(a, b, c) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c);} sl@0: #define DEBUG_PRINTF4(a, b, c, d) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d);} sl@0: #define DEBUG_PRINTF5(a, b, c, d, e) {UserPromptService::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);} sl@0: sl@0: #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) sl@0: sl@0: // UTF-8 overload of the DebufPrintf method. Should be used by default, sl@0: // since it's cheaper both in CPU cycles and stack space. sl@0: sl@0: inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue aFormat, ...) sl@0: { sl@0: TTruncateOverflowHandler8 overflowHandler8; sl@0: VA_LIST list; sl@0: VA_START(list, aFormat); sl@0: sl@0: TTime now; sl@0: now.HomeTime(); sl@0: sl@0: TBuf8<512> buffer; sl@0: _LIT8(KUserPromptServiceLogPrefix, "[UPS] "); sl@0: _LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- "); sl@0: buffer.Append(KUserPromptServiceLogPrefix); sl@0: buffer.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile); sl@0: buffer.AppendFormatList(aFormat, list, &overflowHandler8); sl@0: _LIT8(KUserPromptServiceMsgEnd, "\r\n"); sl@0: if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length())) sl@0: { sl@0: buffer.Append(KUserPromptServiceMsgEnd); sl@0: } sl@0: sl@0: RDebug::RawPrint(buffer); sl@0: sl@0: VA_END(list); sl@0: } sl@0: sl@0: // Unicode DebugPrintf overload sl@0: inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue aFormat, ...) sl@0: { sl@0: TTruncateOverflowHandler16 overflowHandler16; sl@0: VA_LIST list; sl@0: VA_START(list, aFormat); sl@0: sl@0: TTime now; sl@0: now.HomeTime(); sl@0: sl@0: TBuf8<256> header; sl@0: _LIT8(KUserPromptServiceLogPrefix, "[UPS] "); sl@0: _LIT8(KUserPromptServiceLineFileFormat, "%Ld Line: % 5d, File: %s -- "); sl@0: header.Append(KUserPromptServiceLogPrefix); sl@0: header.AppendFormat(KUserPromptServiceLineFileFormat, now.Int64(), aLine, aFile); sl@0: sl@0: TBuf<256> buffer; sl@0: buffer.Copy(header); sl@0: buffer.AppendFormatList(aFormat, list , &overflowHandler16); sl@0: _LIT(KUserPromptServiceMsgEnd, "\r\n"); sl@0: if(buffer.MaxLength() >= (buffer.Length() + KUserPromptServiceMsgEnd().Length())) sl@0: { sl@0: buffer.Append(KUserPromptServiceMsgEnd); sl@0: } sl@0: sl@0: RDebug::RawPrint(buffer); sl@0: sl@0: VA_END(list); sl@0: } sl@0: sl@0: #else sl@0: sl@0: #define DEBUG_PRINTF(a) sl@0: #define DEBUG_PRINTF2(a, b) sl@0: #define DEBUG_PRINTF3(a, b, c) sl@0: #define DEBUG_PRINTF4(a, b, c, d) sl@0: #define DEBUG_PRINTF5(a, b, c, d, e) sl@0: sl@0: #define DEBUG_CODE_SECTION(a) sl@0: sl@0: #endif sl@0: sl@0: sl@0: } // namespace UserPromptService sl@0: sl@0: #endif // UPSLOG_H