|
1 /* |
|
2 * Copyright (c) 2008-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 * Utilities for server. (These depend on the logger.) |
|
16 * |
|
17 */ |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 */ |
|
23 |
|
24 #ifndef UTILS_H |
|
25 #define UTILS_H |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <ecom/ecom.h> |
|
29 #include <usb/usblogger.h> |
|
30 |
|
31 // In debug, using checking forms of CleanupStack::Pop. In release builds, |
|
32 // use the non-checking form to save a little bit of ROM. |
|
33 #ifdef _DEBUG |
|
34 #define CLEANUPSTACK_POP1(a) CleanupStack::Pop(a); |
|
35 #define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(a, b); |
|
36 #else |
|
37 #define CLEANUPSTACK_POP1(a) CleanupStack::Pop(); |
|
38 #define CLEANUPSTACK_POP2(a, b) CleanupStack::Pop(2); |
|
39 #endif // _DEBUG |
|
40 |
|
41 // What we want for internal programming errors in a server is a set of macros |
|
42 // which, to save effort all round, use __LINE__ as the panic code, and a |
|
43 // file-specific panic category. To make this non-standard pattern as helpful |
|
44 // to users as possible, we append ' line#' to the category. That means we |
|
45 // first have to check that the category is 10 characters long or less, so |
|
46 // that the whole thing is legible to users when it appears on the screen. |
|
47 template <TBool> struct ASSERTION_FAILURE; |
|
48 TEMPLATE_SPECIALIZATION struct ASSERTION_FAILURE<ETrue>{}; |
|
49 template <TInt> struct __assertion_test; |
|
50 #define COMPILE_ASSERT( B ) void __compile_assert(::__assertion_test<sizeof(::ASSERTION_FAILURE<(B)>)>) |
|
51 |
|
52 // We want a 10-character string (but allow for the NULL terminator). |
|
53 #define PANICCATEGORY(aaa) COMPILE_ASSERT(sizeof(L##aaa)/2 <= 11); _LIT(KPanicCat, aaa) |
|
54 |
|
55 // A handy panic-self macro- the category is KPanicCat with " line#" appended; |
|
56 // the code is the line number. |
|
57 #define PANIC_LINENUM \ |
|
58 { \ |
|
59 _LIT(KLnNo, " line#"); \ |
|
60 TBuf<KMaxExitCategoryName> cat = KPanicCat(); \ |
|
61 cat.Append(KLnNo()); \ |
|
62 _USB_PANIC(cat, __LINE__); \ |
|
63 } |
|
64 |
|
65 // A handy assertion macro that panics with a locally-defined panic category |
|
66 // and the line number. |
|
67 #define ASSERT_ALWAYS(a) \ |
|
68 { \ |
|
69 if ( !(a) ) \ |
|
70 { \ |
|
71 PANIC_LINENUM; \ |
|
72 } \ |
|
73 } |
|
74 |
|
75 #ifdef _DEBUG |
|
76 #define ASSERT_DEBUG(a) ASSERT_ALWAYS(a) |
|
77 #define DEBUG_PANIC_LINENUM PANIC_LINENUM |
|
78 #else |
|
79 #define ASSERT_DEBUG(a) |
|
80 #define DEBUG_PANIC_LINENUM |
|
81 #endif // _DEBUG |
|
82 |
|
83 // Undefine the e32def.h-defined ASSERT macro to make sure no-one uses it |
|
84 // under the mistaken impression that it's useful. Use our informative one |
|
85 // above instead! |
|
86 #undef ASSERT |
|
87 |
|
88 /** |
|
89 Cleanup stack item to remove a given TUint from an RArray. |
|
90 */ |
|
91 struct TArrayRemove |
|
92 { |
|
93 TArrayRemove(RArray<TUint>& aDeviceIds, TUint aDeviceId); |
|
94 ~TArrayRemove(); |
|
95 |
|
96 RArray<TUint>& iDeviceIds; |
|
97 const TUint iDeviceId; |
|
98 }; |
|
99 void CleanupRemovePushL(TArrayRemove& aArrayRemove); |
|
100 void Remove(TAny* aArrayRemove); |
|
101 |
|
102 #endif // UTILS_H |