|
1 /* |
|
2 * Copyright (c) 2005-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 "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: Debug utility for SeCon components. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef _SECON_DEBUG_H |
|
20 #define _SECON_DEBUG_H |
|
21 |
|
22 #ifdef _DEBUG |
|
23 |
|
24 #ifdef __WINS__ |
|
25 // Enable file logging |
|
26 #define __FLOGGING__ |
|
27 #endif //__WINS__ |
|
28 |
|
29 #include <e32svr.h> |
|
30 #ifdef __FLOGGING__ |
|
31 #include <f32file.h> |
|
32 #include <flogger.h> |
|
33 #endif |
|
34 |
|
35 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
36 { |
|
37 public: |
|
38 void Overflow(TDes16& /*aDes*/) {} |
|
39 }; |
|
40 |
|
41 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
42 { |
|
43 public: |
|
44 void Overflow(TDes8& /*aDes*/) {} |
|
45 }; |
|
46 |
|
47 _LIT( KLogDir, "SECON" ); |
|
48 _LIT( KLogFile, "SeconDebug.txt" ); |
|
49 |
|
50 _LIT(KTracePrefix16, "[SeCon] "); |
|
51 _LIT8(KTracePrefix8, "[SeCon] "); |
|
52 _LIT8(KFuncEntryFormat8, "%S : Begin"); |
|
53 _LIT8(KFuncExitFormat8, "%S : End"); |
|
54 _LIT8(KFuncReturnFormat8, "%S : End, return: %d"); |
|
55 _LIT8(KFuncFormat8, "><%S"); |
|
56 |
|
57 const TInt KMaxLogLineLength = 512; |
|
58 |
|
59 // old function loggin macros |
|
60 #define LOGGER_ENTERFN( name ) {TRACE_FUNC_ENTRY;} |
|
61 #define LOGGER_LEAVEFN( name ) {TRACE_FUNC_EXIT;} |
|
62 |
|
63 #define LOGGER_WRITE( text ) {_LIT( KTemp, text ); FPrint( KTemp );} |
|
64 #define LOGGER_WRITE_1( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );} |
|
65 #define LOGGER_WRITE8_1( text,par1 ) {_LIT8( KTemp, text ); FPrint( KTemp, par1 );} |
|
66 #define LOGGER_WRITE_2( text,par1,par2 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );} |
|
67 #define LOGGER_WRITE_3( text,par1,par2,par3 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2, par3 );} |
|
68 |
|
69 // New function logging macros |
|
70 #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);} |
|
71 #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);} |
|
72 #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);} |
|
73 |
|
74 #define TRACE_FUNC_RET( number ) {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncReturnFormat8, &ptr8, number);} |
|
75 // Declare the FPrint function |
|
76 inline void FPrint( TRefByValue<const TDesC16> aFmt, ...) |
|
77 { |
|
78 VA_LIST list; |
|
79 VA_START(list,aFmt); |
|
80 #ifdef __FLOGGING__ |
|
81 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list ); |
|
82 #endif |
|
83 TBuf16<KMaxLogLineLength> theFinalString; |
|
84 theFinalString.Append(KTracePrefix16); |
|
85 TOverflowTruncate16 overflow; |
|
86 theFinalString.AppendFormatList(aFmt,list,&overflow); |
|
87 RDebug::Print(theFinalString); |
|
88 } |
|
89 |
|
90 // Declare the FPrint function |
|
91 inline void FPrint(TRefByValue<const TDesC8> aFmt, ...) |
|
92 { |
|
93 VA_LIST list; |
|
94 VA_START(list, aFmt); |
|
95 #ifdef __FLOGGING__ |
|
96 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
97 #endif |
|
98 TOverflowTruncate8 overflow; |
|
99 TBuf8<KMaxLogLineLength> buf8; |
|
100 buf8.Append(KTracePrefix8); |
|
101 buf8.AppendFormatList(aFmt, list, &overflow); |
|
102 TBuf16<KMaxLogLineLength> buf16(buf8.Length()); |
|
103 buf16.Copy(buf8); |
|
104 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
105 RDebug::Print(tmpFmt, &buf16); |
|
106 } |
|
107 #else |
|
108 |
|
109 // No loggings --> reduced code size |
|
110 |
|
111 #define LOGGER_ENTERFN( name ) |
|
112 #define LOGGER_LEAVEFN( name ) |
|
113 #define LOGGER_WRITE( text ) |
|
114 #define LOGGER_WRITE_1( text, par1 ) |
|
115 #define LOGGER_WRITE8_1( text, par1 ) |
|
116 #define LOGGER_WRITE_2( text, par1, par2 ) |
|
117 #define LOGGER_WRITE_3( text, par1, par2, par3 ) |
|
118 #define TRACE_FUNC_ENTRY |
|
119 #define TRACE_FUNC_EXIT |
|
120 #define TRACE_FUNC |
|
121 #define TRACE_FUNC_RET( number ) |
|
122 |
|
123 #endif //_DEBUG |
|
124 |
|
125 #endif // SECON_DEBUG_H |
|
126 |
|
127 // End of file |
|
128 |