Symbian3/SDK/Source/GUID-05E3ED3B-41F8-5FC2-87A2-627BD5E6BB04.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 xml:lang="en" id="GUID-05E3ED3B-41F8-5FC2-87A2-627BD5E6BB04"><title> Attaching to an existing RConnection connection: Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The following example shows how an application can attach to an existing connection in order to gather information on the connection. </p> <p>Note that error checking is included in this example. </p> <codeblock id="GUID-32123F0F-45CC-5966-AD0B-E0895D316D3F" xml:space="preserve">
       
    13 //Open a session with the socket server
       
    14 RSocketServ socketServer;
       
    15 TInt err(KErrNone);
       
    16 err = socketServer.Connect();
       
    17 if(err != KErrNone) return err;
       
    18 
       
    19 //Open a subsession with the socket server for the RConnection
       
    20 RConnection myConnection;
       
    21 err = myConnection.Open(socketServer);
       
    22 if(err != KErrNone) return err;
       
    23 
       
    24 //Start or attach the RConnection to an interface on the server
       
    25 TUint connectionCount;
       
    26 //Enumerate currently active connections across all socket servers
       
    27 err = myConnection.EnumerateConnections(connectionCount);
       
    28 if(err != KErrNone) return err;
       
    29 if(connectionCount == 0) // if no connections are started
       
    30 {
       
    31             err = myConnection.Start();
       
    32 }
       
    33 else
       
    34 {
       
    35             TPckgBuf&lt;TConnectionInfoV2&gt; connectionInfo;
       
    36             err = myConnection.GetConnectionInfo(1, connectionInfo); // 1 = first active connection
       
    37             if(err!=KErrNone) return err;
       
    38             err = myConnection.Attach(connectionInfo, RConnection::EAttachTypeMonitor);
       
    39 }</codeblock> <p>At this point <codeph>myConnection</codeph> points to a specific connection. Obviously the code snippet above could be expanded in several ways such as getting connection information for all connections and selecting a connection based on the information rather than simply selecting the first connection, as in this case. </p> <p>Note for this and the next section that the number of connections and subconnections are not constant and can be expected to change during execution. </p> <codeblock id="GUID-F9F6D0DB-BA01-5610-BFDD-B15A61DF0757" xml:space="preserve">
       
    40 //Store subconnection information
       
    41 
       
    42 TUint subConnectionCount(0);
       
    43 err = myConnection.EnumerateSubConnections(subConnectionCount);
       
    44 if(err != KErrNone) return err;
       
    45 
       
    46 //TSubConnectionInfoGprsUmts is a superclass of TSubConnectionInfo, so we will use it
       
    47 //to hold either GPRS/UMTS or CSD connection information as required. (CSD connection 
       
    48 //information is held in a plain TSubConnectionInfo object).
       
    49 TPckgBuf&lt;TSubConnectionInfoGprsUmts&gt; subConnectionInfo[subConnectionCount];
       
    50 //note that for a CSD connection the subConnectionCount will be 1
       
    51 
       
    52 for (TUint i=0; i&lt;subConnectionCount; i++)
       
    53 {
       
    54             err = myConnection.GetSubConnectionInfo(i, subConnectionInfo[i]);
       
    55             if(err != KErrNone) return err;
       
    56 }</codeblock> <p>Once the connection has been attached it is possible to start querying individual subconnections. </p> <p>From this point the client has access to <codeph>subConnectionInfo().iSubConnectionUniqueId</codeph>, which is the unique identifier for the subconnection that has been queried. Now that this value is available the client can make any further calls to subconnection specific functionality within the <codeph>RConnection</codeph>, for example querying the amount of data currently transferred by the specified subconnection. </p> <codeblock id="GUID-436EFBF5-3338-55C1-B864-1A32B115EAD0" xml:space="preserve">
       
    57 TUint connectionuplinkVolume(0);
       
    58 TUint connectiondownlinkVolume(0);
       
    59 TUint subconnectionuplinkVolume(0);
       
    60 TUint subconnectiondownlinkVolume(0);
       
    61 TPckg&lt;TUint&gt; connectionUplinkVolume(connectionuplinkVolume);
       
    62 TPckg&lt;TUint&gt; connectionDownlinkVolume(connectiondownlinkVolume);
       
    63 TPckg&lt;TUint&gt; subConnectionUplinkVolume(subconnectionuplinkVolume);
       
    64 TPckg&lt;TUint&gt; subConnectionDownlinkVolume(subconnectiondownlinkVolume);
       
    65 TRequestStatus status;
       
    66 
       
    67 //Query data transfer over the connection
       
    68 myConnection.DataTransferredRequest(connectionUplinkVolume, connectionDownlinkVolume, status);
       
    69 
       
    70 //Query data transfer over a specified subconnection
       
    71 myConnection.DataTransferredRequest(subConnectionInfo[0]().iSubConnectionUniqueId, connectionUplinkVolume, connectionDownlinkVolume, status);
       
    72 </codeblock> </conbody></concept>