cmmanager/cmmgr/cmmserver/src/cmmcache.cpp
changeset 20 9c97ad6591ae
child 23 7ec726f93df1
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:
       
    15 * Database cache manager.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <cmpluginbaseeng.h>
       
    22 #include <cmdefconnvalues.h>
       
    23 #include <cmpluginembdestinationdef.h>
       
    24 
       
    25 #include <es_sock.h>    // RSocketServ, RConnection
       
    26 #include <in_sock.h>    // KAfInet
       
    27 #include <es_enum.h>    // TConnectionInfo
       
    28 
       
    29 #include "cmmdestinationstruct.h"
       
    30 #include "cmmlistenermanager.h"
       
    31 #include "cmminstancemapping.h"
       
    32 
       
    33 #include "cmmcache.h"
       
    34 
       
    35 #include "cmmdestinationinstance.h"
       
    36 #include "cmmconnmethodinstance.h"
       
    37 
       
    38 #include "cmmtransactionhandler.h"
       
    39 #include "cmmanagerimpl.h"
       
    40 #include "cmmbearerprioritycache.h"
       
    41 
       
    42 #include "OstTraceDefinitions.h"
       
    43 #ifdef OST_TRACE_COMPILER_IN_USE
       
    44 #include "cmmcacheTraces.h"
       
    45 #endif
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Two phased construction.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CCmmCache* CCmmCache::NewL(
       
    53         CCmManagerImpl* aCmManagerImpl,
       
    54         CArrayPtrFlat<const CCmPluginBaseEng>* aPlugins )
       
    55     {
       
    56     OstTraceFunctionEntry0( CCMMCACHE_NEWL_ENTRY );
       
    57 
       
    58     CCmmCache* self = CCmmCache::NewLC( aCmManagerImpl, aPlugins );
       
    59     CleanupStack::Pop( self );
       
    60 
       
    61     OstTraceFunctionExit0( CCMMCACHE_NEWL_EXIT );
       
    62 
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Two phased construction.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CCmmCache* CCmmCache::NewLC(
       
    71         CCmManagerImpl* aCmManagerImpl,
       
    72         CArrayPtrFlat<const CCmPluginBaseEng>* aPlugins )
       
    73     {
       
    74     OstTraceFunctionEntry0( CCMMCACHE_NEWLC_ENTRY );
       
    75 
       
    76     CCmmCache* self = new( ELeave ) CCmmCache( aCmManagerImpl, aPlugins );
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79 
       
    80     OstTraceFunctionExit0( CCMMCACHE_NEWLC_EXIT );
       
    81 
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Destructor.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CCmmCache::~CCmmCache()
       
    90     {
       
    91     OstTraceFunctionEntry0( CCMMCACHE_CCMMCACHE_ENTRY );
       
    92 
       
    93     delete iBearerPriorityCache;
       
    94     delete iListenerManager;
       
    95     delete iInstanceMapping;
       
    96 
       
    97     iConnMethodArray.ResetAndDestroy();
       
    98     iDestinationArray.ResetAndDestroy();
       
    99 
       
   100     iDeletedConnMethods.Close();
       
   101     iUpdatedConnMethods.Close();
       
   102     iUpdatedConnMethods2.Close(); // Does not own contents.
       
   103     iUpdatedDestinations.Close();
       
   104     iUpdatedDestinations2.Close(); // Does not own contents.
       
   105 
       
   106     OstTraceFunctionExit0( CCMMCACHE_CCMMCACHE_EXIT );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Constructor.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 CCmmCache::CCmmCache(
       
   114         CCmManagerImpl* aCmManagerImpl,
       
   115         CArrayPtrFlat<const CCmPluginBaseEng>* aPlugins )
       
   116         :
       
   117         iPlugins( aPlugins ),
       
   118         iCmManagerImpl( aCmManagerImpl )
       
   119     {
       
   120     OstTraceFunctionEntry0( DUP1_CCMMCACHE_CCMMCACHE_ENTRY );
       
   121 
       
   122     iListenerManager = NULL;
       
   123     iInstanceMapping = NULL;
       
   124     iTrans = NULL;
       
   125     iBearerPriorityCache = NULL;
       
   126     iCurrentTemporaryId = KTemporaryIdCounterStart;
       
   127 
       
   128     OstTraceFunctionExit0( DUP1_CCMMCACHE_CCMMCACHE_EXIT );
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Second phase constructor.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CCmmCache::ConstructL()
       
   136     {
       
   137     OstTraceFunctionEntry0( CCMMCACHE_CONSTRUCTL_ENTRY );
       
   138 
       
   139     iTrans = iCmManagerImpl->GetTransactionHandler();
       
   140 
       
   141     iBearerPriorityCache = CCmmBearerPriorityCache::NewL(
       
   142             iTrans,
       
   143             iCmManagerImpl->TableId( ECmmDbBearerPriorityRecord ) );
       
   144     iListenerManager = CCmmListenerManager::NewL( this );
       
   145     iInstanceMapping = CCmmInstanceMapping::NewL( *this );
       
   146 
       
   147     OstTraceFunctionExit0( CCMMCACHE_CONSTRUCTL_EXIT );
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Opens a destination with given ID (if not already opened), then copies the
       
   152 // relevant data to the session instance. Checks that destination ID is valid.
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CCmmCache::OpenDestinationL(
       
   156         CCmmDestinationInstance& aDestinationInstance,
       
   157         const TUint32& aDestinationId )
       
   158     {
       
   159     OstTraceFunctionEntry0( CCMMCACHE_OPENDESTINATIONL_ENTRY );
       
   160 
       
   161     if ( !iInstanceMapping->ValidDestinationId( aDestinationId ) )
       
   162         {
       
   163         User::Leave( KErrNotFound );
       
   164         }
       
   165 
       
   166     TInt index = FindDestinationFromCache( aDestinationId );
       
   167     if ( index == KErrNotFound )
       
   168         {
       
   169         // Cache does not have a handle open to this destination. A new handle
       
   170         // needs to be created first.
       
   171         CCmmDestinationStruct* destination = CCmmDestinationStruct::NewLC(
       
   172                 this,
       
   173                 iTrans,
       
   174                 aDestinationId );
       
   175 
       
   176         // Now that cache has a handle on this destination, copy the relevant
       
   177         // data to the session instance.
       
   178         destination->CreateSessionInstanceL( aDestinationInstance );
       
   179 
       
   180         iDestinationArray.AppendL( destination );
       
   181         CleanupStack::Pop( destination );
       
   182         }
       
   183     else
       
   184         {
       
   185         // Cache already has a handle on this destination. Copy the relevant
       
   186         // data to the session instance.
       
   187         iDestinationArray[index]->CreateSessionInstanceL( aDestinationInstance );
       
   188         }
       
   189 
       
   190     // Add list of currently contained connection methods.
       
   191     iInstanceMapping->GetConnMethodsFromDestinationL(
       
   192             aDestinationId,
       
   193             aDestinationInstance.iConnMethodItemArray );
       
   194 
       
   195     OstTraceFunctionExit0( CCMMCACHE_OPENDESTINATIONL_EXIT );
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Refresh the data contained in aDestinationInstance. This means reloading
       
   200 // the data from database if necessary. After this call the contents of
       
   201 // aDestinationInstance will reflect the current state in the database. 
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CCmmCache::RefreshDestinationL( CCmmDestinationInstance& aDestinationInstance )
       
   205     {
       
   206     OstTraceFunctionEntry0( CCMMCACHE_REFRESHDESTINATIONL_ENTRY );
       
   207 
       
   208     TInt index = FindDestinationFromCache( aDestinationInstance.GetId() );
       
   209     if ( index == KErrNotFound )
       
   210         {
       
   211         index = FindNotSavedDestinationFromCacheL( aDestinationInstance.GetDestinationNameL(), 0 );
       
   212         if ( index == KErrNotFound )
       
   213             {
       
   214             User::Leave( KErrNotFound );
       
   215             }
       
   216         }
       
   217 
       
   218     // If this destination is a newly created one that doesn't yet exist in
       
   219     // database, just return silently.
       
   220     if ( iDestinationArray[index]->GetStatus() == ECmmDestinationStatusNotSaved )
       
   221         {
       
   222         OstTraceFunctionExit0( CCMMCACHE_REFRESHDESTINATIONL_EXIT );
       
   223         return;
       
   224         }
       
   225 
       
   226     iDestinationArray[index]->RefreshDestinationInstanceL( aDestinationInstance );
       
   227 
       
   228     OstTraceFunctionExit0( DUP1_CCMMCACHE_REFRESHDESTINATIONL_EXIT );
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // Create a new destination into cache (with name and ID) and copy the data
       
   233 // into session side handle.
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 void CCmmCache::CreateDestinationL(
       
   237         CCmmDestinationInstance& aDestinationInstance,
       
   238         const TDesC& aName,
       
   239         const TUint32& aId )
       
   240     {
       
   241     OstTraceFunctionEntry0( CCMMCACHE_CREATEDESTINATIONL_ENTRY );
       
   242 
       
   243     // Create a new destination with given name.
       
   244     CCmmDestinationStruct* destination = CCmmDestinationStruct::NewLC( this, iTrans, aName, aId );
       
   245 
       
   246     destination->CreateSessionInstanceL( aDestinationInstance );
       
   247 
       
   248     iDestinationArray.AppendL( destination );
       
   249     CleanupStack::Pop( destination );
       
   250 
       
   251     OstTraceFunctionExit0( CCMMCACHE_CREATEDESTINATIONL_EXIT );
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Opens a connection method with given ID (if not already opened), then
       
   256 // creates and passes an instance of it to the caller.
       
   257 // If aDestinationInstance is not NULL, connection method is opened from
       
   258 // destination.
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CCmmCache::OpenConnMethodL(
       
   262         CCmmConnMethodInstance& aConnMethodInstance,
       
   263         CCmmDestinationInstance* aDestinationInstance,
       
   264         const TUint32& aConnMethodId )
       
   265     {
       
   266     OstTraceFunctionEntry0( CCMMCACHE_OPENCONNMETHODL_ENTRY );
       
   267 
       
   268     // Check connection method ID.
       
   269     TBool validAttributes( EFalse );
       
   270     if ( !aDestinationInstance )
       
   271         {
       
   272         // Check connection method exists in database.
       
   273         validAttributes = iInstanceMapping->ValidConnMethodId( aConnMethodId ); // Embedded destinations not included.
       
   274         }
       
   275     else
       
   276         {
       
   277         // Check connection method is inside the destination.
       
   278         if ( aDestinationInstance->ValidConnMethodIdInDestinationIncludeEmbedded( aConnMethodId ) )
       
   279             {
       
   280             // Check connection method (can be embedded destination too) exists in database.
       
   281             if ( iInstanceMapping->ValidConnMethodId( aConnMethodId ) ||
       
   282                     iInstanceMapping->ValidDestinationId( aConnMethodId ) )
       
   283                 {
       
   284                 validAttributes = ETrue;
       
   285                 }
       
   286             }
       
   287        }
       
   288     if ( !validAttributes )
       
   289         {
       
   290         User::Leave( KErrNotFound );
       
   291         }
       
   292 
       
   293     // Create the connection method instance.
       
   294 
       
   295     // Check if connection method is already opened in cache.
       
   296     TInt index = FindConnMethodFromCache( aConnMethodId );
       
   297     if ( index != KErrNotFound )
       
   298         {
       
   299         // Already open in cache. Copy the connection method data to session
       
   300         // instance.
       
   301         aConnMethodInstance.CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
       
   302         }
       
   303     else
       
   304         {
       
   305         // Not yet open in cache, open now.
       
   306         OpenConnectionMethodInstanceL( aConnMethodInstance, aConnMethodId );
       
   307         }
       
   308 
       
   309     OstTraceFunctionExit0( CCMMCACHE_OPENCONNMETHODL_EXIT );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // Refresh the data contained in aConnMethodInstance. This means reloading the
       
   314 // data from database if necessary. After this call the contents of
       
   315 // aConnMethodInstance will reflect the current state in the database. 
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CCmmCache::RefreshConnMethodL( CCmmConnMethodInstance& aConnMethodInstance )
       
   319     {
       
   320     OstTraceFunctionEntry0( CCMMCACHE_REFRESHCONNMETHODL_ENTRY );
       
   321 
       
   322     //TODO, what to do with embedded?
       
   323 
       
   324     TInt index = FindConnMethodFromCache( aConnMethodInstance.GetId() );
       
   325     if ( index == KErrNotFound )
       
   326         {
       
   327         User::Leave( KErrNotFound );
       
   328         }
       
   329 
       
   330     // If this connection method is a newly created one that doesn't yet exist
       
   331     // in database, just return silently.
       
   332     if ( iConnMethodArray[index]->GetStatus() == ECmmConnMethodStatusNotSaved )
       
   333         {
       
   334         OstTraceFunctionExit0( CCMMCACHE_REFRESHCONNMETHODL_EXIT );
       
   335         return;
       
   336         }
       
   337 
       
   338     iConnMethodArray[index]->RefreshConnMethodInstanceL( aConnMethodInstance );
       
   339 
       
   340     OstTraceFunctionExit0( DUP1_CCMMCACHE_REFRESHCONNMETHODL_EXIT );
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // Creates a new connection method (not embedded destinations) into database
       
   345 // with the given bearer type and optionally ID, then creates and passes an
       
   346 // instance of it to the caller.
       
   347 // If destination instance is provided (not NULL), connection method is
       
   348 // created in that destination.
       
   349 // If connection method ID is provided, it's availability is verified.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CCmmCache::CreateConnMethodL(
       
   353         CCmmConnMethodInstance& aConnMethodInstance,
       
   354         CCmmDestinationInstance* aDestinationInstance,
       
   355         const TUint32& aBearerType,
       
   356         const TUint32& aConnMethodId )
       
   357     {
       
   358     OstTraceFunctionEntry0( CCMMCACHE_CREATECONNMETHODL_ENTRY );
       
   359 
       
   360     // Check that the bearer type is not embedded destination.
       
   361     if ( aBearerType == KUidEmbeddedDestination )
       
   362         {
       
   363         User::Leave( KErrArgument );
       
   364         }
       
   365 
       
   366     TUint32 connMethodId( aConnMethodId );
       
   367     if ( aConnMethodId )
       
   368         {
       
   369         // Check if a connection method with given ID exists (or is already
       
   370         // created but not saved).
       
   371         if ( iInstanceMapping->ValidConnMethodId( aConnMethodId ) ||
       
   372                 ConnMethodOpenWithId( aConnMethodId ) )
       
   373             {
       
   374             User::Leave( KErrAlreadyExists );
       
   375             }
       
   376         }
       
   377     else
       
   378         {
       
   379         // Use a temporary ID until a real one is received from database.
       
   380         connMethodId = NextFreeTemporaryId();
       
   381         }
       
   382 
       
   383 
       
   384     // Check bearer type support and create plugin instance.
       
   385     CCmPluginBaseEng* plugin = NULL;
       
   386     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
   387         {
       
   388         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == aBearerType )
       
   389             {
       
   390             TCmPluginInitParam pluginParams( Session() );
       
   391             plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
       
   392             CleanupStack::PushL( plugin );
       
   393             plugin->CreateNewL( aConnMethodId ); // Use aConnMethodId here, so ID is either a real ID or 0.
       
   394             break;
       
   395             }
       
   396         }
       
   397     if ( !plugin )
       
   398         {
       
   399         User::Leave( KErrArgument );
       
   400         }
       
   401 
       
   402 
       
   403     // Store the connection method into cache.
       
   404     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( connMethodId ); // Use connMethodId here, so ID is either a real ID or a temporary ID.
       
   405     connMethodStruct->SetPlugin( plugin, aBearerType, ECmmConnMethodStatusNotSaved );
       
   406     iConnMethodArray.AppendL( connMethodStruct );
       
   407     CleanupStack::Pop( connMethodStruct );
       
   408     CleanupStack::Pop( plugin ); //TODO, pop after SetPlugin()-call?
       
   409 
       
   410     // Copy the connection method data to session instance.
       
   411     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
       
   412 
       
   413 
       
   414     if ( aDestinationInstance )
       
   415         {
       
   416         // Add connection method to destination.
       
   417         aDestinationInstance->AddConnMethodL( aConnMethodInstance );
       
   418         }
       
   419     OstTraceFunctionExit0( CCMMCACHE_CREATECONNMETHODL_EXIT );
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // Creates a new connection method into cache as a copy of an existing
       
   424 // connection method (exists in cache, not necessarily in database), and opens
       
   425 // a client side handle to it. The new connection method will get a new ID when
       
   426 // updated to database.
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 void CCmmCache::CreateCopyOfConnMethodL(
       
   430         CCmmConnMethodInstance& aNewConnMethodInstance,
       
   431         CCmmConnMethodInstance& aConnMethodInstance )
       
   432     {
       
   433     OstTraceFunctionEntry0( CCMMCACHE_CREATECOPYOFCONNMETHODL_ENTRY );
       
   434 
       
   435     // Check bearer type support and create plugin instance.
       
   436     TInt index = FindConnMethodFromCache( aConnMethodInstance.GetId() );
       
   437     if ( index == KErrNotFound )
       
   438         {
       
   439         User::Leave( index );
       
   440         }
       
   441 
       
   442     CCmPluginBaseEng* plugin = iConnMethodArray[index]->GetPlugin();
       
   443     if ( !plugin )
       
   444         {
       
   445         User::Leave( KErrNotFound );
       
   446         }
       
   447 
       
   448     CCmPluginBaseEng* pluginCopy = plugin->CreateCopyL( aConnMethodInstance.GetPluginDataInstance() );
       
   449     CleanupStack::PushL( pluginCopy );
       
   450 
       
   451     // Store the connection method into cache.
       
   452     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( NextFreeTemporaryId() );
       
   453     connMethodStruct->SetPlugin( pluginCopy, aConnMethodInstance.GetBearerType(), ECmmConnMethodStatusNotSaved );
       
   454     iConnMethodArray.AppendL( connMethodStruct );
       
   455     CleanupStack::Pop( connMethodStruct );
       
   456     CleanupStack::Pop( pluginCopy ); //TODO, pop after SetPlugin()-call?
       
   457 
       
   458     // Copy the connection method data to session instance.
       
   459     aNewConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
       
   460 
       
   461     OstTraceFunctionExit0( CCMMCACHE_CREATECOPYOFCONNMETHODL_EXIT );
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // Re-loads a destination record if needed and copies the latest version to
       
   466 // the session instance given as parameter.
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CCmmCache::LoadDestinationRecordL(
       
   470         CCmmDestinationInstance& aDestinationInstance,
       
   471         TCmmDbRecords aDestRecordType )
       
   472     {
       
   473     OstTraceFunctionEntry0( CCMMCACHE_LOADDESTINATIONRECORDL_ENTRY );
       
   474 
       
   475     TUint32 id = aDestinationInstance.GetId();
       
   476     // If ID is not in the valid range, it means the destination is a newly
       
   477     // created one, and doesn't yet exist in database. Thus, record data exists
       
   478     // only in session side and can't be loaded from cache. So this is an error.
       
   479     if ( id >= KTemporaryIdCounterStart )
       
   480         {
       
   481         User::Leave( KErrCorrupt );
       
   482         }
       
   483     TInt index = FindDestinationFromCache( id );
       
   484     if ( index < 0 )
       
   485         {
       
   486         User::Leave( index );
       
   487         }
       
   488 
       
   489     iDestinationArray[index]->LoadRecordL( aDestinationInstance, aDestRecordType );
       
   490 
       
   491     OstTraceFunctionExit0( CCMMCACHE_LOADDESTINATIONRECORDL_EXIT );
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // Saves the modifications in aDestinationInstance into the database. Also all
       
   496 // connection methods inside this destination are updated (including any
       
   497 // embedded destination).
       
   498 // ---------------------------------------------------------------------------
       
   499 //
       
   500 void CCmmCache::UpdateDestinationL( CCmmDestinationInstance& aDestinationInstance )
       
   501     {
       
   502     OstTraceFunctionEntry0( CCMMCACHE_UPDATEDESTINATIONL_ENTRY );
       
   503 
       
   504     // Arrays to temporarily store information of updated destinations and
       
   505     // connection methods. Used to update status and ID information after
       
   506     // successful commit to database.
       
   507     if ( iTrans->GetReferenceCount() == 0 )
       
   508         {
       
   509         iDeletedConnMethods.Reset();
       
   510         iUpdatedConnMethods.Reset();
       
   511         iUpdatedConnMethods2.Reset();
       
   512         iUpdatedDestinations.Reset();
       
   513         iUpdatedDestinations2.Reset();
       
   514         }
       
   515 
       
   516     TInt index = FindDestinationFromCache( aDestinationInstance.GetId() );
       
   517     if ( index < 0 )
       
   518         {
       
   519         User::Leave( index );
       
   520         }
       
   521 
       
   522     iTrans->OpenTransactionLC();
       
   523 
       
   524     // Check that the connection methods marked for deletion can be deleted.
       
   525     for ( TInt i = 0; i < aDestinationInstance.iConnMethodsToBeDeleted.Count(); i++ )
       
   526         {
       
   527         TUint32 id = aDestinationInstance.iConnMethodsToBeDeleted[i];
       
   528 
       
   529         // Remove connection method from delete list if ID is not valid or if
       
   530         // referenced from any other destination (in database or in any other
       
   531         // client-side destination handles).
       
   532         if ( !iInstanceMapping->ValidConnMethodId( id ) ||
       
   533                 iInstanceMapping->ConnMethodInOtherDestination( id, aDestinationInstance.GetId() ) ||
       
   534                 aDestinationInstance.ConnMethodInOtherDestinationInSession( id, 0 ) )
       
   535             {
       
   536             aDestinationInstance.iConnMethodsToBeDeleted.Remove( i );
       
   537             i--; // Adjust array index counter.
       
   538             }
       
   539         else if ( iInstanceMapping->ConnMethodPointedToByVirtualIap( id ) )
       
   540             {
       
   541             aDestinationInstance.iConnMethodsToBeDeleted.Remove( i );
       
   542             User::Leave( KErrLocked );
       
   543             }
       
   544         else if ( CheckIfCmConnected( id ) )
       
   545             {
       
   546             User::Leave( KErrInUse );
       
   547             }
       
   548         }
       
   549     // Delete connection methods marked for deletion.
       
   550     for ( TInt i = 0; i < aDestinationInstance.iConnMethodsToBeDeleted.Count(); i++ )
       
   551         {
       
   552         DeleteConnMethodAsPartOfDestinationUpdateL(
       
   553                 aDestinationInstance.iConnMethodsToBeDeleted[i] );
       
   554         }
       
   555 
       
   556     // Update the connection methods inside this destination.
       
   557     for ( TInt i = 0; i < aDestinationInstance.iConnMethodItemArray.Count(); i++ )
       
   558         {
       
   559         if ( aDestinationInstance.iConnMethodItemArray[i].iBearerType == KUidEmbeddedDestination )
       
   560             {
       
   561             // Embedded destination.
       
   562 
       
   563             //TODO, Maybe check other restrictions on embedded destination.
       
   564             // - Only one embedded destination per destination. Check.
       
   565             // - No embedded destinations in embedded destination. Check.
       
   566 
       
   567             TUint32 id( aDestinationInstance.iConnMethodItemArray[i].iId );
       
   568             CCmmDestinationInstance* destinationInstance =
       
   569                     aDestinationInstance.FindDestinationInstanceFromSessionById( id );
       
   570 
       
   571             if ( destinationInstance )
       
   572                 {
       
   573                 // Client has a handle open to this destination, update it.
       
   574                 destinationInstance->UpdateL();
       
   575                 }
       
   576             else
       
   577                 {
       
   578                 // TODO: Or, should we update the embedded destination if the
       
   579                 // client has an open handle to any of the embedded
       
   580                 // destinations connection methods.
       
   581                 //
       
   582                 // Skip update since client doesn't have an open handle to this
       
   583                 // destination.
       
   584                 if ( id >= KTemporaryIdCounterStart || !iInstanceMapping->ValidDestinationId( id ) )
       
   585                     {
       
   586                     // Remove destination item from array if:
       
   587                     // - New destination, but client has already closed the handle for it.
       
   588                     // - Destination ID was valid before, but it does not exist anymore.
       
   589                     aDestinationInstance.iConnMethodItemArray.Remove( i );
       
   590                     i--; // Adjust array index counter.
       
   591                     }
       
   592                 }
       
   593             }
       
   594         else
       
   595             {
       
   596             TBool temporaryConnMethodInstance( EFalse );
       
   597             TBool connMethodProtectionMustBeSet( EFalse );
       
   598             TBool cmProtected( EFalse );
       
   599 
       
   600             TUint32 id( aDestinationInstance.iConnMethodItemArray[i].iId );
       
   601             CCmmConnMethodInstance* connMethodInstance =
       
   602                     aDestinationInstance.FindConnMethodInstanceFromSessionById( id );
       
   603 
       
   604             if ( !connMethodInstance )
       
   605                 {
       
   606                 // Remove connection method item from the array if it is a new
       
   607                 // connection method but client has already closed the handle
       
   608                 // for it, or the connection method ID was valid before but
       
   609                 // does not exist anymore.
       
   610                 if ( id >= KTemporaryIdCounterStart || !iInstanceMapping->ValidConnMethodId( id ) )
       
   611                     {
       
   612                     aDestinationInstance.iConnMethodItemArray.Remove( i );
       
   613                     i--; // Adjust array index counter.
       
   614                     continue; // Jump to next connection method.
       
   615                     }
       
   616                 }
       
   617 
       
   618             if ( aDestinationInstance.ProtectionChanged() )
       
   619                 {
       
   620                 // Check if the connection method protection level needs to be set.
       
   621                 switch ( aDestinationInstance.CurrentProtectionLevel() )
       
   622                     {
       
   623                     case CMManager::EProtLevel0:
       
   624                     case CMManager::EProtLevel2:
       
   625                         {
       
   626                         if ( aDestinationInstance.LastProtectionLevel() == CMManager::EProtLevel1 ||
       
   627                                 aDestinationInstance.LastProtectionLevel() == CMManager::EProtLevel3 )
       
   628                             {
       
   629                             connMethodProtectionMustBeSet = ETrue;
       
   630                             cmProtected = EFalse;
       
   631                             }
       
   632                         }
       
   633                         break;
       
   634                     case CMManager::EProtLevel1:
       
   635                     case CMManager::EProtLevel3:
       
   636                         {
       
   637                         connMethodProtectionMustBeSet = ETrue;
       
   638                         cmProtected = ETrue;
       
   639                         }
       
   640                         break;
       
   641                     default:
       
   642                         break;
       
   643                     }
       
   644                 }
       
   645 
       
   646             if ( connMethodProtectionMustBeSet && !connMethodInstance )
       
   647                 {
       
   648                 // Client doesn't have an open handle to this connection method,
       
   649                 // but it still needs to be updated because the destination's
       
   650                 // protection level has been changed in such a way that
       
   651                 // requires a change in all contained connection methods also.
       
   652                 temporaryConnMethodInstance = ETrue;
       
   653                 connMethodInstance = CCmmConnMethodInstance::NewLC( NULL, this );
       
   654                 OpenConnMethodL( *connMethodInstance, NULL, id );
       
   655 
       
   656                 // Read current protection level.
       
   657                 TBool current = connMethodInstance->GetBoolAttributeL( CMManager::ECmProtected );
       
   658                 if ( cmProtected == current )
       
   659                     {
       
   660                     // If the connection method already has the correct
       
   661                     // protection setting, skip the unnecessary update.
       
   662                     connMethodProtectionMustBeSet = EFalse;
       
   663                     temporaryConnMethodInstance = EFalse;
       
   664                     CleanupStack::PopAndDestroy( connMethodInstance );
       
   665                     connMethodInstance = NULL;
       
   666                     }
       
   667                 }
       
   668 
       
   669             // Update the connection method.
       
   670             if ( connMethodInstance )
       
   671                 {
       
   672                 if ( connMethodProtectionMustBeSet )
       
   673                     {
       
   674                     connMethodInstance->SetBoolAttributeL( CMManager::ECmProtected, cmProtected );
       
   675                     }
       
   676                 connMethodInstance->UpdateL( temporaryConnMethodInstance );
       
   677                 }
       
   678 
       
   679             // Cleanup connection method handle, if it was temporary.
       
   680             if ( temporaryConnMethodInstance )
       
   681                 {
       
   682                 CleanupStack::PopAndDestroy( connMethodInstance );
       
   683                 }
       
   684             connMethodInstance = NULL;
       
   685             }
       
   686         }
       
   687     // All connection methods requiring update in the destination should have
       
   688     // been updated to database now.
       
   689 
       
   690     iDestinationArray[index]->UpdateL( aDestinationInstance, this );
       
   691     iTrans->CommitTransactionL();
       
   692 
       
   693     TCmmIdStruct idStruct( iDestinationArray[index]->GetRealId(), 0 );
       
   694     if ( aDestinationInstance.GetId() >= KTemporaryIdCounterStart )
       
   695         {
       
   696         idStruct.iTemporaryId = aDestinationInstance.GetId();
       
   697         }
       
   698     iUpdatedDestinations.AppendL( idStruct );
       
   699     iUpdatedDestinations2.AppendL( &aDestinationInstance );
       
   700 
       
   701     // Check transaction handler reference count.
       
   702     if ( iTrans->GetReferenceCount() == 0 )
       
   703         {
       
   704         // Successful commit to database. Refresh instance mapping and all
       
   705         // necessary status information.
       
   706         for ( TInt i = 0; i < iUpdatedConnMethods.Count(); i++ )
       
   707             {
       
   708             aDestinationInstance.RefreshHandlesForAllSessions( iUpdatedConnMethods[i] );
       
   709             }
       
   710         for ( TInt i = 0; i < iUpdatedConnMethods2.Count(); i++ )
       
   711             {
       
   712             iUpdatedConnMethods2[i]->UpdateSuccessful();
       
   713 
       
   714             TInt cacheIndex = FindConnMethodFromCache( iUpdatedConnMethods2[i]->GetId() );
       
   715             if ( cacheIndex >= 0 )
       
   716                 {
       
   717                 iConnMethodArray[cacheIndex]->UpdateSuccessful();
       
   718                 }
       
   719             }
       
   720         for ( TInt i = 0; i < iDeletedConnMethods.Count(); i++ )
       
   721             {
       
   722             TInt cacheIndex = FindConnMethodFromCache( iDeletedConnMethods[i].iRealId );
       
   723             if ( cacheIndex >= 0 )
       
   724                 {
       
   725                 aDestinationInstance.RefreshHandlesForAllSessions( iDeletedConnMethods[i] );
       
   726                 iConnMethodArray[cacheIndex]->SetStatus( ECmmConnMethodStatusToBeDeleted );
       
   727                 iInstanceMapping->AddConnMethodToDeletedListL( iDeletedConnMethods[i].iRealId );
       
   728                 }
       
   729             }
       
   730         for ( TInt i = 0; i < iUpdatedDestinations.Count(); i++ )
       
   731             {
       
   732             aDestinationInstance.RefreshHandlesForAllSessions( iUpdatedDestinations[i] );
       
   733             }
       
   734         for ( TInt i = 0; i < iUpdatedDestinations2.Count(); i++ )
       
   735             {
       
   736             iUpdatedDestinations2[i]->UpdateSuccessful();
       
   737 
       
   738             TInt cacheIndex = FindDestinationFromCache( iUpdatedDestinations2[i]->GetId() );
       
   739             if ( cacheIndex >= 0 )
       
   740                 {
       
   741                 iDestinationArray[cacheIndex]->UpdateSuccessful();
       
   742                 }
       
   743             }
       
   744         iDeletedConnMethods.Reset();
       
   745         iUpdatedConnMethods.Reset();
       
   746         iUpdatedConnMethods2.Reset();
       
   747         iUpdatedDestinations.Reset();
       
   748         iUpdatedDestinations2.Reset();
       
   749 
       
   750         iInstanceMapping->RefreshL();
       
   751         }
       
   752 
       
   753     OstTraceFunctionExit0( CCMMCACHE_UPDATEDESTINATIONL_EXIT );
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // Saves the modifications in aConnMethodInstance into database.
       
   758 // The second attribute aTemporaryHandle must be true if the connection method
       
   759 // instance is only a temporary one created for the duration of this update
       
   760 // process only.
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 void CCmmCache::UpdateConnMethodL(
       
   764         CCmmConnMethodInstance& aConnMethodInstance,
       
   765         TBool aTemporaryHandle )
       
   766     {
       
   767     OstTraceFunctionEntry0( CCMMCACHE_UPDATECONNMETHODL_ENTRY );
       
   768 
       
   769     // Find connection method from cache.
       
   770     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
   771     TInt index = FindConnMethodFromCache( connMethodId );
       
   772     if ( index < 0 )
       
   773         {
       
   774         // Should never end up here.
       
   775         User::Leave( index );
       
   776         }
       
   777 
       
   778     iTrans->OpenTransactionLC();
       
   779     iConnMethodArray[index]->GetPlugin()->UpdateL( aConnMethodInstance.GetPluginDataInstance() );
       
   780     iTrans->CommitTransactionL();
       
   781 
       
   782     TCmmIdStruct idStruct( aConnMethodInstance.GetPluginDataInstance()->iIapId, 0 );
       
   783     if ( connMethodId >= KTemporaryIdCounterStart )
       
   784         {
       
   785         idStruct.iTemporaryId = connMethodId;
       
   786         }
       
   787 
       
   788     if ( iTrans->GetReferenceCount() == 0 )
       
   789         {
       
   790         // Writing to database is completed, refresh instance mapping and all
       
   791         // necessary status information.
       
   792         iInstanceMapping->RefreshL();
       
   793         aConnMethodInstance.RefreshHandlesForAllSessions( idStruct );
       
   794         aConnMethodInstance.UpdateSuccessful();
       
   795         iConnMethodArray[index]->UpdateSuccessful();
       
   796         }
       
   797     else
       
   798         {
       
   799         // Update request came from destination update. Add connection method
       
   800         // information to temporary arrays so it's status information can be
       
   801         // updated after successful commit to database.
       
   802         iUpdatedConnMethods.AppendL( idStruct );
       
   803         if ( !aTemporaryHandle )
       
   804             {
       
   805             // A temporary handle will be destroyed after update, and so won't
       
   806             // need any status updates after commit.
       
   807             iUpdatedConnMethods2.AppendL( &aConnMethodInstance );
       
   808             }
       
   809         }
       
   810 
       
   811     OstTraceFunctionExit0( CCMMCACHE_UPDATECONNMETHODL_EXIT );
       
   812     }
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // Deletes the destination refered by aDestinationInstance from the database.
       
   816 // In case other sessions have open handles to the same destination, the status
       
   817 // is updated to deleted state, but it is not yet removed from database.
       
   818 // (ID must be kept reserved in commsdat until all handles are closed). The
       
   819 // same is done for the connection methods inside this destination.
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 void CCmmCache::DeleteDestinationL( CCmmDestinationInstance& aDestinationInstance, TBool aForced )
       
   823     {
       
   824     OstTraceFunctionEntry0( CCMMCACHE_DELETEDESTINATIONL_ENTRY );
       
   825 
       
   826     TUint32 destinationId( aDestinationInstance.GetId() );
       
   827 
       
   828     // Array to temporarily store deleted connection method IDs. Status
       
   829     // information for these connection methods is updated after successful
       
   830     // commit to database.
       
   831     iDeletedConnMethods.Reset();
       
   832 
       
   833     // Find destination from cache.
       
   834     TInt index = FindDestinationFromCache( destinationId );
       
   835     if ( index == KErrNotFound )
       
   836         {
       
   837         User::Leave( KErrBadHandle );
       
   838         }
       
   839 
       
   840     // If not forced, check if the destination is already marked to be deleted.
       
   841     if ( !aForced && iDestinationArray[index]->GetStatus() == ECmmDestinationStatusToBeDeleted )
       
   842         {
       
   843         OstTraceFunctionExit0( CCMMCACHE_DELETEDESTINATIONL_EXIT );
       
   844         return;
       
   845         }
       
   846 
       
   847     // Check if there are any additional handles open. If yes, can't delete
       
   848     // detination from database just yet.
       
   849     if ( iDestinationArray[index]->GetReferenceCount() <= 1 )
       
   850         {
       
   851         // No other client handles open to this destination.
       
   852 
       
   853         // Get the connection methods in this destination, and then go through
       
   854         // them removing those that can't be deleted.
       
   855         RArray<TCmmConnMethodItem> connMethodArray;
       
   856         CleanupClosePushL( connMethodArray );
       
   857         if ( !aForced )
       
   858             {
       
   859             iInstanceMapping->GetConnMethodsFromDestinationL( destinationId, connMethodArray );
       
   860             }
       
   861         else
       
   862             {
       
   863             for ( TInt i = 0; i < aDestinationInstance.iConnMethodItemArray.Count() ; i++ )
       
   864                 {
       
   865                 connMethodArray.AppendL( aDestinationInstance.iConnMethodItemArray[i] );
       
   866                 }
       
   867             }
       
   868 
       
   869         // Remove embedded destination from list if found.
       
   870         TInt count( connMethodArray.Count() );
       
   871         if ( count )
       
   872             {
       
   873             if ( connMethodArray[count - 1].iBearerType == KUidEmbeddedDestination )
       
   874                 {
       
   875                 connMethodArray.Remove( count - 1 );
       
   876                 }
       
   877             }
       
   878         // Remove any connection method that belongs to any other destination.
       
   879         for ( TInt i = 0; i < connMethodArray.Count(); i++ )
       
   880             {
       
   881             if ( iInstanceMapping->ConnMethodInOtherDestination( connMethodArray[i].iId, destinationId ) )
       
   882                 {
       
   883                 connMethodArray.Remove( i );
       
   884                 i--;
       
   885                 }
       
   886             }
       
   887         // Remove any connection method that has a virtual IAP pointing to it.
       
   888         for ( TInt i = 0; i < connMethodArray.Count(); i++ )
       
   889             {
       
   890             if ( iInstanceMapping->ConnMethodPointedToByVirtualIap( connMethodArray[i].iId ) )
       
   891                 {
       
   892                 connMethodArray.Remove( i );
       
   893                 i--;
       
   894                 }
       
   895             }
       
   896 
       
   897         iTrans->OpenTransactionLC();
       
   898 
       
   899         // Delete each connection method inside this destination.
       
   900         for ( TInt i = 0; i < connMethodArray.Count(); i++ )
       
   901             {
       
   902             DeleteConnMethodAsPartOfDestinationDeleteL( connMethodArray[i].iId );
       
   903             }
       
   904 
       
   905         // Delete the destination.
       
   906         iDestinationArray[index]->DeleteL();
       
   907 
       
   908         iTrans->CommitTransactionL();
       
   909         CleanupStack::PopAndDestroy( &connMethodArray );
       
   910 
       
   911         for ( TInt i = 0; i < iDeletedConnMethods.Count(); i++ )
       
   912             {
       
   913             TInt index = FindConnMethodFromCache( iDeletedConnMethods[i].iRealId );
       
   914             if ( index == KErrNotFound )
       
   915                 {
       
   916                 // No handles open to this deleted connection method, so it was
       
   917                 // removed from database. Remove it from instance mapping
       
   918                 // structures. Refreshing instance mapping would do the same,
       
   919                 // but more slowly.
       
   920                 iInstanceMapping->RemoveConnMethod( iDeletedConnMethods[i].iRealId );
       
   921                 }
       
   922             else
       
   923                 {
       
   924                 // There is at least one handle open to this deleted connection
       
   925                 // method, so it still exists in database for now. Remove it
       
   926                 // from instance mapping structures and add it to the instance
       
   927                 // mapping's deleted list, so the connection method is ignored
       
   928                 // if refreshing structures from database. Also mark the
       
   929                 // connection method handle on cache side as 'to be deleted'.
       
   930                 //
       
   931                 // If the connection method is updated from another existing
       
   932                 // handle after this, the connection method is restored as
       
   933                 // uncategorized.
       
   934                 iInstanceMapping->AddConnMethodToDeletedListL( iDeletedConnMethods[i].iRealId );
       
   935                 aDestinationInstance.RefreshHandlesForAllSessions( iDeletedConnMethods[i] );
       
   936                 iConnMethodArray[index]->SetStatus( ECmmConnMethodStatusToBeDeleted );
       
   937                 }
       
   938             }
       
   939         iInstanceMapping->RemoveDestination( destinationId );
       
   940         }
       
   941     else
       
   942         {
       
   943         // There are additional client handles open to this destination. Mark
       
   944         // the destination as 'to be deleted'. When the other handles are
       
   945         // closed and reference count goes to 0, the destination will be
       
   946         // removed from database.
       
   947         // If the destination is updated from another existing handle after
       
   948         // this, the destination is restored to normal.
       
   949         iDestinationArray[index]->SetStatus( ECmmDestinationStatusToBeDeleted );
       
   950         iInstanceMapping->AddDestinationToDeletedListL( destinationId );
       
   951         }
       
   952 
       
   953     // Update status for ALL related destination handles on client side to
       
   954     // ECmmDestinationStatusChanged.
       
   955     TCmmIdStruct idStruct( destinationId, 0 );
       
   956     aDestinationInstance.RefreshHandlesForAllSessions( idStruct );
       
   957 
       
   958     iDeletedConnMethods.Reset();
       
   959     OstTraceFunctionExit0( DUP1_CCMMCACHE_DELETEDESTINATIONL_EXIT );
       
   960     }
       
   961 
       
   962 // ---------------------------------------------------------------------------
       
   963 // Deletes a connection method as part of destination delete operation. It is
       
   964 // already checked that the connection method given as parameter can be deleted
       
   965 // and a transaction is already open.
       
   966 // If there are client side handles open to the connection method, the
       
   967 // connection method is marked as deleted, but the actual database removal will
       
   968 // be done after the last handle is closed. Updating a connection method marked
       
   969 // as deleted (through an already open handle) will restore it.
       
   970 // ---------------------------------------------------------------------------
       
   971 //
       
   972 void CCmmCache::DeleteConnMethodAsPartOfDestinationDeleteL( const TUint32& aConnMethodId )
       
   973     {
       
   974     OstTraceFunctionEntry0( CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONDELETEL_ENTRY );
       
   975 
       
   976     // Find connection method from cache side.
       
   977     TInt index = FindConnMethodFromCache( aConnMethodId );
       
   978     if ( index == KErrNotFound )
       
   979         {
       
   980         // There is no open handles to this connection method. Open a temporary
       
   981         // handle and delete it.
       
   982 
       
   983         // Find out the connection method bearer type.
       
   984         TUint32 bearerType( 0 );
       
   985         TInt err = iInstanceMapping->GetConnMethodBearerType( aConnMethodId, bearerType );
       
   986         if ( err || bearerType == KUidEmbeddedDestination )
       
   987             {
       
   988             // If this is an embedded destination, or the bearer is not
       
   989             // supported, skip. The connection method is simply removed from
       
   990             // destination.
       
   991             OstTraceFunctionExit0( CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONDELETEL_EXIT );
       
   992             return;
       
   993             }
       
   994 
       
   995         // Check bearer type support, create plugin instance and delete the
       
   996         // connection method.
       
   997         CCmPluginBaseEng* plugin = NULL;
       
   998         for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
   999             {
       
  1000             if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == bearerType )
       
  1001                 {
       
  1002                 TCmPluginInitParam pluginParams( Session() );
       
  1003                 plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
       
  1004                 CleanupStack::PushL( plugin );
       
  1005 
       
  1006                 // Transaction is already open.
       
  1007                 plugin->LoadL( aConnMethodId );
       
  1008                 plugin->DeleteL();
       
  1009 
       
  1010                 CleanupStack::Pop( plugin );
       
  1011                 break;
       
  1012                 }
       
  1013             }
       
  1014         if ( !plugin )
       
  1015             {
       
  1016             // Skip, if bearer is unsupported. Connection method is simply
       
  1017             // removed from destination.
       
  1018             OstTraceFunctionExit0( DUP1_CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONDELETEL_EXIT );
       
  1019             return;
       
  1020             }
       
  1021         delete plugin;
       
  1022         plugin = NULL;
       
  1023         }
       
  1024     else
       
  1025         {
       
  1026         // If the connection method is already open in cache side, we can't
       
  1027         // delete it from database just yet. It will only be marked as 'to be
       
  1028         // deleted' after a successful commit. When the other handles are
       
  1029         // closed and reference count goes to 0, the connection method will be
       
  1030         // removed from database.
       
  1031 
       
  1032         // Check destination status in cache.
       
  1033         switch ( iConnMethodArray[index]->GetStatus() )
       
  1034             {
       
  1035             case ECmmConnMethodStatusNotSaved:
       
  1036                 {
       
  1037                 // The connection methods that are deleted with the destination
       
  1038                 // are retrieved through instance mapping, so there can't be
       
  1039                 // any newly created unsaved connection methods among them.
       
  1040                 User::Leave( KErrCorrupt );
       
  1041                 }
       
  1042                 break;
       
  1043             case ECmmConnMethodStatusValid:
       
  1044                 // Proceed.
       
  1045                 break;
       
  1046             case ECmmConnMethodStatusToBeDeleted:
       
  1047                 // Connection method has already been deleted.
       
  1048                 return;
       
  1049             case ECmmConnMethodStatusChanged:
       
  1050             default:
       
  1051                 {
       
  1052                 ASSERT( 0 ); // Error, illegal status.
       
  1053                 User::Leave( KErrCorrupt );
       
  1054                 }
       
  1055                 break;
       
  1056             }
       
  1057         }
       
  1058 
       
  1059     // Add connection method ID to temporary array so it's status information
       
  1060     // can be updated after successful commit to database.
       
  1061     TCmmIdStruct idStruct( aConnMethodId, 0 );
       
  1062     iDeletedConnMethods.AppendL( idStruct );
       
  1063 
       
  1064     OstTraceFunctionExit0( DUP2_CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONDELETEL_EXIT );
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------------------------
       
  1068 // Deletes a connection method as part of destination update operation. It is
       
  1069 // already checked that the connection method given as parameter can be deleted
       
  1070 // and a transaction is already open.
       
  1071 // If there are client side handles open to the connection method, the
       
  1072 // connection method is marked as deleted, but the actual database removal will
       
  1073 // be done after the last handle is closed. Updating a connection method marked
       
  1074 // as deleted (through an already open handle) will restore it.
       
  1075 // ---------------------------------------------------------------------------
       
  1076 //
       
  1077 void CCmmCache::DeleteConnMethodAsPartOfDestinationUpdateL(
       
  1078         const TUint32& aConnMethodId )
       
  1079     {
       
  1080     OstTraceFunctionEntry0( CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONUPDATEL_ENTRY );
       
  1081 
       
  1082     // Find connection method from cache side. If not found, open a temporary handle.
       
  1083     TInt index = FindConnMethodFromCache( aConnMethodId );
       
  1084     if ( index == KErrNotFound )
       
  1085         {
       
  1086         // There are no open handles to this connection method. Open a
       
  1087         // temporary handle and delete it.
       
  1088 
       
  1089         // Find out the connection method bearer type.
       
  1090         TUint32 bearerType( 0 );
       
  1091         TInt err = iInstanceMapping->GetConnMethodBearerType( aConnMethodId, bearerType );
       
  1092         if ( err || bearerType == KUidEmbeddedDestination )
       
  1093             {
       
  1094             // If this is an embedded destination, or the bearer is not
       
  1095             // supported, skip. The connection method is simply removed from
       
  1096             // destination.
       
  1097             OstTraceFunctionExit0( CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONUPDATEL_EXIT );
       
  1098             return;
       
  1099             }
       
  1100 
       
  1101         // Check bearer type support, create plugin instance and delete the connection method.
       
  1102         CCmPluginBaseEng* plugin = NULL;
       
  1103         for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  1104             {
       
  1105             if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == bearerType )
       
  1106                 {
       
  1107                 TCmPluginInitParam pluginParams( Session() );
       
  1108                 plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
       
  1109                 CleanupStack::PushL( plugin );
       
  1110                 iTrans->OpenTransactionLC();
       
  1111 
       
  1112                 plugin->LoadL( aConnMethodId );
       
  1113                 plugin->DeleteL();
       
  1114 
       
  1115                 iTrans->CommitTransactionL();
       
  1116                 CleanupStack::Pop( plugin );
       
  1117                 break;
       
  1118                 }
       
  1119             }
       
  1120         if ( !plugin )
       
  1121             {
       
  1122             // Skip, if bearer is unsupported. Connection method is simply
       
  1123             // removed from destination.
       
  1124             OstTraceFunctionExit0( DUP1_CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONUPDATEL_EXIT );
       
  1125             return;
       
  1126             }
       
  1127         delete plugin;
       
  1128         plugin = NULL;
       
  1129 
       
  1130         // Destination update will refresh instance mapping anyway at the end,
       
  1131         // so no need to add this connection method to the temporary
       
  1132         // iDeletedConnMethods-array here.
       
  1133         }
       
  1134     else
       
  1135         {
       
  1136         // There is one or more open handles to this connection method. We
       
  1137         // can't delete it from database just yet. It will only be marked as
       
  1138         // 'to be deleted' after a successful commit. When the other handles
       
  1139         // are closed and reference count goes to 0, the connection method will
       
  1140         // be removed from database.
       
  1141 
       
  1142         // Check connection method status.
       
  1143         switch ( iConnMethodArray[index]->GetStatus() )
       
  1144             {
       
  1145             case ECmmConnMethodStatusNotSaved:
       
  1146                 {
       
  1147                 // Destination update will not attempt to delete any non-valid
       
  1148                 // connection methods.
       
  1149                 User::Leave( KErrCorrupt );
       
  1150                 }
       
  1151                 break;
       
  1152             case ECmmConnMethodStatusValid:
       
  1153                 // Proceed.
       
  1154                 break;
       
  1155             case ECmmConnMethodStatusToBeDeleted:
       
  1156                 // Connection method has already been deleted.
       
  1157                 return;
       
  1158             case ECmmConnMethodStatusChanged:
       
  1159             default:
       
  1160                 {
       
  1161                 ASSERT( 0 ); // Error, illegal status.
       
  1162                 User::Leave( KErrCorrupt );
       
  1163                 }
       
  1164                 break;
       
  1165             }
       
  1166         // Add connection method ID to temporary array so it's status
       
  1167         // information can be updated after successful commit to database.
       
  1168         TCmmIdStruct idStruct( aConnMethodId, 0 );
       
  1169         iDeletedConnMethods.AppendL( idStruct );
       
  1170         }
       
  1171 
       
  1172     OstTraceFunctionExit0( DUP2_CCMMCACHE_DELETECONNMETHODASPARTOFDESTINATIONUPDATEL_EXIT );
       
  1173     }
       
  1174 
       
  1175 // ---------------------------------------------------------------------------
       
  1176 // Basic connection method delete. Removes a connection method from any
       
  1177 // destination it might belong to, and then deletes it.
       
  1178 // ---------------------------------------------------------------------------
       
  1179 //
       
  1180 void CCmmCache::DeleteConnMethodL( CCmmConnMethodInstance& aConnMethodInstance )
       
  1181     {
       
  1182     OstTraceFunctionEntry0( DUP1_CCMMCACHE_DELETECONNMETHODL_ENTRY );
       
  1183 
       
  1184     TUint32 cmId = aConnMethodInstance.GetId();
       
  1185 
       
  1186     // Find connection method from cache.
       
  1187     TInt index = FindConnMethodFromCache( cmId );
       
  1188     if ( index == KErrNotFound )
       
  1189         {
       
  1190         User::Leave( KErrBadHandle );
       
  1191         }
       
  1192 
       
  1193     // Check if the connection method is already deleted.
       
  1194     if ( iConnMethodArray[index]->GetStatus() == ECmmConnMethodStatusToBeDeleted )
       
  1195         {
       
  1196         OstTraceFunctionExit0( DUP1_CCMMCACHE_DELETECONNMETHODL_EXIT );
       
  1197         return;
       
  1198         }
       
  1199 
       
  1200     // Check if there are any additional handles open. If yes, can't delete
       
  1201     // connection method from database just yet.
       
  1202     if ( iConnMethodArray[index]->GetReferenceCounter() <= 1 )
       
  1203         {
       
  1204         // No other client handles open to this connection method.
       
  1205 
       
  1206         // Remove connection method from any destination in database and then delete it.
       
  1207         iTrans->OpenTransactionLC();
       
  1208         RemoveAllReferencesToConnMethodL( aConnMethodInstance );
       
  1209         iConnMethodArray[index]->GetPlugin()->DeleteL();
       
  1210         iTrans->CommitTransactionL();
       
  1211 
       
  1212         // Update instance mapping to reflect the current database state, and
       
  1213         // notify any possible client handles for the changed destinations.
       
  1214         RArray<TUint32> changedDestinations;
       
  1215         iInstanceMapping->RemoveConnMethod( cmId, changedDestinations );
       
  1216         for ( TInt i = 0; i < changedDestinations.Count(); i++ )
       
  1217             {
       
  1218             TCmmIdStruct idStruct( changedDestinations[i], 0 );
       
  1219             aConnMethodInstance.RefreshHandlesForAllSessions( idStruct );
       
  1220             }
       
  1221         changedDestinations.Close();
       
  1222 
       
  1223         // Set status for cache and client handles.
       
  1224         TUint32 newSecondaryId( NextFreeTemporaryId() );
       
  1225         aConnMethodInstance.DeleteSuccessful( newSecondaryId );
       
  1226         iConnMethodArray[index]->DeleteSuccessful( newSecondaryId );
       
  1227         }
       
  1228     else
       
  1229         {
       
  1230         // There are additional client handles open to this connection method.
       
  1231         // Mark the connection method as 'to be deleted' and remove it from any
       
  1232         // destinations in database. When the other handles are closed and
       
  1233         // reference count goes to 0, the connection method will be removed
       
  1234         // from database.
       
  1235         RemoveAllReferencesToConnMethodL( aConnMethodInstance );
       
  1236         iInstanceMapping->AddConnMethodToDeletedListL( cmId );
       
  1237         TCmmIdStruct idStruct( cmId, 0 );
       
  1238         aConnMethodInstance.RefreshHandlesForAllSessions( idStruct );
       
  1239         iConnMethodArray[index]->SetStatus( ECmmConnMethodStatusToBeDeleted );
       
  1240         }
       
  1241 
       
  1242     OstTraceFunctionExit0( DUP2_CCMMCACHE_DELETECONNMETHODL_EXIT );
       
  1243     }
       
  1244 
       
  1245 // ---------------------------------------------------------------------------
       
  1246 // Check if the given ID belongs to a valid existing destination. Attribute
       
  1247 // aId needs to be in the current valid range (0x1001 - 0x10FF atm).
       
  1248 // ---------------------------------------------------------------------------
       
  1249 //
       
  1250 TBool CCmmCache::DestinationExistsWithId( const TUint32& aId )
       
  1251     {
       
  1252     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONEXISTSWITHID_ENTRY );
       
  1253 
       
  1254     TBool exists = iInstanceMapping->ValidDestinationId( aId );
       
  1255 
       
  1256     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONEXISTSWITHID_EXIT );
       
  1257     return exists;
       
  1258     }
       
  1259 
       
  1260 // ---------------------------------------------------------------------------
       
  1261 // Check if the given name belongs to an existing destination.
       
  1262 // If a destination ID is given, that destination is skipped.
       
  1263 // ---------------------------------------------------------------------------
       
  1264 //
       
  1265 TBool CCmmCache::DestinationExistsWithNameL( const TDesC& aName, const TUint32& aDestinationId )
       
  1266     {
       
  1267     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONEXISTSWITHNAMEL_ENTRY );
       
  1268 
       
  1269     TBool found( EFalse );
       
  1270 
       
  1271     // Check AccessPoint-table.
       
  1272     CommsDat::CCDAccessPointRecord* destApRecord = static_cast<CommsDat::CCDAccessPointRecord*>(
       
  1273             CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdAccessPointRecord ) );
       
  1274     CleanupStack::PushL( destApRecord );
       
  1275     destApRecord->iRecordName.SetL( aName );
       
  1276     if ( destApRecord->FindL( iTrans->Session() ) ) // Names should be unique.
       
  1277         {
       
  1278         if ( aDestinationId )
       
  1279             {
       
  1280             // Check the ID is different.
       
  1281             destApRecord->LoadL( iTrans->Session() );
       
  1282             if ( aDestinationId != destApRecord->iRecordTag )
       
  1283                 {
       
  1284                 found = ETrue;
       
  1285                 }
       
  1286             }
       
  1287         else
       
  1288             {
       
  1289             found = ETrue;
       
  1290             }
       
  1291         }
       
  1292     CleanupStack::PopAndDestroy( destApRecord );
       
  1293 
       
  1294     // Check also DataMobilitySelectionPolicy-table.
       
  1295     if ( !found )
       
  1296         {
       
  1297         CCDDataMobilitySelectionPolicyRecord* snapRecord =
       
  1298                 new( ELeave ) CCDDataMobilitySelectionPolicyRecord(
       
  1299                         iCmManagerImpl->TableId( ECmmDbSnapRecord ) );
       
  1300         CleanupStack::PushL( snapRecord );
       
  1301         snapRecord->iRecordName.SetL( aName );
       
  1302         if ( snapRecord->FindL( iTrans->Session() ) ) // Names should be unique.
       
  1303             {
       
  1304             if ( aDestinationId )
       
  1305                 {
       
  1306                 // Check the ID is different.
       
  1307                 snapRecord->LoadL( iTrans->Session() );
       
  1308                 if ( aDestinationId != snapRecord->iSNAP )
       
  1309                     {
       
  1310                     found = ETrue;
       
  1311                     }
       
  1312                 }
       
  1313             else
       
  1314                 {
       
  1315                 found = ETrue;
       
  1316                 }
       
  1317             }
       
  1318         CleanupStack::PopAndDestroy( snapRecord );
       
  1319         }
       
  1320 
       
  1321     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONEXISTSWITHNAMEL_EXIT );
       
  1322 
       
  1323     return found;
       
  1324     }
       
  1325 
       
  1326 // ---------------------------------------------------------------------------
       
  1327 // Check if the given ID belongs to a destination that the cache has an open
       
  1328 // handle on. This will include any destinations created by any client, that
       
  1329 // are not yet saved to database.
       
  1330 // With this check, we can prevent two clients from creating a new destination
       
  1331 // with the same ID (The UpdateL() operation would fail for one of them anyway).
       
  1332 // ---------------------------------------------------------------------------
       
  1333 //
       
  1334 TBool CCmmCache::DestinationOpenWithId( const TUint32& aId )
       
  1335     {
       
  1336     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONOPENWITHID_ENTRY );
       
  1337 
       
  1338     TBool result( EFalse );
       
  1339     TInt index = FindDestinationFromCache( aId );
       
  1340     if ( index != KErrNotFound )
       
  1341         {
       
  1342         result = ETrue;
       
  1343         }
       
  1344     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONOPENWITHID_EXIT );
       
  1345 
       
  1346     return result;
       
  1347     }
       
  1348 
       
  1349 // ---------------------------------------------------------------------------
       
  1350 // Check if the given name belongs to any new unsaved destinations in the
       
  1351 // cache. This includes any destinations created byany client, that are not
       
  1352 // yet saved to database.
       
  1353 // If a destination ID is provided, the search will exclude the relevant
       
  1354 // destination.
       
  1355 // With this check, we can prevent two clients from creating a new destination
       
  1356 // with the same name (The UpdateL() operation would fail for one of them
       
  1357 // anyway).
       
  1358 // ---------------------------------------------------------------------------
       
  1359 //
       
  1360 TBool CCmmCache::NotSavedDestinationOpenWithNameL(
       
  1361         const TDesC& aName,
       
  1362         const TUint32& aDestinationId )
       
  1363     {
       
  1364     OstTraceFunctionEntry0( CCMMCACHE_NOTSAVEDDESTINATIONOPENWITHNAMEL_ENTRY );
       
  1365 
       
  1366     TBool res( EFalse );
       
  1367     TInt index = FindNotSavedDestinationFromCacheL( aName, aDestinationId );
       
  1368     if ( index != KErrNotFound )
       
  1369         {
       
  1370         res = ETrue;
       
  1371         }
       
  1372     OstTraceFunctionExit0( CCMMCACHE_NOTSAVEDDESTINATIONOPENWITHNAMEL_EXIT );
       
  1373 
       
  1374     return res;
       
  1375     }
       
  1376 
       
  1377 // ---------------------------------------------------------------------------
       
  1378 // Check if the given ID belongs to a valid existing connection method.
       
  1379 // ---------------------------------------------------------------------------
       
  1380 //
       
  1381 TBool CCmmCache::ConnMethodExistsWithId( const TUint32& aConnMethodId )
       
  1382     {
       
  1383     OstTraceFunctionEntry0( CCMMCACHE_CONNMETHODEXISTSWITHID_ENTRY );
       
  1384 
       
  1385     TBool exists = iInstanceMapping->ValidConnMethodId( aConnMethodId );
       
  1386 
       
  1387     OstTraceFunctionExit0( CCMMCACHE_CONNMETHODEXISTSWITHID_EXIT );
       
  1388 
       
  1389     return exists;
       
  1390     }
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // Check if the given ID belongs to a connection method that the cache has an
       
  1394 // open handle on. This will include any connection methods created by any
       
  1395 // client, that are not yet saved to database.
       
  1396 // With this check, we can prevent two clients from creating a new connection
       
  1397 // method with the same ID (The UpdateL() operation would fail for one of them
       
  1398 // anyway).
       
  1399 // ---------------------------------------------------------------------------
       
  1400 //
       
  1401 TBool CCmmCache::ConnMethodOpenWithId( const TUint32& aConnMethodId )
       
  1402     {
       
  1403     OstTraceFunctionEntry0( CCMMCACHE_CONNMETHODOPENWITHID_ENTRY );
       
  1404 
       
  1405     TBool result( EFalse );
       
  1406     TInt index = FindConnMethodFromCache( aConnMethodId );
       
  1407     if ( index != KErrNotFound )
       
  1408         {
       
  1409         result = ETrue;
       
  1410         }
       
  1411     OstTraceFunctionExit0( CCMMCACHE_CONNMETHODOPENWITHID_EXIT );
       
  1412 
       
  1413     return result;
       
  1414     }
       
  1415 
       
  1416 // ---------------------------------------------------------------------------
       
  1417 // Checks if there are any destinations with metadata localization
       
  1418 // (ESnapMetadataDestinationIsLocalised) set to aValue. Also checks the
       
  1419 // relevant metadata purpose (ESnapMetadataPurpose) values.
       
  1420 // The destination connected to parameter aDestinationInstance is skipped.
       
  1421 // ---------------------------------------------------------------------------
       
  1422 //
       
  1423 TBool CCmmCache::DestinationExistsWithMetadataLocalizedL(
       
  1424         CCmmDestinationInstance& aDestinationInstance,
       
  1425         const TUint32& aValue )
       
  1426     {
       
  1427     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONEXISTSWITHMETADATALOCALIZEDL_ENTRY );
       
  1428 
       
  1429     TBool result( EFalse );
       
  1430 
       
  1431     if ( aValue != CMManager::ENotLocalisedDest )
       
  1432         {
       
  1433         // Check there is no destination in database that already has the same
       
  1434         // localization metadata value. Also checks metadata purpose.
       
  1435         CommsDat::CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet =
       
  1436                 new( ELeave )CommsDat::CMDBRecordSet<CCDSNAPMetadataRecord>(
       
  1437                         iCmManagerImpl->TableId( ECmmDestMetadataRecord ) );
       
  1438         CleanupStack::PushL( metaSet );
       
  1439         TRAP_IGNORE( metaSet->LoadL( iTrans->Session() ) );
       
  1440         for ( TInt i = 0; i < metaSet->iRecords.Count(); i++ )
       
  1441             {
       
  1442             TInt id = ( ( CCDSNAPMetadataRecord* )metaSet->iRecords[i] )->iSNAP;
       
  1443             TUint32 metadata = ( ( CCDSNAPMetadataRecord* )metaSet->iRecords[i] )->iMetadata;
       
  1444             TUint32 localizationValue =
       
  1445                     ( metadata & CMManager::ESnapMetadataDestinationIsLocalised ) >> 4;
       
  1446             TUint32 purposeValue = ( metadata & CMManager::ESnapMetadataPurpose ) >> 8;
       
  1447 
       
  1448             if ( aDestinationInstance.GetId() != id )
       
  1449                 {
       
  1450                 if ( aValue == localizationValue )
       
  1451                     {
       
  1452                     result = ETrue;
       
  1453                     }
       
  1454                 switch ( aValue )
       
  1455                     {
       
  1456                     case CMManager::ELocalisedDestInternet:
       
  1457                         {
       
  1458                         if ( purposeValue == CMManager::ESnapPurposeInternet ||
       
  1459                                 ( metadata & CMManager::ESnapMetadataInternet ) )
       
  1460                             {
       
  1461                             result = ETrue;
       
  1462                             }
       
  1463                         }
       
  1464                         break;
       
  1465                     case CMManager::ELocalisedDestWap:
       
  1466                         {
       
  1467                         if ( purposeValue == CMManager::ESnapPurposeOperator )
       
  1468                             {
       
  1469                             result = ETrue;
       
  1470                             }
       
  1471                         }
       
  1472                         break;
       
  1473                     case CMManager::ELocalisedDestMMS:
       
  1474                         {
       
  1475                         if ( purposeValue == CMManager::ESnapPurposeMMS )
       
  1476                             {
       
  1477                             result = ETrue;
       
  1478                             }
       
  1479                         }
       
  1480                         break;
       
  1481                     case CMManager::ELocalisedDestIntranet:
       
  1482                         {
       
  1483                         if ( purposeValue == CMManager::ESnapPurposeIntranet )
       
  1484                             {
       
  1485                             result = ETrue;
       
  1486                             }
       
  1487                         }
       
  1488                         break;
       
  1489                     default:
       
  1490                         break;
       
  1491                     }
       
  1492                 }
       
  1493             }
       
  1494         CleanupStack::PopAndDestroy( metaSet );
       
  1495         }
       
  1496     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONEXISTSWITHMETADATALOCALIZEDL_EXIT );
       
  1497 
       
  1498     return result;
       
  1499     }
       
  1500 
       
  1501 // ---------------------------------------------------------------------------
       
  1502 // Checks if there are any destinations with metadata purpose
       
  1503 // (ESnapMetadataPurpose) set to aValue. Also checks the relevant metadata
       
  1504 // localization (ESnapMetadataDestinationIsLocalised) values.
       
  1505 // The destination connected to parameter aDestinationInstance is skipped.
       
  1506 // ---------------------------------------------------------------------------
       
  1507 //
       
  1508 TBool CCmmCache::DestinationExistsWithMetadataPurposeL(
       
  1509         CCmmDestinationInstance& aDestinationInstance,
       
  1510         const TUint32& aValue )
       
  1511     {
       
  1512     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONEXISTSWITHMETADATAPURPOSEL_ENTRY );
       
  1513 
       
  1514     TBool result( EFalse );
       
  1515 
       
  1516     if ( aValue != CMManager::ESnapPurposeUnknown )
       
  1517         {
       
  1518         // Check there is no destination in database that already has the same
       
  1519         // metadata purpose value. Also checks localization metadata.
       
  1520         CommsDat::CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet =
       
  1521                 new( ELeave )CommsDat::CMDBRecordSet<CCDSNAPMetadataRecord>(
       
  1522                         iCmManagerImpl->TableId( ECmmDestMetadataRecord ) );
       
  1523         CleanupStack::PushL( metaSet );
       
  1524         TRAP_IGNORE( metaSet->LoadL( iTrans->Session() ) );
       
  1525         for ( TInt i = 0; i < metaSet->iRecords.Count(); i++ )
       
  1526             {
       
  1527             TInt id = ( ( CCDSNAPMetadataRecord* )metaSet->iRecords[i] )->iSNAP;
       
  1528             TUint32 metadata = ( ( CCDSNAPMetadataRecord* )metaSet->iRecords[i] )->iMetadata;
       
  1529             TUint32 localizationValue =
       
  1530                     ( metadata & CMManager::ESnapMetadataDestinationIsLocalised ) >> 4;
       
  1531             TUint32 purposeValue = ( metadata & CMManager::ESnapMetadataPurpose ) >> 8;
       
  1532 
       
  1533             if ( aDestinationInstance.GetId() != id )
       
  1534                 {
       
  1535                 if ( aValue == purposeValue )
       
  1536                     {
       
  1537                     result = ETrue;
       
  1538                     }
       
  1539                 switch ( aValue )
       
  1540                     {
       
  1541                     case CMManager::ESnapPurposeInternet:
       
  1542                         {
       
  1543                         if ( localizationValue == CMManager::ELocalisedDestInternet ||
       
  1544                                 ( metadata & CMManager::ESnapMetadataInternet ) )
       
  1545                             {
       
  1546                             result = ETrue;
       
  1547                             }
       
  1548                         }
       
  1549                         break;
       
  1550                     case CMManager::ESnapPurposeOperator:
       
  1551                         {
       
  1552                         if ( localizationValue == CMManager::ELocalisedDestWap )
       
  1553                             {
       
  1554                             result = ETrue;
       
  1555                             }
       
  1556                         }
       
  1557                         break;
       
  1558                     case CMManager::ESnapPurposeMMS:
       
  1559                         {
       
  1560                         if ( localizationValue == CMManager::ELocalisedDestMMS )
       
  1561                             {
       
  1562                             result = ETrue;
       
  1563                             }
       
  1564                         }
       
  1565                         break;
       
  1566                     case CMManager::ESnapPurposeIntranet:
       
  1567                         {
       
  1568                         if ( localizationValue == CMManager::ELocalisedDestIntranet )
       
  1569                             {
       
  1570                             result = ETrue;
       
  1571                             }
       
  1572                         }
       
  1573                         break;
       
  1574                     default:
       
  1575                         break;
       
  1576                     }
       
  1577                 }
       
  1578             }
       
  1579         CleanupStack::PopAndDestroy( metaSet );
       
  1580         }
       
  1581     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONEXISTSWITHMETADATAPURPOSEL_EXIT );
       
  1582 
       
  1583     return result;
       
  1584     }
       
  1585 
       
  1586 // ---------------------------------------------------------------------------
       
  1587 // Tells the cache that a database table has changed. If the SNAP/IAP structure
       
  1588 // has possibly changed, the cache will refresh that information immediately.
       
  1589 // For other database tables, the tables are flagged and will be refreshed when
       
  1590 // needed.
       
  1591 // ---------------------------------------------------------------------------
       
  1592 //
       
  1593 void CCmmCache::DbChangeDetected( const TUint32& aTableId )
       
  1594     {
       
  1595     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEDETECTED_ENTRY );
       
  1596 
       
  1597     (void)aTableId; //TODO
       
  1598     // Flag the table as: currently not up-to-date
       
  1599     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEDETECTED_EXIT );
       
  1600     }
       
  1601 
       
  1602 // ---------------------------------------------------------------------------
       
  1603 // Tells the cache that an error has occured with a database listener. Any
       
  1604 // reads to this table need go through the database, since cache can't know if
       
  1605 // it has up-to-date information.
       
  1606 // ---------------------------------------------------------------------------
       
  1607 //
       
  1608 void CCmmCache::DbChangeError( const TUint32& aTableId )
       
  1609     {
       
  1610     OstTraceFunctionEntry0( CCMMCACHE_DBCHANGEERROR_ENTRY );
       
  1611 
       
  1612     (void)aTableId; //TODO
       
  1613     // Flag the table as: permanently not up-to-date
       
  1614     OstTraceFunctionExit0( CCMMCACHE_DBCHANGEERROR_EXIT );
       
  1615     }
       
  1616 
       
  1617 // ---------------------------------------------------------------------------
       
  1618 // Tells the cache that a hadle to a destination was closed. The cache will
       
  1619 // decrement the related reference counter and perform any cleanup if necessary.
       
  1620 // This should be called automatically from the destructor of
       
  1621 // CCmmDestinationInstance-class.
       
  1622 // ---------------------------------------------------------------------------
       
  1623 //
       
  1624 void CCmmCache::CloseDestination( CCmmDestinationInstance& aDestinationInstance )
       
  1625     {
       
  1626     OstTraceFunctionEntry0( CCMMCACHE_CLOSEDESTINATION_ENTRY );
       
  1627 
       
  1628     TInt index = FindDestinationFromCache( aDestinationInstance.GetId() );
       
  1629 
       
  1630     if ( index >= 0 )
       
  1631         {
       
  1632         TInt remainingSessionInstances = iDestinationArray[index]->SessionInstanceClosed();
       
  1633         if ( remainingSessionInstances <= 0)
       
  1634             {
       
  1635             // If status is 'to be deleted', then the last handle keeping this
       
  1636             // destination 'alive' was closed and it can now be deleted from
       
  1637             // database.
       
  1638             if ( iDestinationArray[index]->GetStatus() == ECmmDestinationStatusToBeDeleted )
       
  1639                 {
       
  1640                 // Delete the destination unless an active connection is using
       
  1641                 // one of it's connection methods.
       
  1642                 TRAP_IGNORE( DeleteDestinationForcedL( aDestinationInstance ) );
       
  1643                         //{
       
  1644                         //if ( !DestinationConnectedL( aDestinationInstance.GetId() ) ) DeleteDestinationL( aDestinationInstance, ETrue );
       
  1645                         //} ); //TODO, make helper function
       
  1646 
       
  1647                 // Destination is now removed from database. Tell instance
       
  1648                 // mapping to stop ignoring the related ID.
       
  1649                 iInstanceMapping->RemoveDestinationFromDeletedList( aDestinationInstance.GetId() );
       
  1650                 }
       
  1651 
       
  1652             // No more references, no client has an open handle to this, delete it.
       
  1653             delete iDestinationArray[index];
       
  1654             iDestinationArray.Remove( index );
       
  1655             }
       
  1656         }
       
  1657 
       
  1658     OstTraceFunctionExit0( CCMMCACHE_CLOSEDESTINATION_EXIT );
       
  1659     }
       
  1660 
       
  1661 // ---------------------------------------------------------------------------
       
  1662 // Tells the cache that a hadle to a connection method was closed. The cache
       
  1663 // will decrement the related reference counter and perform any cleanup if
       
  1664 // necessary.
       
  1665 // This should be called automatically from the destructor of
       
  1666 // CCmmConnMethodInstance-class.
       
  1667 // ---------------------------------------------------------------------------
       
  1668 //
       
  1669 void CCmmCache::CloseConnMethod( CCmmConnMethodInstance& aConnMethodInstance )
       
  1670     {
       
  1671     OstTraceFunctionEntry0( CCMMCACHE_CLOSECONNMETHOD_ENTRY );
       
  1672 
       
  1673     TInt index = FindConnMethodFromCache( aConnMethodInstance.GetId() );
       
  1674 
       
  1675     if ( index >= 0 )
       
  1676         {
       
  1677         TInt remainingSessionInstances = iConnMethodArray[index]->SessionInstanceClosed();
       
  1678         if ( remainingSessionInstances <= 0 )
       
  1679             {
       
  1680             // If status is 'to be deleted', then the last handle keeping this
       
  1681             // connection method 'alive' was closed and it can now be deleted
       
  1682             // from database.
       
  1683             if ( iConnMethodArray[index]->GetStatus() == ECmmConnMethodStatusToBeDeleted )
       
  1684                 {
       
  1685                 // Can't remove a connection method that is in use.
       
  1686                 if ( !CheckIfCmConnected( aConnMethodInstance.GetId() ) )
       
  1687                     {
       
  1688                     // Can't leave here.
       
  1689                     TRAP_IGNORE( DeletePluginL( *( iConnMethodArray[index] ) ) );
       
  1690                     }
       
  1691 
       
  1692                 // Connection method is now removed from database. Tell
       
  1693                 // instance mapping to stop ignoring the related ID.
       
  1694                 iInstanceMapping->RemoveConnMethodFromDeletedList( aConnMethodInstance.GetId() );
       
  1695                 }
       
  1696 
       
  1697             // No more references, no client has an open handle to this, delete it.
       
  1698             delete iConnMethodArray[index];
       
  1699             iConnMethodArray.Remove( index );
       
  1700             }
       
  1701         }
       
  1702     OstTraceFunctionExit0( CCMMCACHE_CLOSECONNMETHOD_EXIT );
       
  1703     }
       
  1704 
       
  1705 //-----------------------------------------------------------------------------
       
  1706 // Returns a reference to the CommsDat session.
       
  1707 //-----------------------------------------------------------------------------
       
  1708 //
       
  1709 CommsDat::CMDBSession& CCmmCache::Session() const
       
  1710     {
       
  1711     OstTraceFunctionEntry0( CCMMCACHE_SESSION_ENTRY );
       
  1712 
       
  1713     return iTrans->Session();
       
  1714     }
       
  1715 
       
  1716 //-----------------------------------------------------------------------------
       
  1717 // Finds out the bearer type and priority of the service type from given IAP
       
  1718 // record.
       
  1719 //-----------------------------------------------------------------------------
       
  1720 //
       
  1721 void CCmmCache::BearerInfoFromIapRecordL(
       
  1722         CommsDat::CCDIAPRecord* aIapRecord,
       
  1723         TUint32& aBearerType,
       
  1724         TUint& aBearerPriority ) const
       
  1725     {
       
  1726     OstTraceFunctionEntry0( CCMMCACHE_BEARERINFOFROMIAPRECORDL_ENTRY );
       
  1727 
       
  1728     // Load the IAP record from IAP table. This is an optimization that plugins
       
  1729     // doesn't have to do it every time the CanHandleIapIdL() is called.
       
  1730     aIapRecord->LoadL( Session() );
       
  1731     BearerPriorityFromIapRecordL( aIapRecord, aBearerPriority );
       
  1732     BearerTypeFromIapRecordL( aIapRecord, aBearerType );
       
  1733 
       
  1734     OstTraceFunctionExit0( CCMMCACHE_BEARERINFOFROMIAPRECORDL_EXIT );
       
  1735     }
       
  1736 
       
  1737 //-----------------------------------------------------------------------------
       
  1738 // Finds out the priority of the service type in given IAP record.
       
  1739 //-----------------------------------------------------------------------------
       
  1740 //
       
  1741 void CCmmCache::BearerPriorityFromIapRecordL(
       
  1742         CommsDat::CCDIAPRecord* aIapRecord,
       
  1743         TUint& aBearerPriority ) const
       
  1744     {
       
  1745     OstTraceFunctionEntry0( CCMMCACHE_BEARERPRIORITYFROMIAPRECORDL_ENTRY );
       
  1746 
       
  1747     aBearerPriority = CMManager::KDataMobilitySelectionPolicyPriorityWildCard;
       
  1748     if ( !aIapRecord->iServiceType.IsNull() )
       
  1749         {
       
  1750         aBearerPriority = iBearerPriorityCache->GetPriority( aIapRecord->iServiceType.GetL() );
       
  1751         }
       
  1752 
       
  1753     OstTraceFunctionExit0( CCMMCACHE_BEARERPRIORITYFROMIAPRECORDL_EXIT );
       
  1754     }
       
  1755 
       
  1756 //-----------------------------------------------------------------------------
       
  1757 // Finds out the bearer type of a connection method from given IAP record.
       
  1758 //-----------------------------------------------------------------------------
       
  1759 //
       
  1760 void CCmmCache::BearerTypeFromIapRecordL(
       
  1761         CommsDat::CCDIAPRecord* aIapRecord,
       
  1762         TUint32& aBearerType ) const
       
  1763     {
       
  1764     OstTraceFunctionEntry0( CCMMCACHE_BEARERTYPEFROMIAPRECORDL_ENTRY );
       
  1765 
       
  1766     TInt err( KErrNone );
       
  1767     TUint32 extLevel( 0 );
       
  1768     TBool canHandle( EFalse );
       
  1769 
       
  1770     TInt foundIndex( KErrNotFound );
       
  1771 
       
  1772     // Check which bearer handles the given IAP ID.
       
  1773     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  1774         {
       
  1775         TRAP( err, canHandle = (*iPlugins)[i]->CanHandleIapIdL( aIapRecord ) ); //TODO, check leave, trap needed?
       
  1776         if ( !err && canHandle )
       
  1777             {
       
  1778             TUint32 thisExtLevel = (*iPlugins)[i]->GetBearerInfoIntL( ECmExtensionLevel );
       
  1779             if ( extLevel < thisExtLevel )
       
  1780                 {
       
  1781                 extLevel = thisExtLevel;
       
  1782                 foundIndex = i;
       
  1783                 }
       
  1784             }
       
  1785         }
       
  1786     if ( foundIndex == KErrNotFound )
       
  1787         {
       
  1788         // No supporting plugin found.
       
  1789         User::Leave( KErrNotSupported );
       
  1790         }
       
  1791     aBearerType = (*iPlugins)[foundIndex]->GetBearerInfoIntL( CMManager::ECmBearerType );
       
  1792 
       
  1793     OstTraceFunctionExit0( CCMMCACHE_BEARERTYPEFROMIAPRECORDL_EXIT );
       
  1794     }
       
  1795 
       
  1796 //-----------------------------------------------------------------------------
       
  1797 // Returns all conenction method IDs. Unsupported connection methods are
       
  1798 // included if aCheckBearerType is set to EFalse.
       
  1799 //-----------------------------------------------------------------------------
       
  1800 //
       
  1801 void CCmmCache::GetAllConnMethodsL(
       
  1802         RArray<TUint32>& aConnMethodArray,
       
  1803         TBool aCheckBearerType ) const
       
  1804     {
       
  1805     OstTraceFunctionEntry0( CCMMCACHE_GETALLCONNMETHODSL_ENTRY );
       
  1806 
       
  1807     iInstanceMapping->GetAllConnMethodsL( aConnMethodArray, aCheckBearerType );
       
  1808 
       
  1809     OstTraceFunctionExit0( CCMMCACHE_GETALLCONNMETHODSL_EXIT );
       
  1810     }
       
  1811 
       
  1812 //-----------------------------------------------------------------------------
       
  1813 // Returns the number of destinations the provided connection method belongs to.
       
  1814 //-----------------------------------------------------------------------------
       
  1815 //
       
  1816 TInt CCmmCache::DestinationsContainingConnMethod( const TUint32& aConnMethodId ) const
       
  1817     {
       
  1818     OstTraceFunctionEntry0( CCMMCACHE_CONNMETHODREFERENCECOUNT_ENTRY );
       
  1819 
       
  1820     TInt count = iInstanceMapping->DestinationsContainingConnMethod( aConnMethodId );
       
  1821 
       
  1822     OstTraceFunctionExit0( CCMMCACHE_CONNMETHODREFERENCECOUNT_EXIT );
       
  1823     return count;
       
  1824     }
       
  1825 
       
  1826 //-----------------------------------------------------------------------------
       
  1827 // Return the EasyWLAN IAP ID, zero if not found or WLAN not supported.
       
  1828 //-----------------------------------------------------------------------------
       
  1829 //
       
  1830 TUint32 CCmmCache::EasyWlanIdL() const
       
  1831     {
       
  1832     OstTraceFunctionEntry0( CCMMCACHE_EASYWLANIDL_ENTRY );
       
  1833 
       
  1834     TUint32 easyWlanId = iInstanceMapping->EasyWlanIdL();
       
  1835 
       
  1836     OstTraceFunctionExit0( CCMMCACHE_EASYWLANIDL_EXIT );
       
  1837     return easyWlanId;
       
  1838     }
       
  1839 
       
  1840 //-----------------------------------------------------------------------------
       
  1841 // Check if WLAN is supported on phone.
       
  1842 //-----------------------------------------------------------------------------
       
  1843 //
       
  1844 TBool CCmmCache::WlanSupported() const
       
  1845     {
       
  1846     OstTraceFunctionEntry0( CCMMCACHE_WLANSUPPORTED_ENTRY );
       
  1847 
       
  1848     TBool supported = iCmManagerImpl->WlanSupported();
       
  1849 
       
  1850     OstTraceFunctionExit0( CCMMCACHE_WLANSUPPORTED_EXIT );
       
  1851     return supported;
       
  1852     }
       
  1853 
       
  1854 //-----------------------------------------------------------------------------
       
  1855 // Find out the internet destination ID. Set to 0 if not found.
       
  1856 //-----------------------------------------------------------------------------
       
  1857 //
       
  1858 void CCmmCache::InternetDestinationIdL( TUint& aInternetDestinationId ) const
       
  1859     {
       
  1860     OstTraceFunctionEntry0( CCMMCACHE_INTERNETDESTINATIONIDL_ENTRY );
       
  1861 
       
  1862     iInstanceMapping->InternetDestinationIdL( aInternetDestinationId );
       
  1863 
       
  1864     OstTraceFunctionExit0( CCMMCACHE_INTERNETDESTINATIONIDL_EXIT );
       
  1865     }
       
  1866 
       
  1867 //-----------------------------------------------------------------------------
       
  1868 // Return the number of destinations in database.
       
  1869 //-----------------------------------------------------------------------------
       
  1870 //
       
  1871 TInt CCmmCache::GetDestinationCount() const
       
  1872     {
       
  1873     OstTraceFunctionEntry0( CCMMCACHE_GETDESTINATIONCOUNT_ENTRY );
       
  1874 
       
  1875     TInt count = iInstanceMapping->GetDestinationCount();
       
  1876 
       
  1877     OstTraceFunctionExit0( CCMMCACHE_GETDESTINATIONCOUNT_EXIT );
       
  1878     return count;
       
  1879     }
       
  1880 
       
  1881 //-----------------------------------------------------------------------------
       
  1882 // Return an array containing all destination IDs.
       
  1883 //-----------------------------------------------------------------------------
       
  1884 //
       
  1885 void CCmmCache::GetDestinationsL( RArray<TUint32>& aDestinationArray ) const
       
  1886     {
       
  1887     OstTraceFunctionEntry0( CCMMCACHE_GETDESTINATIONSL_ENTRY );
       
  1888 
       
  1889     iInstanceMapping->GetDestinationsL( aDestinationArray );
       
  1890 
       
  1891     OstTraceFunctionExit0( CCMMCACHE_GETDESTINATIONSL_EXIT );
       
  1892     }
       
  1893 
       
  1894 //-----------------------------------------------------------------------------
       
  1895 // Returns all the valid connection methods under given destination.
       
  1896 //-----------------------------------------------------------------------------
       
  1897 //
       
  1898 void CCmmCache::GetConnMethodsFromDestinationL(
       
  1899         const TUint32& aDestinationId,
       
  1900         RArray<TCmmConnMethodItem>& aConnMethodArray ) const
       
  1901     {
       
  1902     OstTraceFunctionEntry0( CCMMCACHE_GETCONNMETHODSFROMDESTINATIONL_ENTRY );
       
  1903 
       
  1904     iInstanceMapping->GetConnMethodsFromDestinationL(
       
  1905             aDestinationId, aConnMethodArray );
       
  1906 
       
  1907     OstTraceFunctionExit0( CCMMCACHE_GETCONNMETHODSFROMDESTINATIONL_EXIT );
       
  1908     }
       
  1909 
       
  1910 //-----------------------------------------------------------------------------
       
  1911 // Copies the bearer priority array's contents to aArray.
       
  1912 //-----------------------------------------------------------------------------
       
  1913 //
       
  1914 void CCmmCache::CopyBearerPriorityArrayL( RPointerArray<CCmmBearerPriority>& aArray ) const
       
  1915     {
       
  1916     OstTraceFunctionEntry0( CCMMCACHE_COPYBEARERPRIORITYARRAYL_ENTRY );
       
  1917 
       
  1918     iBearerPriorityCache->CopyL( aArray );
       
  1919 
       
  1920     OstTraceFunctionExit0( CCMMCACHE_COPYBEARERPRIORITYARRAYL_EXIT );
       
  1921     }
       
  1922 
       
  1923 //-----------------------------------------------------------------------------
       
  1924 // Updates the bearer priority array with the contents of aArray.
       
  1925 //-----------------------------------------------------------------------------
       
  1926 //
       
  1927 void CCmmCache::UpdateBearerPriorityArrayL( const RPointerArray<CCmmBearerPriority>& aArray )
       
  1928     {
       
  1929     OstTraceFunctionEntry0( CCMMCACHE_UPDATEBEARERPRIORITYARRAYL_ENTRY );
       
  1930 
       
  1931     iBearerPriorityCache->UpdateL( aArray );
       
  1932 
       
  1933     OstTraceFunctionExit0( CCMMCACHE_UPDATEBEARERPRIORITYARRAYL_EXIT );
       
  1934     }
       
  1935 
       
  1936 //-----------------------------------------------------------------------------
       
  1937 // Check from database if the given connection method belongs to any other
       
  1938 // destination than the one provided.
       
  1939 //-----------------------------------------------------------------------------
       
  1940 //
       
  1941 TBool CCmmCache::ConnMethodInOtherDestination(
       
  1942         const TUint32& aConnMethodId,
       
  1943         const TUint32& aDestinationId )
       
  1944     {
       
  1945     OstTraceFunctionEntry0( CCMMCACHE_CONNMETHODINOTHERDESTINATION_ENTRY );
       
  1946 
       
  1947     TBool cmInOtherDestination = iInstanceMapping->
       
  1948             ConnMethodInOtherDestination( aConnMethodId, aDestinationId );
       
  1949 
       
  1950     OstTraceFunctionExit0( CCMMCACHE_CONNMETHODINOTHERDESTINATION_EXIT );
       
  1951     return cmInOtherDestination;
       
  1952     }
       
  1953 
       
  1954 //-----------------------------------------------------------------------------
       
  1955 // Get the next free temporary ID.
       
  1956 //-----------------------------------------------------------------------------
       
  1957 //
       
  1958 TUint32 CCmmCache::NextFreeTemporaryId()
       
  1959     {
       
  1960     OstTraceFunctionEntry0( CCMMCACHE_NEXTFREETEMPORARYID_ENTRY );
       
  1961 
       
  1962     // Zero is not a valid ID.
       
  1963     if ( iCurrentTemporaryId == KMaxTUint32 )
       
  1964         {
       
  1965         //TODO, add flag to indicate a rollover has occured. after that need to check if temp ID is free before giving it out.
       
  1966 
       
  1967         iCurrentTemporaryId = KTemporaryIdCounterStart;
       
  1968         }
       
  1969 
       
  1970     iCurrentTemporaryId++;
       
  1971 
       
  1972     OstTraceFunctionExit0( CCMMCACHE_NEXTFREETEMPORARYID_EXIT );
       
  1973     return iCurrentTemporaryId;
       
  1974     }
       
  1975 
       
  1976 //-----------------------------------------------------------------------------
       
  1977 // Find an open destination matching the give ID from cache.
       
  1978 // Returns either a valid array index or KErrNotFound.
       
  1979 //-----------------------------------------------------------------------------
       
  1980 //
       
  1981 TInt CCmmCache::FindDestinationFromCache( const TUint32& aId )
       
  1982     {
       
  1983     OstTraceFunctionEntry0( CCMMCACHE_FINDDESTINATIONFROMCACHE_ENTRY );
       
  1984 
       
  1985     TInt result( KErrNotFound );
       
  1986 
       
  1987     // Skip if ID is 0.
       
  1988     if ( aId )
       
  1989         {
       
  1990         for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  1991             {
       
  1992             if ( aId == iDestinationArray[i]->GetId() )
       
  1993                 {
       
  1994                 result = i;
       
  1995                 break;
       
  1996                 }
       
  1997             }
       
  1998         }
       
  1999 
       
  2000     OstTraceFunctionExit0( CCMMCACHE_FINDDESTINATIONFROMCACHE_EXIT );
       
  2001     return result;
       
  2002     }
       
  2003 
       
  2004 //-----------------------------------------------------------------------------
       
  2005 // Find an open destination matching the given name from cache. If a destination
       
  2006 // ID is provided, the search will exclude the relevant destination.
       
  2007 // Returns either a valid array index or KErrNotFound.
       
  2008 //-----------------------------------------------------------------------------
       
  2009 //
       
  2010 TInt CCmmCache::FindNotSavedDestinationFromCacheL( const TDesC& aName, const TUint32& aDestinationId )
       
  2011     {
       
  2012     OstTraceFunctionEntry0( CCMMCACHE_FINDNOTSAVEDDESTINATIONFROMCACHEL_ENTRY );
       
  2013 
       
  2014     TInt result( KErrNotFound );
       
  2015 
       
  2016     // Go through destination array.
       
  2017     for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  2018         {
       
  2019         // Only check new destinations that are not yet in database.
       
  2020         if ( iDestinationArray[i]->GetStatus() == ECmmDestinationStatusNotSaved )
       
  2021             {
       
  2022             if ( aDestinationId )
       
  2023                 {
       
  2024                 if ( aDestinationId != iDestinationArray[i]->GetId() )
       
  2025                     {
       
  2026                     if ( !aName.Compare( iDestinationArray[i]->GetDestinationNameL() ) )
       
  2027                         {
       
  2028                         result = i;
       
  2029                         break;
       
  2030                         }
       
  2031                     }
       
  2032                 }
       
  2033             else
       
  2034                 {
       
  2035                 if ( !aName.Compare( iDestinationArray[i]->GetDestinationNameL() ) )
       
  2036                     {
       
  2037                     result = i;
       
  2038                     break;
       
  2039                     }
       
  2040                 }
       
  2041             }
       
  2042         }
       
  2043 
       
  2044     OstTraceFunctionExit0( CCMMCACHE_FINDNOTSAVEDDESTINATIONFROMCACHEL_EXIT );
       
  2045     return result;
       
  2046     }
       
  2047 
       
  2048 //-----------------------------------------------------------------------------
       
  2049 // Find an open connection method matching the given ID from cache.
       
  2050 // Returns either a valid array index or KErrNotFound.
       
  2051 //-----------------------------------------------------------------------------
       
  2052 //
       
  2053 TInt CCmmCache::FindConnMethodFromCache( const TUint32& aConnMethodId )
       
  2054     {
       
  2055     OstTraceFunctionEntry0( CCMMCACHE_FINDCONNMETHODFROMCACHE_ENTRY );
       
  2056 
       
  2057     TInt result( KErrNotFound );
       
  2058 
       
  2059     // Skip if ID is 0.
       
  2060     if ( aConnMethodId )
       
  2061         {
       
  2062         for ( TInt i = 0; i < iConnMethodArray.Count(); i++ )
       
  2063             {
       
  2064             if ( aConnMethodId == iConnMethodArray[i]->GetId() )
       
  2065                 {
       
  2066                 result = i;
       
  2067                 break;
       
  2068                 }
       
  2069             }
       
  2070         }
       
  2071 
       
  2072     OstTraceFunctionExit0( CCMMCACHE_FINDCONNMETHODFROMCACHE_EXIT );
       
  2073     return result;
       
  2074     }
       
  2075 
       
  2076 //-----------------------------------------------------------------------------
       
  2077 // Loads and initializes a connection method instance.
       
  2078 //-----------------------------------------------------------------------------
       
  2079 //
       
  2080 void CCmmCache::OpenConnectionMethodInstanceL(
       
  2081         CCmmConnMethodInstance& aConnMethodInstance,
       
  2082         const TUint32& aConnMethodId )
       
  2083     {
       
  2084     OstTraceFunctionEntry0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_ENTRY );
       
  2085 
       
  2086     // Find out the connection method bearer type.
       
  2087     TUint32 bearerType( 0 );
       
  2088     User::LeaveIfError( iInstanceMapping->GetConnMethodBearerType( aConnMethodId, bearerType ) );
       
  2089 
       
  2090     // Check bearer type support and create plugin instance.
       
  2091     CCmPluginBaseEng* plugin = NULL;
       
  2092     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  2093         {
       
  2094         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == bearerType )
       
  2095             {
       
  2096             TCmPluginInitParam pluginParams( Session() );
       
  2097             plugin = ( *iPlugins )[i]->CreateInstanceL( pluginParams );
       
  2098             CleanupStack::PushL( plugin );
       
  2099             plugin->LoadL( aConnMethodId );
       
  2100             break;
       
  2101             }
       
  2102         }
       
  2103     if ( !plugin )
       
  2104         {
       
  2105         User::Leave( KErrNotSupported );
       
  2106         }
       
  2107 
       
  2108     // Store the connection method into cache.
       
  2109     CCmmConnMethodStruct* connMethodStruct = CCmmConnMethodStruct::NewLC( aConnMethodId );
       
  2110     connMethodStruct->SetPlugin( plugin, bearerType, ECmmConnMethodStatusValid );
       
  2111     iConnMethodArray.AppendL( connMethodStruct );
       
  2112     CleanupStack::Pop( connMethodStruct );
       
  2113     CleanupStack::Pop( plugin ); //TODO, pop after SetPlugin()-call?
       
  2114 
       
  2115     // Copy the connection method data to session instance.
       
  2116     aConnMethodInstance.CopyDataL( connMethodStruct ); // Will increase reference counter.
       
  2117 
       
  2118     OstTraceFunctionExit0( CCMMCACHE_OPENCONNECTIONMETHODINSTANCEL_EXIT );
       
  2119     }
       
  2120 
       
  2121 //-----------------------------------------------------------------------------
       
  2122 // CCmmCache::GetConnectionMethodInfoIntL
       
  2123 //-----------------------------------------------------------------------------
       
  2124 //
       
  2125 TUint32 CCmmCache::GetConnectionMethodInfoIntL(
       
  2126         const TUint32& aCmId,
       
  2127         const TUint32& aAttribute )
       
  2128     {
       
  2129     OstTraceFunctionEntry0( CCMMCACHE_GETCONNECTIONMETHODINFOINTL_ENTRY );
       
  2130 
       
  2131     TUint32 retVal( 0 );
       
  2132 
       
  2133     CCmmConnMethodInstance* cmInstance = CCmmConnMethodInstance::NewLC( NULL, this );
       
  2134 
       
  2135     // Check if connection method is already opened in cache.
       
  2136     TInt index = FindConnMethodFromCache( aCmId );
       
  2137     if ( index != KErrNotFound )
       
  2138         {
       
  2139         // Already open in cache. Copy the connection method to session instance.
       
  2140         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
       
  2141         }
       
  2142     else
       
  2143         {
       
  2144         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
       
  2145         }
       
  2146 
       
  2147     retVal = cmInstance->GetIntAttributeL( aAttribute );
       
  2148 
       
  2149     CloseConnMethod( *cmInstance );
       
  2150     CleanupStack::PopAndDestroy( cmInstance );
       
  2151 
       
  2152     OstTraceFunctionExit0( CCMMCACHE_GETCONNECTIONMETHODINFOINTL_EXIT );
       
  2153     return retVal;
       
  2154     }
       
  2155 
       
  2156 //-----------------------------------------------------------------------------
       
  2157 // CCmmCache::GetConnectionMethodInfoBoolL
       
  2158 //-----------------------------------------------------------------------------
       
  2159 //
       
  2160 TBool CCmmCache::GetConnectionMethodInfoBoolL(
       
  2161         const TUint32& aCmId,
       
  2162         const TUint32& aAttribute )
       
  2163     {
       
  2164     OstTraceFunctionEntry0( CCMMCACHE_GETCONNECTIONMETHODINFOBOOLL_ENTRY );
       
  2165 
       
  2166     TBool retVal( EFalse );
       
  2167 
       
  2168     CCmmConnMethodInstance* cmInstance = CCmmConnMethodInstance::NewLC( NULL, this );
       
  2169 
       
  2170     // Check if connection method is already opened in cache.
       
  2171     TInt index = FindConnMethodFromCache( aCmId );
       
  2172     if ( index != KErrNotFound )
       
  2173         {
       
  2174         // Already open in cache. Copy the connection method to session instance.
       
  2175         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
       
  2176         }
       
  2177     else
       
  2178         {
       
  2179         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
       
  2180         }
       
  2181 
       
  2182     retVal = cmInstance->GetBoolAttributeL( aAttribute );
       
  2183 
       
  2184     CloseConnMethod( *cmInstance );
       
  2185     CleanupStack::PopAndDestroy( cmInstance );
       
  2186 
       
  2187     OstTraceFunctionExit0( CCMMCACHE_GETCONNECTIONMETHODINFOBOOLL_EXIT );
       
  2188     return retVal;
       
  2189     }
       
  2190 
       
  2191 //-----------------------------------------------------------------------------
       
  2192 // CCmmCache::GetConnectionMethodInfoStringL
       
  2193 //-----------------------------------------------------------------------------
       
  2194 //
       
  2195 HBufC* CCmmCache::GetConnectionMethodInfoStringL(
       
  2196         const TUint32& aCmId,
       
  2197         const TUint32& aAttribute )
       
  2198     {
       
  2199     OstTraceFunctionEntry0( CCMMCACHE_GETCONNECTIONMETHODINFOSTRINGL_ENTRY );
       
  2200 
       
  2201     HBufC* retVal( NULL );
       
  2202 
       
  2203     CCmmConnMethodInstance* cmInstance = CCmmConnMethodInstance::NewLC( NULL, this );
       
  2204 
       
  2205     // Check if connection method is already opened in cache.
       
  2206     TInt index = FindConnMethodFromCache( aCmId );
       
  2207     if ( index != KErrNotFound )
       
  2208         {
       
  2209         // Already open in cache. Copy the connection method to session instance.
       
  2210         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
       
  2211         }
       
  2212     else
       
  2213         {
       
  2214         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
       
  2215         }
       
  2216 
       
  2217     retVal = cmInstance->GetStringAttributeL( aAttribute );
       
  2218 
       
  2219     CloseConnMethod( *cmInstance );
       
  2220     CleanupStack::PopAndDestroy( cmInstance );
       
  2221 
       
  2222     OstTraceFunctionExit0( CCMMCACHE_GETCONNECTIONMETHODINFOSTRINGL_EXIT );
       
  2223     return retVal;
       
  2224     }
       
  2225 
       
  2226 //-----------------------------------------------------------------------------
       
  2227 // CCmmCache::GetConnectionMethodInfoString8L
       
  2228 //-----------------------------------------------------------------------------
       
  2229 //
       
  2230 HBufC8* CCmmCache::GetConnectionMethodInfoString8L(
       
  2231         const TUint32& aCmId,
       
  2232         const TUint32& aAttribute )
       
  2233     {
       
  2234     OstTraceFunctionEntry0( CCMMCACHE_GETCONNECTIONMETHODINFOSTRING8L_ENTRY );
       
  2235 
       
  2236     HBufC8* retVal( NULL );
       
  2237 
       
  2238     CCmmConnMethodInstance* cmInstance = CCmmConnMethodInstance::NewLC( NULL, this );
       
  2239 
       
  2240     // Check if connection method is already opened in cache.
       
  2241     TInt index = FindConnMethodFromCache( aCmId );
       
  2242     if ( index != KErrNotFound )
       
  2243         {
       
  2244         // Already open in cache. Copy the connection method to session instance.
       
  2245         cmInstance->CopyDataL( iConnMethodArray[index] ); // Will increase reference counter.
       
  2246         }
       
  2247     else
       
  2248         {
       
  2249         OpenConnectionMethodInstanceL( *cmInstance, aCmId );
       
  2250         }
       
  2251 
       
  2252     retVal = cmInstance->GetString8AttributeL( aAttribute );
       
  2253 
       
  2254     CloseConnMethod( *cmInstance );
       
  2255     CleanupStack::PopAndDestroy( cmInstance );
       
  2256 
       
  2257     OstTraceFunctionExit0( CCMMCACHE_GETCONNECTIONMETHODINFOSTRING8L_EXIT );
       
  2258     return retVal;
       
  2259     }
       
  2260 
       
  2261 
       
  2262 //-----------------------------------------------------------------------------
       
  2263 // CCmmCache::GetBearerInfoIntL
       
  2264 //-----------------------------------------------------------------------------
       
  2265 //
       
  2266 TUint32 CCmmCache::GetBearerInfoIntL(
       
  2267         const TUint32& aBearerType,
       
  2268         const TUint32& aAttribute )
       
  2269     {
       
  2270     OstTraceFunctionEntry0( CCMMCACHE_GETBEARERINFOINTL_ENTRY );
       
  2271 
       
  2272     TUint32 retVal( 0 );
       
  2273     TBool found( EFalse );
       
  2274 
       
  2275     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  2276         {
       
  2277         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == aBearerType )
       
  2278             {
       
  2279             found = ETrue;
       
  2280             retVal = ( *iPlugins )[i]->GetBearerInfoIntL( aAttribute );
       
  2281             break;
       
  2282             }
       
  2283         }
       
  2284     if ( !found )
       
  2285         {
       
  2286         User::Leave( KErrArgument );
       
  2287         }
       
  2288 
       
  2289     OstTraceFunctionExit0( CCMMCACHE_GETBEARERINFOINTL_EXIT );
       
  2290     return retVal;
       
  2291     }
       
  2292 
       
  2293 //-----------------------------------------------------------------------------
       
  2294 // CCmmCache::GetBearerInfoBoolL
       
  2295 //-----------------------------------------------------------------------------
       
  2296 //
       
  2297 TBool CCmmCache::GetBearerInfoBoolL(
       
  2298         const TUint32& aBearerType,
       
  2299         const TUint32& aAttribute )
       
  2300     {
       
  2301     OstTraceFunctionEntry0( CCMMCACHE_GETBEARERINFOBOOLL_ENTRY );
       
  2302 
       
  2303     TBool retVal( EFalse );
       
  2304     TBool found( EFalse );
       
  2305 
       
  2306     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  2307         {
       
  2308         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == aBearerType )
       
  2309             {
       
  2310             found = ETrue;
       
  2311             retVal = ( *iPlugins )[i]->GetBearerInfoBoolL( aAttribute );
       
  2312             break;
       
  2313             }
       
  2314         }
       
  2315     if ( !found )
       
  2316         {
       
  2317         User::Leave( KErrArgument );
       
  2318         }
       
  2319 
       
  2320     OstTraceFunctionExit0( CCMMCACHE_GETBEARERINFOBOOLL_EXIT );
       
  2321     return retVal;
       
  2322     }
       
  2323 
       
  2324 //-----------------------------------------------------------------------------
       
  2325 // CCmmCache::GetBearerInfoStringL
       
  2326 //-----------------------------------------------------------------------------
       
  2327 //
       
  2328 HBufC* CCmmCache::GetBearerInfoStringL(
       
  2329         const TUint32& aBearerType,
       
  2330         const TUint32& aAttribute )
       
  2331     {
       
  2332     OstTraceFunctionEntry0( CCMMCACHE_GETBEARERINFOSTRINGL_ENTRY );
       
  2333 
       
  2334     HBufC* retVal( NULL );
       
  2335     TBool found( EFalse );
       
  2336 
       
  2337     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  2338         {
       
  2339         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == aBearerType )
       
  2340             {
       
  2341             found = ETrue;
       
  2342             retVal = ( *iPlugins )[i]->GetBearerInfoStringL( aAttribute );
       
  2343             break;
       
  2344             }
       
  2345         }
       
  2346     if ( !found )
       
  2347         {
       
  2348         User::Leave( KErrArgument );
       
  2349         }
       
  2350 
       
  2351     OstTraceFunctionExit0( CCMMCACHE_GETBEARERINFOSTRINGL_EXIT );
       
  2352     return retVal;
       
  2353     }
       
  2354 
       
  2355 //-----------------------------------------------------------------------------
       
  2356 // CCmmCache::GetBearerInfoString8L
       
  2357 //-----------------------------------------------------------------------------
       
  2358 //
       
  2359 HBufC8* CCmmCache::GetBearerInfoString8L(
       
  2360         const TUint32& aBearerType,
       
  2361         const TUint32& aAttribute )
       
  2362     {
       
  2363     OstTraceFunctionEntry0( CCMMCACHE_GETBEARERINFOSTRING8L_ENTRY );
       
  2364 
       
  2365     HBufC8* retVal( NULL );
       
  2366     TBool found( EFalse );
       
  2367 
       
  2368     for ( TInt i = 0; i < iPlugins->Count(); i++ )
       
  2369         {
       
  2370         if ( ( *iPlugins )[i]->GetBearerInfoIntL( CMManager::ECmBearerType ) == aBearerType )
       
  2371             {
       
  2372             found = ETrue;
       
  2373             retVal = ( *iPlugins )[i]->GetBearerInfoString8L( aAttribute );
       
  2374             break;
       
  2375             }
       
  2376         }
       
  2377     if ( !found )
       
  2378         {
       
  2379         User::Leave( KErrArgument );
       
  2380         }
       
  2381 
       
  2382     OstTraceFunctionExit0( CCMMCACHE_GETBEARERINFOSTRING8L_EXIT );
       
  2383     return retVal;
       
  2384     }
       
  2385 
       
  2386 //-----------------------------------------------------------------------------
       
  2387 // Read general connection settings from database.
       
  2388 //-----------------------------------------------------------------------------
       
  2389 //
       
  2390 void CCmmCache::ReadGenConnSettingsL( TCmGenConnSettings& aGenConnSettings ) const
       
  2391     {
       
  2392     OstTraceFunctionEntry0( CCMMCACHE_READGENCONNSETTINGSL_ENTRY );
       
  2393 
       
  2394     CommsDat::CMDBRecordSet<CCDDefConnRecord>* defConnRecordSet =
       
  2395             new( ELeave ) CommsDat::CMDBRecordSet<CCDDefConnRecord>(
       
  2396                     iCmManagerImpl->TableId( ECmmDbDefConnRecord ) );
       
  2397     CleanupStack::PushL( defConnRecordSet );
       
  2398 
       
  2399     CCDDefConnRecord* defConnRecord =
       
  2400             new( ELeave ) CCDDefConnRecord(
       
  2401                     iCmManagerImpl->TableId( ECmmDbDefConnRecord ) );
       
  2402     CleanupStack::PushL( defConnRecord );
       
  2403 
       
  2404     TRAP_IGNORE( defConnRecordSet->LoadL( Session() ) );
       
  2405     if ( defConnRecordSet->iRecords.Count() > 0 )
       
  2406         {
       
  2407         defConnRecord->SetElementId( defConnRecordSet->iRecords[0]->ElementId() );
       
  2408         defConnRecord->LoadL( Session() );
       
  2409 
       
  2410         aGenConnSettings.iUsageOfWlan =
       
  2411                 TCmUsageOfWlan( ( TInt )defConnRecord->iUsageOfWlan );
       
  2412         aGenConnSettings.iCellularDataUsageHome =
       
  2413                 TCmCellularDataUsage( ( TInt )defConnRecord->iCellularDataUsageHome );
       
  2414         aGenConnSettings.iCellularDataUsageVisitor =
       
  2415                 TCmCellularDataUsage( ( TInt )defConnRecord->iCellularDataUsageVisitor );
       
  2416         }
       
  2417     else
       
  2418         {
       
  2419         iTrans->OpenTransactionLC();
       
  2420 
       
  2421         TUint defConnType( 0 );
       
  2422         TUint internetSnapId( 0 );
       
  2423         iInstanceMapping->InternetDestinationIdL( internetSnapId );
       
  2424         if ( internetSnapId )
       
  2425             {
       
  2426             defConnType = ECmDefConnDestination;
       
  2427             }
       
  2428 
       
  2429         aGenConnSettings.iUsageOfWlan = ECmUsageOfWlanKnown;
       
  2430         aGenConnSettings.iCellularDataUsageHome = ECmCellularDataUsageAutomatic;
       
  2431         aGenConnSettings.iCellularDataUsageVisitor = ECmCellularDataUsageConfirm;
       
  2432 
       
  2433         defConnRecord->SetRecordId( KCDNewRecordRequest );
       
  2434         defConnRecord->iDefConnType = defConnType;
       
  2435         defConnRecord->iDefConnUid = internetSnapId;
       
  2436         defConnRecord->iUsageOfWlan = ( TUint )aGenConnSettings.iUsageOfWlan;
       
  2437         defConnRecord->iCellularDataUsageHome = ( TUint )aGenConnSettings.iCellularDataUsageHome;
       
  2438         defConnRecord->iCellularDataUsageVisitor = ( TUint )aGenConnSettings.iCellularDataUsageVisitor;
       
  2439         defConnRecord->StoreL( Session() );
       
  2440 
       
  2441         iTrans->CommitTransactionL();
       
  2442         }
       
  2443 
       
  2444     CleanupStack::PopAndDestroy( defConnRecord );
       
  2445     CleanupStack::PopAndDestroy( defConnRecordSet );
       
  2446 
       
  2447     OstTraceFunctionExit0( CCMMCACHE_READGENCONNSETTINGSL_EXIT );
       
  2448     }
       
  2449 
       
  2450 //-----------------------------------------------------------------------------
       
  2451 // Write general connection settings to database.
       
  2452 //-----------------------------------------------------------------------------
       
  2453 //
       
  2454 void CCmmCache::WriteGenConnSettingsL( const TCmGenConnSettings& aGenConnSettings )
       
  2455     {
       
  2456     OstTraceFunctionEntry0( CCMMCACHE_WRITEGENCONNSETTINGSL_ENTRY );
       
  2457 
       
  2458     iTrans->OpenTransactionLC();
       
  2459 
       
  2460     ReplaceGenConnSettingsL( aGenConnSettings );
       
  2461 
       
  2462     iTrans->CommitTransactionL();
       
  2463 
       
  2464     OstTraceFunctionExit0( CCMMCACHE_WRITEGENCONNSETTINGSL_EXIT );
       
  2465     }
       
  2466 
       
  2467 //-----------------------------------------------------------------------------
       
  2468 //  CCmmCache::ReplaceGenConnSettingsL()
       
  2469 //-----------------------------------------------------------------------------
       
  2470 //
       
  2471 void CCmmCache::ReplaceGenConnSettingsL( const TCmGenConnSettings& aGenConnSettings )
       
  2472     {
       
  2473     OstTraceFunctionEntry0( CCMMCACHE_REPLACEGENCONNSETTINGSL_ENTRY );
       
  2474     TBool oldRecordExists( EFalse );
       
  2475 
       
  2476     CommsDat::CMDBRecordSet<CCDDefConnRecord>* defConnRecordSet =
       
  2477             new( ELeave ) CommsDat::CMDBRecordSet<CCDDefConnRecord>(
       
  2478                     iCmManagerImpl->TableId( ECmmDbDefConnRecord ) );
       
  2479     CleanupStack::PushL( defConnRecordSet );
       
  2480 
       
  2481     CCDDefConnRecord* defConnRecord =
       
  2482             new( ELeave ) CCDDefConnRecord(
       
  2483                     iCmManagerImpl->TableId( ECmmDbDefConnRecord ) );
       
  2484     CleanupStack::PushL( defConnRecord );
       
  2485 
       
  2486     TRAPD( err, defConnRecordSet->LoadL( Session() ) );
       
  2487     if ( err == KErrNone )
       
  2488         {
       
  2489         defConnRecord->SetElementId( defConnRecordSet->iRecords[0]->ElementId() );
       
  2490         defConnRecord->LoadL( Session() );
       
  2491         oldRecordExists = ETrue;
       
  2492         }
       
  2493     else if ( err == KErrNotFound )
       
  2494         {
       
  2495         defConnRecord->SetRecordId( KCDNewRecordRequest );
       
  2496         }
       
  2497     else
       
  2498         {
       
  2499         User::Leave( err );
       
  2500         }
       
  2501 
       
  2502     defConnRecord->iUsageOfWlan = ( TUint )aGenConnSettings.iUsageOfWlan;
       
  2503     defConnRecord->iCellularDataUsageHome = ( TUint )aGenConnSettings.iCellularDataUsageHome;
       
  2504     defConnRecord->iCellularDataUsageVisitor = ( TUint )aGenConnSettings.iCellularDataUsageVisitor;
       
  2505 
       
  2506     if ( oldRecordExists )
       
  2507         {
       
  2508         defConnRecord->ModifyL( Session() );
       
  2509         }
       
  2510     else
       
  2511         {
       
  2512         defConnRecord->StoreL( Session() );
       
  2513         }
       
  2514 
       
  2515     CleanupStack::PopAndDestroy( defConnRecord );
       
  2516     CleanupStack::PopAndDestroy( defConnRecordSet );
       
  2517 
       
  2518     OstTraceFunctionExit0( CCMMCACHE_REPLACEGENCONNSETTINGSL_EXIT );
       
  2519     }
       
  2520 
       
  2521 // ---------------------------------------------------------------------------
       
  2522 // Opens a transaction and deletes the given connection method.
       
  2523 // ---------------------------------------------------------------------------
       
  2524 //
       
  2525 void CCmmCache::DeletePluginL( CCmmConnMethodStruct& aConnMethodStruct )
       
  2526     {
       
  2527     iTrans->OpenTransactionLC();
       
  2528     aConnMethodStruct.GetPlugin()->DeleteL();
       
  2529     iTrans->CommitTransactionL();
       
  2530     }
       
  2531 
       
  2532 // ---------------------------------------------------------------------------
       
  2533 // Enumerates connections and checks if the given connection method is
       
  2534 // connected.
       
  2535 // ---------------------------------------------------------------------------
       
  2536 //
       
  2537 TBool CCmmCache::CheckIfCmConnected( const TUint32& aCmId ) const
       
  2538     {
       
  2539     OstTraceFunctionEntry0( CCMMCACHE_CHECKIFCMCONNECTED_ENTRY );
       
  2540 
       
  2541     TBool result( EFalse );
       
  2542     RSocketServ ss;
       
  2543     RConnection connection;
       
  2544     TUint connectionCount( 0 );
       
  2545 
       
  2546     if ( ss.Connect() == KErrNone )
       
  2547         {
       
  2548         if ( connection.Open( ss, KAfInet ) == KErrNone )
       
  2549             {
       
  2550             if ( connection.EnumerateConnections( connectionCount ) == KErrNone )
       
  2551                 {
       
  2552                 TPckgBuf<TConnectionInfo> connInfo;
       
  2553 
       
  2554                 for ( TInt i = 1; i <= connectionCount; i++ )
       
  2555                     {
       
  2556                     connection.GetConnectionInfo( i, connInfo );
       
  2557 
       
  2558                     if ( connInfo().iIapId == aCmId )
       
  2559                         {
       
  2560                         result = ETrue;
       
  2561                         break;
       
  2562                         }
       
  2563                     }
       
  2564 
       
  2565                 }
       
  2566             connection.Close();
       
  2567             }
       
  2568         ss.Close();
       
  2569         }
       
  2570 
       
  2571     OstTraceFunctionExit0( CCMMCACHE_CHECKIFCMCONNECTED_EXIT );
       
  2572 
       
  2573     return result;
       
  2574     }
       
  2575 
       
  2576 // ---------------------------------------------------------------------------
       
  2577 // Enumerates connections and checks if any of the connection methods in the
       
  2578 // given destination is connected.
       
  2579 // ---------------------------------------------------------------------------
       
  2580 //
       
  2581 TBool CCmmCache::DestinationConnectedL(
       
  2582         const TUint32 aDestinationId,
       
  2583         CCmmDestinationInstance* aDestinationInstance ) const
       
  2584     {
       
  2585     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONCONNECTEDL_ENTRY );
       
  2586 
       
  2587     TBool result( EFalse );
       
  2588     RSocketServ ss;
       
  2589     RConnection connection;
       
  2590     TUint connectionCount( 0 );
       
  2591 
       
  2592     if ( ss.Connect() == KErrNone )
       
  2593         {
       
  2594         if ( connection.Open( ss, KAfInet ) == KErrNone )
       
  2595             {
       
  2596             if ( connection.EnumerateConnections( connectionCount ) == KErrNone )
       
  2597                 {
       
  2598                 RArray<TCmmConnMethodItem> connMethodArray;
       
  2599                 CleanupClosePushL( connMethodArray );
       
  2600 
       
  2601                 // If destination instance provided, take the destination's
       
  2602                 // connection methods from there. Otherwise get the connection
       
  2603                 // methods from instance mapping. (If the destination is marked
       
  2604                 // to be deleted, instance mapping won't have information about
       
  2605                 // it.)
       
  2606                 if ( aDestinationInstance )
       
  2607                     {
       
  2608                     for ( TInt i = 0; i < aDestinationInstance->iConnMethodItemArray.Count(); i++ )
       
  2609                         {
       
  2610                         connMethodArray.AppendL( aDestinationInstance->iConnMethodItemArray[i] );
       
  2611                         }
       
  2612                     }
       
  2613                 else
       
  2614                     {
       
  2615                     iInstanceMapping->GetConnMethodsFromDestinationL( aDestinationId, connMethodArray );
       
  2616                     }
       
  2617 
       
  2618                 // Iterate through all connections.
       
  2619                 TPckgBuf<TConnectionInfo> connInfo;
       
  2620                 for ( TUint i = 1; i <= connectionCount; i++ )
       
  2621                     {
       
  2622                     connection.GetConnectionInfo( i, connInfo );
       
  2623 
       
  2624                     // Iterate through all connection methods in destinations.
       
  2625                     for ( TInt j = 0; j < connMethodArray.Count(); j++ )
       
  2626                         {
       
  2627                         if ( connInfo().iIapId == connMethodArray[j].iId )
       
  2628                             {
       
  2629                             result = ETrue;
       
  2630                             break;
       
  2631                             }
       
  2632                         }
       
  2633                     if ( result )
       
  2634                         {
       
  2635                         break;
       
  2636                         }
       
  2637                     }
       
  2638 
       
  2639                 CleanupStack::PopAndDestroy( &connMethodArray );
       
  2640                 }
       
  2641             connection.Close();
       
  2642             }
       
  2643         ss.Close();
       
  2644         }
       
  2645 
       
  2646     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONCONNECTEDL_EXIT );
       
  2647     return result;
       
  2648     }
       
  2649 
       
  2650 // ---------------------------------------------------------------------------
       
  2651 // Check from database if the given destination is an embedded destination in
       
  2652 // any other destination.
       
  2653 // ---------------------------------------------------------------------------
       
  2654 //
       
  2655 TBool CCmmCache::DestinationIsEmbedded( const TUint32& aDestinationId ) const
       
  2656     {
       
  2657     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONISEMBEDDED_ENTRY );
       
  2658 
       
  2659     TBool isEmbedded = iInstanceMapping->DestinationIsEmbedded( aDestinationId );
       
  2660 
       
  2661     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONISEMBEDDED_EXIT );
       
  2662 
       
  2663     return isEmbedded;
       
  2664     }
       
  2665 
       
  2666 // ---------------------------------------------------------------------------
       
  2667 // Check from database if the given destination has an embedded destination.
       
  2668 // ---------------------------------------------------------------------------
       
  2669 //
       
  2670 TBool CCmmCache::DestinationHasEmbedded( const TUint32& aDestinationId ) const
       
  2671     {
       
  2672     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONHASEMBEDDED_ENTRY );
       
  2673 
       
  2674     TBool hasEmbedded = iInstanceMapping->DestinationHasEmbedded( aDestinationId );
       
  2675 
       
  2676     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONHASEMBEDDED_EXIT );
       
  2677 
       
  2678     return hasEmbedded;
       
  2679     }
       
  2680 
       
  2681 // ---------------------------------------------------------------------------
       
  2682 // Check from database if the given destination is pointed to by any virtual
       
  2683 // IAP.
       
  2684 // ---------------------------------------------------------------------------
       
  2685 //
       
  2686 TBool CCmmCache::DestinationPointedToByVirtualIap( const TUint32& aDestinationId ) const
       
  2687     {
       
  2688     OstTraceFunctionEntry0( CCMMCACHE_DESTINATIONPOINTEDTOBYVIRTUALIAP_ENTRY );
       
  2689 
       
  2690     TBool pointedByVirtual =
       
  2691             iInstanceMapping->DestinationPointedToByVirtualIap( aDestinationId );
       
  2692 
       
  2693     OstTraceFunctionExit0( CCMMCACHE_DESTINATIONPOINTEDTOBYVIRTUALIAP_EXIT );
       
  2694 
       
  2695     return pointedByVirtual;
       
  2696     }
       
  2697 
       
  2698 // ---------------------------------------------------------------------------
       
  2699 // Check from database if the given connection method is pointed to by any
       
  2700 // virtual IAP.
       
  2701 // ---------------------------------------------------------------------------
       
  2702 //
       
  2703 TBool CCmmCache::ConnMethodPointedToByVirtualIap( const TUint32& aConnMethodId ) const
       
  2704     {
       
  2705 
       
  2706     TBool pointedByVirtual =
       
  2707             iInstanceMapping->ConnMethodPointedToByVirtualIap( aConnMethodId );
       
  2708 
       
  2709     return pointedByVirtual;
       
  2710     }
       
  2711 
       
  2712 // ---------------------------------------------------------------------------
       
  2713 // Check if the given connection method is the only connection method in the
       
  2714 // given destination and if a virtual IAP points to that destination.
       
  2715 // ---------------------------------------------------------------------------
       
  2716 //
       
  2717 TBool CCmmCache::ConnMethodInDestinationButLocked(
       
  2718         const TUint32& aConnMethodId, const TUint32& aDestinationId ) const
       
  2719     {
       
  2720     OstTraceFunctionEntry0( CCMMCACHE_CONNMETHODINDESTINATIONBUTLOCKED_ENTRY );
       
  2721 
       
  2722     TBool inAndlocked = iInstanceMapping->
       
  2723             ConnMethodInDestinationButLocked( aConnMethodId, aDestinationId );
       
  2724 
       
  2725     OstTraceFunctionExit0( CCMMCACHE_CONNMETHODINDESTINATIONBUTLOCKED_EXIT );
       
  2726 
       
  2727     return inAndlocked;
       
  2728     }
       
  2729 
       
  2730 // ---------------------------------------------------------------------------
       
  2731 // Remove all references to the given connection method from the datamobility
       
  2732 // selection policy records. Then update instance mapping to reflect the
       
  2733 // current database state, and notify any possible client handles for the
       
  2734 // changed destinations. Also removes the connection method from any
       
  2735 // destination handles the client has open.
       
  2736 // ---------------------------------------------------------------------------
       
  2737 //
       
  2738 void CCmmCache::RemoveAllReferencesToConnMethodL(
       
  2739         CCmmConnMethodInstance& aConnMethodInstance )
       
  2740     {
       
  2741     OstTraceFunctionEntry0( CCMMCACHE_REMOVEALLREFERENCESTOCONNMETHODL_ENTRY );
       
  2742 
       
  2743     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
  2744 
       
  2745     iTrans->OpenTransactionLC();
       
  2746 
       
  2747     // Create DataMobilitySelectionPolicy-record set.
       
  2748     CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* snapRecordSet =
       
  2749             new( ELeave ) CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>(
       
  2750                     iCmManagerImpl->TableId( ECmmDbSnapRecord ) );
       
  2751     CleanupStack::PushL( snapRecordSet );
       
  2752 
       
  2753     // Create a DataMobilitySelectionPolicy-record.
       
  2754     CCDDataMobilitySelectionPolicyRecord* snapRecord =
       
  2755             new( ELeave ) CCDDataMobilitySelectionPolicyRecord(
       
  2756                     iCmManagerImpl->TableId( ECmmDbSnapRecord ) );
       
  2757     CleanupStack::PushL( snapRecord );
       
  2758 
       
  2759     TRAP_IGNORE( snapRecordSet->LoadL( iTrans->Session() ) );
       
  2760 
       
  2761     // Read IAP ID from each record and delete any that match the connection
       
  2762     // method we are removing all references for.
       
  2763     TUint32 connMethodIdInRecord( 0 );
       
  2764     TInt snapRecordCount( snapRecordSet->iRecords.Count() );
       
  2765     for ( TInt i = 0; i < snapRecordCount; i++ )
       
  2766         {
       
  2767         snapRecord->SetElementId( snapRecordSet->iRecords[i]->ElementId() );
       
  2768         snapRecord->LoadL( iTrans->Session() );
       
  2769 
       
  2770         connMethodIdInRecord = ( snapRecord->iIAP & KCDMaskShowRecordId ) >> 8;
       
  2771         if ( connMethodIdInRecord == connMethodId )
       
  2772             {
       
  2773             snapRecord->DeleteL( iTrans->Session() );
       
  2774             }
       
  2775         }
       
  2776     CleanupStack::PopAndDestroy( snapRecord );
       
  2777     CleanupStack::PopAndDestroy( snapRecordSet );
       
  2778 
       
  2779     iTrans->CommitTransactionL();
       
  2780 
       
  2781     // Reference count will be zero if this method call is not part of some
       
  2782     // bigger operation (e.g. connection method delete).
       
  2783     if ( iTrans->GetReferenceCount() == 0 )
       
  2784         {
       
  2785         // Update instance mapping to reflect the current database state, and
       
  2786         // notify any possible client handles for the changed destinations.
       
  2787         RArray<TUint32> changedDestinations;
       
  2788         iInstanceMapping->RemoveConnMethodFromDestinations( connMethodId, changedDestinations );
       
  2789         for ( TInt i = 0; i < changedDestinations.Count(); i++ )
       
  2790             {
       
  2791             TCmmIdStruct idStruct( changedDestinations[i], 0 );
       
  2792             aConnMethodInstance.RefreshHandlesForAllSessions( idStruct );
       
  2793             }
       
  2794         changedDestinations.Close();
       
  2795 
       
  2796         // Remove the connection method from any destination handles the client
       
  2797         // has open.
       
  2798         aConnMethodInstance.RemoveConnMethodFromSessionDestinationHandles( connMethodId );
       
  2799         }
       
  2800 
       
  2801     OstTraceFunctionExit0( CCMMCACHE_REMOVEALLREFERENCESTOCONNMETHODL_EXIT );
       
  2802     }
       
  2803 
       
  2804 // ---------------------------------------------------------------------------
       
  2805 // Update the ID of a new destination from temporary ID to real ID after a
       
  2806 // successful update to database.
       
  2807 // ---------------------------------------------------------------------------
       
  2808 //
       
  2809 void CCmmCache::RefreshDestinationId( const TCmmIdStruct& aIdStruct )
       
  2810     {
       
  2811     OstTraceFunctionEntry0( CCMMCACHE_REFRESHDESTINATIONID_ENTRY );
       
  2812 
       
  2813     // Iterate destinations in cache and update the ID if match found.
       
  2814     for ( TInt i = 0; i < iDestinationArray.Count(); i++ )
       
  2815         {
       
  2816         if ( iDestinationArray[i]->GetId() == aIdStruct.iTemporaryId )
       
  2817             {
       
  2818             iDestinationArray[i]->SetId( aIdStruct.iRealId );
       
  2819             break;
       
  2820             }
       
  2821         }
       
  2822     OstTraceFunctionExit0( CCMMCACHE_REFRESHDESTINATIONID_EXIT );
       
  2823     }
       
  2824 
       
  2825 // ---------------------------------------------------------------------------
       
  2826 // Update the ID of a new connection method from temporary ID to real ID after
       
  2827 // a successful update to database.
       
  2828 // ---------------------------------------------------------------------------
       
  2829 //
       
  2830 void CCmmCache::RefreshConnMethodId( const TCmmIdStruct& aIdStruct )
       
  2831     {
       
  2832     OstTraceFunctionEntry0( CCMMCACHE_REFRESHCONNMETHODID_ENTRY );
       
  2833 
       
  2834     // Iterate connection methods in cache and update the ID if match found.
       
  2835     for ( TInt i = 0; i < iConnMethodArray.Count(); i++ )
       
  2836         {
       
  2837         if ( iConnMethodArray[i]->GetId() == aIdStruct.iTemporaryId )
       
  2838             {
       
  2839             iConnMethodArray[i]->SetId( aIdStruct.iRealId );
       
  2840             break; // Can only be 1 match.
       
  2841             }
       
  2842         }
       
  2843     OstTraceFunctionExit0( CCMMCACHE_REFRESHCONNMETHODID_EXIT );
       
  2844     }
       
  2845 
       
  2846 // ---------------------------------------------------------------------------
       
  2847 // During destination update, after updating connection methods inside the
       
  2848 // destination, the database records containing the information of what
       
  2849 // connection methods are inside the destination need to be updated with real
       
  2850 // IDs for any newly created connection methods. These real IDs are held in the
       
  2851 // temporary array iUpdatedConnMethods until successful commit to database.
       
  2852 // This method is used to find out those real IDs before that.
       
  2853 // ---------------------------------------------------------------------------
       
  2854 //
       
  2855 void CCmmCache::TranslateTemporaryId( const TUint32& aTemporaryId, TUint32& aRealId ) const
       
  2856     {
       
  2857     OstTraceFunctionEntry0( CCMMCACHE_TRANSLATETEMPORARYID_ENTRY );
       
  2858 
       
  2859     aRealId = 0;
       
  2860 
       
  2861     for ( TInt i = 0; i < iUpdatedConnMethods.Count(); i++ )
       
  2862         {
       
  2863         if ( iUpdatedConnMethods[i].iTemporaryId == aTemporaryId )
       
  2864             {
       
  2865             aRealId = iUpdatedConnMethods[i].iRealId;
       
  2866             break;
       
  2867             }
       
  2868         }
       
  2869     if ( !aRealId )
       
  2870         {
       
  2871         ASSERT( 0 );
       
  2872         }
       
  2873     OstTraceFunctionExit0( CCMMCACHE_TRANSLATETEMPORARYID_EXIT );
       
  2874     }
       
  2875 
       
  2876 // ---------------------------------------------------------------------------
       
  2877 // Check if the given connection method can have all references removed and
       
  2878 // made into an uncategorized connection method.
       
  2879 // ---------------------------------------------------------------------------
       
  2880 //
       
  2881 void CCmmCache::CheckIfConnMethodReferencesCanBeRemovedL(
       
  2882         const CCmmConnMethodInstance& aConnMethodInstance )
       
  2883     {
       
  2884     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
  2885 
       
  2886     // Check that connection method exists in database.
       
  2887     if ( !iInstanceMapping->ValidConnMethodId( connMethodId ) )
       
  2888         {
       
  2889         User::Leave( KErrNotFound );
       
  2890         }
       
  2891 
       
  2892     // Can't remove an embedded destination this way.
       
  2893     if ( aConnMethodInstance.IsEmbeddedDestination() )
       
  2894         {
       
  2895         User::Leave( KErrArgument );
       
  2896         }
       
  2897 
       
  2898     //TODO, what if protected?
       
  2899 
       
  2900     // Iterate all destinations in database and check if possible reference can
       
  2901     // be removed.
       
  2902     RArray<TUint32> dbDestinations;
       
  2903     CleanupClosePushL( dbDestinations );
       
  2904     iInstanceMapping->GetDestinationsL( dbDestinations );
       
  2905     for ( TInt i = 0; i < dbDestinations.Count(); i++ )
       
  2906         {
       
  2907         if ( iInstanceMapping->ConnMethodInDestinationButLocked( connMethodId, dbDestinations[i] ) )
       
  2908             {
       
  2909             User::Leave( KErrLocked );
       
  2910             }
       
  2911         }
       
  2912     CleanupStack::PopAndDestroy( &dbDestinations );
       
  2913 
       
  2914     // Can't remove a connection method that is in use.
       
  2915     if ( CheckIfCmConnected( connMethodId ) )
       
  2916         {
       
  2917         User::Leave( KErrInUse );
       
  2918         }
       
  2919     }
       
  2920 
       
  2921 // ---------------------------------------------------------------------------
       
  2922 // Check if the given connection method can be deleted.
       
  2923 // ---------------------------------------------------------------------------
       
  2924 //
       
  2925 void CCmmCache::CheckIfConnMethodCanBeDeletedL(
       
  2926         const CCmmConnMethodInstance& aConnMethodInstance )
       
  2927     {
       
  2928     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
  2929 
       
  2930     // Find connection method from cache.
       
  2931     TInt index = FindConnMethodFromCache( connMethodId );
       
  2932     if ( index == KErrNotFound )
       
  2933         {
       
  2934         User::Leave( KErrBadHandle );
       
  2935         }
       
  2936 
       
  2937     // Check connection method status at cache side.
       
  2938     switch ( iConnMethodArray[index]->GetStatus() )
       
  2939         {
       
  2940         case ECmmConnMethodStatusNotSaved:
       
  2941             {
       
  2942             // Connection method is not in database, nothing to delete.
       
  2943             User::Leave( KErrNotFound );
       
  2944             }
       
  2945             break;
       
  2946         case ECmmConnMethodStatusValid:
       
  2947             // Proceed.
       
  2948             break;
       
  2949         case ECmmConnMethodStatusToBeDeleted:
       
  2950             // Connection method has already been deleted.
       
  2951             return;
       
  2952         case ECmmConnMethodStatusChanged:
       
  2953         default:
       
  2954             {
       
  2955             ASSERT( 0 ); // Error, illegal status.
       
  2956             User::Leave( KErrCorrupt );
       
  2957             }
       
  2958             break;
       
  2959         }
       
  2960 
       
  2961     // Removing all references is part of deleting a connection method. Check
       
  2962     // if can do that.
       
  2963     CheckIfConnMethodReferencesCanBeRemovedL( aConnMethodInstance );
       
  2964 
       
  2965     // Check that no virtual IAP points to this connection method.
       
  2966     if ( iInstanceMapping->ConnMethodPointedToByVirtualIap( connMethodId ) )
       
  2967         {
       
  2968         User::Leave( KErrLocked );
       
  2969         }
       
  2970     }
       
  2971 
       
  2972 // ---------------------------------------------------------------------------
       
  2973 // Check if the given destination can be deleted.
       
  2974 // ---------------------------------------------------------------------------
       
  2975 //
       
  2976 void CCmmCache::CheckIfDestinationCanBeDeletedL(
       
  2977         const CCmmDestinationInstance& aDestinationInstance )
       
  2978     {
       
  2979     TUint32 destinationId( aDestinationInstance.GetId() );
       
  2980 
       
  2981     // Find destination from cache.
       
  2982     TInt index = FindDestinationFromCache( destinationId );
       
  2983     if ( index == KErrNotFound )
       
  2984         {
       
  2985         User::Leave( KErrBadHandle );
       
  2986         }
       
  2987 
       
  2988     // Check destination status in cache.
       
  2989     switch ( iDestinationArray[index]->GetStatus() )
       
  2990         {
       
  2991         case ECmmDestinationStatusNotSaved:
       
  2992             {
       
  2993             User::Leave( KErrNotFound );
       
  2994             }
       
  2995             break;
       
  2996         case ECmmDestinationStatusValid:
       
  2997             // Proceed.
       
  2998             break;
       
  2999         case ECmmDestinationStatusToBeDeleted:
       
  3000             // Destination has already been deleted.
       
  3001             return;
       
  3002         case ECmmDestinationStatusChanged:
       
  3003         default:
       
  3004             {
       
  3005             ASSERT( 0 ); // Error, illegal status.
       
  3006             User::Leave( KErrCorrupt );
       
  3007             }
       
  3008             break;
       
  3009         }
       
  3010 
       
  3011     // Check destination exists in database.
       
  3012     if ( !iInstanceMapping->ValidDestinationId( destinationId ) )
       
  3013         {
       
  3014         User::Leave( KErrNotFound );
       
  3015         }
       
  3016 
       
  3017     // Check if any virtual IAP points to this destination. Don't check session side.
       
  3018     if ( iInstanceMapping->DestinationPointedToByVirtualIap( destinationId ) )
       
  3019         {
       
  3020         User::Leave( KErrLocked );
       
  3021         }
       
  3022 
       
  3023     // Check if any of the connection methods in this destination are currently in use.
       
  3024     if ( DestinationConnectedL( destinationId ) )
       
  3025         {
       
  3026         User::Leave( KErrInUse );
       
  3027         }
       
  3028     }
       
  3029 
       
  3030 // ---------------------------------------------------------------------------
       
  3031 // Return the requested table ID.
       
  3032 // ---------------------------------------------------------------------------
       
  3033 //
       
  3034 CommsDat::TMDBElementId CCmmCache::TableId( TCmmDbRecords aRecord )
       
  3035     {
       
  3036     return iCmManagerImpl->TableId( aRecord );
       
  3037     }
       
  3038 
       
  3039 // ---------------------------------------------------------------------------
       
  3040 // TODO
       
  3041 // ---------------------------------------------------------------------------
       
  3042 //
       
  3043 void CCmmCache::DeleteDestinationForcedL( CCmmDestinationInstance& aDestinationInstance ) //TODO, OST
       
  3044     {
       
  3045     //TODO
       
  3046     if ( !DestinationConnectedL( 0, &aDestinationInstance ) )
       
  3047     //if ( !DestinationConnectedL( aDestinationInstance.GetId() ) ) //TODO
       
  3048         {
       
  3049         DeleteDestinationL( aDestinationInstance, ETrue );
       
  3050         }
       
  3051     }
       
  3052 
       
  3053 // End of file