|
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 xml:lang="en" id="GUID-4C7ABD1C-B42C-590A-AD24-7FA6C3A8D18C"><title> Registering for Sub-Connection events: Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This tutorial describes how an application can register for sub-connection events. </p> <p>This tutorial has three parts. The first part describes how the application can register for all events. The second part describes how the application can register for a subset of events. The third part describes how the application can extract information from an event response. </p> <section><title>Registering for events – Simple case</title> <p>The following example shows the simplest case of how an application can register for events occurring on a sub-connection. In this example the application registers for notification of all events. </p> <codeblock id="GUID-A57F97F1-B0A2-5631-8F7B-1D38EA18E0D4" xml:space="preserve">// Create the container for all sub connection parameters |
|
13 RSubConParameterBundle subconParams; |
|
14 CleanupClosePushL(subconParams); |
|
15 |
|
16 ……… |
|
17 ……… |
|
18 // Create and initialise parameters sets as above |
|
19 ……… |
|
20 ……… |
|
21 |
|
22 // Create a new sub-connection |
|
23 subconn.Open(ss, RSubConnection::ECreateNew, conn); |
|
24 |
|
25 TNotificationEventBuf eventBuffer; |
|
26 TRequestStatus eventStatus; |
|
27 subconn.EventNotification(eventBuffer, EFalse, eventStatus); |
|
28 |
|
29 // Set Properties of the sub-connection |
|
30 subconn.SetParameters(subconParams); |
|
31 |
|
32 // Destroy parameters |
|
33 CleanupStack::PopAndDestroy(); // subconParams |
|
34 |
|
35 // Open and connect a TCP socket on the sub-connection |
|
36 sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, subconn); |
|
37 sock.Connect(destAddr, status); |
|
38 User::WaitForRequest(status); |
|
39 |
|
40 // Negotiation may not occur until a socket is assigned to the sub-connection |
|
41 // First event should be cSubConGenEventDataClientJoining |
|
42 User::WaitForRequest(eventStatus); |
|
43 |
|
44 // Next we’d expect a CSubconGenEventParamsGranted/ CSubconGenEventParamsRejected |
|
45 subconn.EventNotification(eventBuffer, EFalse, eventStatus); |
|
46 User::WaitForRequest(eventStatus); |
|
47 </codeblock> <p> <b>Note:</b> Error handling is not included to aid clarity. </p> </section> <section><title>Registering for events – Using filters</title> <p>The following example shows how to register for specific events by using filters. In this example the application registers for notification when sub-connection parameters have been granted or rejected. Each <xref href="GUID-FDE12D94-17D3-3646-B645-26A08926F86C.dita"><apiname>TEventFilter</apiname></xref> contains the factory Uid of the events and a mask of event Ids bitwise OR’d together. </p> <codeblock id="GUID-01830B80-B62E-5D88-AD0E-BF805EDAC150" xml:space="preserve">// Create the container for all sub connection parameters |
|
48 RSubConParameterBundle subconParams; |
|
49 CleanupClosePushL(subconParams); |
|
50 |
|
51 ……… |
|
52 ……… |
|
53 // Create and initialise parameters sets as above |
|
54 ……… |
|
55 ……… |
|
56 |
|
57 // Create a new sub-connection |
|
58 subconn.Open(ss, RSubConnection::ECreateNew, conn); |
|
59 |
|
60 // Create event filter |
|
61 TEventFilter filter; |
|
62 filter.iEventGroupUid = KSubConnGenericEventsImplUid; |
|
63 filter.iEventMask = KSubConGenericEventParamsRejected | KSubConGenericEventParamsGranted; |
|
64 |
|
65 // Register for event |
|
66 TNotificationEventBuf eventBuffer; |
|
67 TRequestStatus eventStatus; |
|
68 subconn.EventNotification(eventBuffer, &filter, 1, eventStatus); |
|
69 |
|
70 // Set Properties of the sub-connection |
|
71 subconn.SetParameters(subconParams); |
|
72 |
|
73 // Destroy parameters |
|
74 CleanupStack::PopAndDestroy(); // subconParams |
|
75 |
|
76 // Open and connect a TCP socket on the sub-connection |
|
77 sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, subconn); |
|
78 sock.Connect(destAddr, status); |
|
79 User::WaitForRequest(status); |
|
80 |
|
81 // Event should be CSubconGenEventParamsGranted/CSubconGenEventParamsRejected |
|
82 User::WaitForRequest(eventStatus); |
|
83 </codeblock> <p> <b>Note:</b> Error handling is not included to aid clarity. </p> </section> <section><title>Extracting information from received events</title> <p>The following example shows how to extract the information contained within an event notification once it has been received. </p> <codeblock id="GUID-FC08CC07-469E-5048-930F-E04F4AE8FDE3" xml:space="preserve">// Create the container for all sub connection parameters |
|
84 RSubConParameterBundle subconParams; |
|
85 CleanupClosePushL(subconParams); |
|
86 |
|
87 ……… |
|
88 ……… |
|
89 // Create and initialise parameters sets as above |
|
90 ……… |
|
91 ……… |
|
92 |
|
93 // Create a new sub-connection |
|
94 subconn.Open(ss, RSubConnection::ECreateNew, conn); |
|
95 |
|
96 // Create filter, register for events, and set parameters as above |
|
97 …… |
|
98 subconn.EventNotification(eventBuffer, &filter, 1, eventStatus); |
|
99 …… |
|
100 |
|
101 // Open and connect a TCP socket on the sub-connection |
|
102 …… |
|
103 |
|
104 // Receive the event notification |
|
105 User::WaitForRequest(eventStatus); |
|
106 |
|
107 CSubConNotificationEvent* event; |
|
108 event = CSubConNotificationEvent::NewL(eventBuffer); |
|
109 CleanupStack::PushL (event); |
|
110 |
|
111 if (event->GroupId() == KSubConnGenericEventsImplUid |
|
112 && event->Id() == CSubConGenEventParamsRejected) |
|
113 { |
|
114 CSubConGenEventParamsRejected* rejectedEvent = |
|
115 static_cast< CSubConGenEventParamsRejected*>(event); |
|
116 |
|
117 TInt error = rejectedEvent->Error(); |
|
118 …… |
|
119 // Do something with the error |
|
120 …… |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy (event); |
|
124 </codeblock> <p> <b>Note:</b> Error handling is not included to aid clarity. </p> </section> </conbody></concept> |