cmmanager/cmmgr/Framework/Src/cmdestinationimpl.cpp
branchRCL_3
changeset 57 05bc53fe583b
parent 55 fc7b30ed2058
child 58 83ca720e2b9a
equal deleted inserted replaced
55:fc7b30ed2058 57:05bc53fe583b
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation of CCmDestinationImpl
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmdestinationimpl.h"
       
    19 #include "cmmanagerimpl.h"
       
    20 #include <cmpluginbaseeng.h>
       
    21 #include <cmpluginbase.h>
       
    22 #include <cmmanager.h>
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include <commsdattypeinfov1_1_internal.h>
       
    25 #include <commsdattypesv1_1_partner.h> 
       
    26 #endif
       
    27 #include "cmlogger.h"
       
    28 #include "cmmanager.hrh"
       
    29 #include <cmcommonconstants.h>
       
    30 #include "datamobilitycommsdattypes.h"
       
    31 #include <cmpluginembdestinationdef.h>
       
    32 #include <cmmanagerdef.h>
       
    33 #include <data_caging_path_literals.hrh>
       
    34 #include <cmmanager.rsg>
       
    35 #include <cmmanager.mbg>   // icons
       
    36 #include <AknsUtils.h>
       
    37 #include <e32cmn.h>
       
    38 
       
    39 // System includes
       
    40 #include <ecom/ecom.h>        // For REComSession
       
    41 #include <commsdattypesv1_1.h>
       
    42 
       
    43 #include <in_sock.h>
       
    44 
       
    45 using namespace CMManager;
       
    46 using namespace CommsDat;
       
    47 
       
    48 const TUint KDefaultTierManagerTagId = KAfInet;
       
    49 
       
    50 const TInt KDestinationIconConvTable[][4] = {
       
    51     { EAknsMajorGeneric, 
       
    52       EAknsMinorGenericQgnIndiSettProtectedAdd,
       
    53       EMbmCmmanagerQgn_prop_set_conn_dest_internet, 
       
    54       EMbmCmmanagerQgn_prop_set_conn_dest_internet_mask },
       
    55       
       
    56     { EAknsMajorGeneric, 
       
    57       EAknsMinorGenericQgnPropWmlGprs,
       
    58       EMbmCmmanagerQgn_prop_set_conn_dest_wap, 
       
    59       EMbmCmmanagerQgn_prop_set_conn_dest_wap_mask },                   
       
    60       
       
    61     { EAknsMajorGeneric, 
       
    62       EAknsMinorGenericQgnPropWmlGprs,
       
    63       EMbmCmmanagerQgn_prop_set_conn_dest_mms, 
       
    64       EMbmCmmanagerQgn_prop_set_conn_dest_mms_mask },
       
    65       
       
    66     { EAknsMajorGeneric, 
       
    67       EAknsMinorGenericQgnPropWmlGprs,
       
    68       EMbmCmmanagerQgn_prop_set_conn_dest_intranet, 
       
    69       EMbmCmmanagerQgn_prop_set_conn_dest_intranet_mask },          
       
    70       
       
    71     { EAknsMajorGeneric, 
       
    72       EAknsMinorGenericQgnPropWmlGprs,
       
    73       EMbmCmmanagerQgn_prop_set_conn_dest_operator, 
       
    74       EMbmCmmanagerQgn_prop_set_conn_dest_operator_mask },
       
    75       
       
    76     { EAknsMajorGeneric, 
       
    77       EAknsMinorGenericQgnPropWmlGprs,
       
    78       EMbmCmmanagerQgn_prop_set_conn_dest_icon1, 
       
    79       EMbmCmmanagerQgn_prop_set_conn_dest_icon1_mask },     
       
    80       
       
    81     { EAknsMajorGeneric, 
       
    82       EAknsMinorGenericQgnPropWmlGprs,
       
    83       EMbmCmmanagerQgn_prop_set_conn_dest_icon2, 
       
    84       EMbmCmmanagerQgn_prop_set_conn_dest_icon2_mask },
       
    85       
       
    86     { EAknsMajorGeneric, 
       
    87       EAknsMinorGenericQgnPropWmlGprs,
       
    88       EMbmCmmanagerQgn_prop_set_conn_dest_icon3, 
       
    89       EMbmCmmanagerQgn_prop_set_conn_dest_icon3_mask },            
       
    90       
       
    91     { EAknsMajorGeneric, 
       
    92       EAknsMinorGenericQgnPropWmlGprs,
       
    93       EMbmCmmanagerQgn_prop_set_conn_dest_icon4, 
       
    94       EMbmCmmanagerQgn_prop_set_conn_dest_icon4_mask },       
       
    95 
       
    96     { EAknsMajorGeneric, 
       
    97       EAknsMinorGenericQgnPropWmlGprs,
       
    98       EMbmCmmanagerQgn_prop_set_conn_dest_icon5, 
       
    99       EMbmCmmanagerQgn_prop_set_conn_dest_icon5_mask }, 
       
   100              
       
   101     { EAknsMajorGeneric, 
       
   102       EAknsMinorGenericQgnPropWmlGprs,
       
   103       EMbmCmmanagerQgn_prop_set_conn_dest_icon6, 
       
   104       EMbmCmmanagerQgn_prop_set_conn_dest_icon6_mask }, 
       
   105       
       
   106     { EAknsMajorGeneric, 
       
   107       EAknsMinorGenericQgnPropWmlGprs,
       
   108       EMbmCmmanagerQgn_prop_set_conn_dest_default, 
       
   109       EMbmCmmanagerQgn_prop_set_conn_dest_default_mask },            
       
   110     {0, 0, 0, 0}
       
   111     };
       
   112 
       
   113 // ================= MEMBER FUNCTIONS =======================
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CCmDestinationImpl::NewL()
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C CCmDestinationImpl* 
       
   120                            CCmDestinationImpl::NewL( CCmManagerImpl& aCmMgr,
       
   121                                                      const TDesC& aName )
       
   122     {
       
   123     CCmDestinationImpl* dest = 
       
   124                     new (ELeave) CCmDestinationImpl( aCmMgr );
       
   125     CleanupStack::PushL( dest );
       
   126     
       
   127     dest->ConstructL( aName );
       
   128     
       
   129     CleanupStack::Pop( dest );
       
   130     return dest;        
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CCmDestinationImpl::NewL()
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C CCmDestinationImpl* 
       
   138                         CCmDestinationImpl::NewL( CCmManagerImpl& aCmMgr,
       
   139                                                   TUint aDestinationId )
       
   140     {
       
   141     CCmDestinationImpl* dest = 
       
   142                     new (ELeave) CCmDestinationImpl( aCmMgr );
       
   143     CleanupStack::PushL( dest );
       
   144     
       
   145     dest->ConstructL( aDestinationId );
       
   146     
       
   147     CleanupStack::Pop( dest );
       
   148     return dest;        
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CCmDestinationImpl::NewL()
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 CCmDestinationImpl* CCmDestinationImpl::NewL( CCmManagerImpl& aCmMgr,
       
   156                                               CCmDestinationData* aData )
       
   157     {
       
   158     CCmDestinationImpl* dest = 
       
   159                     new (ELeave) CCmDestinationImpl( aCmMgr );
       
   160     dest->iData = aData;
       
   161     return dest;        
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CCmDestinationImpl::NewL()
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 CCmDestinationImpl* CCmDestinationImpl::NewL( CCmManagerImpl& aCmMgr,
       
   169                                               const TDesC& aName,
       
   170                                               TUint32 aDestId)
       
   171     {
       
   172     CCmDestinationImpl* dest = 
       
   173                               new (ELeave) CCmDestinationImpl( aCmMgr );
       
   174     CleanupStack::PushL( dest );
       
   175 
       
   176     dest->ConstructL( aName, aDestId );
       
   177 
       
   178     CleanupStack::Pop( dest );
       
   179     return dest;        
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CCmDestinationImpl::NewLC()
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 CCmDestinationImpl* CCmDestinationImpl::NewLC( CCmDestinationData* aData )
       
   188     {
       
   189     CCmDestinationImpl* dest = 
       
   190                     new (ELeave) CCmDestinationImpl( aData->iCmMgr );
       
   191     CleanupStack::PushL( dest );
       
   192     dest->iData = aData;
       
   193     return dest;        
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CCmDestinationImpl::CCmDestinationImpl()
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CCmDestinationImpl::CCmDestinationImpl( CCmManagerImpl& aCmMgr )
       
   202     : iCmMgr( aCmMgr )
       
   203     {
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CCmDestinationData::CCmDestinationData()
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 CCmDestinationData::CCmDestinationData( CCmManagerImpl& aCmMgr )
       
   211     : iCmMgr( aCmMgr ),
       
   212     iNewWithId ( EFalse )
       
   213     {
       
   214     }
       
   215     
       
   216 // -----------------------------------------------------------------------------
       
   217 // CCmDestinationData::~CCmDestinationData()
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 CCmDestinationData::~CCmDestinationData()
       
   221     {
       
   222     delete iMetaDataRec;
       
   223     delete iNetworkRecord;
       
   224     delete iDestAPRecord;
       
   225 
       
   226     if (iConnMethodArray)
       
   227         {
       
   228         ResetAndDestroyArray( iConnMethodArray, ETrue );        
       
   229         }
       
   230     if (iDeleteCmArray)
       
   231         {
       
   232         ResetAndDestroyArray( iDeleteCmArray, ETrue );        
       
   233         }
       
   234     
       
   235     CLOG_CLOSE;
       
   236     }
       
   237     
       
   238 // -----------------------------------------------------------------------------
       
   239 // CCmDestinationImpl::~CCmDestinationImpl()
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 CCmDestinationImpl::~CCmDestinationImpl()
       
   243     {
       
   244     if (iData)
       
   245         {
       
   246         if (GetRefCounter())
       
   247             {
       
   248             iCmMgr.RemoveDestFromPool(this);        
       
   249             }
       
   250         else //if leaves during construction refcounter is 0
       
   251             {
       
   252             delete iData; 
       
   253             }        
       
   254         }
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CCmDestinationImpl::ConstructL()
       
   259 // -----------------------------------------------------------------------------
       
   260 //    
       
   261 void CCmDestinationImpl::ConstructL( const TDesC& aName )
       
   262     {
       
   263     CLOG_CREATE;
       
   264     CLOG_NAME_2( _L("Destination_0x%x_%S"), this, &aName );
       
   265     
       
   266     iData =  new (ELeave) CCmDestinationData(iCmMgr);
       
   267     iData->iNetworkRecord = static_cast<CCDNetworkRecord *>(
       
   268                          CCDRecordBase::RecordFactoryL( KCDTIdNetworkRecord ) );
       
   269     
       
   270     iData->iConnMethodArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   271     iData->iDeleteCmArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   272     
       
   273     iData->iMetaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
   274                                        iCmMgr.IconTableId() );
       
   275 
       
   276     iData->iDestAPRecord = static_cast<CCDAccessPointRecord *>(
       
   277                     CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   278 
       
   279     SetNameL( aName );
       
   280 
       
   281     InitializeDestAPRecordL();
       
   282 
       
   283     CPluginItem* item = new (ELeave) CPluginItem;
       
   284     CleanupStack::PushL( item );
       
   285 
       
   286     // create the new record
       
   287     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
   288     CleanupStack::PushL( item->iDNRecord );
       
   289     
       
   290     AddToArrayL( item );
       
   291     
       
   292     CleanupStack::Pop( 2, item );  // iDNRecord, item
       
   293     iData->iIdIsValid = EFalse;// the Id is still zero here
       
   294     } 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CCmDestinationImpl::ConstructL()
       
   298 // -----------------------------------------------------------------------------
       
   299 //    
       
   300 void CCmDestinationImpl::ConstructL( const TDesC& aName, TUint32 aDestId )
       
   301     {
       
   302     CLOG_CREATE;
       
   303     CLOG_NAME_2( _L("Destination_0x%x_%S"), this, &aName );
       
   304 
       
   305     iData =  new (ELeave) CCmDestinationData(iCmMgr);
       
   306     iData->iNetworkRecord = static_cast<CCDNetworkRecord *>(
       
   307                     CCDRecordBase::RecordFactoryL( KCDTIdNetworkRecord ) );
       
   308 
       
   309     iData->iConnMethodArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   310     iData->iDeleteCmArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   311 
       
   312     iData->iMetaDataRec = new (ELeave) CCDSNAPMetadataRecord( iCmMgr.IconTableId() );
       
   313 
       
   314     iData->iDestAPRecord = static_cast<CCDAccessPointRecord *>(
       
   315                     CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   316 
       
   317     SetNameL( aName );
       
   318     
       
   319     TInt correctAPId = aDestId;
       
   320     TInt correctNetworkId = aDestId;
       
   321 	
       
   322     if ( aDestId > 0 && aDestId < 255 )
       
   323         {
       
   324         correctAPId = aDestId + KCmDefaultDestinationAPTagId;
       
   325         }
       
   326     else if ( aDestId > KCmDefaultDestinationAPTagId 
       
   327               && ( aDestId < ( KCmDefaultDestinationAPTagId+255 ) ) )
       
   328         {
       
   329         correctNetworkId = aDestId - KCmDefaultDestinationAPTagId;
       
   330         }
       
   331     else
       
   332         {
       
   333         User::Leave( KErrArgument );
       
   334         }
       
   335     
       
   336     SetIdL( correctAPId );
       
   337 
       
   338     InitializeDestAPRecordL();
       
   339 
       
   340     CPluginItem* item = new (ELeave) CPluginItem;
       
   341     CleanupStack::PushL( item );
       
   342 
       
   343     // create the new record
       
   344     iData->iNetworkRecord->SetRecordId( correctNetworkId );
       
   345     iData->iNewWithId = ETrue;
       
   346     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
   347     CleanupStack::PushL( item->iDNRecord );
       
   348 
       
   349     AddToArrayL( item );
       
   350 
       
   351     CleanupStack::Pop( 2, item );  // iDNRecord, item
       
   352     iData->iIdIsValid = EFalse;// the Id is still zero here
       
   353     } 
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CCmDestinationImpl::SetIdL()
       
   357 // -----------------------------------------------------------------------------
       
   358 //        
       
   359 void CCmDestinationImpl::SetIdL( TInt aDestId )
       
   360     {
       
   361     LOGGER_ENTERFN( "CCmDestinationImpl::SetIdL" );
       
   362 
       
   363     TInt correctAPId( aDestId );
       
   364     if ( aDestId > 0 && aDestId < 255 )
       
   365         {
       
   366         correctAPId = aDestId + KCmDefaultDestinationAPTagId;
       
   367         }
       
   368     else if ( aDestId < KCmDefaultDestinationAPTagId + 1
       
   369              || aDestId > KCmDefaultDestinationAPTagId + 255 )
       
   370         {
       
   371         User::Leave( KErrArgument );
       
   372         }
       
   373         
       
   374     CheckIfDestinationIdExistsL( correctAPId );
       
   375 
       
   376     iData->iDestAPRecord->iRecordTag = correctAPId;
       
   377     };
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CCmDestinationImpl::CheckIfDestinationIdExistsL()
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 void CCmDestinationImpl::CheckIfDestinationIdExistsL( TUint32 aDestId )
       
   384     {
       
   385     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfDestinationNameExistL" );
       
   386 
       
   387     CMDBRecordSet<CCDAccessPointRecord>*  ptrRecordSet = 
       
   388           new (ELeave) CMDBRecordSet<CCDAccessPointRecord>( KCDTIdAccessPointRecord );
       
   389     CleanupStack::PushL( ptrRecordSet );    
       
   390 
       
   391     // Prime record
       
   392     CCDAccessPointRecord* record = static_cast<CCDAccessPointRecord *>
       
   393                                    ( CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   394     CleanupStack::PushL( record );
       
   395 
       
   396     record->iRecordTag = ( TInt )aDestId;
       
   397 
       
   398     ptrRecordSet->iRecords.AppendL( record );
       
   399 
       
   400     CleanupStack::Pop( record );
       
   401     record = NULL;
       
   402 
       
   403     if ( ptrRecordSet->FindL( Session() ) )
       
   404         {
       
   405         User::Leave( KErrAlreadyExists );      
       
   406         }
       
   407 
       
   408     ptrRecordSet->iRecords.ResetAndDestroy();
       
   409     CleanupStack::PopAndDestroy( ptrRecordSet );
       
   410 
       
   411     iData->iDestAPRecord->iRecordTag = aDestId;
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CCmDestinationImpl::CheckIfDestinationNameExistL()
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CCmDestinationImpl::CheckIfDestinationNameExistL( const TDesC& aName )
       
   419     {
       
   420     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfDestinationNameExistL" );
       
   421     
       
   422     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
   423                             new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
   424                                  iCmMgr.DestinationTableId() );
       
   425     CleanupStack::PushL( ptrRecordSet );    
       
   426     
       
   427     // Prime record
       
   428     CCDSnapRecord* record = iCmMgr.SNAPRecordL( 0 );
       
   429     CleanupStack::PushL( record );
       
   430     
       
   431     record->iRecordName.SetL( aName );
       
   432     
       
   433     ptrRecordSet->iRecords.AppendL( record );
       
   434 
       
   435     CleanupStack::Pop( record );
       
   436     record = NULL;
       
   437                 
       
   438     if ( ptrRecordSet->FindL( Session() ) )
       
   439         {
       
   440         User::Leave( KErrAlreadyExists );          
       
   441         }
       
   442         
       
   443     ptrRecordSet->iRecords.ResetAndDestroy();
       
   444     CleanupStack::PopAndDestroy( ptrRecordSet );            
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CCmDestinationImpl::ConstructL()
       
   449 // -----------------------------------------------------------------------------
       
   450 //    
       
   451 void CCmDestinationImpl::ConstructL( TUint aDestinationId )
       
   452     {
       
   453     CLOG_CREATE;
       
   454     CLOG_NAME_2( _L("Destination_0x%x_%d"), this, aDestinationId );
       
   455     iData =  new (ELeave) CCmDestinationData(iCmMgr);
       
   456     OpenTransactionLC();
       
   457     
       
   458     iData->iNetworkRecord = static_cast<CCDNetworkRecord *>(
       
   459                          CCDRecordBase::RecordFactoryL( KCDTIdNetworkRecord ) );
       
   460 
       
   461     iData->iDestAPRecord = static_cast<CCDAccessPointRecord *>(
       
   462                          CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
   463     
       
   464     iData->iConnMethodArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   465     iData->iDeleteCmArray = new (ELeave) CCmArray( KCmArrayBigGranularity );
       
   466 
       
   467     TInt correctAPId = aDestinationId;
       
   468     TInt correctNetworkId = aDestinationId;
       
   469 	
       
   470     if ( aDestinationId > 0 && aDestinationId < 255 )
       
   471         {
       
   472         correctAPId = aDestinationId + KCmDefaultDestinationAPTagId;
       
   473         }
       
   474     else if ( aDestinationId > KCmDefaultDestinationAPTagId 
       
   475               && ( aDestinationId < ( KCmDefaultDestinationAPTagId+255 ) ) )
       
   476         {
       
   477         correctNetworkId = aDestinationId - KCmDefaultDestinationAPTagId;
       
   478         }
       
   479     else
       
   480         {
       
   481         User::Leave( KErrArgument );
       
   482         }
       
   483         
       
   484     LoadDestAPRecordL( correctAPId );
       
   485     
       
   486     LoadNetworkRecordL( correctNetworkId );
       
   487 
       
   488     LoadConnectionMethodsL();
       
   489     LoadSNAPMetadataTableL();
       
   490     
       
   491     RollbackTransaction();
       
   492     
       
   493     iData->iIdIsValid = ETrue;
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CCmDestinationImpl::Session()
       
   498 // -----------------------------------------------------------------------------
       
   499 //        
       
   500 CMDBSession& CCmDestinationImpl::Session()const
       
   501     {
       
   502     return iCmMgr.Session();
       
   503     }
       
   504     
       
   505 // ---------------------------------------------------------------------------
       
   506 // CCmDestinationImpl::OpenTransactionLC
       
   507 // ---------------------------------------------------------------------------
       
   508 //
       
   509 void CCmDestinationImpl::OpenTransactionLC()
       
   510     {
       
   511     LOGGER_ENTERFN( "CCmDestinationImpl::OpenTransactionL" );
       
   512     // Do NOT call OpenTransactionLC() more then once!
       
   513     iCmMgr.OpenTransactionLC( ETrue );
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // CCmDestinationImpl::CommitTransactionL
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CCmDestinationImpl::CommitTransactionL( TInt aError )
       
   521     {
       
   522     LOGGER_ENTERFN( "CCmDestinationImpl::CommitTransactionL" );
       
   523     
       
   524     iCmMgr.CommitTransactionL( aError );
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CCmDestinationImpl::RollbackTransaction
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 void CCmDestinationImpl::RollbackTransaction()
       
   532     {
       
   533     LOGGER_ENTERFN( "CCmDestinationImpl::RollbackTransaction" );
       
   534     
       
   535     iCmMgr.RollbackTransaction();
       
   536     }
       
   537 
       
   538     
       
   539 // -----------------------------------------------------------------------------
       
   540 // CCmDestinationImpl::NameLC()
       
   541 // -----------------------------------------------------------------------------
       
   542 //        
       
   543 EXPORT_C HBufC* CCmDestinationImpl::NameLC( )
       
   544     {
       
   545     LOGGER_ENTERFN( "CCmDestinationImpl::NameLC" );
       
   546 
       
   547     HBufC* name = NULL;
       
   548     const TUint32 KSnapMetadataNameMask = 0x0000000F;
       
   549 
       
   550     TUint32 val = TUint32(iData->iMetaDataRec->iMetadata) & KSnapMetadataNameMask;
       
   551     TUint32 val2 = (TUint32(iData->iMetaDataRec->iMetadata) & ESnapMetadataDestinationIsLocalised)
       
   552                      >> 4;                   
       
   553     
       
   554     if( (val == ESnapMetadataInternet) ||
       
   555         (val2 == ELocalisedDestInternet) )
       
   556         {
       
   557         name = iCmMgr.AllocReadL( R_CMMANAGERUI_DEST_INTERNET );
       
   558         }
       
   559     else if ( val2 == ELocalisedDestWap )
       
   560         {
       
   561         name = iCmMgr.AllocReadL( R_CMMANAGERUI_DEST_WAP );
       
   562         }
       
   563     else if ( val2 == ELocalisedDestMMS )
       
   564         {
       
   565         name = iCmMgr.AllocReadL( R_CMMANAGERUI_DEST_MMS );
       
   566         }
       
   567     else if ( val2 == ELocalisedDestIntranet )
       
   568         {
       
   569         name = iCmMgr.AllocReadL( R_CMMANAGERUI_DEST_INTRANET );
       
   570         }
       
   571     else
       
   572         {
       
   573         name = TPtrC(iData->iNetworkRecord->iRecordName).AllocL();
       
   574         }
       
   575         
       
   576     CleanupStack::PushL( name );
       
   577         
       
   578     return name;
       
   579     };
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // CCmDestinationImpl::SetNameL()
       
   583 // -----------------------------------------------------------------------------
       
   584 //        
       
   585 EXPORT_C void CCmDestinationImpl::SetNameL( const TDesC& aName )
       
   586     {
       
   587     LOGGER_ENTERFN( "CCmDestinationImpl::SetNameL" );
       
   588 
       
   589     // Destination cannot be renamed if it's
       
   590     // - protected
       
   591     // - Internet    
       
   592     if ( ProtectionLevel() == EProtLevel1 ||
       
   593          ProtectionLevel() == EProtLevel2 ||
       
   594          MetadataL( ESnapMetadataInternet ) )
       
   595         {
       
   596         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
   597         }
       
   598 
       
   599     OpenTransactionLC();
       
   600     CheckIfDestinationNameExistL( aName );
       
   601     CommitTransactionL( KErrNone );        
       
   602 
       
   603     iData->iNetworkRecord->iRecordName.SetL( aName );
       
   604     iData->iDestAPRecord->iRecordName.SetL( aName );
       
   605     };
       
   606     
       
   607 // -----------------------------------------------------------------------------
       
   608 // CCmDestinationImpl::ConnectionMethodCount()
       
   609 // -----------------------------------------------------------------------------
       
   610 //        
       
   611 TInt CCmDestinationData::ConnectionMethodCount()
       
   612     {    
       
   613     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodCount" );
       
   614 
       
   615     return iConnMethodArray->Count() - KCmInitIndex;
       
   616     };
       
   617     
       
   618 // -----------------------------------------------------------------------------
       
   619 // CCmDestinationImpl::ConnectionMethodCount()
       
   620 // -----------------------------------------------------------------------------
       
   621 //        
       
   622 EXPORT_C TInt CCmDestinationImpl::ConnectionMethodCount()
       
   623     {
       
   624     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodCount" );
       
   625     
       
   626     return iData->ConnectionMethodCount();
       
   627     };
       
   628     
       
   629 // -----------------------------------------------------------------------------
       
   630 // CCmDestinationImpl::ConnectionMethodL
       
   631 // -----------------------------------------------------------------------------
       
   632 //     
       
   633 EXPORT_C CCmPluginBaseEng* CCmDestinationImpl::ConnectionMethodL( TInt /*aIndex*/ )
       
   634     {
       
   635     LOGGER_ENTERFN( "Error: Obsolete function CCmDestinationImpl::ConnectionMethodL used" );
       
   636     User::Panic( _L("CMManager"), KErrNotSupported );
       
   637     return NULL;    
       
   638     }
       
   639     
       
   640 // -----------------------------------------------------------------------------
       
   641 // CCmDestinationImpl::ConnectionMethodL
       
   642 // -----------------------------------------------------------------------------
       
   643 //     
       
   644 EXPORT_C CCmPluginBase* CCmDestinationImpl::GetConnectionMethodL( TInt aIndex )
       
   645     {
       
   646     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodL" );
       
   647     // Initial entry!
       
   648    
       
   649     CCmPluginBase* retVal = NULL;    
       
   650     TInt index = KCmInitIndex + aIndex;
       
   651     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
   652 
       
   653     LoadPluginL( *item );
       
   654     retVal = item->iPlugin;
       
   655     
       
   656     return retVal;
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CCmDestinationImpl::ConnectionMethodByIDL
       
   661 // -----------------------------------------------------------------------------
       
   662 //     
       
   663 CCmPluginBase* CCmDestinationImpl::ConnectionMethodByIDL( TUint32 aCmId )
       
   664     {
       
   665     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodByIDL" );
       
   666 
       
   667     TInt found = ConnectionMethodIndex( aCmId );
       
   668 
       
   669     if( found == KErrNotFound )
       
   670         {
       
   671         User::Leave( KErrNotFound );
       
   672         }
       
   673         
       
   674     CPluginItem* item = (*(iData->iConnMethodArray))[found];
       
   675 
       
   676     LoadPluginL( *item );
       
   677     
       
   678     return item->iPlugin;
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CCmDestinationImpl::ConnectMethodIdArrayL
       
   683 // -----------------------------------------------------------------------------
       
   684 //     
       
   685 void CCmDestinationImpl::ConnectMethodIdArrayL( RArray<TUint32>& aCmIds )
       
   686     {
       
   687     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectMethodIdArrayL" );
       
   688 
       
   689     TInt count = iData->iConnMethodArray->Count();    
       
   690 
       
   691     for( TInt i = KCmInitIndex; i < count; ++i )
       
   692         {
       
   693         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
   694 
       
   695         TUint32 elementId = item->iDNRecord->iIAP ?
       
   696                           RECORD_FROM_ELEMENT_ID( TUint32(item->iDNRecord->iIAP) ) :
       
   697                           TUint32( item->iDNRecord->iEmbeddedSNAP );
       
   698                           
       
   699         User::LeaveIfError( aCmIds.Append( elementId ) );
       
   700         }
       
   701     }
       
   702 
       
   703 // -----------------------------------------------------------------------------
       
   704 // CCmDestinationImpl::AddToArrayL
       
   705 // -----------------------------------------------------------------------------
       
   706 // 
       
   707 TInt CCmDestinationImpl::AddToArrayL( CPluginItem* aItem )
       
   708     {
       
   709     LOGGER_ENTERFN( "CCmDestinationImpl::AddToArrayL" );
       
   710 
       
   711     TInt count = iData->iConnMethodArray->Count();    
       
   712     if ( 0 == count  )
       
   713         {
       
   714         iData->iConnMethodArray->AppendL( aItem );
       
   715         CLOG_WRITE_1( "inserted: [%d]", count );
       
   716         return count;
       
   717         }
       
   718         
       
   719     // Fill in SNAP record with IAP/EmbSNAP/SNAP values    
       
   720     TMDBElementId iapElemetid( 0 );
       
   721     TInt embDestId( 0 );
       
   722 
       
   723     // No plugin means this is the template record.
       
   724     TBool isDestination = aItem->iPlugin->GetBoolAttributeL( ECmDestination );
       
   725     if ( isDestination )
       
   726         {
       
   727         embDestId = aItem->iPlugin->Destination()->Id();    
       
   728         }
       
   729     else
       
   730         {
       
   731         iapElemetid = aItem->iPlugin->IAPRecordElementId();   
       
   732         }
       
   733         
       
   734     aItem->iDNRecord->iIAP = iapElemetid;
       
   735     aItem->iDNRecord->iEmbeddedSNAP = embDestId;
       
   736 
       
   737     TUint32 prio = 0;
       
   738     TUint32 bearerType = 0;
       
   739     TUint32 extLevel = 0;
       
   740     
       
   741     TBool isVirtual( EFalse );
       
   742     
       
   743     if ( count == KCmInitIndex )
       
   744         {
       
   745         if( !aItem->iDNRecord->iIAP && !aItem->iDNRecord->iEmbeddedSNAP )
       
   746             {
       
   747             iData->iConnMethodArray->AppendL( aItem );
       
   748             }
       
   749         else
       
   750             {
       
   751             isVirtual = PrioDataL( aItem, prio, bearerType, extLevel );
       
   752             aItem->iDNRecord->iPriority = prio;
       
   753             iData->iConnMethodArray->AppendL( aItem );
       
   754             }
       
   755         return count;
       
   756         }
       
   757     
       
   758     TInt insertedAt( -1 );
       
   759 
       
   760     if ( !isDestination )
       
   761         {
       
   762         // This function returns the info necessary for determining the priority
       
   763         // It is the cm data in none VPN case 
       
   764         // It is the data of the underlying cm in case of VPN over cm
       
   765         // It is wildcard prio in case of VPN over destination
       
   766         isVirtual = PrioDataL( aItem, prio, bearerType, extLevel );
       
   767 
       
   768         CLOG_WRITE_3( "inserted item prio: [%d], bearer: [%x] ext: [%d]", 
       
   769                        prio, bearerType, extLevel );
       
   770 
       
   771         // wildcard priority goes to back
       
   772         if ( KDataMobilitySelectionPolicyPriorityWildCard == prio ) 
       
   773             {
       
   774             // Set the default priority of a wildcard bearer
       
   775             aItem->iDNRecord->iPriority = prio;
       
   776             }   
       
   777         else 
       
   778             {
       
   779             insertedAt = InsertSameMethodL( bearerType, isVirtual );
       
   780             if( insertedAt == -1 )
       
   781                 {
       
   782                 insertedAt = InsertPriorityMethodL( prio, extLevel );
       
   783                 }
       
   784  
       
   785             } // if wildcard
       
   786         } // if !destination
       
   787    
       
   788     if( insertedAt == -1 )
       
   789         {
       
   790         //Add to the end of the list        
       
   791         iData->iConnMethodArray->AppendL( aItem );
       
   792         insertedAt = iData->iConnMethodArray->Count()-1;
       
   793         CLOG_WRITE_1( "inserted as last: [%d]", insertedAt );
       
   794         }
       
   795     else
       
   796         {
       
   797         iData->iConnMethodArray->InsertL( insertedAt, aItem );
       
   798         }    
       
   799 
       
   800     CLOG_WRITE_1( "inserted at: [%d]", insertedAt );
       
   801         
       
   802     return insertedAt;
       
   803     }
       
   804 
       
   805 // -----------------------------------------------------------------------------
       
   806 // CCmDestinationImpl::PrioDataL
       
   807 // -----------------------------------------------------------------------------
       
   808 // 
       
   809 TBool CCmDestinationImpl::PrioDataL( CPluginItem* aItem,  TUint32& aRetPrio, 
       
   810                                      TUint32& aRetBearer, TUint32& aRetExtLevel )
       
   811     {
       
   812     LOGGER_ENTERFN( "CCmDestinationImpl::PrioDataL" );
       
   813 
       
   814     // Gets the data affecting the priority of the plugin in the list.
       
   815     // It means the VPN priory based on the barer priority of the underlying cm
       
   816     // or "wildcard" if VPN points to a destination      
       
   817     aRetPrio   = aItem->iPlugin->GetIntAttributeL( ECmDefaultPriority );
       
   818     aRetBearer = aItem->iPlugin->GetIntAttributeL( ECmBearerType );
       
   819     aRetExtLevel = aItem->iPlugin->GetIntAttributeL( ECmExtensionLevel );
       
   820     
       
   821     TBool isVirtual = aItem->iPlugin->GetBoolAttributeL( ECmVirtual );
       
   822     if( isVirtual )
       
   823         {
       
   824         // Embeded destination is also virtual but further checking should
       
   825         // not be done. 
       
   826         TBool isDestination = aItem->iPlugin->GetBoolAttributeL( ECmDestination );
       
   827         if( !isDestination )
       
   828             {
       
   829             TUint32 underlying = aItem->iPlugin->GetIntAttributeL( 
       
   830                                                            ECmNextLayerIapId );
       
   831             if ( underlying != 0 )
       
   832                 {
       
   833                 // Gets the bearer of the underlying cm
       
   834                 aRetBearer = iCmMgr.BearerTypeFromCmIdL( underlying );
       
   835                 // Gets the prio of the bearer
       
   836                 aRetPrio = 
       
   837                 iCmMgr.GetBearerInfoIntL( aRetBearer, ECmDefaultPriority );
       
   838                 aRetExtLevel = 
       
   839                 iCmMgr.GetBearerInfoIntL( aRetBearer, ECmExtensionLevel );
       
   840                 }
       
   841             else
       
   842                 {
       
   843                 // VPN points to a destination so its priority is "wildcard"
       
   844                 aRetPrio = KDataMobilitySelectionPolicyPriorityWildCard;
       
   845                 }    
       
   846             }
       
   847         }
       
   848 
       
   849     return isVirtual;
       
   850     }
       
   851 
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 // CCmDestinationImpl::InsertSameMethodL
       
   855 // -----------------------------------------------------------------------------
       
   856 // 
       
   857 TInt CCmDestinationImpl::InsertSameMethodL( TUint32 aBearerType, TBool aIsVirtual )
       
   858     {
       
   859     LOGGER_ENTERFN( "CCmDestinationImpl::InsertSameMethodL" );
       
   860 
       
   861     TInt insertedAt( -1 );
       
   862     TUint32 bearerInList( 0 );
       
   863     TUint32 prioInList( 0 );
       
   864     TUint32 extLevelInList( 0 ); 
       
   865     TBool isVirtualInList( EFalse );
       
   866      
       
   867     TInt count = iData->iConnMethodArray->Count();    
       
   868     // Loops throught the items in the list
       
   869     for ( TInt i = count-1; ( i >= KCmInitIndex ) && ( insertedAt == -1) ; i-- )
       
   870         {
       
   871         // Loads the plugin
       
   872         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
   873         LoadPluginL( *item );
       
   874         
       
   875         // Gets the data of the list item    
       
   876         isVirtualInList = PrioDataL( item, 
       
   877                                     prioInList, bearerInList, extLevelInList );
       
   878 
       
   879         CLOG_WRITE_4( "actual item [%d] prio: [%d], bearer: [%x] ext: [%d]", 
       
   880                             i, prioInList, bearerInList, extLevelInList );
       
   881           
       
   882         // Bearer type the same
       
   883         if( aBearerType == bearerInList )
       
   884             {
       
   885             // puts Virt/Virt or !Virt/!Virt or !Virt/Virt
       
   886             if( ( aIsVirtual == isVirtualInList ) || ( aIsVirtual && !isVirtualInList ))
       
   887                 {
       
   888                 insertedAt = i+1;
       
   889                 CLOG_WRITE_1( "inserted same bearer: [%d]", insertedAt );
       
   890                 }
       
   891             } // if bearer
       
   892         } // for
       
   893         return insertedAt;
       
   894     }
       
   895     
       
   896     
       
   897 // -----------------------------------------------------------------------------
       
   898 // CCmDestinationImpl::InsertPriorityMethodL
       
   899 // -----------------------------------------------------------------------------
       
   900 // 
       
   901 TInt CCmDestinationImpl::InsertPriorityMethodL( TUint32 aPrio, TUint32 aExtLevel )
       
   902     {
       
   903     LOGGER_ENTERFN( "CCmDestinationImpl::InsertPriorityMethodL" );
       
   904 
       
   905     TInt insertedAt = -1;
       
   906     TUint32 bearerInList( 0 );
       
   907     TUint32 prioInList( 0 );
       
   908     TUint32 extLevelInList( 0 );
       
   909 
       
   910     TInt count = iData->iConnMethodArray->Count();    
       
   911     // Loops throught the items in the list
       
   912     ////for ( TInt i = KCmInitIndex; ( i < count ) && ( insertedAt == -1) ; i++ )
       
   913     TInt i ( count-1 );
       
   914     for ( ; ( i >= KCmInitIndex ) && ( insertedAt == -1) ; i-- )
       
   915         {
       
   916         // Loads the plugin
       
   917         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
   918         LoadPluginL( *item );
       
   919 
       
   920         // Gets the data of the list item    
       
   921         PrioDataL( item, prioInList, bearerInList, extLevelInList );
       
   922 
       
   923         CLOG_WRITE_4( "actual item [%d] prio: [%d], bearer: [%x] ext: [%d]", 
       
   924                         i, prioInList, bearerInList, extLevelInList );
       
   925         
       
   926         // If the priority is the same then it should be inserted near here
       
   927         if ( aPrio == prioInList )
       
   928             {
       
   929             if( aExtLevel <= extLevelInList )
       
   930                 {
       
   931                 insertedAt = i+1;
       
   932                 CLOG_WRITE_1( "inserted same bearer non virtual: [%d]", insertedAt );
       
   933                 }
       
   934             }
       
   935         // Insert in front of the higher priority (prio 1 is the highest ...)    
       
   936         else if ( aPrio > prioInList )
       
   937             {
       
   938             insertedAt = i+1;
       
   939             CLOG_WRITE_1( "inserted higher prio: [%d]", insertedAt );
       
   940             } // if same prio
       
   941             
       
   942         } // for
       
   943         
       
   944     // This is the highest priority one. It should be inserted at the first pos. 
       
   945     if( -1 == insertedAt )
       
   946         {
       
   947         insertedAt = KCmInitIndex;
       
   948         CLOG_WRITE_1( "inserted first position: [%d]", insertedAt );
       
   949         } // if same prio
       
   950 
       
   951     return insertedAt;
       
   952     }
       
   953     
       
   954 // -----------------------------------------------------------------------------
       
   955 // CCmDestinationData::ProtectionLevel()
       
   956 // -----------------------------------------------------------------------------
       
   957 //  
       
   958 TProtectionLevel CCmDestinationData::ProtectionLevel()
       
   959     {
       
   960     TInt protection = TUint32(iMetaDataRec->iMetadata) & 
       
   961                       KSnapMetadataProtecionLevelMask;
       
   962     return TProtectionLevel(protection >> 28);
       
   963     }
       
   964     
       
   965 // -----------------------------------------------------------------------------
       
   966 // CCmDestinationImpl::ProtectionLevel()
       
   967 // -----------------------------------------------------------------------------
       
   968 //  
       
   969 EXPORT_C 
       
   970     TProtectionLevel CCmDestinationImpl::ProtectionLevel()
       
   971     {
       
   972     return iData->ProtectionLevel();
       
   973     }
       
   974 
       
   975 // -----------------------------------------------------------------------------
       
   976 // CCmDestinationImpl::SetAttributeL()
       
   977 // -----------------------------------------------------------------------------
       
   978 //  
       
   979 EXPORT_C void CCmDestinationImpl::SetProtectionL( TProtectionLevel aProtectionLevel )
       
   980     {
       
   981     LOGGER_ENTERFN( "CCmDestinationImpl::SetProtectionL" );
       
   982     
       
   983     CLOG_WRITE_1( "Level: [%d]", aProtectionLevel );
       
   984 
       
   985     CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
   986     
       
   987     // Make a destination protected.
       
   988     TUint32 mask = ~KSnapMetadataProtecionLevelMask;
       
   989     TUint32 temp = TUint32(iData->iMetaDataRec->iMetadata) & mask;    
       
   990     iData->iMetaDataRec->iMetadata = aProtectionLevel << 28;
       
   991     iData->iMetaDataRec->iMetadata = temp | TUint32(iData->iMetaDataRec->iMetadata);
       
   992     
       
   993     iData->iProtectionChanged = ETrue;
       
   994     }
       
   995         
       
   996 // -----------------------------------------------------------------------------
       
   997 // CCmDestinationImpl::CreateConnectionMethodL()
       
   998 // -----------------------------------------------------------------------------
       
   999 //  
       
  1000 CCmPluginBase* CCmDestinationImpl::CreateConnectionMethodL( 
       
  1001                                                    TUint32 aImplementationUid )
       
  1002     {
       
  1003     LOGGER_ENTERFN( "CCmDestinationImpl::CreateConnectionMethodL" );
       
  1004 
       
  1005     CCmPluginBase* retval = NULL;
       
  1006     if( ProtectionLevel() == EProtLevel1 )
       
  1007         {
       
  1008         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1009         }
       
  1010     retval = iCmMgr.CreateConnectionMethodL(aImplementationUid, this);
       
  1011     CleanupStack::PushL(retval); 
       
  1012     AddConnectionMethodL(*retval);
       
  1013     CleanupStack::Pop(retval);
       
  1014     return retval;
       
  1015     }
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // CCmDestinationImpl::CreateConnectionMethodL()
       
  1019 // -----------------------------------------------------------------------------
       
  1020 //  
       
  1021 CCmPluginBase* CCmDestinationImpl::CreateConnectionMethodL( 
       
  1022     TUint32 aImplementationUid,
       
  1023     TUint32 aConnMthId )
       
  1024     {
       
  1025     LOGGER_ENTERFN( "CCmDestinationImpl::CreateConnectionMethodL" );
       
  1026 
       
  1027     CCmPluginBase* retval = NULL;
       
  1028     if( ProtectionLevel() == EProtLevel1 )
       
  1029         {
       
  1030         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1031         }
       
  1032 
       
  1033     retval = iCmMgr.CreateConnectionMethodL( aImplementationUid,
       
  1034                                              aConnMthId,
       
  1035                                              this );
       
  1036     CleanupStack::PushL(retval);
       
  1037     AddConnectionMethodL(*retval);
       
  1038     CleanupStack::Pop(retval);
       
  1039     return retval;
       
  1040     }
       
  1041 
       
  1042 
       
  1043 // -----------------------------------------------------------------------------
       
  1044 // CCmDestinationImpl::AddConnectionMethodL()
       
  1045 // -----------------------------------------------------------------------------
       
  1046 //
       
  1047 TInt CCmDestinationImpl::AddConnectionMethodL( 
       
  1048                                            CCmPluginBase& aConnectionMethod )
       
  1049     {    
       
  1050     LOGGER_ENTERFN( "CCmDestinationImpl::AddConnectionMethodL" );
       
  1051 
       
  1052     if( ProtectionLevel() == EProtLevel1 )
       
  1053         {
       
  1054         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1055         }
       
  1056         
       
  1057     TUint cmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1058     
       
  1059     CPluginItem* item = new (ELeave) CPluginItem;
       
  1060     CleanupStack::PushL( item ); // 1
       
  1061     
       
  1062     // get the plugin
       
  1063     CCmPluginBase* connMethod = new (ELeave) 
       
  1064                             CCmPluginBase(aConnectionMethod.Plugin());
       
  1065     CleanupStack::PushL( connMethod );// 2           
       
  1066     connMethod->IncrementRefCounter();    
       
  1067     item->iPlugin = connMethod;
       
  1068 
       
  1069     // create the new record
       
  1070     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
  1071 
       
  1072     CleanupStack::PushL( item->iDNRecord ); // 3
       
  1073     
       
  1074     // if the destination is protection level 1, the connection method must be protected
       
  1075     if ( ProtectionLevel() == EProtLevel1 )
       
  1076         {
       
  1077         item->iPlugin->SetBoolAttributeL( ECmProtected, ETrue );
       
  1078         }
       
  1079     
       
  1080     TInt index = AddToArrayL( item );
       
  1081     index = index - KCmInitIndex; //the array contains one initial item, so subtract KCmInitIndex from the index to get cm index!
       
  1082     
       
  1083     CleanupStack::Pop( 3, item ); // item, connMethod, iDNRecord
       
  1084     
       
  1085     return index;
       
  1086     }
       
  1087 
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // CCmDestinationImpl::AddEmbeddedDestinationL()
       
  1090 // -----------------------------------------------------------------------------
       
  1091 //
       
  1092 TInt CCmDestinationImpl::AddEmbeddedDestinationL( 
       
  1093                                              CCmDestinationImpl& aDestination )
       
  1094     {
       
  1095     LOGGER_ENTERFN( "CCmDestinationImpl::AddEmbeddedDestinationL" );
       
  1096     
       
  1097     if( ProtectionLevel() == EProtLevel1 )
       
  1098         {
       
  1099         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1100         }
       
  1101         
       
  1102     //Check to avoid multiple levels of embedding
       
  1103     CheckIfEmbeddedL( Id() );
       
  1104     
       
  1105     //Check to avoid multiple levels of embedding
       
  1106     if ( aDestination.HasEmbeddedL() )
       
  1107         {
       
  1108         User::Leave( KErrNotSupported );
       
  1109         }
       
  1110         
       
  1111     // Only one embedded destination per destination is allowed
       
  1112     if ( HasEmbeddedL() )
       
  1113         {
       
  1114         User::Leave( KErrNotSupported );
       
  1115         }
       
  1116            
       
  1117     CPluginItem* item = new (ELeave) CPluginItem;
       
  1118     CleanupStack::PushL( item ); // 1
       
  1119 
       
  1120     CreateEmbeddedDestinationPluginL( *item, aDestination.Id() );
       
  1121      // create the new record
       
  1122     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
  1123     item->iDNRecord->iPriority = KDataMobilitySelectionPolicyPriorityWildCard;
       
  1124 
       
  1125     CleanupStack::PushL( item->iDNRecord ); // 2    
       
  1126     TInt index = AddToArrayL( item );
       
  1127     index = index - KCmInitIndex; //the array contains one initial item, so subtract KCmInitIndex from the index to get cm index!
       
  1128     
       
  1129     CleanupStack::Pop( 2, item ); // item, iDNRecord
       
  1130     
       
  1131     return index;   
       
  1132     }
       
  1133 
       
  1134 // -----------------------------------------------------------------------------
       
  1135 // CCmDestinationImpl::DeleteConnectionMethodL()
       
  1136 // -----------------------------------------------------------------------------
       
  1137 // 
       
  1138 void CCmDestinationImpl::DeleteConnectionMethodL( 
       
  1139                                         CCmPluginBase& aConnectionMethod )
       
  1140     {
       
  1141     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1142     
       
  1143     if( ProtectionLevel() == EProtLevel1 ||
       
  1144         ProtectionLevel() == EProtLevel3 )
       
  1145         {
       
  1146         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1147         }
       
  1148         
       
  1149     if ( aConnectionMethod.GetBoolAttributeL( ECmConnected ) )
       
  1150         {
       
  1151         User::Leave( KErrInUse );
       
  1152         }
       
  1153         
       
  1154     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1155 
       
  1156     // move this method to the 'to be deleted' array         
       
  1157     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1158     
       
  1159     LoadPluginL( *item );
       
  1160     
       
  1161     if( item->iPlugin->GetBoolAttributeL( ECmIsLinked ) )
       
  1162         {
       
  1163         User::Leave( KErrLocked );
       
  1164         }
       
  1165 
       
  1166     if ( ConnectionMethodCount() == 1 )
       
  1167         {
       
  1168         // Check if this destination is referenced by Virtual CM 
       
  1169         CheckIfReferencedByVirtualCML();
       
  1170         }
       
  1171 
       
  1172     iData->iDeleteCmArray->AppendL( item );
       
  1173     iData->iConnMethodArray->Delete( index );
       
  1174     }
       
  1175     
       
  1176 // -----------------------------------------------------------------------------
       
  1177 // CCmDestinationImpl::RemoveConnectionMethodL()
       
  1178 // -----------------------------------------------------------------------------
       
  1179 // 
       
  1180 void CCmDestinationImpl::RemoveConnectionMethodL( 
       
  1181                                      const CCmPluginBase& aConnectionMethod )
       
  1182     {
       
  1183     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1184 
       
  1185     if( ProtectionLevel() == EProtLevel1 ||
       
  1186         ProtectionLevel() == EProtLevel3 )
       
  1187         {
       
  1188         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1189         }
       
  1190     
       
  1191     if ( ConnectionMethodCount() == 1 )
       
  1192         {
       
  1193         // Check if this destination is referenced by Virtual CM 
       
  1194         CheckIfReferencedByVirtualCML();
       
  1195         }
       
  1196         
       
  1197     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1198 
       
  1199     // move this method to the 'to be deleted' array, but
       
  1200     // set remove only from, not to delete it on update.
       
  1201     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1202     
       
  1203     item->iFlags |= CPluginItem::ERemoveCm;
       
  1204    
       
  1205     iData->iDeleteCmArray->AppendL( item );
       
  1206     iData->iConnMethodArray->Delete( index );
       
  1207     }
       
  1208 
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // CCmDestinationImpl::CheckIfReferencedByVirtualCML()
       
  1211 // -----------------------------------------------------------------------------
       
  1212 // 
       
  1213 void CCmDestinationImpl::CheckIfReferencedByVirtualCML()
       
  1214     {
       
  1215     // for each IAP in CM manager
       
  1216     //   1. check if it is virtual
       
  1217     //      if not => goto 1.
       
  1218     //      if yes:
       
  1219     //      2. check if it links to the destination of this CM
       
  1220     //         if yes => carryOn = EFalse, ERROR
       
  1221     //         if not: carryOn = ETrue
       
  1222     CommsDat::CMDBRecordSet<CommsDat::CCDIAPRecord>* iaps = iCmMgr.AllIapsL();
       
  1223     CleanupStack::PushL( iaps );
       
  1224 
       
  1225     TBool carryOn = ETrue;
       
  1226     TUint32 destId = Id();
       
  1227 
       
  1228     // for each IAP in CM manager
       
  1229     for ( TInt i = KCmInitIndex; carryOn && i < iaps->iRecords.Count(); ++i )
       
  1230         {
       
  1231         CommsDat::CCDIAPRecord* rec = (*iaps)[i];
       
  1232         TUint32 bearerType = 0;
       
  1233 
       
  1234         TRAP_IGNORE( bearerType = iCmMgr.BearerTypeFromIapRecordL( rec ) );
       
  1235         if ( !bearerType )
       
  1236             {
       
  1237             continue;
       
  1238             }
       
  1239 
       
  1240         // check if it is virtual
       
  1241         if ( iCmMgr.GetBearerInfoBoolL( bearerType, ECmVirtual ) )
       
  1242             {
       
  1243             // check if it links to the current destination
       
  1244             CCmPluginBase* plugin = NULL;            
       
  1245             TRAP_IGNORE( plugin = iCmMgr.GetConnectionMethodL( rec->RecordId() ) );
       
  1246 
       
  1247             if ( !plugin )
       
  1248                 {
       
  1249                 continue;
       
  1250                 }
       
  1251 
       
  1252             if ( plugin->IsLinkedToSnap( destId ) )
       
  1253                 {
       
  1254                 // the CM links to this destination, deletion not allowed
       
  1255                 carryOn = EFalse;
       
  1256                 }
       
  1257 
       
  1258             delete plugin;
       
  1259             }
       
  1260         }
       
  1261 
       
  1262     CleanupStack::PopAndDestroy( iaps );
       
  1263 
       
  1264     if ( !carryOn )
       
  1265         {
       
  1266         User::Leave( KErrLocked );
       
  1267         }
       
  1268     }
       
  1269 // -----------------------------------------------------------------------------
       
  1270 // CCmDestinationImpl::RemoveConnectionMethodL()
       
  1271 // -----------------------------------------------------------------------------
       
  1272 // 
       
  1273 void CCmDestinationImpl::RemoveConnectionMethodL( 
       
  1274                                      const CCmPluginBaseEng& aConnectionMethod )
       
  1275     {
       
  1276     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1277 
       
  1278     if( ProtectionLevel() == EProtLevel1 ||
       
  1279         ProtectionLevel() == EProtLevel3 )
       
  1280         {
       
  1281         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1282         }
       
  1283         
       
  1284     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1285 
       
  1286     // move this method to the 'to be deleted' array, but
       
  1287     // set remove only from, not to delete it on update.
       
  1288     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1289     
       
  1290     item->iFlags |= CPluginItem::ERemoveCm;
       
  1291    
       
  1292     iData->iDeleteCmArray->AppendL( item );
       
  1293     iData->iConnMethodArray->Delete( index );
       
  1294     }
       
  1295 
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // CCmDestinationImpl::ConnectionMethodDeletedL()
       
  1298 // -----------------------------------------------------------------------------
       
  1299 // 
       
  1300 void CCmDestinationImpl::ConnectionMethodDeletedL( 
       
  1301                                     const CCmPluginBase& aConnectionMethod )
       
  1302     {
       
  1303     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodDeletedL" );
       
  1304 
       
  1305     TInt found( KErrNotFound );
       
  1306     TUint32 aCmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1307 
       
  1308     found = ConnectionMethodIndex( aCmId );
       
  1309 
       
  1310     if( found != KErrNotFound )
       
  1311         {
       
  1312         CPluginItem* item = (*(iData->iConnMethodArray))[found];
       
  1313         
       
  1314         (*(iData->iConnMethodArray))[found] = NULL;
       
  1315         iData->iConnMethodArray->Delete( found );
       
  1316         iData->iConnMethodArray->Compress();
       
  1317         
       
  1318         // The iPlugin is deleted in plugin interface function
       
  1319         // that called this function.
       
  1320         delete item->iDNRecord;
       
  1321         delete item;
       
  1322         }
       
  1323     }
       
  1324 
       
  1325 // -----------------------------------------------------------------------------
       
  1326 // CCmDestinationImpl::FindConnectionMethodL()
       
  1327 // -----------------------------------------------------------------------------
       
  1328 // 
       
  1329 TInt CCmDestinationImpl::FindConnectionMethodL( 
       
  1330                                      const CCmPluginBase& aConnectionMethod )
       
  1331     {
       
  1332     LOGGER_ENTERFN( "CCmDestinationImpl::FindConnectionMethodL" );
       
  1333 
       
  1334     TInt cmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1335     TBool embeded = aConnectionMethod.GetBoolAttributeL( ECmDestination ) ?
       
  1336                       ETrue :
       
  1337                       EFalse;
       
  1338 
       
  1339     CLOG_WRITE_2( "ID: [%d], embDest: [%d]", 
       
  1340                   cmId, 
       
  1341                   aConnectionMethod.GetBoolAttributeL( ECmDestination ) );
       
  1342     
       
  1343     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1344         {
       
  1345         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1346         if( embeded )
       
  1347             {
       
  1348             if( item->iDNRecord->iEmbeddedSNAP == cmId )
       
  1349                 {
       
  1350                 return i;
       
  1351                 }        
       
  1352             }
       
  1353         else
       
  1354             {
       
  1355             if( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == cmId )
       
  1356                 {
       
  1357                 return i;
       
  1358                 }
       
  1359             }
       
  1360         }
       
  1361         
       
  1362     CLOG_WRITE( "Not found" );
       
  1363     User::Leave( KErrNotFound );
       
  1364     
       
  1365     // dummy return value. never used.
       
  1366     return -1;
       
  1367     }
       
  1368 
       
  1369 // -----------------------------------------------------------------------------
       
  1370 // CCmDestinationImpl::FindConnectionMethodL()
       
  1371 // -----------------------------------------------------------------------------
       
  1372 // 
       
  1373 TInt CCmDestinationImpl::FindConnectionMethodL( 
       
  1374                                      const CCmPluginBaseEng& aConnectionMethod )
       
  1375     {
       
  1376     LOGGER_ENTERFN( "CCmDestinationImpl::FindConnectionMethodL" );
       
  1377 
       
  1378     TInt cmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1379     TBool embeded = aConnectionMethod.GetBoolAttributeL( ECmDestination ) ?
       
  1380                       ETrue :
       
  1381                       EFalse;
       
  1382 
       
  1383     CLOG_WRITE_2( "ID: [%d], embDest: [%d]", 
       
  1384                   cmId, 
       
  1385                   aConnectionMethod.GetBoolAttributeL( ECmDestination ) );
       
  1386     
       
  1387     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1388         {
       
  1389         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1390         if( embeded )
       
  1391             {
       
  1392             if( item->iDNRecord->iEmbeddedSNAP == cmId )
       
  1393                 {
       
  1394                 return i;
       
  1395                 }        
       
  1396             }
       
  1397         else
       
  1398             {
       
  1399             if( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == cmId )
       
  1400                 {
       
  1401                 return i;
       
  1402                 }
       
  1403             }
       
  1404         }
       
  1405         
       
  1406     CLOG_WRITE( "Not found" );
       
  1407     User::Leave( KErrNotFound );
       
  1408     
       
  1409     // dummy return value. never used.
       
  1410     return -1;
       
  1411     }
       
  1412 
       
  1413 // -----------------------------------------------------------------------------
       
  1414 // CCmDestinationImpl::ModifyPriorityL()
       
  1415 // -----------------------------------------------------------------------------
       
  1416 //      
       
  1417 void CCmDestinationImpl::ModifyPriorityL( CCmPluginBase& aCCMItem, 
       
  1418                                           TUint aIndex )
       
  1419     {
       
  1420     LOGGER_ENTERFN( "CCmDestinationImpl::ModifyPriorityL" );
       
  1421     
       
  1422     if (aCCMItem.GetBoolAttributeL(ECmDestination) ||
       
  1423         (aCCMItem.GetBoolAttributeL(ECmVirtual) &&
       
  1424          aCCMItem.GetIntAttributeL(ECmNextLayerSNAPId)))
       
  1425         {
       
  1426         // Priority can not be changed for this cm
       
  1427         return;
       
  1428         }
       
  1429         
       
  1430     if( ProtectionLevel() == EProtLevel1 ||
       
  1431         ProtectionLevel() == EProtLevel3 )
       
  1432         {
       
  1433         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1434         }
       
  1435         
       
  1436     TBool found( EFalse );
       
  1437     TInt cm2 = aCCMItem.GetIntAttributeL( ECmId );
       
  1438     
       
  1439     if ( aIndex >= ( iData->iConnMethodArray->Count() - KCmInitIndex ) )
       
  1440         {
       
  1441         User::Leave( KErrArgument );
       
  1442         }
       
  1443     
       
  1444     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1445         {
       
  1446         LoadPluginL( *(*(iData->iConnMethodArray))[i] );
       
  1447             
       
  1448         // Compare the IAP IDs
       
  1449         TInt cm1 = (*(iData->iConnMethodArray))[i]->iPlugin->GetIntAttributeL( ECmId );        
       
  1450         
       
  1451         if ( cm1 == cm2 )
       
  1452             {
       
  1453             CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1454             
       
  1455             TInt pri = (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority;
       
  1456             if ( pri == KDataMobilitySelectionPolicyPriorityWildCard )
       
  1457                 {
       
  1458                 TUint32 prio = 0;
       
  1459                 TUint32 bearerType = 0;
       
  1460                 TUint32 extLevel = 0;
       
  1461                 
       
  1462                 TBool isVirtual = PrioDataL( item, prio, bearerType, extLevel );
       
  1463                 if (prio != KDataMobilitySelectionPolicyPriorityWildCard)
       
  1464                     {
       
  1465                     // The priority will be changed later when UpdateL is called
       
  1466                     // So, the priority will simply be chnaged from
       
  1467                     // KDataMobilitySelectionPolicyPriorityWildCard to value i
       
  1468                     (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority = i; 
       
  1469                     }
       
  1470                 }
       
  1471             
       
  1472             (*(iData->iConnMethodArray))[i] = NULL;
       
  1473             
       
  1474             // remove from array
       
  1475             iData->iConnMethodArray->Delete( i );
       
  1476             iData->iConnMethodArray->Compress();
       
  1477             iData->iConnMethodArray->InsertL( KCmInitIndex + aIndex, item );
       
  1478             
       
  1479             found = ETrue;           
       
  1480             break;
       
  1481             }
       
  1482         }
       
  1483         
       
  1484     if ( !found )
       
  1485         {
       
  1486         User::Leave( KErrArgument );
       
  1487         }
       
  1488         
       
  1489     }
       
  1490     
       
  1491 // -----------------------------------------------------------------------------
       
  1492 // CCmDestinationImpl::PriorityL()
       
  1493 // -----------------------------------------------------------------------------
       
  1494 //          
       
  1495 TUint CCmDestinationImpl::PriorityL( CCmPluginBaseEng& aCCMItem )
       
  1496     {
       
  1497     LOGGER_ENTERFN( "CCmDestinationImpl::PriorityL" );
       
  1498 
       
  1499     TInt index = FindConnectionMethodL( aCCMItem );
       
  1500     
       
  1501     return (*(iData->iConnMethodArray))[index]->iDNRecord->iPriority;
       
  1502     }
       
  1503     
       
  1504 // -----------------------------------------------------------------------------
       
  1505 // CCmDestinationImpl::PriorityL()
       
  1506 // -----------------------------------------------------------------------------
       
  1507 //          
       
  1508 TUint CCmDestinationImpl::PriorityL( CCmPluginBase& aCCMItem )
       
  1509     {
       
  1510     LOGGER_ENTERFN( "CCmDestinationImpl::PriorityL" );
       
  1511 
       
  1512     TInt index = FindConnectionMethodL( aCCMItem );
       
  1513     
       
  1514     return (*(iData->iConnMethodArray))[index]->iDNRecord->iPriority;
       
  1515     }
       
  1516     
       
  1517 // -----------------------------------------------------------------------------
       
  1518 // CCmDestinationImpl::UpdateL()
       
  1519 // -----------------------------------------------------------------------------
       
  1520 //          
       
  1521 EXPORT_C void CCmDestinationImpl::UpdateL()
       
  1522     {
       
  1523     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateL" );
       
  1524 
       
  1525     // Connection methods and destination records are updated in 
       
  1526     // one transaction.
       
  1527     OpenTransactionLC();
       
  1528     
       
  1529     DeleteConnectionMethodsL();
       
  1530 
       
  1531     // Update protection level of connection methods if it's changed in 
       
  1532     // the destination
       
  1533     UpdateProtectionL();
       
  1534     // Updates all modified connection methods.
       
  1535     UpdateConnectionMethodsL();
       
  1536     UpdateNetworkRecordL();
       
  1537     UpdateDestAPRecordL();
       
  1538     UpdateSNAPTableL();
       
  1539     UpdateSNAPMetadataTableL();
       
  1540         
       
  1541     CommitTransactionL( KErrNone );
       
  1542     
       
  1543     // set the last updated protection level of the destination
       
  1544     iData->iLastProtectionLevel = ProtectionLevel();
       
  1545 
       
  1546     // Clear the modified flag
       
  1547     iData->iProtectionChanged = EFalse;
       
  1548 
       
  1549     // empty the array, but do not delete it
       
  1550     iData->ResetAndDestroyArray( iData->iDeleteCmArray, EFalse );
       
  1551         
       
  1552     iCmMgr.DestinationUpdated(this);
       
  1553     iData->iIdIsValid = ETrue;
       
  1554     }
       
  1555 
       
  1556 // -----------------------------------------------------------------------------
       
  1557 // CCmDestinationImpl::DeleteLD()
       
  1558 // -----------------------------------------------------------------------------
       
  1559 //
       
  1560 EXPORT_C void CCmDestinationImpl::DeleteLD()
       
  1561     {
       
  1562     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteLD" );
       
  1563 
       
  1564     if( ProtectionLevel() == EProtLevel1 )
       
  1565         {
       
  1566         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1567         }
       
  1568         
       
  1569     TInt count = iData->iConnMethodArray->Count();
       
  1570 
       
  1571     if( IsConnectedL() )
       
  1572         {
       
  1573         User::Leave( KErrInUse );
       
  1574         }
       
  1575 
       
  1576     // Check first that any of the CMs in this Destination is not
       
  1577     // referenced by Virtual CM
       
  1578     TInt i( 0 );
       
  1579     
       
  1580     for( i = KCmInitIndex; i < count; ++i )
       
  1581         {
       
  1582         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1583         
       
  1584         LoadPluginL( *item );
       
  1585             
       
  1586         if( item->iPlugin->GetBoolAttributeL( ECmIsLinked ) )
       
  1587             {
       
  1588             User::Leave( KErrLocked );
       
  1589             }
       
  1590         }
       
  1591     // Check that this Destination is not referenced by any Virtual CM
       
  1592     if ( ConnectionMethodCount() > 0 )
       
  1593         {
       
  1594         CheckIfReferencedByVirtualCML();
       
  1595         }
       
  1596 
       
  1597     OpenTransactionLC();
       
  1598     TRAPD( err, DeleteRelatedRecordsL( count ) );
       
  1599     if ( err )
       
  1600         {
       
  1601         RollbackTransaction();
       
  1602         User::Leave( err );
       
  1603         }
       
  1604     CommitTransactionL(KErrNone);
       
  1605 
       
  1606     delete this;
       
  1607     }
       
  1608 
       
  1609 // -----------------------------------------------------------------------------
       
  1610 // CCmDestinationImpl::DeleteRelatedRecordsL()
       
  1611 // -----------------------------------------------------------------------------
       
  1612 //
       
  1613 void CCmDestinationImpl::DeleteRelatedRecordsL( TInt aCount )
       
  1614     {
       
  1615     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteRelatedRecordsL" );
       
  1616 
       
  1617     CleanUpEmbeddedL( Id() );
       
  1618 
       
  1619     TCmDefConnValue deletedItem;
       
  1620     deletedItem.iType = ECmDefConnDestination;
       
  1621     deletedItem.iId = Id();
       
  1622     iCmMgr.HandleDefConnDeletedL( deletedItem );       
       
  1623     CMDBRecordBase* dnIapRecord;
       
  1624     TInt i;
       
  1625     
       
  1626     // Here we don't use KCmInitIndex becouse initial entry should be deleted
       
  1627     // too!
       
  1628     for ( i = 0; i < aCount; i++ )
       
  1629         {
       
  1630         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1631         
       
  1632         // Delete the plugin
       
  1633         if ( i >= KCmInitIndex )
       
  1634             {
       
  1635             if ( !item->iPlugin->Plugin()->IdIsValid() )
       
  1636                 {
       
  1637                 // Delete incomplete plugin 
       
  1638                 delete item->iPlugin;
       
  1639                 item->iPlugin = NULL;
       
  1640                 }
       
  1641             else
       
  1642                 {
       
  1643                 TRAPD( err, item->iPlugin->DeleteL( EFalse ) );
       
  1644                 
       
  1645                 if( err != KErrLocked &&
       
  1646                     err != KErrNotReady )
       
  1647                     {
       
  1648                     User::LeaveIfError( err );
       
  1649                     }
       
  1650                     
       
  1651                 delete item->iPlugin;
       
  1652                 item->iPlugin = NULL;
       
  1653                 }
       
  1654             }  
       
  1655         
       
  1656         // Delete the DN-IAP record
       
  1657         dnIapRecord = item->iDNRecord;
       
  1658         
       
  1659         if ( dnIapRecord->RecordId() )
       
  1660             // If we have record Id, this record is already in CommsDat
       
  1661             {
       
  1662             dnIapRecord->DeleteL( Session() );
       
  1663             }   
       
  1664         delete item->iDNRecord;
       
  1665         item->iDNRecord = NULL;
       
  1666         }
       
  1667 
       
  1668     iData->iDestAPRecord->DeleteL( Session() ); // deletes a record
       
  1669     iData->iNetworkRecord->DeleteL( Session() ); // deletes a record
       
  1670     
       
  1671     // Delete SNAPMetadata table    
       
  1672     CMDBRecordSet<CCDSNAPMetadataRecord>*  ptrRecordSet = 
       
  1673                     new (ELeave) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  1674                                                  iCmMgr.IconTableId() );
       
  1675     CleanupStack::PushL( ptrRecordSet );
       
  1676 
       
  1677     // Prime record
       
  1678     CCDSNAPMetadataRecord* record = 
       
  1679         new (ELeave) CCDSNAPMetadataRecord( iCmMgr.IconTableId() );
       
  1680     CleanupStack::PushL( record );
       
  1681     record->iSNAP = Id();
       
  1682     ptrRecordSet->iRecords.AppendL( record );
       
  1683 
       
  1684     CleanupStack::Pop( record );
       
  1685     record = NULL;
       
  1686                 
       
  1687     if ( ptrRecordSet->FindL( Session() ) )
       
  1688         {
       
  1689         (*ptrRecordSet)[0]->DeleteL( Session() );          
       
  1690         }
       
  1691         
       
  1692     ptrRecordSet->iRecords.ResetAndDestroy();
       
  1693     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  1694     }
       
  1695 
       
  1696 // -----------------------------------------------------------------------------
       
  1697 // CCmDestinationImpl::CheckIfEmbeddedL()
       
  1698 // -----------------------------------------------------------------------------
       
  1699 //
       
  1700 void CCmDestinationImpl::CheckIfEmbeddedL( TInt aId )
       
  1701     {
       
  1702     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfEmbeddedL" );
       
  1703     
       
  1704     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  1705                     new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  1706                                           iCmMgr.DestinationTableId() );
       
  1707     CleanupStack::PushL( ptrRecordSet );
       
  1708 
       
  1709     // Prime record
       
  1710     CCDSnapRecord* record = iCmMgr.SNAPRecordL( 0 );
       
  1711     CleanupStack::PushL( record );
       
  1712     record->iEmbeddedSNAP = aId;
       
  1713     ptrRecordSet->iRecords.AppendL( record );
       
  1714 
       
  1715     CleanupStack::Pop( record );
       
  1716     record = NULL;
       
  1717         
       
  1718     OpenTransactionLC();    
       
  1719     if( ptrRecordSet->FindL( Session() ) )
       
  1720         // Match found - it's embedded
       
  1721         {
       
  1722         User::Leave( KErrNotSupported );          
       
  1723         }
       
  1724     RollbackTransaction();
       
  1725 
       
  1726     ptrRecordSet->iRecords.ResetAndDestroy();
       
  1727     
       
  1728     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  1729     }
       
  1730 
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // CCmDestinationImpl::HasEmbeddedL
       
  1733 // -----------------------------------------------------------------------------
       
  1734 //
       
  1735 TBool CCmDestinationImpl::HasEmbeddedL()
       
  1736     {
       
  1737     LOGGER_ENTERFN( "CCmDestinationImpl::HasEmbeddedL" );
       
  1738 
       
  1739     return ( EmbeddedL() != NULL )? ETrue : EFalse;
       
  1740     }
       
  1741 
       
  1742 // -----------------------------------------------------------------------------
       
  1743 // CCmDestinationImpl::EmbeddedL
       
  1744 // -----------------------------------------------------------------------------
       
  1745 //
       
  1746 CCmDestinationImpl* CCmDestinationImpl::EmbeddedL()
       
  1747     {
       
  1748     LOGGER_ENTERFN( "CCmDestinationImpl::EmbeddedL" );
       
  1749 
       
  1750     CCmDestinationImpl* retVal = NULL;
       
  1751     // Check if the destination contains embedded destinations
       
  1752     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1753         {
       
  1754         LoadPluginL( *(*(iData->iConnMethodArray))[i] );
       
  1755         // It's an embedded destination ( this is also true for VPN CMs )
       
  1756         retVal = (*(iData->iConnMethodArray))[i]->iPlugin->Destination();
       
  1757         if ( retVal )
       
  1758             {
       
  1759             // as there can be only one
       
  1760             // embedded destination, the first one is enough
       
  1761             break;
       
  1762             }
       
  1763         }
       
  1764     
       
  1765     return retVal;
       
  1766     }
       
  1767  
       
  1768  // -----------------------------------------------------------------------------
       
  1769 // CCmDestinationImpl::CanUseToConnectL
       
  1770 // -----------------------------------------------------------------------------
       
  1771 //
       
  1772 TBool CCmDestinationImpl::CanUseToConnectL()
       
  1773     {
       
  1774     LOGGER_ENTERFN( "CCmDestinationImpl::CanUseToConnectL" );
       
  1775 
       
  1776     const TInt KZeroItem = 0;
       
  1777     const TInt KOneItem = 1;
       
  1778     TInt cmCount = ConnectionMethodCount(); //without KCmInitIndex !!!
       
  1779     switch ( cmCount )
       
  1780         {
       
  1781         case KZeroItem:// no items at all
       
  1782             {
       
  1783             return EFalse;
       
  1784             }
       
  1785         case KOneItem:// One item, a possible empty embedded destination!
       
  1786             {
       
  1787             CCmDestinationImpl* embeddedDest = EmbeddedL();
       
  1788             if ( embeddedDest )
       
  1789                 {
       
  1790                 // If embeddedDest->ConnectionMethodCount() is not zero,
       
  1791                 // we have something in the embedded destination
       
  1792                 // which cannot be another embedded destination, 
       
  1793                 // since multiple embedding is not allowed.
       
  1794                 return embeddedDest->ConnectionMethodCount();
       
  1795                 }
       
  1796              else
       
  1797                 {
       
  1798                 return ETrue; //not an embedded destination
       
  1799                 }
       
  1800             }
       
  1801         default: // more than one item, only one can be an empty embedded
       
  1802                  // destination, so we surely contain a valid cm
       
  1803             {
       
  1804             return ETrue;
       
  1805             }
       
  1806             
       
  1807         }
       
  1808     }
       
  1809     
       
  1810 // -----------------------------------------------------------------------------
       
  1811 // CCmDestinationImpl::UpdateNetworkRecordL()
       
  1812 // -----------------------------------------------------------------------------
       
  1813 //
       
  1814 void CCmDestinationImpl::UpdateNetworkRecordL()
       
  1815     {
       
  1816     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateNetworkRecordL" );
       
  1817 
       
  1818     if ( !iData->iNetworkRecord->RecordId() || iData->iNewWithId )
       
  1819         {
       
  1820         CLOG_WRITE( "New Destination, create it!" );
       
  1821         //Create a network record, set the host name and add it to the database    
       
  1822 
       
  1823         if ( !iData->iNewWithId )
       
  1824         	{
       
  1825         	iData->iNetworkRecord->SetRecordId(KCDNewRecordRequest);
       
  1826         	}
       
  1827 
       
  1828         SetAttribute( iData->iNetworkRecord, 
       
  1829                       ECDProtectedWrite, 
       
  1830                       ProtectionLevel() == EProtLevel1 );
       
  1831 
       
  1832         iData->iNetworkRecord->StoreL( Session() ); //adds a new record
       
  1833         iData->iNewWithId = EFalse;
       
  1834         }
       
  1835     else
       
  1836         {
       
  1837         SetAttribute( iData->iNetworkRecord, 
       
  1838                       ECDProtectedWrite, 
       
  1839                       ProtectionLevel() == EProtLevel1 );
       
  1840 
       
  1841         iData->iNetworkRecord->ModifyL( Session() );
       
  1842         }
       
  1843     }
       
  1844 
       
  1845 // -----------------------------------------------------------------------------
       
  1846 // CCmDestinationImpl::UpdateDestAPRecordL()
       
  1847 // -----------------------------------------------------------------------------
       
  1848 //
       
  1849 void CCmDestinationImpl::UpdateDestAPRecordL()
       
  1850     {
       
  1851     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateDestAPRecordL" );
       
  1852 
       
  1853     if ( !iData->iDestAPRecord->RecordId() )
       
  1854         {
       
  1855         CLOG_WRITE( "New Destination, create AP for it!" );
       
  1856         //Create an AP record, set the selection policy(network id)
       
  1857         //and add it to the database
       
  1858         iData->iDestAPRecord->SetRecordId(KCDNewRecordRequest);
       
  1859         iData->iDestAPRecord->iRecordTag = CreateDestinationAPTagIdL();
       
  1860         iData->iDestAPRecord->iCustomSelectionPolicy = iData->iNetworkRecord->RecordId();
       
  1861         iData->iDestAPRecord->iRecordName.SetL(iData->iNetworkRecord->iRecordName);
       
  1862         iData->iDestAPRecord->StoreL( Session() ); //adds a new record
       
  1863         }
       
  1864     else
       
  1865         {
       
  1866         iData->iDestAPRecord->iCustomSelectionPolicy = iData->iNetworkRecord->RecordId();
       
  1867         iData->iDestAPRecord->iRecordName.SetL(iData->iNetworkRecord->iRecordName);
       
  1868         iData->iDestAPRecord->ModifyL( Session() ); //modifies the existing
       
  1869         }
       
  1870     }
       
  1871 
       
  1872 // -----------------------------------------------------------------------------
       
  1873 // CCmDestinationImpl::CreateDestinationAPTagId()
       
  1874 // -----------------------------------------------------------------------------
       
  1875 //
       
  1876 TUint32 CCmDestinationImpl::CreateDestinationAPTagIdL()
       
  1877     {
       
  1878     LOGGER_ENTERFN( "CCmDestinationImpl::CreateDestinationAPTagId" );
       
  1879 
       
  1880     return KCmDefaultDestinationAPTagId + iData->iNetworkRecord->RecordId();
       
  1881     }
       
  1882 
       
  1883 // -----------------------------------------------------------------------------
       
  1884 // CCmDestinationImpl::GetDestinationAPTagId()
       
  1885 // -----------------------------------------------------------------------------
       
  1886 //
       
  1887 TUint32 CCmDestinationImpl::GetDestinationAPTagId( )
       
  1888     {
       
  1889     return iData->iNetworkRecord->RecordId() + KCmDefaultDestinationAPTagId;
       
  1890     }
       
  1891 
       
  1892 
       
  1893 // -----------------------------------------------------------------------------
       
  1894 // CCmDestinationImpl::UpdateProtectionL()
       
  1895 // -----------------------------------------------------------------------------
       
  1896 //
       
  1897 void CCmDestinationImpl::UpdateProtectionL()
       
  1898     {
       
  1899     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateProtectionL" );
       
  1900 
       
  1901     if( !iData->iProtectionChanged )
       
  1902         // protection level not changed -> nothing to update here
       
  1903         {
       
  1904         return;
       
  1905         }
       
  1906         
       
  1907     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1908         {
       
  1909         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1910         
       
  1911         LoadPluginL( *item );
       
  1912         
       
  1913         switch ( ProtectionLevel() ) 
       
  1914             {
       
  1915             case EProtLevel0:
       
  1916             case EProtLevel2:
       
  1917                 {
       
  1918                 // from the protection level 0 to 2 and vice versa 
       
  1919                 // the ECmProtected value of the CM is not changed                
       
  1920                 if( iData->iLastProtectionLevel == EProtLevel1 ||
       
  1921                     iData->iLastProtectionLevel == EProtLevel3 )
       
  1922                     {
       
  1923                     item->iPlugin->SetBoolAttributeL( ECmProtected, EFalse );
       
  1924                     }
       
  1925                 }
       
  1926               break;
       
  1927             case EProtLevel1:
       
  1928             case EProtLevel3:
       
  1929                 {
       
  1930                 item->iPlugin->SetBoolAttributeL( ECmProtected, ETrue );
       
  1931                 }
       
  1932               break;
       
  1933             default:
       
  1934                 {
       
  1935                 //
       
  1936                 }
       
  1937               break;              
       
  1938              }                      
       
  1939         }
       
  1940     }
       
  1941 
       
  1942 // -----------------------------------------------------------------------------
       
  1943 // CCmDestinationImpl::UpdateConnectionMethodsL()
       
  1944 // -----------------------------------------------------------------------------
       
  1945 //
       
  1946 void CCmDestinationImpl::UpdateConnectionMethodsL()
       
  1947     {
       
  1948     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateConnectionMethodsL" );
       
  1949 
       
  1950     for( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1951         {
       
  1952         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1953         
       
  1954         // If the plugin is not loaded, it means that this a old one, or nothing
       
  1955         // modified in it -> there's no need to update it.
       
  1956         if( item->iPlugin )
       
  1957             {
       
  1958             item->iPlugin->UpdateL();
       
  1959             }
       
  1960         }
       
  1961     }
       
  1962 
       
  1963 // -----------------------------------------------------------------------------
       
  1964 // CCmDestinationImpl::SetAttribute()
       
  1965 // -----------------------------------------------------------------------------
       
  1966 //
       
  1967 void CCmDestinationImpl::SetAttribute( CMDBRecordBase* aRecord, 
       
  1968                                        TUint32 aAttribute, TBool aSet )
       
  1969     {
       
  1970     LOGGER_ENTERFN( "CCmDestinationImpl::SetAttribute" );
       
  1971     
       
  1972     if ( aSet && !aRecord->IsSetAttribute( aAttribute ) )
       
  1973         {
       
  1974         aRecord->SetAttributes( aAttribute );
       
  1975         }
       
  1976     else if( !aSet && aRecord->IsSetAttribute( aAttribute ) )
       
  1977         {
       
  1978         aRecord->ClearAttributes( aAttribute );
       
  1979         }
       
  1980     }
       
  1981 
       
  1982 // -----------------------------------------------------------------------------
       
  1983 // CCmDestinationImpl::UpdateSNAPTableL()
       
  1984 // -----------------------------------------------------------------------------
       
  1985 //
       
  1986 void CCmDestinationImpl::UpdateSNAPTableL()
       
  1987     {
       
  1988     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateSNAPTableL" );
       
  1989     
       
  1990     TInt i;
       
  1991     CCDSnapRecord* dnIapRecord;
       
  1992 
       
  1993     // Now we have only records of which are new or needs to be updated
       
  1994     for ( i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1995         {
       
  1996         TInt pri = (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority;
       
  1997 
       
  1998         if ( pri != i &&
       
  1999              pri != KDataMobilitySelectionPolicyPriorityWildCard )
       
  2000             // wildcard priority CM have to be the last one in the array.
       
  2001             // In theory they cannot be re-prioritized.
       
  2002             {
       
  2003             (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority = i;
       
  2004             }
       
  2005         }
       
  2006 
       
  2007     // Here we don't use KCmInitIndex becouse initial entry should be updated 
       
  2008     // too!
       
  2009     for ( i = 0; i < iData->iConnMethodArray->Count(); ++i )
       
  2010         {
       
  2011         dnIapRecord = (*(iData->iConnMethodArray))[i]->iDNRecord;
       
  2012         
       
  2013         if( dnIapRecord->iIAP )
       
  2014             {
       
  2015             if( !RECORD_FROM_ELEMENT_ID( dnIapRecord->iIAP ) )
       
  2016                 {
       
  2017                 dnIapRecord->iIAP = (*(iData->iConnMethodArray))[i]->iPlugin->IAPRecordElementId();
       
  2018                 }
       
  2019             }
       
  2020         
       
  2021         // Set protection on connection methods 
       
  2022         SetAttribute( dnIapRecord, 
       
  2023                       ECDProtectedWrite, 
       
  2024                       ProtectionLevel() == EProtLevel1 ? ETrue : EFalse );
       
  2025         // Metadata is used instead of ECDHidden Attribute                      
       
  2026         //SetAttribute( dnIapRecord, ECDHidden, iData->iNetworkRecord->Attributes() & ECDHidden );
       
  2027         CheckIfNameModifiedL( dnIapRecord );
       
  2028              
       
  2029         if ( dnIapRecord->RecordId() )
       
  2030             {           
       
  2031             dnIapRecord->ModifyL( Session() );
       
  2032             }
       
  2033         else
       
  2034             // this is a new record
       
  2035             {
       
  2036             dnIapRecord->SetRecordId(KCDNewRecordRequest);
       
  2037             dnIapRecord->iSNAP = Id();
       
  2038             dnIapRecord->StoreL( Session() );
       
  2039             }
       
  2040         }
       
  2041     }
       
  2042 
       
  2043 // -----------------------------------------------------------------------------
       
  2044 // CCmDestinationImpl::UpdateSNAPMetadataTableL()
       
  2045 // -----------------------------------------------------------------------------
       
  2046 //
       
  2047 void CCmDestinationImpl::UpdateSNAPMetadataTableL()
       
  2048     {
       
  2049     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateSNAPMetadataTableL" );
       
  2050     
       
  2051     if( !iData->iMetaDataRec->RecordId() )
       
  2052         // new record
       
  2053         {
       
  2054         iData->iMetaDataRec->iSNAP = Id();
       
  2055         iData->iMetaDataRec->SetRecordId( KCDNewRecordRequest );
       
  2056         iData->iMetaDataRec->StoreL( Session() );
       
  2057         }
       
  2058     else
       
  2059         {
       
  2060         iData->iMetaDataRec->ModifyL( Session() );
       
  2061         }
       
  2062     }
       
  2063 
       
  2064 // -----------------------------------------------------------------------------
       
  2065 // CCmDestinationImpl::LoadSNAPMetadataTableL()
       
  2066 // -----------------------------------------------------------------------------
       
  2067 //
       
  2068 void CCmDestinationImpl::LoadSNAPMetadataTableL()
       
  2069     {
       
  2070     LOGGER_ENTERFN( "CCmDestinationImpl::LoadSNAPMetadataTableL" );
       
  2071 
       
  2072     iData->iMetaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  2073                                             iCmMgr.IconTableId() );
       
  2074 
       
  2075     iData->iMetaDataRec->iSNAP = Id();
       
  2076                 
       
  2077     if ( !iData->iMetaDataRec->FindL( Session() ) )
       
  2078         // Not found -> fill in with default values
       
  2079         {
       
  2080         iData->iMetaDataRec->iSNAP = Id();
       
  2081         iData->iMetaDataRec->iIcon = 0;
       
  2082         iData->iMetaDataRec->iMetadata = 0;
       
  2083         }
       
  2084     }
       
  2085 
       
  2086 // -----------------------------------------------------------------------------
       
  2087 // CCmDestinationImpl::LoadNetworkRecordL()
       
  2088 // -----------------------------------------------------------------------------
       
  2089 //
       
  2090 void CCmDestinationImpl::LoadNetworkRecordL( TUint32 /*aDestinationId*/ )
       
  2091     {
       
  2092     LOGGER_ENTERFN( "CCmDestinationImpl::LoadNetworkRecordL" );
       
  2093 
       
  2094     // set the record ID
       
  2095     iData->iNetworkRecord->SetRecordId( iData->iDestAPRecord->iCustomSelectionPolicy );
       
  2096   
       
  2097     // load the record ID
       
  2098     iData->iNetworkRecord->LoadL( Session() );
       
  2099     }
       
  2100 
       
  2101 // -----------------------------------------------------------------------------
       
  2102 // CCmDestinationImpl::LoadDestAPRecordL()
       
  2103 // -----------------------------------------------------------------------------
       
  2104 //
       
  2105 void CCmDestinationImpl::LoadDestAPRecordL( TUint32 aDestinationId )
       
  2106     {
       
  2107     LOGGER_ENTERFN( "CCmDestinationImpl::LoadDestAPRecordL" );
       
  2108 
       
  2109     if ( aDestinationId > KCmDefaultDestinationAPTagId )
       
  2110         {
       
  2111         // set the record ID
       
  2112         iData->iDestAPRecord->iRecordTag = aDestinationId;
       
  2113         // load the record ID
       
  2114         if ( iData->iDestAPRecord->FindL( Session() ) )
       
  2115             {
       
  2116             iData->iDestAPRecord->LoadL( Session() );
       
  2117             }
       
  2118         else
       
  2119             {
       
  2120             User::Leave( KErrNotFound );
       
  2121             }
       
  2122         }
       
  2123     else
       
  2124         {
       
  2125         User::Leave( KErrArgument );
       
  2126         }
       
  2127     }
       
  2128 
       
  2129 // -----------------------------------------------------------------------------
       
  2130 // CCmDestinationImpl::LoadConnectionMethodsL()
       
  2131 // -----------------------------------------------------------------------------
       
  2132 //    
       
  2133 void CCmDestinationImpl::LoadConnectionMethodsL()
       
  2134     {
       
  2135     LOGGER_ENTERFN( "CCmDestinationImpl::LoadConnectionMethodsL" );
       
  2136     
       
  2137     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  2138                         new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  2139                                           iCmMgr.DestinationTableId() );
       
  2140     CleanupStack::PushL( ptrRecordSet );
       
  2141 
       
  2142     // Prime record
       
  2143     CCDSnapRecord* snapRec = iCmMgr.SNAPRecordL( 0 );
       
  2144     CleanupStack::PushL( snapRec );
       
  2145     snapRec->iSNAP = Id();
       
  2146     ptrRecordSet->iRecords.AppendL( snapRec );
       
  2147 
       
  2148     CleanupStack::Pop( snapRec );
       
  2149     snapRec = NULL;
       
  2150 
       
  2151     OpenTransactionLC();            
       
  2152     if ( !ptrRecordSet->FindL(Session()) )
       
  2153         // no conn method is to this destination -> it was not us who made it
       
  2154         {
       
  2155         CLOG_WRITE( "Empty destination" );
       
  2156         User::Leave( KErrUnderflow );
       
  2157         }
       
  2158 
       
  2159     TLinearOrder<CMDBRecordBase> orderbyId( 
       
  2160                                     CCmDestinationImpl::SortRecordsByPriority );
       
  2161     ptrRecordSet->iRecords.Sort(orderbyId);
       
  2162 
       
  2163     TInt count = ptrRecordSet->iRecords.Count();
       
  2164     
       
  2165     //Load IAP records to be used to check if the IAPs are existing
       
  2166     CMDBRecordSet<CCDIAPRecord>*  ptrIapSet = 
       
  2167                     new (ELeave) CMDBRecordSet<CCDIAPRecord>( KCDTIdIAPRecord );
       
  2168     CleanupStack::PushL( ptrIapSet );
       
  2169     
       
  2170     TRAPD( err, ptrIapSet->LoadL( Session() ) );
       
  2171 
       
  2172     if( !err )
       
  2173         {
       
  2174         CLOG_WRITE_1_PTR( NULL, "Record num [%d]", ptrIapSet->iRecords.Count() );
       
  2175         
       
  2176         // Here we don't use CM_INIT_INDEX because initial entry should be 
       
  2177         // loaded too!
       
  2178         for ( TInt i = 0; i < count; i++ )
       
  2179             {
       
  2180             snapRec = (*ptrRecordSet)[i];
       
  2181             TBool exist( EFalse );
       
  2182             
       
  2183             // Check if CM really exists, if not 
       
  2184             // it should be cleared from selection policy table
       
  2185             TInt32 embedded = QUERY_INT_FIELD( 
       
  2186                                 snapRec, 
       
  2187                                 KCDTIdDataMobilitySelectionPolicyEmbeddedSNAP );
       
  2188             TInt32 iap = RECORD_FROM_ELEMENT_ID( 
       
  2189                             QUERY_INT_FIELD( 
       
  2190                                        snapRec, 
       
  2191                                        KCDTIdDataMobilitySelectionPolicyIAP ) );
       
  2192             // Item could be embedded destination or iap
       
  2193             if ( embedded )
       
  2194                 {
       
  2195                 CCDAccessPointRecord * destAPRecord = static_cast<CCDAccessPointRecord *>(
       
  2196                                 CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2197                 CleanupStack::PushL( destAPRecord );
       
  2198                 destAPRecord->iRecordTag = embedded;
       
  2199                 if ( !destAPRecord->FindL( Session() ) )
       
  2200                     {
       
  2201                     CleanUpSnapMetadataTableL( embedded );
       
  2202                     (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2203                     }
       
  2204                 else
       
  2205                     {
       
  2206                     exist = ETrue;
       
  2207                     }
       
  2208                     
       
  2209                 CleanupStack::PopAndDestroy( destAPRecord );
       
  2210                 }                
       
  2211             else if ( iap )
       
  2212                 // This is an AP
       
  2213                 {
       
  2214                 for ( TInt iapInd = 0; iapInd < ptrIapSet->iRecords.Count(); ++iapInd )
       
  2215                     {
       
  2216                     CMDBRecordBase* iapRec = (*ptrIapSet)[iapInd];
       
  2217 
       
  2218                     if ( iap == iapRec->RecordId() )
       
  2219                         {
       
  2220                         exist = ETrue;
       
  2221                         delete iapRec;
       
  2222                         // this way we can filter out duplicated CMs
       
  2223                         ptrIapSet->iRecords.Remove( iapInd );
       
  2224                         break;
       
  2225                         }
       
  2226                     }
       
  2227                 if ( !exist )
       
  2228                     {
       
  2229                     DeleteIAPRecordsL( snapRec );
       
  2230                     }
       
  2231                 }
       
  2232             
       
  2233             // The first record is a dummy one where iap and snap are zero
       
  2234             if ( exist || ( !embedded && !iap ) )
       
  2235                 {
       
  2236                 // The item may have to be loaded at this stage so that the supported can be checked 
       
  2237                 // before it is put into iData->iConnMethodArray for the item may be unsupported.
       
  2238                 TInt err( 0 );
       
  2239                 
       
  2240                 if ( i != 0 )
       
  2241                     {
       
  2242                     if ( embedded )
       
  2243                         {
       
  2244                         TRAP( err, TUint32 bearerType = iCmMgr.BearerTypeFromCmIdL( embedded ) );
       
  2245                         }
       
  2246                     else if ( iap )
       
  2247                         {
       
  2248                         TRAP( err, TUint32 bearerType = iCmMgr.BearerTypeFromCmIdL( iap ) );
       
  2249                         }
       
  2250                     }
       
  2251                
       
  2252                 if ( !err )
       
  2253                     {
       
  2254                     CPluginItem* item = new (ELeave) CPluginItem;
       
  2255                     CleanupStack::PushL( item );
       
  2256                     
       
  2257                     item->iDNRecord = iCmMgr.SNAPRecordL( snapRec->RecordId() );
       
  2258                     item->iPlugin = NULL;
       
  2259 
       
  2260                     iData->iConnMethodArray->AppendL( item );
       
  2261                 
       
  2262                     CleanupStack::Pop( item );
       
  2263                     }
       
  2264                 }
       
  2265             }
       
  2266         }
       
  2267     else
       
  2268         // There's no connection method in the phone
       
  2269         {
       
  2270         CPluginItem* item = new (ELeave) CPluginItem;
       
  2271         
       
  2272         CleanupStack::PushL( item );
       
  2273         
       
  2274         item->iDNRecord = iCmMgr.SNAPRecordL( (*ptrRecordSet)[0]->RecordId() );
       
  2275 
       
  2276         iData->iConnMethodArray->AppendL( item );       
       
  2277         
       
  2278         CleanupStack::Pop( item );                 
       
  2279         }
       
  2280         
       
  2281     CleanupStack::PopAndDestroy( ptrIapSet );
       
  2282     RollbackTransaction();
       
  2283         
       
  2284     ptrRecordSet->iRecords.ResetAndDestroy();
       
  2285     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2286     }
       
  2287 
       
  2288 // -----------------------------------------------------------------------------
       
  2289 // CCmDestinationImpl::ReLoadConnectionMethodsL()
       
  2290 // -----------------------------------------------------------------------------
       
  2291 //
       
  2292 void CCmDestinationImpl::ReLoadConnectionMethodsL()
       
  2293     {
       
  2294     TInt count = iData->iConnMethodArray->Count();
       
  2295     //TInt index = KCmInitIndex;
       
  2296     TInt index = 0;
       
  2297     
       
  2298     while ( index < count )
       
  2299         {
       
  2300         CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  2301         item->iFlags |= CPluginItem::ERemoveCm;
       
  2302         
       
  2303         iData->iDeleteCmArray->AppendL( item );
       
  2304         iData->iConnMethodArray->Delete( index );
       
  2305         iData->iConnMethodArray->Compress();
       
  2306         
       
  2307         count = iData->iConnMethodArray->Count();
       
  2308         }
       
  2309     
       
  2310     // Empty the array, but do not delete it
       
  2311     iData->ResetAndDestroyArray( iData->iDeleteCmArray, EFalse );
       
  2312     
       
  2313     LoadConnectionMethodsL();
       
  2314     }
       
  2315     
       
  2316 // ---------------------------------------------------------
       
  2317 // CCmDestinationImpl::CleanUpEmbeddedL
       
  2318 // ---------------------------------------------------------
       
  2319 //
       
  2320 void CCmDestinationImpl::CleanUpEmbeddedL(TUint32 aDestId)
       
  2321     {
       
  2322     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpEmbeddedL" );
       
  2323 
       
  2324     TBool found = EFalse;
       
  2325     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  2326                         new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  2327                                           iCmMgr.DestinationTableId() );
       
  2328     CleanupStack::PushL( ptrRecordSet );
       
  2329     // Prime record
       
  2330     CCDSnapRecord* snapRec = iCmMgr.SNAPRecordL( 0 );
       
  2331     CleanupStack::PushL( snapRec );
       
  2332     snapRec->iEmbeddedSNAP = aDestId;
       
  2333     ptrRecordSet->iRecords.AppendL( snapRec );
       
  2334     CleanupStack::Pop( snapRec );
       
  2335     snapRec = NULL;
       
  2336 
       
  2337     if ( ptrRecordSet->FindL(Session()) )
       
  2338         {
       
  2339         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2340             {
       
  2341             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2342             }
       
  2343         found = ETrue;
       
  2344         }
       
  2345     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2346     if (found)
       
  2347         {
       
  2348         CleanUpSnapMetadataTableL(aDestId);    
       
  2349         }
       
  2350     }
       
  2351 // ---------------------------------------------------------
       
  2352 // CCmDestinationImpl::CleanUpSnapMetadataTableL
       
  2353 // ---------------------------------------------------------
       
  2354 //
       
  2355 void CCmDestinationImpl::CleanUpSnapMetadataTableL( TUint32 aSnap )
       
  2356     {
       
  2357     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpSnapMetadataTableL" );
       
  2358     
       
  2359     // Just to test how many record we have
       
  2360     CMDBRecordSet<CCDSNAPMetadataRecord>*  ptrRecordSet 
       
  2361                 = new (ELeave) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  2362                                                 iCmMgr.IconTableId() );
       
  2363     CleanupStack::PushL( ptrRecordSet );
       
  2364         
       
  2365     // Prime record
       
  2366     CCDSNAPMetadataRecord* record = 
       
  2367             new (ELeave) CCDSNAPMetadataRecord( iCmMgr.IconTableId() );
       
  2368     CleanupStack::PushL( record );
       
  2369     
       
  2370     record->iSNAP = aSnap;
       
  2371     ptrRecordSet->iRecords.AppendL( record );
       
  2372     
       
  2373     CleanupStack::Pop( record );
       
  2374     record = NULL;
       
  2375     
       
  2376     if ( ptrRecordSet->FindL( Session() ) )
       
  2377         {
       
  2378         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2379             {
       
  2380             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2381             }
       
  2382         }
       
  2383         
       
  2384     CleanupStack::PopAndDestroy( ptrRecordSet );    //ptrRecordSet 
       
  2385     }
       
  2386 
       
  2387 // ---------------------------------------------------------
       
  2388 // CCmDestinationImpl::CleanUpSeamlessnessTableL
       
  2389 // ---------------------------------------------------------
       
  2390 //
       
  2391 void CCmDestinationImpl::CleanUpSeamlessnessTableL( TUint32 aIapId )
       
  2392     {
       
  2393     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpSeamlessnesstableL" );
       
  2394     
       
  2395     // Just to test how many record we have
       
  2396     CMDBRecordSet<CCDIAPMetadataRecord>*  ptrRecordSet 
       
  2397         = new (ELeave) CMDBRecordSet<CCDIAPMetadataRecord>( 
       
  2398                                         iCmMgr.SeamlessnessTableId() );
       
  2399     CleanupStack::PushL( ptrRecordSet );
       
  2400         
       
  2401     // Prime record
       
  2402     CCDIAPMetadataRecord* record = 
       
  2403       new (ELeave) CCDIAPMetadataRecord( iCmMgr.SeamlessnessTableId() );
       
  2404     CleanupStack::PushL( record );
       
  2405     
       
  2406     TMDBElementId elementid = iCmMgr.SeamlessnessTableId() & 
       
  2407                               KCDTIdIAPMetadataIAP & 
       
  2408                               aIapId;
       
  2409     record->iSeamlessness = elementid;
       
  2410     ptrRecordSet->iRecords.AppendL( record );
       
  2411     
       
  2412     CleanupStack::Pop( record );
       
  2413     record = NULL;
       
  2414     
       
  2415     if ( ptrRecordSet->FindL( Session() ) )
       
  2416         {
       
  2417         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2418             {
       
  2419             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2420             }
       
  2421         }
       
  2422         
       
  2423     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2424     }
       
  2425     
       
  2426 // ---------------------------------------------------------
       
  2427 // CCmDestinationImpl::SortRecordsByPriority
       
  2428 // ---------------------------------------------------------
       
  2429 //
       
  2430 TInt CCmDestinationImpl::SortRecordsByPriority( const CMDBRecordBase& aLeft, 
       
  2431                                                 const CMDBRecordBase& aRight )
       
  2432     {
       
  2433     TUint left = QUERY_INT_FIELD( const_cast<CMDBRecordBase*>(&aLeft), 
       
  2434                                   KCDTIdDataMobilitySelectionPolicyPriority );
       
  2435     TUint right = QUERY_INT_FIELD( const_cast<CMDBRecordBase*>(&aRight),
       
  2436                                    KCDTIdDataMobilitySelectionPolicyPriority );
       
  2437 
       
  2438     /*
       
  2439     *   - negative value, if aLeft is less than aRight;
       
  2440     *   - 0,              if aLeft equals to aRight;
       
  2441     *   - positive value, if aLeft is greater than aRight.
       
  2442     */
       
  2443     if ( left == right )
       
  2444         {
       
  2445         return 0;
       
  2446         }
       
  2447     
       
  2448     return ( left < right ) ? -1 : 1;
       
  2449     }
       
  2450 
       
  2451 // -----------------------------------------------------------------------------
       
  2452 // CCmDestinationImpl::IconL()
       
  2453 // -----------------------------------------------------------------------------
       
  2454 //      
       
  2455 EXPORT_C CGulIcon* CCmDestinationImpl::IconL() 
       
  2456     {
       
  2457     LOGGER_ENTERFN( "CCmDestinationImpl::IconL" );
       
  2458 
       
  2459     return IconL( iData->iMetaDataRec->iIcon );
       
  2460     }
       
  2461 
       
  2462 // -----------------------------------------------------------------------------
       
  2463 // CCmDestinationImpl::SetIconL()
       
  2464 // -----------------------------------------------------------------------------
       
  2465 //      
       
  2466 void CCmDestinationImpl::SetIconL( TUint32 anIndex )
       
  2467     {
       
  2468     LOGGER_ENTERFN( "CCmDestinationImpl::SetIconL" )
       
  2469     
       
  2470     if( ProtectionLevel() == EProtLevel1 )
       
  2471         {
       
  2472         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2473         }
       
  2474         
       
  2475     iData->iMetaDataRec->iIcon = anIndex;
       
  2476     }
       
  2477 
       
  2478 // -----------------------------------------------------------------------------
       
  2479 // CCmDestinationData::MetadataL()
       
  2480 // -----------------------------------------------------------------------------
       
  2481 //
       
  2482 TUint32 CCmDestinationData::MetadataL( TSnapMetadataField aMetaField ) const
       
  2483     {
       
  2484     LOGGER_ENTERFN( "CCmDestinationImpl::MetadataL" )
       
  2485 
       
  2486     TUint retVal( 0 );
       
  2487 
       
  2488     switch( aMetaField )
       
  2489         {
       
  2490         case ESnapMetadataInternet:
       
  2491             {
       
  2492             retVal = TUint32(iMetaDataRec->iMetadata) & 
       
  2493                      ESnapMetadataInternet;
       
  2494             }
       
  2495             break;
       
  2496             
       
  2497         case ESnapMetadataHighlight:
       
  2498             {
       
  2499             retVal = TUint32(iMetaDataRec->iMetadata) & 
       
  2500                      ESnapMetadataHighlight;
       
  2501             }
       
  2502             break;
       
  2503             
       
  2504         case ESnapMetadataHiddenAgent:
       
  2505             {
       
  2506             retVal = TUint32(iMetaDataRec->iMetadata) &
       
  2507                      ESnapMetadataHiddenAgent;
       
  2508             }
       
  2509             break;
       
  2510 
       
  2511         case ESnapMetadataDestinationIsLocalised:
       
  2512             {
       
  2513             retVal = (TUint32(iMetaDataRec->iMetadata) &
       
  2514                       ESnapMetadataDestinationIsLocalised) >> 4;
       
  2515             }
       
  2516             break;
       
  2517             
       
  2518         case ESnapMetadataPurpose:
       
  2519             {
       
  2520             retVal = (TUint32(iMetaDataRec->iMetadata) &
       
  2521                      ESnapMetadataPurpose) >> 8;
       
  2522             }
       
  2523             break;
       
  2524 
       
  2525         default:
       
  2526             {
       
  2527             User::Leave( KErrArgument );
       
  2528             }
       
  2529         }
       
  2530     
       
  2531     return retVal;
       
  2532     }
       
  2533 
       
  2534 // -----------------------------------------------------------------------------
       
  2535 // CCmDestinationImpl::MetadataL()
       
  2536 // -----------------------------------------------------------------------------
       
  2537 //
       
  2538 TUint32 CCmDestinationImpl::MetadataL( TSnapMetadataField aMetaField ) const
       
  2539     {
       
  2540     LOGGER_ENTERFN( "CCmDestinationImpl::MetadataL" )
       
  2541     return iData->MetadataL(aMetaField);
       
  2542     }
       
  2543     
       
  2544 // -----------------------------------------------------------------------------
       
  2545 // CCmDestinationImpl::SetMetadataL()
       
  2546 // -----------------------------------------------------------------------------
       
  2547 //
       
  2548 void CCmDestinationImpl::SetMetadataL( TSnapMetadataField aMetaField, 
       
  2549 		                               TUint32 aValue )
       
  2550     {
       
  2551     LOGGER_ENTERFN( "CCmDestinationImpl::SetMetadata" );
       
  2552     
       
  2553     if( ProtectionLevel() == EProtLevel1 )
       
  2554         {
       
  2555         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2556         }
       
  2557         
       
  2558     switch( aMetaField )
       
  2559         {
       
  2560         case ESnapMetadataInternet:
       
  2561             {
       
  2562             if( aValue )
       
  2563                 {
       
  2564                 CheckIfInternetExistsL();
       
  2565                 
       
  2566                 iData->iMetaDataRec->iMetadata = 
       
  2567                         ESnapMetadataInternet | iData->iMetaDataRec->iMetadata;
       
  2568 
       
  2569                 // Set the new way, too!!!
       
  2570                 SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2571                               ELocalisedDestInternet );
       
  2572                 }
       
  2573             else
       
  2574                 {
       
  2575                 iData->iMetaDataRec->iMetadata =
       
  2576                         ~ESnapMetadataInternet & iData->iMetaDataRec->iMetadata;
       
  2577                 // Clear the new way, too!!!
       
  2578                 SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2579                               ENotLocalisedDest );                
       
  2580                 }
       
  2581             }
       
  2582             break;
       
  2583 
       
  2584         case ESnapMetadataDestinationIsLocalised:
       
  2585             {
       
  2586             // Check that aValue is within valid range.
       
  2587             if ( aValue > ELocalisedDestIntranet )
       
  2588                 {
       
  2589                 User::Leave( KErrArgument );
       
  2590                 }
       
  2591             
       
  2592             TUint32 oldVal = TUint32(iData->iMetaDataRec->iMetadata) & 
       
  2593                              ESnapMetadataInternet;
       
  2594             if ( aValue != ENotLocalisedDest )
       
  2595                 {
       
  2596                 // check if already exists...
       
  2597                 CheckIfLocalisedDestExistL( aValue );
       
  2598                 // does not exists, first clear original value
       
  2599                 // if old one was Internet, clear that, too:
       
  2600                 if ( oldVal )
       
  2601                     {
       
  2602                     // copied here to avoid recursivity!!!
       
  2603                     // SetMetadataL(ESnapMetadataInternet, 0 );
       
  2604                     iData->iMetaDataRec->iMetadata =
       
  2605                         ~ESnapMetadataInternet & iData->iMetaDataRec->iMetadata;
       
  2606                     }
       
  2607                 // clearing
       
  2608                 iData->iMetaDataRec->iMetadata =
       
  2609                                                 ~ESnapMetadataDestinationIsLocalised &
       
  2610                                                 iData->iMetaDataRec->iMetadata;
       
  2611                 // set new value
       
  2612                 TUint32 mask = aValue << 4; 
       
  2613                 iData->iMetaDataRec->iMetadata = 
       
  2614                                                 mask | 
       
  2615                                                 iData->iMetaDataRec->iMetadata;
       
  2616                 // for backward compatibility, if it is internet, 
       
  2617                 // set it the old way, too
       
  2618                 if ( aValue == ELocalisedDestInternet )
       
  2619                     {
       
  2620                     // copied here to avoid recursivity!!!
       
  2621                     iData->iMetaDataRec->iMetadata = 
       
  2622                         ESnapMetadataInternet | iData->iMetaDataRec->iMetadata;
       
  2623                     // SetMetadataL(ESnapMetadataInternet, 1 );
       
  2624                     }
       
  2625                 }
       
  2626             else
       
  2627                 {
       
  2628                 // not localised, set to ENotLocalisedDest = 0
       
  2629                 // for backward compatibility, if it was internet, 
       
  2630                 // set it the old way, too
       
  2631                 if ( oldVal )
       
  2632                     {
       
  2633                     SetMetadataL(ESnapMetadataInternet, 0 );
       
  2634                     }
       
  2635                 // clear the new way...
       
  2636                 iData->iMetaDataRec->iMetadata =
       
  2637                                                 ~ESnapMetadataDestinationIsLocalised &
       
  2638                                                 iData->iMetaDataRec->iMetadata;
       
  2639                 }
       
  2640 
       
  2641             break;
       
  2642             }
       
  2643 
       
  2644         case ESnapMetadataPurpose:
       
  2645             {
       
  2646             // Check that aValue is within valid range.
       
  2647             if ( aValue > ESnapPurposeIntranet )
       
  2648                 {
       
  2649                 User::Leave( KErrArgument );
       
  2650                 }
       
  2651             
       
  2652             // Check if destination with the given purpose already
       
  2653             // exists
       
  2654             CheckIfPurposeExistL( aValue );
       
  2655             
       
  2656             // ESnapPurposeInternet and ESnapPurposeMMS need special
       
  2657             // handling
       
  2658             switch( aValue )
       
  2659                 {
       
  2660                 case ESnapPurposeUnknown:
       
  2661                     {
       
  2662                     // This also clears ESnapMetadataInternet
       
  2663                     SetMetadataL( ESnapMetadataDestinationIsLocalised, ENotLocalisedDest );
       
  2664                     break;
       
  2665                     }
       
  2666                 case ESnapPurposeInternet:
       
  2667                     {
       
  2668                     // This sets ESnapMetadataInternet and
       
  2669                     // ELocalisedDestInternet
       
  2670                     SetMetadataL( ESnapMetadataInternet, 1 );
       
  2671                     }
       
  2672                     break;
       
  2673                 case ESnapPurposeOperator:
       
  2674                     {
       
  2675                     SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2676                                   ELocalisedDestWap );
       
  2677                     }
       
  2678                 	break;
       
  2679                 case ESnapPurposeMMS:
       
  2680                     {
       
  2681                     SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2682                                   ELocalisedDestMMS );
       
  2683                     iData->iMetaDataRec->iMetadata = 
       
  2684                         ESnapMetadataHiddenAgent | iData->iMetaDataRec->iMetadata;
       
  2685                     }
       
  2686                     break;
       
  2687                 case ESnapPurposeIntranet:
       
  2688                     {
       
  2689                     SetMetadataL( ESnapMetadataDestinationIsLocalised,
       
  2690                                   ELocalisedDestIntranet );
       
  2691                     }
       
  2692                     break;
       
  2693                 default:
       
  2694                     break;
       
  2695                 }
       
  2696             
       
  2697             TUint32 value = aValue << 8;
       
  2698             // reset the purpose bit
       
  2699             iData->iMetaDataRec->iMetadata = ~ESnapMetadataPurpose & iData->iMetaDataRec->iMetadata;
       
  2700             // set the purpose bit
       
  2701             iData->iMetaDataRec->iMetadata = value | iData->iMetaDataRec->iMetadata;
       
  2702             }
       
  2703             break;
       
  2704 
       
  2705         case ESnapMetadataHighlight:
       
  2706             {
       
  2707             if( aValue )
       
  2708                 {
       
  2709                 iData->iMetaDataRec->iMetadata = 
       
  2710                         ESnapMetadataHighlight | iData->iMetaDataRec->iMetadata;
       
  2711                 }
       
  2712             else
       
  2713                 {
       
  2714                 iData->iMetaDataRec->iMetadata =
       
  2715                         ~ESnapMetadataHighlight & iData->iMetaDataRec->iMetadata;
       
  2716                 }
       
  2717             }
       
  2718             break;
       
  2719             
       
  2720         case ESnapMetadataHiddenAgent:
       
  2721             {
       
  2722             TUint32 internet = iData->iMetaDataRec->iMetadata & ESnapMetadataInternet;
       
  2723             TUint32 internetLocal = ( iData->iMetaDataRec->iMetadata & ESnapMetadataDestinationIsLocalised ) >> 4;
       
  2724             TUint32 internetPurpose = ( iData->iMetaDataRec->iMetadata & ESnapMetadataPurpose ) >> 8;
       
  2725             if( aValue )
       
  2726                 {
       
  2727                 if ( internet
       
  2728                      || ( internetLocal == ELocalisedDestInternet )
       
  2729                      || ( internetPurpose == ESnapPurposeInternet ) )
       
  2730                     {
       
  2731                     User::Leave( KErrArgument );
       
  2732                     }
       
  2733 
       
  2734                 iData->iMetaDataRec->iMetadata = 
       
  2735                         ESnapMetadataHiddenAgent | iData->iMetaDataRec->iMetadata;
       
  2736                 }
       
  2737             else
       
  2738                 {
       
  2739                 iData->iMetaDataRec->iMetadata = 
       
  2740                         ~ESnapMetadataHiddenAgent & iData->iMetaDataRec->iMetadata;
       
  2741                 }
       
  2742             }
       
  2743             break;
       
  2744             
       
  2745         default:
       
  2746             {
       
  2747             User::Leave( KErrArgument );
       
  2748             }
       
  2749         }
       
  2750     }
       
  2751 // -----------------------------------------------------------------------------
       
  2752 // CCmDestinationImpl::CreateEmbeddedDestinationPluginL()
       
  2753 // -----------------------------------------------------------------------------
       
  2754 //      
       
  2755 void CCmDestinationImpl::CreateEmbeddedDestinationPluginL( 
       
  2756                                                         CPluginItem& aItem, 
       
  2757                                                         TInt aDestinationId )
       
  2758     {
       
  2759     LOGGER_ENTERFN( "CCmDestinationImpl::CreateEmbeddedDestinationPluginL" );
       
  2760 
       
  2761     aItem.iPlugin = iCmMgr.CreateConnectionMethodL(KUidEmbeddedDestination, this); 
       
  2762     CleanupStack::PushL( aItem.iPlugin );
       
  2763     // Load this destination
       
  2764     aItem.iPlugin->LoadL( aDestinationId );
       
  2765     CleanupStack::Pop( aItem.iPlugin );        
       
  2766     }
       
  2767 
       
  2768 // -----------------------------------------------------------------------------
       
  2769 // CCmDestinationImpl::LoadEmbeddedDestinationPluginL()
       
  2770 // -----------------------------------------------------------------------------
       
  2771 //      
       
  2772 void CCmDestinationImpl::LoadEmbeddedDestinationPluginL( 
       
  2773                                                         CPluginItem& aItem )
       
  2774     {
       
  2775     LOGGER_ENTERFN( "CCmDestinationImpl::LoadEmbeddedDestinationPluginL" );
       
  2776 
       
  2777     CreateEmbeddedDestinationPluginL(aItem, aItem.iDNRecord->ElementId());
       
  2778     }
       
  2779 
       
  2780 // -----------------------------------------------------------------------------
       
  2781 // CCmDestinationImpl::LoadPluginL()
       
  2782 // -----------------------------------------------------------------------------
       
  2783 //      
       
  2784 void CCmDestinationImpl::LoadPluginL( CPluginItem& aItem )
       
  2785     {
       
  2786     LOGGER_ENTERFN( "CCmDestinationImpl::LoadPluginL" );
       
  2787     
       
  2788     if( aItem.iPlugin )
       
  2789         {
       
  2790         return;
       
  2791         }
       
  2792         
       
  2793     TUint32 cmId;
       
  2794     if ( aItem.iDNRecord->iEmbeddedSNAP )
       
  2795         // This is an embedded destination
       
  2796         {
       
  2797         cmId = aItem.iDNRecord->iEmbeddedSNAP;
       
  2798         
       
  2799         }
       
  2800     else
       
  2801         // Normal IAP id
       
  2802         {
       
  2803         cmId = RECORD_FROM_ELEMENT_ID( aItem.iDNRecord->iIAP );
       
  2804         }
       
  2805 
       
  2806     aItem.iPlugin = iCmMgr.DoFindConnMethodL( 
       
  2807                         cmId, 
       
  2808                         this );
       
  2809                         
       
  2810     CLOG_ATTACH( aItem.iPlugin, this );
       
  2811     }    
       
  2812 
       
  2813 // -----------------------------------------------------------------------------
       
  2814 // CCmDestinationImpl::PluginClosed()
       
  2815 // -----------------------------------------------------------------------------
       
  2816 //
       
  2817 void CCmDestinationImpl::PluginClosed( CCmPluginBase* aPlugin )
       
  2818     {
       
  2819     LOGGER_ENTERFN( "CCmDestinationImpl::PluginClosed" );
       
  2820 
       
  2821     if (iData->iConnMethodArray)
       
  2822         {
       
  2823         for ( TInt i = 0; i < iData->iConnMethodArray->Count(); ++i )
       
  2824             {
       
  2825             if ( (*(iData->iConnMethodArray))[i]->iPlugin == aPlugin )
       
  2826                 {
       
  2827                 // Must NOT delete it here. Simply forget that
       
  2828                 // we had this plugin instance.
       
  2829                 (*(iData->iConnMethodArray))[i]->iPlugin = NULL;
       
  2830                 
       
  2831                 break;
       
  2832                 }
       
  2833             }        
       
  2834         }
       
  2835     }
       
  2836     
       
  2837 // -----------------------------------------------------------------------------
       
  2838 // CCmDestinationData::IsHiddenL()
       
  2839 // -----------------------------------------------------------------------------
       
  2840 //          
       
  2841 TBool CCmDestinationData::IsHiddenL()
       
  2842     {
       
  2843     TSnapMetadataField hiddenValue = ( TSnapMetadataField )MetadataL( ESnapMetadataHiddenAgent );
       
  2844     if ( hiddenValue == ESnapMetadataHiddenAgent )
       
  2845         {
       
  2846     	return ETrue;
       
  2847         }
       
  2848     else
       
  2849         {
       
  2850     	return EFalse;
       
  2851         }
       
  2852     }    
       
  2853     
       
  2854 // -----------------------------------------------------------------------------
       
  2855 // CCmDestinationImpl::IsHiddenL()
       
  2856 // -----------------------------------------------------------------------------
       
  2857 //          
       
  2858 EXPORT_C TBool CCmDestinationImpl::IsHidden()
       
  2859     {
       
  2860     TBool hidden( EFalse );
       
  2861     TRAPD( err, hidden = iData->IsHiddenL() );
       
  2862     __ASSERT_ALWAYS( err == KErrNone, User::Panic(_L( "CMManager" ), err ) );
       
  2863     
       
  2864     return hidden;
       
  2865     }    
       
  2866 
       
  2867 // -----------------------------------------------------------------------------
       
  2868 // CCmDestinationImpl::SetHiddenL()
       
  2869 // -----------------------------------------------------------------------------
       
  2870 //          
       
  2871 EXPORT_C void CCmDestinationImpl::SetHiddenL( TBool aHidden )
       
  2872     {
       
  2873     if( ProtectionLevel() == EProtLevel1 )
       
  2874         {
       
  2875         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2876         }
       
  2877     SetMetadataL( ESnapMetadataHiddenAgent, aHidden );
       
  2878     }
       
  2879 
       
  2880 // -----------------------------------------------------------------------------
       
  2881 // CCmDestinationImpl::DeleteConnectionMethodsL
       
  2882 //
       
  2883 // Can be called only during opened transaction. 
       
  2884 // Array is emptied only after transaction commited!
       
  2885 //
       
  2886 // -----------------------------------------------------------------------------
       
  2887 //          
       
  2888 void CCmDestinationImpl::DeleteConnectionMethodsL()
       
  2889     {
       
  2890     LOGGER_ENTERFN( "DeleteConnectionMethodsL" );
       
  2891     
       
  2892     TInt i;
       
  2893     
       
  2894     for ( i = 0; i < iData->iDeleteCmArray->Count(); ++i )
       
  2895         {
       
  2896         CPluginItem* item = (*iData->iDeleteCmArray)[i];
       
  2897         
       
  2898         LoadPluginL( *item );   
       
  2899 
       
  2900         if( !(item->iFlags & CPluginItem::ERemoveCm) )
       
  2901             {
       
  2902             item->iPlugin->DeleteL( EFalse );
       
  2903             }
       
  2904             
       
  2905         item->iDNRecord->DeleteL( Session() );
       
  2906         }
       
  2907     }
       
  2908     
       
  2909 // -----------------------------------------------------------------------------
       
  2910 // CCmDestinationData::ResetAndDestroyArray
       
  2911 // -----------------------------------------------------------------------------
       
  2912 //          
       
  2913 void CCmDestinationData::ResetAndDestroyArray( CCmArray* &aArray, TBool aDestroy )
       
  2914     {
       
  2915     if( aArray )
       
  2916         {
       
  2917         for ( TInt i = 0; i < aArray->Count(); ++i )
       
  2918             {
       
  2919             CPluginItem* item = (*aArray)[i];
       
  2920             
       
  2921             delete item->iPlugin;
       
  2922             delete item->iDNRecord;
       
  2923             }
       
  2924             
       
  2925         aArray->ResetAndDestroy();
       
  2926         
       
  2927         if( aDestroy )
       
  2928             {
       
  2929             delete aArray; aArray = NULL;
       
  2930             }
       
  2931         }
       
  2932     }
       
  2933 
       
  2934 // -----------------------------------------------------------------------------
       
  2935 // CCmDestinationImpl::DeleteIAPRecordsL
       
  2936 // -----------------------------------------------------------------------------
       
  2937 //          
       
  2938 void CCmDestinationImpl::DeleteIAPRecordsL( CMDBRecordBase* aSnapRecord )
       
  2939     {
       
  2940     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteIAPRecordsL" );
       
  2941 
       
  2942     // First delete the metadata record
       
  2943     CCDIAPMetadataRecord* metaRec = new (ELeave) CCDIAPMetadataRecord( 
       
  2944                                         iCmMgr.SeamlessnessTableId() );
       
  2945                                         
       
  2946     CleanupStack::PushL( metaRec );
       
  2947 
       
  2948     metaRec->iIAP = RECORD_FROM_ELEMENT_ID( 
       
  2949                                 QUERY_INT_FIELD( 
       
  2950                                        aSnapRecord, 
       
  2951                                        KCDTIdDataMobilitySelectionPolicyIAP ) );
       
  2952 
       
  2953     if( metaRec->FindL( Session() ) )
       
  2954         {
       
  2955         metaRec->DeleteL( Session() );
       
  2956         }
       
  2957         
       
  2958     CleanupStack::PopAndDestroy( metaRec );
       
  2959     
       
  2960     // and now delete the SNAP record
       
  2961     aSnapRecord->DeleteL( Session() );
       
  2962     }
       
  2963 
       
  2964 // -----------------------------------------------------------------------------
       
  2965 // CCmDestinationImpl::CheckIfNameModifiedL
       
  2966 // -----------------------------------------------------------------------------
       
  2967 void CCmDestinationImpl::CheckIfNameModifiedL( CCDSnapRecord* aRecord )
       
  2968     {
       
  2969     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfNameModifiedL" );
       
  2970             
       
  2971     if ( !TPtrC(iData->iDestAPRecord->iRecordName).CompareF( TPtrC(aRecord->iRecordName) ) )
       
  2972         // names matches
       
  2973         {
       
  2974         return;
       
  2975         }
       
  2976     
       
  2977     aRecord->iRecordName.SetL( TPtrC(iData->iDestAPRecord->iRecordName) );
       
  2978     }
       
  2979 
       
  2980 // -----------------------------------------------------------------------------
       
  2981 // CCmDestinationImpl::IsConnectedL
       
  2982 // -----------------------------------------------------------------------------
       
  2983 EXPORT_C TBool CCmDestinationImpl::IsConnectedL() const
       
  2984     {
       
  2985     LOGGER_ENTERFN( "CCmDestinationImpl::IsConnectedL" );
       
  2986 
       
  2987     CCmDestinationImpl* myThis = const_cast<CCmDestinationImpl*>( this );
       
  2988     TBool retVal( EFalse );
       
  2989     TInt i;
       
  2990     
       
  2991     for( i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  2992         {
       
  2993         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  2994         
       
  2995         myThis->LoadPluginL( *item );
       
  2996             
       
  2997         if( item->iPlugin->GetBoolAttributeL( ECmConnected ) )
       
  2998             {
       
  2999             retVal = ETrue;
       
  3000             break;
       
  3001             }
       
  3002         }
       
  3003         
       
  3004     return retVal;
       
  3005     }
       
  3006 
       
  3007 // -----------------------------------------------------------------------------
       
  3008 // CCmDestinationImpl::CheckIfInternetExistsL
       
  3009 //
       
  3010 // There can be only one SNAP with Internet metadata field set.
       
  3011 // -----------------------------------------------------------------------------
       
  3012 void CCmDestinationImpl::CheckIfInternetExistsL()
       
  3013     {
       
  3014     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfInternetExistsL" );
       
  3015 
       
  3016     OpenTransactionLC();
       
  3017 
       
  3018     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3019            new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  3020                                                  iCmMgr.IconTableId() );
       
  3021     CleanupStack::PushL( metaSet );
       
  3022 
       
  3023     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3024 
       
  3025     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3026         {
       
  3027         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3028                                      KCDTIdSNAPMetadataMetadata );
       
  3029 
       
  3030         if( meta & ESnapMetadataInternet )
       
  3031             {
       
  3032             if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3033                                                 KCDTIdSNAPMetadataSNAP ) )
       
  3034                 {
       
  3035                 User::Leave( KErrAlreadyExists );
       
  3036                 }
       
  3037             }
       
  3038         }
       
  3039     
       
  3040     CleanupStack::PopAndDestroy( metaSet );
       
  3041     
       
  3042     RollbackTransaction();
       
  3043     }
       
  3044 
       
  3045 // -----------------------------------------------------------------------------
       
  3046 // CCmDestinationImpl::ConnectionMethodIndex
       
  3047 // -----------------------------------------------------------------------------
       
  3048 TInt CCmDestinationImpl::ConnectionMethodIndex( TUint32 aCmId )
       
  3049     {
       
  3050     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodIndex" );
       
  3051 
       
  3052     TInt found( KErrNotFound );
       
  3053     
       
  3054     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  3055         {
       
  3056         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  3057         if ( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == aCmId ||
       
  3058              (item->iDNRecord->iEmbeddedSNAP == aCmId && aCmId != 0) )
       
  3059             {
       
  3060             found = i;
       
  3061             break;
       
  3062             }        
       
  3063         }
       
  3064         
       
  3065     return found;
       
  3066     }        
       
  3067 
       
  3068 // -----------------------------------------------------------------------------
       
  3069 // CCmDestinationImpl::IconIdL
       
  3070 // -----------------------------------------------------------------------------
       
  3071 CGulIcon* CCmDestinationImpl::IconIdL( CCmManagerImpl& aCmMgr,
       
  3072                                        TMDBElementId aId )
       
  3073     {
       
  3074     CGulIcon* retVal = NULL;
       
  3075     CCDSNAPMetadataRecord* metaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  3076                                                         aCmMgr.IconTableId() );
       
  3077     CleanupStack::PushL( metaDataRec );
       
  3078     metaDataRec->iSNAP = aId;
       
  3079                 
       
  3080     if ( metaDataRec->FindL( aCmMgr.Session() ) )
       
  3081         // Not found -> fill in with default values
       
  3082         {
       
  3083         retVal = IconL( metaDataRec->iIcon );
       
  3084         }
       
  3085     else
       
  3086         {
       
  3087         User::Leave( KErrNotFound );
       
  3088         }
       
  3089         
       
  3090     CleanupStack::PopAndDestroy( metaDataRec );
       
  3091     
       
  3092     return retVal;
       
  3093     }
       
  3094 
       
  3095 // -----------------------------------------------------------------------------
       
  3096 // CCmDestinationImpl::ProtectionLevelL
       
  3097 // -----------------------------------------------------------------------------
       
  3098 TProtectionLevel CCmDestinationImpl::ProtectionLevelL( CCmManagerImpl& aCmMgr, 
       
  3099                                                        TMDBElementId aId ) 
       
  3100     {
       
  3101     TProtectionLevel retVal( EProtLevel0 );
       
  3102     CCDSNAPMetadataRecord* metaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  3103                                                         aCmMgr.IconTableId() );
       
  3104     CleanupStack::PushL( metaDataRec );
       
  3105     metaDataRec->iSNAP = aId;
       
  3106                 
       
  3107     if ( metaDataRec->FindL( aCmMgr.Session() ) )
       
  3108         // Not found -> fill in with default values
       
  3109         {
       
  3110         retVal = ProtectionLevel( metaDataRec );
       
  3111         }
       
  3112     else
       
  3113         {
       
  3114         User::Leave( KErrNotFound );
       
  3115         }
       
  3116         
       
  3117     CleanupStack::PopAndDestroy( metaDataRec );
       
  3118     return retVal;
       
  3119     }
       
  3120 
       
  3121 // -----------------------------------------------------------------------------
       
  3122 // CCmDestinationImpl::ProtectionLevel
       
  3123 // -----------------------------------------------------------------------------
       
  3124 TProtectionLevel CCmDestinationImpl::ProtectionLevel( 
       
  3125                                            CCDSNAPMetadataRecord* aMetaDataRec )
       
  3126     {
       
  3127     TInt protection = TUint32(aMetaDataRec->iMetadata) & 
       
  3128                       KSnapMetadataProtecionLevelMask;
       
  3129     return TProtectionLevel(protection >> 28);
       
  3130     }
       
  3131 
       
  3132 // -----------------------------------------------------------------------------
       
  3133 // CCmDestinationImpl::ProtectionLevelL
       
  3134 // -----------------------------------------------------------------------------
       
  3135 CGulIcon* CCmDestinationImpl::IconL( TInt aIconIndex )
       
  3136     {
       
  3137     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  3138            
       
  3139     TParse mbmFile;
       
  3140     User::LeaveIfError( mbmFile.Set( KManagerIconFilename, 
       
  3141                                      &KDC_BITMAP_DIR, 
       
  3142                                      NULL ) );
       
  3143                                      
       
  3144     TAknsItemID aknItemID;
       
  3145     aknItemID.Set( KDestinationIconConvTable[aIconIndex][0],
       
  3146                    KDestinationIconConvTable[aIconIndex][1] );
       
  3147            
       
  3148     CGulIcon* icon = AknsUtils::CreateGulIconL( 
       
  3149                             skinInstance, 
       
  3150                             aknItemID,
       
  3151                             mbmFile.FullName(), 
       
  3152                             KDestinationIconConvTable[aIconIndex][2], 
       
  3153                             KDestinationIconConvTable[aIconIndex][3] );
       
  3154                             
       
  3155     return icon;
       
  3156     }
       
  3157     
       
  3158 // -----------------------------------------------------------------------------
       
  3159 // CCmDestinationImpl::RemoveFromPool
       
  3160 // -----------------------------------------------------------------------------
       
  3161 EXPORT_C void CCmDestinationImpl::RemoveFromPool()
       
  3162     {
       
  3163     iCmMgr.RemoveDestFromPool(this);            
       
  3164     }
       
  3165     
       
  3166 // -----------------------------------------------------------------------------
       
  3167 // CCmDestinationImpl::IncrementRefCounter
       
  3168 // -----------------------------------------------------------------------------
       
  3169 void CCmDestinationImpl::IncrementRefCounter()
       
  3170     {
       
  3171     iData->IncrementRefCounter();
       
  3172     }
       
  3173 // -----------------------------------------------------------------------------
       
  3174 // CCmDestinationImpl::DecrementRefCounter
       
  3175 // -----------------------------------------------------------------------------
       
  3176 void CCmDestinationImpl::DecrementRefCounter()
       
  3177     {
       
  3178     iData->DecrementRefCounter();
       
  3179     }
       
  3180 // -----------------------------------------------------------------------------
       
  3181 // CCmDestinationData::IncrementRefCounter
       
  3182 // -----------------------------------------------------------------------------
       
  3183 void CCmDestinationData::IncrementRefCounter()
       
  3184     {
       
  3185     iRefCounter++;
       
  3186     }
       
  3187 // -----------------------------------------------------------------------------
       
  3188 // CCmDestinationData::DecrementRefCounter
       
  3189 // -----------------------------------------------------------------------------
       
  3190 void CCmDestinationData::DecrementRefCounter()
       
  3191     {
       
  3192     iRefCounter--;
       
  3193     }
       
  3194 
       
  3195 // -----------------------------------------------------------------------------
       
  3196 // CCmDestinationData::GetRefCounter
       
  3197 // -----------------------------------------------------------------------------
       
  3198 TInt CCmDestinationData::GetRefCounter()
       
  3199     {
       
  3200     return iRefCounter;
       
  3201     }
       
  3202 
       
  3203 // -----------------------------------------------------------------------------
       
  3204 // CCmDestinationImpl::GetRefCounter
       
  3205 // -----------------------------------------------------------------------------
       
  3206 TInt CCmDestinationImpl::GetRefCounter()
       
  3207     {
       
  3208     return iData->iRefCounter;
       
  3209     }
       
  3210 
       
  3211 // -----------------------------------------------------------------------------
       
  3212 // CCmDestinationImpl::GetData
       
  3213 // -----------------------------------------------------------------------------
       
  3214 CCmDestinationData* CCmDestinationImpl::GetData()
       
  3215     {
       
  3216     return iData;
       
  3217     }
       
  3218 // -----------------------------------------------------------------------------
       
  3219 // CCmDestinationImpl::SetData
       
  3220 // -----------------------------------------------------------------------------
       
  3221 void CCmDestinationImpl::SetData(CCmDestinationData* aData)
       
  3222     {
       
  3223     iData = aData;
       
  3224     }
       
  3225 
       
  3226 // -----------------------------------------------------------------------------
       
  3227 // CCmDestinationData::IdIsValid
       
  3228 // -----------------------------------------------------------------------------
       
  3229 TBool CCmDestinationData::IdIsValid()
       
  3230     {
       
  3231     return iIdIsValid;
       
  3232     }
       
  3233 
       
  3234 // -----------------------------------------------------------------------------
       
  3235 // CCmDestinationImpl::IdIsValid
       
  3236 // -----------------------------------------------------------------------------
       
  3237 TBool CCmDestinationImpl::IdIsValid()
       
  3238     {
       
  3239     return iData->iIdIsValid;
       
  3240     }
       
  3241 
       
  3242 // -----------------------------------------------------------------------------
       
  3243 // CCmDestinationImpl::Cmmgr
       
  3244 // -----------------------------------------------------------------------------
       
  3245 CCmManagerImpl* CCmDestinationData::Cmmgr()
       
  3246     {
       
  3247     return &iCmMgr;    
       
  3248     }
       
  3249 
       
  3250 // -----------------------------------------------------------------------------
       
  3251 // CCmDestinationImpl::Cmmgr
       
  3252 // -----------------------------------------------------------------------------
       
  3253 CCmManagerImpl* CCmDestinationImpl::Cmmgr()
       
  3254     {
       
  3255     return &iCmMgr;    
       
  3256     }
       
  3257 
       
  3258 // -----------------------------------------------------------------------------
       
  3259 // CCmDestinationImpl::CheckIfLocalisedDestExistL
       
  3260 //
       
  3261 // There can be only one SNAP with a certain localised metadata field set.
       
  3262 // -----------------------------------------------------------------------------
       
  3263 void CCmDestinationImpl::CheckIfLocalisedDestExistL( TUint32 aValue )
       
  3264     {
       
  3265     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfLocalisedDestExistL" );
       
  3266 
       
  3267     OpenTransactionLC();
       
  3268 
       
  3269     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3270                 new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( iCmMgr.IconTableId() );
       
  3271     CleanupStack::PushL( metaSet );
       
  3272 
       
  3273     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3274 
       
  3275     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3276         {
       
  3277         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3278                                      KCDTIdSNAPMetadataMetadata );
       
  3279 
       
  3280         if ( meta & ESnapMetadataDestinationIsLocalised )
       
  3281             {
       
  3282             TInt locval = (meta & ESnapMetadataDestinationIsLocalised) >> 4;
       
  3283             if ( aValue == locval )
       
  3284                 {
       
  3285                 if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], KCDTIdSNAPMetadataSNAP ) )
       
  3286                     {
       
  3287                     User::Leave( KErrAlreadyExists );
       
  3288                     }
       
  3289                 }
       
  3290             if ( aValue ==  ELocalisedDestInternet )
       
  3291                 { // internet might also be set the 'old way', check it!
       
  3292                 if( meta & ESnapMetadataInternet )
       
  3293                     {
       
  3294                     if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], KCDTIdSNAPMetadataSNAP ) )
       
  3295                         {
       
  3296                         User::Leave( KErrAlreadyExists );
       
  3297                         }
       
  3298                     }                
       
  3299                 }
       
  3300             }            
       
  3301         }
       
  3302 
       
  3303     CleanupStack::PopAndDestroy( metaSet );
       
  3304 
       
  3305     RollbackTransaction();
       
  3306     }
       
  3307 
       
  3308 // -----------------------------------------------------------------------------
       
  3309 // CCmDestinationImpl::CheckIfPurposeExistL
       
  3310 //
       
  3311 // There can be only one SNAP with a certain purpose metadata field set.
       
  3312 // -----------------------------------------------------------------------------
       
  3313 void CCmDestinationImpl::CheckIfPurposeExistL( TUint32 aValue )
       
  3314     {
       
  3315     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfPurposeExistL" );
       
  3316 
       
  3317     OpenTransactionLC();
       
  3318 
       
  3319     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3320                 new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( iCmMgr.IconTableId() );
       
  3321     CleanupStack::PushL( metaSet );
       
  3322 
       
  3323     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3324 
       
  3325     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3326         {
       
  3327         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3328                                      KCDTIdSNAPMetadataMetadata );
       
  3329 
       
  3330         if ( meta & ESnapMetadataPurpose )
       
  3331             {
       
  3332             TInt purVal = ( meta & ESnapMetadataPurpose ) >> 8;
       
  3333             if ( aValue == purVal )
       
  3334                 {
       
  3335                 if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3336                                         KCDTIdSNAPMetadataSNAP ) )
       
  3337                     {
       
  3338                     User::Leave( KErrAlreadyExists );
       
  3339                     }
       
  3340                 }
       
  3341             }            
       
  3342         }
       
  3343 
       
  3344     CleanupStack::PopAndDestroy( metaSet );
       
  3345 
       
  3346     RollbackTransaction();
       
  3347     }
       
  3348 
       
  3349 // -----------------------------------------------------------------------------
       
  3350 // CCmDestinationImpl::InitializeDestAPRecordL
       
  3351 //
       
  3352 // 
       
  3353 // -----------------------------------------------------------------------------
       
  3354 void CCmDestinationImpl::InitializeDestAPRecordL()
       
  3355     {
       
  3356     LOGGER_ENTERFN( "CCmDestinationImpl::InitializeDestAPRecordL" );
       
  3357 
       
  3358     SetDefaultTierManagerL();
       
  3359     SetDefaultMCprL();
       
  3360     SetDefaultCprL();
       
  3361     SetDefaultSCprL();
       
  3362     SetDefaultProtocolL();
       
  3363     iData->iDestAPRecord->iCustomSelectionPolicy = 0;
       
  3364     }
       
  3365 
       
  3366 // -----------------------------------------------------------------------------
       
  3367 // CCmDestinationImpl::SetDefaultTierManagerL
       
  3368 //
       
  3369 // 
       
  3370 // -----------------------------------------------------------------------------
       
  3371 void CCmDestinationImpl::SetDefaultTierManagerL()
       
  3372     {
       
  3373     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultTierManagerL" );
       
  3374 
       
  3375     CCDTierRecord* tierRec = static_cast<CCDTierRecord *>
       
  3376                                ( CCDRecordBase::RecordFactoryL( KCDTIdTierRecord ) );
       
  3377     CleanupStack::PushL( tierRec );
       
  3378 
       
  3379     tierRec->iRecordTag = KDefaultTierManagerTagId;
       
  3380 
       
  3381     if ( tierRec->FindL( Session() ) )
       
  3382         {
       
  3383         iData->iDestAPRecord->iTier = tierRec->ElementId();
       
  3384         }
       
  3385     else
       
  3386         {
       
  3387         User::Leave( KErrNotFound );
       
  3388         }
       
  3389 
       
  3390     CleanupStack::PopAndDestroy();
       
  3391     }
       
  3392 
       
  3393 // -----------------------------------------------------------------------------
       
  3394 // CCmDestinationImpl::SetDefaultMCprL
       
  3395 //
       
  3396 // 
       
  3397 // -----------------------------------------------------------------------------
       
  3398 void CCmDestinationImpl::SetDefaultMCprL()
       
  3399     {
       
  3400     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultMCprL" );
       
  3401 
       
  3402     CCDMCprRecord* mcprRec = static_cast<CCDMCprRecord *>
       
  3403                              ( CCDRecordBase::RecordFactoryL( KCDTIdMCprRecord ) );
       
  3404     CleanupStack::PushL( mcprRec );
       
  3405 
       
  3406     mcprRec->SetRecordId( 1 );
       
  3407 
       
  3408     mcprRec->LoadL( Session() );
       
  3409 	
       
  3410 	iData->iDestAPRecord->iMCpr = mcprRec->ElementId();
       
  3411 
       
  3412     CleanupStack::PopAndDestroy();
       
  3413     }
       
  3414 
       
  3415 // -----------------------------------------------------------------------------
       
  3416 // CCmDestinationImpl::SetDefaultCprL
       
  3417 //
       
  3418 // 
       
  3419 // -----------------------------------------------------------------------------
       
  3420 void CCmDestinationImpl::SetDefaultCprL()
       
  3421     {
       
  3422     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultCprL" );
       
  3423 
       
  3424     CCDCprRecord* cprRec = static_cast<CCDCprRecord *>
       
  3425                              ( CCDRecordBase::RecordFactoryL( KCDTIdCprRecord ) );
       
  3426     CleanupStack::PushL( cprRec );
       
  3427 
       
  3428     cprRec->SetRecordId( 1 );
       
  3429 
       
  3430     cprRec->LoadL( Session() );
       
  3431 	iData->iDestAPRecord->iCpr = cprRec->ElementId();
       
  3432 
       
  3433     CleanupStack::PopAndDestroy();
       
  3434     }
       
  3435 
       
  3436 // -----------------------------------------------------------------------------
       
  3437 // CCmDestinationImpl::SetDefaultSCprL
       
  3438 //
       
  3439 // 
       
  3440 // -----------------------------------------------------------------------------
       
  3441 void CCmDestinationImpl::SetDefaultSCprL()
       
  3442     {
       
  3443     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultSCprL" );
       
  3444 
       
  3445     CCDSCprRecord* scprRec = static_cast<CCDSCprRecord *>
       
  3446                              ( CCDRecordBase::RecordFactoryL( KCDTIdSCprRecord ) );
       
  3447     CleanupStack::PushL( scprRec );
       
  3448 
       
  3449     scprRec->SetRecordId( 1 );
       
  3450 
       
  3451     scprRec->LoadL( Session() );
       
  3452 	iData->iDestAPRecord->iSCpr = scprRec->ElementId();
       
  3453 
       
  3454     CleanupStack::PopAndDestroy();
       
  3455     }
       
  3456 
       
  3457 // -----------------------------------------------------------------------------
       
  3458 // CCmDestinationImpl::SetDefaultProtocolL
       
  3459 //
       
  3460 // 
       
  3461 // -----------------------------------------------------------------------------
       
  3462 void CCmDestinationImpl::SetDefaultProtocolL()
       
  3463     {
       
  3464     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultProtocolL" );
       
  3465 
       
  3466     CCDProtocolRecord* protocolRec = static_cast<CCDProtocolRecord *>
       
  3467                              ( CCDRecordBase::RecordFactoryL( KCDTIdProtocolRecord ) );
       
  3468     CleanupStack::PushL( protocolRec );
       
  3469 
       
  3470     protocolRec->SetRecordId( 1 );
       
  3471 
       
  3472     protocolRec->LoadL( Session() );
       
  3473 	iData->iDestAPRecord->iProtocol = protocolRec->ElementId();
       
  3474 
       
  3475     CleanupStack::PopAndDestroy();
       
  3476     }
       
  3477 
       
  3478 // -----------------------------------------------------------------------------
       
  3479 // CCmDestinationImpl::CheckIfCMExists
       
  3480 //
       
  3481 // 
       
  3482 // -----------------------------------------------------------------------------
       
  3483 TBool CCmDestinationImpl::CheckIfCMExistsL( CCmPluginBase& aConnectionMethod )
       
  3484     {
       
  3485     TRAPD( err, (void)FindConnectionMethodL( aConnectionMethod ) );
       
  3486     if ( err )
       
  3487         {
       
  3488         if ( err == KErrNotFound )
       
  3489             {
       
  3490             return EFalse;
       
  3491             }
       
  3492         else
       
  3493             {
       
  3494             User::Leave( err );
       
  3495             }
       
  3496         }
       
  3497 
       
  3498     return ETrue;
       
  3499     }