omadrm/drmengine/roap/src/RoapConnection.cpp
branchRCL_3
changeset 27 1481bf457703
parent 26 1221b68b8a5f
equal deleted inserted replaced
26:1221b68b8a5f 27:1481bf457703
     1 /*
     1 /*
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include <cmconnectionmethod.h>
    20 #include <cmconnectionmethod.h>
    21 #include <cmdestination.h>
    21 #include <cmdestination.h>
    22 #include <cmconnectionmethoddef.h>
    22 #include <cmconnectionmethoddef.h>
    23 #include <cmmanager.h>
    23 #include <cmmanager.h>
    24 #include <centralrepository.h>
    24 #include <centralrepository.h>
    25 #include <extendedconnpref.h>
    25 #include <commdbconnpref.h>
    26 #include <cdblen.h>
    26 #include <cdblen.h>
    27 #include <cdbcols.h> // IAP, COMMDB_ID
       
    28 #include <es_enum.h>
    27 #include <es_enum.h>
       
    28 #ifdef __SERIES60_NATIVE_BROWSER
       
    29 #include <browseruisdkcrkeys.h>
       
    30 #endif
    29 #include "RoapConnection.h"
    31 #include "RoapConnection.h"
    30 #include "RoapDef.h"
    32 #include "RoapDef.h"
    31 #include "RoapLog.h"
    33 #include "RoapLog.h"
    32 
    34 
    33 
    35 
       
    36 
       
    37 #ifndef __SERIES60_NATIVE_BROWSER
       
    38     const TUid KCRUidBrowser   = {0x10008D39};
       
    39     const TUint32 KBrowserDefaultAccessPoint =  0x0000000E;
       
    40     const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
       
    41     const TUint32 KBrowserNGDefaultSnapId = 0x00000053;
       
    42 #endif
       
    43 
       
    44 
       
    45 // ================= LOCAL FUNCTIONS =========================================
       
    46 // ---------------------------------------------------------------------------
       
    47 // IapIdOfDefaultSnapL
       
    48 // for trapping purposes only
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 LOCAL_C TUint32 IapIdOfDefaultSnapL(
       
    52     RCmManager& aCmManager,
       
    53     const TUint32 aDefaultSnap )
       
    54     {
       
    55     RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) );
       
    56     CleanupClosePushL( dest );
       
    57     TUint32 iapIdOfDest( 0 );
       
    58 
       
    59     if ( dest.ConnectionMethodCount() <= 0 )
       
    60         {
       
    61         User::Leave( KErrNotFound );
       
    62         }
       
    63 
       
    64     RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
       
    65     CleanupClosePushL( cMeth );
       
    66 
       
    67     iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId );
       
    68     CleanupStack::PopAndDestroy( &cMeth );
       
    69     CleanupStack::PopAndDestroy( &dest );
       
    70     return iapIdOfDest;
       
    71     }
    34 
    72 
    35 // ================= MEMBER FUNCTIONS =======================
    73 // ================= MEMBER FUNCTIONS =======================
    36 
    74 
    37 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    38 // Roap::CRoapConnection::NewL
    76 // Roap::CRoapConnection::NewL
    64 //
   102 //
    65 void Roap::CRoapConnection::ConnectL
   103 void Roap::CRoapConnection::ConnectL
    66 ( TUint32 aIap, TRequestStatus* aStatus )
   104 ( TUint32 aIap, TRequestStatus* aStatus )
    67     {
   105     {
    68     LOGLIT( "CRoapConnection::ConnectL" )
   106     LOGLIT( "CRoapConnection::ConnectL" )
       
   107     const TInt KAlwaysAskSelectionMode( 1 );
       
   108     const TInt KDestinationSelectionMode( 2 );
    69 
   109 
    70     if ( iState == EInit )
   110     if ( iState == EInit )
    71         {
   111         {
    72         // Not connected. Attach to existing connection, or create new one if
   112         // Not connected. Attach to existing connection, or create new one if
    73         // allowed.
   113         // allowed.
    78         CleanupClosePushL<RSocketServ>( iSocketServ );
   118         CleanupClosePushL<RSocketServ>( iSocketServ );
    79         User::LeaveIfError( iConnection.Open( iSocketServ ) );
   119         User::LeaveIfError( iConnection.Open( iSocketServ ) );
    80         CleanupClosePushL<RConnection>( iConnection );
   120         CleanupClosePushL<RConnection>( iConnection );
    81 
   121 
    82         TConnectionInfoBuf connInfo;
   122         TConnectionInfoBuf connInfo;
    83         TUint count(0);
   123         TInt ap = 0;
       
   124         TInt alwaysAsk = 0;
       
   125         TUint count;
    84         User::LeaveIfError( iConnection.EnumerateConnections( count ) );
   126         User::LeaveIfError( iConnection.EnumerateConnections( count ) );
    85         TUint i(0);
   127         TUint i;
    86         if ( count )
   128         if ( count )
    87             {
   129             {
    88             // Select from existing connections. Try to make AP match.
   130             // Select from existing connections. Try to make AP match.
    89             for ( i = count; i; i-- )
   131             for ( i = count; i; i-- )
    90                 {
   132                 {
   108             iStatus = KErrNone;
   150             iStatus = KErrNone;
   109             }
   151             }
   110         else
   152         else
   111             {
   153             {
   112             // No existing connections, create new one.
   154             // No existing connections, create new one.
   113             // Create overrides
   155 #ifdef __WINS__
   114             TConnPrefList prefList;
   156             // WINS connection creation does not work if preferences are given.
   115             TExtendedConnPref prefs;
   157             // Defaults are to be used always.
   116 
   158             iConnection.Start( iStatus );
   117             prefs.SetNoteBehaviour(TExtendedConnPref::ENoteBehaviourConnSilent);
   159 #else
   118 
   160             // Note: the TCommDbConnPref must NOT be stack variable.
   119             //Fetch default connection
   161             // It must persist until completion of RConnection::Start().
   120             TBool hasDefault(ETrue);
   162             iConnPref.SetDirection( ECommDbConnectionDirectionOutgoing );
   121             TCmDefConnValue defConn;
   163             //iConnPref.SetDialogPreference( ECommDbDialogPrefWarn )
   122             RCmManager cmManager;
   164             iConnPref.SetBearerSet( ECommDbBearerCSD | ECommDbBearerWcdma );
   123             cmManager.OpenLC();
   165             // New connection is always created with user-selected AP
   124             cmManager.ReadDefConnL(defConn);
   166             // so 0 is used instead of aIap.
   125             if (defConn.iType == ECmDefConnConnectionMethod)
   167 
   126                 {
   168             TInt defaultSnap( 0 );
   127                 prefs.SetIapId(defConn.iId);
   169             CRepository* repository( NULL );
   128                 }
   170             repository = CRepository::NewL( KCRUidBrowser );
   129             else if (defConn.iType == ECmDefConnDestination)
   171             CleanupStack::PushL( repository );
   130                 {
   172 
   131                 prefs.SetSnapId(defConn.iId);
   173             repository->Get( KBrowserDefaultAccessPoint, ap);
       
   174             repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
       
   175             repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
       
   176             CleanupStack::PopAndDestroy( repository );
       
   177             repository = NULL;
       
   178 
       
   179             TUint32 iapd32 = 0;
       
   180             TInt err = KErrNone;
       
   181 
       
   182             if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
       
   183                 {
       
   184                 alwaysAsk = KAlwaysAskSelectionMode;
   132                 }
   185                 }
   133             else
   186             else
   134                 {
   187                 {
   135                 hasDefault = EFalse;
   188                 RCmManager cmManager;
   136                 }
   189                 cmManager.OpenLC();
   137             // End of fetch default connection
   190                 if ( !alwaysAsk )
   138             if (hasDefault)
   191                     {
   139                 {
   192                     TRAP( err, iapd32 = cmManager.GetConnectionMethodInfoIntL(
   140                 prefList.AppendL(&prefs);
   193                             ap, CMManager::ECmIapId ) );
   141 
   194                     }
   142                 // Start an Outgoing Connection with overrides
   195                 else if ( alwaysAsk == KDestinationSelectionMode )
   143                 iConnection.Start(prefList, iStatus);
   196                     {
       
   197                     TRAP( err, iapd32 = IapIdOfDefaultSnapL(
       
   198                             cmManager, defaultSnap ) );
       
   199                     }
       
   200                 CleanupStack::PopAndDestroy( &cmManager );
       
   201                 }
       
   202 
       
   203             if ( err || alwaysAsk == KAlwaysAskSelectionMode )
       
   204                 {
       
   205                 // Always ask
       
   206                 LOGLIT( "SetDialogPreference( ECommDbDialogPrefPrompt )" )
       
   207                 iConnPref.SetDialogPreference( ECommDbDialogPrefPrompt );
       
   208                 iapd32 = 0;
   144                 }
   209                 }
   145             else
   210             else
   146                 {
   211                 {
   147                 // No default found --> trying with query
   212                 // User defined
   148                 iConnection.Start(iStatus);
   213                 LOGLIT( "SetDialogPreference( ECommDbDialogPrefDoNotPrompt )" )
   149                 }
   214                 iConnPref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
   150             CleanupStack::PopAndDestroy(&cmManager);
   215                 }
       
   216 
       
   217             iConnPref.SetIapId( iapd32 );
       
   218             iConnection.Start( iConnPref, iStatus );
       
   219 #endif
   151             iState = EConnecting;
   220             iState = EConnecting;
   152             SetActive();    // The only path with a real async request.
   221             SetActive();    // The only path with a real async request.
   153             }
   222             }
   154         CleanupStack::Pop( 2, &iSocketServ ); // closing iConn and iSockServ
   223         CleanupStack::Pop( 2, &iSocketServ ); // closing iConn and iSockServ
   155         // End of atomic part.
   224         // End of atomic part.