examples/DataComms/Rconnection/example.cpp

00001 /*
00002 Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00032 #include <e32base.h>
00033 #include <e32cons.h>
00034 #include "rconnection.h"
00035 
00036 
00037 _LIT(KRow01,"*****************************************\n");
00038 _LIT(KRow02,"*     Welcome to RConnection Example    *\n");
00039 _LIT(KRow03,"*****************************************\n");
00040 _LIT(KRow04,"Press a Key to step through the Example\n");
00041 _LIT(KNewLine,"\n");
00042 
00043 static void DoStartL(CConsoleBase* aConsole); 
00044 static void WelcomeScreen(CConsoleBase* aConsole);
00045 static void CallExampleL(); // initialize with cleanup stack, then do example
00046 
00047 static void DoStartL(CConsoleBase* aConsole)
00048         {
00049         // Create active scheduler (to run active objects).
00050         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00051         CleanupStack::PushL(scheduler);
00052         CActiveScheduler::Install(scheduler);
00053 
00054         CRConnection* example = new (ELeave) CRConnection(aConsole);
00055         CleanupStack::PushL(example);
00056         
00057         WelcomeScreen(aConsole);
00058         
00059         example->DemoApiWithoutDbOverrideL();   
00060         
00061         example->DemoApiWithDbOverrideL();
00062         
00063         example->AttachToExistingInterfaceL();
00064         
00065         CleanupStack::PopAndDestroy(example);
00066 
00067         // Delete active scheduler.
00068         CleanupStack::PopAndDestroy(scheduler); 
00069         }
00070 
00071 static void CallExampleL() // initialize and call example code under cleanup stack
00072     {
00073     _LIT(KTxtExampleCode,"Symbian platform Example Code");
00074     _LIT(KFormatFailed,"failed: leave code=%d");
00075     _LIT(KTxtOK,"ok");
00076     _LIT(KTxtPressAnyKey," [press any key to exit]");
00077     
00078         CConsoleBase* console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00079         CleanupStack::PushL(console);
00080         
00081         TRAPD(error,DoStartL(console)); // perform example
00082         
00083         if (error)
00084                 console->Printf(KFormatFailed, error);
00085         else
00086                 console->Printf(KTxtOK);
00087         
00088         console->Printf(KTxtPressAnyKey);
00089         console->Getch(); // get and ignore character
00090         
00091         CleanupStack::PopAndDestroy(); // close console
00092     }
00093 
00094 extern TInt E32Main() // main function called by E32
00095     {
00096     _LIT(KEgPanicCat,"EXAMPLES");
00097         __UHEAP_MARK;
00098         CTrapCleanup* cleanup=CTrapCleanup::New(); // create clean-up stack
00099         TRAPD(error,CallExampleL()); // do example
00100         __ASSERT_ALWAYS(!error,User::Panic(KEgPanicCat,error));
00101         delete cleanup; // destroy clean-up stack
00102         __UHEAP_MARKEND;
00103         return 0; // and return
00104     }
00105 
00106 //Display for welcome screen.
00107 static void WelcomeScreen(CConsoleBase* aConsole)
00108         {
00109         aConsole->ClearScreen();
00110         aConsole->Printf(KRow01);
00111         aConsole->Printf(KRow02);
00112         aConsole->Printf(KRow03);
00113         aConsole->Printf(KNewLine);
00114         aConsole->Printf(KRow04);
00115         aConsole->Getch();      
00116         }
00117 

Generated by  doxygen 1.6.2