Symbian3/SDK/Source/GUID-4C7ABD1C-B42C-590A-AD24-7FA6C3A8D18C.dita
changeset 0 89d6a7a84779
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-4C7ABD1C-B42C-590A-AD24-7FA6C3A8D18C.dita	Thu Jan 21 18:18:20 2010 +0000
@@ -0,0 +1,124 @@
+<?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 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
+RSubConParameterBundle subconParams;
+CleanupClosePushL(subconParams);
+
+………
+………
+// Create and initialise parameters sets as above
+………
+………
+
+// Create a new sub-connection
+subconn.Open(ss, RSubConnection::ECreateNew, conn);
+
+TNotificationEventBuf eventBuffer;
+TRequestStatus eventStatus;
+subconn.EventNotification(eventBuffer, EFalse, eventStatus);
+
+// Set Properties of the sub-connection
+subconn.SetParameters(subconParams);
+
+// Destroy parameters
+CleanupStack::PopAndDestroy();         // subconParams
+
+// Open and connect a TCP socket on the sub-connection
+sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, subconn);
+sock.Connect(destAddr, status);
+User::WaitForRequest(status);
+
+// Negotiation may not occur until a socket is assigned to the sub-connection
+// First event should be cSubConGenEventDataClientJoining
+User::WaitForRequest(eventStatus);
+
+// Next we’d expect a CSubconGenEventParamsGranted/ CSubconGenEventParamsRejected
+subconn.EventNotification(eventBuffer, EFalse, eventStatus);
+User::WaitForRequest(eventStatus);
+</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
+RSubConParameterBundle subconParams;
+CleanupClosePushL(subconParams);
+
+………
+………
+// Create and initialise parameters sets as above
+………
+………
+
+// Create a new sub-connection
+subconn.Open(ss, RSubConnection::ECreateNew, conn);
+
+// Create event filter
+TEventFilter filter;
+filter.iEventGroupUid = KSubConnGenericEventsImplUid;
+filter.iEventMask = KSubConGenericEventParamsRejected | KSubConGenericEventParamsGranted;
+
+// Register for event
+TNotificationEventBuf eventBuffer;
+TRequestStatus eventStatus;
+subconn.EventNotification(eventBuffer, &amp;filter, 1, eventStatus);
+
+// Set Properties of the sub-connection
+subconn.SetParameters(subconParams);
+
+// Destroy parameters
+CleanupStack::PopAndDestroy();         // subconParams
+
+// Open and connect a TCP socket on the sub-connection
+sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, subconn);
+sock.Connect(destAddr, status);
+User::WaitForRequest(status);
+
+// Event should be CSubconGenEventParamsGranted/CSubconGenEventParamsRejected
+User::WaitForRequest(eventStatus);
+</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
+RSubConParameterBundle subconParams;
+CleanupClosePushL(subconParams);
+
+………
+………
+// Create and initialise parameters sets as above
+………
+………
+
+// Create a new sub-connection
+subconn.Open(ss, RSubConnection::ECreateNew, conn);
+
+// Create filter, register for events, and set parameters as above
+……
+subconn.EventNotification(eventBuffer, &amp;filter, 1, eventStatus);
+……
+
+// Open and connect a TCP socket on the sub-connection
+……
+
+// Receive the event notification
+User::WaitForRequest(eventStatus);
+
+CSubConNotificationEvent* event;
+event = CSubConNotificationEvent::NewL(eventBuffer);
+CleanupStack::PushL (event);
+
+if (event-&gt;GroupId() == KSubConnGenericEventsImplUid
+    &amp;&amp; event-&gt;Id() == CSubConGenEventParamsRejected)
+    {
+    CSubConGenEventParamsRejected* rejectedEvent =
+        static_cast&lt; CSubConGenEventParamsRejected*&gt;(event);
+
+    TInt error = rejectedEvent-&gt;Error();
+    ……
+    // Do something with the error
+    ……
+    }
+
+CleanupStack::PopAndDestroy (event);
+</codeblock> <p> <b>Note:</b> Error handling is not included to aid clarity. </p> </section> </conbody></concept>
\ No newline at end of file