bearermanagement/S60MCPR/src/s60tiermanagerselector.cpp
changeset 0 5a93021fdf25
child 8 2e6c4614c58e
child 18 fcbbe021d614
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: S60 IP TM selector implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @file s60tiermanagerselector.cpp
       
    20 S60 IP TM selector implementation
       
    21 */
       
    22 
       
    23 #include <comms-infras/ss_log.h>
       
    24 #include <comms-infras/ss_tiermanagerutils.h>
       
    25 #include <commsdattypesv1_1.h> // CommsDat
       
    26 #include <es_connpref.h>    //TConnIdList
       
    27 #include <commdbconnpref.h>
       
    28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    29 #include <commsdattypeinfov1_1_internal.h>
       
    30 #include <commsdattypesv1_1_partner.h> 
       
    31 #endif
       
    32 
       
    33 #include "s60tiermanagerselector.h"
       
    34 #include "s60tiermanagerfactory.h"
       
    35 #include "s60mcpr.h"
       
    36 
       
    37 using namespace ESock;
       
    38 using namespace CommsDat;
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // IpProto Tier Manager's UID.
       
    42 // Since meaning of the selection policy id changes with
       
    43 // the legacy flavor it is difficult to derive the next layer
       
    44 // tier's id dynamically when supporting all of the legacy scenarios.
       
    45 // At the same time it is known that for all of these legacy
       
    46 // setups this is and always will be the only next layer tier manager.
       
    47 // -----------------------------------------------------------------------------
       
    48 static const TUid KLegacyNextLayerTierId = { 0x10281DF0 }; //CIPProtoTierManagerFactory::iUid
       
    49 
       
    50 #ifdef __CFLOG_ACTIVE
       
    51 #define KS60TierMgrTag KESockMetaConnectionTag
       
    52 _LIT8(KS60TierMgrSubTag, "netmcpr");
       
    53 #endif
       
    54 
       
    55 //Panic codes
       
    56 #ifdef _DEBUG
       
    57 _LIT(KS60SelectorPanic, "S60TMSelector");
       
    58 enum TS60SelectorPanic
       
    59     {
       
    60     EExpectedAccessPointAwareSystem = 0,     //
       
    61     EUnExpectedSelectionPreferences = 1,
       
    62     };
       
    63 #endif // _DEBUG
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSimpleS60SelectorBase::CSimpleS60SelectorBase
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CSimpleS60SelectorBase::CSimpleS60SelectorBase( const Meta::SMetaData& aSelectionPreferences )
       
    70     :    ASimpleSelectorBase( aSelectionPreferences )
       
    71     {
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CSimpleS60SelectorBase::~CSimpleS60SelectorBase
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CSimpleS60SelectorBase::~CSimpleS60SelectorBase()
       
    79     {
       
    80     }
       
    81     
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSimpleS60SelectorBase::SelectL
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CSimpleS60SelectorBase::SelectL( ISelectionNotify& aSelectionNotify )
       
    87     {
       
    88     ASSERT(iDbs);
       
    89     ASSERT(iTierRecord);
       
    90 
       
    91     // Default access point is required as it will point the correct node UIDs for the next layer.
       
    92     iDefaultAp = iTierRecord->iDefaultAccessPoint;
       
    93     //Since we do not understand the preferences, we create a provider based on a default Access Point,
       
    94     //like in the implicit case, but we also pass the preferences down.
       
    95     __CFLOG_VAR((KS60TierMgrTag, KS60TierMgrSubTag, _L8("S60MCPR::CSimpleS60SelectorBase %08x::\tSelectL() Using Default AP:%d"),this,iDefaultAp));
       
    96 
       
    97     //Legacy Attach -case handling is in NetMCPR and IPProtoTM
       
    98     // 399 Attach is not supported
       
    99     const TConnPref& prefs = iSelectionPrefs.Prefs();
       
   100     switch ( prefs.ExtensionId() )
       
   101         {
       
   102         case TConnPref::EConnPrefCommDbMulti:
       
   103             {
       
   104             // Sanity check.
       
   105             TCommDbMultiConnPref& multiPrefs = TCommDbMultiConnPref::Cast( prefs );
       
   106             TCommDbConnPref connpref;
       
   107             TInt error = multiPrefs.GetPreference( 1, connpref );
       
   108             // if bad connpref
       
   109             if ( error != KErrNone )
       
   110                 {
       
   111                 User::Leave( error );
       
   112                 }
       
   113             //else ok. MPM handles the TConnPref parsing.
       
   114             break;
       
   115             }
       
   116         case TConnPref::EConnPrefUnknown: // same as IsEmpty() == ETrue
       
   117         case TConnPref::EConnPrefCommDb:
       
   118         case TConnPref::EConnPrefSnap:
       
   119             {
       
   120             // Supported. MPM handles the parsing.
       
   121             break;
       
   122             }
       
   123         case TConnPref::EConnPrefIdList:
       
   124         case TConnPref::EConnPrefSip:
       
   125         case TConnPref::EConnPrefProviderInfo:
       
   126         default:
       
   127             {
       
   128             // Unsupported
       
   129             User::Leave( KErrNotSupported );
       
   130             break;
       
   131             }
       
   132         }
       
   133     // We do the default behavior. AP is only needed to get proper UIds for TM etc..
       
   134     // TODO: change to use AP.
       
   135     aSelectionNotify.SelectComplete( this, FindOrCreateProviderL( iDefaultAp ));
       
   136     aSelectionNotify.SelectComplete( this, NULL );
       
   137     }
       
   138     
       
   139 // -----------------------------------------------------------------------------
       
   140 // CSimpleS60SelectorBase::FindOrCreateProviderL
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 CMetaConnectionProviderBase* CSimpleS60SelectorBase::FindOrCreateProviderL( TUint aAccessPoint )
       
   144     {
       
   145     ASSERT(aAccessPoint); //Should not be 0 now.
       
   146 
       
   147     //Find factory
       
   148     TUid mCprUid = TierManagerUtils::ReadMCprUidL( aAccessPoint, *iDbs );
       
   149     CMetaConnectionProviderFactoryBase* factory = 
       
   150         static_cast<CMetaConnectionProviderFactoryBase*>(iMetaContainer.FindOrCreateFactoryL( mCprUid ));
       
   151 
       
   152     //Create the provider
       
   153     TUid tierId = TUid::Uid( iTierRecord->iRecordTag );
       
   154 	TProviderInfo providerInfo( tierId, aAccessPoint );
       
   155 	TUid tierImplUid = TierManagerUtils::MapTierIdtoTierImplIdL(tierId,*iDbs);
       
   156     TMetaConnectionFactoryQuery query( providerInfo, tierImplUid );
       
   157     
       
   158     //We are not looking for an existing provider, we always create a new one.
       
   159     //This is the legacy selection (can also be the legacy attach, one layer deep selection)
       
   160     CMetaConnectionProviderBase* provider = static_cast<CMetaConnectionProviderBase*>( factory->CreateObjectL( query ));
       
   161     CS60MetaConnectionProvider* prov = static_cast<CS60MetaConnectionProvider*>( provider );
       
   162     
       
   163     CleanupStack::PushL( provider );
       
   164     
       
   165     // Provision selection preferences to S60 NetMCPR.
       
   166     prov->SetSelectionPrefs( iSelectionPrefs );
       
   167 
       
   168     // Change the provider info so that this provider is never found by other selections
       
   169     const TProviderInfo& pi = provider->ProviderInfo();
       
   170     provider->SetProviderInfo( TProviderInfo( pi.TierId(), pi.APId(), provider )); //This provider will never be found
       
   171     
       
   172     // Override the selection policy as we always do for legacy prefs
       
   173     ASSERT(provider->AccessPointConfig().FindExtension(TOverridenSelectionPrefsExt::TypeId())==NULL);
       
   174 
       
   175 	RMetaExtensionContainer mec;
       
   176 	mec.Open(provider->AccessPointConfig());
       
   177 	CleanupClosePushL(mec);
       
   178 	
       
   179     TOverridenSelectionPrefsExt* ext = new (ELeave) TOverridenSelectionPrefsExt( KLegacyNextLayerTierId, iSelectionPrefs );
       
   180     CleanupStack::PushL( ext );
       
   181     mec.AppendExtensionL( ext ); //The ownership of the extension goes to AccessPointConfig now.
       
   182     CleanupStack::Pop( ext );
       
   183 
       
   184 	provider->AccessPointConfig().Close();
       
   185 	provider->AccessPointConfig().Open(mec);
       
   186 	CleanupStack::PopAndDestroy(&mec);
       
   187 	
       
   188     CleanupStack::Pop( provider );
       
   189     provider->IncrementBlockingDestroy();
       
   190     return provider;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // TS60ProviderSelectorFactory::NewSelectorL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 MProviderSelector* TS60ProviderSelectorFactory::NewSelectorL(const Meta::SMetaData& aSelectionPreferences)
       
   198     {
       
   199     __CFLOG_VAR((KS60TierMgrTag, KS60TierMgrSubTag, _L8("S60MCPR::CS60ProviderSelectorBase::\tNewSelectorL()")));
       
   200     ASSERT(aSelectionPreferences.IsTypeOf(TSelectionPrefs::TypeId()));
       
   201     //const ESock::TSelectionPrefs& sp = static_cast<const ESock::TSelectionPrefs&>(aSelectionPreferences);
       
   202     ASimpleSelectorBase* self = NULL;
       
   203     CBase* selfCleanupItem = NULL;
       
   204     CMDBSession* dbs = CMDBSession::NewLC(KCDVersion1_2);
       
   205 
       
   206     // Reveal hidden or private IAP records if a licensee has chosen to protect a record
       
   207     // using one of these flags - the API to do this is public so internal components
       
   208     // have to support the use of such records.
       
   209     dbs->SetAttributeMask( ECDHidden | ECDPrivate );
       
   210 
       
   211     // In all cases with S60 IP TM we want to use the S60 selector.
       
   212     // This means that it's pointless to allow any other selector to run besides CSimpleS60SelectorBase
       
   213     __CFLOG_VAR((KS60TierMgrTag, KS60TierMgrSubTag, _L8("S60MCPR::TIpProviderSelectorFactory::\tNewSelectorL() - Using S60 Simple Selector")));
       
   214     CSimpleS60SelectorBase* ipSelSelf = new (ELeave) CSimpleS60SelectorBase( aSelectionPreferences );
       
   215     selfCleanupItem = ipSelSelf;
       
   216     self = ipSelSelf;
       
   217 
       
   218     CleanupStack::PushL( selfCleanupItem );
       
   219     self->iTierRecord = TierManagerUtils::LoadTierRecordL( TUid::Uid(KAfInet), *dbs );
       
   220     __ASSERT_DEBUG(static_cast<TUint32>(self->iTierRecord->iDefaultAccessPoint)!=0,User::Panic(KS60SelectorPanic,EExpectedAccessPointAwareSystem));
       
   221 
       
   222     CleanupStack::Pop( selfCleanupItem );
       
   223     CleanupStack::Pop( dbs );
       
   224     ASSERT(self->iDbs==NULL);
       
   225     self->iDbs = dbs;
       
   226     return self;
       
   227     }
       
   228