usbmgmt/usbmgr/host/fdf/production/server/inc/utils.h
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    35 #else
    35 #else
    36 #define CLEANUPSTACK_POP1(a)		CleanupStack::Pop();
    36 #define CLEANUPSTACK_POP1(a)		CleanupStack::Pop();
    37 #define CLEANUPSTACK_POP2(a, b) 	CleanupStack::Pop(2);
    37 #define CLEANUPSTACK_POP2(a, b) 	CleanupStack::Pop(2);
    38 #endif // _DEBUG
    38 #endif // _DEBUG
    39 
    39 
       
    40 // What we want for internal programming errors in a server is a set of macros 
       
    41 // which, to save effort all round, use __LINE__ as the panic code, and a 
       
    42 // file-specific panic category. To make this non-standard pattern as helpful 
       
    43 // to users as possible, we append ' line#' to the category. That means we 
       
    44 // first have to check that the category is 10 characters long or less, so 
       
    45 // that the whole thing is legible to users when it appears on the screen.
       
    46 template <TBool> struct ASSERTION_FAILURE;
       
    47 TEMPLATE_SPECIALIZATION struct ASSERTION_FAILURE<ETrue>{};
       
    48 template <TInt> struct __assertion_test;
       
    49 #define COMPILE_ASSERT( B ) void __compile_assert(::__assertion_test<sizeof(::ASSERTION_FAILURE<(B)>)>)
    40 
    50 
       
    51 // We want a 10-character string (but allow for the NULL terminator).
       
    52 #define PANICCATEGORY(aaa) COMPILE_ASSERT(sizeof(L##aaa)/2 <= 11); _LIT(KPanicCat, aaa) 
       
    53 
       
    54 // A handy panic-self macro- the category is KPanicCat with " line#" appended; 
       
    55 // the code is the line number. 
       
    56 #define PANIC_LINENUM \
       
    57 	{ \
       
    58 	_LIT(KLnNo, " line#"); \
       
    59 	TBuf<KMaxExitCategoryName> cat = KPanicCat(); \
       
    60 	cat.Append(KLnNo()); \
       
    61 	_USB_PANIC(cat, __LINE__); \
       
    62 	}
       
    63 
       
    64 // A handy assertion macro that panics with a locally-defined panic category 
       
    65 // and the line number.
       
    66 #define ASSERT_ALWAYS(a) \
       
    67 	{ \
       
    68 	if ( !(a) ) \
       
    69 		{ \
       
    70 		PANIC_LINENUM; \
       
    71 		} \
       
    72 	}
       
    73 
       
    74 #ifdef _DEBUG
       
    75 #define ASSERT_DEBUG(a) ASSERT_ALWAYS(a)
       
    76 #define DEBUG_PANIC_LINENUM PANIC_LINENUM
       
    77 #else
       
    78 #define ASSERT_DEBUG(a)
       
    79 #define DEBUG_PANIC_LINENUM
       
    80 #endif // _DEBUG
    41 
    81 
    42 // Undefine the e32def.h-defined ASSERT macro to make sure no-one uses it 
    82 // Undefine the e32def.h-defined ASSERT macro to make sure no-one uses it 
    43 // under the mistaken impression that it's useful. Use our informative one 
    83 // under the mistaken impression that it's useful. Use our informative one 
    44 // above instead!
    84 // above instead!
    45 #undef ASSERT
    85 #undef ASSERT