examples/Basics/ExtensionPattern/src_originalclient/OriginalClient.cpp

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

Generated by  doxygen 1.6.2