sl@0: // Copyright (c) 2003-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: // sl@0: sl@0: #include sl@0: #include "BaAssert.h" sl@0: #include "BaCompileAssert.h" sl@0: sl@0: //You are not allowed to add/change something into KErrorMapTbl sl@0: //array without adding/changing TBafPanic enum value, which is used sl@0: //as an array index for accessing KErrorMapTbl array elements. sl@0: LOCAL_D const TInt KErrorMapTbl[] = sl@0: { sl@0: KErrCorrupt, sl@0: KErrCorrupt, //EBafPanicResourceLongerThanBuffer =1, sl@0: KErrCorrupt, //EBafPanicMatcherOutOfRange =2, sl@0: KErrCorrupt, //EBafPanicTextBufOutOfRange =3, sl@0: KErrEof, //EBafPanicResourceReaderEndExceeded =4, sl@0: KErrArgument,//EBafPanicResourceReaderStartExceeded =5, sl@0: KErrCorrupt, //EBafPanicBulkDataWriting =6, sl@0: KErrCorrupt, //EBafPanicBulkDataNotWriting =7, sl@0: KErrCorrupt, //EBafPanicBulkDataCannotSaveToFile =8, sl@0: KErrCorrupt, //EBafPanicBulkDataNotEmbedded =9, sl@0: KErrCorrupt, //EBafPanicSoundDataCannotChangeCompressorType =10, sl@0: KErrCorrupt, //EBafPanicSoundPlaying =11, sl@0: KErrCorrupt, //EBafPanicSoundSamplerActive =12, sl@0: KErrCorrupt, //EBafPanicLibAssocAlreadySet =13, sl@0: KErrCorrupt, //EBafPanicSystemSoundNoPath =14, sl@0: KErrCorrupt, //EBafPanicUnicodeTextPaddingError =15, sl@0: KErrCorrupt, //EBafPanicOldResourceFormat =16, // no longer used sl@0: KErrCorrupt, //EBafPanicInvalidSoundCategory =17, sl@0: KErrCorrupt, //EBafPanicInvalidSoundPriority =18, sl@0: KErrCorrupt, //EBafPanicNullUid =19, sl@0: KErrCorrupt, //EBafPanicBadResourceFileFormat =20, sl@0: KErrCorrupt, //EBafPanicBadArrayPosition =21, sl@0: KErrCorrupt, //EBafPanicBadCompareNames =22, sl@0: KErrCorrupt, //EBafPanicBadDrive =23, sl@0: KErrCorrupt, //EBafPanicBadDecompression =24, sl@0: KErrCorrupt, //EBafPanicIndexIsOddNumberOfBytes =25, sl@0: KErrCorrupt, //EBafPanicBadNumberOfResources =26, sl@0: KErrCorrupt, //EBafPanicBadCacheLength =27, sl@0: KErrCorrupt, //EBafPanicBadIndexLength1 =28, sl@0: KErrCorrupt, //EBafPanicBadIndexLength2 =29, sl@0: KErrCorrupt, //EBafPanicBadIndexLength3 =30, sl@0: KErrArgument,//EBafPanicBadInitialization1 =31, We can't get ROM file address, so we expect that it is RAM file sl@0: KErrArgument,//EBafPanicBadInitialization2 =32, sl@0: KErrArgument,//EBafPanicBadInitialization3 =33, sl@0: KErrCorrupt, //EBafPanicIndexOverRan =34, sl@0: KErrCorrupt, //EBafPanicNullPointer =35, sl@0: KErrGeneral, //EBafPanicNotOpened =36, CExtra instance is NULL sl@0: KErrCorrupt, //EBafPanicNegativeArrayIndex =37, sl@0: KErrEof, //EBafPanicEndOfStream1 =38, sl@0: KErrEof, //EBafPanicEndOfStream2 =39, sl@0: KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits1 =40, sl@0: KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits2 =41, sl@0: KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary1 =42, sl@0: KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary2 =43, sl@0: KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit1 =44, sl@0: KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit2 =45, sl@0: KErrCorrupt, //EBafPanicBadCurrentBitPosition1 =46, sl@0: KErrCorrupt, //EBafPanicBadCurrentBitPosition2 =47, sl@0: KErrCorrupt, //EBafPanicBadNumberOfBitsReadFromCurrentByte =48, sl@0: KErrCorrupt, //EBafPanicBadNumberOfBitsLeftToRead =49, sl@0: KErrCorrupt, //EBafPanicNotConstructed1 =50, sl@0: KErrCorrupt, //EBafPanicNotConstructed2 =51, sl@0: KErrCorrupt, //EBafPanicNotConstructed3 =52, sl@0: KErrCorrupt, //EBafPanicNotConstructed4 =53, sl@0: KErrCorrupt, //EBafPanicNotConstructed5 =54, sl@0: KErrCorrupt, //EBafPanicNegativeLengthOfBitBuffer =55, sl@0: KErrArgument,//EBafPanicNegativeResourceIndex1 =56, sl@0: KErrCorrupt, //EBafPanicNegativeResourceIndex2 =57, sl@0: KErrCorrupt, //EBafPanicNegativeResourceIndex3 =58, sl@0: KErrCorrupt, //EBafPanicBadFlags1 =59, sl@0: KErrCorrupt, //EBafPanicBadFlags2 =60, sl@0: KErrCorrupt, //EBafPanicBadFlags3 =61, sl@0: KErrCorrupt, //EBafPanicBadFlags4 =62, sl@0: KErrCorrupt, //EBafPanicBadFlags5 =63, sl@0: KErrCorrupt, //EBafPanicBadFlags6 =64, sl@0: KErrCorrupt, //EBafPanicNegativeIndexEntry =65, sl@0: KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed1=66, sl@0: KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed2=67, sl@0: KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed3=68, sl@0: KErrCorrupt, //EBafPanicBadHeaderLength =69 sl@0: KErrCorrupt, //EBafPanicNullPtr1 =70, sl@0: KErrArgument,//EBafPanicNullPtr2 =71 sl@0: KErrCorrupt, //EBafPanicNullPtr3 =72 sl@0: KErrCorrupt, //EBafPanicNullPtr4 =73 sl@0: KErrCorrupt, //EBafPanicNullPtr5 =74 sl@0: KErrCorrupt, //EBafPanicNullPtr6 =75 sl@0: KErrCorrupt, //EBafPanicNullPtr7 =76 sl@0: KErrCorrupt, //EBafPanicNullPtr8 =77 sl@0: KErrCorrupt, //EBafPanicNullPtr9 =78 sl@0: KErrCorrupt, //EBafPanicNullPtr10 =79 sl@0: KErrCorrupt, //EBafPanicNullPtr11 =80 sl@0: KErrCorrupt, //EBafPanicNullPtr12 =81 sl@0: KErrCorrupt, //EBafPanicNullPtr13 =82 sl@0: KErrCorrupt, //EBafPanicNullPtr14 =83 sl@0: KErrCorrupt, //EBafPanicNegativeNumber =84 sl@0: KErrCorrupt, //EBafPanicBadHeader1 =85 sl@0: KErrCorrupt, //EBafPanicBadHeader2 =86 sl@0: KErrCorrupt, //EBafPanicBadHeader3 =87 sl@0: KErrCorrupt, //EBafPanicBadHeader4 =88 sl@0: KErrCorrupt, //EBafPanicBadHeader5 =89 sl@0: KErrCorrupt, //EBafPanicFileSize =90 sl@0: KErrCorrupt, //EBafPanicOverflow =91 sl@0: KErrCorrupt, //EBafPanicBadIndex =92 sl@0: KErrCorrupt, //EBafPanicNegativeNumber2 =93 sl@0: KErrCorrupt, //EBafPanicFileSize2 =94 sl@0: KErrCorrupt, //EBafPanicNegativeNumber3 =95 sl@0: KErrCorrupt, //EBafPanicNegativePos =96 sl@0: KErrCorrupt, //EBafPanicNegativeLength =97 sl@0: KErrCorrupt, //EBafPanicMaxLength =98 sl@0: KErrCorrupt, //EBafPanicBadIndex2 =99 sl@0: KErrCorrupt, //EBafPanicBadIndex3 =100 sl@0: KErrCorrupt, //EBafPanicMaxLength2 =101 sl@0: KErrCorrupt, //EBafPanicFileSize3 =102 sl@0: KErrCorrupt, //EBafPanicStartPos =103 sl@0: KErrCorrupt, //EBafPanicStartPos2 =104 sl@0: KErrCorrupt, //EBafPanicFileSize4 =105 sl@0: KErrCorrupt, //EBafPanicBadOffset =106 sl@0: KErrCorrupt, //EBafPanicBadOffset2 =107 sl@0: KErrArgument,//EBafPanicBadOpenArg =108 sl@0: KErrCorrupt, //EBafPanicBufLength =109 sl@0: KErrArgument //EBafPanicRFsConnectArg =110 sl@0: }; sl@0: sl@0: /** This static funtion is used by TBaAssert instances to convert Panic code to sl@0: error codes. KErrorMapTbl static array is used. sl@0: sl@0: @internalComponent sl@0: @param aPanicCode - BAFL panic code. sl@0: @return Error code - KErrCorrupt, KErrArgument,... sl@0: @leave KErrArgument - if the panic code value can't be used as and array index sl@0: to access corresponding error code. */ sl@0: LOCAL_C TInt Panic2ErrorL(TBafPanic aPanicCode) sl@0: { sl@0: if(static_cast (aPanicCode) >= (sizeof(KErrorMapTbl)/ sizeof(KErrorMapTbl[0]))) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return KErrorMapTbl[static_cast (aPanicCode)]; sl@0: } sl@0: sl@0: /** Global Panic function. Used internaly by BAFL classes. sl@0: The default function behaviour is to call User::Panic(). sl@0: @internalComponent */ sl@0: GLDEF_C void Panic(TBafPanic aPanic) sl@0: { sl@0: User::Panic(_L("BAFL"), aPanic); sl@0: } sl@0: sl@0: /** By default TBaAssert methods will panic. sl@0: An error will be issued at compile time if the class size is not sl@0: sizeof(TBaAssert::TErrorAction). sl@0: @internalComponent */ sl@0: TBaAssert::TBaAssert() : sl@0: iErrorAction(TBaAssert::EPanic) sl@0: { sl@0: COMPILE_TIME_ASSERT(sizeof(TBaAssert) == sizeof(TBaAssert::TErrorAction)); sl@0: } sl@0: sl@0: /** Initializes TBaAssert object panic/leave behaviour. sl@0: @internalComponent sl@0: @param aErrorAction - TBaAssert::EPanic or TBaAssert::ELeave. */ sl@0: TBaAssert::TBaAssert(TErrorAction aErrorAction) : sl@0: iErrorAction(aErrorAction) sl@0: { sl@0: } sl@0: sl@0: /** The method panics/leaves if aAssertExprVal value is EFalse. The panic will be raised sl@0: only in the DEBUG build. sl@0: @internalComponent sl@0: @param aAssertExprVal If EFalse, the method panics/leaves. sl@0: @param aPanic Panic code. If the method must leave, the code sl@0: will be mapped to some Symbian OS error code. */ sl@0: void TBaAssert::AssertDebL(TBool aAssertExprVal, TBafPanic aPanic) const sl@0: { sl@0: DoAssertL(aAssertExprVal, ETrue, aPanic); sl@0: } sl@0: sl@0: /** The method panics/leaves if aAssertExprVal value is EFalse. sl@0: @internalComponent sl@0: @param aAssertExprVal If EFalse, the method panics/leaves. sl@0: @param aPanic Panic code. If the method must leave, the code sl@0: will be mapped to some Symbian OS error code. */ sl@0: void TBaAssert::AssertRelL(TBool aAssertExprVal, TBafPanic aPanic) const sl@0: { sl@0: DoAssertL(aAssertExprVal, EFalse, aPanic); sl@0: } sl@0: sl@0: /** @internalComponent */ sl@0: void TBaAssert::DoAssertL(TBool aAssertExprVal, TBool aDebug, TBafPanic aPanic) const sl@0: { sl@0: if(!aAssertExprVal) sl@0: { sl@0: iErrorAction == TBaAssert::ELeave ? DoLeaveL(aPanic) : DoAssert(aDebug, aPanic); sl@0: } sl@0: } sl@0: sl@0: /** @internalComponent */ sl@0: void TBaAssert::DoLeaveL(TBafPanic aPanic) const sl@0: { sl@0: TInt error = Panic2ErrorL(aPanic); sl@0: User::Leave(error); sl@0: } sl@0: sl@0: /** @internalComponent */ sl@0: void TBaAssert::DoAssert(TBool aDebug, TBafPanic aPanic) const sl@0: { sl@0: if(aDebug) sl@0: { sl@0: __ASSERT_DEBUG(EFalse, ::Panic(aPanic)); sl@0: } sl@0: else sl@0: { sl@0: ::Panic(aPanic); sl@0: } sl@0: } sl@0: sl@0: sl@0: