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