examples/DataComms/Rconnection/example.cpp

00001 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 
00017 #include <e32base.h>
00018 #include <e32cons.h>
00019 #include "rconnection.h"
00020 
00021 
00022 _LIT(KRow01,"*****************************************\n");
00023 _LIT(KRow02,"*     Welcome to RConnection Example    *\n");
00024 _LIT(KRow03,"*****************************************\n");
00025 _LIT(KRow04,"Press a Key to step through the Example\n");
00026 _LIT(KNewLine,"\n");
00027 
00028 static void DoStartL(CConsoleBase* aConsole); 
00029 static void WelcomeScreen(CConsoleBase* aConsole);
00030 static void CallExampleL(); // initialize with cleanup stack, then do example
00031 
00032 static void DoStartL(CConsoleBase* aConsole)
00033         {
00034         // Create active scheduler (to run active objects).
00035         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00036         CleanupStack::PushL(scheduler);
00037         CActiveScheduler::Install(scheduler);
00038 
00039         CRConnection* example = new (ELeave) CRConnection(aConsole);
00040         CleanupStack::PushL(example);
00041         
00042         WelcomeScreen(aConsole);
00043         
00044         example->DemoApiWithoutDbOverrideL();   
00045         
00046         example->DemoApiWithDbOverrideL();
00047         
00048         example->AttachToExistingInterfaceL();
00049         
00050         CleanupStack::PopAndDestroy(example);
00051 
00052         // Delete active scheduler.
00053         CleanupStack::PopAndDestroy(scheduler); 
00054         }
00055 
00056 static void CallExampleL() // initialize and call example code under cleanup stack
00057     {
00058     _LIT(KTxtExampleCode,"Symbian platform Example Code");
00059     _LIT(KFormatFailed,"failed: leave code=%d");
00060     _LIT(KTxtOK,"ok");
00061     _LIT(KTxtPressAnyKey," [press any key to exit]");
00062     
00063         CConsoleBase* console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00064         CleanupStack::PushL(console);
00065         
00066         TRAPD(error,DoStartL(console)); // perform example
00067         
00068         if (error)
00069                 console->Printf(KFormatFailed, error);
00070         else
00071                 console->Printf(KTxtOK);
00072         
00073         console->Printf(KTxtPressAnyKey);
00074         console->Getch(); // get and ignore character
00075         
00076         CleanupStack::PopAndDestroy(); // close console
00077     }
00078 
00079 extern TInt E32Main() // main function called by E32
00080     {
00081     _LIT(KEgPanicCat,"EXAMPLES");
00082         __UHEAP_MARK;
00083         CTrapCleanup* cleanup=CTrapCleanup::New(); // create clean-up stack
00084         TRAPD(error,CallExampleL()); // do example
00085         __ASSERT_ALWAYS(!error,User::Panic(KEgPanicCat,error));
00086         delete cleanup; // destroy clean-up stack
00087         __UHEAP_MARKEND;
00088         return 0; // and return
00089     }
00090 
00091 //Display for welcome screen.
00092 static void WelcomeScreen(CConsoleBase* aConsole)
00093         {
00094         aConsole->ClearScreen();
00095         aConsole->Printf(KRow01);
00096         aConsole->Printf(KRow02);
00097         aConsole->Printf(KRow03);
00098         aConsole->Printf(KNewLine);
00099         aConsole->Printf(KRow04);
00100         aConsole->Getch();      
00101         }
00102 

Generated by  doxygen 1.6.2