Symbian3/PDK/Source/GUID-579D7C32-B6C8-5C77-88A5-B3078729E1BA.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 18:02:22 +0000
changeset 3 46218c8b8afa
parent 1 25a17d01db0c
child 5 f345bda72bc4
permissions -rw-r--r--
week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-579D7C32-B6C8-5C77-88A5-B3078729E1BA" xml:lang="en"><title>How
to implement a simple client interface</title><shortdesc>Provides code snippets to help you to implement a simple client
interface.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<section id="GUID-EE1BFD0F-EE55-47BA-A8FD-D753EC132255"><title>Client side session with a server</title> <p>A client side
session is represented by an instance of a class derived from <codeph>RSessionBase</codeph> which
provides the behaviour for connecting to the server and sending messages to
it. </p> <p>In the following code fragment, taken from the example that can
be found at <filepath>...\examples\Base\IPC\ClientServer\simple</filepath>,
the class <codeph>RCountServSession</codeph>, derived from <codeph>RSessionBase</codeph>,
represents the client side session with a server. In the example, this may
be referred to as the "count server". Note that sessions can not be shared
in this example, and it just shows the basic mechanics of the client/server
interaction. </p> <codeblock id="GUID-48AC1BF2-BA67-5959-A49A-AF57AC25E155" xml:space="preserve">class RCountServSession : public RSessionBase
    {
public:
    RCountServSession();
    TInt Connect();
    TVersion Version() const;
    TInt UnsupportedRequest();
    TInt SetFromString(const TDesC&amp; aString);
    void Increase();
    void Decrease();
    void IncreaseBy(TInt anInt);
    void DecreaseBy(TInt anInt);
    void Reset();
    TInt CounterValue();
    void BadRequest();
    void Close();
private:
    RThread iServerThread;
    };</codeblock> <p>The important points are: </p> <ul>
<li id="GUID-B6AC51AC-91A3-5794-815A-292E308735F6"><p>Use <codeph>Connect()</codeph> to
start the count server. This calls <codeph>RSessionBase::CreateSession()</codeph> to
create a session with the server. Note that in this simple example, the server
is implemented as a separate thread, which is started by the example executable. </p> </li>
<li id="GUID-EBDC7F23-8D2F-5093-8C32-50C3DE137EF5"><p>Use a client interface
function, such as <codeph>Increase()</codeph>, to send a specific message
to the server. The client interface function builds the message using the
appropriate operation code and assembling a suitable <xref href="GUID-4AD02F14-1142-372F-9D11-224595932034.dita"><apiname>TIpcArgs</apiname></xref> object,
i.e. the object containing the integers and/or the descriptor pointers to
the message arguments in the client address space. </p> </li>
</ul> <p>As an example, the function <codeph>SetFromString()</codeph> is implemented
as follows: </p> <codeblock id="GUID-A673A2A4-0999-5EDE-9FFB-E0C7335B58D9" xml:space="preserve">TInt RCountServSession::SetFromString(const TDesC&amp; aString)
    {
    TIpcArgs args(&amp;aString);
    return SendReceive(ECountServSetFromString, args);
    }</codeblock> <p> <codeph>SendReceive()</codeph> is called, specifying
an operation code <codeph>ECountServSetFromString</codeph> and a <xref href="GUID-4AD02F14-1142-372F-9D11-224595932034.dita"><apiname>TIpcArgs</apiname></xref> object
containing argument values. In this case, there is only one argument - a pointer
to a <codeph>TDesC</codeph> object containing the string to be passed to the
server. Typically, operation codes are enum values defined in a header file
visible to both the client interface and the server. Note that the client
descriptor must remain in existence until the server request completes. </p> </section>
</conbody></concept>