examples/Base/IPC/ClientServer/Complex/ComplexClient.cpp

00001 // Copyright (c) 2000-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 "ComplexClientAndServer.h"
00018 #include "ComplexClient.h"
00019 #include "CommonFramework.h"
00020 
00021 
00022 
00035 LOCAL_C void doExampleL()
00036         {
00037         _LIT(KTxtTestingCountServer,"Testing the count server test with 2 client subsessions; these represent independent counters \n\n");
00038         _LIT(KTxtInitCounterAWith,"\nInitialize counter A with : ");
00039         _LIT(KTxtInitCounterBWith,"\nInitialize counter B with : ");
00040         _LIT(KTxtInitCounterFailed,"\nSetting the counter from string failed: non-numeric character detected\n");
00041         _LIT(KTxtInitCounterSucceeded,"\nSetting the counter from string succeededd\n");
00042     _LIT(KTxtGetCounterAValue,"Getting counterA value from server: %d \n");
00043     _LIT(KTxtGetCounterBValue,"Getting counterB value from server: %d \n");     
00044     _LIT(KMsgPressAnyKey," (press any key to continue)\n");
00045           // Useful integer variable.
00046         TInt ret;
00047                         
00048           // Say that we are testing the count server.
00049         console->Printf(KTxtTestingCountServer);
00050         
00051           // This is our handle to the server.
00052     RCountSession countserv;
00053 
00054           // Connect to the count server, starting it up if we need to 
00055           // (which in this example we do need to).
00056           // This creates a session with the server.
00057         User::LeaveIfError(countserv.Connect());
00058         
00059 
00060           // Set up the first subsession with the count server.
00061           // We need to pass our handle to the server.
00062         RCountSubSession counterA;
00063         counterA.Open(countserv);
00064         console->Printf(KTxtInitCounterAWith);
00065         
00066         
00067       // Initialise the counter by passing an illegal string - this 
00068       // should fail - but we will check anyway before reporting
00069       // a failure.
00070         _LIT(KTxtIllegalString,"2a");
00071         console->Printf(KTxtIllegalString);
00072         ret = counterA.SetFromString(KTxtIllegalString);
00073         if (ret==ENonNumericString)
00074             {
00075                 console->Printf(KTxtInitCounterFailed);
00076             }
00077         else
00078             {
00079             console->Printf(KTxtInitCounterSucceeded);  
00080             }
00081         
00082                 
00083           // Set up the second subsession with the count server.
00084           // We need to pass our handle to the server.
00085         RCountSubSession counterB;
00086         counterB.Open(countserv);
00087         console->Printf(KTxtInitCounterBWith);
00088         
00089         
00090       // Initialise the counter by passing a legal string.
00091         _LIT(KTxtLegalString,"100");
00092         console->Printf(KTxtLegalString);
00093         ret = counterB.SetFromString(KTxtLegalString);
00094         if (ret==ENonNumericString)
00095             {
00096                 console->Printf(KTxtInitCounterFailed);
00097             }
00098         else
00099             {
00100             console->Printf(KTxtInitCounterSucceeded);  
00101             }
00102             
00103         console->Printf(KMsgPressAnyKey);
00104         console->Getch();
00105         console->ClearScreen();
00106         
00107   
00108           // Now get the initial values back from the server.
00109           // The 1st subsession should have a default value (because we initialised it with an illegal value).
00110           // The 2nd subsession should have the value we specified (because we initialised it witha legal value).
00111         console->Printf(KTxtGetCounterAValue,counterA.CounterValue());  
00112         console->Printf(KTxtGetCounterBValue,counterB.CounterValue()); 
00113         
00114 
00115                 // Increase CounterA by the default value
00116         _LIT(KTxt1,"\nIncrease counterA by default value (i.e. 1)..\n");
00117         console->Printf(KTxt1);
00118         counterA.Increase();
00119         console->Printf(KTxtGetCounterAValue,counterA.CounterValue());  
00120 
00121                 // Increase CounterA by 2
00122         _LIT(KTxt2,"\nIncrease counterA by 2..\n");
00123         console->Printf(KTxt2);
00124         counterA.IncreaseBy(2);
00125         console->Printf(KTxtGetCounterAValue,counterA.CounterValue());  
00126         
00127           // Increase CounterB by the default value
00128     _LIT(KTxt3,"\nIncrease counterB by default value (i.e. 1)..\n");
00129         console->Printf(KTxt3);
00130         counterB.Increase();
00131         console->Printf(KTxtGetCounterBValue,counterB.CounterValue());  
00132         
00133       // Increase CounterA by 7 
00134         _LIT(KTxt4,"\nIncrease counterA by 7..\n");
00135         console->Printf(KTxt4);
00136         counterA.IncreaseBy(7);
00137     console->Printf(KTxtGetCounterAValue,counterA.CounterValue());      
00138         
00139           // Increase CounterB by 5     
00140         _LIT(KTxt5,"\nIncrease counterB by 5..\n");
00141         console->Printf(KTxt5);
00142         counterB.IncreaseBy(5);
00143     console->Printf(KTxtGetCounterBValue,counterB.CounterValue());      
00144         
00145           // Decrease CounterA by the default value
00146         _LIT(KTxt6,"\nDecrease counterA..\n");
00147         console->Printf(KTxt6);
00148         counterA.Decrease();
00149     console->Printf(KTxtGetCounterAValue,counterA.CounterValue());      
00150    
00151       // Decrease CounterB by 3
00152         _LIT(KTxt7,"\nDecrease counterB by 3..\n");
00153         console->Printf(KTxt7);
00154         counterB.DecreaseBy(3);
00155         console->Printf(KTxtGetCounterBValue,counterB.CounterValue());          
00156 
00157       // Show the number of resources in use.
00158         _LIT(KTxt8,"\nResource count is.. %d \n");
00159     console->Printf(KTxt8,countserv.ResourceCount());
00160 
00161                 //close both subsessions
00162                 
00163         _LIT(KTxt9,"\nClosing counterA and then CounterB..\n");
00164         console->Printf(KTxt9);
00165         counterA.Close();
00166         counterB.Close();
00167         
00168 
00169           // Close the sesssion with the count server.
00170         countserv.Close();
00171         
00172           // NB in this example, it is possible to close the session before closing the 
00173           // subsessions. This is because the subsessions are themsleves closed as a
00174           // consequence of closing the session - also the subsessions offer a simple
00175           // (almost trivial) synchronous service.
00176           // In more complex cases, you would need to think through the consequences
00177           // of closing a session, while a subsession is sill open.
00178         }
00179 

Generated by  doxygen 1.6.2