Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/processserver_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/AdvancedClientServerExample/ProcessServer/src/processserver.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/AdvancedClientServerExample/ProcessServer/src/processserver.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2007-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">//</span>
<a name="l00015"></a>00015
<a name="l00016"></a>00016 <span class="preprocessor">#include "processserver.h"</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include "processserverstart.h"</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "processserversession.h"</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include<e32debug.h></span>
<a name="l00020"></a>00020
<a name="l00021"></a>00021 <span class="keyword">const</span> TInt KProcessServerShutDownDelay = 50000000; <span class="comment">//50 sec</span>
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="comment">//******CProcessServer******//</span>
<a name="l00024"></a><a class="code" href="class_c_process_server.html#239278f30e2253b2d0827752355dbef2">00024</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#239278f30e2253b2d0827752355dbef2">CProcessServer::NewLC</a>()
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026 <a class="code" href="class_c_process_server.html">CProcessServer</a>* s = <span class="keyword">new</span>(ELeave) <a class="code" href="class_c_process_server.html">CProcessServer</a>();
<a name="l00027"></a>00027 CleanupStack::PushL(s);
<a name="l00028"></a>00028 s-><a class="code" href="class_c_process_server.html#c02aba37cd71b94f4df290bd3402df4b">ConstructL</a>();
<a name="l00029"></a>00029 }
<a name="l00033"></a>00033 CProcessServer::CProcessServer()
<a name="l00034"></a>00034 :CServer2(EPriorityStandard, ESharableSessions),iDriverState(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38febfde84b09cb7b3b4bfc1fe81587451">EStateUnknown</a>)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036 }
<a name="l00040"></a>00040 <span class="keywordtype">void</span> CProcessServer::ConstructL()
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 <span class="comment">// Call CServer2::StartL() before any other functions inside ConstructL()</span>
<a name="l00043"></a>00043 <span class="comment">// to avoid an error other than KErrAlreadyExists when the duplicate server starts</span>
<a name="l00044"></a>00044 StartL(KProcessServerName);
<a name="l00045"></a>00045 iDelayProcessServerShutDown = <a class="code" href="class_c_delay_server_shut_down.html#b57ff972b3f6f5807c26de442521f637">CDelayServerShutDown::NewL</a>();
<a name="l00046"></a>00046 }
<a name="l00050"></a><a class="code" href="class_c_process_server.html#f9cff6818110c62a7ad6a1c19984297b">00050</a> <a class="code" href="class_c_process_server.html#f9cff6818110c62a7ad6a1c19984297b">CProcessServer::~CProcessServer</a>()
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052 <span class="keywordflow">if</span> (iDelayProcessServerShutDown)
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054 iDelayProcessServerShutDown->Cancel();
<a name="l00055"></a>00055 <span class="keyword">delete</span> iDelayProcessServerShutDown;
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057
<a name="l00058"></a>00058 <span class="comment">// unload device driver when server terminated</span>
<a name="l00059"></a>00059 <a class="code" href="class_c_process_server.html#3e78b0766ff78223d4ccf77fa717b269">UnloadDevice</a>();
<a name="l00060"></a>00060 }
<a name="l00067"></a><a class="code" href="class_c_process_server.html#0025005d37f3cc34dc8e181373980ce9">00067</a> CSession2* <a class="code" href="class_c_process_server.html#0025005d37f3cc34dc8e181373980ce9">CProcessServer::NewSessionL</a>(<span class="keyword">const</span> TVersion& aVersion,<span class="keyword">const</span> RMessage2& aMessage)<span class="keyword"> const</span>
<a name="l00068"></a>00068 <span class="keyword"> </span>{
<a name="l00069"></a>00069 <span class="comment">//check whether version is compatible</span>
<a name="l00070"></a>00070 TVersion v(KProcessServerVersion,KProcessServerMinorVersionNumber,KProcessServerBuildVersionNumber);
<a name="l00071"></a>00071 <span class="keywordflow">if</span>(!User::QueryVersionSupported(v, aVersion))
<a name="l00072"></a>00072 User::Leave(KErrNotSupported);
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">// check client process has the required capability</span>
<a name="l00075"></a>00075 <span class="keywordflow">if</span>(!aMessage.HasCapability(ECapabilityMultimediaDD))
<a name="l00076"></a>00076 User::Leave(KErrPermissionDenied);
<a name="l00077"></a>00077
<a name="l00078"></a>00078 <span class="comment">// construct and return the server side client session object</span>
<a name="l00079"></a>00079 <a class="code" href="class_c_process_server.html">CProcessServer</a>& ncThis = <span class="keyword">const_cast<</span><a class="code" href="class_c_process_server.html">CProcessServer</a>&<span class="keyword">></span>(*this);
<a name="l00080"></a>00080 <a class="code" href="class_c_process_server_session.html">CProcessServerSession</a>* serverSession = <a class="code" href="class_c_process_server_session.html#78c129c639699c68a66b718fa7952728">CProcessServerSession::NewL</a>(ncThis);
<a name="l00081"></a>00081 <span class="keywordflow">return</span> serverSession;
<a name="l00082"></a>00082 }
<a name="l00086"></a><a class="code" href="class_c_process_server.html#d113263093aaa3489308e2ecc6f20c87">00086</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#d113263093aaa3489308e2ecc6f20c87">CProcessServer::IncrementRefCount</a>()
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 iRefCount++;
<a name="l00089"></a>00089 iDelayProcessServerShutDown->Cancel(); <span class="comment">// Cancel shutdown if it has started due to no clients being connected </span>
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091
<a name="l00095"></a><a class="code" href="class_c_process_server.html#cc9e2e8092c07e6fbf8aa4f866a1ba89">00095</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#cc9e2e8092c07e6fbf8aa4f866a1ba89">CProcessServer::DecrementRefCount</a>()
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097 iRefCount--;
<a name="l00098"></a>00098 <span class="keywordflow">if</span> ( iRefCount == 0 )
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100 iDelayProcessServerShutDown-><a class="code" href="class_c_delay_server_shut_down.html#1b51f1f1518e93bc35e65f3a789ef009">SetDelay</a>(TTimeIntervalMicroSeconds32(KProcessServerShutDownDelay));
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102 }
<a name="l00107"></a><a class="code" href="class_c_process_server.html#9333ba960d07b42c72d98466b01788ce">00107</a> TInt <a class="code" href="class_c_process_server.html#9333ba960d07b42c72d98466b01788ce">CProcessServer::LoadDevice</a>()
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109 <span class="keywordflow">if</span> (iDriverState>=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38e0571fa5b49a37bdac4e3d6e5f6f30a1">EDriverLoaded</a> && iDriverState<<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b386156c4dd182e5386ec555f3da184fdfd">EDriverUnloaded</a>)
<a name="l00110"></a>00110 <span class="keywordflow">return</span> KErrNone; <span class="comment">//Device has been loaded, return immediately</span>
<a name="l00111"></a>00111
<a name="l00112"></a>00112 TInt r=User::LoadPhysicalDevice(KDriver1PddFileName);
<a name="l00113"></a>00113 <span class="keywordflow">if</span> (r!=KErrNone && r!=KErrAlreadyExists)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 <span class="keywordflow">return</span> r; <span class="comment">//some error occurred</span>
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117
<a name="l00118"></a>00118 r = User::LoadLogicalDevice(KDriver1LddFileName);
<a name="l00119"></a>00119 <span class="keywordflow">if</span> (r!=KErrNone && r!=KErrAlreadyExists)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 <span class="keywordflow">return</span> r; <span class="comment">//some error occurred </span>
<a name="l00122"></a>00122 }
<a name="l00123"></a>00123
<a name="l00124"></a>00124 <span class="comment">//both PDD and LDD have been loaded</span>
<a name="l00125"></a>00125 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38e0571fa5b49a37bdac4e3d6e5f6f30a1">EDriverLoaded</a>);
<a name="l00126"></a>00126 <span class="keywordflow">return</span> KErrNone;
<a name="l00127"></a>00127 }
<a name="l00132"></a><a class="code" href="class_c_process_server.html#3e78b0766ff78223d4ccf77fa717b269">00132</a> TInt <a class="code" href="class_c_process_server.html#3e78b0766ff78223d4ccf77fa717b269">CProcessServer::UnloadDevice</a>()
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134 <span class="keywordflow">if</span> (iDriverState==<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b386156c4dd182e5386ec555f3da184fdfd">EDriverUnloaded</a> || iDriverState == <a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38febfde84b09cb7b3b4bfc1fe81587451">EStateUnknown</a>)
<a name="l00135"></a>00135 <span class="keywordflow">return</span> KErrNone; <span class="comment">//no device is loaded, return immediately</span>
<a name="l00136"></a>00136
<a name="l00137"></a>00137 <span class="comment">// close device</span>
<a name="l00138"></a>00138 <span class="keywordflow">if</span> (iDriver.Handle())
<a name="l00139"></a>00139 iDriver.Close();
<a name="l00140"></a>00140 <span class="comment">// Unload Logical Device</span>
<a name="l00141"></a>00141 TInt r = User::FreeLogicalDevice(<a class="code" href="class_r_driver1.html#7e98e9f7ec04a53a404d646481f589ca">RDriver1::Name</a>());
<a name="l00142"></a>00142 <span class="keywordflow">if</span> (r!=KErrNone)
<a name="l00143"></a>00143 <span class="keywordflow">return</span> r;
<a name="l00144"></a>00144 <span class="comment">// Unload Physical Device</span>
<a name="l00145"></a>00145 TName pddName(<a class="code" href="class_r_driver1.html#7e98e9f7ec04a53a404d646481f589ca">RDriver1::Name</a>());
<a name="l00146"></a>00146 _LIT(KVariantExtension,<span class="stringliteral">".template"</span>);
<a name="l00147"></a>00147 pddName.Append(KVariantExtension);
<a name="l00148"></a>00148 r=User::FreePhysicalDevice(pddName);
<a name="l00149"></a>00149
<a name="l00150"></a>00150 <span class="keywordflow">if</span> (KErrNone==r)
<a name="l00151"></a>00151 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b386156c4dd182e5386ec555f3da184fdfd">EDriverUnloaded</a>);
<a name="l00152"></a>00152 <span class="keywordflow">return</span> r;
<a name="l00153"></a>00153 }
<a name="l00158"></a><a class="code" href="class_c_process_server.html#1861af3b7073acf002b55520397c4678">00158</a> TInt <a class="code" href="class_c_process_server.html#1861af3b7073acf002b55520397c4678">CProcessServer::OpenLogicalChannel</a>()
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160 <span class="keywordflow">if</span> (iDriverState>=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a> && iDriverState<<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b385357bdbb689c819cd07b927e09b11e3f">ELogicalChannelClosed</a>)
<a name="l00161"></a>00161 <span class="keywordflow">return</span> KErrNone;
<a name="l00162"></a>00162
<a name="l00163"></a>00163 TInt r = iDriver.<a class="code" href="class_r_driver1.html#f30696b673cd91e87f9c7497a72798eb">Open</a>();
<a name="l00164"></a>00164 <span class="keywordflow">if</span> (KErrNone==r)
<a name="l00165"></a>00165 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a>);
<a name="l00166"></a>00166
<a name="l00167"></a>00167 <span class="keywordflow">return</span> r;
<a name="l00168"></a>00168 }
<a name="l00172"></a><a class="code" href="class_c_process_server.html#c381e3ac102f3c720ca1cffec2ab570d">00172</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#c381e3ac102f3c720ca1cffec2ab570d">CProcessServer::CloseLogicalChannel</a>()
<a name="l00173"></a>00173 {
<a name="l00174"></a>00174 <span class="keywordflow">if</span> (iDriver.Handle())
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176 iDriver.Close();
<a name="l00177"></a>00177 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b385357bdbb689c819cd07b927e09b11e3f">ELogicalChannelClosed</a>);
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 }
<a name="l00186"></a><a class="code" href="class_c_process_server.html#a1e3677c879b6a531f67267ff63ec214">00186</a> TInt <a class="code" href="class_c_process_server.html#a1e3677c879b6a531f67267ff63ec214">CProcessServer::SendDataToDevice</a>(TRequestStatus& aStatus, <span class="keyword">const</span> TDesC8& aData)
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188 TInt r = KErrNone;
<a name="l00189"></a>00189 <span class="keywordflow">if</span> (iDriverState>=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a> && iDriverState<<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b385357bdbb689c819cd07b927e09b11e3f">ELogicalChannelClosed</a>)
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191 iDriver.<a class="code" href="class_r_driver1.html#2b99c6487e8916a54720d8eb3071cd85">SendData</a>(aStatus, aData);
<a name="l00192"></a>00192 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38946b4628ef31d91ded88495747be5902">ESendingData</a>);
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 <span class="keywordflow">else</span>
<a name="l00195"></a>00195 {
<a name="l00196"></a>00196 r = KErrArgument;
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 <span class="keywordflow">return</span> r;
<a name="l00199"></a>00199 }
<a name="l00203"></a><a class="code" href="class_c_process_server.html#853cb371c075e2f74ac3e28a9a66f38e">00203</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#853cb371c075e2f74ac3e28a9a66f38e">CProcessServer::CancelSendData</a>()
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205 iDriver.<a class="code" href="class_r_driver1.html#3a9b32b811f9bec9b3317d2b187b8417">SendDataCancel</a>();
<a name="l00206"></a>00206 <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a>);
<a name="l00207"></a>00207 }
<a name="l00212"></a><a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">00212</a> <span class="keywordtype">void</span> <a class="code" href="class_c_process_server.html#6af5450445ef1f12826f88a24ec83043">CProcessServer::UpdateDriverState</a>(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38">TDriverState</a> aState)
<a name="l00213"></a>00213 {
<a name="l00214"></a>00214 iDriverState = aState;
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216
<a name="l00217"></a>00217 <span class="comment">//EOF</span>
</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>