|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #ifndef UTILS_H |
|
24 #define UTILS_H |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <ecom/ecom.h> |
|
28 #include <usb/usblogger.h> |
|
29 |
|
30 // In debug, using checking forms of CleanupStack::Pop. In release builds, |
|
31 // use the non-checking form to save a little bit of ROM. |
|
32 #ifdef _DEBUG |
|
33 #define CLEANUPSTACK_POP1(a) CleanupStack::Pop(a); |
|
34 #define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(a, b); |
|
35 #else |
|
36 #define CLEANUPSTACK_POP1(a) CleanupStack::Pop(); |
|
37 #define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(2); |
|
38 #endif // _DEBUG |
|
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)>)>) |
|
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 |
|
81 |
|
82 // Undefine the e32def.h-defined ASSERT macro to make sure no-one uses it |
|
83 // under the mistaken impression that it's useful. Use our informative one |
|
84 // above instead! |
|
85 #undef ASSERT |
|
86 |
|
87 /** |
|
88 Cleanup stack item to remove a given TUint from an RArray. |
|
89 */ |
|
90 struct TArrayRemove |
|
91 { |
|
92 TArrayRemove(RArray<TUint>& aDeviceIds, TUint aDeviceId); |
|
93 ~TArrayRemove(); |
|
94 |
|
95 RArray<TUint>& iDeviceIds; |
|
96 const TUint iDeviceId; |
|
97 }; |
|
98 void CleanupRemovePushL(TArrayRemove& aArrayRemove); |
|
99 void Remove(TAny* aArrayRemove); |
|
100 |
|
101 #endif // UTILS_H |