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