|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #ifndef __CommonFramework_H |
|
18 #define __CommonFramework_H |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <e32cons.h> |
|
22 |
|
23 _LIT(KTxtEPOC32EX,"EXAMPLES"); |
|
24 _LIT(KTxtExampleCode,"Symbian OS Example Code"); |
|
25 _LIT(KFormatFailed,"failed: leave code=%d"); |
|
26 _LIT(KTxtOK,"ok"); |
|
27 _LIT(KTxtPressAnyKey," [press any key]"); |
|
28 |
|
29 // public |
|
30 LOCAL_D CConsoleBase* console; // write all your messages to this |
|
31 LOCAL_C void doExampleL(); // code this function for the real example |
|
32 |
|
33 // private |
|
34 LOCAL_C void callExampleL(); // initialize with cleanup stack, then do example |
|
35 |
|
36 GLDEF_C TInt E32Main() // main function called by E32 |
|
37 { |
|
38 __UHEAP_MARK; |
|
39 CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack |
|
40 TRAPD(error,callExampleL()); // more initialization, then do example |
|
41 __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error)); |
|
42 delete cleanup; // destroy clean-up stack |
|
43 __UHEAP_MARKEND; |
|
44 return 0; // and return |
|
45 } |
|
46 |
|
47 LOCAL_C void callExampleL() // initialize and call example code under cleanup stack |
|
48 { |
|
49 console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen)); |
|
50 CleanupStack::PushL(console); |
|
51 TRAPD(error,doExampleL()); // perform example function |
|
52 if (error) |
|
53 console->Printf(KFormatFailed, error); |
|
54 else |
|
55 console->Printf(KTxtOK); |
|
56 console->Printf(KTxtPressAnyKey); |
|
57 console->Getch(); // get and ignore character |
|
58 CleanupStack::PopAndDestroy(); // close console |
|
59 } |
|
60 |
|
61 #endif |