persistentstorage/sql/SRC/Common/SqlAssert.h
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
    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 "SqlPanic.h"   //TSqlPanic
    20 #include "UTraceSql.h"
    21 
    21 
    22 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    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 //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
       
    58 
    23 
    59 #ifdef _DEBUG
    24 #ifdef _DEBUG
    60     //Enable _SQL_PANIC_TRACE_ENABLED if you want to get more detailed output regarding panics
    25 #define _ASSERTIONS
    61     //#define _SQL_PANIC_TRACE_ENABLED
    26 //#define _LOGGING
    62 
    27 //#define _NOTIFY		//Enable _NOTIFY if you want to get more detailed output in _DEBUG mode
    63     //Enable _SQL_LEAVE_TRACE_ENABLED if you want to get more detailed output regarding leaving locations
       
    64     //#define _SQL_LEAVE_TRACE_ENABLED
       
    65 #endif
    28 #endif
    66 
    29 
    67 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    30 const TInt KSqlLeavePanic = -359;//The (last-1) error code from the reserved area for the SQL component.
    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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    82 
    31 
    83 //Forward declarations
    32 //Forward declarations
    84 class RMessage2;
    33 class RMessage2;
    85 
    34 
    86 /**
    35 /**
    87 Set of useful functions to print diagnostic messages on the console when an error/leaving occurs.
    36 Set of useful functions to print diagnostic messages on the console when an error/leaving occurs.
    88 
    37 
    89 @internalComponent
    38 @internalComponent
    90 */
    39 */
    91 class TSqlUtil
    40 class Util
    92 	{
    41 	{
    93 	friend void UtilFileNameTest();
    42 	friend void UtilFileNameTest();
    94 	
    43 	
    95 public:
    44 public:
    96 	static void GetTimeStr(TDes& aWhere);
    45 	static void GetTimeStr(TDes& aWhere);
    97 	static TInt Panic(const TText* aFile, TInt aLine, TInt aPanicCode, TUint aHandle);
    46 	static TInt Assert(const TText* aFile, TInt aLine, TInt aPanicCode);
    98 	static void Leave(const TText* aFile, TInt aLine, TInt aError, TUint aHandle);
    47 	static void Leave(const TText* aFile, TInt aLine, TInt aError);
    99 	static TInt LeaveIfError(const TText* aFile, TInt aLine, TInt aError, TUint aHandle);
    48 	static TInt LeaveIfError(const TText* aFile, TInt aLine, TInt aError);
   100 	static void* LeaveIfNull(const TText* aFile, TInt aLine, void* aPtr, TUint aHandle);
    49 	static const void* LeaveIfNull(const TText* aFile, TInt aLine, const void* aPtr);
   101 	static TInt PanicClientL(const TText* aFile, TInt aLine, const RMessage2& aMessage, TInt aPanicCode, TUint aHandle);
    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);
   102 	
    53 	
   103 private:
    54 private:
   104 	static TPtrC FileName(const TText* aFile);
    55 	static TPtrC Filename(const TText* aFile);
   105 	
    56 	
   106 	};
    57 	};
   107 
    58 
   108 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    59 #define __STRING(str) _S(str)
   109 
    60 
   110 #define __SQLSTRING(str) _S(str)
    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))
   111 
    64 
   112 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    66 //////////////////////////////       _ASSERTIONS          /////////////////////////////////////////////////////////
       
    67 #ifdef _ASSERTIONS
   113 
    68 
   114 //__SQLPANIC/__SQLPANIC2 macro is used for printing out additional information when panic occurs in SQL:
    69 //This macro should be used when there is a need to panic the client/server if "expr" condition is not satisfied.
   115 //source file name, line number, "this" pointer, panic category.
    70 //Works in only in debug mode. In release mode evaluates to nothing.
   116 #define __SQLPANIC(aPanicCode)      TSqlUtil::Panic(__SQLSTRING(__FILE__), __LINE__, aPanicCode, (TUint)this)
    71 #define __SQLASSERT(expr, panicCode)	(void)((expr) || Util::Assert(__STRING(__FILE__), __LINE__, panicCode))
   117 #define __SQLPANIC2(aPanicCode)     TSqlUtil::Panic(__SQLSTRING(__FILE__), __LINE__, aPanicCode, 0)
    72 
       
    73 #else
       
    74 
       
    75 #define __SQLASSERT(expr, panicCode) 	void(0)
       
    76 
       
    77 #endif //_ASSERTIONS
   118 
    78 
   119 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    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
   120 
   103 
   121 //This macro should be used to leave with "err" error code.
   104 //This macro should be used to leave with "err" error code.
   122 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   105 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   123 //In release mode only leaves.
   106 //In release mode only leaves.
   124 #define __SQLLEAVE(err)             TSqlUtil::Leave(__SQLSTRING(__FILE__), __LINE__, err, (TUint)this)
   107 #define __SQLLEAVE(err) 					Util::Leave(__STRING(__FILE__), __LINE__, err)
   125 #define __SQLLEAVE2(err)            TSqlUtil::Leave(__SQLSTRING(__FILE__), __LINE__, err, 0)
       
   126 
   108 
   127 //This macro should be used to leave with "err" error code, if the error code is negative.
   109 //This macro should be used to leave with "err" error code, if the error code is negative.
   128 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   110 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   129 //In release mode only leaves.
   111 //In release mode only leaves.
   130 #define __SQLLEAVE_IF_ERROR(err)    TSqlUtil::LeaveIfError(__SQLSTRING(__FILE__), __LINE__, err, (TUint)this)
   112 #define __SQLLEAVE_IF_ERROR(err) 			Util::LeaveIfError(__STRING(__FILE__), __LINE__, err)
   131 #define __SQLLEAVE_IF_ERROR2(err)   TSqlUtil::LeaveIfError(__SQLSTRING(__FILE__), __LINE__, err, 0)
       
   132 
   113 
   133 //This macro should be used to leave with KErrNoMemory if "ptr" argument is NULL.
   114 //This macro should be used to leave with KErrNoMemory if "ptr" argument is NULL.
   134 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   115 //In debug mode prints the file name and the line number where the leaving occurs and then leaves.
   135 //In release mode only leaves.
   116 //In release mode only leaves.
   136 #define __SQLLEAVE_IF_NULL(ptr)     TSqlUtil::LeaveIfNull(__SQLSTRING(__FILE__), __LINE__, ptr, (TUint)this)
   117 #define __SQLLEAVE_IF_NULL(ptr) 			Util::LeaveIfNull(__STRING(__FILE__), __LINE__, ptr)
   137 
   118 
   138 //This macro should be used to panic the client and leave if "expr" condition is not satisfied.
   119 //This macro should be used to panic the client and leave if "expr" condition is not satisfied.
   139 //In debug mode prints the file name and the line number where the leaving occurs and then 
   120 //In debug mode prints the file name and the line number where the leaving occurs and then 
   140 //panics the client and leaves.
   121 //panics the client and leaves.
   141 //In release mode only panics the client and leaves.
   122 //In release mode only panics the client and leaves.
   142 #define __SQLPANIC_CLIENT(expr, msg, panicCode)  (void)((expr) || TSqlUtil::PanicClientL(__SQLSTRING(__FILE__), __LINE__, msg, panicCode, (TUint)this))
   123 #define __SQLPANIC_CLIENT(expr, msg, panicCode)	(void)((expr) || Util::PanicClientL(__STRING(__FILE__), __LINE__, msg, panicCode))
   143 #define __SQLPANIC_CLIENT2(expr, msg, panicCode) (void)((expr) || TSqlUtil::PanicClientL(__SQLSTRING(__FILE__), __LINE__, msg, panicCode, 0))
       
   144 
   124 
   145 //===================================================================================
   125 #else
   146 
   126 
   147 #ifdef _SQL_BORDER_TRACE_ENABLED
   127 #define __SQLLEAVE(err) 					User::Leave(err)
   148     #define SQL_TRACE_BORDER(trace)   trace
   128 #define __SQLLEAVE_IF_ERROR(err) 			User::LeaveIfError(err)
   149 #else
   129 #define __SQLLEAVE_IF_NULL(ptr) 			User::LeaveIfNull(ptr)
   150     #define SQL_TRACE_BORDER(trace)   do {} while(0)
   130 #define __SQLPANIC_CLIENT(expr, msg, panicCode)	(void)((expr) || ::SqlPanicClientL(msg, panicCode))
   151 #endif
       
   152 
   131 
   153 #ifdef _SQL_INTERNALS_TRACE_ENABLED
   132 #endif //_NOTIFY || SYMBIAN_TRACE_SQL_ERR
   154     #define SQL_TRACE_INTERNALS(trace)   trace
       
   155 #else
       
   156     #define SQL_TRACE_INTERNALS(trace)   do {} while(0)
       
   157 #endif
       
   158 
       
   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 //===================================================================================
       
   190 
   133 
   191 #endif//__SQLASSERT_H__
   134 #endif//__SQLASSERT_H__