sl@0: /* sl@0: * Copyright (c) 2007-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: * Implements common print functions used in debug mode for all security components. sl@0: * A component that wants to use these common debugging functions should define its sl@0: * own log header file and include this header file. In the component's header file, sl@0: * the followings should be defined: sl@0: * _LIT8(KComponentName, "[TheComponentName]"); sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: sl@0: #ifndef SECURITYLOG_H sl@0: #define SECURITYLOG_H sl@0: sl@0: #include sl@0: 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: #ifdef _DEBUG sl@0: sl@0: const TInt KMaxLogBufferSize8 = 512; sl@0: const TInt KMaxLogBufferSize16 = 256; sl@0: sl@0: #define SEC_DEBUG_PRINTF(x, a) {::CommonDebugPrintf(x, __LINE__, __FILE__, a);} sl@0: #define SEC_DEBUG_PRINTF2(x, a, b) {::CommonDebugPrintf(x, __LINE__, __FILE__, a, b);} sl@0: #define SEC_DEBUG_PRINTF3(x, a, b, c) {::CommonDebugPrintf(x, __LINE__, __FILE__, a, b, c);} sl@0: #define SEC_DEBUG_PRINTF4(x, a, b, c, d) {::CommonDebugPrintf(x, __LINE__, __FILE__, a, b, c, d);} sl@0: #define SEC_DEBUG_PRINTF5(x, a, b, c, d, e) {::CommonDebugPrintf(x, __LINE__, __FILE__, a, b, c, d, e);} sl@0: sl@0: #define SEC_DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) sl@0: sl@0: inline void FileFormatLine(TDes8& aBuffer, const TDesC8& aComponent, TInt aLine, char* aFile) sl@0: { sl@0: TTime now; sl@0: now.HomeTime(); sl@0: sl@0: _LIT8(KLineFileFormat, "%Ld Line: % 5d, File: %s -- "); sl@0: aBuffer.Append(aComponent); sl@0: aBuffer.AppendFormat(KLineFileFormat, now.Int64(), aLine, aFile); sl@0: } sl@0: sl@0: // UTF-8 overload of the CoomonDebufPrintf method. Should be used by default, sl@0: // since it's cheaper both in CPU cycles and stack space. sl@0: inline void CommonDebugPrintf(const TDesC8& aComponent, 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: TBuf8 buffer; sl@0: FileFormatLine(buffer, aComponent, aLine, aFile); sl@0: sl@0: buffer.AppendFormatList(aFormat, list, &overflowHandler8); sl@0: _LIT8(KLogMsgEnd, "\r\n"); sl@0: if(buffer.MaxLength() >= (buffer.Length() + KLogMsgEnd().Length())) sl@0: { sl@0: buffer.Append(KLogMsgEnd); sl@0: } sl@0: sl@0: RDebug::RawPrint(buffer); sl@0: sl@0: VA_END(list); sl@0: } sl@0: sl@0: // Unicode CommonDebufPrintf overload sl@0: inline void CommonDebugPrintf(const TDesC8& aComponent, 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: TBuf8 header; sl@0: FileFormatLine(header, aComponent, aLine, aFile); sl@0: sl@0: TBuf buffer; sl@0: buffer.Copy(header); sl@0: buffer.AppendFormatList(aFormat, list , &overflowHandler16); sl@0: sl@0: _LIT(KLogMsgEnd, "\r\n"); sl@0: if(buffer.MaxLength() >= (buffer.Length() + KLogMsgEnd().Length())) sl@0: { sl@0: buffer.Append(KLogMsgEnd); 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 SEC_DEBUG_PRINTF(x, a) sl@0: #define SEC_DEBUG_PRINTF2(x, a, b) sl@0: #define SEC_DEBUG_PRINTF3(x, a, b, c) sl@0: #define SEC_DEBUG_PRINTF4(x, a, b, c, d) sl@0: #define SEC_DEBUG_PRINTF5(x, a, b, c, d, e) sl@0: sl@0: #define SEC_DEBUG_CODE_SECTION(a) sl@0: sl@0: #endif // _DEBUG sl@0: sl@0: #endif // SECURITYLOG_H