1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/src/BaAssert.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32std.h>
1.20 +#include "BaAssert.h"
1.21 +#include "BaCompileAssert.h"
1.22 +
1.23 +//You are not allowed to add/change something into KErrorMapTbl
1.24 +//array without adding/changing TBafPanic enum value, which is used
1.25 +//as an array index for accessing KErrorMapTbl array elements.
1.26 +LOCAL_D const TInt KErrorMapTbl[] =
1.27 + {
1.28 + KErrCorrupt,
1.29 + KErrCorrupt, //EBafPanicResourceLongerThanBuffer =1,
1.30 + KErrCorrupt, //EBafPanicMatcherOutOfRange =2,
1.31 + KErrCorrupt, //EBafPanicTextBufOutOfRange =3,
1.32 + KErrEof, //EBafPanicResourceReaderEndExceeded =4,
1.33 + KErrArgument,//EBafPanicResourceReaderStartExceeded =5,
1.34 + KErrCorrupt, //EBafPanicBulkDataWriting =6,
1.35 + KErrCorrupt, //EBafPanicBulkDataNotWriting =7,
1.36 + KErrCorrupt, //EBafPanicBulkDataCannotSaveToFile =8,
1.37 + KErrCorrupt, //EBafPanicBulkDataNotEmbedded =9,
1.38 + KErrCorrupt, //EBafPanicSoundDataCannotChangeCompressorType =10,
1.39 + KErrCorrupt, //EBafPanicSoundPlaying =11,
1.40 + KErrCorrupt, //EBafPanicSoundSamplerActive =12,
1.41 + KErrCorrupt, //EBafPanicLibAssocAlreadySet =13,
1.42 + KErrCorrupt, //EBafPanicSystemSoundNoPath =14,
1.43 + KErrCorrupt, //EBafPanicUnicodeTextPaddingError =15,
1.44 + KErrCorrupt, //EBafPanicOldResourceFormat =16, // no longer used
1.45 + KErrCorrupt, //EBafPanicInvalidSoundCategory =17,
1.46 + KErrCorrupt, //EBafPanicInvalidSoundPriority =18,
1.47 + KErrCorrupt, //EBafPanicNullUid =19,
1.48 + KErrCorrupt, //EBafPanicBadResourceFileFormat =20,
1.49 + KErrCorrupt, //EBafPanicBadArrayPosition =21,
1.50 + KErrCorrupt, //EBafPanicBadCompareNames =22,
1.51 + KErrCorrupt, //EBafPanicBadDrive =23,
1.52 + KErrCorrupt, //EBafPanicBadDecompression =24,
1.53 + KErrCorrupt, //EBafPanicIndexIsOddNumberOfBytes =25,
1.54 + KErrCorrupt, //EBafPanicBadNumberOfResources =26,
1.55 + KErrCorrupt, //EBafPanicBadCacheLength =27,
1.56 + KErrCorrupt, //EBafPanicBadIndexLength1 =28,
1.57 + KErrCorrupt, //EBafPanicBadIndexLength2 =29,
1.58 + KErrCorrupt, //EBafPanicBadIndexLength3 =30,
1.59 + KErrArgument,//EBafPanicBadInitialization1 =31, We can't get ROM file address, so we expect that it is RAM file
1.60 + KErrArgument,//EBafPanicBadInitialization2 =32,
1.61 + KErrArgument,//EBafPanicBadInitialization3 =33,
1.62 + KErrCorrupt, //EBafPanicIndexOverRan =34,
1.63 + KErrCorrupt, //EBafPanicNullPointer =35,
1.64 + KErrGeneral, //EBafPanicNotOpened =36, CExtra instance is NULL
1.65 + KErrCorrupt, //EBafPanicNegativeArrayIndex =37,
1.66 + KErrEof, //EBafPanicEndOfStream1 =38,
1.67 + KErrEof, //EBafPanicEndOfStream2 =39,
1.68 + KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits1 =40,
1.69 + KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits2 =41,
1.70 + KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary1 =42,
1.71 + KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary2 =43,
1.72 + KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit1 =44,
1.73 + KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit2 =45,
1.74 + KErrCorrupt, //EBafPanicBadCurrentBitPosition1 =46,
1.75 + KErrCorrupt, //EBafPanicBadCurrentBitPosition2 =47,
1.76 + KErrCorrupt, //EBafPanicBadNumberOfBitsReadFromCurrentByte =48,
1.77 + KErrCorrupt, //EBafPanicBadNumberOfBitsLeftToRead =49,
1.78 + KErrCorrupt, //EBafPanicNotConstructed1 =50,
1.79 + KErrCorrupt, //EBafPanicNotConstructed2 =51,
1.80 + KErrCorrupt, //EBafPanicNotConstructed3 =52,
1.81 + KErrCorrupt, //EBafPanicNotConstructed4 =53,
1.82 + KErrCorrupt, //EBafPanicNotConstructed5 =54,
1.83 + KErrCorrupt, //EBafPanicNegativeLengthOfBitBuffer =55,
1.84 + KErrArgument,//EBafPanicNegativeResourceIndex1 =56,
1.85 + KErrCorrupt, //EBafPanicNegativeResourceIndex2 =57,
1.86 + KErrCorrupt, //EBafPanicNegativeResourceIndex3 =58,
1.87 + KErrCorrupt, //EBafPanicBadFlags1 =59,
1.88 + KErrCorrupt, //EBafPanicBadFlags2 =60,
1.89 + KErrCorrupt, //EBafPanicBadFlags3 =61,
1.90 + KErrCorrupt, //EBafPanicBadFlags4 =62,
1.91 + KErrCorrupt, //EBafPanicBadFlags5 =63,
1.92 + KErrCorrupt, //EBafPanicBadFlags6 =64,
1.93 + KErrCorrupt, //EBafPanicNegativeIndexEntry =65,
1.94 + KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed1=66,
1.95 + KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed2=67,
1.96 + KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed3=68,
1.97 + KErrCorrupt, //EBafPanicBadHeaderLength =69
1.98 + KErrCorrupt, //EBafPanicNullPtr1 =70,
1.99 + KErrArgument,//EBafPanicNullPtr2 =71
1.100 + KErrCorrupt, //EBafPanicNullPtr3 =72
1.101 + KErrCorrupt, //EBafPanicNullPtr4 =73
1.102 + KErrCorrupt, //EBafPanicNullPtr5 =74
1.103 + KErrCorrupt, //EBafPanicNullPtr6 =75
1.104 + KErrCorrupt, //EBafPanicNullPtr7 =76
1.105 + KErrCorrupt, //EBafPanicNullPtr8 =77
1.106 + KErrCorrupt, //EBafPanicNullPtr9 =78
1.107 + KErrCorrupt, //EBafPanicNullPtr10 =79
1.108 + KErrCorrupt, //EBafPanicNullPtr11 =80
1.109 + KErrCorrupt, //EBafPanicNullPtr12 =81
1.110 + KErrCorrupt, //EBafPanicNullPtr13 =82
1.111 + KErrCorrupt, //EBafPanicNullPtr14 =83
1.112 + KErrCorrupt, //EBafPanicNegativeNumber =84
1.113 + KErrCorrupt, //EBafPanicBadHeader1 =85
1.114 + KErrCorrupt, //EBafPanicBadHeader2 =86
1.115 + KErrCorrupt, //EBafPanicBadHeader3 =87
1.116 + KErrCorrupt, //EBafPanicBadHeader4 =88
1.117 + KErrCorrupt, //EBafPanicBadHeader5 =89
1.118 + KErrCorrupt, //EBafPanicFileSize =90
1.119 + KErrCorrupt, //EBafPanicOverflow =91
1.120 + KErrCorrupt, //EBafPanicBadIndex =92
1.121 + KErrCorrupt, //EBafPanicNegativeNumber2 =93
1.122 + KErrCorrupt, //EBafPanicFileSize2 =94
1.123 + KErrCorrupt, //EBafPanicNegativeNumber3 =95
1.124 + KErrCorrupt, //EBafPanicNegativePos =96
1.125 + KErrCorrupt, //EBafPanicNegativeLength =97
1.126 + KErrCorrupt, //EBafPanicMaxLength =98
1.127 + KErrCorrupt, //EBafPanicBadIndex2 =99
1.128 + KErrCorrupt, //EBafPanicBadIndex3 =100
1.129 + KErrCorrupt, //EBafPanicMaxLength2 =101
1.130 + KErrCorrupt, //EBafPanicFileSize3 =102
1.131 + KErrCorrupt, //EBafPanicStartPos =103
1.132 + KErrCorrupt, //EBafPanicStartPos2 =104
1.133 + KErrCorrupt, //EBafPanicFileSize4 =105
1.134 + KErrCorrupt, //EBafPanicBadOffset =106
1.135 + KErrCorrupt, //EBafPanicBadOffset2 =107
1.136 + KErrArgument,//EBafPanicBadOpenArg =108
1.137 + KErrCorrupt, //EBafPanicBufLength =109
1.138 + KErrArgument //EBafPanicRFsConnectArg =110
1.139 + };
1.140 +
1.141 +/** This static funtion is used by TBaAssert instances to convert Panic code to
1.142 +error codes. KErrorMapTbl static array is used.
1.143 +
1.144 +@internalComponent
1.145 +@param aPanicCode - BAFL panic code.
1.146 +@return Error code - KErrCorrupt, KErrArgument,...
1.147 +@leave KErrArgument - if the panic code value can't be used as and array index
1.148 +to access corresponding error code. */
1.149 +LOCAL_C TInt Panic2ErrorL(TBafPanic aPanicCode)
1.150 + {
1.151 + if(static_cast <TUint> (aPanicCode) >= (sizeof(KErrorMapTbl)/ sizeof(KErrorMapTbl[0])))
1.152 + {
1.153 + User::Leave(KErrArgument);
1.154 + }
1.155 + return KErrorMapTbl[static_cast <TUint> (aPanicCode)];
1.156 + }
1.157 +
1.158 +/** Global Panic function. Used internaly by BAFL classes.
1.159 +The default function behaviour is to call User::Panic().
1.160 +@internalComponent */
1.161 +GLDEF_C void Panic(TBafPanic aPanic)
1.162 + {
1.163 + User::Panic(_L("BAFL"), aPanic);
1.164 + }
1.165 +
1.166 +/** By default TBaAssert methods will panic.
1.167 +An error will be issued at compile time if the class size is not
1.168 +sizeof(TBaAssert::TErrorAction).
1.169 +@internalComponent */
1.170 +TBaAssert::TBaAssert() :
1.171 + iErrorAction(TBaAssert::EPanic)
1.172 + {
1.173 + COMPILE_TIME_ASSERT(sizeof(TBaAssert) == sizeof(TBaAssert::TErrorAction));
1.174 + }
1.175 +
1.176 +/** Initializes TBaAssert object panic/leave behaviour.
1.177 +@internalComponent
1.178 +@param aErrorAction - TBaAssert::EPanic or TBaAssert::ELeave. */
1.179 +TBaAssert::TBaAssert(TErrorAction aErrorAction) :
1.180 + iErrorAction(aErrorAction)
1.181 + {
1.182 + }
1.183 +
1.184 +/** The method panics/leaves if aAssertExprVal value is EFalse. The panic will be raised
1.185 +only in the DEBUG build.
1.186 +@internalComponent
1.187 +@param aAssertExprVal If EFalse, the method panics/leaves.
1.188 +@param aPanic Panic code. If the method must leave, the code
1.189 +will be mapped to some Symbian OS error code. */
1.190 +void TBaAssert::AssertDebL(TBool aAssertExprVal, TBafPanic aPanic) const
1.191 + {
1.192 + DoAssertL(aAssertExprVal, ETrue, aPanic);
1.193 + }
1.194 +
1.195 +/** The method panics/leaves if aAssertExprVal value is EFalse.
1.196 +@internalComponent
1.197 +@param aAssertExprVal If EFalse, the method panics/leaves.
1.198 +@param aPanic Panic code. If the method must leave, the code
1.199 +will be mapped to some Symbian OS error code. */
1.200 +void TBaAssert::AssertRelL(TBool aAssertExprVal, TBafPanic aPanic) const
1.201 + {
1.202 + DoAssertL(aAssertExprVal, EFalse, aPanic);
1.203 + }
1.204 +
1.205 +/** @internalComponent */
1.206 +void TBaAssert::DoAssertL(TBool aAssertExprVal, TBool aDebug, TBafPanic aPanic) const
1.207 + {
1.208 + if(!aAssertExprVal)
1.209 + {
1.210 + iErrorAction == TBaAssert::ELeave ? DoLeaveL(aPanic) : DoAssert(aDebug, aPanic);
1.211 + }
1.212 + }
1.213 +
1.214 +/** @internalComponent */
1.215 +void TBaAssert::DoLeaveL(TBafPanic aPanic) const
1.216 + {
1.217 + TInt error = Panic2ErrorL(aPanic);
1.218 + User::Leave(error);
1.219 + }
1.220 +
1.221 +/** @internalComponent */
1.222 +void TBaAssert::DoAssert(TBool aDebug, TBafPanic aPanic) const
1.223 + {
1.224 + if(aDebug)
1.225 + {
1.226 + __ASSERT_DEBUG(EFalse, ::Panic(aPanic));
1.227 + }
1.228 + else
1.229 + {
1.230 + ::Panic(aPanic);
1.231 + }
1.232 + }
1.233 +
1.234 +
1.235 +