|
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-A30C1204-F130-501E-BD2D-1EE1537BEFC3" xml:lang="en"><title>How |
|
13 to implement a client interface with subsessions</title><shortdesc>Provides code snippets to help you to implement a |
|
14 client interface with subsessions.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
15 <p>A client side subsession is represented by an instance of a class derived |
|
16 from <codeph>RSubSessionBase</codeph> which provides the behaviour for: </p> |
|
17 <ul> |
|
18 <li id="GUID-E82084CE-E5AF-56D8-934C-A183809532A2"><p>creating a subsession |
|
19 in the server </p> </li> |
|
20 <li id="GUID-F810EEC0-E0B1-52F1-9587-72BB41AD54C0"><p>sending messages to |
|
21 the subsession. </p> </li> |
|
22 </ul> |
|
23 <p>In the following code fragment, taken from the example that can be found |
|
24 at <filepath>...\examples\Base\IPC\ClientServer\complex</filepath>, the class <codeph>RCountSubSession</codeph>, |
|
25 derived from <codeph>RSubSessionBase</codeph>, represents the client side |
|
26 subsession with a server (in the example the server is also referred to as |
|
27 the count server). The assumption is made that the client has already established |
|
28 a session with the server as represented by the <codeph>RCountSession</codeph> class. </p> |
|
29 <codeblock id="GUID-C9F043AD-A44B-5EC8-9ED4-932747EB6C9B" xml:space="preserve">class RCountSubSession : public RSubSessionBase |
|
30 { |
|
31 public: |
|
32 TInt Open(RCountSession& aServer); |
|
33 TInt SetFromString(const TDesC& aString); |
|
34 void Close(); |
|
35 void Increase(); |
|
36 void Decrease(); |
|
37 void IncreaseBy(TInt anInt); |
|
38 void DecreaseBy(TInt anInt); |
|
39 void Reset(); |
|
40 TInt CounterValue(); |
|
41 }; |
|
42 </codeblock> |
|
43 <codeblock id="GUID-7CE73750-213F-56EF-AEE5-04125147F934" xml:space="preserve">class RCountSession : public RSessionBase |
|
44 { |
|
45 public: |
|
46 RCountSession(); |
|
47 TInt Connect(); |
|
48 TVersion Version() const; |
|
49 TInt ResourceCount(); |
|
50 void Close(); |
|
51 private: |
|
52 RThread iServerThread; |
|
53 };</codeblock> |
|
54 <p>The important points in this example are: </p> |
|
55 <ul> |
|
56 <li id="GUID-AC212539-94D5-515D-991A-1D9E2D756922"><p> <codeph>Open()</codeph> creates |
|
57 a subsession within the client-side session. A reference to the client-side |
|
58 session is specified as the function's single argument. The function calls <codeph>RSubSessionBase::CreateSubSession()</codeph> which, |
|
59 in turn, causes a server side subsession object to be created and its handle |
|
60 number to be returned. </p> </li> |
|
61 <li id="GUID-3762EF2B-D88B-5F8A-A0CD-C9D83ACEC208"><p>Client subsession interface |
|
62 functions, such as <codeph>CounterValue()</codeph>, send a specific message |
|
63 to the server. </p> <codeblock id="GUID-ABFAD354-7632-5FF5-A721-C95B0B8D29AD" xml:space="preserve">TInt RCountSubSession::CounterValue() |
|
64 { |
|
65 TInt res = KErrNotFound; |
|
66 TPckgBuf<TInt> pckg; |
|
67 |
|
68 if (SubSessionHandle()) |
|
69 { |
|
70 // Note that TPckgBuf is of type TDes8 |
|
71 TIpcArgs args(&pckg); |
|
72 SendReceive(ECountServValue, args); |
|
73 |
|
74 // Extract the value returned from the server. |
|
75 res = pckg(); |
|
76 } |
|
77 |
|
78 return res; |
|
79 }</codeblock> </li> |
|
80 </ul> |
|
81 <ul> |
|
82 <li id="GUID-64C2EC87-84BF-5892-AD04-40B8DDC0DEA0"><p> <codeph>Close()</codeph> closes |
|
83 the subsession. </p> </li> |
|
84 </ul> |
|
85 <section id="GUID-5E96565F-8D14-43AB-80A0-F6FD558F0073"><title>Notes</title> <ul> |
|
86 <li id="GUID-49CCA864-57FD-5E28-8890-F2A1CE707428"><p>The operation code passed |
|
87 to <codeph>RSubSessionBase::CreateSubSession()</codeph> must be interpreted |
|
88 by the server as a request to create a subsession. </p> </li> |
|
89 <li id="GUID-8F920E77-7FFF-5591-87A7-40BFE75A7649"><p>When sending a message |
|
90 to the server with a call to <codeph>RSubSessionBase::SendReceive()</codeph>, |
|
91 only three arguments can be passed . This function always uses the fourth |
|
92 argument to hold the client subsession handle number which is used to identify |
|
93 the corresponding server side subsession object. The message arguments are |
|
94 subsequently passed to a call to <codeph>RSessionBase::SendReceive()</codeph>. </p> </li> |
|
95 <li id="GUID-C690D49E-F5F0-5B71-BE11-5461556FF3A0"><p>The operation code passed |
|
96 to <codeph>RSubSessionBase::CloseSubSession()</codeph> must be interpreted |
|
97 by the server as a request to close the subsession. </p> </li> |
|
98 </ul> </section> |
|
99 </conbody></concept> |