Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/processserver_8cpp-source.html
changeset 1 25a17d01db0c
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
       
     2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
       
     3 <title>TB10.1 Example Applications: examples/Base/IPC/AdvancedClientServerExample/ProcessServer/src/processserver.cpp Source File</title>
       
     4 <link href="doxygen.css" rel="stylesheet" type="text/css">
       
     5 <link href="tabs.css" rel="stylesheet" type="text/css">
       
     6 </head><body>
       
     7 <!-- Generated by Doxygen 1.5.3 -->
       
     8 <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>
       
     9 <a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
       
    10 <a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
       
    11 <a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
       
    12 <a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
       
    13 <a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
       
    14 <a name="l00007"></a>00007 <span class="comment">//</span>
       
    15 <a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
       
    16 <a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
       
    17 <a name="l00010"></a>00010 <span class="comment">//</span>
       
    18 <a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
       
    19 <a name="l00012"></a>00012 <span class="comment">//</span>
       
    20 <a name="l00013"></a>00013 <span class="comment">// Description:</span>
       
    21 <a name="l00014"></a>00014 <span class="comment">//</span>
       
    22 <a name="l00015"></a>00015 
       
    23 <a name="l00016"></a>00016 <span class="preprocessor">#include "processserver.h"</span>
       
    24 <a name="l00017"></a>00017 <span class="preprocessor">#include "processserverstart.h"</span>
       
    25 <a name="l00018"></a>00018 <span class="preprocessor">#include "processserversession.h"</span>
       
    26 <a name="l00019"></a>00019 <span class="preprocessor">#include&lt;e32debug.h&gt;</span>
       
    27 <a name="l00020"></a>00020 
       
    28 <a name="l00021"></a>00021 <span class="keyword">const</span> TInt KProcessServerShutDownDelay = 50000000; <span class="comment">//50 sec</span>
       
    29 <a name="l00022"></a>00022 
       
    30 <a name="l00023"></a>00023 <span class="comment">//******CProcessServer******//</span>
       
    31 <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>()
       
    32 <a name="l00025"></a>00025         {
       
    33 <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>();
       
    34 <a name="l00027"></a>00027         CleanupStack::PushL(s);
       
    35 <a name="l00028"></a>00028         s-&gt;<a class="code" href="class_c_process_server.html#c02aba37cd71b94f4df290bd3402df4b">ConstructL</a>();
       
    36 <a name="l00029"></a>00029         }
       
    37 <a name="l00033"></a>00033 CProcessServer::CProcessServer()
       
    38 <a name="l00034"></a>00034         :CServer2(EPriorityStandard, ESharableSessions),iDriverState(<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38febfde84b09cb7b3b4bfc1fe81587451">EStateUnknown</a>)
       
    39 <a name="l00035"></a>00035         {
       
    40 <a name="l00036"></a>00036         }
       
    41 <a name="l00040"></a>00040 <span class="keywordtype">void</span> CProcessServer::ConstructL()
       
    42 <a name="l00041"></a>00041         {
       
    43 <a name="l00042"></a>00042         <span class="comment">// Call CServer2::StartL() before any other functions inside ConstructL()</span>
       
    44 <a name="l00043"></a>00043         <span class="comment">// to avoid an error other than KErrAlreadyExists when the duplicate server starts</span>
       
    45 <a name="l00044"></a>00044         StartL(KProcessServerName);
       
    46 <a name="l00045"></a>00045         iDelayProcessServerShutDown = <a class="code" href="class_c_delay_server_shut_down.html#b57ff972b3f6f5807c26de442521f637">CDelayServerShutDown::NewL</a>();
       
    47 <a name="l00046"></a>00046         }
       
    48 <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>()
       
    49 <a name="l00051"></a>00051         {
       
    50 <a name="l00052"></a>00052         <span class="keywordflow">if</span> (iDelayProcessServerShutDown)
       
    51 <a name="l00053"></a>00053                 {
       
    52 <a name="l00054"></a>00054                 iDelayProcessServerShutDown-&gt;Cancel();
       
    53 <a name="l00055"></a>00055                 <span class="keyword">delete</span> iDelayProcessServerShutDown;
       
    54 <a name="l00056"></a>00056                 }
       
    55 <a name="l00057"></a>00057                 
       
    56 <a name="l00058"></a>00058         <span class="comment">// unload device driver when server terminated</span>
       
    57 <a name="l00059"></a>00059         <a class="code" href="class_c_process_server.html#3e78b0766ff78223d4ccf77fa717b269">UnloadDevice</a>();
       
    58 <a name="l00060"></a>00060         }
       
    59 <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&amp; aVersion,<span class="keyword">const</span> RMessage2&amp; aMessage)<span class="keyword"> const</span>
       
    60 <a name="l00068"></a>00068 <span class="keyword">        </span>{
       
    61 <a name="l00069"></a>00069         <span class="comment">//check whether version is compatible</span>
       
    62 <a name="l00070"></a>00070         TVersion v(KProcessServerVersion,KProcessServerMinorVersionNumber,KProcessServerBuildVersionNumber);
       
    63 <a name="l00071"></a>00071         <span class="keywordflow">if</span>(!User::QueryVersionSupported(v, aVersion))
       
    64 <a name="l00072"></a>00072                 User::Leave(KErrNotSupported);
       
    65 <a name="l00073"></a>00073         
       
    66 <a name="l00074"></a>00074         <span class="comment">// check client process has the required capability</span>
       
    67 <a name="l00075"></a>00075         <span class="keywordflow">if</span>(!aMessage.HasCapability(ECapabilityMultimediaDD))
       
    68 <a name="l00076"></a>00076                 User::Leave(KErrPermissionDenied);              
       
    69 <a name="l00077"></a>00077 
       
    70 <a name="l00078"></a>00078         <span class="comment">// construct and return the server side client session object</span>
       
    71 <a name="l00079"></a>00079         <a class="code" href="class_c_process_server.html">CProcessServer</a>&amp; ncThis = <span class="keyword">const_cast&lt;</span><a class="code" href="class_c_process_server.html">CProcessServer</a>&amp;<span class="keyword">&gt;</span>(*this);
       
    72 <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);
       
    73 <a name="l00081"></a>00081         <span class="keywordflow">return</span> serverSession;
       
    74 <a name="l00082"></a>00082         }
       
    75 <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>()
       
    76 <a name="l00087"></a>00087         {
       
    77 <a name="l00088"></a>00088         iRefCount++;
       
    78 <a name="l00089"></a>00089         iDelayProcessServerShutDown-&gt;Cancel(); <span class="comment">// Cancel shutdown if it has started due to no clients being connected </span>
       
    79 <a name="l00090"></a>00090         }
       
    80 <a name="l00091"></a>00091         
       
    81 <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>() 
       
    82 <a name="l00096"></a>00096         {
       
    83 <a name="l00097"></a>00097         iRefCount--;
       
    84 <a name="l00098"></a>00098         <span class="keywordflow">if</span> ( iRefCount == 0 )
       
    85 <a name="l00099"></a>00099                 {
       
    86 <a name="l00100"></a>00100                 iDelayProcessServerShutDown-&gt;<a class="code" href="class_c_delay_server_shut_down.html#1b51f1f1518e93bc35e65f3a789ef009">SetDelay</a>(TTimeIntervalMicroSeconds32(KProcessServerShutDownDelay));
       
    87 <a name="l00101"></a>00101                 }
       
    88 <a name="l00102"></a>00102         }
       
    89 <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>()
       
    90 <a name="l00108"></a>00108         {
       
    91 <a name="l00109"></a>00109         <span class="keywordflow">if</span> (iDriverState&gt;=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38e0571fa5b49a37bdac4e3d6e5f6f30a1">EDriverLoaded</a> &amp;&amp; iDriverState&lt;<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b386156c4dd182e5386ec555f3da184fdfd">EDriverUnloaded</a>)
       
    92 <a name="l00110"></a>00110                 <span class="keywordflow">return</span> KErrNone; <span class="comment">//Device has been loaded, return immediately</span>
       
    93 <a name="l00111"></a>00111                 
       
    94 <a name="l00112"></a>00112         TInt r=User::LoadPhysicalDevice(KDriver1PddFileName);
       
    95 <a name="l00113"></a>00113         <span class="keywordflow">if</span> (r!=KErrNone &amp;&amp; r!=KErrAlreadyExists)
       
    96 <a name="l00114"></a>00114                 {
       
    97 <a name="l00115"></a>00115                 <span class="keywordflow">return</span> r; <span class="comment">//some error occurred</span>
       
    98 <a name="l00116"></a>00116                 }
       
    99 <a name="l00117"></a>00117 
       
   100 <a name="l00118"></a>00118         r = User::LoadLogicalDevice(KDriver1LddFileName);
       
   101 <a name="l00119"></a>00119         <span class="keywordflow">if</span> (r!=KErrNone &amp;&amp; r!=KErrAlreadyExists)
       
   102 <a name="l00120"></a>00120                 {
       
   103 <a name="l00121"></a>00121                 <span class="keywordflow">return</span> r; <span class="comment">//some error occurred </span>
       
   104 <a name="l00122"></a>00122                 }
       
   105 <a name="l00123"></a>00123 
       
   106 <a name="l00124"></a>00124         <span class="comment">//both PDD and LDD have been loaded</span>
       
   107 <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>);
       
   108 <a name="l00126"></a>00126         <span class="keywordflow">return</span> KErrNone; 
       
   109 <a name="l00127"></a>00127         }
       
   110 <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>()
       
   111 <a name="l00133"></a>00133         {
       
   112 <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>)
       
   113 <a name="l00135"></a>00135                 <span class="keywordflow">return</span> KErrNone; <span class="comment">//no device is loaded, return immediately</span>
       
   114 <a name="l00136"></a>00136                 
       
   115 <a name="l00137"></a>00137         <span class="comment">// close device</span>
       
   116 <a name="l00138"></a>00138         <span class="keywordflow">if</span> (iDriver.Handle())
       
   117 <a name="l00139"></a>00139                 iDriver.Close();
       
   118 <a name="l00140"></a>00140         <span class="comment">// Unload Logical Device</span>
       
   119 <a name="l00141"></a>00141         TInt r = User::FreeLogicalDevice(<a class="code" href="class_r_driver1.html#7e98e9f7ec04a53a404d646481f589ca">RDriver1::Name</a>());
       
   120 <a name="l00142"></a>00142         <span class="keywordflow">if</span> (r!=KErrNone)
       
   121 <a name="l00143"></a>00143                 <span class="keywordflow">return</span> r;
       
   122 <a name="l00144"></a>00144         <span class="comment">// Unload Physical Device</span>
       
   123 <a name="l00145"></a>00145         TName pddName(<a class="code" href="class_r_driver1.html#7e98e9f7ec04a53a404d646481f589ca">RDriver1::Name</a>());
       
   124 <a name="l00146"></a>00146         _LIT(KVariantExtension,<span class="stringliteral">".template"</span>);
       
   125 <a name="l00147"></a>00147         pddName.Append(KVariantExtension);
       
   126 <a name="l00148"></a>00148         r=User::FreePhysicalDevice(pddName);
       
   127 <a name="l00149"></a>00149         
       
   128 <a name="l00150"></a>00150         <span class="keywordflow">if</span> (KErrNone==r)
       
   129 <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>);     
       
   130 <a name="l00152"></a>00152         <span class="keywordflow">return</span> r;
       
   131 <a name="l00153"></a>00153         }
       
   132 <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>()
       
   133 <a name="l00159"></a>00159         {
       
   134 <a name="l00160"></a>00160         <span class="keywordflow">if</span> (iDriverState&gt;=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a> &amp;&amp; iDriverState&lt;<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b385357bdbb689c819cd07b927e09b11e3f">ELogicalChannelClosed</a>)
       
   135 <a name="l00161"></a>00161                 <span class="keywordflow">return</span> KErrNone;
       
   136 <a name="l00162"></a>00162         
       
   137 <a name="l00163"></a>00163         TInt r = iDriver.<a class="code" href="class_r_driver1.html#f30696b673cd91e87f9c7497a72798eb">Open</a>();
       
   138 <a name="l00164"></a>00164         <span class="keywordflow">if</span> (KErrNone==r)
       
   139 <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>);
       
   140 <a name="l00166"></a>00166         
       
   141 <a name="l00167"></a>00167         <span class="keywordflow">return</span> r;
       
   142 <a name="l00168"></a>00168         }
       
   143 <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>()
       
   144 <a name="l00173"></a>00173         {
       
   145 <a name="l00174"></a>00174         <span class="keywordflow">if</span> (iDriver.Handle())
       
   146 <a name="l00175"></a>00175                 {
       
   147 <a name="l00176"></a>00176                 iDriver.Close();
       
   148 <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>);
       
   149 <a name="l00178"></a>00178                 }
       
   150 <a name="l00179"></a>00179         }
       
   151 <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&amp; aStatus, <span class="keyword">const</span> TDesC8&amp; aData)
       
   152 <a name="l00187"></a>00187         {
       
   153 <a name="l00188"></a>00188         TInt r = KErrNone;
       
   154 <a name="l00189"></a>00189         <span class="keywordflow">if</span> (iDriverState&gt;=<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b38d1f2b7048e915bb24c249a40e10c500c">ELogicalChannelOpened</a> &amp;&amp; iDriverState&lt;<a class="code" href="class_c_process_server.html#82cab30ea5d500e0abc51d39a0889b385357bdbb689c819cd07b927e09b11e3f">ELogicalChannelClosed</a>)
       
   155 <a name="l00190"></a>00190                 {
       
   156 <a name="l00191"></a>00191                 iDriver.<a class="code" href="class_r_driver1.html#2b99c6487e8916a54720d8eb3071cd85">SendData</a>(aStatus, aData);
       
   157 <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>);
       
   158 <a name="l00193"></a>00193                 }
       
   159 <a name="l00194"></a>00194         <span class="keywordflow">else</span>
       
   160 <a name="l00195"></a>00195                 {
       
   161 <a name="l00196"></a>00196                 r = KErrArgument;
       
   162 <a name="l00197"></a>00197                 }
       
   163 <a name="l00198"></a>00198         <span class="keywordflow">return</span> r;
       
   164 <a name="l00199"></a>00199         }
       
   165 <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>()
       
   166 <a name="l00204"></a>00204         {
       
   167 <a name="l00205"></a>00205         iDriver.<a class="code" href="class_r_driver1.html#3a9b32b811f9bec9b3317d2b187b8417">SendDataCancel</a>();
       
   168 <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>);
       
   169 <a name="l00207"></a>00207         }
       
   170 <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)
       
   171 <a name="l00213"></a>00213         {
       
   172 <a name="l00214"></a>00214         iDriverState = aState;
       
   173 <a name="l00215"></a>00215         }
       
   174 <a name="l00216"></a>00216 
       
   175 <a name="l00217"></a>00217 <span class="comment">//EOF</span>
       
   176 </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&nbsp;
       
   177 <a href="http://www.doxygen.org/index.html">
       
   178 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
       
   179 </body>
       
   180 </html>