|
1 /* |
|
2 * Copyright (c) 2004-2005 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: |
|
15 * Central place for nice debug-type macros & functions |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef BT_SAP_DEBUG_H |
|
21 #define BT_SAP_DEBUG_H |
|
22 |
|
23 #ifdef _DEBUG |
|
24 |
|
25 // Debugging options |
|
26 |
|
27 #define KBTSAP_TRACE_ERROR 0x00000001 // Print errors traces |
|
28 #define KBTSAP_TRACE_FUNCTIONS 0x00000002 // Print function traces |
|
29 #define KBTSAP_TRACE_STM 0x00000004 // Print state machine traces |
|
30 #define KBTSAP_TRACE_MEMORY 0x00000008 // Print memory traces |
|
31 #define KBTSAP_TRACE_INFO 0x00000010 // Print informational traces |
|
32 |
|
33 // Add desired tracing levels below |
|
34 const TInt KBTSapDebugMask = KBTSAP_TRACE_ERROR | |
|
35 KBTSAP_TRACE_FUNCTIONS | |
|
36 KBTSAP_TRACE_STM | |
|
37 KBTSAP_TRACE_MEMORY | |
|
38 KBTSAP_TRACE_INFO; |
|
39 |
|
40 #ifdef __WINS__ |
|
41 // File logging for WINS |
|
42 #define __FLOGGING__ |
|
43 #else |
|
44 // RDebug logging for target HW |
|
45 #define __CLOGGING__ |
|
46 #endif |
|
47 |
|
48 #ifdef __FLOGGING__ |
|
49 |
|
50 #include <e32std.h> |
|
51 #include <f32file.h> |
|
52 #include <flogger.h> |
|
53 |
|
54 _LIT(KLogFile,"BTSapLog.txt"); |
|
55 _LIT(KLogDir,"BT"); |
|
56 |
|
57 inline void TraceMem() |
|
58 { |
|
59 #ifdef MEMTRACE |
|
60 TInt size; |
|
61 User::Heap().AllocSize(size); |
|
62 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, _L("Memory usage: %d high: %d"), size, User::Heap().Size()); |
|
63 #endif |
|
64 } |
|
65 |
|
66 inline void BTSapPrintTrace(const TRefByValue<const TDesC8> aFmt, ...) |
|
67 { |
|
68 VA_LIST list; |
|
69 VA_START(list,aFmt); |
|
70 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
71 TraceMem(); |
|
72 } |
|
73 |
|
74 inline void BTSapPrintTrace(const TRefByValue<const TDesC16> aFmt, ...) |
|
75 { |
|
76 VA_LIST list; |
|
77 VA_START(list,aFmt); |
|
78 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
79 TraceMem(); |
|
80 } |
|
81 |
|
82 #else // __CLOGGING__ |
|
83 |
|
84 #include <e32svr.h> |
|
85 |
|
86 inline void BTSapPrintTrace(const TRefByValue<const TDesC16> aFmt, ...) |
|
87 { |
|
88 VA_LIST list; |
|
89 VA_START(list,aFmt); |
|
90 TInt tmpInt = VA_ARG(list, TInt); |
|
91 TInt tmpInt2 = VA_ARG(list, TInt); |
|
92 TInt tmpInt3 = VA_ARG(list, TInt); |
|
93 VA_END(list); |
|
94 RDebug::Print(aFmt, tmpInt, tmpInt2, tmpInt3); |
|
95 } |
|
96 |
|
97 inline void BTSapPrintTrace(TRefByValue<const TDesC8> aFmt, ...) |
|
98 { |
|
99 VA_LIST list; |
|
100 VA_START(list, aFmt); |
|
101 TBuf8<256> buf8; |
|
102 buf8.AppendFormatList(aFmt, list); |
|
103 |
|
104 TBuf16<256> buf16(buf8.Length()); |
|
105 buf16.Copy(buf8); |
|
106 |
|
107 TRefByValue<const TDesC> tmpFmt(_L("%S")); |
|
108 RDebug::Print(tmpFmt, &buf16); |
|
109 } |
|
110 |
|
111 #endif // __CLOGGING__ |
|
112 |
|
113 inline void BTSapPrintHex(const TRefByValue<const TDesC8> aFmt, ...) |
|
114 { |
|
115 VA_LIST list; |
|
116 VA_START(list, aFmt); |
|
117 TDesC8* aValue = VA_ARG(list, TDesC8*); |
|
118 VA_END(list); |
|
119 |
|
120 TBuf8<85> buf8; |
|
121 for (TInt i = 0; i < aValue->Length(); i ++) |
|
122 { |
|
123 if (buf8.Length() > 80) break; |
|
124 buf8.AppendNumFixedWidth((*aValue)[i], EHex, 2); |
|
125 buf8.Append(0x20); |
|
126 } |
|
127 |
|
128 BTSapPrintTrace(aFmt, &buf8); |
|
129 } |
|
130 |
|
131 #define BTSAP_TRACE_OPT(a,p) { if((KBTSapDebugMask) & (a)) (p); } |
|
132 |
|
133 #else // NO DEBUG |
|
134 |
|
135 #define BTSAP_TRACE_OPT(a,p) |
|
136 |
|
137 #endif // _DEBUG |
|
138 |
|
139 #endif // BT_SAP_DEBUG_H |
|
140 |
|
141 // End of File |