|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __SQLASSERT_H__ |
|
17 #define __SQLASSERT_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include "UTraceSql.h" |
|
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. |
|
23 |
|
24 #ifdef _DEBUG |
|
25 #define _ASSERTIONS |
|
26 //#define _LOGGING |
|
27 //#define _NOTIFY //Enable _NOTIFY if you want to get more detailed output in _DEBUG mode |
|
28 #endif |
|
29 |
|
30 const TInt KSqlLeavePanic = -359;//The (last-1) error code from the reserved area for the SQL component. |
|
31 |
|
32 //Forward declarations |
|
33 class RMessage2; |
|
34 |
|
35 /** |
|
36 Set of useful functions to print diagnostic messages on the console when an error/leaving occurs. |
|
37 |
|
38 @internalComponent |
|
39 */ |
|
40 class Util |
|
41 { |
|
42 friend void UtilFileNameTest(); |
|
43 |
|
44 public: |
|
45 static void GetTimeStr(TDes& aWhere); |
|
46 static TInt Assert(const TText* aFile, TInt aLine, TInt aPanicCode); |
|
47 static void Leave(const TText* aFile, TInt aLine, TInt aError); |
|
48 static TInt LeaveIfError(const TText* aFile, TInt aLine, TInt aError); |
|
49 static void* LeaveIfNull(const TText* aFile, TInt aLine, void* aPtr); |
|
50 static TInt PanicClientL(const TText* aFile, TInt aLine, const RMessage2& aMessage, TInt aPanicCode); |
|
51 static void ErrorPrint(const TDesC& aMsg, TInt aErr); |
|
52 static void ErrorPrint(const TDesC& aMsg, const TDesC& aStr); |
|
53 |
|
54 private: |
|
55 static TPtrC Filename(const TText* aFile); |
|
56 |
|
57 }; |
|
58 |
|
59 #define __STRING(str) _S(str) |
|
60 |
|
61 //This macro should be used when there is a need to panic the client/server if "expr" condition is not satisfied. |
|
62 //Works in both debug and release modes. |
|
63 #define __SQLASSERT_ALWAYS(expr, panicCode) (void)((expr) || Util::Assert(__STRING(__FILE__), __LINE__, panicCode)) |
|
64 |
|
65 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 ////////////////////////////// _ASSERTIONS ///////////////////////////////////////////////////////// |
|
67 #ifdef _ASSERTIONS |
|
68 |
|
69 //This macro should be used when there is a need to panic the client/server if "expr" condition is not satisfied. |
|
70 //Works in only in debug mode. In release mode evaluates to nothing. |
|
71 #define __SQLASSERT(expr, panicCode) (void)((expr) || Util::Assert(__STRING(__FILE__), __LINE__, panicCode)) |
|
72 |
|
73 #else |
|
74 |
|
75 #define __SQLASSERT(expr, panicCode) void(0) |
|
76 |
|
77 #endif //_ASSERTIONS |
|
78 |
|
79 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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 |
|
104 //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. |
|
106 //In release mode only leaves. |
|
107 #define __SQLLEAVE(err) Util::Leave(__STRING(__FILE__), __LINE__, err) |
|
108 |
|
109 //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. |
|
111 //In release mode only leaves. |
|
112 #define __SQLLEAVE_IF_ERROR(err) Util::LeaveIfError(__STRING(__FILE__), __LINE__, err) |
|
113 |
|
114 //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. |
|
116 //In release mode only leaves. |
|
117 #define __SQLLEAVE_IF_NULL(ptr) Util::LeaveIfNull(__STRING(__FILE__), __LINE__, ptr) |
|
118 |
|
119 //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 |
|
121 //panics the client and leaves. |
|
122 //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)) |
|
124 |
|
125 #else |
|
126 |
|
127 #define __SQLLEAVE(err) User::Leave(err) |
|
128 #define __SQLLEAVE_IF_ERROR(err) User::LeaveIfError(err) |
|
129 #define __SQLLEAVE_IF_NULL(ptr) User::LeaveIfNull(ptr) |
|
130 #define __SQLPANIC_CLIENT(expr, msg, panicCode) (void)((expr) || ::SqlPanicClientL(msg, panicCode)) |
|
131 |
|
132 #endif //_NOTIFY || SYMBIAN_TRACE_SQL_ERR |
|
133 |
|
134 #endif//__SQLASSERT_H__ |