Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_client_server_sync_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/ClientServerSync/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/ClientServerSync/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;Synchronous 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;Synchronous 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 synchronous 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;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 exists as a complete application, and has the standard Symbian OS application architecture employing the Application, Document, UI, and View classes. 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;Inter process communication, 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;/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.jpg&quot;</span> alt=<span class="stringliteral">&quot;initial_screen.jpg&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.jpg&quot;</span> alt=<span class="stringliteral">&quot;options_menu.jpg&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;Display Time&lt;/b&gt; to request a time update from the server.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Exit&lt;/b&gt; 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;Display Time&lt;/b&gt;, the display will be updated, to reflect the server supplied time, as shown in the following screenshot.&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;updated_time.jpg&quot;</span> alt=<span class="stringliteral">&quot;updated_time.jpg&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;hr&gt;
<a name="l00071"></a>00071 &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="l00072"></a>00072 2. Architecture&lt;/a&gt;&lt;/h2&gt;
<a name="l00073"></a>00073 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="l00074"></a>00074 &lt;hr&gt;
<a name="l00075"></a>00075 &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="l00076"></a>00076 3. Design and Implementation&lt;/a&gt;&lt;/h2&gt;
<a name="l00077"></a>00077 The following component diagram illustrates the split of classes over the Client and Server components, and their inter-relationships.&lt;p&gt;
<a name="l00078"></a>00078 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00079"></a>00079 &lt;img src=<span class="stringliteral">&quot;client-server_components.jpg&quot;</span> alt=<span class="stringliteral">&quot;client-server_components.jpg&quot;</span>&gt;
<a name="l00080"></a>00080 &lt;/div&gt;
<a name="l00081"></a>00081 &lt;p&gt;
<a name="l00082"></a>00082 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="l00083"></a>00083 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 two use case scenarios, where the user:&lt;ul&gt;</span>
<a name="l00084"></a>00084 <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;/ul&gt;</span>
<a name="l00085"></a>00085 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00086"></a>00086 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00087"></a>00087 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub31&quot;&gt;</span>
<a name="l00088"></a>00088 <span class="stringliteral">3.1 Design overview&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00089"></a>00089 <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="l00090"></a>00090 <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="l00091"></a>00091 <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="l00092"></a>00092 <span class="stringliteral">The following class diagram shows the server-session associations for this example.&lt;p&gt;</span>
<a name="l00093"></a>00093 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00094"></a>00094 <span class="stringliteral">&lt;img src=&quot;server-session_classes.png&quot; alt=&quot;server-session_classes.png&quot;&gt;</span>
<a name="l00095"></a>00095 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00096"></a>00096 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00097"></a>00097 <span class="stringliteral">A client can create multiple sessions with a server. It is more resource-efficient to use sub-sessions, but this feature is not employed in this example, for simplicity.&lt;p&gt;</span>
<a name="l00098"></a>00098 <span class="stringliteral">The RMessage2 class is the data structure passed between client and server. The client does not manipulate this directly; they use a TIpcArgs object to package the message information that is to be sent to the server. Server side sessions read from, and write to, this structure to receive and send data.&lt;p&gt;</span>
<a name="l00099"></a>00099 <span class="stringliteral">&lt;hr&gt;</span>
<a name="l00100"></a>00100 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub32&quot;&gt;</span>
<a name="l00101"></a>00101 <span class="stringliteral">3.2 Creating a session&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00102"></a>00102 <span class="stringliteral">To create a session, the client must establish a channel of communication with the server. The following diagram shows the sequence involved.&lt;p&gt;</span>
<a name="l00103"></a>00103 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00104"></a>00104 <span class="stringliteral">&lt;img src=&quot;session_sequence_diagram.png&quot; alt=&quot;session_sequence_diagram.png&quot;&gt;</span>
<a name="l00105"></a>00105 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00106"></a>00106 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00107"></a>00107 <span class="stringliteral">&lt;ol type=1&gt;</span>
<a name="l00108"></a>00108 <span class="stringliteral">&lt;li&gt;Connect is called on construction of the document. This function is responsible for starting the server, if necessary, and establishing communication with the server.&lt;/li&gt;&lt;li&gt;It is necessary to start the server if it is not already running. StartServer accomplishes this, and returns an appropriate error code on completion. This is described further in the Starting the server section.&lt;/li&gt;&lt;li&gt;If the server was started successfully (or was already running), a session is created by calling the inherited CreateSession function. This takes three parameters. These are:&lt;ul&gt;</span>
<a name="l00109"></a>00109 <span class="stringliteral">&lt;li&gt;Server name - this is used to search for an already existing server.&lt;/li&gt;&lt;li&gt;Version - the lowest version of the server with which this client is compatible.&lt;/li&gt;&lt;li&gt;Message slots - the number of asynchronous message requests that the client can have outstanding at any time. For a synchronous server, this is zero.&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00110"></a>00110 <span class="stringliteral">&lt;/li&gt;&lt;li&gt;The CreateSession function calls corresponding function from kernel side. The actual name of this function is undocumented.&lt;/li&gt;&lt;li&gt;The kernel layer calls the server&#39;</span>s NewSessionL function. The exact mechanism is not documented but is included to show the complete sequence of events. NewSessionL verifies the client version, returning an error <span class="keywordflow">if</span> it is not compatible with the server. It then creates a <span class="keyword">new</span> &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&quot;</span>&gt;<a class="code" href="class_c_time_server_session.html">CTimeServerSession</a>&lt;/a&gt; to handle the client/server communication.&lt;/li&gt;&lt;li&gt;The session is created <span class="keyword">using</span> the standard Symbian OS two-phase construction.&lt;/li&gt;&lt;li&gt;The <span class="keyword">new</span> session is registered with the server, <span class="keyword">using</span> IncrementSessions. The server keeps a count of the number of open sessions. The DecrementSessions function is called when a server session is destroyed, and terminates the server when there are no more open sessions.&lt;/li&gt;&lt;/ol&gt;
<a name="l00111"></a>00111 &lt;p&gt;
<a name="l00112"></a>00112 &lt;hr&gt;
<a name="l00113"></a>00113 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub321&quot;</span>&gt;
<a name="l00114"></a>00114 3.2.1 Starting the server&lt;/a&gt;&lt;/h3&gt;
<a name="l00115"></a>00115 A server needs its own thread of execution. In <span class="keyword">this</span> example, the client uses StartServer to check whether the server is running. If the server is not running, a thread is created and the server is started.&lt;p&gt;
<a name="l00116"></a>00116 The following diagram shows the sequence involved in creating the server.&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;start_server_sequence.png&quot;</span> alt=<span class="stringliteral">&quot;start_server_sequence.png&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;The StartServer function attempts to find an already running server. If it cannot, it will create a <span class="keyword">new</span> server, waiting until the server has been created before returning.&lt;/li&gt;&lt;li&gt;A <span class="keyword">new</span> TFindServer <span class="keywordtype">object</span> is created with the server name to search <span class="keywordflow">for</span>.&lt;/li&gt;&lt;li&gt;The call to TFindServer::Next returns KErrNone <span class="keywordflow">if</span> the server was found.&lt;/li&gt;&lt;li&gt;A <span class="keyword">new</span> RSemaphore is created.&lt;/li&gt;&lt;li&gt;The call to RSemaphore::CreateGlobal is passed the semaphore name to use. The semaphore needs to be global since the client and server run in separate processes (on the target). The server uses <span class="keyword">this</span> semaphore to tell the client when the server construction is complete.&lt;/li&gt;&lt;li&gt;CreateServerProcess will create and run the server. This is described in the Creating a process <span class="keywordflow">for</span> the server.&lt;/li&gt;&lt;li&gt;The client now waits <span class="keywordflow">for</span> the server to initialise and become ready to accept requests. It accomplishes <span class="keyword">this</span> by calling RSemaphore::Wait.&lt;/li&gt;&lt;li&gt;When the server issues a corresponding RSemaphore::Signal, the client will <span class="keywordflow">continue</span>. The semaphore is now closed <span class="keyword">using</span> RSemaphore::Close.&lt;/li&gt;&lt;/ol&gt;
<a name="l00123"></a>00123 &lt;p&gt;
<a name="l00124"></a>00124 &lt;hr&gt;
<a name="l00125"></a>00125 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub322&quot;</span>&gt;
<a name="l00126"></a>00126 3.2.2 Creating a process <span class="keywordflow">for</span> the server&lt;/a&gt;&lt;/h3&gt;
<a name="l00127"></a>00127 The sequence involved in creating a process <span class="keywordflow">for</span> the server is shown below. On emulator it creates a thread, because server must run as a thread in the emulator<span class="stringliteral">&#39;s process, and a process in target device.&lt;p&gt;</span>
<a name="l00128"></a>00128 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00129"></a>00129 <span class="stringliteral">&lt;img src=&quot;server_process_creating.png&quot; alt=&quot;server_process_creating.png&quot;&gt;</span>
<a name="l00130"></a>00130 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00131"></a>00131 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00132"></a>00132 <span class="stringliteral">&lt;ol type=1&gt;</span>
<a name="l00133"></a>00133 <span class="stringliteral">&lt;li&gt;The CreateServerProcess function is responsible for creating a process for the server to run in, then starting the server.&lt;/li&gt;&lt;li&gt;A handle for manipulating the server is created using RProcess::Create.&lt;/li&gt;&lt;li&gt;The RProcess::Create is supplied with three parameters. These are:&lt;ul&gt;</span>
<a name="l00134"></a>00134 <span class="stringliteral">&lt;li&gt;Server file name - the name of the server, including the path, to be executed.&lt;/li&gt;&lt;li&gt;Parameters - any data to be passed to the server (in this case, no data is passed).&lt;/li&gt;&lt;li&gt;UID - the UID of the server executable.&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00135"></a>00135 <span class="stringliteral">&lt;/li&gt;&lt;li&gt;The process has now been created by the kernel. The process is suspended until a call to RProcess::Resume is made.&lt;/li&gt;&lt;li&gt;The process is signalled to start by calling RProcess::Resume.&lt;/li&gt;&lt;li&gt;Kernel&#39;</span>s DProcess::Resume() is called.&lt;/li&gt;&lt;li&gt;The E32Main is called, which is the EXE entry point.&lt;/li&gt;&lt;li&gt;The E32Main call starts processing at the &lt;a class=&quot;el&quot; href=&quot;class_c_time_server.html<span class="preprocessor">#d575a6cfda27d2fc60179c9cf5f90663&quot;&gt;CTimeServer::ThreadFunction&lt;/a&gt;. This is described in the Server-side initialisation section.&lt;/li&gt;&lt;li&gt;The handle to the server is no longer required, and is closed. Close must be called here, otherwise this process would have an open reference to the server&#39;s process. This would prevent the process being released after the server terminates.&lt;/li&gt;&lt;/ol&gt;</span>
<a name="l00136"></a>00136 <span class="preprocessor"></span>&lt;p&gt;
<a name="l00137"></a>00137 &lt;hr&gt;
<a name="l00138"></a>00138 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub323&quot;</span>&gt;
<a name="l00139"></a>00139 3.2.3 Server-side initialisation&lt;/a&gt;&lt;/h3&gt;
<a name="l00140"></a>00140 An EXE component implements the E32Main function, which provides the API <span class="keywordflow">for</span> the operating system to start the executable. This function returns the address of the <a class="code" href="_msg_q_client_8c.html#aa6c400c3d8dbbba550d14cc697133e96">ThreadFunction</a> function to be called.&lt;p&gt;
<a name="l00141"></a>00141 The following diagram shows the initialisation the server undergoes on startup.&lt;p&gt;
<a name="l00142"></a>00142 &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00143"></a>00143 &lt;img src=<span class="stringliteral">&quot;server_startup.png&quot;</span> alt=<span class="stringliteral">&quot;server_startup.png&quot;</span>&gt;
<a name="l00144"></a>00144 &lt;/div&gt;
<a name="l00145"></a>00145 &lt;p&gt;
<a name="l00146"></a>00146 &lt;ol type=1&gt;
<a name="l00147"></a>00147 &lt;li&gt;Kernel calls EXE entrypoint E32Main().&lt;/li&gt;&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.html#d575a6cfda27d2fc60179c9cf5f90663&quot;</span>&gt;<a class="code" href="class_c_time_server.html#af9f826864fde246cd6c53af89563ba70">CTimeServer::ThreadFunction</a>&lt;/a&gt; is responsible <span class="keywordflow">for</span> setting up any services that <span class="keyword">this</span> thread/process requires, as well as creating an instance of the &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server.html&quot;</span>&gt;<a class="code" href="class_c_time_server.html">CTimeServer</a>&lt;/a&gt; <span class="keyword">class </span>to service requests from clients. It is important to note that <a class="code" href="_msg_q_client_8c.html#aa6c400c3d8dbbba550d14cc697133e96">ThreadFunction</a> cannot leave. Any errors that occur need to be handled or must raise a panic, as there is no way to pass error information back to the calling thread.&lt;/li&gt;&lt;li&gt;A cleanup stack is constructed and initialised. A thread/process does not have a cleanup stack by default, so one has to be created <a class="code" href="interfacefor.html">for</a> it.&lt;/li&gt;&lt;li&gt;&lt;a class=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server.html#be5e4a4628587739b7c76951f9577e8e&quot;</span>&gt;CTimeServer::ThreadFunctionL&lt;/a&gt; is called within a TRAP to <span class="keywordflow">do</span> the remainder of the construction that can leave. Following steps 5 -14 are executed inside of <span class="keyword">this</span> function.&lt;/li&gt;&lt;li&gt;An active scheduler is required, to handle active objects. It is created&lt;/li&gt;&lt;li&gt;The active scheduler is installed.&lt;/li&gt;&lt;li&gt;An anonymous instance of &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_time_server.html&quot;</span>&gt;<a class="code" href="class_c_time_server.html">CTimeServer</a>&lt;/a&gt; is created.&lt;/li&gt;&lt;li&gt;As all the work of the server is activated via the active scheduler, it is not necessary to refer to server. The ConstructL calls CServer::StartL.&lt;/li&gt;&lt;li&gt;The CServer::StartL call adds the server to the active scheduler and signals an active <span class="keywordtype">object</span> request.&lt;/li&gt;&lt;li&gt;Semaphore is created.&lt;/li&gt;&lt;li&gt;Handle to the global semaphore is created.&lt;/li&gt;&lt;li&gt;The global semaphore is signalled. This indicates that the server has now been constructed and is ready to use. The client will <span class="keywordflow">return</span> from its RSemaphore::Wait the next time that it is scheduled by the run time system.&lt;/li&gt;&lt;li&gt;Semaphore is closed.&lt;/li&gt;&lt;li&gt;The active scheduler is started by calling CActiveScheduler::Start. This function only returns when CActiveScheduler::Stop() is called, which should occur when the final client is closed. Note that an active scheduler must have a pending active <span class="keywordtype">object</span> before the call to CActiveScheduler::Start() is made. This was performed in steps 7 - 9.&lt;/li&gt;&lt;/ol&gt;
<a name="l00148"></a>00148 &lt;p&gt;
<a name="l00149"></a>00149 &lt;hr&gt;
<a name="l00150"></a>00150 &lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub33&quot;&gt;
<a name="l00151"></a>00151 3.3 Making a server request&lt;/a&gt;&lt;/h3&gt;
<a name="l00152"></a>00152 The RMessage2 class is used to transfer information between the client and the server.&lt;p&gt;
<a name="l00153"></a>00153 An instance of an RMessage2 <span class="keywordtype">object</span> is automatically created <a class="code" href="interfacefor.html">for</a> the session when the client calls the RSessionBase::SendReceive. This function can take a parameter that is a reference to TIpcArgs <span class="keywordtype">object</span>, which can contain up to four 32-bit data arguments to be passed to server.&lt;p&gt;
<a name="l00154"></a>00154 The sequence involved in making a server request is shown below.&lt;p&gt;
<a name="l00155"></a>00155 &lt;div align=&quot;center&quot;&gt;
<a name="l00156"></a>00156 &lt;img src=&quot;server_request.png&quot; alt=&quot;server_request.png&quot;&gt;
<a name="l00157"></a>00157 &lt;/div&gt;
<a name="l00158"></a>00158 &lt;p&gt;
<a name="l00159"></a>00159 &lt;ol type=1&gt;
<a name="l00160"></a>00160 &lt;li&gt;RequestTime is called by the application in response to the user selecting the Display Time option. A reference to a TTime <span class="keywordtype">object</span> is passed into this function. A descriptor is now created, representing this TTime <span class="keywordtype">object</span>. This descriptor&#39;s address is added into TIpcArgs <span class="keywordtype">object</span>, which is passed to the inherited SendReceive function.&lt;/li&gt;&lt;li&gt;The call to SendReceive results in the client thread being suspended.&lt;/li&gt;&lt;li&gt;SendReceive calls undocumented function from kernel side.&lt;/li&gt;&lt;li&gt;The kernel calls the ServiceL function of the associated server session and passes the appropriate RMessage2 <span class="keywordtype">object</span>. This <span class="keywordtype">object</span> specifies the operation to be performed by the server and also the message parameters. It also allows the server to indicate to the client when the request has completed, and raise a panic upon the client.&lt;/li&gt;&lt;li&gt;ServiceL checks the requested service using RMessage2::Function.&lt;/li&gt;&lt;li&gt;If requested service is ETimeServRequestTime it calls RequestTimeL, otherwise it raises a panic upon the client.&lt;/li&gt;&lt;li&gt;RequestTimeL calculates the current time and creates a new descriptor representing it. RMessage2::WriteL is now called with the descriptor as parameter. The first parameter of the WriteL function is index value identifying the argument. This value must be 0 because the client&#39;s descriptor is the first argument. This function call causes the time to be written to the client&#39;s address space.&lt;/li&gt;&lt;/ol&gt;
<a name="l00161"></a>00161 &lt;p&gt;
<a name="l00162"></a>00162 &lt;hr&gt;
<a name="l00163"></a>00163 &lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub34&quot;&gt;
<a name="l00164"></a>00164 3.4 Capabilities&lt;/a&gt;&lt;/h3&gt;
<a name="l00165"></a>00165 The application does not require any capabilities. The program capabilities are defined in both mmp-files as CAPABILITY NONE. &lt;hr&gt;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167 &lt;table x-use-null-cells
<a name="l00168"></a>00168                 style=&quot;x-cell-content-align: top;
<a name="l00169"></a>00169                                 width: 100%;
<a name="l00170"></a>00170                                 border-spacing: 0px;
<a name="l00171"></a>00171                                 border-spacing: 0px;&quot;
<a name="l00172"></a>00172                 cellspacing=0
<a name="l00173"></a>00173                 width=100%&gt;
<a name="l00174"></a>00174   &lt;col style=&quot;width: 50%;&quot;&gt;
<a name="l00175"></a>00175   &lt;col style=&quot;width: 50%;&quot;&gt;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177   &lt;tr style=&quot;x-cell-content-align: top;&quot;
<a name="l00178"></a>00178         valign=top&gt;
<a name="l00179"></a>00179   &lt;td style=&quot;width: 50%;
<a name="l00180"></a>00180                         padding-right: 10px;
<a name="l00181"></a>00181                         padding-left: 10px;
<a name="l00182"></a>00182                         border-right-style: None;
<a name="l00183"></a>00183                         border-left-style: None;
<a name="l00184"></a>00184                         border-top-style: None;
<a name="l00185"></a>00185                         border-bottom-style: None;&quot;
<a name="l00186"></a>00186         width=50%&gt;
<a name="l00187"></a>00187   &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;
<a name="l00188"></a>00188   &lt;td style=&quot;width: 50%;
<a name="l00189"></a>00189                         padding-right: 10px;
<a name="l00190"></a>00190                         padding-left: 10px;
<a name="l00191"></a>00191                         border-top-style: None;
<a name="l00192"></a>00192                         border-bottom-style: None;
<a name="l00193"></a>00193                         border-right-style: None;&quot;
<a name="l00194"></a>00194         width=50%&gt;
<a name="l00195"></a>00195   &lt;p style=&quot;text-align: right; margin-right: -4px;&quot;
<a name="l00196"></a>00196         align=right&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;a href=&quot;<span class="preprocessor">#Top&quot;</span>
<a name="l00197"></a>00197 <span class="preprocessor"></span>                                                                                                        title=<span class="stringliteral">&quot;Back to top&quot;</span>&gt;&lt;img
<a name="l00198"></a>00198  src=<span class="stringliteral">&quot;top.gif&quot;</span>
<a name="l00199"></a>00199         x-maintain-ratio=TRUE
<a name="l00200"></a>00200         alt=<span class="stringliteral">&quot;Back to top&quot;</span>
<a name="l00201"></a>00201         style=<span class="stringliteral">&quot;border: none;</span>
<a name="l00202"></a>00202 <span class="stringliteral">                        width: 18px;</span>
<a name="l00203"></a>00203 <span class="stringliteral">                        height: 15px;</span>
<a name="l00204"></a>00204 <span class="stringliteral">                        float: none;</span>
<a name="l00205"></a>00205 <span class="stringliteral">                        border-style: none;</span>
<a name="l00206"></a>00206 <span class="stringliteral">                        border-style: none;&quot;</span>
<a name="l00207"></a>00207         width=18
<a name="l00208"></a>00208         height=15
<a name="l00209"></a>00209         border=0&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
<a name="l00210"></a>00210  &lt;/table&gt;
<a name="l00211"></a>00211 &lt;/body&gt;
<a name="l00212"></a>00212 &lt;/html&gt;
<a name="l00213"></a>00213 
</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>