|
1 /* |
|
2 * Copyright (c) 2009 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: Tracing macros, 2nd generation |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef TRACE_H |
|
19 #define TRACE_H |
|
20 |
|
21 #include <QDebug> |
|
22 |
|
23 //----------------------------------------------------------------------------- |
|
24 // Trace definitions |
|
25 //----------------------------------------------------------------------------- |
|
26 // |
|
27 |
|
28 /** |
|
29 * Error trace enabled |
|
30 */ |
|
31 #ifdef _DEBUG |
|
32 #define ERROR_TRACE |
|
33 #define INFO_TRACE |
|
34 #define TIMESTAMP_TRACE |
|
35 #define FUNC_TRACE |
|
36 #else |
|
37 #define ERROR_TRACE |
|
38 #define INFO_TRACE |
|
39 #define TIMESTAMP_TRACE |
|
40 #define FUNC_TRACE |
|
41 #endif |
|
42 |
|
43 //----------------------------------------------------------------------------- |
|
44 // Constants |
|
45 //----------------------------------------------------------------------------- |
|
46 // |
|
47 |
|
48 /** |
|
49 * Trace prefixes for macros with component name. |
|
50 */ |
|
51 #define _TRACE_PREFIX "[SVPB]:" |
|
52 |
|
53 /** |
|
54 * Prefix error trace |
|
55 */ |
|
56 #define _ERROR_PREFIX _TRACE_PREFIX " [ERROR]:" |
|
57 |
|
58 /** |
|
59 * Prefix info trace. |
|
60 */ |
|
61 #define _INFO_PREFIX _TRACE_PREFIX " [INFO]:" |
|
62 |
|
63 /** |
|
64 * Prefix timestamp trace. |
|
65 */ |
|
66 #define _TIMESTAMP_PREFIX _TRACE_PREFIX " [TIMESTAMP]:" |
|
67 |
|
68 //----------------------------------------------------------------------------- |
|
69 // Error trace macros |
|
70 // Usage: wrap traces in ERROR() macro to allow disabling them in release builds. |
|
71 // Use normal stream object operations. |
|
72 // Examples: |
|
73 // ERROR( "xxx failed" ); |
|
74 // ERROR( "Test trace arg =" << 999 << "arg2 =" << title() ); |
|
75 //----------------------------------------------------------------------------- |
|
76 // |
|
77 #ifdef ERROR_TRACE |
|
78 #define ERROR(trace) {qDebug() << _ERROR_PREFIX << trace;} |
|
79 #define ERROR_PARAM(param) param |
|
80 #define HANDLE_ERROR(trace) {ERROR(trace); __BREAKPOINT();} |
|
81 #define HANDLE_ERROR_BOOL(x) {if (!x) {ERROR(#x << "is false"); __BREAKPOINT();}} |
|
82 #define HANDLE_ERROR_NULL(x) {if (!x) {ERROR(#x << "is NULL"); __BREAKPOINT();}} |
|
83 #define HANDLE_ERROR_NEG(x) {if (x < 0) {ERROR(#x << "=" << x << "File:" << __FILE__ << ", line:" << __LINE__); __BREAKPOINT();}} |
|
84 #define CHECK_ERROR(err, trace) {if (err < 0) ERROR(trace << err);} |
|
85 #else //ERROR_TRACE not defined |
|
86 #define ERROR(trace) |
|
87 #define ERROR_PARAM(param) |
|
88 #define HANDLE_ERROR(trace) |
|
89 #define HANDLE_ERROR_BOOL(x) |
|
90 #define HANDLE_ERROR_NULL(x) |
|
91 #define HANDLE_ERROR_NEG(x) |
|
92 #define CHECK_ERROR(err,trace) |
|
93 #endif //ERROR_TRACE |
|
94 |
|
95 //----------------------------------------------------------------------------- |
|
96 // Info trace macros |
|
97 // Usage: wrap traces in INFO() macro to allow disabling them in release builds. |
|
98 // Use normal stream object operations. |
|
99 // Examples: |
|
100 // INFO( "Test trace" ); |
|
101 // INFO( "Test trace arg =" << 999 << "arg2 =" << title() ); |
|
102 //----------------------------------------------------------------------------- |
|
103 // |
|
104 #ifdef INFO_TRACE |
|
105 #define INFO(trace) {qDebug() << _INFO_PREFIX << trace;} |
|
106 #define INFO_PARAM(param) param |
|
107 #else //INFO_TRACE not defined |
|
108 #define INFO(trace) |
|
109 #define INFO_PARAM(param) |
|
110 #endif //INFO_TRACE |
|
111 |
|
112 //----------------------------------------------------------------------------- |
|
113 // Function trace macros |
|
114 //----------------------------------------------------------------------------- |
|
115 // |
|
116 #ifdef FUNC_TRACE |
|
117 |
|
118 class FuncLog |
|
119 { |
|
120 public: |
|
121 inline FuncLog( const char* func ) : m_func( func ) |
|
122 { qDebug() << _TRACE_PREFIX << m_func << "-START"; } |
|
123 inline ~FuncLog() { qDebug() << _TRACE_PREFIX << m_func << "-END"; } |
|
124 private: // Data |
|
125 QString m_func; |
|
126 }; |
|
127 |
|
128 #define FUNC_LOG FuncLog _fl( __PRETTY_FUNCTION__ ); |
|
129 #else //FUNC_TRACE not defined |
|
130 #define FUNC_LOG |
|
131 #endif //FUNC_TRACE |
|
132 |
|
133 //----------------------------------------------------------------------------- |
|
134 // Timestamp trace macros |
|
135 //----------------------------------------------------------------------------- |
|
136 // |
|
137 #ifdef TIMESTAMP_TRACE |
|
138 #include <QTime> |
|
139 #define TIMESTAMP(trace)\ |
|
140 {qDebug() << _TIMESTAMP_PREFIX << "(" << \ |
|
141 QTime::currentTime().toString("HH:mm:ss:zzz") << ")" << trace;} |
|
142 #else //TIMESTAMP_TRACE not defined |
|
143 #define TIMESTAMP(trace) |
|
144 #endif //TIMESTAMP_TRACE |
|
145 |
|
146 #endif // TRACE_H |