os/ossrv/lowlevellibsandfws/apputils/src/BaAssert.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-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 //
    15 
    16 #include <e32std.h>
    17 #include "BaAssert.h"
    18 #include "BaCompileAssert.h"
    19 
    20 //You are not allowed to add/change something into KErrorMapTbl
    21 //array without adding/changing TBafPanic enum value, which is used
    22 //as an array index for accessing KErrorMapTbl array elements.
    23 LOCAL_D const TInt KErrorMapTbl[] = 
    24 	{
    25 	KErrCorrupt,
    26 	KErrCorrupt, //EBafPanicResourceLongerThanBuffer			=1,
    27 	KErrCorrupt, //EBafPanicMatcherOutOfRange					=2,
    28 	KErrCorrupt, //EBafPanicTextBufOutOfRange					=3,
    29 	KErrEof,	 //EBafPanicResourceReaderEndExceeded			=4,
    30 	KErrArgument,//EBafPanicResourceReaderStartExceeded			=5,
    31 	KErrCorrupt, //EBafPanicBulkDataWriting						=6,
    32 	KErrCorrupt, //EBafPanicBulkDataNotWriting					=7,
    33 	KErrCorrupt, //EBafPanicBulkDataCannotSaveToFile			=8,
    34 	KErrCorrupt, //EBafPanicBulkDataNotEmbedded					=9,
    35 	KErrCorrupt, //EBafPanicSoundDataCannotChangeCompressorType	=10,
    36 	KErrCorrupt, //EBafPanicSoundPlaying						=11,
    37 	KErrCorrupt, //EBafPanicSoundSamplerActive					=12,
    38 	KErrCorrupt, //EBafPanicLibAssocAlreadySet					=13,
    39 	KErrCorrupt, //EBafPanicSystemSoundNoPath					=14,
    40 	KErrCorrupt, //EBafPanicUnicodeTextPaddingError				=15,
    41 	KErrCorrupt, //EBafPanicOldResourceFormat					=16, // no longer used
    42 	KErrCorrupt, //EBafPanicInvalidSoundCategory				=17,
    43 	KErrCorrupt, //EBafPanicInvalidSoundPriority				=18,
    44 	KErrCorrupt, //EBafPanicNullUid								=19,
    45 	KErrCorrupt, //EBafPanicBadResourceFileFormat				=20,
    46 	KErrCorrupt, //EBafPanicBadArrayPosition					=21,
    47 	KErrCorrupt, //EBafPanicBadCompareNames						=22,
    48 	KErrCorrupt, //EBafPanicBadDrive							=23,
    49 	KErrCorrupt, //EBafPanicBadDecompression					=24,
    50 	KErrCorrupt, //EBafPanicIndexIsOddNumberOfBytes				=25,
    51 	KErrCorrupt, //EBafPanicBadNumberOfResources				=26,
    52 	KErrCorrupt, //EBafPanicBadCacheLength						=27,
    53 	KErrCorrupt, //EBafPanicBadIndexLength1						=28,
    54 	KErrCorrupt, //EBafPanicBadIndexLength2						=29,
    55 	KErrCorrupt, //EBafPanicBadIndexLength3						=30,
    56 	KErrArgument,//EBafPanicBadInitialization1					=31, We can't get ROM file address, so we expect that it is RAM file
    57 	KErrArgument,//EBafPanicBadInitialization2					=32,
    58 	KErrArgument,//EBafPanicBadInitialization3					=33,
    59 	KErrCorrupt, //EBafPanicIndexOverRan						=34,
    60 	KErrCorrupt, //EBafPanicNullPointer							=35,
    61 	KErrGeneral, //EBafPanicNotOpened							=36, CExtra instance is NULL
    62 	KErrCorrupt, //EBafPanicNegativeArrayIndex					=37,
    63 	KErrEof,	 //EBafPanicEndOfStream1						=38,
    64 	KErrEof,	 //EBafPanicEndOfStream2						=39,
    65 	KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits1	=40,
    66 	KErrCorrupt, //EBafPanicBadNumberOfConsecutivePrefixBits2	=41,
    67 	KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary1		=42,
    68 	KErrCorrupt, //EBafPanicBadNumberOfBitsOffByteBoundary2		=43,
    69 	KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit1			=44,
    70 	KErrCorrupt, //EBafPanicNegativeOffsetToFirstBit2			=45,
    71 	KErrCorrupt, //EBafPanicBadCurrentBitPosition1				=46,
    72 	KErrCorrupt, //EBafPanicBadCurrentBitPosition2				=47,
    73 	KErrCorrupt, //EBafPanicBadNumberOfBitsReadFromCurrentByte	=48,
    74 	KErrCorrupt, //EBafPanicBadNumberOfBitsLeftToRead			=49,
    75 	KErrCorrupt, //EBafPanicNotConstructed1						=50,
    76 	KErrCorrupt, //EBafPanicNotConstructed2						=51,
    77 	KErrCorrupt, //EBafPanicNotConstructed3						=52,
    78 	KErrCorrupt, //EBafPanicNotConstructed4						=53,
    79 	KErrCorrupt, //EBafPanicNotConstructed5						=54,
    80 	KErrCorrupt, //EBafPanicNegativeLengthOfBitBuffer			=55,
    81 	KErrArgument,//EBafPanicNegativeResourceIndex1				=56,
    82 	KErrCorrupt, //EBafPanicNegativeResourceIndex2				=57,
    83 	KErrCorrupt, //EBafPanicNegativeResourceIndex3				=58,
    84 	KErrCorrupt, //EBafPanicBadFlags1							=59,
    85 	KErrCorrupt, //EBafPanicBadFlags2							=60,
    86 	KErrCorrupt, //EBafPanicBadFlags3							=61,
    87 	KErrCorrupt, //EBafPanicBadFlags4							=62,
    88 	KErrCorrupt, //EBafPanicBadFlags5							=63,
    89 	KErrCorrupt, //EBafPanicBadFlags6							=64,
    90 	KErrCorrupt, //EBafPanicNegativeIndexEntry					=65,
    91 	KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed1=66,
    92 	KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed2=67,
    93 	KErrCorrupt, //EBafPanicBadSizeOfLargestResourceWhenCompletelyUncompressed3=68,
    94 	KErrCorrupt, //EBafPanicBadHeaderLength						=69
    95 	KErrCorrupt, //EBafPanicNullPtr1							=70,
    96 	KErrArgument,//EBafPanicNullPtr2							=71
    97 	KErrCorrupt, //EBafPanicNullPtr3							=72
    98 	KErrCorrupt, //EBafPanicNullPtr4							=73
    99 	KErrCorrupt, //EBafPanicNullPtr5							=74
   100 	KErrCorrupt, //EBafPanicNullPtr6							=75
   101 	KErrCorrupt, //EBafPanicNullPtr7							=76
   102 	KErrCorrupt, //EBafPanicNullPtr8							=77
   103 	KErrCorrupt, //EBafPanicNullPtr9							=78
   104 	KErrCorrupt, //EBafPanicNullPtr10							=79
   105 	KErrCorrupt, //EBafPanicNullPtr11							=80
   106 	KErrCorrupt, //EBafPanicNullPtr12							=81
   107 	KErrCorrupt, //EBafPanicNullPtr13							=82
   108 	KErrCorrupt, //EBafPanicNullPtr14							=83
   109 	KErrCorrupt, //EBafPanicNegativeNumber						=84
   110 	KErrCorrupt, //EBafPanicBadHeader1							=85
   111 	KErrCorrupt, //EBafPanicBadHeader2							=86
   112 	KErrCorrupt, //EBafPanicBadHeader3							=87
   113 	KErrCorrupt, //EBafPanicBadHeader4							=88
   114 	KErrCorrupt, //EBafPanicBadHeader5							=89
   115 	KErrCorrupt, //EBafPanicFileSize							=90
   116 	KErrCorrupt, //EBafPanicOverflow							=91
   117 	KErrCorrupt, //EBafPanicBadIndex							=92
   118 	KErrCorrupt, //EBafPanicNegativeNumber2						=93
   119 	KErrCorrupt, //EBafPanicFileSize2							=94
   120 	KErrCorrupt, //EBafPanicNegativeNumber3						=95
   121 	KErrCorrupt, //EBafPanicNegativePos							=96
   122 	KErrCorrupt, //EBafPanicNegativeLength						=97
   123 	KErrCorrupt, //EBafPanicMaxLength							=98
   124 	KErrCorrupt, //EBafPanicBadIndex2							=99
   125 	KErrCorrupt, //EBafPanicBadIndex3							=100
   126 	KErrCorrupt, //EBafPanicMaxLength2							=101
   127 	KErrCorrupt, //EBafPanicFileSize3							=102
   128 	KErrCorrupt, //EBafPanicStartPos							=103
   129 	KErrCorrupt, //EBafPanicStartPos2							=104
   130 	KErrCorrupt, //EBafPanicFileSize4							=105
   131 	KErrCorrupt, //EBafPanicBadOffset							=106
   132 	KErrCorrupt, //EBafPanicBadOffset2							=107
   133 	KErrArgument,//EBafPanicBadOpenArg							=108
   134 	KErrCorrupt, //EBafPanicBufLength							=109
   135 	KErrArgument //EBafPanicRFsConnectArg						=110
   136 	};
   137 
   138 /** This static funtion is used by TBaAssert instances to convert Panic code to
   139 error codes. KErrorMapTbl static array is used. 
   140 
   141 @internalComponent
   142 @param aPanicCode - BAFL panic code.
   143 @return Error code - KErrCorrupt, KErrArgument,...
   144 @leave KErrArgument - if the panic code value can't be used as and array index
   145 to access corresponding error code. */
   146 LOCAL_C TInt Panic2ErrorL(TBafPanic aPanicCode) 
   147 	{
   148 	if(static_cast <TUint> (aPanicCode) >= (sizeof(KErrorMapTbl)/ sizeof(KErrorMapTbl[0])))
   149 		{
   150 		User::Leave(KErrArgument);
   151 		}
   152 	return KErrorMapTbl[static_cast <TUint> (aPanicCode)];
   153 	}
   154 
   155 /** Global Panic function. Used internaly by BAFL classes.
   156 The default function behaviour is to call User::Panic().
   157 @internalComponent */
   158 GLDEF_C void Panic(TBafPanic aPanic)
   159 	{
   160 	User::Panic(_L("BAFL"), aPanic);
   161 	}
   162 
   163 /** By default TBaAssert methods will panic.
   164 An error will be issued at compile time if the class size is not 
   165 sizeof(TBaAssert::TErrorAction).
   166 @internalComponent */
   167 TBaAssert::TBaAssert() :
   168 	iErrorAction(TBaAssert::EPanic)
   169 	{
   170 	COMPILE_TIME_ASSERT(sizeof(TBaAssert) == sizeof(TBaAssert::TErrorAction));
   171 	}
   172 
   173 /** Initializes TBaAssert object panic/leave behaviour.
   174 @internalComponent
   175 @param aErrorAction - TBaAssert::EPanic or TBaAssert::ELeave. */
   176 TBaAssert::TBaAssert(TErrorAction aErrorAction) :
   177 	iErrorAction(aErrorAction)
   178 	{
   179 	}
   180 
   181 /** The method panics/leaves if aAssertExprVal value is EFalse. The panic will be raised
   182 only in the DEBUG build.
   183 @internalComponent
   184 @param aAssertExprVal If EFalse, the method panics/leaves.
   185 @param aPanic Panic code. If the method must leave, the code
   186 will be mapped to some Symbian OS error code. */
   187 void TBaAssert::AssertDebL(TBool aAssertExprVal, TBafPanic aPanic) const
   188 	{
   189 	DoAssertL(aAssertExprVal, ETrue, aPanic);
   190 	}
   191 
   192 /** The method panics/leaves if aAssertExprVal value is EFalse.
   193 @internalComponent
   194 @param aAssertExprVal If EFalse, the method panics/leaves.
   195 @param aPanic Panic code. If the method must leave, the code
   196 will be mapped to some Symbian OS error code. */
   197 void TBaAssert::AssertRelL(TBool aAssertExprVal, TBafPanic aPanic) const
   198 	{
   199 	DoAssertL(aAssertExprVal, EFalse, aPanic);
   200 	}
   201 
   202 /** @internalComponent */
   203 void TBaAssert::DoAssertL(TBool aAssertExprVal, TBool aDebug, TBafPanic aPanic) const
   204 	{
   205 	if(!aAssertExprVal)
   206 		{
   207 		iErrorAction == TBaAssert::ELeave ? DoLeaveL(aPanic) : DoAssert(aDebug, aPanic);
   208 		}
   209 	}
   210 
   211 /** @internalComponent */
   212 void TBaAssert::DoLeaveL(TBafPanic aPanic) const
   213 	{
   214 	TInt error = Panic2ErrorL(aPanic);
   215 	User::Leave(error);
   216 	}
   217 
   218 /** @internalComponent */
   219 void TBaAssert::DoAssert(TBool aDebug, TBafPanic aPanic) const
   220 	{
   221 	if(aDebug)
   222 		{
   223 		__ASSERT_DEBUG(EFalse, ::Panic(aPanic));
   224 		}
   225 	else
   226 		{
   227 		::Panic(aPanic);
   228 		}
   229 	}
   230 
   231 
   232