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

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

Generated by  doxygen 1.6.2