15 |
15 |
16 #ifndef __SQLASSERT_H__ |
16 #ifndef __SQLASSERT_H__ |
17 #define __SQLASSERT_H__ |
17 #define __SQLASSERT_H__ |
18 |
18 |
19 #include <e32std.h> |
19 #include <e32std.h> |
20 #include "UTraceSql.h" |
20 #include "SqlPanic.h" //TSqlPanic |
21 |
21 |
22 //#define _SQLPROFILER //Enable _SQLPROFILER if you want to use the TSqlResourceProfiler functions. Do not forget the same macro declaration in os_symbian.cpp file. |
22 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
24 //Enable _SQLPROFILER if you want to use the TSqlResourceProfiler functions. Do not forget the same macro declaration in os_symbian.cpp file. |
|
25 |
|
26 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 //All macros in this header will have a non-void definition only if the OST_TRACE_COMPILER_IN_USE macro |
|
29 //is defined. |
|
30 //In order to get the traces enabled, the OST_TRACE_COMPILER_IN_USE macro has to be defined in |
|
31 //OstTraceDefinitions.h file. |
|
32 //After that, the trace output can be redirected by defining _SQL_RDEBUG_PRINT or specific categories |
|
33 //of traces can be enabled/disabled. |
|
34 |
|
35 //Enable _SQL_RDEBUG_PRINT if you want to redirect the tracing output via RDebug::Print() |
|
36 //#define _SQL_RDEBUG_PRINT |
|
37 |
|
38 //Enable _SQL_BORDER_TRACE_ENABLED if you want to get the entry/exit traces compiled in the binary |
|
39 //#define _SQL_BORDER_TRACE_ENABLED |
|
40 |
|
41 //Enable _SQL_INTERNALS_TRACE_ENABLED if you want to get the internal traces compiled in the binary |
|
42 //#define _SQL_INTERNALS_TRACE_ENABLED |
|
43 |
|
44 //Enable _SQL_BUR_TRACE_ENABLED if you want to get the backup&restore traces compiled in the binary |
|
45 //#define _SQL_BUR_TRACE_ENABLED |
|
46 |
|
47 //Enable _SQL_COMPACT_TRACE_ENABLED if you want to get the background compaction traces compiled in the binary |
|
48 //#define _SQL_COMPACT_TRACE_ENABLED |
|
49 |
|
50 //Enable _SQL_SESSION_TRACE_ENABLED if you want to get the client and server sessions traces compiled in the binary |
|
51 //#define _SQL_SESSION_TRACE_ENABLED |
|
52 |
|
53 //Enable _SQL_AUTHORIZER_TRACE_ENABLED if you want to trace the authorizer parameters |
|
54 //#define _SQL_AUTHORIZER_TRACE_ENABLED |
|
55 |
|
56 //Enable _SQL_BLOB_TRACE_ENABLED if you want to trace the server side BLOB calls |
|
57 //#define _SQL_BLOB_TRACE_ENABLED |
23 |
58 |
24 #ifdef _DEBUG |
59 #ifdef _DEBUG |
25 #define _ASSERTIONS |
60 //Enable _SQL_PANIC_TRACE_ENABLED if you want to get more detailed output regarding panics |
26 //#define _LOGGING |
61 //#define _SQL_PANIC_TRACE_ENABLED |
27 //#define _NOTIFY //Enable _NOTIFY if you want to get more detailed output in _DEBUG mode |
62 |
|
63 //Enable _SQL_LEAVE_TRACE_ENABLED if you want to get more detailed output regarding leaving locations |
|
64 //#define _SQL_LEAVE_TRACE_ENABLED |
28 #endif |
65 #endif |
29 |
66 |
30 const TInt KSqlLeavePanic = -359;//The (last-1) error code from the reserved area for the SQL component. |
67 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
69 //Wrap every string (file name, file path, etc.) you want to trace, in a __SQLPRNSTR()/__SQLPRNSTR8() macro. |
|
70 //There is a difference how RDebug::Print() and OstTraceExt<n>() work. |
|
71 #if defined _SQL_RDEBUG_PRINT |
|
72 const TInt KSqlMaxPrnStrLen = 512; |
|
73 #define __SQLPRNSTR(des) &des |
|
74 const TDesC* SqlDes8to16Ptr(const TDesC8& aDes, TDes& aOut); |
|
75 #define __SQLPRNSTR8(des, out) SqlDes8to16Ptr(des, out) |
|
76 #else |
|
77 #define __SQLPRNSTR(des) des |
|
78 #define __SQLPRNSTR8(des, out) des |
|
79 #endif |
|
80 |
|
81 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
31 |
82 |
32 //Forward declarations |
83 //Forward declarations |
33 class RMessage2; |
84 class RMessage2; |
34 |
85 |
35 /** |
86 /** |
36 Set of useful functions to print diagnostic messages on the console when an error/leaving occurs. |
87 Set of useful functions to print diagnostic messages on the console when an error/leaving occurs. |
37 |
88 |
38 @internalComponent |
89 @internalComponent |
39 */ |
90 */ |
40 class Util |
91 class TSqlUtil |
41 { |
92 { |
42 friend void UtilFileNameTest(); |
93 friend void UtilFileNameTest(); |
43 |
94 |
44 public: |
95 public: |
45 static void GetTimeStr(TDes& aWhere); |
96 static void GetTimeStr(TDes& aWhere); |
46 static TInt Assert(const TText* aFile, TInt aLine, TInt aPanicCode); |
97 static TInt Panic(const TText* aFile, TInt aLine, TInt aPanicCode, TUint aHandle); |
47 static void Leave(const TText* aFile, TInt aLine, TInt aError); |
98 static void Leave(const TText* aFile, TInt aLine, TInt aError, TUint aHandle); |
48 static TInt LeaveIfError(const TText* aFile, TInt aLine, TInt aError); |
99 static TInt LeaveIfError(const TText* aFile, TInt aLine, TInt aError, TUint aHandle); |
49 static const void* LeaveIfNull(const TText* aFile, TInt aLine, const void* aPtr); |
100 static void* LeaveIfNull(const TText* aFile, TInt aLine, void* aPtr, TUint aHandle); |
50 static TInt PanicClientL(const TText* aFile, TInt aLine, const RMessage2& aMessage, TInt aPanicCode); |
101 static TInt PanicClientL(const TText* aFile, TInt aLine, const RMessage2& aMessage, TInt aPanicCode, TUint aHandle); |
51 static void ErrorPrint(const TDesC& aMsg, TInt aErr); |
|
52 static void ErrorPrint(const TDesC& aMsg, const TDesC& aStr); |
|
53 |
102 |
54 private: |
103 private: |
55 static TPtrC Filename(const TText* aFile); |
104 static TPtrC FileName(const TText* aFile); |
56 |
105 |
57 }; |
106 }; |
58 |
107 |
59 #define __STRING(str) _S(str) |
108 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
60 |
109 |
61 //This macro should be used when there is a need to panic the client/server if "expr" condition is not satisfied. |
110 #define __SQLSTRING(str) _S(str) |
62 //Works in both debug and release modes. |
|
63 #define __SQLASSERT_ALWAYS(expr, panicCode) (void)((expr) || Util::Assert(__STRING(__FILE__), __LINE__, panicCode)) |
|
64 |
111 |
65 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
112 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
66 ////////////////////////////// _ASSERTIONS ///////////////////////////////////////////////////////// |
|
67 #ifdef _ASSERTIONS |
|
68 |
113 |
69 //This macro should be used when there is a need to panic the client/server if "expr" condition is not satisfied. |
114 //__SQLPANIC/__SQLPANIC2 macro is used for printing out additional information when panic occurs in SQL: |
70 //Works in only in debug mode. In release mode evaluates to nothing. |
115 //source file name, line number, "this" pointer, panic category. |
71 #define __SQLASSERT(expr, panicCode) (void)((expr) || Util::Assert(__STRING(__FILE__), __LINE__, panicCode)) |
116 #define __SQLPANIC(aPanicCode) TSqlUtil::Panic(__SQLSTRING(__FILE__), __LINE__, aPanicCode, (TUint)this) |
72 |
117 #define __SQLPANIC2(aPanicCode) TSqlUtil::Panic(__SQLSTRING(__FILE__), __LINE__, aPanicCode, 0) |
73 #else |
|
74 |
|
75 #define __SQLASSERT(expr, panicCode) void(0) |
|
76 |
|
77 #endif //_ASSERTIONS |
|
78 |
118 |
79 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
119 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
80 ////////////////////////////// _LOGGING ////////////////////////////////////////////////////////// |
|
81 #if defined _LOGGING || defined SYMBIAN_TRACE_SQL_ERR |
|
82 |
|
83 //This macro should be used to log the message "msg" containing the "err" error code. |
|
84 //The message "msg" should contain the format specifier %d. |
|
85 //Works only in debug mode. In release mode evaluates to nothing. |
|
86 #define __SQLLOG_ERR(msg, err) Util::ErrorPrint(msg, err) |
|
87 |
|
88 //This macro should be used to log the message "msg" containing the "str" string. |
|
89 //The message "msg" should contain the format specifier %S. |
|
90 //Works only in debug mode. In release mode evaluates to nothing. |
|
91 #define __SQLLOG_STRING(msg, str) Util::ErrorPrint(msg, str) |
|
92 |
|
93 #else |
|
94 |
|
95 #define __SQLLOG_ERR(msg, err) do {} while(0) |
|
96 #define __SQLLOG_STRING(msg, str) do {} while(0) |
|
97 |
|
98 #endif //_LOGGING || SYMBIAN_TRACE_SQL_ERR |
|
99 |
|
100 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 ////////////////////////////// _NOTIFY /////////////////////////////////////////////////////////// |
|
102 #if defined _NOTIFY || defined SYMBIAN_TRACE_SQL_ERR |
|
103 |
120 |
104 //This macro should be used to leave with "err" error code. |
121 //This macro should be used to leave with "err" error code. |
105 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
122 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
106 //In release mode only leaves. |
123 //In release mode only leaves. |
107 #define __SQLLEAVE(err) Util::Leave(__STRING(__FILE__), __LINE__, err) |
124 #define __SQLLEAVE(err) TSqlUtil::Leave(__SQLSTRING(__FILE__), __LINE__, err, (TUint)this) |
|
125 #define __SQLLEAVE2(err) TSqlUtil::Leave(__SQLSTRING(__FILE__), __LINE__, err, 0) |
108 |
126 |
109 //This macro should be used to leave with "err" error code, if the error code is negative. |
127 //This macro should be used to leave with "err" error code, if the error code is negative. |
110 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
128 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
111 //In release mode only leaves. |
129 //In release mode only leaves. |
112 #define __SQLLEAVE_IF_ERROR(err) Util::LeaveIfError(__STRING(__FILE__), __LINE__, err) |
130 #define __SQLLEAVE_IF_ERROR(err) TSqlUtil::LeaveIfError(__SQLSTRING(__FILE__), __LINE__, err, (TUint)this) |
|
131 #define __SQLLEAVE_IF_ERROR2(err) TSqlUtil::LeaveIfError(__SQLSTRING(__FILE__), __LINE__, err, 0) |
113 |
132 |
114 //This macro should be used to leave with KErrNoMemory if "ptr" argument is NULL. |
133 //This macro should be used to leave with KErrNoMemory if "ptr" argument is NULL. |
115 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
134 //In debug mode prints the file name and the line number where the leaving occurs and then leaves. |
116 //In release mode only leaves. |
135 //In release mode only leaves. |
117 #define __SQLLEAVE_IF_NULL(ptr) Util::LeaveIfNull(__STRING(__FILE__), __LINE__, ptr) |
136 #define __SQLLEAVE_IF_NULL(ptr) TSqlUtil::LeaveIfNull(__SQLSTRING(__FILE__), __LINE__, ptr, (TUint)this) |
118 |
137 |
119 //This macro should be used to panic the client and leave if "expr" condition is not satisfied. |
138 //This macro should be used to panic the client and leave if "expr" condition is not satisfied. |
120 //In debug mode prints the file name and the line number where the leaving occurs and then |
139 //In debug mode prints the file name and the line number where the leaving occurs and then |
121 //panics the client and leaves. |
140 //panics the client and leaves. |
122 //In release mode only panics the client and leaves. |
141 //In release mode only panics the client and leaves. |
123 #define __SQLPANIC_CLIENT(expr, msg, panicCode) (void)((expr) || Util::PanicClientL(__STRING(__FILE__), __LINE__, msg, panicCode)) |
142 #define __SQLPANIC_CLIENT(expr, msg, panicCode) (void)((expr) || TSqlUtil::PanicClientL(__SQLSTRING(__FILE__), __LINE__, msg, panicCode, (TUint)this)) |
|
143 #define __SQLPANIC_CLIENT2(expr, msg, panicCode) (void)((expr) || TSqlUtil::PanicClientL(__SQLSTRING(__FILE__), __LINE__, msg, panicCode, 0)) |
124 |
144 |
|
145 //=================================================================================== |
|
146 |
|
147 #ifdef _SQL_BORDER_TRACE_ENABLED |
|
148 #define SQL_TRACE_BORDER(trace) trace |
125 #else |
149 #else |
|
150 #define SQL_TRACE_BORDER(trace) do {} while(0) |
|
151 #endif |
126 |
152 |
127 #define __SQLLEAVE(err) User::Leave(err) |
153 #ifdef _SQL_INTERNALS_TRACE_ENABLED |
128 #define __SQLLEAVE_IF_ERROR(err) User::LeaveIfError(err) |
154 #define SQL_TRACE_INTERNALS(trace) trace |
129 #define __SQLLEAVE_IF_NULL(ptr) User::LeaveIfNull(ptr) |
155 #else |
130 #define __SQLPANIC_CLIENT(expr, msg, panicCode) (void)((expr) || ::SqlPanicClientL(msg, panicCode)) |
156 #define SQL_TRACE_INTERNALS(trace) do {} while(0) |
|
157 #endif |
131 |
158 |
132 #endif //_NOTIFY || SYMBIAN_TRACE_SQL_ERR |
159 #ifdef _SQL_BUR_TRACE_ENABLED |
|
160 #define SQL_TRACE_BUR(trace) trace |
|
161 #else |
|
162 #define SQL_TRACE_BUR(trace) do {} while(0) |
|
163 #endif |
|
164 |
|
165 #ifdef _SQL_COMPACT_TRACE_ENABLED |
|
166 #define SQL_TRACE_COMPACT(trace) trace |
|
167 #else |
|
168 #define SQL_TRACE_COMPACT(trace) do {} while(0) |
|
169 #endif |
|
170 |
|
171 #ifdef _SQL_SESSION_TRACE_ENABLED |
|
172 #define SQL_TRACE_SESSION(trace) trace |
|
173 #else |
|
174 #define SQL_TRACE_SESSION(trace) do {} while(0) |
|
175 #endif |
|
176 |
|
177 #ifdef _SQL_AUTHORIZER_TRACE_ENABLED |
|
178 #define SQL_TRACE_AUTHORIZER(trace) trace |
|
179 #else |
|
180 #define SQL_TRACE_AUTHORIZER(trace) do {} while(0) |
|
181 #endif |
|
182 |
|
183 #ifdef _SQL_BLOB_TRACE_ENABLED |
|
184 #define SQL_TRACE_BLOB(trace) trace |
|
185 #else |
|
186 #define SQL_TRACE_BLOB(trace) do {} while(0) |
|
187 #endif |
|
188 |
|
189 //=================================================================================== |
133 |
190 |
134 #endif//__SQLASSERT_H__ |
191 #endif//__SQLASSERT_H__ |