examples/S60CppExamples/ClientServerAsync/doc/timeserver_8cpp-source.html

00001 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
00002 <html>
00003 
00004 <head>
00005 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
00006 <title>timeserver.cpp Source File</title>
00007 <link href="style.css" rel="stylesheet" type="text/css">
00008 </head>
00009 
00010 <table border="0" width="100%" height="8" bgcolor="#eeeeee">
00011 <tr> <td width="100%" height="1"><b><font size="2" color="#000000" face="Arial, Helvetica, sans-serif"><strong><a name=Top></a>
00012 S60 5th Edition SDK </strong></font></b><br><i>Example Applications Guide</i></td></tr> </table>
00013 <!-- Generated by Doxygen 1.4.5 -->
00014 <div class="tabs">
00015   <ul>
00016     <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
00017     <li><a href="annotated.html"><span>Classes</span></a></li>
00018     <li id="current"><a href="files.html"><span>Files</span></a></li>
00019   </ul></div>
00020 <h1>timeserver.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
00021 <a name="l00002"></a>00002 <span class="comment">* ==============================================================================</span>
00022 <a name="l00003"></a>00003 <span class="comment">*  Name        : timeserver.cpp</span>
00023 <a name="l00004"></a>00004 <span class="comment">*  Part of     : CSAsync</span>
00024 <a name="l00005"></a>00005 <span class="comment">*  Interface   :</span>
00025 <a name="l00006"></a>00006 <span class="comment">*  Description :</span>
00026 <a name="l00007"></a>00007 <span class="comment">*  Version     :</span>
00027 <a name="l00008"></a>00008 <span class="comment">*</span>
00028 <a name="l00009"></a>00009 <span class="comment">*  Copyright (c) 2004-2006 Nokia Corporation.</span>
00029 <a name="l00010"></a>00010 <span class="comment">*  This material, including documentation and any related</span>
00030 <a name="l00011"></a>00011 <span class="comment">*  computer programs, is protected by copyright controlled by</span>
00031 <a name="l00012"></a>00012 <span class="comment">*  Nokia Corporation.</span>
00032 <a name="l00013"></a>00013 <span class="comment">* ==============================================================================</span>
00033 <a name="l00014"></a>00014 <span class="comment">*/</span>
00034 <a name="l00015"></a>00015 
00035 <a name="l00016"></a>00016 
00036 <a name="l00017"></a>00017 <span class="comment">// INCLUDE FILES</span>
00037 <a name="l00018"></a>00018 <span class="preprocessor">#include &lt;e32svr.h&gt;</span>
00038 <a name="l00019"></a>00019 <span class="preprocessor">#include &lt;e32math.h&gt;</span>
00039 <a name="l00020"></a>00020 
00040 <a name="l00021"></a>00021 <span class="preprocessor">#include "TimeServer.h"</span>
00041 <a name="l00022"></a>00022 <span class="preprocessor">#include "ClientServerCommon.h"</span>
00042 <a name="l00023"></a>00023 <span class="preprocessor">#include "TimeSession.h"</span>
00043 <a name="l00024"></a>00024 
00044 <a name="l00025"></a>00025 <span class="comment">// ========================= MEMBER FUNCTIONS ==================================</span>
00045 <a name="l00026"></a>00026 
00046 <a name="l00027"></a>00027 <span class="comment">// -----------------------------------------------------------------------------</span>
00047 <a name="l00028"></a>00028 <span class="comment">// CTimeServer::NewL()</span>
00048 <a name="l00029"></a>00029 <span class="comment">// Two-phased constructor.</span>
00049 <a name="l00030"></a>00030 <span class="comment">// -----------------------------------------------------------------------------</span>
00050 <a name="l00031"></a>00031 <span class="comment">//</span>
00051 <a name="l00032"></a><a class="code" href="class_c_time_server.html#990716240ccf3341f7fdbf289ec927ad">00032</a> <a class="code" href="class_c_time_server.html">CTimeServer</a>* <a class="code" href="class_c_time_server.html#990716240ccf3341f7fdbf289ec927ad">CTimeServer::NewL</a>()
00052 <a name="l00033"></a>00033     {
00053 <a name="l00034"></a>00034     <a class="code" href="class_c_time_server.html">CTimeServer</a>* timeServer = <a class="code" href="class_c_time_server.html#94389c6729b439332fc74a54ac683740">CTimeServer::NewLC</a>();
00054 <a name="l00035"></a>00035     CleanupStack::Pop( timeServer );
00055 <a name="l00036"></a>00036     <span class="keywordflow">return</span> timeServer;
00056 <a name="l00037"></a>00037     }
00057 <a name="l00038"></a>00038 
00058 <a name="l00039"></a>00039 <span class="comment">// -----------------------------------------------------------------------------</span>
00059 <a name="l00040"></a>00040 <span class="comment">// CTimeServer::NewLC()</span>
00060 <a name="l00041"></a>00041 <span class="comment">// Two-phased constructor.</span>
00061 <a name="l00042"></a>00042 <span class="comment">// -----------------------------------------------------------------------------</span>
00062 <a name="l00043"></a>00043 <span class="comment">//</span>
00063 <a name="l00044"></a><a class="code" href="class_c_time_server.html#94389c6729b439332fc74a54ac683740">00044</a> <a class="code" href="class_c_time_server.html">CTimeServer</a>* <a class="code" href="class_c_time_server.html#94389c6729b439332fc74a54ac683740">CTimeServer::NewLC</a>()
00064 <a name="l00045"></a>00045     {
00065 <a name="l00046"></a>00046     <a class="code" href="class_c_time_server.html">CTimeServer</a>* timeServer = <span class="keyword">new</span> ( ELeave ) <a class="code" href="class_c_time_server.html#95423dd47aaf3240e1e4b42baa280c39">CTimeServer</a>( EPriorityNormal );
00066 <a name="l00047"></a>00047     CleanupStack::PushL( timeServer );
00067 <a name="l00048"></a>00048     timeServer-&gt;<a class="code" href="class_c_time_server.html#9ce34ba0b947863222da3c63d0481044">ConstructL</a>();
00068 <a name="l00049"></a>00049     <span class="keywordflow">return</span> timeServer;
00069 <a name="l00050"></a>00050     }
00070 <a name="l00051"></a>00051 
00071 <a name="l00052"></a>00052 <span class="comment">// -----------------------------------------------------------------------------</span>
00072 <a name="l00053"></a>00053 <span class="comment">// CTimeServer::ConstructL()</span>
00073 <a name="l00054"></a>00054 <span class="comment">// Symbian 2nd phase constructor can leave.</span>
00074 <a name="l00055"></a>00055 <span class="comment">// -----------------------------------------------------------------------------</span>
00075 <a name="l00056"></a>00056 <span class="comment">//</span>
00076 <a name="l00057"></a><a class="code" href="class_c_time_server.html#9ce34ba0b947863222da3c63d0481044">00057</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#9ce34ba0b947863222da3c63d0481044">CTimeServer::ConstructL</a>()
00077 <a name="l00058"></a>00058     {
00078 <a name="l00059"></a>00059     StartL( KTimeServerName );
00079 <a name="l00060"></a>00060     }
00080 <a name="l00061"></a>00061 
00081 <a name="l00062"></a>00062 <span class="comment">// -----------------------------------------------------------------------------</span>
00082 <a name="l00063"></a>00063 <span class="comment">// CTimeServer::CTimeServer()</span>
00083 <a name="l00064"></a>00064 <span class="comment">// C++ default constructor can NOT contain any code, that might leave.</span>
00084 <a name="l00065"></a>00065 <span class="comment">// -----------------------------------------------------------------------------</span>
00085 <a name="l00066"></a>00066 <span class="comment">//</span>
00086 <a name="l00067"></a><a class="code" href="class_c_time_server.html#95423dd47aaf3240e1e4b42baa280c39">00067</a> <a class="code" href="class_c_time_server.html#95423dd47aaf3240e1e4b42baa280c39">CTimeServer::CTimeServer</a>( TInt aPriority )
00087 <a name="l00068"></a>00068 : CServer2( aPriority )
00088 <a name="l00069"></a>00069     {
00089 <a name="l00070"></a>00070     <span class="comment">// Implementation not required</span>
00090 <a name="l00071"></a>00071     }
00091 <a name="l00072"></a>00072 
00092 <a name="l00073"></a>00073 <span class="comment">// -----------------------------------------------------------------------------</span>
00093 <a name="l00074"></a>00074 <span class="comment">// CTimeServer::~CTimeServer()</span>
00094 <a name="l00075"></a>00075 <span class="comment">// Destructor.</span>
00095 <a name="l00076"></a>00076 <span class="comment">// -----------------------------------------------------------------------------</span>
00096 <a name="l00077"></a>00077 <span class="comment">//</span>
00097 <a name="l00078"></a><a class="code" href="class_c_time_server.html#ab523c20e96ddd5e1413d525bad59fdd">00078</a> <a class="code" href="class_c_time_server.html#ab523c20e96ddd5e1413d525bad59fdd">CTimeServer::~CTimeServer</a>()
00098 <a name="l00079"></a>00079     {
00099 <a name="l00080"></a>00080     <span class="keyword">delete</span> <a class="code" href="class_c_time_server.html#bd20aae428bf045cb28f7958102a14e1">iHeartbeat</a>;
00100 <a name="l00081"></a>00081     <a class="code" href="class_c_time_server.html#bd20aae428bf045cb28f7958102a14e1">iHeartbeat</a> = NULL;
00101 <a name="l00082"></a>00082     }
00102 <a name="l00083"></a>00083 
00103 <a name="l00084"></a>00084 <span class="comment">// -----------------------------------------------------------------------------</span>
00104 <a name="l00085"></a>00085 <span class="comment">// CTimeServer::NewSessionL()</span>
00105 <a name="l00086"></a>00086 <span class="comment">// Creates a time server session.</span>
00106 <a name="l00087"></a>00087 <span class="comment">// -----------------------------------------------------------------------------</span>
00107 <a name="l00088"></a>00088 <span class="comment">//</span>
00108 <a name="l00089"></a><a class="code" href="class_c_time_server.html#e8cc7a175c8a6ec0a2b0ee8bf27badb9">00089</a> CSession2* <a class="code" href="class_c_time_server.html#e8cc7a175c8a6ec0a2b0ee8bf27badb9">CTimeServer::NewSessionL</a>( <span class="keyword">const</span> TVersion&amp; aVersion,
00109 <a name="l00090"></a>00090                                      <span class="keyword">const</span> RMessage2&amp; <span class="comment">/*aMessage*/</span> )<span class="keyword"> const</span>
00110 <a name="l00091"></a>00091 <span class="keyword">    </span>{
00111 <a name="l00092"></a>00092     <span class="comment">// Check we are the right version</span>
00112 <a name="l00093"></a>00093     <span class="keywordflow">if</span> ( !User::QueryVersionSupported( TVersion( KTimeServMajorVersionNumber,
00113 <a name="l00094"></a>00094                                                  KTimeServMinorVersionNumber,
00114 <a name="l00095"></a>00095                                                  KTimeServBuildVersionNumber ),
00115 <a name="l00096"></a>00096                                        aVersion ) )
00116 <a name="l00097"></a>00097         {
00117 <a name="l00098"></a>00098         User::Leave( KErrNotSupported );
00118 <a name="l00099"></a>00099         }
00119 <a name="l00100"></a>00100 
00120 <a name="l00101"></a>00101     <span class="comment">// Make new session</span>
00121 <a name="l00102"></a>00102     <span class="comment">//RThread client = Message().Client();</span>
00122 <a name="l00103"></a>00103     <span class="keywordflow">return</span> <a class="code" href="class_c_time_server_session.html#73d44aed371951fd548af4329b779411">CTimeServerSession::NewL</a>( *const_cast&lt;CTimeServer*&gt; ( <span class="keyword">this</span> ) );
00123 <a name="l00104"></a>00104     }
00124 <a name="l00105"></a>00105 
00125 <a name="l00106"></a>00106 <span class="comment">// -----------------------------------------------------------------------------</span>
00126 <a name="l00107"></a>00107 <span class="comment">// CTimeServer::IncrementSessions()</span>
00127 <a name="l00108"></a>00108 <span class="comment">// Increments the count of the active sessions for this server.</span>
00128 <a name="l00109"></a>00109 <span class="comment">// -----------------------------------------------------------------------------</span>
00129 <a name="l00110"></a>00110 <span class="comment">//</span>
00130 <a name="l00111"></a><a class="code" href="class_c_time_server.html#a3afdfcfbf3d8aa45b7f96b5a1c7119e">00111</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#a3afdfcfbf3d8aa45b7f96b5a1c7119e">CTimeServer::IncrementSessions</a>()
00131 <a name="l00112"></a>00112     {
00132 <a name="l00113"></a>00113     <a class="code" href="class_c_time_server.html#40ac9219e4400c125719d767d564fc3e">iSessionCount</a>++;
00133 <a name="l00114"></a>00114     }
00134 <a name="l00115"></a>00115 
00135 <a name="l00116"></a>00116 <span class="comment">// -----------------------------------------------------------------------------</span>
00136 <a name="l00117"></a>00117 <span class="comment">// CTimeServer::DecrementSessions()</span>
00137 <a name="l00118"></a>00118 <span class="comment">// Decrements the count of the active sessions for this server.</span>
00138 <a name="l00119"></a>00119 <span class="comment">// -----------------------------------------------------------------------------</span>
00139 <a name="l00120"></a>00120 <span class="comment">//</span>
00140 <a name="l00121"></a><a class="code" href="class_c_time_server.html#982e65810ad50ce20759fd26fad488dc">00121</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#982e65810ad50ce20759fd26fad488dc">CTimeServer::DecrementSessions</a>()
00141 <a name="l00122"></a>00122     {
00142 <a name="l00123"></a>00123     <a class="code" href="class_c_time_server.html#40ac9219e4400c125719d767d564fc3e">iSessionCount</a>--;
00143 <a name="l00124"></a>00124     <span class="keywordflow">if</span> ( <a class="code" href="class_c_time_server.html#40ac9219e4400c125719d767d564fc3e">iSessionCount</a> &lt;= 0 )
00144 <a name="l00125"></a>00125         {
00145 <a name="l00126"></a>00126         CActiveScheduler::Stop();
00146 <a name="l00127"></a>00127         }
00147 <a name="l00128"></a>00128     }
00148 <a name="l00129"></a>00129 
00149 <a name="l00130"></a>00130 <span class="comment">// -----------------------------------------------------------------------------</span>
00150 <a name="l00131"></a>00131 <span class="comment">// CTimeServer::RunError()</span>
00151 <a name="l00132"></a>00132 <span class="comment">// Processes any errors.</span>
00152 <a name="l00133"></a>00133 <span class="comment">// -----------------------------------------------------------------------------</span>
00153 <a name="l00134"></a>00134 <span class="comment">//</span>
00154 <a name="l00135"></a><a class="code" href="class_c_time_server.html#0f788de08f5d216c674e6eaeaea1c67a">00135</a> TInt <a class="code" href="class_c_time_server.html#0f788de08f5d216c674e6eaeaea1c67a">CTimeServer::RunError</a>( TInt aError )
00155 <a name="l00136"></a>00136     {
00156 <a name="l00137"></a>00137     <span class="keywordflow">if</span> ( aError == KErrBadDescriptor )
00157 <a name="l00138"></a>00138         {
00158 <a name="l00139"></a>00139         <span class="comment">// A bad descriptor error implies a badly programmed client,</span>
00159 <a name="l00140"></a>00140         <span class="comment">// so panic it; otherwise report the error to the client</span>
00160 <a name="l00141"></a>00141         <a class="code" href="class_c_time_server.html#5486029c4d68e3db4b0cbbbd2c4c711e">PanicClient</a>( Message(), EBadDescriptor );
00161 <a name="l00142"></a>00142         }
00162 <a name="l00143"></a>00143     <span class="keywordflow">else</span>
00163 <a name="l00144"></a>00144         {
00164 <a name="l00145"></a>00145         Message().Complete( aError );
00165 <a name="l00146"></a>00146         }
00166 <a name="l00147"></a>00147 
00167 <a name="l00148"></a>00148     <span class="comment">// The leave will result in an early return from CServer::RunL(), skipping</span>
00168 <a name="l00149"></a>00149     <span class="comment">// the call to request another message. So do that now in order to keep the</span>
00169 <a name="l00150"></a>00150     <span class="comment">// server running.</span>
00170 <a name="l00151"></a>00151     ReStart();
00171 <a name="l00152"></a>00152 
00172 <a name="l00153"></a>00153     <span class="keywordflow">return</span> KErrNone;    <span class="comment">// Handled the error fully</span>
00173 <a name="l00154"></a>00154     }
00174 <a name="l00155"></a>00155 
00175 <a name="l00156"></a>00156 <span class="comment">// -----------------------------------------------------------------------------</span>
00176 <a name="l00157"></a>00157 <span class="comment">// CTimeServer::PanicClient()</span>
00177 <a name="l00158"></a>00158 <span class="comment">// Panics the client.</span>
00178 <a name="l00159"></a>00159 <span class="comment">// -----------------------------------------------------------------------------</span>
00179 <a name="l00160"></a>00160 <span class="comment">//</span>
00180 <a name="l00161"></a><a class="code" href="class_c_time_server.html#5486029c4d68e3db4b0cbbbd2c4c711e">00161</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#5486029c4d68e3db4b0cbbbd2c4c711e">CTimeServer::PanicClient</a>( <span class="keyword">const</span> RMessage2&amp; aMessage, TTimeServPanic aPanic )
00181 <a name="l00162"></a>00162     {
00182 <a name="l00163"></a>00163     aMessage.Panic( KCSAsyncServer, aPanic );
00183 <a name="l00164"></a>00164     }
00184 <a name="l00165"></a>00165 
00185 <a name="l00166"></a>00166 <span class="comment">// -----------------------------------------------------------------------------</span>
00186 <a name="l00167"></a>00167 <span class="comment">// CTimeServer::PanicServer()</span>
00187 <a name="l00168"></a>00168 <span class="comment">// Panics the server.</span>
00188 <a name="l00169"></a>00169 <span class="comment">// -----------------------------------------------------------------------------</span>
00189 <a name="l00170"></a>00170 <span class="comment">//</span>
00190 <a name="l00171"></a><a class="code" href="class_c_time_server.html#57317bfd7bbf407064d8f0b845a16d46">00171</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#57317bfd7bbf407064d8f0b845a16d46">CTimeServer::PanicServer</a>( TTimeServPanic aPanic )
00191 <a name="l00172"></a>00172     {
00192 <a name="l00173"></a>00173     User::Panic( KCSAsyncServer, aPanic );
00193 <a name="l00174"></a>00174     }
00194 <a name="l00175"></a>00175 
00195 <a name="l00176"></a>00176 <span class="comment">// -----------------------------------------------------------------------------</span>
00196 <a name="l00177"></a>00177 <span class="comment">// CTimeServer::WaitForTickL()</span>
00197 <a name="l00178"></a>00178 <span class="comment">// Activates the heartbeat.</span>
00198 <a name="l00179"></a>00179 <span class="comment">// -----------------------------------------------------------------------------</span>
00199 <a name="l00180"></a>00180 <span class="comment">//</span>
00200 <a name="l00181"></a><a class="code" href="class_c_time_server.html#a8205372b5d379fa4b803e98b0726473">00181</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#a8205372b5d379fa4b803e98b0726473">CTimeServer::WaitForTickL</a>()
00201 <a name="l00182"></a>00182     {
00202 <a name="l00183"></a>00183     <span class="keywordflow">if</span> ( !<a class="code" href="class_c_time_server.html#bd20aae428bf045cb28f7958102a14e1">iHeartbeat</a> )
00203 <a name="l00184"></a>00184         {
00204 <a name="l00185"></a>00185         <a class="code" href="class_c_time_server.html#bd20aae428bf045cb28f7958102a14e1">iHeartbeat</a> = CHeartbeat::NewL( EPriorityHigh );
00205 <a name="l00186"></a>00186         <a class="code" href="class_c_time_server.html#bd20aae428bf045cb28f7958102a14e1">iHeartbeat</a>-&gt;Start( ETwelveOClock, <span class="keyword">this</span> );
00206 <a name="l00187"></a>00187         }
00207 <a name="l00188"></a>00188     }
00208 <a name="l00189"></a>00189 
00209 <a name="l00190"></a>00190 <span class="comment">// -----------------------------------------------------------------------------</span>
00210 <a name="l00191"></a>00191 <span class="comment">// CTimeServer::Beat()</span>
00211 <a name="l00192"></a>00192 <span class="comment">// A clock tick has occured.</span>
00212 <a name="l00193"></a>00193 <span class="comment">// -----------------------------------------------------------------------------</span>
00213 <a name="l00194"></a>00194 <span class="comment">//</span>
00214 <a name="l00195"></a><a class="code" href="class_c_time_server.html#8bc39d8613772fe04fa5d6a845ede8cd">00195</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#8bc39d8613772fe04fa5d6a845ede8cd">CTimeServer::Beat</a>()
00215 <a name="l00196"></a>00196     {
00216 <a name="l00197"></a>00197     <a class="code" href="class_c_time_server.html#993249bd000d59f1d0437eea0ab25fc3">SendTimeToSessions</a>();
00217 <a name="l00198"></a>00198     }
00218 <a name="l00199"></a>00199 
00219 <a name="l00200"></a>00200 <span class="comment">// -----------------------------------------------------------------------------</span>
00220 <a name="l00201"></a>00201 <span class="comment">// CTimeServer::Synchronize()</span>
00221 <a name="l00202"></a>00202 <span class="comment">// Several clock ticks have occured.</span>
00222 <a name="l00203"></a>00203 <span class="comment">// -----------------------------------------------------------------------------</span>
00223 <a name="l00204"></a>00204 <span class="comment">//</span>
00224 <a name="l00205"></a><a class="code" href="class_c_time_server.html#a6043d9cad7048bb64b0d0d125ddc875">00205</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#a6043d9cad7048bb64b0d0d125ddc875">CTimeServer::Synchronize</a>()
00225 <a name="l00206"></a>00206     {
00226 <a name="l00207"></a>00207     <a class="code" href="class_c_time_server.html#993249bd000d59f1d0437eea0ab25fc3">SendTimeToSessions</a>();
00227 <a name="l00208"></a>00208     }
00228 <a name="l00209"></a>00209 
00229 <a name="l00210"></a>00210 <span class="comment">// -----------------------------------------------------------------------------</span>
00230 <a name="l00211"></a>00211 <span class="comment">// CTimeServer::SendTimeToSessions()</span>
00231 <a name="l00212"></a>00212 <span class="comment">// Informs all the clients that a time change has occured.</span>
00232 <a name="l00213"></a>00213 <span class="comment">// -----------------------------------------------------------------------------</span>
00233 <a name="l00214"></a>00214 <span class="comment">//</span>
00234 <a name="l00215"></a><a class="code" href="class_c_time_server.html#993249bd000d59f1d0437eea0ab25fc3">00215</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#993249bd000d59f1d0437eea0ab25fc3">CTimeServer::SendTimeToSessions</a>()
00235 <a name="l00216"></a>00216     {
00236 <a name="l00217"></a>00217     iSessionIter.SetToFirst();
00237 <a name="l00218"></a>00218     <a class="code" href="class_c_time_server_session.html">CTimeServerSession</a>* session;
00238 <a name="l00219"></a>00219     session = reinterpret_cast&lt;CTimeServerSession*&gt;( iSessionIter++ );
00239 <a name="l00220"></a>00220     <span class="keywordflow">while</span> ( session )
00240 <a name="l00221"></a>00221         {
00241 <a name="l00222"></a>00222         session-&gt;<a class="code" href="class_c_time_server_session.html#ecff8e289d914777ae0c503db937cf33">SendTimeToClient</a>();
00242 <a name="l00223"></a>00223         session = reinterpret_cast&lt;CTimeServerSession*&gt;( iSessionIter++ );
00243 <a name="l00224"></a>00224         }
00244 <a name="l00225"></a>00225     }
00245 <a name="l00226"></a>00226 
00246 <a name="l00227"></a>00227 <span class="comment">// -----------------------------------------------------------------------------</span>
00247 <a name="l00228"></a>00228 <span class="comment">// CTimeServer::ThreadFunctionL()</span>
00248 <a name="l00229"></a>00229 <span class="comment">// Second stage startup for the server thread.</span>
00249 <a name="l00230"></a>00230 <span class="comment">// -----------------------------------------------------------------------------</span>
00250 <a name="l00231"></a>00231 <span class="comment">//</span>
00251 <a name="l00232"></a><a class="code" href="class_c_time_server.html#be5e4a4628587739b7c76951f9577e8e">00232</a> <span class="keywordtype">void</span> <a class="code" href="class_c_time_server.html#be5e4a4628587739b7c76951f9577e8e">CTimeServer::ThreadFunctionL</a>()
00252 <a name="l00233"></a>00233     {
00253 <a name="l00234"></a>00234     <span class="comment">// Construct active scheduler</span>
00254 <a name="l00235"></a>00235     CActiveScheduler* activeScheduler = <span class="keyword">new</span> ( ELeave ) CActiveScheduler;
00255 <a name="l00236"></a>00236     CleanupStack::PushL( activeScheduler );
00256 <a name="l00237"></a>00237 
00257 <a name="l00238"></a>00238     <span class="comment">// Install active scheduler</span>
00258 <a name="l00239"></a>00239     <span class="comment">// We don't need to check whether an active scheduler is already installed</span>
00259 <a name="l00240"></a>00240     <span class="comment">// as this is a new thread, so there won't be one</span>
00260 <a name="l00241"></a>00241     CActiveScheduler::Install( activeScheduler );
00261 <a name="l00242"></a>00242 
00262 <a name="l00243"></a>00243     <span class="comment">// Construct our server</span>
00263 <a name="l00244"></a>00244     <a class="code" href="class_c_time_server.html#94389c6729b439332fc74a54ac683740">CTimeServer::NewLC</a>();    <span class="comment">// Anonymous</span>
00264 <a name="l00245"></a>00245 
00265 <a name="l00246"></a>00246     RSemaphore semaphore;
00266 <a name="l00247"></a>00247     User::LeaveIfError( semaphore.OpenGlobal( KTimeServerSemaphoreName ) );
00267 <a name="l00248"></a>00248 
00268 <a name="l00249"></a>00249     <span class="comment">// Semaphore opened ok</span>
00269 <a name="l00250"></a>00250     semaphore.Signal();
00270 <a name="l00251"></a>00251     semaphore.Close();
00271 <a name="l00252"></a>00252 
00272 <a name="l00253"></a>00253     <span class="comment">// Start handling requests</span>
00273 <a name="l00254"></a>00254     CActiveScheduler::Start();
00274 <a name="l00255"></a>00255 
00275 <a name="l00256"></a>00256     CleanupStack::PopAndDestroy( 2, activeScheduler ); <span class="comment">//Anonymous CTimeServer</span>
00276 <a name="l00257"></a>00257     }
00277 <a name="l00258"></a>00258 
00278 <a name="l00259"></a>00259 <span class="comment">// -----------------------------------------------------------------------------</span>
00279 <a name="l00260"></a>00260 <span class="comment">// CTimeServer::ThreadFunction()</span>
00280 <a name="l00261"></a>00261 <span class="comment">// Main function for the server thread.</span>
00281 <a name="l00262"></a>00262 <span class="comment">// -----------------------------------------------------------------------------</span>
00282 <a name="l00263"></a>00263 <span class="comment">//</span>
00283 <a name="l00264"></a><a class="code" href="class_c_time_server.html#61b4b595801bf9fedbb0df14ed44332c">00264</a> TInt <a class="code" href="class_c_time_server.html#61b4b595801bf9fedbb0df14ed44332c">CTimeServer::ThreadFunction</a>( TAny* <span class="comment">/*aNone*/</span> )
00284 <a name="l00265"></a>00265     {
00285 <a name="l00266"></a>00266     CTrapCleanup* cleanupStack = CTrapCleanup::New();
00286 <a name="l00267"></a>00267     <span class="keywordflow">if</span> ( !( cleanupStack ) )
00287 <a name="l00268"></a>00268         {
00288 <a name="l00269"></a>00269         <a class="code" href="class_c_time_server.html#57317bfd7bbf407064d8f0b845a16d46">PanicServer</a>( ECreateTrapCleanup );
00289 <a name="l00270"></a>00270         }
00290 <a name="l00271"></a>00271 
00291 <a name="l00272"></a>00272     TRAPD( err, <a class="code" href="class_c_time_server.html#be5e4a4628587739b7c76951f9577e8e">ThreadFunctionL</a>() );
00292 <a name="l00273"></a>00273     <span class="keywordflow">if</span> ( err != KErrNone )
00293 <a name="l00274"></a>00274         {
00294 <a name="l00275"></a>00275         <a class="code" href="class_c_time_server.html#57317bfd7bbf407064d8f0b845a16d46">PanicServer</a>( ESrvCreateServer );
00295 <a name="l00276"></a>00276         }
00296 <a name="l00277"></a>00277 
00297 <a name="l00278"></a>00278     <span class="keyword">delete</span> cleanupStack;
00298 <a name="l00279"></a>00279     cleanupStack = NULL;
00299 <a name="l00280"></a>00280 
00300 <a name="l00281"></a>00281     <span class="keywordflow">return</span> KErrNone;
00301 <a name="l00282"></a>00282     }
00302 <a name="l00283"></a>00283 
00303 <a name="l00284"></a>00284 
00304 <a name="l00285"></a>00285 <span class="comment">// -----------------------------------------------------------------------------</span>
00305 <a name="l00286"></a>00286 <span class="comment">// E32Main()</span>
00306 <a name="l00287"></a>00287 <span class="comment">// Provides the API for the operating system to start the executable.</span>
00307 <a name="l00288"></a>00288 <span class="comment">// Returns the address of the function to be called.</span>
00308 <a name="l00289"></a>00289 <span class="comment">// -----------------------------------------------------------------------------</span>
00309 <a name="l00290"></a>00290 <span class="comment">//</span>
00310 <a name="l00291"></a>00291 TInt E32Main()
00311 <a name="l00292"></a>00292     {
00312 <a name="l00293"></a>00293     <span class="keywordflow">return</span> <a class="code" href="class_c_time_server.html#61b4b595801bf9fedbb0df14ed44332c">CTimeServer::ThreadFunction</a>( NULL );
00313 <a name="l00294"></a>00294     }
00314 <a name="l00295"></a>00295 
00315 <a name="l00296"></a>00296 
00316 <a name="l00297"></a>00297 
00317 <a name="l00298"></a>00298 <span class="comment">// End of File</span>
00318 </pre></div><hr>
00319 
00320 <table x-use-null-cells
00321                 style="x-cell-content-align: top;
00322                                 width: 100%;
00323                                 border-spacing: 0px;
00324                                 border-spacing: 0px;"
00325                 cellspacing=0
00326                 width=100%>
00327   <col style="width: 50%;">
00328   <col style="width: 50%;">
00329 
00330   <tr style="x-cell-content-align: top;"
00331         valign=top>
00332   <td style="width: 50%;
00333                         padding-right: 10px;
00334                         padding-left: 10px;
00335                         border-right-style: None;
00336                         border-left-style: None;
00337                         border-top-style: None;
00338                         border-bottom-style: None;"
00339         width=50%>
00340   <p style="font-family: Arial;"><small style="font-size: smaller;">© Nokia 2009</small></td>
00341   <td style="width: 50%;
00342                         padding-right: 10px;
00343                         padding-left: 10px;
00344                         border-top-style: None;
00345                         border-bottom-style: None;
00346                         border-right-style: None;"
00347         width=50%>
00348   <p style="text-align: right; margin-right: -4px;"
00349         align=right><span style="font-weight: bold;"><a href="#Top"
00350                                                                                                         title="Back to top"><img
00351  src="top.gif"
00352         x-maintain-ratio=TRUE
00353         alt="Back to top"
00354         style="border: none;
00355                         width: 18px;
00356                         height: 15px;
00357                         float: none;
00358                         border-style: none;
00359                         border-style: none;"
00360         width=18
00361         height=15
00362         border=0></a></span></td></tr>
00363  </table>
00364 </body>
00365 </html>
00366 

Generated by  doxygen 1.6.2