sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Ut_Assert.cpp sl@0: // sl@0: // sl@0: sl@0: #include "D32Assert.h" sl@0: sl@0: #if defined(_ASSERTIONS) || defined(_NOTIFY) || defined(_TRACE) sl@0: TPtrC Util::Filename(const TText* aFile) sl@0: { sl@0: TPtrC p(aFile); sl@0: TInt ix=p.LocateReverse('\\'); // MSVC uses \ as path separator, GCC uses / sl@0: if (ix<0) sl@0: ix=p.LocateReverse('/'); sl@0: if (ix>=0) sl@0: p.Set(p.Mid(1+ix)); sl@0: return p; sl@0: } sl@0: #endif//defined(_ASSERTIONS) || defined(_NOTIFY) || defined(_TRACE) sl@0: sl@0: #if defined(_ASSERTIONS) sl@0: void Util::Assert(const TText* aFile,TInt aLine) sl@0: { sl@0: TBuf<32> b=_S("dbms:"); sl@0: b+=Filename(aFile); sl@0: User::Panic(b,aLine); sl@0: } sl@0: #endif//defined(_ASSERTIONS) sl@0: sl@0: #if defined(_NOTIFY) sl@0: #pragma message(__FILE__ " : Leave Notification is enabled") sl@0: sl@0: void Util::Leave(const TText* aFile,TInt aLine,TInt aError) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: TBuf<60> buf; sl@0: _LIT(KFormat,"***Error=%d at %S(%d)"); sl@0: buf.Format(KFormat,aError,&f,aLine); sl@0: __TRACE(buf); sl@0: _LIT(KNotify,"DBMS Leave "); sl@0: buf.Insert(0,KNotify); sl@0: // User::InfoPrint(buf); sl@0: __TRACE(buf); sl@0: User::Leave(aError); sl@0: } sl@0: sl@0: TInt Util::LeaveIfError(const TText* aFile,TInt aLine,TInt aError) sl@0: { sl@0: if (aError<0) sl@0: Leave(aFile,aLine,aError); sl@0: return aError; sl@0: } sl@0: #endif//defined(_NOTIFY) sl@0: sl@0: #if defined(_TRACE) sl@0: #pragma message(__FILE__ " : Tracing is enabled") sl@0: sl@0: void Util::Trace(const TText* aFile,TInt aLine) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: _LIT(KFormat,"%S(%d)\n"); sl@0: RDebug::Print(KFormat,&f,aLine); sl@0: } sl@0: sl@0: void Util::Trace(const TText* aFile,TInt aLine,const TText* aString) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: _LIT(KFormat,"%S(%d) : %s\n"); sl@0: RDebug::Print(KFormat,&f,aLine,aString); sl@0: } sl@0: void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,const TDesC& aDes) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: _LIT(KFormat,"%S(%d) : %s = \"%S\"\n"); sl@0: RDebug::Print(KFormat,&f,aLine,aExp,&aDes); sl@0: } sl@0: sl@0: void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,const TAny* aPtr) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: _LIT(KFormat,"%S(%d) : %s = %08x\n"); sl@0: RDebug::Print(KFormat,&f,aLine,aExp,TUint(aPtr)); sl@0: } sl@0: sl@0: void Util::Trace(const TText* aFile,TInt aLine,const TText* aExp,TInt aVal) sl@0: { sl@0: TPtrC f(Filename(aFile)); sl@0: _LIT(KFormat,"%S(%d) : %s = %d (0x%x)\n"); sl@0: RDebug::Print(KFormat,&f,aLine,aExp,aVal,aVal); sl@0: } sl@0: #endif//defined(_TRACE) sl@0: sl@0: #ifdef __DBINVARIANT__ sl@0: void Util::Invariant(TBool aExprVal) sl@0: { sl@0: if(!aExprVal) sl@0: { sl@0: User::Invariant(); sl@0: } sl@0: } sl@0: #endif//__DBINVARIANT__ sl@0: