author | hgs |
Fri, 28 May 2010 13:56:43 +0300 | |
changeset 43 | 99bcbff212ad |
parent 40 | 2c62ef3caffd |
child 44 | c2d07d913565 |
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 |
/* |
43 | 61 |
* The function NM_COMMENT() prints a trace message. The INFO macros and the |
62 |
* NMLOG macro are provided for legacy compatibility. They are deprecated and |
|
63 |
* should not be used. If sprintf() type of formatting is desired, consider |
|
64 |
* using QString::arg() or QTextStream. |
|
40 | 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) |
|
43 | 91 |
#define NMLOG(msg) NM_COMMENT(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
|
40 | 93 |
#else |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
|
40 | 95 |
#define NM_COMMENT(msg) |
96 |
#define INFO(msg) |
|
97 |
#define INFO_1(msg,arg1) |
|
98 |
#define INFO_2(msg,arg1,arg2) |
|
99 |
#define INFO_3(msg,arg1,arg2,arg3) |
|
43 | 100 |
#define NMLOG(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
|
40 | 102 |
#endif /* COMMENT_TRACES */ |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
|
40 | 104 |
/* |
105 |
* The function NM_ERROR() prints its second argument if the first argument |
|
106 |
* is non-zero. The ERROR macros are provided for legacy compatibility. They |
|
107 |
* are deprecated and should not be used. If sprintf() type of formatting is |
|
108 |
* desired, consider using QString::arg() or QTextStream. |
|
109 |
*/ |
|
110 |
#if ERROR_TRACES |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
111 |
|
40 | 112 |
inline void NM_ERROR(int err, const QString& msg) |
113 |
{ |
|
114 |
if (err) { |
|
115 |
print_trace("ERROR : " + msg); |
|
116 |
} |
|
117 |
} |
|
118 |
#define ERROR(err,msg) NM_ERROR(err,msg) |
|
119 |
#define ERROR_1(err,msg,arg1)\ |
|
120 |
do {\ |
|
121 |
QString __msg;\ |
|
122 |
__msg.sprintf(msg,arg1);\ |
|
123 |
NM_ERROR(err,__msg);\ |
|
124 |
} while (0) |
|
125 |
#define ERROR_2(err,msg,arg1,arg2)\ |
|
126 |
do {\ |
|
127 |
QString __msg;\ |
|
128 |
__msg.sprintf(msg,arg1,arg2);\ |
|
129 |
NM_ERROR(err,__msg);\ |
|
130 |
} while(0) |
|
131 |
#define ERROR_3(err,msg,arg1,arg2,arg3)\ |
|
132 |
do {\ |
|
133 |
QString __msg;\ |
|
134 |
__msg.sprintf(msg,arg1,srg2,arg3);\ |
|
135 |
NM_ERROR(err,__msg);\ |
|
136 |
} while(0) |
|
137 |
#define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
|
138 |
#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
|
139 |
|
40 | 140 |
#else |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
|
40 | 142 |
#define NM_ERROR(err,msg) |
143 |
#define ERROR(err,msg) |
|
144 |
#define ERROR_1(err,msg,arg1) |
|
145 |
#define ERROR_2(err,msg,arg1,arg2) |
|
146 |
#define ERROR_3(err,msg,arg1,arg2,arg3) |
|
147 |
#define ERROR_GEN(msg) |
|
148 |
#define ERROR_GEN_1(msg,arg1) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
|
40 | 150 |
#endif /* ERROR_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
151 |
|
40 | 152 |
/* |
153 |
* The macro NM_FUNCTION, when used inside a function body, enables tracing |
|
154 |
* for a function. Trace messages with labels ENTER and RETURN are printed |
|
155 |
* when entering into and returning from a function, respectively. In case of |
|
156 |
* an exception or a Symbian leave, a message with label UNWIND is printed |
|
157 |
* (UNWIND stands for stack unwinding). The FUNC_LOG macro is provided for |
|
158 |
* legacy compatibility. It is deprecated and should not be used. |
|
159 |
*/ |
|
160 |
#if FUNCTION_TRACES |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
161 |
|
40 | 162 |
class __ftracer |
163 |
{ |
|
164 |
public: |
|
165 |
__ftracer(const QString& _fn) |
|
166 |
: fn(_fn) |
|
167 |
{ |
|
168 |
print_trace("ENTER : " + fn); |
|
169 |
} |
|
170 |
~__ftracer() |
|
171 |
{ |
|
172 |
if (std::uncaught_exception()) { |
|
173 |
print_trace("UNWIND : " + fn); |
|
174 |
} else { |
|
175 |
print_trace("RETURN : " + fn); |
|
176 |
} |
|
177 |
} |
|
178 |
private: |
|
179 |
QString fn; |
|
180 |
}; |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
181 |
|
43 | 182 |
#define NM_FUNCTION __ftracer __ft(__PRETTY_FUNCTION__) |
40 | 183 |
#define FUNC_LOG NM_FUNCTION |
184 |
||
185 |
#else |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
186 |
|
40 | 187 |
#define NM_FUNCTION |
188 |
#define FUNC_LOG |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
40 | 190 |
#endif /* FUNCTION TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
191 |
|
40 | 192 |
#endif /* EMAILTRACE_H */ |