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