Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_simple_client_8cpp_source.html
changeset 6 43e37759235e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_simple_client_8cpp_source.html	Tue Mar 30 16:16:55 2010 +0100
@@ -0,0 +1,260 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
+<title>TB9.2 Example Applications: examples/Base/IPC/ClientServer/Simple/SimpleClient.cpp Source File</title>
+<link href="tabs.css" rel="stylesheet" type="text/css"/>
+<link href="doxygen.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+<!-- Generated by Doxygen 1.6.2 -->
+<h1>examples/Base/IPC/ClientServer/Simple/SimpleClient.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
+<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
+<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
+<a name="l00004"></a>00004 <span class="comment">// under the terms of &quot;Eclipse Public License v1.0&quot;</span>
+<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
+<a name="l00006"></a>00006 <span class="comment">// at the URL &quot;http://www.eclipse.org/legal/epl-v10.html&quot;.</span>
+<a name="l00007"></a>00007 <span class="comment">//</span>
+<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
+<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
+<a name="l00010"></a>00010 <span class="comment">//</span>
+<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
+<a name="l00012"></a>00012 <span class="comment">//</span>
+<a name="l00013"></a>00013 <span class="comment">// Description:</span>
+<a name="l00014"></a>00014 <span class="comment">// **NOTE**: The example does not demonstrate any security features - its purpose is simply</span>
+<a name="l00015"></a>00015 <span class="comment">// to demonstrate the basic principles of client/server interaction.</span>
+<a name="l00016"></a>00016 <span class="comment">//</span>
+<a name="l00017"></a>00017 
+<a name="l00018"></a>00018 
+<a name="l00019"></a>00019 
+<a name="l00020"></a>00020 <span class="comment">// needed for client interface</span>
+<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;ClientServer.h&quot;</span>
+<a name="l00022"></a>00022 
+<a name="l00023"></a>00023 <span class="comment">// needed for client (doExampleL)</span>
+<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;SimpleClient.h&quot;</span>
+<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;CommonFramework.h&quot;</span>
+<a name="l00026"></a>00026 
+<a name="l00027"></a>00027 
+<a name="l00028"></a>00028 <span class="keyword">const</span> TUint kDefaultMessageSlots=4;
+<a name="l00029"></a>00029 
+<a name="l00030"></a>00030 
+<a name="l00031"></a>00031 <span class="comment">//**********************************</span>
+<a name="l00032"></a>00032 <span class="comment">//RCountServ</span>
+<a name="l00033"></a>00033 <span class="comment">//**********************************</span>
+<a name="l00034"></a>00034 
+<a name="l00035"></a>00035 RCountServSession::RCountServSession()
+<a name="l00036"></a>00036         {
+<a name="l00037"></a>00037         }
+<a name="l00038"></a>00038 
+<a name="l00039"></a>00039 
+<a name="l00049"></a>00049 TInt RCountServSession::Connect()
+<a name="l00050"></a>00050         {
+<a name="l00051"></a>00051         TInt r=StartThread(iServerThread);
+<a name="l00052"></a>00052         <span class="keywordflow">if</span> (r==KErrNone)
+<a name="l00053"></a>00053                 r=CreateSession(KCountServerName,Version(),kDefaultMessageSlots);
+<a name="l00054"></a>00054         <span class="keywordflow">return</span>(r); 
+<a name="l00055"></a>00055         }
+<a name="l00056"></a>00056 
+<a name="l00057"></a>00057 
+<a name="l00061"></a>00061 TVersion RCountServSession::Version(<span class="keywordtype">void</span>)<span class="keyword"> const</span>
+<a name="l00062"></a>00062 <span class="keyword">        </span>{
+<a name="l00063"></a>00063         <span class="keywordflow">return</span>(TVersion(KCountServMajorVersionNumber,KCountServMinorVersionNumber,KCountServBuildVersionNumber));
+<a name="l00064"></a>00064         }
+<a name="l00065"></a>00065 
+<a name="l00066"></a>00066 
+<a name="l00071"></a>00071 TInt RCountServSession::SetFromString(<span class="keyword">const</span> TDesC&amp; aString)
+<a name="l00072"></a>00072         {
+<a name="l00073"></a>00073         TIpcArgs args(&amp;aString);
+<a name="l00074"></a>00074     <span class="keywordflow">return</span> SendReceive(ECountServSetFromString, args);
+<a name="l00075"></a>00075         }
+<a name="l00076"></a>00076 
+<a name="l00077"></a>00077 
+<a name="l00081"></a>00081 <span class="keywordtype">void</span> RCountServSession::Increase()
+<a name="l00082"></a>00082         {
+<a name="l00083"></a>00083         SendReceive(ECountServIncrease);
+<a name="l00084"></a>00084         }
+<a name="l00085"></a>00085 
+<a name="l00086"></a>00086 
+<a name="l00091"></a>00091 <span class="keywordtype">void</span> RCountServSession::IncreaseBy(TInt anInt)
+<a name="l00092"></a>00092         {
+<a name="l00093"></a>00093         TIpcArgs args(anInt);
+<a name="l00094"></a>00094         SendReceive(ECountServIncreaseBy, args);
+<a name="l00095"></a>00095         }
+<a name="l00096"></a>00096 
+<a name="l00097"></a>00097 
+<a name="l00101"></a>00101 <span class="keywordtype">void</span> RCountServSession::Decrease()
+<a name="l00102"></a>00102         {
+<a name="l00103"></a>00103         SendReceive(ECountServDecrease);        
+<a name="l00104"></a>00104         }
+<a name="l00105"></a>00105 
+<a name="l00106"></a>00106 
+<a name="l00111"></a>00111 <span class="keywordtype">void</span> RCountServSession::DecreaseBy(TInt anInt)
+<a name="l00112"></a>00112         {
+<a name="l00113"></a>00113         TIpcArgs args(anInt);
+<a name="l00114"></a>00114         SendReceive(ECountServDecreaseBy, args);
+<a name="l00115"></a>00115         }
+<a name="l00116"></a>00116 
+<a name="l00120"></a>00120 <span class="keywordtype">void</span> RCountServSession::Reset()
+<a name="l00121"></a>00121         {
+<a name="l00122"></a>00122         SendReceive(ECountServReset);   
+<a name="l00123"></a>00123         }
+<a name="l00124"></a>00124 
+<a name="l00125"></a>00125 
+<a name="l00131"></a>00131 TInt RCountServSession::CounterValue()
+<a name="l00132"></a>00132         {
+<a name="l00133"></a>00133         TInt res=0;
+<a name="l00134"></a>00134         TPckgBuf&lt;TInt&gt; pckg;
+<a name="l00135"></a>00135         
+<a name="l00136"></a>00136           <span class="comment">// Note that TPckgBuf is of type TDes8</span>
+<a name="l00137"></a>00137         TIpcArgs args(&amp;pckg);
+<a name="l00138"></a>00138         SendReceive(ECountServValue, args);
+<a name="l00139"></a>00139     
+<a name="l00140"></a>00140       <span class="comment">// Extract the value returned from the server. </span>
+<a name="l00141"></a>00141         res = pckg();
+<a name="l00142"></a>00142         <span class="keywordflow">return</span> res;
+<a name="l00143"></a>00143         }
+<a name="l00144"></a>00144 
+<a name="l00145"></a>00145 
+<a name="l00152"></a>00152 TInt RCountServSession::UnsupportedRequest()
+<a name="l00153"></a>00153         {
+<a name="l00154"></a>00154         <span class="keywordflow">return</span> SendReceive(ECountServUnsupportedRequest);
+<a name="l00155"></a>00155         }
+<a name="l00156"></a>00156 
+<a name="l00160"></a>00160 <span class="keywordtype">void</span> RCountServSession::BadRequest()
+<a name="l00161"></a>00161         {
+<a name="l00162"></a>00162         SendReceive(9999);
+<a name="l00163"></a>00163         }
+<a name="l00164"></a>00164 
+<a name="l00165"></a>00165 
+<a name="l00166"></a>00166 
+<a name="l00170"></a>00170 <span class="keywordtype">void</span> RCountServSession::Close()
+<a name="l00171"></a>00171         {
+<a name="l00172"></a>00172         RSessionBase::Close();
+<a name="l00173"></a>00173     iServerThread.Close();      
+<a name="l00174"></a>00174         }
+<a name="l00175"></a>00175 
+<a name="l00176"></a>00176 
+<a name="l00177"></a>00177 
+<a name="l00178"></a>00178 
+<a name="l00186"></a>00186 LOCAL_C <span class="keywordtype">void</span> doExampleL()
+<a name="l00187"></a>00187         {
+<a name="l00188"></a>00188         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtTestingCountServer,<span class="stringliteral">&quot;Testing the count server \n\n&quot;</span>);
+<a name="l00189"></a>00189         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtInitCounterWith,<span class="stringliteral">&quot;\nInitialize the counter with : &quot;</span>);           
+<a name="l00190"></a>00190     <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtInitCounterFailed,<span class="stringliteral">&quot;\nSetting the counter from string failed: non-numeric character detected\n&quot;</span>);   
+<a name="l00191"></a>00191     <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtGetCounterValue,<span class="stringliteral">&quot;\nGetting the counter value back from the server: %d \n&quot;</span>);
+<a name="l00192"></a>00192         
+<a name="l00193"></a>00193         
+<a name="l00194"></a>00194           <span class="comment">// Say that we are testing the count server</span>
+<a name="l00195"></a>00195         console-&gt;Printf(KTxtTestingCountServer); 
+<a name="l00196"></a>00196         
+<a name="l00197"></a>00197           <span class="comment">// This is our handle to the server</span>
+<a name="l00198"></a>00198     RCountServSession ss;
+<a name="l00199"></a>00199 
+<a name="l00200"></a>00200           <span class="comment">// Connect to the count server, starting it up if we need to </span>
+<a name="l00201"></a>00201           <span class="comment">// (which in this example we do need to).</span>
+<a name="l00202"></a>00202           <span class="comment">// This creates a session with the server.</span>
+<a name="l00203"></a>00203         User::LeaveIfError(ss.Connect());
+<a name="l00204"></a>00204 
+<a name="l00205"></a>00205       <span class="comment">// At this point the server appears ready to accept requests.</span>
+<a name="l00206"></a>00206         console-&gt;Printf(KTxtInitCounterWith);
+<a name="l00207"></a>00207 
+<a name="l00208"></a>00208       <span class="comment">// Initialise the counter by passing an illegal string - this should</span>
+<a name="l00209"></a>00209       <span class="comment">// fail - but we will check anyway before reporting a failure.</span>
+<a name="l00210"></a>00210     <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtIllegalString,<span class="stringliteral">&quot;22h4&quot;</span>);
+<a name="l00211"></a>00211         console-&gt;Printf(KTxtIllegalString);
+<a name="l00212"></a>00212         TInt ret = ss.SetFromString(KTxtIllegalString);
+<a name="l00213"></a>00213         <span class="keywordflow">if</span> (ret==<a class="code" href="secureclientandserver_8h.html#ac31a03d737c6ab16ba55ceab73d57b71ae3a6b8e17c25d02a3ae9ca7362ba4d0c">ENonNumericString</a>)
+<a name="l00214"></a>00214             {
+<a name="l00215"></a>00215                 console-&gt;Printf(KTxtInitCounterFailed);
+<a name="l00216"></a>00216             }
+<a name="l00217"></a>00217         
+<a name="l00218"></a>00218           <span class="comment">// Now try and initialise the counter using a legal string.</span>
+<a name="l00219"></a>00219         console-&gt;Printf(KTxtInitCounterWith);
+<a name="l00220"></a>00220         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxtLegalString,<span class="stringliteral">&quot;224&quot;</span>);
+<a name="l00221"></a>00221         console-&gt;Printf(KTxtLegalString);
+<a name="l00222"></a>00222         ret = ss.SetFromString(KTxtLegalString);
+<a name="l00223"></a>00223         <span class="keywordflow">if</span> (ret==<a class="code" href="secureclientandserver_8h.html#ac31a03d737c6ab16ba55ceab73d57b71ae3a6b8e17c25d02a3ae9ca7362ba4d0c">ENonNumericString</a>)
+<a name="l00224"></a>00224             {
+<a name="l00225"></a>00225                 console-&gt;Printf(KTxtInitCounterFailed);
+<a name="l00226"></a>00226             }
+<a name="l00227"></a>00227         
+<a name="l00228"></a>00228           <span class="comment">// Now get the value back from the server, just to see what it believes</span>
+<a name="l00229"></a>00229           <span class="comment">// it has. We are expecting the value 224 (of course!!!).</span>
+<a name="l00230"></a>00230         ret = ss.CounterValue();
+<a name="l00231"></a>00231         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00232"></a>00232         
+<a name="l00233"></a>00233           <span class="comment">// Now increase the counter value by the default value.</span>
+<a name="l00234"></a>00234         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt1,<span class="stringliteral">&quot;\nIncrease counter (default 1)..&quot;</span>);         
+<a name="l00235"></a>00235         console-&gt;Printf(KTxt1);
+<a name="l00236"></a>00236         ss.Increase();
+<a name="l00237"></a>00237         ret = ss.CounterValue();
+<a name="l00238"></a>00238         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00239"></a>00239 
+<a name="l00240"></a>00240           <span class="comment">// Now increase the counter value by 2.</span>
+<a name="l00241"></a>00241         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt2,<span class="stringliteral">&quot;\nIncrease counter by 2..&quot;</span>);                
+<a name="l00242"></a>00242         console-&gt;Printf(KTxt2);
+<a name="l00243"></a>00243         ss.IncreaseBy(2);
+<a name="l00244"></a>00244         ret = ss.CounterValue();
+<a name="l00245"></a>00245         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00246"></a>00246         
+<a name="l00247"></a>00247           <span class="comment">// Now decrease the counter value by the default value.       </span>
+<a name="l00248"></a>00248         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt3,<span class="stringliteral">&quot;\nDecrease counter(default 1)..&quot;</span>);          
+<a name="l00249"></a>00249         console-&gt;Printf(KTxt3);
+<a name="l00250"></a>00250         ss.Decrease();
+<a name="l00251"></a>00251     ret = ss.CounterValue();
+<a name="l00252"></a>00252         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00253"></a>00253         
+<a name="l00254"></a>00254       <span class="comment">// Now increase the counter value by 7.</span>
+<a name="l00255"></a>00255         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt4,<span class="stringliteral">&quot;\nIncrease counter by 7..&quot;</span>);                
+<a name="l00256"></a>00256         console-&gt;Printf(KTxt4);
+<a name="l00257"></a>00257         ss.IncreaseBy(7);
+<a name="l00258"></a>00258         ret = ss.CounterValue();
+<a name="l00259"></a>00259         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00260"></a>00260                 
+<a name="l00261"></a>00261       <span class="comment">// Now increase the counter value again by the default value.             </span>
+<a name="l00262"></a>00262         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt5,<span class="stringliteral">&quot;\nIncrease counter(default 1)..&quot;</span>);  
+<a name="l00263"></a>00263         console-&gt;Printf(KTxt5);
+<a name="l00264"></a>00264         ss.Increase();
+<a name="l00265"></a>00265         ret = ss.CounterValue();
+<a name="l00266"></a>00266         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00267"></a>00267 
+<a name="l00268"></a>00268       <span class="comment">// Now decrease the counter value by 3.           </span>
+<a name="l00269"></a>00269         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt6,<span class="stringliteral">&quot;\nDecrease counter by 3..&quot;</span>);        
+<a name="l00270"></a>00270         console-&gt;Printf(KTxt6);
+<a name="l00271"></a>00271         ss.DecreaseBy(3);
+<a name="l00272"></a>00272         ret = ss.CounterValue();
+<a name="l00273"></a>00273         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00274"></a>00274         
+<a name="l00275"></a>00275           <span class="comment">// Reset counter value</span>
+<a name="l00276"></a>00276         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt7,<span class="stringliteral">&quot;\nReseting counter value to 0..&quot;</span>);
+<a name="l00277"></a>00277         console-&gt;Printf(KTxt7);
+<a name="l00278"></a>00278         ss.Reset();
+<a name="l00279"></a>00279         ret = ss.CounterValue();
+<a name="l00280"></a>00280         console-&gt;Printf(KTxtGetCounterValue, ret);
+<a name="l00281"></a>00281 
+<a name="l00282"></a>00282         
+<a name="l00283"></a>00283           <span class="comment">// Call API function which is not implemented in the server</span>
+<a name="l00284"></a>00284         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt8,<span class="stringliteral">&quot;\nAbout to call the unsupported function Stop()..&quot;</span>);
+<a name="l00285"></a>00285         console-&gt;Printf(KTxt8);
+<a name="l00286"></a>00286         ret = ss.UnsupportedRequest();
+<a name="l00287"></a>00287         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KTxt9,<span class="stringliteral">&quot;\nSorry, UnsupportedRequest() is not supported\n&quot;</span>);
+<a name="l00288"></a>00288         <span class="keywordflow">if</span> (ret==KErrNotSupported)
+<a name="l00289"></a>00289             {
+<a name="l00290"></a>00290                 console-&gt;Printf(KTxt9);
+<a name="l00291"></a>00291             }
+<a name="l00292"></a>00292                 
+<a name="l00293"></a>00293      
+<a name="l00294"></a>00294       <span class="comment">// This request will panic this client so do not remove the</span>
+<a name="l00295"></a>00295       <span class="comment">// following comment unless you want to try it.</span>
+<a name="l00296"></a>00296 <span class="comment">//      ss.BadRequest();</span>
+<a name="l00297"></a>00297    
+<a name="l00298"></a>00298    
+<a name="l00299"></a>00299           <span class="comment">// Close the sesssion with the count server.</span>
+<a name="l00300"></a>00300         ss.Close();
+<a name="l00301"></a>00301         }
+</pre></div></div>
+<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
+<a href="http://www.doxygen.org/index.html">
+<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
+</body>
+</html>