|
1 /* |
|
2 * Copyright (c) 2008 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: Logging utils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef HGLOGUTILS_H |
|
20 #define HGLOGUTILS_H |
|
21 |
|
22 /** |
|
23 * NOTE: This file contains the logic related to logging. Change only if you |
|
24 * know what you're doing. |
|
25 */ |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 #ifdef _DEBUG |
|
37 |
|
38 #include <e32debug.h> |
|
39 #include <e32std.h> |
|
40 |
|
41 static const TUint HGLOGERR = 2; /**< Used to create an error message */ |
|
42 |
|
43 // These macros are real macros, that should be used. For temporary purposes, these |
|
44 // are left out and the logging is done by simple entry logging |
|
45 #define _HGLOG_UNCONTROLLED_INPUT_MSG L"%s%d[%x:%x:%x]>%s UNCONTROLLED ENTRY!" |
|
46 #define _HGLOG_MULTIPLE_ENTRY_MSG L"%s%d[%x:%x:%x]%s ADDITIONAL ENTRY!" |
|
47 #define _HGLOG_UNCONTROLLER_EXIT_MSG L"%s%d[%x:%x:%x]<%s UNCONTROLLED EXIT!" |
|
48 #define _HGLOG_MULTIPLE_EXIT_MSG L"%s%d[%x:%x:%x]%s ADDITIONAL EXIT!" |
|
49 #define _HGLOG_TRAP_HARNESS_ENTRY L"_D%d[%x:%x:%x]TraceFramework: Entering trap harness" |
|
50 #define _HGLOG_TRAP_HARNESS_EXIT L"_D%d[%x:%x:%x]TraceFramework: Exiting trap harness" |
|
51 #define _HGLOG_TRAP_HARNESS_LEAVE L"_D%d[%x:%x:%x]TraceFramework: ---------- LEAVE OCCURRED !!! ---------- " |
|
52 #define _HGLOG_API_PREFIX L"_A" |
|
53 #define _HGLOG_LOCAL_PREFIX L"_L" |
|
54 |
|
55 /** |
|
56 * @file |
|
57 * trace_utils.h contains definitions needed for advanced tracing features. |
|
58 * Tracing can be customized using the following compile time flags: |
|
59 * - <b>_DEBUG</b> |
|
60 * - With this flag undefined, all traces are disabled |
|
61 * - <b>__KERNEL_MODE__</b> |
|
62 * - if kernel mode flag is defined, kernel macro variants are used (no unicode or shared heap related stuff, faster) |
|
63 * - <b>DISABLE_SYNTAX_CHECK</b> |
|
64 * - If this flag is defined, runtime syntax checking features are disabled from traces |
|
65 */ |
|
66 #ifndef DISABLE_SYNTAX_CHECK |
|
67 #define _MARK_ENTRY() _dc.inOk=ETrue |
|
68 #define _DOINCHK() _dc.DoInChk() |
|
69 #define _CHK_MULTIIN() _dc.ChkMultiIn() |
|
70 #define _CHK_MULTIOUT() _dc.ChkMultiOut() |
|
71 #define _MARK_EXIT() _dc.outOk=ETrue |
|
72 #else |
|
73 #define _MARK_ENTRY() |
|
74 #define _DOINCHK() |
|
75 #define _CHK_MULTIIN() |
|
76 #define _CHK_MULTIOUT() |
|
77 #define _MARK_EXIT() |
|
78 #endif // DISABLE_SYNTAX_CHECK |
|
79 |
|
80 /** For tracing */ |
|
81 #ifdef _HGLOG_RDEBUG |
|
82 #define _IT(a) (TPtrC((const TText *)(a))) |
|
83 #define _HGLOGPRINTER RDebug::Print |
|
84 |
|
85 /** For filedebug */ |
|
86 #else // _HGLOG_RDEBUG |
|
87 |
|
88 /** Includes */ |
|
89 #include <e32base.h> |
|
90 #include <e32std.h> |
|
91 #include <e32def.h> |
|
92 #include <e32svr.h> |
|
93 |
|
94 // both of headers defines KLogBufferSize |
|
95 #ifndef __COMMSDEBUGUTILITY_H__ |
|
96 #include <flogger.h> |
|
97 #endif |
|
98 |
|
99 #define _IT(a) KHgLogPath, KHgLogFile, EFileLoggingModeAppend, (TPtrC((const TText *)(a))) |
|
100 #define _HGLOGPRINTER RFileLogger::WriteFormat |
|
101 #endif // _HGLOG_RDEBUG |
|
102 |
|
103 class _THgLogContext |
|
104 { |
|
105 public: |
|
106 _THgLogContext( |
|
107 const TText* _fn, |
|
108 const TUint _id, |
|
109 const TUint _vis, |
|
110 const TUint _addr, |
|
111 const TUint _thdId, |
|
112 const TUint _category=0 ) |
|
113 : |
|
114 iFn(_fn), |
|
115 iId(_id), |
|
116 iApi((TBool)_vis), |
|
117 iAddr(_addr), |
|
118 iThdId(_thdId), |
|
119 iVis((_vis == 0 ? (TText*)_HGLOG_API_PREFIX : (TText*)_HGLOG_LOCAL_PREFIX)), |
|
120 iCategory(_category) |
|
121 #ifndef DISABLE_SYNTAX_CHECK |
|
122 ,outOk(EFalse), inOk(EFalse) |
|
123 #endif |
|
124 { |
|
125 } |
|
126 ~_THgLogContext() |
|
127 { |
|
128 #ifndef DISABLE_SYNTAX_CHECK |
|
129 do |
|
130 { |
|
131 DoInChk(); |
|
132 if (!outOk) |
|
133 { |
|
134 _HGLOGPRINTER(_IT(_HGLOG_UNCONTROLLER_EXIT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn); |
|
135 } |
|
136 } while (0); |
|
137 #endif // DISABLE_SYNTAX_CHECK |
|
138 } |
|
139 |
|
140 const TText* iFn; |
|
141 const TUint iId; |
|
142 const TText* iVis; |
|
143 const TUint iAddr; |
|
144 const TInt iThdId; |
|
145 const TBool iApi; |
|
146 const TUint iCategory; |
|
147 |
|
148 #ifndef DISABLE_SYNTAX_CHECK |
|
149 inline void DoInChk() |
|
150 { |
|
151 if (!inOk) |
|
152 { |
|
153 _HGLOGPRINTER(_IT(_HGLOG_UNCONTROLLED_INPUT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn); |
|
154 inOk = ETrue; |
|
155 } |
|
156 } |
|
157 |
|
158 inline void ChkMultiIn() |
|
159 { |
|
160 if (inOk) |
|
161 { |
|
162 _HGLOGPRINTER(_IT(_HGLOG_MULTIPLE_ENTRY_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn); |
|
163 } |
|
164 } |
|
165 |
|
166 inline void ChkMultiOut() |
|
167 { |
|
168 if (outOk) |
|
169 { |
|
170 _HGLOGPRINTER(_IT(_HGLOG_MULTIPLE_EXIT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn); |
|
171 } |
|
172 } |
|
173 |
|
174 TBool inOk; |
|
175 TBool outOk; |
|
176 #endif // DISABLE_SYNTAX_CHECK |
|
177 }; |
|
178 |
|
179 class _THgLogTrapHandler: public TTrapHandler |
|
180 { |
|
181 public: |
|
182 |
|
183 _THgLogTrapHandler(_THgLogContext& _context) : _dc( _context ) |
|
184 { |
|
185 RThread me; |
|
186 iThdId = (TInt)me.Id(); |
|
187 } |
|
188 void Trap() |
|
189 { |
|
190 _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_ENTRY), 0, HGLOGERR, iThdId, this); |
|
191 oldHandler->Trap(); |
|
192 } |
|
193 void UnTrap() |
|
194 { |
|
195 _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_EXIT), 0, HGLOGERR, iThdId, this); |
|
196 oldHandler->UnTrap(); |
|
197 } |
|
198 void Leave(TInt aValue) |
|
199 { |
|
200 _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_LEAVE), 0, HGLOGERR, iThdId, this); |
|
201 oldHandler->Leave(aValue); |
|
202 } |
|
203 TTrapHandler* oldHandler; |
|
204 private: |
|
205 _THgLogContext& _dc; |
|
206 TInt iThdId; |
|
207 }; |
|
208 |
|
209 #endif // _DEBUG |
|
210 |
|
211 #endif // HGLOGUTILS_H |