usbmgmt/usbmgr/host/fdf/production/server/inc/utils.h
branchRCL_3
changeset 43 012cc2ee6408
parent 42 f92a4f87e424
--- a/usbmgmt/usbmgr/host/fdf/production/server/inc/utils.h	Tue Aug 31 17:01:47 2010 +0300
+++ b/usbmgmt/usbmgr/host/fdf/production/server/inc/utils.h	Wed Sep 01 12:35:00 2010 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -37,7 +37,47 @@
 #define CLEANUPSTACK_POP2(a, b) 	CleanupStack::Pop(2);
 #endif // _DEBUG
 
+// What we want for internal programming errors in a server is a set of macros 
+// which, to save effort all round, use __LINE__ as the panic code, and a 
+// file-specific panic category. To make this non-standard pattern as helpful 
+// to users as possible, we append ' line#' to the category. That means we 
+// first have to check that the category is 10 characters long or less, so 
+// that the whole thing is legible to users when it appears on the screen.
+template <TBool> struct ASSERTION_FAILURE;
+TEMPLATE_SPECIALIZATION struct ASSERTION_FAILURE<ETrue>{};
+template <TInt> struct __assertion_test;
+#define COMPILE_ASSERT( B ) void __compile_assert(::__assertion_test<sizeof(::ASSERTION_FAILURE<(B)>)>)
 
+// We want a 10-character string (but allow for the NULL terminator).
+#define PANICCATEGORY(aaa) COMPILE_ASSERT(sizeof(L##aaa)/2 <= 11); _LIT(KPanicCat, aaa) 
+
+// A handy panic-self macro- the category is KPanicCat with " line#" appended; 
+// the code is the line number. 
+#define PANIC_LINENUM \
+	{ \
+	_LIT(KLnNo, " line#"); \
+	TBuf<KMaxExitCategoryName> cat = KPanicCat(); \
+	cat.Append(KLnNo()); \
+	_USB_PANIC(cat, __LINE__); \
+	}
+
+// A handy assertion macro that panics with a locally-defined panic category 
+// and the line number.
+#define ASSERT_ALWAYS(a) \
+	{ \
+	if ( !(a) ) \
+		{ \
+		PANIC_LINENUM; \
+		} \
+	}
+
+#ifdef _DEBUG
+#define ASSERT_DEBUG(a) ASSERT_ALWAYS(a)
+#define DEBUG_PANIC_LINENUM PANIC_LINENUM
+#else
+#define ASSERT_DEBUG(a)
+#define DEBUG_PANIC_LINENUM
+#endif // _DEBUG
 
 // Undefine the e32def.h-defined ASSERT macro to make sure no-one uses it 
 // under the mistaken impression that it's useful. Use our informative one