persistentstorage/dbms/udbms/Ud_Assert.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1998-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 // Ut_Assert.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32svr.h>
       
    19 #include "D32Assert.h"
       
    20 
       
    21 #if defined(_ASSERTIONS) || defined(_NOTIFY) || defined(_TRACE)
       
    22 TPtrC Util::Filename(const TText* aFile)
       
    23 	{
       
    24 	TPtrC p(aFile);
       
    25 	TInt ix=p.LocateReverse('\\');	// MSVC uses \ as path separator, GCC uses /
       
    26 	if (ix<0)
       
    27 		ix=p.LocateReverse('/');
       
    28 	if (ix>=0)
       
    29 		p.Set(p.Mid(1+ix));
       
    30 	return p;
       
    31 	}
       
    32 #endif//defined(_ASSERTIONS) || defined(_NOTIFY) || defined(_TRACE)
       
    33 
       
    34 #if defined(_ASSERTIONS)
       
    35 void Util::Assert(const TText* aFile,TInt aLine)
       
    36 	{
       
    37 	TBuf<32> b=_S("dbms:");
       
    38 	b+=Filename(aFile);
       
    39 	User::Panic(b,aLine);
       
    40 	}
       
    41 #endif//defined(_ASSERTIONS)
       
    42 
       
    43 #if defined(_NOTIFY)
       
    44 #pragma message(__FILE__ " : Leave Notification is enabled")
       
    45 
       
    46 void Util::Leave(const TText* aFile,TInt aLine,TInt aError)
       
    47 	{
       
    48 	TPtrC f(Filename(aFile));
       
    49 	TBuf<60> buf;
       
    50 	_LIT(KFormat,"***Error=%d at %S(%d)");
       
    51 	buf.Format(KFormat,aError,&f,aLine);
       
    52 	__TRACE(buf);
       
    53 #if _NOTIFY_WAIT
       
    54 	RNotifier notify;
       
    55 	if (notify.Connect()==KErrNone)
       
    56 		{
       
    57 		TRequestStatus stat;
       
    58 		TInt but;
       
    59 		_LIT(KNotify,"DBMS Leave");
       
    60 		_LIT(KContinue,"Continue");
       
    61 		notify.Notify(KNotify,buf,KContinue,KNullDesC,but,stat);
       
    62 		User::WaitForRequest(stat);
       
    63 		notify.Close();
       
    64 		}
       
    65 #else
       
    66 	_LIT(KNotify,"DBMS Leave ");
       
    67 	buf.Insert(0,KNotify);
       
    68 //	User::InfoPrint(buf);
       
    69 	__TRACE(buf);
       
    70 #endif
       
    71 	User::Leave(aError);
       
    72 	}
       
    73 
       
    74 TInt Util::LeaveIfError(const TText* aFile,TInt aLine,TInt aError)
       
    75 	{
       
    76 	if (aError<0)
       
    77 		Leave(aFile,aLine,aError);
       
    78 	return aError;
       
    79 	}
       
    80 #endif//defined(_NOTIFY)
       
    81 
       
    82 #if defined(_TRACE)
       
    83 #pragma message(__FILE__ " : Tracing is enabled")
       
    84 
       
    85 void Util::Trace(const TText* aFile,TInt aLine)
       
    86 	{
       
    87 	TPtrC f(Filename(aFile));
       
    88 	_LIT(KFormat,"%S(%d)\n");
       
    89 	RDebug::Print(KFormat,&f,aLine);
       
    90 	}
       
    91 
       
    92 void Util::Trace(const TText* aFile,TInt aLine,const TText* aString)
       
    93 	{
       
    94 	TPtrC f(Filename(aFile));
       
    95 	_LIT(KFormat,"%S(%d) : %s\n");
       
    96 	RDebug::Print(KFormat,&f,aLine,aString);
       
    97 	}
       
    98 void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,const TDesC& aDes)
       
    99 	{
       
   100 	TPtrC f(Filename(aFile));
       
   101 	_LIT(KFormat,"%S(%d) : %s = \"%S\"\n");
       
   102 	RDebug::Print(KFormat,&f,aLine,aExp,&aDes);
       
   103 	}
       
   104 
       
   105 void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,const TAny* aPtr)
       
   106 	{
       
   107 	TPtrC f(Filename(aFile));
       
   108 	_LIT(KFormat,"%S(%d) : %s = %08x\n");
       
   109 	RDebug::Print(KFormat,&f,aLine,aExp,TUint(aPtr));
       
   110 	}
       
   111 
       
   112 void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,TInt aVal)
       
   113 	{
       
   114 	TPtrC f(Filename(aFile));
       
   115 	_LIT(KFormat,"%S(%d) : %s = %d (0x%x)\n");
       
   116 	RDebug::Print(KFormat,&f,aLine,aExp,aVal,aVal);
       
   117 	}
       
   118 #endif//defined(_TRACE)
       
   119 
       
   120 #ifdef __DBINVARIANT__
       
   121 void Util::Invariant(TBool aExprVal)
       
   122 	{
       
   123 	if(!aExprVal)
       
   124 		{
       
   125 		User::Invariant();
       
   126 		}
       
   127 	}
       
   128 #endif//__DBINVARIANT__
       
   129