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