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: // Special build functions: ASSERTING, NOTIFY on Leave, TRACING
sl@0: // 
sl@0: //
sl@0: 
sl@0: #ifndef __D32ASSERT_H__
sl@0: #define __D32ASSERT_H__
sl@0: 
sl@0: #include <e32std.h>
sl@0: 
sl@0: #if defined(_DEBUG)
sl@0: 	#define __DEBUG(s) s
sl@0: 	#define _ASSERTIONS
sl@0: 	//#define _NOTIFY
sl@0: 	//#define _TRACE
sl@0: 	//#define __DBDUMP__
sl@0: 	#define __DBINVARIANT__
sl@0: #else
sl@0: 	#define __DEBUG(s)
sl@0: #endif
sl@0: 
sl@0: #ifdef __DBDUMP__
sl@0: #include <f32file.h>		//RFile
sl@0: #endif
sl@0: 
sl@0: /**
sl@0: DECLARE_DB_DUMP, DECLARE_DB_DUMP2, DECLARE_DB_DUMP3 macros can be used for printing out
sl@0: DBMS security policy data to a text file. 
sl@0: __DBDUMP__ macro must be defined if you want to use them.
sl@0: Usage:
sl@0: Use DECLARE_DB_DUMP macro for declaring pure virtual Dump(RFile& aFile) method in a particular class.
sl@0: Use DECLARE_DB_DUMP2 macro for declaring virtual Dump(RFile& aFile) method in a particular class.
sl@0: Use DECLARE_DB_DUMP3 macro for declaring non-virtual Dump(RFile& aFile) method in a particular class.
sl@0: @internalComponent
sl@0: */
sl@0: 
sl@0: #ifdef __DBDUMP__
sl@0: #define DECLARE_DB_DUMP(aFile) virtual void Dump(RFile& aFile) const = 0;
sl@0: #define DECLARE_DB_DUMP2(aFile) virtual void Dump(RFile& aFile) const;
sl@0: #define DECLARE_DB_DUMP3(aFile) void Dump(RFile& aFile) const;
sl@0: #else
sl@0: #define DECLARE_DB_DUMP(aFile)
sl@0: #define DECLARE_DB_DUMP2(aFile)
sl@0: #define DECLARE_DB_DUMP3(aFile)
sl@0: #endif
sl@0: 
sl@0: /**
sl@0: DECLARE_DB_INVARIANT, DECLARE_DB_INVARIANT2, DB_INVARIANT, DB_INVARIANT_ASSERT 
sl@0: macros can be used for asserting the internal state of DBMS security policy classes. 
sl@0: __DBINVARIANT__ macro must be defined if you want to use them.
sl@0: Usage:
sl@0: Use DECLARE_DB_INVARIANT macro for declaring virtual Invariant() method in a particular class.
sl@0: Use DECLARE_DB_INVARIANT2 macro for declaring non-virtual Invariant() method in a particular class.
sl@0: Use DB_INVARIANT macro to call Invariant() method somewhere in the code.
sl@0: Use DB_INVARIANT_ASSERT macro in places, where you want to use __ASSERT macro (it may not be defined).
sl@0: @internalComponent
sl@0: */
sl@0: 
sl@0: #ifdef __DBINVARIANT__
sl@0: #define DECLARE_DB_INVARIANT() virtual void Invariant() const;
sl@0: #define DECLARE_DB_INVARIANT2() void Invariant() const;
sl@0: #define DB_INVARIANT() Invariant()
sl@0: #define DB_INVARIANT_ASSERT(aExprVal) Util::Invariant(aExprVal)
sl@0: #else
sl@0: #define DECLARE_DB_INVARIANT()
sl@0: #define DECLARE_DB_INVARIANT2()
sl@0: #define DB_INVARIANT() void(0)
sl@0: #define DB_INVARIANT_ASSERT(aExprVal) void(0)
sl@0: #endif
sl@0: 
sl@0: /**
sl@0: @internalComponent
sl@0: */
sl@0: class Util
sl@0: 	{
sl@0: public:
sl@0: 	static void Assert(const TText* aFile,TInt aLine);
sl@0: //
sl@0: 	static void Leave(const TText* aFile,TInt aLine,TInt aError);
sl@0: 	static TInt LeaveIfError(const TText* aFile,TInt aLine,TInt aError);
sl@0: //
sl@0: 	static void Trace(const TText* aFile,TInt aLine);
sl@0: 	static void Trace(const TText* aFile,TInt aLine,const TText* aString);
sl@0: 	static void Trace(const TText* aFile,TInt aLine,const TText* aExp,const TDesC& aDes);
sl@0: 	static void Trace(const TText* aFile,TInt aLine,const TText* aExp,TInt aVal);
sl@0: 	static void Trace(const TText* aFile,TInt aLine,const TText* aExp,const TAny* aPtr);
sl@0: 	static void Invariant(TBool aExprVal);
sl@0: private:
sl@0: 	static TPtrC Filename(const TText* aFile);
sl@0: 	};
sl@0: 
sl@0: #define __STRING(s) _S(s)
sl@0: 
sl@0: #if defined(_ASSERTIONS)
sl@0: 	#define __ASSERT(c) (void)((c)||(Util::Assert(__STRING(__FILE__),__LINE__),0))
sl@0: #else
sl@0: 	#define __ASSERT(c) void(0)
sl@0: #endif
sl@0: 
sl@0: #if defined(_NOTIFY)
sl@0: 	#define __LEAVE(r) Util::Leave(__STRING(__FILE__),__LINE__,r)
sl@0: 	#define __LEAVE_IF_ERROR(r) Util::LeaveIfError(__STRING(__FILE__),__LINE__,r)
sl@0: #else
sl@0: 	#define __LEAVE(r) User::Leave(r)
sl@0: 	#define __LEAVE_IF_ERROR(r) User::LeaveIfError(r)
sl@0: #endif
sl@0: 
sl@0: #if defined(_TRACE)
sl@0: 	#define __TRACEP() Util::Trace(__STRING(__FILE__),__LINE__)
sl@0: 	#define __TRACES(string) Util::Trace(__STRING(__FILE__),__LINE__,_S(string))
sl@0: 	#define __TRACE(exp) Util::Trace(__STRING(__FILE__),__LINE__,__STRING(#exp),exp)
sl@0: #else
sl@0: 	#define __TRACEP() void(0)
sl@0: 	#define __TRACES(string) void(0)
sl@0: 	#define __TRACE(exp) void(0)
sl@0: #endif
sl@0: 
sl@0: #endif//__D32ASSERT_H__