# examples/Basics/ExtensionPattern/src_originalclient/OriginalClient.cpp

    00001 // Copyright (c) 1997-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 // Implements a simple console application that uses functions supplied by OriginalDll
    00015 // Should work without rebuild for both versions of OriginalDll & ExtensionDll
    00016 //
    00017
    00018 #include <e32base.h>
    00019 #include <e32cons.h>
    00020 #include <NumberStore.h>
    00021
    00022 _LIT(KHello,"Hello World!\r\n");
    00023 _LIT(KTxtEPOC32EX,"EPOC32EX");
    00024 _LIT(KTxtExampleCode,"Symbian platform Example Code");
    00025 _LIT(KFormatFailed,"failed: leave code=%d");
    00026 _LIT(KTxtOK,"ok");
    00027 _LIT(KTxtPressAnyKey," [press any key]");
    00028
    00029 LOCAL_D CConsoleBase* console;
    00030 LOCAL_C void callExampleL();
    00031 LOCAL_C void doExampleL();
    00032
    00033 GLDEF_C TInt E32Main()
    00034     {
    00035         __UHEAP_MARK;
    00036         CTrapCleanup* cleanup=CTrapCleanup::New();
    00037         TRAPD(error,callExampleL());
    00038         __ASSERT_ALWAYS(!error,User::Panic(KTxtEPOC32EX,error));
    00039         delete cleanup;
    00040         __UHEAP_MARKEND;
    00041         return 0;
    00042     }
    00043
    00044 LOCAL_C void callExampleL()
    00045     {
    00046         console=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
    00047         CleanupStack::PushL(console);
    00048         TRAPD(error,doExampleL());
    00049         if (error)
    00050                 console->Printf(KFormatFailed, error);
    00051         else
    00052                 console->Printf(KTxtOK);
    00053         console->Printf(KTxtPressAnyKey);
    00054         console->Getch();
    00055         CleanupStack::PopAndDestroy();
    00056     }
    00057
    00058 LOCAL_C void doExampleL()
    00059     {
    00060         console->Printf(KHello);
    00061         TInt num1=3;
    00062         TInt num2=7;
    00063
    00064         //Create & initialise the number store using original functionality
    00065         CNumberStore* numberstore=new (ELeave) CNumberStore();
    00066         numberstore->SetNumber1(num1);
    00067         numberstore->SetNumber2(num2);
    00068         console->Printf(_L("Created CNumberStore with values %d & %d\n"),num1,num2);
    00069         num1=numberstore->Number1();
    00070         num2=numberstore->Number2();
    00071         console->Printf(_L("CNumberStore has values %d & %d\n"),num1,num2);
    00072
    00073         TInt total=-1;
    00074         TInt product=-1;
    00075
    00076         //Attempt to use extension functionality
    00077
    00078         //The following line will fail to link, as it requires the extension dll
    00079         //total=numberstore->AddNumbers();
    00080
    00081         //The following line will fail to compile, as it attempts to call a private function
    00082         //product=numberstore->DoMultiplyNumbers();
    00083
    00084         //The following line will fail to link, as it requires the extension dll
    00085         //product=numberstore->MultiplyNumbers();
    00086
    00087         console->Printf(_L("CNumberStore extension gives total %d\n"),total);
    00088         console->Printf(_L("CNumberStore extension gives product with magic multiplyer %d\n"),product);
    00089
    00090         delete numberstore;
    00091         }