Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_client_server_async_2doc_2index_8html_source.html
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 6 43e37759235e
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/S60CppExamples/ClientServerAsync/doc/index.html Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<h1>examples/S60CppExamples/ClientServerAsync/doc/index.html</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;!DOCTYPE HTML PUBLIC <span class="stringliteral">&quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;</span>&gt;
<a name="l00002"></a>00002 &lt;html&gt;
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 &lt;head&gt;
<a name="l00005"></a>00005 &lt;meta http-equiv=<span class="stringliteral">&quot;Content-Type&quot;</span> content=<span class="stringliteral">&quot;text/html;charset=iso-8859-1&quot;</span>&gt;
<a name="l00006"></a>00006 &lt;title&gt;Asynchronous Client/Server Example&lt;/title&gt;
<a name="l00007"></a>00007 &lt;link href=<span class="stringliteral">&quot;style.css&quot;</span> rel=<span class="stringliteral">&quot;stylesheet&quot;</span> type=<span class="stringliteral">&quot;text/css&quot;</span>&gt;
<a name="l00008"></a>00008 &lt;/head&gt;
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 &lt;table border=<span class="stringliteral">&quot;0&quot;</span> width=<span class="stringliteral">&quot;100%&quot;</span> height=<span class="stringliteral">&quot;8&quot;</span> bgcolor=<span class="stringliteral">&quot;#eeeeee&quot;</span>&gt;
<a name="l00011"></a>00011 &lt;tr&gt; &lt;td width=<span class="stringliteral">&quot;100%&quot;</span> height=<span class="stringliteral">&quot;1&quot;</span>&gt;&lt;b&gt;&lt;font size=<span class="stringliteral">&quot;2&quot;</span> color=<span class="stringliteral">&quot;#000000&quot;</span> face=<span class="stringliteral">&quot;Arial, Helvetica, sans-serif&quot;</span>&gt;&lt;strong&gt;&lt;a name=Top&gt;&lt;/a&gt;
<a name="l00012"></a>00012 S60 5th Edition SDK &lt;/strong&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;i&gt;Example Applications Guide&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;
<a name="l00013"></a>00013 &lt;!-- Generated by Doxygen 1.4.5 --&gt;
<a name="l00014"></a>00014 &lt;div <span class="keyword">class</span>=<span class="stringliteral">&quot;tabs&quot;</span>&gt;
<a name="l00015"></a>00015   &lt;ul&gt;
<a name="l00016"></a>00016     &lt;li <span class="keywordtype">id</span>=<span class="stringliteral">&quot;current&quot;</span>&gt;&lt;a href=<span class="stringliteral">&quot;index.html&quot;</span>&gt;&lt;span&gt;Main&amp;nbsp;Page&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00017"></a>00017     &lt;li&gt;&lt;a href=<span class="stringliteral">&quot;annotated.html&quot;</span>&gt;&lt;span&gt;Classes&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00018"></a>00018     &lt;li&gt;&lt;a href=<span class="stringliteral">&quot;files.html&quot;</span>&gt;&lt;span&gt;Files&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00019"></a>00019   &lt;/ul&gt;&lt;/div&gt;
<a name="l00020"></a>00020 &lt;h1&gt;Asynchronous Client/Server Example&lt;/h1&gt;
<a name="l00021"></a>00021 &lt;p&gt;
<a name="l00022"></a>00022 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Intro_sec&quot;</span>&gt;1. About <span class="keyword">this</span> Example&lt;/a&gt; &lt;br&gt;
<a name="l00023"></a>00023 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Arch_sec&quot;</span>&gt;2. Architecture&lt;/a&gt; &lt;br&gt;
<a name="l00024"></a>00024 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Design_sec&quot;</span>&gt;3. Design and Implementation&lt;/a&gt;&lt;p&gt;
<a name="l00025"></a>00025 &lt;hr&gt;
<a name="l00026"></a>00026 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Intro_sec&quot;</span>&gt;
<a name="l00027"></a>00027 1. About <span class="keyword">this</span> Example&lt;/a&gt;&lt;/h2&gt;
<a name="l00028"></a>00028 This example demonstrates the architecture of a simple client server application utilising asynchronous calls to the server. The server supplies the current time to its clients.&lt;p&gt;
<a name="l00029"></a>00029 &lt;hr&gt;
<a name="l00030"></a>00030 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub11&quot;</span>&gt;
<a name="l00031"></a>00031 1.1 APIs demonstrated&lt;/a&gt;&lt;/h3&gt;
<a name="l00032"></a>00032 &lt;ul&gt;
<a name="l00033"></a>00033 &lt;li&gt;CActive&lt;/li&gt;&lt;li&gt;CServer2&lt;/li&gt;&lt;li&gt;CSession2&lt;/li&gt;&lt;li&gt;RMessagePtr2&lt;/li&gt;&lt;li&gt;RMessage2&lt;/li&gt;&lt;li&gt;RSessionBase&lt;/li&gt;&lt;/ul&gt;
<a name="l00034"></a>00034 &lt;p&gt;
<a name="l00035"></a>00035 &lt;hr&gt;
<a name="l00036"></a>00036 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub12&quot;</span>&gt;
<a name="l00037"></a>00037 1.2 Prerequisites&lt;/a&gt;&lt;/h3&gt;
<a name="l00038"></a>00038 This example makes use of the standard Symbian OS application framework, comprising the Application, Document, UI, and View classes. The reader should be aware of <span class="keyword">this</span> architecture before attempting to understand <span class="keyword">this</span> example. The example makes use of several other Symbian OS concepts which the reader should be aware of before attempting to understand <span class="keyword">this</span> example. These are:&lt;p&gt;
<a name="l00039"></a>00039 &lt;ul&gt;
<a name="l00040"></a>00040 &lt;li&gt;Asynchronous programming, in particular the following topics:&lt;ul&gt;
<a name="l00041"></a>00041 &lt;li&gt;Inter-process communication overview.&lt;/li&gt;&lt;li&gt;Client/server overview.&lt;/li&gt;&lt;li&gt;Using client/server.&lt;/li&gt;&lt;li&gt;CActive&lt;/li&gt;&lt;/ul&gt;
<a name="l00042"></a>00042 &lt;/li&gt;&lt;/ul&gt;
<a name="l00043"></a>00043 &lt;p&gt;
<a name="l00044"></a>00044 &lt;ul&gt;
<a name="l00045"></a>00045 &lt;li&gt;Thread and process management, in particular the following topics:&lt;ul&gt;
<a name="l00046"></a>00046 &lt;li&gt;Thread and process management overview.&lt;/li&gt;&lt;li&gt;Semaphores overview.&lt;/li&gt;&lt;li&gt;Threads and processes overview.&lt;/li&gt;&lt;li&gt;Using semaphores.&lt;/li&gt;&lt;/ul&gt;
<a name="l00047"></a>00047 &lt;/li&gt;&lt;/ul&gt;
<a name="l00048"></a>00048 &lt;p&gt;
<a name="l00049"></a>00049 &lt;hr&gt;
<a name="l00050"></a>00050 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub13&quot;</span>&gt;
<a name="l00051"></a>00051 1.3 Running <span class="keyword">this</span> example&lt;/a&gt;&lt;/h3&gt;
<a name="l00052"></a>00052 The application initially presents a <span class="keywordflow">default</span> time to the user, as shown in the following screenshot.&lt;p&gt;
<a name="l00053"></a>00053 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00054"></a>00054 &lt;img src=<span class="stringliteral">&quot;initial_screen.png&quot;</span> alt=<span class="stringliteral">&quot;initial_screen.png&quot;</span>&gt;
<a name="l00055"></a>00055 &lt;/div&gt;
<a name="l00056"></a>00056 &lt;p&gt;
<a name="l00057"></a>00057 The Options menu presents the following choices:&lt;p&gt;
<a name="l00058"></a>00058 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00059"></a>00059 &lt;img src=<span class="stringliteral">&quot;options_menu.png&quot;</span> alt=<span class="stringliteral">&quot;options_menu.png&quot;</span>&gt;
<a name="l00060"></a>00060 &lt;/div&gt;
<a name="l00061"></a>00061 &lt;p&gt;
<a name="l00062"></a>00062 &lt;ul&gt;
<a name="l00063"></a>00063 &lt;li&gt;Select &lt;b&gt;Start Clock&lt;/b&gt; to start updating the displayed time.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Exit&lt;/b&gt; at any time, to exit the application.&lt;/li&gt;&lt;/ul&gt;
<a name="l00064"></a>00064 &lt;p&gt;
<a name="l00065"></a>00065 On selecting &lt;b&gt;Start Clock&lt;/b&gt;, the display will be updated periodically with the current time. While the clock is running, the Options menu presents the following choices:&lt;p&gt;
<a name="l00066"></a>00066 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00067"></a>00067 &lt;img src=<span class="stringliteral">&quot;options_menu_running.png&quot;</span> alt=<span class="stringliteral">&quot;options_menu_running.png&quot;</span>&gt;
<a name="l00068"></a>00068 &lt;/div&gt;
<a name="l00069"></a>00069 &lt;p&gt;
<a name="l00070"></a>00070 &lt;ul&gt;
<a name="l00071"></a>00071 &lt;li&gt;Select &lt;b&gt;Stop Clock&lt;/b&gt; to stop updating the displayed time.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Exit&lt;/b&gt; at any time, to exit the application.&lt;/li&gt;&lt;/ul&gt;
<a name="l00072"></a>00072 &lt;p&gt;
<a name="l00073"></a>00073 &lt;hr&gt;
<a name="l00074"></a>00074 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Arch_sec&quot;</span>&gt;
<a name="l00075"></a>00075 2. Architecture&lt;/a&gt;&lt;/h2&gt;
<a name="l00076"></a>00076 This example exists as a complete application and has the standard Symbian OS application architecture employing the Application, Document, UI, and View classes. The reader should be familiar with <span class="keyword">this</span> architecture before proceeding.&lt;p&gt;
<a name="l00077"></a>00077 &lt;hr&gt;
<a name="l00078"></a>00078 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Design_sec&quot;</span>&gt;
<a name="l00079"></a>00079 3. Design and Implementation&lt;/a&gt;&lt;/h2&gt;
<a name="l00080"></a>00080 The following component diagram illustrates the split of classes over the client and server components, and their inter-relationships.&lt;p&gt;
<a name="l00081"></a>00081 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00082"></a>00082 &lt;img src=<span class="stringliteral">&quot;component.jpg&quot;</span> alt=<span class="stringliteral">&quot;component.jpg&quot;</span>&gt;
<a name="l00083"></a>00083 &lt;/div&gt;
<a name="l00084"></a>00084 &lt;p&gt;
<a name="l00085"></a>00085 The client is a standard Symbian OS application, utilising an RSessionBase-derived <span class="keywordtype">object</span> to communicate with the server. The server is implemented as an EXE.&lt;p&gt;
<a name="l00086"></a>00086 In the following description, an overview of <span class="keyword">this</span> example<span class="stringliteral">&#39;s design is presented in the Design overview section. This is followed by a description of three use case scenarios, where the user:&lt;p&gt;</span>
<a name="l00087"></a>00087 <span class="stringliteral">&lt;ul&gt;</span>
<a name="l00088"></a>00088 <span class="stringliteral">&lt;li&gt;Invokes the application - here, the application establishes communication with the server, creating the server if necessary. This is achieved using the &lt;a class=&quot;el&quot; href=&quot;class_r_time_server_session.html&quot;&gt;RTimeServerSession&lt;/a&gt; class, and is described in the Creating a session section.&lt;/li&gt;&lt;li&gt;Makes a server request - the application uses the established session to request data from the server. This is described in the Making a server request section.&lt;/li&gt;&lt;li&gt;Cancels a server request - the user cancels an outstanding request. This is described in the Canceling a server request section.&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00089"></a>00089 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00090"></a>00090 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00091"></a>00091 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub31&quot;&gt;</span>
<a name="l00092"></a>00092 <span class="stringliteral">3.1 Design overview&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00093"></a>00093 <span class="stringliteral">The Symbian OS client/server architecture uses four key concepts: server (CServer2), session (CSession2 and RSessionBase), sub-session (RSubSessionBase), and message (RMessage2, and RMessagePtr2).&lt;p&gt;</span>
<a name="l00094"></a>00094 <span class="stringliteral">Servers derive from CServer2, and are responsible for handling any requests from clients to establish connections.&lt;p&gt;</span>
<a name="l00095"></a>00095 <span class="stringliteral">The session represents the channel of communication between client and server. Clients use a derivation of RSessionBase, and servers use a derivation from CSession2.&lt;p&gt;</span>
<a name="l00096"></a>00096 <span class="stringliteral">The following class diagram shows the server-session associations for this example.&lt;p&gt;</span>
<a name="l00097"></a>00097 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00098"></a>00098 <span class="stringliteral">&lt;img src=&quot;classes.png&quot; alt=&quot;classes.png&quot;&gt;</span>
<a name="l00099"></a>00099 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00100"></a>00100 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00101"></a>00101 <span class="stringliteral">A client can create multiple sessions with a server. However, it is more resource-efficient to use sub-sessions. This feature is not employed in this example, for simplicity.&lt;p&gt;</span>
<a name="l00102"></a>00102 <span class="stringliteral">The RMessage2 class is the data structure passed between client and server. The client does not manipulate this directly, as it is encapsulated in the client-side interface. Server side sessions read from, and write to, this structure to receive and send data.&lt;p&gt;</span>
<a name="l00103"></a>00103 <span class="stringliteral">To handle asynchronous services, the client requires the use of an active object. In this case, the active object is an instance of the &lt;a class=&quot;el&quot; href=&quot;class_c_c_s_async_request_handler.html&quot;&gt;CCSAsyncRequestHandler&lt;/a&gt; class. This is responsible for managing the asynchronous nature of this example. It issues requests (through the &lt;a class=&quot;el&quot; href=&quot;class_r_time_server_session.html&quot;&gt;RTimeServerSession&lt;/a&gt; class) for asynchronous services, and receives notification of completion through its RunL method. It uses an observer, &lt;a class=&quot;el&quot; href=&quot;class_m_async_time_observer.html&quot;&gt;MAsyncTimeObserver&lt;/a&gt;, to report the completion of requests to interested parties.&lt;p&gt;</span>
<a name="l00104"></a>00104 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00105"></a>00105 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub32&quot;&gt;</span>
<a name="l00106"></a>00106 <span class="stringliteral">3.2 Creating a session&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00107"></a>00107 <span class="stringliteral">The sequence involved in creating a session is very similar to that described in the Synchronous Client/Server Example, and hence is not described in this document. The only differences in this case are that the session is created by the &lt;a class=&quot;el&quot; href=&quot;class_c_c_s_async_request_handler.html&quot;&gt;CCSAsyncRequestHandler&lt;/a&gt; class, and the number of asynchronous message slots specified in the RSessionBase::Connect call is no longer zero.&lt;p&gt;</span>
<a name="l00108"></a>00108 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00109"></a>00109 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub33&quot;&gt;</span>
<a name="l00110"></a>00110 <span class="stringliteral">3.3 Making a server request&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00111"></a>00111 <span class="stringliteral">The RMessage2 and RMessagePtr2 classes are used to transfer information between the client and the server. These classes have several useful methods:&lt;p&gt;</span>
<a name="l00112"></a>00112 <span class="stringliteral">&lt;ul&gt;</span>
<a name="l00113"></a>00113 <span class="stringliteral">&lt;li&gt;RMessage2 allows client to specify the required server operation.&lt;/li&gt;&lt;li&gt;RMessage2 allows four 32-bit words of information to be passed back and forth between the client and server.&lt;/li&gt;&lt;li&gt;RMessagePtr2 allows the server to signal when a client&#39;</span>s request has completed, <span class="keyword">using</span> the Complete method.&lt;/li&gt;&lt;li&gt;RMessagePtr2 allows the server to panic its client.&lt;/li&gt;&lt;/ul&gt;
<a name="l00114"></a>00114 &lt;p&gt;
<a name="l00115"></a>00115 An instance of an RMessage2 <span class="keywordtype">object</span> is automatically created <span class="keywordflow">for</span> the session when the client calls one of the RSessionBase::SendReceive or RSessionBase::Send methods. These methods can take a parameter that is a reference to TIpcArgs object, which can have up to four 32-bit arguments.&lt;p&gt;
<a name="l00116"></a>00116 The sequence involved in making an asynchronous server request is shown below.&lt;p&gt;
<a name="l00117"></a>00117 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00118"></a>00118 &lt;img src=<span class="stringliteral">&quot;requesttime.jpg&quot;</span> alt=<span class="stringliteral">&quot;requesttime.jpg&quot;</span>&gt;
<a name="l00119"></a>00119 &lt;/div&gt;
<a name="l00120"></a>00120 &lt;p&gt;
<a name="l00121"></a>00121 &lt;ol type=1&gt;
<a name="l00122"></a>00122 &lt;li&gt;RequestTime is called in response to the user selecting Start Clock. This calls &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_c_s_async_request_handler.html#481d63e2f4e33b9cb8ed4680a965da25&quot;</span>&gt;<a class="code" href="class_c_c_s_async_request_handler.html#ad34e374499b67c21347c5f87f7911324">CCSAsyncRequestHandler::RequestTime</a>&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;The &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_r_time_server_session.html#0e65b7c45b7af042183f1c5525cfcc1b&quot;</span>&gt;<a class="code" href="class_r_time_server_session.html#a456203c7ad8889a4753222e98173ff00">RTimeServerSession::RequestTime</a>&lt;/a&gt; is called and a TTime reference, and the active <span class="keywordtype">object</span><span class="stringliteral">&#39;s iStatus flag are passed to it.&lt;/li&gt;&lt;li&gt;A descriptor is now created, representing the supplied TTime object. This descriptor&#39;</span>s address is entered into the TIpcArgs object, which is passed to the inherited SendReceive method. SendReceive is an asynchronous method, and returns immediately.&lt;/li&gt;&lt;li&gt;The SetActive method is called, to indicate that the active <span class="keywordtype">object</span> has issued a request that is now outstanding. &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_c_s_async_request_handler.html#98dcd20e4dd117488a6a90dadd4dfac5&quot;</span>&gt;<a class="code" href="class_c_c_s_async_request_handler.html#a68039f23cd042511b6911beeec532a0f">CCSAsyncRequestHandler::RunL</a>&lt;/a&gt; will be called when the server completes the request.&lt;/li&gt;&lt;/ol&gt;
<a name="l00123"></a>00123 &lt;p&gt;
<a name="l00124"></a>00124 As a result of the call to SendReceive, the framework calls the &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server_session.html#75c0a1442736b57144c9ad541d87d370&quot;</span>&gt;<a class="code" href="class_c_time_server_session.html#a0fd8da10042e0e7c97a74eef7f1fe413">CTimeServerSession::ServiceL</a>&lt;/a&gt; of the associated server-side session, as shown in the following diagram.&lt;p&gt;
<a name="l00125"></a>00125 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00126"></a>00126 &lt;img src=<span class="stringliteral">&quot;servicel.png&quot;</span> alt=<span class="stringliteral">&quot;servicel.png&quot;</span>&gt;
<a name="l00127"></a>00127 &lt;/div&gt;
<a name="l00128"></a>00128 &lt;p&gt;
<a name="l00129"></a>00129 &lt;ol type=1&gt;
<a name="l00130"></a>00130 &lt;li&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server_session.html#75c0a1442736b57144c9ad541d87d370&quot;</span>&gt;<a class="code" href="class_c_time_server_session.html#a0fd8da10042e0e7c97a74eef7f1fe413">CTimeServerSession::ServiceL</a>&lt;/a&gt; is called by the kernel, and passed an RMessage2 encapsulating the client<span class="stringliteral">&#39;s request.&lt;/li&gt;&lt;li&gt;RMessage2::Function is called to determine the request type.&lt;/li&gt;&lt;li&gt;If the request is for a time update, RequestTimeL is called.&lt;/li&gt;&lt;li&gt;The received request (RMessage2) is stored. The session now registers its interest in the server&#39;</span>s time updates by calling &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server.html#a8205372b5d379fa4b803e98b0726473&quot;</span>&gt;<a class="code" href="class_c_time_server.html#a6787f6b173c59446b202ae04177a5d88">CTimeServer::WaitForTickL</a>&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;The server uses an instance of the CHeartbeat <span class="keyword">class </span>to notify sessions of a time update. New instance is created here if the heartbeat is not already created.&lt;/li&gt;&lt;li&gt;The heartbeat is also started, if it was not already created in previous step.&lt;/li&gt;&lt;li&gt;When the next heartbeat occurs, &lt;a class=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server.html#8bc39d8613772fe04fa5d6a845ede8cd&quot;</span>&gt;<a class="code" href="class_c_time_server.html#aaf1149f0fedf24e384705ce734d6d7fe">CTimeServer::Beat</a>&lt;/a&gt; is called.&lt;/li&gt;&lt;li&gt;The Beat function calls SendTimeToSessions, which iterates over all established sessions, calling &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server_session.html#ecff8e289d914777ae0c503db937cf33&quot;</span>&gt;<a class="code" href="class_c_time_server_session.html#a5db282a872864d62b94a2a6a25159d5f">CTimeServerSession::SendTimeToClient</a>&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;SendTimeToClient is called.&lt;/li&gt;&lt;li&gt;SendTimeToClient calculates the current time and creates a <span class="keyword">new</span> descriptor representing it (<span class="keyword">using</span> TPtr8 since it<span class="stringliteral">&#39;s binary data). RMessage2::WriteL is now called, with the created descriptor as parameter. First parameter of the WriteL is zero identifying the argument index value. The descriptor at the client side was the first argument, so server has to write into the first argument (index 0). If server writes to index 1, in this case, WriteL would return error KErrBadDescriptor. The WriteL function call causes the time to be written to the client&#39;</span>s address space.&lt;/li&gt;&lt;li&gt;The server session then signals the client, <span class="keyword">using</span> the RMessage2::Complete method. This causes the client<span class="stringliteral">&#39;s &lt;a class=&quot;el&quot; href=&quot;class_c_c_s_async_request_handler.html#98dcd20e4dd117488a6a90dadd4dfac5&quot;&gt;CCSAsyncRequestHandler::RunL&lt;/a&gt; method to be called, as shown in the following diagram.&lt;/li&gt;&lt;/ol&gt;</span>
<a name="l00131"></a>00131 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00132"></a>00132 <span class="stringliteral">Once the server has completed the request, the active object which initiated the request will be signalled, and its RunL method called, as shown in the following diagram.&lt;p&gt;</span>
<a name="l00133"></a>00133 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00134"></a>00134 <span class="stringliteral">&lt;img src=&quot;runl.jpg&quot; alt=&quot;runl.jpg&quot;&gt;</span>
<a name="l00135"></a>00135 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00136"></a>00136 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00137"></a>00137 <span class="stringliteral">&lt;ol type=1&gt;</span>
<a name="l00138"></a>00138 <span class="stringliteral">&lt;li&gt;The active scheduler calls the RunL method in response to the server completing the request.&lt;/li&gt;&lt;li&gt;The observer is notified and the time is updated to the screen if the status flag indicates successful completion of the request.&lt;/li&gt;&lt;li&gt;A new request is scheduled, to keep the clock &#39;</span>running<span class="stringliteral">&#39;.&lt;/li&gt;&lt;/ol&gt;</span>
<a name="l00139"></a>00139 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00140"></a>00140 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00141"></a>00141 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub34&quot;&gt;</span>
<a name="l00142"></a>00142 <span class="stringliteral">3.4 Canceling a server request&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00143"></a>00143 <span class="stringliteral">When the user selects Stop Clock, the following sequence is entered.&lt;p&gt;</span>
<a name="l00144"></a>00144 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00145"></a>00145 <span class="stringliteral">&lt;img src=&quot;cancel.jpg&quot; alt=&quot;cancel.jpg&quot;&gt;</span>
<a name="l00146"></a>00146 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00147"></a>00147 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00148"></a>00148 <span class="stringliteral">&lt;ol type=1&gt;</span>
<a name="l00149"></a>00149 <span class="stringliteral">&lt;li&gt;CancelRequest is called in response to the user selecting Stop Clock from the Options menu.&lt;/li&gt;&lt;li&gt;To handle cancelled requests, active objects should call CActive::Cancel and also implement a DoCancel method. This will be called as a result of calling CActive::Cancel.&lt;/li&gt;&lt;li&gt;DoCancel is called, which instructs the session to cancel the outstanding request by calling &lt;a class=&quot;el&quot; href=&quot;class_r_time_server_session.html#52a5f2cddd36f215fea9c11e32ab88b8&quot;&gt;RTimeServerSession::CancelRequestTime&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;CancelRequestTime() is called.&lt;/li&gt;&lt;li&gt;The synchronous request is now sent to the server, instructing it to cancel the outstanding request by calling SendReceive. The framework will call the corresponding server-side session&#39;</span>s ServiceL method as shown in the following sequence.&lt;/li&gt;&lt;/ol&gt;
<a name="l00150"></a>00150 &lt;p&gt;
<a name="l00151"></a>00151 As a result of the call to SendReceive, the framework calls the &lt;a class=&quot;el&quot; href=&quot;class_c_time_server_session.html#75c0a1442736b57144c9ad541d87d370&quot;&gt;CTimeServerSession::ServiceL&lt;/a&gt; of the associated server-side session, as shown in the following diagram.&lt;p&gt;
<a name="l00152"></a>00152 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00153"></a>00153 &lt;img src=<span class="stringliteral">&quot;servicel-cancel.png&quot;</span> alt=<span class="stringliteral">&quot;servicel-cancel.png&quot;</span>&gt;
<a name="l00154"></a>00154 &lt;/div&gt;
<a name="l00155"></a>00155 &lt;p&gt;
<a name="l00156"></a>00156 &lt;ol type=1&gt;
<a name="l00157"></a>00157 &lt;li&gt;ServiceL is called by the framework in response to a request from the client.&lt;/li&gt;&lt;li&gt;The requested method is checked by examining the returned <span class="keywordtype">id</span> from RMessage2::Function. In <span class="keyword">this</span> <span class="keywordflow">case</span>, it indicates that the client has requested cancellation of an outstanding request. The servicing of <span class="keyword">this</span> request should complete in as <span class="keywordtype">short</span> a time as possible, since the client waits <span class="keywordflow">for</span> completion.&lt;/li&gt;&lt;li&gt;If a previous request is pending, the server completes it by calling Complete on the stored request<span class="stringliteral">&#39;s associated RMessage2.&lt;/li&gt;&lt;li&gt;The cancellation request is now completed, freeing the client to continue processing.&lt;/li&gt;&lt;/ol&gt;</span>
<a name="l00158"></a>00158 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00159"></a>00159 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00160"></a>00160 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub35&quot;&gt;</span>
<a name="l00161"></a>00161 <span class="stringliteral">3.5 Capabilities&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00162"></a>00162 <span class="stringliteral">The application does not require any capabilities. The program capabilities are defined in both mmp-files as CAPABILITY NONE. &lt;hr&gt;</span>
<a name="l00163"></a>00163 <span class="stringliteral"></span>
<a name="l00164"></a>00164 <span class="stringliteral">&lt;table x-use-null-cells</span>
<a name="l00165"></a>00165 <span class="stringliteral">                style=&quot;x-cell-content-align: top;</span>
<a name="l00166"></a>00166 <span class="stringliteral">                                width: 100%;</span>
<a name="l00167"></a>00167 <span class="stringliteral">                                border-spacing: 0px;</span>
<a name="l00168"></a>00168 <span class="stringliteral">                                border-spacing: 0px;&quot;</span>
<a name="l00169"></a>00169 <span class="stringliteral">                cellspacing=0</span>
<a name="l00170"></a>00170 <span class="stringliteral">                width=100%&gt;</span>
<a name="l00171"></a>00171 <span class="stringliteral">  &lt;col style=&quot;width: 50%;&quot;&gt;</span>
<a name="l00172"></a>00172 <span class="stringliteral">  &lt;col style=&quot;width: 50%;&quot;&gt;</span>
<a name="l00173"></a>00173 <span class="stringliteral"></span>
<a name="l00174"></a>00174 <span class="stringliteral">  &lt;tr style=&quot;x-cell-content-align: top;&quot;</span>
<a name="l00175"></a>00175 <span class="stringliteral">        valign=top&gt;</span>
<a name="l00176"></a>00176 <span class="stringliteral">  &lt;td style=&quot;width: 50%;</span>
<a name="l00177"></a>00177 <span class="stringliteral">                        padding-right: 10px;</span>
<a name="l00178"></a>00178 <span class="stringliteral">                        padding-left: 10px;</span>
<a name="l00179"></a>00179 <span class="stringliteral">                        border-right-style: None;</span>
<a name="l00180"></a>00180 <span class="stringliteral">                        border-left-style: None;</span>
<a name="l00181"></a>00181 <span class="stringliteral">                        border-top-style: None;</span>
<a name="l00182"></a>00182 <span class="stringliteral">                        border-bottom-style: None;&quot;</span>
<a name="l00183"></a>00183 <span class="stringliteral">        width=50%&gt;</span>
<a name="l00184"></a>00184 <span class="stringliteral">  &lt;p style=&quot;font-family: Arial;&quot;&gt;&lt;small style=&quot;font-size: smaller;&quot;&gt;© Nokia 2009&lt;/small&gt;&lt;/td&gt;</span>
<a name="l00185"></a>00185 <span class="stringliteral">  &lt;td style=&quot;width: 50%;</span>
<a name="l00186"></a>00186 <span class="stringliteral">                        padding-right: 10px;</span>
<a name="l00187"></a>00187 <span class="stringliteral">                        padding-left: 10px;</span>
<a name="l00188"></a>00188 <span class="stringliteral">                        border-top-style: None;</span>
<a name="l00189"></a>00189 <span class="stringliteral">                        border-bottom-style: None;</span>
<a name="l00190"></a>00190 <span class="stringliteral">                        border-right-style: None;&quot;</span>
<a name="l00191"></a>00191 <span class="stringliteral">        width=50%&gt;</span>
<a name="l00192"></a>00192 <span class="stringliteral">  &lt;p style=&quot;text-align: right; margin-right: -4px;&quot;</span>
<a name="l00193"></a>00193 <span class="stringliteral">        align=right&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;a href=&quot;#Top&quot;</span>
<a name="l00194"></a>00194 <span class="stringliteral">                                                                                                        title=&quot;Back to top&quot;&gt;&lt;img</span>
<a name="l00195"></a>00195 <span class="stringliteral"> src=&quot;top.gif&quot;</span>
<a name="l00196"></a>00196 <span class="stringliteral">        x-maintain-ratio=TRUE</span>
<a name="l00197"></a>00197 <span class="stringliteral">        alt=&quot;Back to top&quot;</span>
<a name="l00198"></a>00198 <span class="stringliteral">        style=&quot;border: none;</span>
<a name="l00199"></a>00199 <span class="stringliteral">                        width: 18px;</span>
<a name="l00200"></a>00200 <span class="stringliteral">                        height: 15px;</span>
<a name="l00201"></a>00201 <span class="stringliteral">                        float: none;</span>
<a name="l00202"></a>00202 <span class="stringliteral">                        border-style: none;</span>
<a name="l00203"></a>00203 <span class="stringliteral">                        border-style: none;&quot;</span>
<a name="l00204"></a>00204 <span class="stringliteral">        width=18</span>
<a name="l00205"></a>00205 <span class="stringliteral">        height=15</span>
<a name="l00206"></a>00206 <span class="stringliteral">        border=0&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;</span>
<a name="l00207"></a>00207 <span class="stringliteral"> &lt;/table&gt;</span>
<a name="l00208"></a>00208 <span class="stringliteral">&lt;/body&gt;</span>
<a name="l00209"></a>00209 <span class="stringliteral">&lt;/html&gt;</span>
<a name="l00210"></a>00210 <span class="stringliteral"></span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>