Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_simple_server_8cpp-source.html
Week 12 contribution of SDK documentation_content. See release notes for details. Fixes Bug 1892, Bug 1522, Bug 1520, Bug 394, Bug 1319, Bug 344, Bug 1897
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/Base/IPC/ClientServer/Simple/SimpleServer.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/Base/IPC/ClientServer/Simple/SimpleServer.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 "Eclipse Public License v1.0"</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 "http://www.eclipse.org/legal/epl-v10.html".</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">// The implementation of our simple server that increments and decrements a simple counter value.</span>
<a name="l00015"></a>00015 <span class="comment">// **NOTE**: The example does not demonstrate any security features - its purpose is simply</span>
<a name="l00016"></a>00016 <span class="comment">// to demonstrate the basic principles of client/server interaction.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="preprocessor">#include "ClientServer.h"</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include "SimpleServer.h"</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include <e32svr.h></span>
<a name="l00023"></a>00023 <span class="preprocessor">#include <e32uid.h></span>
<a name="l00024"></a>00024
<a name="l00025"></a>00025
<a name="l00026"></a>00026 <span class="comment">//**********************************</span>
<a name="l00027"></a>00027 <span class="comment">//CCountServServer - implementations</span>
<a name="l00028"></a>00028 <span class="comment">//**********************************</span>
<a name="l00029"></a>00029
<a name="l00040"></a><a class="code" href="class_c_count_serv_server.html#ed2a6e31e0028426cca9da53a4f8e1d4">00040</a> <a class="code" href="class_c_count_serv_server.html#ed2a6e31e0028426cca9da53a4f8e1d4">CCountServServer::CCountServServer</a>(CActive::TPriority aActiveObjectPriority)
<a name="l00041"></a>00041 : CServer2(aActiveObjectPriority)
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044
<a name="l00045"></a>00045
<a name="l00049"></a><a class="code" href="class_c_count_serv_server.html#6fd10682426087fa47686a535b1a03ad">00049</a> CSession2* <a class="code" href="class_c_count_serv_server.html#6fd10682426087fa47686a535b1a03ad">CCountServServer::NewSessionL</a>(<span class="keyword">const</span> TVersion& aVersion,<span class="keyword">const</span> RMessage2& <span class="comment">/*aMessage*/</span>)<span class="keyword"> const</span>
<a name="l00050"></a>00050 <span class="keyword"> </span>{
<a name="l00051"></a>00051 <span class="comment">// Check that the version is OK</span>
<a name="l00052"></a>00052 TVersion v(KCountServMajorVersionNumber,KCountServMinorVersionNumber,KCountServBuildVersionNumber);
<a name="l00053"></a>00053 <span class="keywordflow">if</span> (!User::QueryVersionSupported(v,aVersion))
<a name="l00054"></a>00054 User::Leave(KErrNotSupported);
<a name="l00055"></a>00055
<a name="l00056"></a>00056 <span class="comment">// CAN USE THE aMessage argument to check client's security and identity</span>
<a name="l00057"></a>00057 <span class="comment">// can make use of this later but for now ignore. AH 4/5/05</span>
<a name="l00058"></a>00058 <span class="comment">// the connect message is delivered via the RMessage2 object passed. </span>
<a name="l00059"></a>00059
<a name="l00060"></a>00060 <span class="comment">// do something with this later (and move it to the start of the function?)</span>
<a name="l00061"></a>00061
<a name="l00062"></a>00062 <span class="comment">// Create the session.</span>
<a name="l00063"></a>00063 <span class="keywordflow">return</span> <span class="keyword">new</span> (ELeave) <a class="code" href="class_c_count_serv_session.html">CCountServSession</a>;
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065
<a name="l00066"></a>00066
<a name="l00070"></a><a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">00070</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">CCountServServer::PanicServer</a>(TCountServPanic aPanic)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072 _LIT(KTxtServerPanic,<span class="stringliteral">"Count server panic"</span>);
<a name="l00073"></a>00073 User::Panic(KTxtServerPanic,aPanic);
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075
<a name="l00076"></a>00076
<a name="l00077"></a>00077 <span class="comment">//***********************************</span>
<a name="l00078"></a>00078 <span class="comment">//CCountServSession - implementations</span>
<a name="l00079"></a>00079 <span class="comment">//***********************************</span>
<a name="l00080"></a>00080
<a name="l00081"></a>00081
<a name="l00085"></a><a class="code" href="class_c_count_serv_session.html#c68abcf96df46d35d7b42daef3373a7e">00085</a> <a class="code" href="class_c_count_serv_session.html#c68abcf96df46d35d7b42daef3373a7e">CCountServSession::CCountServSession</a>()
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088
<a name="l00092"></a><a class="code" href="class_c_count_serv_session.html#d339aa53d99cf7e1fe2584ccc523eade">00092</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#d339aa53d99cf7e1fe2584ccc523eade">CCountServSession::ServiceL</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094 TRAPD(err,<a class="code" href="class_c_count_serv_session.html#0c22651f5af66827c00baab5ad0c697e">DispatchMessageL</a>(aMessage));
<a name="l00095"></a>00095 aMessage.Complete(err);
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097
<a name="l00104"></a><a class="code" href="class_c_count_serv_session.html#0c22651f5af66827c00baab5ad0c697e">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#0c22651f5af66827c00baab5ad0c697e">CCountServSession::DispatchMessageL</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 <span class="keywordflow">switch</span> (aMessage.Function())
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108 <span class="keywordflow">case</span> ECountServSetFromString:
<a name="l00109"></a>00109 <a class="code" href="class_c_count_serv_session.html#4525c4f71d949a86fe4c02a7b242ce1e">SetFromStringL</a>(aMessage);
<a name="l00110"></a>00110 <span class="keywordflow">return</span>;
<a name="l00111"></a>00111 <span class="keywordflow">case</span> ECountServIncrease:
<a name="l00112"></a>00112 <a class="code" href="class_c_count_serv_session.html#26b884886f050963b5c29b792131418d">Increase</a>();
<a name="l00113"></a>00113 <span class="keywordflow">return</span>;
<a name="l00114"></a>00114 <span class="keywordflow">case</span> ECountServIncreaseBy:
<a name="l00115"></a>00115 <a class="code" href="class_c_count_serv_session.html#36a92a040c8531527ae6de25ee1a1299">IncreaseBy</a>(aMessage);
<a name="l00116"></a>00116 <span class="keywordflow">return</span>;
<a name="l00117"></a>00117 <span class="keywordflow">case</span> ECountServDecrease:
<a name="l00118"></a>00118 <a class="code" href="class_c_count_serv_session.html#eaeb91138f6d418a4fa580e095ed6081">Decrease</a>();
<a name="l00119"></a>00119 <span class="keywordflow">return</span>;
<a name="l00120"></a>00120 <span class="keywordflow">case</span> ECountServDecreaseBy:
<a name="l00121"></a>00121 <a class="code" href="class_c_count_serv_session.html#b3a11addfd25b34b31ec7537d2e389af">DecreaseBy</a>(aMessage);
<a name="l00122"></a>00122 <span class="keywordflow">return</span>;
<a name="l00123"></a>00123 <span class="keywordflow">case</span> ECountServReset:
<a name="l00124"></a>00124 <a class="code" href="class_c_count_serv_session.html#11afb27d6b3cfb6b658c46e3f5d1bd22">Reset</a>();
<a name="l00125"></a>00125 <span class="keywordflow">return</span>;
<a name="l00126"></a>00126 <span class="keywordflow">case</span> ECountServValue:
<a name="l00127"></a>00127 <a class="code" href="class_c_count_serv_session.html#1c4cd0dd8c2cab784c4e3fafea9e4115">CounterValueL</a>(aMessage);
<a name="l00128"></a>00128 <span class="keywordflow">return</span>;
<a name="l00129"></a>00129
<a name="l00130"></a>00130 <span class="comment">// This is an example of a request that we know about, but don't support.</span>
<a name="l00131"></a>00131 <span class="comment">// We cause KErrNotSupported to be returned to the client.</span>
<a name="l00132"></a>00132 <span class="keywordflow">case</span> ECountServUnsupportedRequest:
<a name="l00133"></a>00133 User::Leave(KErrNotSupported);
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Requests that we don't understand at all are a different matter.</span>
<a name="l00136"></a>00136 <span class="comment">// This is considered a client programming error, so we panic the </span>
<a name="l00137"></a>00137 <span class="comment">// client - this also completes the message.</span>
<a name="l00138"></a>00138 <span class="keywordflow">default</span>:
<a name="l00139"></a>00139 <a class="code" href="class_c_count_serv_session.html#136ce24bef4184ad3b61aa9ae4bca5e0">PanicClient</a>(aMessage,<a class="code" href="secureserver_8h.html#091a5ad2956fb84c4470a59010a0d4efeef6b7f2a8413e6863e2136b93228c3a">EBadRequest</a>);
<a name="l00140"></a>00140 <span class="keywordflow">return</span>;
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143
<a name="l00149"></a><a class="code" href="class_c_count_serv_session.html#4525c4f71d949a86fe4c02a7b242ce1e">00149</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#4525c4f71d949a86fe4c02a7b242ce1e">CCountServSession::SetFromStringL</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151
<a name="l00152"></a>00152 <span class="comment">// length of passed descriptor (1st parameter passed from client)</span>
<a name="l00153"></a>00153 TInt deslen = aMessage.GetDesLength(0);
<a name="l00154"></a>00154
<a name="l00155"></a>00155 <span class="comment">// Passed data will be saved in this descriptor.</span>
<a name="l00156"></a>00156 RBuf buffer;
<a name="l00157"></a>00157
<a name="l00158"></a>00158 <span class="comment">// Max length set to the value of "deslen", but current length is zero</span>
<a name="l00159"></a>00159 buffer.CreateL(deslen);
<a name="l00160"></a>00160
<a name="l00161"></a>00161 <span class="comment">// Do the right cleanup if anything subsequently goes wrong</span>
<a name="l00162"></a>00162 buffer.CleanupClosePushL();
<a name="l00163"></a>00163
<a name="l00164"></a>00164 <span class="comment">// Copy the client's descriptor data into our buffer.</span>
<a name="l00165"></a>00165 aMessage.ReadL(0,buffer,0);
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="comment">// Now do a validation to make sure that the string only has digits</span>
<a name="l00168"></a>00168 <span class="keywordflow">if</span> (buffer.Length() == 0)
<a name="l00169"></a>00169 {
<a name="l00170"></a>00170 User::Leave(<a class="code" href="secureclientandserver_8h.html#c31a03d737c6ab16ba55ceab73d57b71e3a6b8e17c25d02a3ae9ca7362ba4d0c">ENonNumericString</a>);
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172
<a name="l00173"></a>00173 TLex16 lexer;
<a name="l00174"></a>00174
<a name="l00175"></a>00175 lexer.Assign(buffer);
<a name="l00176"></a>00176 <span class="keywordflow">while</span> (!lexer.Eos())
<a name="l00177"></a>00177 {
<a name="l00178"></a>00178 TChar thechar;
<a name="l00179"></a>00179
<a name="l00180"></a>00180 thechar = lexer.Peek();
<a name="l00181"></a>00181 <span class="keywordflow">if</span> (!thechar.IsDigit())
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183 User::Leave(<a class="code" href="secureclientandserver_8h.html#c31a03d737c6ab16ba55ceab73d57b71e3a6b8e17c25d02a3ae9ca7362ba4d0c">ENonNumericString</a>);
<a name="l00184"></a>00184 }
<a name="l00185"></a>00185 lexer.Inc();
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187
<a name="l00188"></a>00188 <span class="comment">// Convert to a simple TInt value. </span>
<a name="l00189"></a>00189 lexer.Assign(buffer);
<a name="l00190"></a>00190 <span class="keywordflow">if</span> (lexer.Val(iCount))
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192 User::Leave(<a class="code" href="secureclientandserver_8h.html#c31a03d737c6ab16ba55ceab73d57b71e3a6b8e17c25d02a3ae9ca7362ba4d0c">ENonNumericString</a>);
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194
<a name="l00195"></a>00195 <span class="comment">// Clean up the memory acquired by the RBuf variable "buffer"</span>
<a name="l00196"></a>00196 CleanupStack::PopAndDestroy();
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198
<a name="l00199"></a>00199
<a name="l00203"></a><a class="code" href="class_c_count_serv_session.html#26b884886f050963b5c29b792131418d">00203</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#26b884886f050963b5c29b792131418d">CCountServSession::Increase</a>()
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205 iCount++;
<a name="l00206"></a>00206 }
<a name="l00207"></a>00207
<a name="l00208"></a>00208
<a name="l00212"></a><a class="code" href="class_c_count_serv_session.html#36a92a040c8531527ae6de25ee1a1299">00212</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#36a92a040c8531527ae6de25ee1a1299">CCountServSession::IncreaseBy</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00213"></a>00213 {
<a name="l00214"></a>00214 iCount = iCount + aMessage.Int0();
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216
<a name="l00220"></a><a class="code" href="class_c_count_serv_session.html#eaeb91138f6d418a4fa580e095ed6081">00220</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#eaeb91138f6d418a4fa580e095ed6081">CCountServSession::Decrease</a>()
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222 iCount--;
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224
<a name="l00225"></a>00225
<a name="l00229"></a><a class="code" href="class_c_count_serv_session.html#b3a11addfd25b34b31ec7537d2e389af">00229</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#b3a11addfd25b34b31ec7537d2e389af">CCountServSession::DecreaseBy</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00230"></a>00230 {
<a name="l00231"></a>00231 iCount = iCount - aMessage.Int0();
<a name="l00232"></a>00232 }
<a name="l00233"></a>00233
<a name="l00234"></a>00234
<a name="l00238"></a><a class="code" href="class_c_count_serv_session.html#11afb27d6b3cfb6b658c46e3f5d1bd22">00238</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#11afb27d6b3cfb6b658c46e3f5d1bd22">CCountServSession::Reset</a>()
<a name="l00239"></a>00239 {
<a name="l00240"></a>00240 iCount=0;
<a name="l00241"></a>00241 }
<a name="l00242"></a>00242
<a name="l00243"></a>00243
<a name="l00248"></a><a class="code" href="class_c_count_serv_session.html#1c4cd0dd8c2cab784c4e3fafea9e4115">00248</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#1c4cd0dd8c2cab784c4e3fafea9e4115">CCountServSession::CounterValueL</a>(<span class="keyword">const</span> RMessage2& aMessage)
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250 TPckgBuf<TInt> p(iCount);
<a name="l00251"></a>00251 aMessage.WriteL(0,p);
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253
<a name="l00254"></a>00254
<a name="l00258"></a><a class="code" href="class_c_count_serv_session.html#136ce24bef4184ad3b61aa9ae4bca5e0">00258</a> <span class="keywordtype">void</span> <a class="code" href="class_c_count_serv_session.html#136ce24bef4184ad3b61aa9ae4bca5e0">CCountServSession::PanicClient</a>(<span class="keyword">const</span> RMessage2& aMessage,TInt aPanic)<span class="keyword"> const</span>
<a name="l00259"></a>00259 <span class="keyword"> </span>{
<a name="l00260"></a>00260 _LIT(KTxtServer,<span class="stringliteral">"CountServ server"</span>);
<a name="l00261"></a>00261 aMessage.Panic(KTxtServer,aPanic);
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263
<a name="l00264"></a>00264
<a name="l00265"></a>00265
<a name="l00266"></a>00266 <span class="comment">//**********************************</span>
<a name="l00267"></a>00267 <span class="comment">//Global functions</span>
<a name="l00268"></a>00268 <span class="comment">//**********************************</span>
<a name="l00269"></a>00269
<a name="l00270"></a>00270 <span class="comment">// The count server thread function that initialises the server.</span>
<a name="l00271"></a><a class="code" href="class_c_count_serv_server.html#8cbb4cf23ce6146bded0f2fa9a09b285">00271</a> GLDEF_C TInt <a class="code" href="class_c_count_serv_server.html#8cbb4cf23ce6146bded0f2fa9a09b285">CCountServServer::ThreadFunction</a>(TAny* )
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273 <span class="comment">// get clean-up stack</span>
<a name="l00274"></a>00274 CTrapCleanup* cleanup=CTrapCleanup::New();
<a name="l00275"></a>00275 <span class="keywordflow">if</span> (cleanup == NULL)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277 <a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">CCountServServer::PanicServer</a>(<a class="code" href="secureserver_8h.html#091a5ad2956fb84c4470a59010a0d4ef36f3ebda4e94aedb5817599162216e69">ECreateTrapCleanup</a>);
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279
<a name="l00280"></a>00280 <span class="comment">// create an active scheduler and server</span>
<a name="l00281"></a>00281 CActiveScheduler *pA=<span class="keyword">new</span> CActiveScheduler;
<a name="l00282"></a>00282 __ASSERT_ALWAYS(pA!=NULL,<a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">CCountServServer::PanicServer</a>(<a class="code" href="secureserver_8h.html#091a5ad2956fb84c4470a59010a0d4ef4dc32eda4a06b69469187275e825d99f">EMainSchedulerError</a>));
<a name="l00283"></a>00283 <a class="code" href="class_c_count_serv_server.html">CCountServServer</a> *pS=<span class="keyword">new</span> <a class="code" href="class_c_count_serv_server.html#ed2a6e31e0028426cca9da53a4f8e1d4">CCountServServer</a>(EPriorityStandard);
<a name="l00284"></a>00284 __ASSERT_ALWAYS(pS!=NULL,<a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">CCountServServer::PanicServer</a>(ESvrCreateServer));
<a name="l00285"></a>00285
<a name="l00286"></a>00286 <span class="comment">//Install the active scheduler</span>
<a name="l00287"></a>00287 CActiveScheduler::Install(pA);
<a name="l00288"></a>00288
<a name="l00289"></a>00289 <span class="comment">// Start the server</span>
<a name="l00290"></a>00290 TInt err = pS->Start(KCountServerName);
<a name="l00291"></a>00291 <span class="keywordflow">if</span> (err != KErrNone)
<a name="l00292"></a>00292 {
<a name="l00293"></a>00293 <a class="code" href="class_c_count_serv_server.html#75700ec8051bd8a2bbd677f7244207cb">CCountServServer::PanicServer</a>(ESvrStartServer);
<a name="l00294"></a>00294 }
<a name="l00295"></a>00295
<a name="l00296"></a>00296 <span class="comment">// Let everyone know that we are ready to</span>
<a name="l00297"></a>00297 <span class="comment">// deal with requests.</span>
<a name="l00298"></a>00298 RThread::Rendezvous(KErrNone);
<a name="l00299"></a>00299
<a name="l00300"></a>00300 <span class="comment">// And start fielding requests from client(s).</span>
<a name="l00301"></a>00301 CActiveScheduler::Start();
<a name="l00302"></a>00302
<a name="l00303"></a>00303 <span class="comment">// Tidy up... </span>
<a name="l00304"></a>00304 <span class="keyword">delete</span> pS;
<a name="l00305"></a>00305 <span class="keyword">delete</span> pA;
<a name="l00306"></a>00306 <span class="keyword">delete</span> cleanup;
<a name="l00307"></a>00307
<a name="l00308"></a>00308 <span class="comment">// ...although we should never get here!</span>
<a name="l00309"></a>00309 <span class="keywordflow">return</span>(KErrNone);
<a name="l00310"></a>00310 }
<a name="l00311"></a>00311
<a name="l00312"></a>00312
<a name="l00320"></a>00320 EXPORT_C TInt StartThread(RThread& aServerThread)
<a name="l00321"></a>00321 {
<a name="l00322"></a>00322 TInt res=KErrNone;
<a name="l00323"></a>00323
<a name="l00324"></a>00324 <span class="comment">// Create the server, if one with this name does not already exist.</span>
<a name="l00325"></a>00325 TFindServer findCountServer(KCountServerName);
<a name="l00326"></a>00326 TFullName name;
<a name="l00327"></a>00327
<a name="l00328"></a>00328 <span class="comment">// Need to check that the server exists.</span>
<a name="l00329"></a>00329 <span class="keywordflow">if</span> (findCountServer.Next(name)!=KErrNone)
<a name="l00330"></a>00330 {
<a name="l00331"></a>00331 <span class="comment">// Create the thread for the server.</span>
<a name="l00332"></a>00332 res=aServerThread.Create(KCountServerName,
<a name="l00333"></a>00333 <a class="code" href="class_c_count_serv_server.html#8cbb4cf23ce6146bded0f2fa9a09b285">CCountServServer::ThreadFunction</a>,
<a name="l00334"></a>00334 KDefaultStackSize,
<a name="l00335"></a>00335 <a class="code" href="secureserver_8h.html#bccd7aceb4760cddd96866248e305f29">KDefaultHeapSize</a>,
<a name="l00336"></a>00336 <a class="code" href="secureserver_8h.html#bccd7aceb4760cddd96866248e305f29">KDefaultHeapSize</a>,
<a name="l00337"></a>00337 NULL
<a name="l00338"></a>00338 );
<a name="l00339"></a>00339
<a name="l00340"></a>00340 <span class="comment">// The thread has been created OK so get it started - however</span>
<a name="l00341"></a>00341 <span class="comment">// we need to make sure that it has started before we continue.</span>
<a name="l00342"></a>00342 <span class="keywordflow">if</span> (res==KErrNone)
<a name="l00343"></a>00343 {
<a name="l00344"></a>00344 TRequestStatus rendezvousStatus;
<a name="l00345"></a>00345
<a name="l00346"></a>00346 aServerThread.SetPriority(EPriorityNormal);
<a name="l00347"></a>00347 aServerThread.Rendezvous(rendezvousStatus);
<a name="l00348"></a>00348 aServerThread.Resume();
<a name="l00349"></a>00349 User::WaitForRequest(rendezvousStatus);
<a name="l00350"></a>00350 }
<a name="l00351"></a>00351
<a name="l00352"></a>00352 <span class="comment">// The thread has not been created - clearly there's been a problem.</span>
<a name="l00353"></a>00353 <span class="keywordflow">else</span>
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355 aServerThread.Close();
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 }
<a name="l00358"></a>00358 <span class="keywordflow">return</span> res;
<a name="l00359"></a>00359 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:56 2010 for TB10.1 Example Applications by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>