sl@0: /*
sl@0: * Copyright (c) 2000 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: #ifndef __CommonFramework_H
sl@0: #define __CommonFramework_H
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <e32cons.h>
sl@0: 
sl@0: _LIT(KTxtEPOC32EX,"EXAMPLES");
sl@0: _LIT(KTxtExampleCode,"Symbian OS Example Code");
sl@0: _LIT(KFormatFailed,"failed: leave code=%d");
sl@0: _LIT(KTxtOK,"ok");
sl@0: _LIT(KTxtPressAnyKey," [press any key]");
sl@0: 
sl@0: // public
sl@0: LOCAL_D CConsoleBase* console; // write all your messages to this
sl@0: LOCAL_C void doExampleL(); // code this function for the real example
sl@0: 
sl@0: // private
sl@0: LOCAL_C void callExampleL(); // initialize with cleanup stack, then do example
sl@0: 
sl@0: GLDEF_C TInt E32Main() // main function called by E32
sl@0:     {
sl@0: 	__UHEAP_MARK;
sl@0: 	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
sl@0: 	TRAPD(error,callExampleL()); // more initialization, then do example
sl@0: 	__ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
sl@0: 	delete cleanup; // destroy clean-up stack
sl@0: 	__UHEAP_MARKEND;
sl@0: 	return 0; // and return
sl@0:     }
sl@0: 
sl@0: LOCAL_C void callExampleL() // initialize and call example code under cleanup stack
sl@0:     {
sl@0: 	console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
sl@0: 	CleanupStack::PushL(console);
sl@0: 	TRAPD(error,doExampleL()); // perform example function
sl@0: 	if (error)
sl@0: 		console->Printf(KFormatFailed, error);
sl@0: 	else
sl@0: 		console->Printf(KTxtOK);
sl@0: 	console->Printf(KTxtPressAnyKey);
sl@0: 	console->Getch(); // get and ignore character
sl@0: 	CleanupStack::PopAndDestroy(); // close console
sl@0:     }
sl@0: 
sl@0: #endif