author | hgs |
Fri, 14 May 2010 04:41:45 +0300 | |
changeset 40 | 2c62ef3caffd |
parent 18 | 578830873419 |
child 30 | 759dc5235cdb |
permissions | -rw-r--r-- |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
40 | 2 |
* Copyright (c) 2010 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 |
* |
|
16 |
*/ |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#ifndef EMAILTRACE_H |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#define EMAILTRACE_H |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
|
40 | 21 |
#include <e32debug.h> |
22 |
#include <qdebug.h> |
|
23 |
#include <qfile.h> |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
40 | 25 |
/* |
26 |
* The macros COMMENT_TRACES, ERROR_TRACES, and FUNCTION_TRACES control which |
|
27 |
* trace messages are printed. The trace message logging is controlled with |
|
28 |
* the LOG_TO_FILE macro, whereas the LOG_FILE macro defines which file is to |
|
29 |
* be used in logging. The print_trace() helper function implements printing. |
|
30 |
* If LOG_TO_FILE is zero or the LOG_FILE cannot be opened, the messages are |
|
31 |
* printed to qDebug(). |
|
32 |
*/ |
|
33 |
#if defined(DEBUG) || defined(_DEBUG) |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
|
40 | 35 |
#define COMMENT_TRACES 1 |
36 |
#define ERROR_TRACES 1 |
|
37 |
#define FUNCTION_TRACES 1 |
|
38 |
||
39 |
#if COMMENT_TRACES || ERROR_TRACES || FUNCTION_TRACES |
|
40 |
||
41 |
#define LOG_TO_FILE 0 |
|
42 |
#define LOG_FILE "c:/logs/nmail_trace.log" |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
|
40 | 44 |
inline void print_trace(const QString& msg) |
45 |
{ |
|
46 |
QFile out(LOG_FILE); |
|
47 |
if (LOG_TO_FILE && out.open(QIODevice::Append | QIODevice::Text)) { |
|
48 |
QDebug(&out) << "[Nmail]" << msg; |
|
49 |
out.putChar('\n'); |
|
50 |
out.close(); |
|
51 |
} else { |
|
52 |
qDebug() << "[Nmail]" << msg; |
|
53 |
} |
|
54 |
} |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
|
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
#endif |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
|
40 | 58 |
#endif /* DEBUG */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
|
40 | 60 |
/* |
61 |
* The function NM_COMMENT() prints a trace message. The INFO macros are |
|
62 |
* provided for legacy compatibility. They are deprecated and should not be |
|
63 |
* used. If sprintf() type of formatting is desired, consider using QString:: |
|
64 |
* arg() or QTextStream. |
|
65 |
*/ |
|
66 |
#if COMMENT_TRACES |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
|
40 | 68 |
inline void NM_COMMENT(const QString& msg) |
69 |
{ |
|
70 |
print_trace("COMMENT : " + msg); |
|
71 |
} |
|
72 |
#define INFO(msg) NM_COMMENT(msg) |
|
73 |
#define INFO_1(msg,arg1)\ |
|
74 |
do {\ |
|
75 |
QString __msg;\ |
|
76 |
__msg.sprintf(msg,arg1);\ |
|
77 |
NM_COMMENT(__msg);\ |
|
78 |
} while (0) |
|
79 |
#define INFO_2(msg,arg1,arg2)\ |
|
80 |
do {\ |
|
81 |
QString __msg;\ |
|
82 |
__msg.sprintf(msg,arg1,arg2);\ |
|
83 |
NM_COMMENT(__msg);\ |
|
84 |
} while (0) |
|
85 |
#define INFO_3(msg,arg1,arg2,arg3)\ |
|
86 |
do {\ |
|
87 |
QString __msg;\ |
|
88 |
__msg.sprintf(msg,arg1,arg2,arg3);\ |
|
89 |
NM_COMMENT(__msg);\ |
|
90 |
} while (0) |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
|
40 | 92 |
#else |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
|
40 | 94 |
#define NM_COMMENT(msg) |
95 |
#define INFO(msg) |
|
96 |
#define INFO_1(msg,arg1) |
|
97 |
#define INFO_2(msg,arg1,arg2) |
|
98 |
#define INFO_3(msg,arg1,arg2,arg3) |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
99 |
|
40 | 100 |
#endif /* COMMENT_TRACES */ |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
|
40 | 102 |
/* |
103 |
* The function NM_ERROR() prints its second argument if the first argument |
|
104 |
* is non-zero. The ERROR macros are provided for legacy compatibility. They |
|
105 |
* are deprecated and should not be used. If sprintf() type of formatting is |
|
106 |
* desired, consider using QString::arg() or QTextStream. |
|
107 |
*/ |
|
108 |
#if ERROR_TRACES |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
109 |
|
40 | 110 |
inline void NM_ERROR(int err, const QString& msg) |
111 |
{ |
|
112 |
if (err) { |
|
113 |
print_trace("ERROR : " + msg); |
|
114 |
} |
|
115 |
} |
|
116 |
#define ERROR(err,msg) NM_ERROR(err,msg) |
|
117 |
#define ERROR_1(err,msg,arg1)\ |
|
118 |
do {\ |
|
119 |
QString __msg;\ |
|
120 |
__msg.sprintf(msg,arg1);\ |
|
121 |
NM_ERROR(err,__msg);\ |
|
122 |
} while (0) |
|
123 |
#define ERROR_2(err,msg,arg1,arg2)\ |
|
124 |
do {\ |
|
125 |
QString __msg;\ |
|
126 |
__msg.sprintf(msg,arg1,arg2);\ |
|
127 |
NM_ERROR(err,__msg);\ |
|
128 |
} while(0) |
|
129 |
#define ERROR_3(err,msg,arg1,arg2,arg3)\ |
|
130 |
do {\ |
|
131 |
QString __msg;\ |
|
132 |
__msg.sprintf(msg,arg1,srg2,arg3);\ |
|
133 |
NM_ERROR(err,__msg);\ |
|
134 |
} while(0) |
|
135 |
#define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
|
136 |
#define ERROR_GEN_1(msg,arg1) ERROR_1(KErrGeneral,msg,arg1) |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
|
40 | 138 |
#else |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
|
40 | 140 |
#define NM_ERROR(err,msg) |
141 |
#define ERROR(err,msg) |
|
142 |
#define ERROR_1(err,msg,arg1) |
|
143 |
#define ERROR_2(err,msg,arg1,arg2) |
|
144 |
#define ERROR_3(err,msg,arg1,arg2,arg3) |
|
145 |
#define ERROR_GEN(msg) |
|
146 |
#define ERROR_GEN_1(msg,arg1) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
|
40 | 148 |
#endif /* ERROR_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
149 |
|
40 | 150 |
/* |
151 |
* The macro NM_FUNCTION, when used inside a function body, enables tracing |
|
152 |
* for a function. Trace messages with labels ENTER and RETURN are printed |
|
153 |
* when entering into and returning from a function, respectively. In case of |
|
154 |
* an exception or a Symbian leave, a message with label UNWIND is printed |
|
155 |
* (UNWIND stands for stack unwinding). The FUNC_LOG macro is provided for |
|
156 |
* legacy compatibility. It is deprecated and should not be used. |
|
157 |
*/ |
|
158 |
#if FUNCTION_TRACES |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
159 |
|
40 | 160 |
class __ftracer |
161 |
{ |
|
162 |
public: |
|
163 |
__ftracer(const QString& _fn) |
|
164 |
: fn(_fn) |
|
165 |
{ |
|
166 |
print_trace("ENTER : " + fn); |
|
167 |
} |
|
168 |
~__ftracer() |
|
169 |
{ |
|
170 |
if (std::uncaught_exception()) { |
|
171 |
print_trace("UNWIND : " + fn); |
|
172 |
} else { |
|
173 |
print_trace("RETURN : " + fn); |
|
174 |
} |
|
175 |
} |
|
176 |
private: |
|
177 |
QString fn; |
|
178 |
}; |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
179 |
|
40 | 180 |
#define NM_FUNCTION __ftracer __ft(__PRETTY_FUNCTION__); |
181 |
#define FUNC_LOG NM_FUNCTION |
|
182 |
||
183 |
#else |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
184 |
|
40 | 185 |
#define NM_FUNCTION |
186 |
#define FUNC_LOG |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
187 |
|
40 | 188 |
#endif /* FUNCTION TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
40 | 190 |
#endif /* EMAILTRACE_H */ |