cmmanager/cmmgr/Framework/Src/cmdestinationimpl.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     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     CleanupStack::PushL( item->iPlugin ); // 3         
       
  1070     // create the new record
       
  1071     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
  1072 
       
  1073     CleanupStack::PushL( item->iDNRecord ); // 4
       
  1074     
       
  1075     // if the destination is protection level 1, the connection method must be protected
       
  1076     if ( ProtectionLevel() == EProtLevel1 )
       
  1077         {
       
  1078         item->iPlugin->SetBoolAttributeL( ECmProtected, ETrue );
       
  1079         }
       
  1080     
       
  1081     TInt index = AddToArrayL( item );
       
  1082     index = index - KCmInitIndex; //the array contains one initial item, so subtract KCmInitIndex from the index to get cm index!
       
  1083     
       
  1084     CleanupStack::Pop( 4, item ); // item, connMethod, iDNRecord, iPlugin
       
  1085     
       
  1086     return index;
       
  1087     }
       
  1088 
       
  1089 // -----------------------------------------------------------------------------
       
  1090 // CCmDestinationImpl::AddEmbeddedDestinationL()
       
  1091 // -----------------------------------------------------------------------------
       
  1092 //
       
  1093 TInt CCmDestinationImpl::AddEmbeddedDestinationL( 
       
  1094                                              CCmDestinationImpl& aDestination )
       
  1095     {
       
  1096     LOGGER_ENTERFN( "CCmDestinationImpl::AddEmbeddedDestinationL" );
       
  1097     
       
  1098     if( ProtectionLevel() == EProtLevel1 )
       
  1099         {
       
  1100         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1101         }
       
  1102         
       
  1103     //Check to avoid multiple levels of embedding
       
  1104     CheckIfEmbeddedL( Id() );
       
  1105     
       
  1106     //Check to avoid multiple levels of embedding
       
  1107     if ( aDestination.HasEmbeddedL() )
       
  1108         {
       
  1109         User::Leave( KErrNotSupported );
       
  1110         }
       
  1111         
       
  1112     // Only one embedded destination per destination is allowed
       
  1113     if ( HasEmbeddedL() )
       
  1114         {
       
  1115         User::Leave( KErrNotSupported );
       
  1116         }
       
  1117            
       
  1118     CPluginItem* item = new (ELeave) CPluginItem;
       
  1119     CleanupStack::PushL( item ); // 1
       
  1120 
       
  1121     CreateEmbeddedDestinationPluginL( *item, aDestination.Id() );
       
  1122      // create the new record
       
  1123     item->iDNRecord = iCmMgr.SNAPRecordL( 0 );
       
  1124     item->iDNRecord->iPriority = KDataMobilitySelectionPolicyPriorityWildCard;
       
  1125 
       
  1126     CleanupStack::PushL( item->iDNRecord ); // 2    
       
  1127     TInt index = AddToArrayL( item );
       
  1128     index = index - KCmInitIndex; //the array contains one initial item, so subtract KCmInitIndex from the index to get cm index!
       
  1129     
       
  1130     CleanupStack::Pop( 2, item ); // item, iDNRecord
       
  1131     
       
  1132     return index;   
       
  1133     }
       
  1134 
       
  1135 // -----------------------------------------------------------------------------
       
  1136 // CCmDestinationImpl::DeleteConnectionMethodL()
       
  1137 // -----------------------------------------------------------------------------
       
  1138 // 
       
  1139 void CCmDestinationImpl::DeleteConnectionMethodL( 
       
  1140                                         CCmPluginBase& aConnectionMethod )
       
  1141     {
       
  1142     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1143     
       
  1144     if( ProtectionLevel() == EProtLevel1 ||
       
  1145         ProtectionLevel() == EProtLevel3 )
       
  1146         {
       
  1147         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1148         }
       
  1149         
       
  1150     if ( aConnectionMethod.GetBoolAttributeL( ECmConnected ) )
       
  1151         {
       
  1152         User::Leave( KErrInUse );
       
  1153         }
       
  1154         
       
  1155     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1156 
       
  1157     // move this method to the 'to be deleted' array         
       
  1158     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1159     
       
  1160     LoadPluginL( *item );
       
  1161     
       
  1162     if( item->iPlugin->GetBoolAttributeL( ECmIsLinked ) )
       
  1163         {
       
  1164         User::Leave( KErrLocked );
       
  1165         }
       
  1166 
       
  1167     if ( ConnectionMethodCount() == 1 )
       
  1168         {
       
  1169         // Check if this destination is referenced by Virtual CM 
       
  1170         CheckIfReferencedByVirtualCML();
       
  1171         }
       
  1172 
       
  1173     iData->iDeleteCmArray->AppendL( item );
       
  1174     iData->iConnMethodArray->Delete( index );
       
  1175     }
       
  1176     
       
  1177 // -----------------------------------------------------------------------------
       
  1178 // CCmDestinationImpl::RemoveConnectionMethodL()
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // 
       
  1181 void CCmDestinationImpl::RemoveConnectionMethodL( 
       
  1182                                      const CCmPluginBase& aConnectionMethod )
       
  1183     {
       
  1184     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1185 
       
  1186     if( ProtectionLevel() == EProtLevel1 ||
       
  1187         ProtectionLevel() == EProtLevel3 )
       
  1188         {
       
  1189         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1190         }
       
  1191     
       
  1192     if ( ConnectionMethodCount() == 1 )
       
  1193         {
       
  1194         // Check if this destination is referenced by Virtual CM 
       
  1195         CheckIfReferencedByVirtualCML();
       
  1196         }
       
  1197         
       
  1198     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1199 
       
  1200     // move this method to the 'to be deleted' array, but
       
  1201     // set remove only from, not to delete it on update.
       
  1202     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1203     
       
  1204     item->iFlags |= CPluginItem::ERemoveCm;
       
  1205    
       
  1206     iData->iDeleteCmArray->AppendL( item );
       
  1207     iData->iConnMethodArray->Delete( index );
       
  1208     }
       
  1209 
       
  1210 // -----------------------------------------------------------------------------
       
  1211 // CCmDestinationImpl::CheckIfReferencedByVirtualCML()
       
  1212 // -----------------------------------------------------------------------------
       
  1213 // 
       
  1214 void CCmDestinationImpl::CheckIfReferencedByVirtualCML()
       
  1215     {
       
  1216     // for each IAP in CM manager
       
  1217     //   1. check if it is virtual
       
  1218     //      if not => goto 1.
       
  1219     //      if yes:
       
  1220     //      2. check if it links to the destination of this CM
       
  1221     //         if yes => carryOn = EFalse, ERROR
       
  1222     //         if not: carryOn = ETrue
       
  1223     CommsDat::CMDBRecordSet<CommsDat::CCDIAPRecord>* iaps = iCmMgr.AllIapsL();
       
  1224     CleanupStack::PushL( iaps );
       
  1225 
       
  1226     TBool carryOn = ETrue;
       
  1227     TUint32 destId = Id();
       
  1228 
       
  1229     // for each IAP in CM manager
       
  1230     for ( TInt i = KCmInitIndex; carryOn && i < iaps->iRecords.Count(); ++i )
       
  1231         {
       
  1232         CommsDat::CCDIAPRecord* rec = (*iaps)[i];
       
  1233         TUint32 bearerType = 0;
       
  1234 
       
  1235         TRAP_IGNORE( bearerType = iCmMgr.BearerTypeFromIapRecordL( rec ) );
       
  1236         if ( !bearerType )
       
  1237             {
       
  1238             continue;
       
  1239             }
       
  1240 
       
  1241         // check if it is virtual
       
  1242         if ( iCmMgr.GetBearerInfoBoolL( bearerType, ECmVirtual ) )
       
  1243             {
       
  1244             // check if it links to the current destination
       
  1245             CCmPluginBase* plugin = NULL;            
       
  1246             TRAP_IGNORE( plugin = iCmMgr.GetConnectionMethodL( rec->RecordId() ) );
       
  1247 
       
  1248             if ( !plugin )
       
  1249                 {
       
  1250                 continue;
       
  1251                 }
       
  1252 
       
  1253             if ( plugin->IsLinkedToSnap( destId ) )
       
  1254                 {
       
  1255                 // the CM links to this destination, deletion not allowed
       
  1256                 carryOn = EFalse;
       
  1257                 }
       
  1258 
       
  1259             delete plugin;
       
  1260             }
       
  1261         }
       
  1262 
       
  1263     CleanupStack::PopAndDestroy( iaps );
       
  1264 
       
  1265     if ( !carryOn )
       
  1266         {
       
  1267         User::Leave( KErrLocked );
       
  1268         }
       
  1269     }
       
  1270 // -----------------------------------------------------------------------------
       
  1271 // CCmDestinationImpl::RemoveConnectionMethodL()
       
  1272 // -----------------------------------------------------------------------------
       
  1273 // 
       
  1274 void CCmDestinationImpl::RemoveConnectionMethodL( 
       
  1275                                      const CCmPluginBaseEng& aConnectionMethod )
       
  1276     {
       
  1277     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteConnectionMethodL" );
       
  1278 
       
  1279     if( ProtectionLevel() == EProtLevel1 ||
       
  1280         ProtectionLevel() == EProtLevel3 )
       
  1281         {
       
  1282         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1283         }
       
  1284         
       
  1285     TInt index = FindConnectionMethodL( aConnectionMethod );
       
  1286 
       
  1287     // move this method to the 'to be deleted' array, but
       
  1288     // set remove only from, not to delete it on update.
       
  1289     CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  1290     
       
  1291     item->iFlags |= CPluginItem::ERemoveCm;
       
  1292    
       
  1293     iData->iDeleteCmArray->AppendL( item );
       
  1294     iData->iConnMethodArray->Delete( index );
       
  1295     }
       
  1296 
       
  1297 // -----------------------------------------------------------------------------
       
  1298 // CCmDestinationImpl::ConnectionMethodDeletedL()
       
  1299 // -----------------------------------------------------------------------------
       
  1300 // 
       
  1301 void CCmDestinationImpl::ConnectionMethodDeletedL( 
       
  1302                                     const CCmPluginBase& aConnectionMethod )
       
  1303     {
       
  1304     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodDeletedL" );
       
  1305 
       
  1306     TInt found( KErrNotFound );
       
  1307     TUint32 aCmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1308 
       
  1309     found = ConnectionMethodIndex( aCmId );
       
  1310 
       
  1311     if( found != KErrNotFound )
       
  1312         {
       
  1313         CPluginItem* item = (*(iData->iConnMethodArray))[found];
       
  1314         
       
  1315         (*(iData->iConnMethodArray))[found] = NULL;
       
  1316         iData->iConnMethodArray->Delete( found );
       
  1317         iData->iConnMethodArray->Compress();
       
  1318         
       
  1319         // The iPlugin is deleted in plugin interface function
       
  1320         // that called this function.
       
  1321         delete item->iDNRecord;
       
  1322         delete item;
       
  1323         }
       
  1324     }
       
  1325 
       
  1326 // -----------------------------------------------------------------------------
       
  1327 // CCmDestinationImpl::FindConnectionMethodL()
       
  1328 // -----------------------------------------------------------------------------
       
  1329 // 
       
  1330 TInt CCmDestinationImpl::FindConnectionMethodL( 
       
  1331                                      const CCmPluginBase& aConnectionMethod )
       
  1332     {
       
  1333     LOGGER_ENTERFN( "CCmDestinationImpl::FindConnectionMethodL" );
       
  1334 
       
  1335     TInt cmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1336     TBool embeded = aConnectionMethod.GetBoolAttributeL( ECmDestination ) ?
       
  1337                       ETrue :
       
  1338                       EFalse;
       
  1339 
       
  1340     CLOG_WRITE_2( "ID: [%d], embDest: [%d]", 
       
  1341                   cmId, 
       
  1342                   aConnectionMethod.GetBoolAttributeL( ECmDestination ) );
       
  1343     
       
  1344     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1345         {
       
  1346         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1347         if( embeded )
       
  1348             {
       
  1349             if( item->iDNRecord->iEmbeddedSNAP == cmId )
       
  1350                 {
       
  1351                 return i;
       
  1352                 }        
       
  1353             }
       
  1354         else
       
  1355             {
       
  1356             if( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == cmId )
       
  1357                 {
       
  1358                 return i;
       
  1359                 }
       
  1360             }
       
  1361         }
       
  1362         
       
  1363     CLOG_WRITE( "Not found" );
       
  1364     User::Leave( KErrNotFound );
       
  1365     
       
  1366     // dummy return value. never used.
       
  1367     return -1;
       
  1368     }
       
  1369 
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // CCmDestinationImpl::FindConnectionMethodL()
       
  1372 // -----------------------------------------------------------------------------
       
  1373 // 
       
  1374 TInt CCmDestinationImpl::FindConnectionMethodL( 
       
  1375                                      const CCmPluginBaseEng& aConnectionMethod )
       
  1376     {
       
  1377     LOGGER_ENTERFN( "CCmDestinationImpl::FindConnectionMethodL" );
       
  1378 
       
  1379     TInt cmId = aConnectionMethod.GetIntAttributeL( ECmId );
       
  1380     TBool embeded = aConnectionMethod.GetBoolAttributeL( ECmDestination ) ?
       
  1381                       ETrue :
       
  1382                       EFalse;
       
  1383 
       
  1384     CLOG_WRITE_2( "ID: [%d], embDest: [%d]", 
       
  1385                   cmId, 
       
  1386                   aConnectionMethod.GetBoolAttributeL( ECmDestination ) );
       
  1387     
       
  1388     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1389         {
       
  1390         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1391         if( embeded )
       
  1392             {
       
  1393             if( item->iDNRecord->iEmbeddedSNAP == cmId )
       
  1394                 {
       
  1395                 return i;
       
  1396                 }        
       
  1397             }
       
  1398         else
       
  1399             {
       
  1400             if( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == cmId )
       
  1401                 {
       
  1402                 return i;
       
  1403                 }
       
  1404             }
       
  1405         }
       
  1406         
       
  1407     CLOG_WRITE( "Not found" );
       
  1408     User::Leave( KErrNotFound );
       
  1409     
       
  1410     // dummy return value. never used.
       
  1411     return -1;
       
  1412     }
       
  1413 
       
  1414 // -----------------------------------------------------------------------------
       
  1415 // CCmDestinationImpl::ModifyPriorityL()
       
  1416 // -----------------------------------------------------------------------------
       
  1417 //      
       
  1418 void CCmDestinationImpl::ModifyPriorityL( CCmPluginBase& aCCMItem, 
       
  1419                                           TUint aIndex )
       
  1420     {
       
  1421     LOGGER_ENTERFN( "CCmDestinationImpl::ModifyPriorityL" );
       
  1422     
       
  1423     if (aCCMItem.GetBoolAttributeL(ECmDestination) ||
       
  1424         (aCCMItem.GetBoolAttributeL(ECmVirtual) &&
       
  1425          aCCMItem.GetIntAttributeL(ECmNextLayerSNAPId)))
       
  1426         {
       
  1427         // Priority can not be changed for this cm
       
  1428         return;
       
  1429         }
       
  1430         
       
  1431     if( ProtectionLevel() == EProtLevel1 ||
       
  1432         ProtectionLevel() == EProtLevel3 )
       
  1433         {
       
  1434         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1435         }
       
  1436         
       
  1437     TBool found( EFalse );
       
  1438     TInt cm2 = aCCMItem.GetIntAttributeL( ECmId );
       
  1439     
       
  1440     if ( aIndex >= ( iData->iConnMethodArray->Count() - KCmInitIndex ) )
       
  1441         {
       
  1442         User::Leave( KErrArgument );
       
  1443         }
       
  1444     
       
  1445     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1446         {
       
  1447         LoadPluginL( *(*(iData->iConnMethodArray))[i] );
       
  1448             
       
  1449         // Compare the IAP IDs
       
  1450         TInt cm1 = (*(iData->iConnMethodArray))[i]->iPlugin->GetIntAttributeL( ECmId );        
       
  1451         
       
  1452         if ( cm1 == cm2 )
       
  1453             {
       
  1454             CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1455             
       
  1456             TInt pri = (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority;
       
  1457             if ( pri == KDataMobilitySelectionPolicyPriorityWildCard )
       
  1458                 {
       
  1459                 TUint32 prio = 0;
       
  1460                 TUint32 bearerType = 0;
       
  1461                 TUint32 extLevel = 0;
       
  1462                 
       
  1463                 TBool isVirtual = PrioDataL( item, prio, bearerType, extLevel );
       
  1464                 if (prio != KDataMobilitySelectionPolicyPriorityWildCard)
       
  1465                     {
       
  1466                     // The priority will be changed later when UpdateL is called
       
  1467                     // So, the priority will simply be chnaged from
       
  1468                     // KDataMobilitySelectionPolicyPriorityWildCard to value i
       
  1469                     (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority = i; 
       
  1470                     }
       
  1471                 }
       
  1472             
       
  1473             (*(iData->iConnMethodArray))[i] = NULL;
       
  1474             
       
  1475             // remove from array
       
  1476             iData->iConnMethodArray->Delete( i );
       
  1477             iData->iConnMethodArray->Compress();
       
  1478             iData->iConnMethodArray->InsertL( KCmInitIndex + aIndex, item );
       
  1479             
       
  1480             found = ETrue;           
       
  1481             break;
       
  1482             }
       
  1483         }
       
  1484         
       
  1485     if ( !found )
       
  1486         {
       
  1487         User::Leave( KErrArgument );
       
  1488         }
       
  1489         
       
  1490     }
       
  1491     
       
  1492 // -----------------------------------------------------------------------------
       
  1493 // CCmDestinationImpl::PriorityL()
       
  1494 // -----------------------------------------------------------------------------
       
  1495 //          
       
  1496 TUint CCmDestinationImpl::PriorityL( CCmPluginBaseEng& aCCMItem )
       
  1497     {
       
  1498     LOGGER_ENTERFN( "CCmDestinationImpl::PriorityL" );
       
  1499 
       
  1500     TInt index = FindConnectionMethodL( aCCMItem );
       
  1501     
       
  1502     return (*(iData->iConnMethodArray))[index]->iDNRecord->iPriority;
       
  1503     }
       
  1504     
       
  1505 // -----------------------------------------------------------------------------
       
  1506 // CCmDestinationImpl::PriorityL()
       
  1507 // -----------------------------------------------------------------------------
       
  1508 //          
       
  1509 TUint CCmDestinationImpl::PriorityL( CCmPluginBase& aCCMItem )
       
  1510     {
       
  1511     LOGGER_ENTERFN( "CCmDestinationImpl::PriorityL" );
       
  1512 
       
  1513     TInt index = FindConnectionMethodL( aCCMItem );
       
  1514     
       
  1515     return (*(iData->iConnMethodArray))[index]->iDNRecord->iPriority;
       
  1516     }
       
  1517     
       
  1518 // -----------------------------------------------------------------------------
       
  1519 // CCmDestinationImpl::UpdateL()
       
  1520 // -----------------------------------------------------------------------------
       
  1521 //          
       
  1522 EXPORT_C void CCmDestinationImpl::UpdateL()
       
  1523     {
       
  1524     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateL" );
       
  1525 
       
  1526     // Connection methods and destination records are updated in 
       
  1527     // one transaction.
       
  1528     OpenTransactionLC();
       
  1529     
       
  1530     DeleteConnectionMethodsL();
       
  1531 
       
  1532     // Update protection level of connection methods if it's changed in 
       
  1533     // the destination
       
  1534     UpdateProtectionL();
       
  1535     // Updates all modified connection methods.
       
  1536     UpdateConnectionMethodsL();
       
  1537     UpdateNetworkRecordL();
       
  1538     UpdateDestAPRecordL();
       
  1539     UpdateSNAPTableL();
       
  1540     UpdateSNAPMetadataTableL();
       
  1541         
       
  1542     CommitTransactionL( KErrNone );
       
  1543     
       
  1544     // set the last updated protection level of the destination
       
  1545     iData->iLastProtectionLevel = ProtectionLevel();
       
  1546 
       
  1547     // Clear the modified flag
       
  1548     iData->iProtectionChanged = EFalse;
       
  1549 
       
  1550     // empty the array, but do not delete it
       
  1551     iData->ResetAndDestroyArray( iData->iDeleteCmArray, EFalse );
       
  1552         
       
  1553     iCmMgr.DestinationUpdated(this);
       
  1554     iData->iIdIsValid = ETrue;
       
  1555     }
       
  1556 
       
  1557 // -----------------------------------------------------------------------------
       
  1558 // CCmDestinationImpl::DeleteLD()
       
  1559 // -----------------------------------------------------------------------------
       
  1560 //
       
  1561 EXPORT_C void CCmDestinationImpl::DeleteLD()
       
  1562     {
       
  1563     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteLD" );
       
  1564 
       
  1565     if( ProtectionLevel() == EProtLevel1 )
       
  1566         {
       
  1567         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  1568         }
       
  1569         
       
  1570     TInt count = iData->iConnMethodArray->Count();
       
  1571 
       
  1572     if( IsConnectedL() )
       
  1573         {
       
  1574         User::Leave( KErrInUse );
       
  1575         }
       
  1576 
       
  1577     // Check first that any of the CMs in this Destination is not
       
  1578     // referenced by Virtual CM
       
  1579     TInt i( 0 );
       
  1580     
       
  1581     for( i = KCmInitIndex; i < count; ++i )
       
  1582         {
       
  1583         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1584         
       
  1585         LoadPluginL( *item );
       
  1586             
       
  1587         if( item->iPlugin->GetBoolAttributeL( ECmIsLinked ) )
       
  1588             {
       
  1589             User::Leave( KErrLocked );
       
  1590             }
       
  1591         }
       
  1592     // Check that this Destination is not referenced by any Virtual CM
       
  1593     if ( ConnectionMethodCount() > 0 )
       
  1594         {
       
  1595         CheckIfReferencedByVirtualCML();
       
  1596         }
       
  1597 
       
  1598     OpenTransactionLC();
       
  1599     TRAPD( err, DeleteRelatedRecordsL( count ) );
       
  1600     if ( err )
       
  1601         {
       
  1602         RollbackTransaction();
       
  1603         User::Leave( err );
       
  1604         }
       
  1605     CommitTransactionL(KErrNone);
       
  1606 
       
  1607     delete this;
       
  1608     }
       
  1609 
       
  1610 // -----------------------------------------------------------------------------
       
  1611 // CCmDestinationImpl::DeleteRelatedRecordsL()
       
  1612 // -----------------------------------------------------------------------------
       
  1613 //
       
  1614 void CCmDestinationImpl::DeleteRelatedRecordsL( TInt aCount )
       
  1615     {
       
  1616     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteRelatedRecordsL" );
       
  1617 
       
  1618     CleanUpEmbeddedL( Id() );
       
  1619 
       
  1620     TCmDefConnValue deletedItem;
       
  1621     deletedItem.iType = ECmDefConnDestination;
       
  1622     deletedItem.iId = Id();
       
  1623     iCmMgr.HandleDefConnDeletedL( deletedItem );       
       
  1624     CMDBRecordBase* dnIapRecord;
       
  1625     TInt i;
       
  1626     
       
  1627     // Here we don't use KCmInitIndex becouse initial entry should be deleted
       
  1628     // too!
       
  1629     for ( i = 0; i < aCount; i++ )
       
  1630         {
       
  1631         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1632         
       
  1633         // Delete the plugin
       
  1634         if ( i >= KCmInitIndex )
       
  1635             {
       
  1636             if ( !item->iPlugin->Plugin()->IdIsValid() )
       
  1637                 {
       
  1638                 // Delete incomplete plugin 
       
  1639                 delete item->iPlugin;
       
  1640                 item->iPlugin = NULL;
       
  1641                 }
       
  1642             else
       
  1643                 {
       
  1644                 TRAPD( err, item->iPlugin->DeleteL( EFalse ) );
       
  1645                 
       
  1646                 if( err != KErrLocked &&
       
  1647                     err != KErrNotReady )
       
  1648                     {
       
  1649                     User::LeaveIfError( err );
       
  1650                     }
       
  1651                     
       
  1652                 delete item->iPlugin;
       
  1653                 item->iPlugin = NULL;
       
  1654                 }
       
  1655             }  
       
  1656         
       
  1657         // Delete the DN-IAP record
       
  1658         dnIapRecord = item->iDNRecord;
       
  1659         
       
  1660         if ( dnIapRecord->RecordId() )
       
  1661             // If we have record Id, this record is already in CommsDat
       
  1662             {
       
  1663             dnIapRecord->DeleteL( Session() );
       
  1664             }   
       
  1665         delete item->iDNRecord;
       
  1666         item->iDNRecord = NULL;
       
  1667         }
       
  1668 
       
  1669     iData->iDestAPRecord->DeleteL( Session() ); // deletes a record
       
  1670     iData->iNetworkRecord->DeleteL( Session() ); // deletes a record
       
  1671     
       
  1672     // Delete SNAPMetadata table    
       
  1673     CMDBRecordSet<CCDSNAPMetadataRecord>*  ptrRecordSet = 
       
  1674                     new (ELeave) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  1675                                                  iCmMgr.IconTableId() );
       
  1676     CleanupStack::PushL( ptrRecordSet );
       
  1677 
       
  1678     // Prime record
       
  1679     CCDSNAPMetadataRecord* record = 
       
  1680         new (ELeave) CCDSNAPMetadataRecord( iCmMgr.IconTableId() );
       
  1681     CleanupStack::PushL( record );
       
  1682     record->iSNAP = Id();
       
  1683     ptrRecordSet->iRecords.AppendL( record );
       
  1684 
       
  1685     CleanupStack::Pop( record );
       
  1686     record = NULL;
       
  1687                 
       
  1688     if ( ptrRecordSet->FindL( Session() ) )
       
  1689         {
       
  1690         (*ptrRecordSet)[0]->DeleteL( Session() );          
       
  1691         }
       
  1692         
       
  1693     ptrRecordSet->iRecords.ResetAndDestroy();
       
  1694     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  1695     }
       
  1696 
       
  1697 // -----------------------------------------------------------------------------
       
  1698 // CCmDestinationImpl::CheckIfEmbeddedL()
       
  1699 // -----------------------------------------------------------------------------
       
  1700 //
       
  1701 void CCmDestinationImpl::CheckIfEmbeddedL( TInt aId )
       
  1702     {
       
  1703     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfEmbeddedL" );
       
  1704     
       
  1705     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  1706                     new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  1707                                           iCmMgr.DestinationTableId() );
       
  1708     CleanupStack::PushL( ptrRecordSet );
       
  1709 
       
  1710     // Prime record
       
  1711     CCDSnapRecord* record = iCmMgr.SNAPRecordL( 0 );
       
  1712     CleanupStack::PushL( record );
       
  1713     record->iEmbeddedSNAP = aId;
       
  1714     ptrRecordSet->iRecords.AppendL( record );
       
  1715 
       
  1716     CleanupStack::Pop( record );
       
  1717     record = NULL;
       
  1718         
       
  1719     OpenTransactionLC();    
       
  1720     if( ptrRecordSet->FindL( Session() ) )
       
  1721         // Match found - it's embedded
       
  1722         {
       
  1723         User::Leave( KErrNotSupported );          
       
  1724         }
       
  1725     RollbackTransaction();
       
  1726 
       
  1727     ptrRecordSet->iRecords.ResetAndDestroy();
       
  1728     
       
  1729     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  1730     }
       
  1731 
       
  1732 // -----------------------------------------------------------------------------
       
  1733 // CCmDestinationImpl::HasEmbeddedL
       
  1734 // -----------------------------------------------------------------------------
       
  1735 //
       
  1736 TBool CCmDestinationImpl::HasEmbeddedL()
       
  1737     {
       
  1738     LOGGER_ENTERFN( "CCmDestinationImpl::HasEmbeddedL" );
       
  1739 
       
  1740     return ( EmbeddedL() != NULL )? ETrue : EFalse;
       
  1741     }
       
  1742 
       
  1743 // -----------------------------------------------------------------------------
       
  1744 // CCmDestinationImpl::EmbeddedL
       
  1745 // -----------------------------------------------------------------------------
       
  1746 //
       
  1747 CCmDestinationImpl* CCmDestinationImpl::EmbeddedL()
       
  1748     {
       
  1749     LOGGER_ENTERFN( "CCmDestinationImpl::EmbeddedL" );
       
  1750 
       
  1751     CCmDestinationImpl* retVal = NULL;
       
  1752     // Check if the destination contains embedded destinations
       
  1753     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1754         {
       
  1755         LoadPluginL( *(*(iData->iConnMethodArray))[i] );
       
  1756         // It's an embedded destination ( this is also true for VPN CMs )
       
  1757         retVal = (*(iData->iConnMethodArray))[i]->iPlugin->Destination();
       
  1758         if ( retVal )
       
  1759             {
       
  1760             // as there can be only one
       
  1761             // embedded destination, the first one is enough
       
  1762             break;
       
  1763             }
       
  1764         }
       
  1765     
       
  1766     return retVal;
       
  1767     }
       
  1768  
       
  1769  // -----------------------------------------------------------------------------
       
  1770 // CCmDestinationImpl::CanUseToConnectL
       
  1771 // -----------------------------------------------------------------------------
       
  1772 //
       
  1773 TBool CCmDestinationImpl::CanUseToConnectL()
       
  1774     {
       
  1775     LOGGER_ENTERFN( "CCmDestinationImpl::CanUseToConnectL" );
       
  1776 
       
  1777     const TInt KZeroItem = 0;
       
  1778     const TInt KOneItem = 1;
       
  1779     TInt cmCount = ConnectionMethodCount(); //without KCmInitIndex !!!
       
  1780     switch ( cmCount )
       
  1781         {
       
  1782         case KZeroItem:// no items at all
       
  1783             {
       
  1784             return EFalse;
       
  1785             }
       
  1786         case KOneItem:// One item, a possible empty embedded destination!
       
  1787             {
       
  1788             CCmDestinationImpl* embeddedDest = EmbeddedL();
       
  1789             if ( embeddedDest )
       
  1790                 {
       
  1791                 // If embeddedDest->ConnectionMethodCount() is not zero,
       
  1792                 // we have something in the embedded destination
       
  1793                 // which cannot be another embedded destination, 
       
  1794                 // since multiple embedding is not allowed.
       
  1795                 return embeddedDest->ConnectionMethodCount();
       
  1796                 }
       
  1797              else
       
  1798                 {
       
  1799                 return ETrue; //not an embedded destination
       
  1800                 }
       
  1801             }
       
  1802         default: // more than one item, only one can be an empty embedded
       
  1803                  // destination, so we surely contain a valid cm
       
  1804             {
       
  1805             return ETrue;
       
  1806             }
       
  1807             
       
  1808         }
       
  1809     }
       
  1810     
       
  1811 // -----------------------------------------------------------------------------
       
  1812 // CCmDestinationImpl::UpdateNetworkRecordL()
       
  1813 // -----------------------------------------------------------------------------
       
  1814 //
       
  1815 void CCmDestinationImpl::UpdateNetworkRecordL()
       
  1816     {
       
  1817     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateNetworkRecordL" );
       
  1818 
       
  1819     if ( !iData->iNetworkRecord->RecordId() || iData->iNewWithId )
       
  1820         {
       
  1821         CLOG_WRITE( "New Destination, create it!" );
       
  1822         //Create a network record, set the host name and add it to the database    
       
  1823 
       
  1824         if ( !iData->iNewWithId )
       
  1825         	{
       
  1826         	iData->iNetworkRecord->SetRecordId(KCDNewRecordRequest);
       
  1827         	}
       
  1828 
       
  1829         SetAttribute( iData->iNetworkRecord, 
       
  1830                       ECDProtectedWrite, 
       
  1831                       ProtectionLevel() == EProtLevel1 );
       
  1832 
       
  1833         iData->iNetworkRecord->StoreL( Session() ); //adds a new record
       
  1834         iData->iNewWithId = EFalse;
       
  1835         }
       
  1836     else
       
  1837         {
       
  1838         SetAttribute( iData->iNetworkRecord, 
       
  1839                       ECDProtectedWrite, 
       
  1840                       ProtectionLevel() == EProtLevel1 );
       
  1841 
       
  1842         iData->iNetworkRecord->ModifyL( Session() );
       
  1843         }
       
  1844     }
       
  1845 
       
  1846 // -----------------------------------------------------------------------------
       
  1847 // CCmDestinationImpl::UpdateDestAPRecordL()
       
  1848 // -----------------------------------------------------------------------------
       
  1849 //
       
  1850 void CCmDestinationImpl::UpdateDestAPRecordL()
       
  1851     {
       
  1852     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateDestAPRecordL" );
       
  1853 
       
  1854     if ( !iData->iDestAPRecord->RecordId() )
       
  1855         {
       
  1856         CLOG_WRITE( "New Destination, create AP for it!" );
       
  1857         //Create an AP record, set the selection policy(network id)
       
  1858         //and add it to the database
       
  1859         iData->iDestAPRecord->SetRecordId(KCDNewRecordRequest);
       
  1860         iData->iDestAPRecord->iRecordTag = CreateDestinationAPTagIdL();
       
  1861         iData->iDestAPRecord->iCustomSelectionPolicy = iData->iNetworkRecord->RecordId();
       
  1862         iData->iDestAPRecord->iRecordName.SetL(iData->iNetworkRecord->iRecordName);
       
  1863         iData->iDestAPRecord->StoreL( Session() ); //adds a new record
       
  1864         }
       
  1865     else
       
  1866         {
       
  1867         iData->iDestAPRecord->iCustomSelectionPolicy = iData->iNetworkRecord->RecordId();
       
  1868         iData->iDestAPRecord->iRecordName.SetL(iData->iNetworkRecord->iRecordName);
       
  1869         iData->iDestAPRecord->ModifyL( Session() ); //modifies the existing
       
  1870         }
       
  1871     }
       
  1872 
       
  1873 // -----------------------------------------------------------------------------
       
  1874 // CCmDestinationImpl::CreateDestinationAPTagId()
       
  1875 // -----------------------------------------------------------------------------
       
  1876 //
       
  1877 TUint32 CCmDestinationImpl::CreateDestinationAPTagIdL()
       
  1878     {
       
  1879     LOGGER_ENTERFN( "CCmDestinationImpl::CreateDestinationAPTagId" );
       
  1880 
       
  1881     return KCmDefaultDestinationAPTagId + iData->iNetworkRecord->RecordId();
       
  1882     }
       
  1883 
       
  1884 // -----------------------------------------------------------------------------
       
  1885 // CCmDestinationImpl::GetDestinationAPTagId()
       
  1886 // -----------------------------------------------------------------------------
       
  1887 //
       
  1888 TUint32 CCmDestinationImpl::GetDestinationAPTagId( )
       
  1889     {
       
  1890     return iData->iNetworkRecord->RecordId() + KCmDefaultDestinationAPTagId;
       
  1891     }
       
  1892 
       
  1893 
       
  1894 // -----------------------------------------------------------------------------
       
  1895 // CCmDestinationImpl::UpdateProtectionL()
       
  1896 // -----------------------------------------------------------------------------
       
  1897 //
       
  1898 void CCmDestinationImpl::UpdateProtectionL()
       
  1899     {
       
  1900     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateProtectionL" );
       
  1901 
       
  1902     if( !iData->iProtectionChanged )
       
  1903         // protection level not changed -> nothing to update here
       
  1904         {
       
  1905         return;
       
  1906         }
       
  1907         
       
  1908     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); i++ )
       
  1909         {
       
  1910         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1911         
       
  1912         LoadPluginL( *item );
       
  1913         
       
  1914         switch ( ProtectionLevel() ) 
       
  1915             {
       
  1916             case EProtLevel0:
       
  1917             case EProtLevel2:
       
  1918                 {
       
  1919                 // from the protection level 0 to 2 and vice versa 
       
  1920                 // the ECmProtected value of the CM is not changed                
       
  1921                 if( iData->iLastProtectionLevel == EProtLevel1 ||
       
  1922                     iData->iLastProtectionLevel == EProtLevel3 )
       
  1923                     {
       
  1924                     item->iPlugin->SetBoolAttributeL( ECmProtected, EFalse );
       
  1925                     }
       
  1926                 }
       
  1927               break;
       
  1928             case EProtLevel1:
       
  1929             case EProtLevel3:
       
  1930                 {
       
  1931                 item->iPlugin->SetBoolAttributeL( ECmProtected, ETrue );
       
  1932                 }
       
  1933               break;
       
  1934             default:
       
  1935                 {
       
  1936                 //
       
  1937                 }
       
  1938               break;              
       
  1939              }                      
       
  1940         }
       
  1941     }
       
  1942 
       
  1943 // -----------------------------------------------------------------------------
       
  1944 // CCmDestinationImpl::UpdateConnectionMethodsL()
       
  1945 // -----------------------------------------------------------------------------
       
  1946 //
       
  1947 void CCmDestinationImpl::UpdateConnectionMethodsL()
       
  1948     {
       
  1949     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateConnectionMethodsL" );
       
  1950 
       
  1951     for( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1952         {
       
  1953         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  1954         
       
  1955         // If the plugin is not loaded, it means that this a old one, or nothing
       
  1956         // modified in it -> there's no need to update it.
       
  1957         if( item->iPlugin )
       
  1958             {
       
  1959             item->iPlugin->UpdateL();
       
  1960             }
       
  1961         }
       
  1962     }
       
  1963 
       
  1964 // -----------------------------------------------------------------------------
       
  1965 // CCmDestinationImpl::SetAttribute()
       
  1966 // -----------------------------------------------------------------------------
       
  1967 //
       
  1968 void CCmDestinationImpl::SetAttribute( CMDBRecordBase* aRecord, 
       
  1969                                        TUint32 aAttribute, TBool aSet )
       
  1970     {
       
  1971     LOGGER_ENTERFN( "CCmDestinationImpl::SetAttribute" );
       
  1972     
       
  1973     if ( aSet && !aRecord->IsSetAttribute( aAttribute ) )
       
  1974         {
       
  1975         aRecord->SetAttributes( aAttribute );
       
  1976         }
       
  1977     else if( !aSet && aRecord->IsSetAttribute( aAttribute ) )
       
  1978         {
       
  1979         aRecord->ClearAttributes( aAttribute );
       
  1980         }
       
  1981     }
       
  1982 
       
  1983 // -----------------------------------------------------------------------------
       
  1984 // CCmDestinationImpl::UpdateSNAPTableL()
       
  1985 // -----------------------------------------------------------------------------
       
  1986 //
       
  1987 void CCmDestinationImpl::UpdateSNAPTableL()
       
  1988     {
       
  1989     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateSNAPTableL" );
       
  1990     
       
  1991     TInt i;
       
  1992     CCDSnapRecord* dnIapRecord;
       
  1993 
       
  1994     // Now we have only records of which are new or needs to be updated
       
  1995     for ( i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  1996         {
       
  1997         TInt pri = (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority;
       
  1998 
       
  1999         if ( pri != i &&
       
  2000              pri != KDataMobilitySelectionPolicyPriorityWildCard )
       
  2001             // wildcard priority CM have to be the last one in the array.
       
  2002             // In theory they cannot be re-prioritized.
       
  2003             {
       
  2004             (*(iData->iConnMethodArray))[i]->iDNRecord->iPriority = i;
       
  2005             }
       
  2006         }
       
  2007 
       
  2008     // Here we don't use KCmInitIndex becouse initial entry should be updated 
       
  2009     // too!
       
  2010     for ( i = 0; i < iData->iConnMethodArray->Count(); ++i )
       
  2011         {
       
  2012         dnIapRecord = (*(iData->iConnMethodArray))[i]->iDNRecord;
       
  2013         
       
  2014         if( dnIapRecord->iIAP )
       
  2015             {
       
  2016             if( !RECORD_FROM_ELEMENT_ID( dnIapRecord->iIAP ) )
       
  2017                 {
       
  2018                 dnIapRecord->iIAP = (*(iData->iConnMethodArray))[i]->iPlugin->IAPRecordElementId();
       
  2019                 }
       
  2020             }
       
  2021         
       
  2022         // Set protection on connection methods 
       
  2023         SetAttribute( dnIapRecord, 
       
  2024                       ECDProtectedWrite, 
       
  2025                       ProtectionLevel() == EProtLevel1 ? ETrue : EFalse );
       
  2026         // Metadata is used instead of ECDHidden Attribute                      
       
  2027         //SetAttribute( dnIapRecord, ECDHidden, iData->iNetworkRecord->Attributes() & ECDHidden );
       
  2028         CheckIfNameModifiedL( dnIapRecord );
       
  2029              
       
  2030         if ( dnIapRecord->RecordId() )
       
  2031             {           
       
  2032             dnIapRecord->ModifyL( Session() );
       
  2033             }
       
  2034         else
       
  2035             // this is a new record
       
  2036             {
       
  2037             dnIapRecord->SetRecordId(KCDNewRecordRequest);
       
  2038             dnIapRecord->iSNAP = Id();
       
  2039             dnIapRecord->StoreL( Session() );
       
  2040             }
       
  2041         }
       
  2042     }
       
  2043 
       
  2044 // -----------------------------------------------------------------------------
       
  2045 // CCmDestinationImpl::UpdateSNAPMetadataTableL()
       
  2046 // -----------------------------------------------------------------------------
       
  2047 //
       
  2048 void CCmDestinationImpl::UpdateSNAPMetadataTableL()
       
  2049     {
       
  2050     LOGGER_ENTERFN( "CCmDestinationImpl::UpdateSNAPMetadataTableL" );
       
  2051     
       
  2052     if( !iData->iMetaDataRec->RecordId() )
       
  2053         // new record
       
  2054         {
       
  2055         iData->iMetaDataRec->iSNAP = Id();
       
  2056         iData->iMetaDataRec->SetRecordId( KCDNewRecordRequest );
       
  2057         iData->iMetaDataRec->StoreL( Session() );
       
  2058         }
       
  2059     else
       
  2060         {
       
  2061         iData->iMetaDataRec->ModifyL( Session() );
       
  2062         }
       
  2063     }
       
  2064 
       
  2065 // -----------------------------------------------------------------------------
       
  2066 // CCmDestinationImpl::LoadSNAPMetadataTableL()
       
  2067 // -----------------------------------------------------------------------------
       
  2068 //
       
  2069 void CCmDestinationImpl::LoadSNAPMetadataTableL()
       
  2070     {
       
  2071     LOGGER_ENTERFN( "CCmDestinationImpl::LoadSNAPMetadataTableL" );
       
  2072 
       
  2073     iData->iMetaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  2074                                             iCmMgr.IconTableId() );
       
  2075 
       
  2076     iData->iMetaDataRec->iSNAP = Id();
       
  2077                 
       
  2078     if ( !iData->iMetaDataRec->FindL( Session() ) )
       
  2079         // Not found -> fill in with default values
       
  2080         {
       
  2081         iData->iMetaDataRec->iSNAP = Id();
       
  2082         iData->iMetaDataRec->iIcon = 0;
       
  2083         iData->iMetaDataRec->iMetadata = 0;
       
  2084         }
       
  2085     }
       
  2086 
       
  2087 // -----------------------------------------------------------------------------
       
  2088 // CCmDestinationImpl::LoadNetworkRecordL()
       
  2089 // -----------------------------------------------------------------------------
       
  2090 //
       
  2091 void CCmDestinationImpl::LoadNetworkRecordL( TUint32 /*aDestinationId*/ )
       
  2092     {
       
  2093     LOGGER_ENTERFN( "CCmDestinationImpl::LoadNetworkRecordL" );
       
  2094 
       
  2095     // set the record ID
       
  2096     iData->iNetworkRecord->SetRecordId( iData->iDestAPRecord->iCustomSelectionPolicy );
       
  2097   
       
  2098     // load the record ID
       
  2099     iData->iNetworkRecord->LoadL( Session() );
       
  2100     }
       
  2101 
       
  2102 // -----------------------------------------------------------------------------
       
  2103 // CCmDestinationImpl::LoadDestAPRecordL()
       
  2104 // -----------------------------------------------------------------------------
       
  2105 //
       
  2106 void CCmDestinationImpl::LoadDestAPRecordL( TUint32 aDestinationId )
       
  2107     {
       
  2108     LOGGER_ENTERFN( "CCmDestinationImpl::LoadDestAPRecordL" );
       
  2109 
       
  2110     if ( aDestinationId > KCmDefaultDestinationAPTagId )
       
  2111         {
       
  2112         // set the record ID
       
  2113         iData->iDestAPRecord->iRecordTag = aDestinationId;
       
  2114         // load the record ID
       
  2115         if ( iData->iDestAPRecord->FindL( Session() ) )
       
  2116             {
       
  2117             iData->iDestAPRecord->LoadL( Session() );
       
  2118             }
       
  2119         else
       
  2120             {
       
  2121             User::Leave( KErrNotFound );
       
  2122             }
       
  2123         }
       
  2124     else
       
  2125         {
       
  2126         User::Leave( KErrArgument );
       
  2127         }
       
  2128     }
       
  2129 
       
  2130 // -----------------------------------------------------------------------------
       
  2131 // CCmDestinationImpl::LoadConnectionMethodsL()
       
  2132 // -----------------------------------------------------------------------------
       
  2133 //    
       
  2134 void CCmDestinationImpl::LoadConnectionMethodsL()
       
  2135     {
       
  2136     LOGGER_ENTERFN( "CCmDestinationImpl::LoadConnectionMethodsL" );
       
  2137     
       
  2138     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  2139                         new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  2140                                           iCmMgr.DestinationTableId() );
       
  2141     CleanupStack::PushL( ptrRecordSet );
       
  2142 
       
  2143     // Prime record
       
  2144     CCDSnapRecord* snapRec = iCmMgr.SNAPRecordL( 0 );
       
  2145     CleanupStack::PushL( snapRec );
       
  2146     snapRec->iSNAP = Id();
       
  2147     ptrRecordSet->iRecords.AppendL( snapRec );
       
  2148 
       
  2149     CleanupStack::Pop( snapRec );
       
  2150     snapRec = NULL;
       
  2151 
       
  2152     OpenTransactionLC();            
       
  2153     if ( !ptrRecordSet->FindL(Session()) )
       
  2154         // no conn method is to this destination -> it was not us who made it
       
  2155         {
       
  2156         CLOG_WRITE( "Empty destination" );
       
  2157         User::Leave( KErrUnderflow );
       
  2158         }
       
  2159 
       
  2160     TLinearOrder<CMDBRecordBase> orderbyId( 
       
  2161                                     CCmDestinationImpl::SortRecordsByPriority );
       
  2162     ptrRecordSet->iRecords.Sort(orderbyId);
       
  2163 
       
  2164     TInt count = ptrRecordSet->iRecords.Count();
       
  2165     
       
  2166     //Load IAP records to be used to check if the IAPs are existing
       
  2167     CMDBRecordSet<CCDIAPRecord>*  ptrIapSet = 
       
  2168                     new (ELeave) CMDBRecordSet<CCDIAPRecord>( KCDTIdIAPRecord );
       
  2169     CleanupStack::PushL( ptrIapSet );
       
  2170     
       
  2171     TRAPD( err, ptrIapSet->LoadL( Session() ) );
       
  2172 
       
  2173     if( !err )
       
  2174         {
       
  2175         CLOG_WRITE_1_PTR( NULL, "Record num [%d]", ptrIapSet->iRecords.Count() );
       
  2176         
       
  2177         // Here we don't use CM_INIT_INDEX because initial entry should be 
       
  2178         // loaded too!
       
  2179         for ( TInt i = 0; i < count; i++ )
       
  2180             {
       
  2181             snapRec = (*ptrRecordSet)[i];
       
  2182             TBool exist( EFalse );
       
  2183             
       
  2184             // Check if CM really exists, if not 
       
  2185             // it should be cleared from selection policy table
       
  2186             TInt32 embedded = QUERY_INT_FIELD( 
       
  2187                                 snapRec, 
       
  2188                                 KCDTIdDataMobilitySelectionPolicyEmbeddedSNAP );
       
  2189             TInt32 iap = RECORD_FROM_ELEMENT_ID( 
       
  2190                             QUERY_INT_FIELD( 
       
  2191                                        snapRec, 
       
  2192                                        KCDTIdDataMobilitySelectionPolicyIAP ) );
       
  2193             // Item could be embedded destination or iap
       
  2194             if ( embedded )
       
  2195                 {
       
  2196                 CCDAccessPointRecord * destAPRecord = static_cast<CCDAccessPointRecord *>(
       
  2197                                 CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  2198                 CleanupStack::PushL( destAPRecord );
       
  2199                 destAPRecord->iRecordTag = embedded;
       
  2200                 if ( !destAPRecord->FindL( Session() ) )
       
  2201                     {
       
  2202                     CleanUpSnapMetadataTableL( embedded );
       
  2203                     (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2204                     }
       
  2205                 else
       
  2206                     {
       
  2207                     exist = ETrue;
       
  2208                     }
       
  2209                     
       
  2210                 CleanupStack::PopAndDestroy( destAPRecord );
       
  2211                 }                
       
  2212             else if ( iap )
       
  2213                 // This is an AP
       
  2214                 {
       
  2215                 for ( TInt iapInd = 0; iapInd < ptrIapSet->iRecords.Count(); ++iapInd )
       
  2216                     {
       
  2217                     CMDBRecordBase* iapRec = (*ptrIapSet)[iapInd];
       
  2218 
       
  2219                     if ( iap == iapRec->RecordId() )
       
  2220                         {
       
  2221                         exist = ETrue;
       
  2222                         delete iapRec;
       
  2223                         // this way we can filter out duplicated CMs
       
  2224                         ptrIapSet->iRecords.Remove( iapInd );
       
  2225                         break;
       
  2226                         }
       
  2227                     }
       
  2228                 if ( !exist )
       
  2229                     {
       
  2230                     DeleteIAPRecordsL( snapRec );
       
  2231                     }
       
  2232                 }
       
  2233             
       
  2234             // The first record is a dummy one where iap and snap are zero
       
  2235             if ( exist || ( !embedded && !iap ) )
       
  2236                 {
       
  2237                 // The item may have to be loaded at this stage so that the supported can be checked 
       
  2238                 // before it is put into iData->iConnMethodArray for the item may be unsupported.
       
  2239                 TInt err( 0 );
       
  2240                 
       
  2241                 if ( i != 0 )
       
  2242                     {
       
  2243                     if ( embedded )
       
  2244                         {
       
  2245                         TRAP( err, TUint32 bearerType = iCmMgr.BearerTypeFromCmIdL( embedded ) );
       
  2246                         }
       
  2247                     else if ( iap )
       
  2248                         {
       
  2249                         TRAP( err, TUint32 bearerType = iCmMgr.BearerTypeFromCmIdL( iap ) );
       
  2250                         }
       
  2251                     }
       
  2252                
       
  2253                 if ( !err )
       
  2254                     {
       
  2255                     CPluginItem* item = new (ELeave) CPluginItem;
       
  2256                     CleanupStack::PushL( item );
       
  2257                     
       
  2258                     item->iDNRecord = iCmMgr.SNAPRecordL( snapRec->RecordId() );
       
  2259                     item->iPlugin = NULL;
       
  2260 
       
  2261                     iData->iConnMethodArray->AppendL( item );
       
  2262                 
       
  2263                     CleanupStack::Pop( item );
       
  2264                     }
       
  2265                 }
       
  2266             }
       
  2267         }
       
  2268     else
       
  2269         // There's no connection method in the phone
       
  2270         {
       
  2271         CPluginItem* item = new (ELeave) CPluginItem;
       
  2272         
       
  2273         CleanupStack::PushL( item );
       
  2274         
       
  2275         item->iDNRecord = iCmMgr.SNAPRecordL( (*ptrRecordSet)[0]->RecordId() );
       
  2276 
       
  2277         iData->iConnMethodArray->AppendL( item );       
       
  2278         
       
  2279         CleanupStack::Pop( item );                 
       
  2280         }
       
  2281         
       
  2282     CleanupStack::PopAndDestroy( ptrIapSet );
       
  2283     RollbackTransaction();
       
  2284         
       
  2285     ptrRecordSet->iRecords.ResetAndDestroy();
       
  2286     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2287     }
       
  2288 
       
  2289 // -----------------------------------------------------------------------------
       
  2290 // CCmDestinationImpl::ReLoadConnectionMethodsL()
       
  2291 // -----------------------------------------------------------------------------
       
  2292 //
       
  2293 void CCmDestinationImpl::ReLoadConnectionMethodsL()
       
  2294     {
       
  2295     TInt count = iData->iConnMethodArray->Count();
       
  2296     //TInt index = KCmInitIndex;
       
  2297     TInt index = 0;
       
  2298     
       
  2299     while ( index < count )
       
  2300         {
       
  2301         CPluginItem* item = (*(iData->iConnMethodArray))[index];
       
  2302         item->iFlags |= CPluginItem::ERemoveCm;
       
  2303         
       
  2304         iData->iDeleteCmArray->AppendL( item );
       
  2305         iData->iConnMethodArray->Delete( index );
       
  2306         iData->iConnMethodArray->Compress();
       
  2307         
       
  2308         count = iData->iConnMethodArray->Count();
       
  2309         }
       
  2310     
       
  2311     // Empty the array, but do not delete it
       
  2312     iData->ResetAndDestroyArray( iData->iDeleteCmArray, EFalse );
       
  2313     
       
  2314     LoadConnectionMethodsL();
       
  2315     }
       
  2316     
       
  2317 // ---------------------------------------------------------
       
  2318 // CCmDestinationImpl::CleanUpEmbeddedL
       
  2319 // ---------------------------------------------------------
       
  2320 //
       
  2321 void CCmDestinationImpl::CleanUpEmbeddedL(TUint32 aDestId)
       
  2322     {
       
  2323     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpEmbeddedL" );
       
  2324 
       
  2325     TBool found = EFalse;
       
  2326     CMDBRecordSet<CCDSnapRecord>*  ptrRecordSet = 
       
  2327                         new (ELeave) CMDBRecordSet<CCDSnapRecord>( 
       
  2328                                           iCmMgr.DestinationTableId() );
       
  2329     CleanupStack::PushL( ptrRecordSet );
       
  2330     // Prime record
       
  2331     CCDSnapRecord* snapRec = iCmMgr.SNAPRecordL( 0 );
       
  2332     CleanupStack::PushL( snapRec );
       
  2333     snapRec->iEmbeddedSNAP = aDestId;
       
  2334     ptrRecordSet->iRecords.AppendL( snapRec );
       
  2335     CleanupStack::Pop( snapRec );
       
  2336     snapRec = NULL;
       
  2337 
       
  2338     if ( ptrRecordSet->FindL(Session()) )
       
  2339         {
       
  2340         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2341             {
       
  2342             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2343             }
       
  2344         found = ETrue;
       
  2345         }
       
  2346     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2347     if (found)
       
  2348         {
       
  2349         CleanUpSnapMetadataTableL(aDestId);    
       
  2350         }
       
  2351     }
       
  2352 // ---------------------------------------------------------
       
  2353 // CCmDestinationImpl::CleanUpSnapMetadataTableL
       
  2354 // ---------------------------------------------------------
       
  2355 //
       
  2356 void CCmDestinationImpl::CleanUpSnapMetadataTableL( TUint32 aSnap )
       
  2357     {
       
  2358     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpSnapMetadataTableL" );
       
  2359     
       
  2360     // Just to test how many record we have
       
  2361     CMDBRecordSet<CCDSNAPMetadataRecord>*  ptrRecordSet 
       
  2362                 = new (ELeave) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  2363                                                 iCmMgr.IconTableId() );
       
  2364     CleanupStack::PushL( ptrRecordSet );
       
  2365         
       
  2366     // Prime record
       
  2367     CCDSNAPMetadataRecord* record = 
       
  2368             new (ELeave) CCDSNAPMetadataRecord( iCmMgr.IconTableId() );
       
  2369     CleanupStack::PushL( record );
       
  2370     
       
  2371     record->iSNAP = aSnap;
       
  2372     ptrRecordSet->iRecords.AppendL( record );
       
  2373     
       
  2374     CleanupStack::Pop( record );
       
  2375     record = NULL;
       
  2376     
       
  2377     if ( ptrRecordSet->FindL( Session() ) )
       
  2378         {
       
  2379         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2380             {
       
  2381             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2382             }
       
  2383         }
       
  2384         
       
  2385     CleanupStack::PopAndDestroy( ptrRecordSet );    //ptrRecordSet 
       
  2386     }
       
  2387 
       
  2388 // ---------------------------------------------------------
       
  2389 // CCmDestinationImpl::CleanUpSeamlessnessTableL
       
  2390 // ---------------------------------------------------------
       
  2391 //
       
  2392 void CCmDestinationImpl::CleanUpSeamlessnessTableL( TUint32 aIapId )
       
  2393     {
       
  2394     LOGGER_ENTERFN( "CCmDestinationImpl::CleanUpSeamlessnesstableL" );
       
  2395     
       
  2396     // Just to test how many record we have
       
  2397     CMDBRecordSet<CCDIAPMetadataRecord>*  ptrRecordSet 
       
  2398         = new (ELeave) CMDBRecordSet<CCDIAPMetadataRecord>( 
       
  2399                                         iCmMgr.SeamlessnessTableId() );
       
  2400     CleanupStack::PushL( ptrRecordSet );
       
  2401         
       
  2402     // Prime record
       
  2403     CCDIAPMetadataRecord* record = 
       
  2404       new (ELeave) CCDIAPMetadataRecord( iCmMgr.SeamlessnessTableId() );
       
  2405     CleanupStack::PushL( record );
       
  2406     
       
  2407     TMDBElementId elementid = iCmMgr.SeamlessnessTableId() & 
       
  2408                               KCDTIdIAPMetadataIAP & 
       
  2409                               aIapId;
       
  2410     record->iSeamlessness = elementid;
       
  2411     ptrRecordSet->iRecords.AppendL( record );
       
  2412     
       
  2413     CleanupStack::Pop( record );
       
  2414     record = NULL;
       
  2415     
       
  2416     if ( ptrRecordSet->FindL( Session() ) )
       
  2417         {
       
  2418         for ( TInt i = 0; i <ptrRecordSet->iRecords.Count(); i++ )
       
  2419             {
       
  2420             (*ptrRecordSet)[i]->DeleteL( Session() );
       
  2421             }
       
  2422         }
       
  2423         
       
  2424     CleanupStack::PopAndDestroy( ptrRecordSet );
       
  2425     }
       
  2426     
       
  2427 // ---------------------------------------------------------
       
  2428 // CCmDestinationImpl::SortRecordsByPriority
       
  2429 // ---------------------------------------------------------
       
  2430 //
       
  2431 TInt CCmDestinationImpl::SortRecordsByPriority( const CMDBRecordBase& aLeft, 
       
  2432                                                 const CMDBRecordBase& aRight )
       
  2433     {
       
  2434     TUint left = QUERY_INT_FIELD( const_cast<CMDBRecordBase*>(&aLeft), 
       
  2435                                   KCDTIdDataMobilitySelectionPolicyPriority );
       
  2436     TUint right = QUERY_INT_FIELD( const_cast<CMDBRecordBase*>(&aRight),
       
  2437                                    KCDTIdDataMobilitySelectionPolicyPriority );
       
  2438 
       
  2439     /*
       
  2440     *   - negative value, if aLeft is less than aRight;
       
  2441     *   - 0,              if aLeft equals to aRight;
       
  2442     *   - positive value, if aLeft is greater than aRight.
       
  2443     */
       
  2444     if ( left == right )
       
  2445         {
       
  2446         return 0;
       
  2447         }
       
  2448     
       
  2449     return ( left < right ) ? -1 : 1;
       
  2450     }
       
  2451 
       
  2452 // -----------------------------------------------------------------------------
       
  2453 // CCmDestinationImpl::IconL()
       
  2454 // -----------------------------------------------------------------------------
       
  2455 //      
       
  2456 EXPORT_C CGulIcon* CCmDestinationImpl::IconL() 
       
  2457     {
       
  2458     LOGGER_ENTERFN( "CCmDestinationImpl::IconL" );
       
  2459 
       
  2460     return IconL( iData->iMetaDataRec->iIcon );
       
  2461     }
       
  2462 
       
  2463 // -----------------------------------------------------------------------------
       
  2464 // CCmDestinationImpl::SetIconL()
       
  2465 // -----------------------------------------------------------------------------
       
  2466 //      
       
  2467 void CCmDestinationImpl::SetIconL( TUint32 anIndex )
       
  2468     {
       
  2469     LOGGER_ENTERFN( "CCmDestinationImpl::SetIconL" )
       
  2470     
       
  2471     if( ProtectionLevel() == EProtLevel1 )
       
  2472         {
       
  2473         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2474         }
       
  2475         
       
  2476     iData->iMetaDataRec->iIcon = anIndex;
       
  2477     }
       
  2478 
       
  2479 // -----------------------------------------------------------------------------
       
  2480 // CCmDestinationData::MetadataL()
       
  2481 // -----------------------------------------------------------------------------
       
  2482 //
       
  2483 TUint32 CCmDestinationData::MetadataL( TSnapMetadataField aMetaField ) const
       
  2484     {
       
  2485     LOGGER_ENTERFN( "CCmDestinationImpl::MetadataL" )
       
  2486 
       
  2487     TUint retVal( 0 );
       
  2488 
       
  2489     switch( aMetaField )
       
  2490         {
       
  2491         case ESnapMetadataInternet:
       
  2492             {
       
  2493             retVal = TUint32(iMetaDataRec->iMetadata) & 
       
  2494                      ESnapMetadataInternet;
       
  2495             }
       
  2496             break;
       
  2497             
       
  2498         case ESnapMetadataHighlight:
       
  2499             {
       
  2500             retVal = TUint32(iMetaDataRec->iMetadata) & 
       
  2501                      ESnapMetadataHighlight;
       
  2502             }
       
  2503             break;
       
  2504             
       
  2505         case ESnapMetadataHiddenAgent:
       
  2506             {
       
  2507             retVal = TUint32(iMetaDataRec->iMetadata) &
       
  2508                      ESnapMetadataHiddenAgent;
       
  2509             }
       
  2510             break;
       
  2511 
       
  2512         case ESnapMetadataDestinationIsLocalised:
       
  2513             {
       
  2514             retVal = (TUint32(iMetaDataRec->iMetadata) &
       
  2515                       ESnapMetadataDestinationIsLocalised) >> 4;
       
  2516             }
       
  2517             break;
       
  2518             
       
  2519         case ESnapMetadataPurpose:
       
  2520             {
       
  2521             retVal = (TUint32(iMetaDataRec->iMetadata) &
       
  2522                      ESnapMetadataPurpose) >> 8;
       
  2523             }
       
  2524             break;
       
  2525 
       
  2526         default:
       
  2527             {
       
  2528             User::Leave( KErrArgument );
       
  2529             }
       
  2530         }
       
  2531     
       
  2532     return retVal;
       
  2533     }
       
  2534 
       
  2535 // -----------------------------------------------------------------------------
       
  2536 // CCmDestinationImpl::MetadataL()
       
  2537 // -----------------------------------------------------------------------------
       
  2538 //
       
  2539 TUint32 CCmDestinationImpl::MetadataL( TSnapMetadataField aMetaField ) const
       
  2540     {
       
  2541     LOGGER_ENTERFN( "CCmDestinationImpl::MetadataL" )
       
  2542     return iData->MetadataL(aMetaField);
       
  2543     }
       
  2544     
       
  2545 // -----------------------------------------------------------------------------
       
  2546 // CCmDestinationImpl::SetMetadataL()
       
  2547 // -----------------------------------------------------------------------------
       
  2548 //
       
  2549 void CCmDestinationImpl::SetMetadataL( TSnapMetadataField aMetaField, 
       
  2550 		                               TUint32 aValue )
       
  2551     {
       
  2552     LOGGER_ENTERFN( "CCmDestinationImpl::SetMetadata" );
       
  2553     
       
  2554     if( ProtectionLevel() == EProtLevel1 )
       
  2555         {
       
  2556         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2557         }
       
  2558         
       
  2559     switch( aMetaField )
       
  2560         {
       
  2561         case ESnapMetadataInternet:
       
  2562             {
       
  2563             if( aValue )
       
  2564                 {
       
  2565                 CheckIfInternetExistsL();
       
  2566                 
       
  2567                 iData->iMetaDataRec->iMetadata = 
       
  2568                         ESnapMetadataInternet | iData->iMetaDataRec->iMetadata;
       
  2569 
       
  2570                 // Set the new way, too!!!
       
  2571                 SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2572                               ELocalisedDestInternet );
       
  2573                 }
       
  2574             else
       
  2575                 {
       
  2576                 iData->iMetaDataRec->iMetadata =
       
  2577                         ~ESnapMetadataInternet & iData->iMetaDataRec->iMetadata;
       
  2578                 // Clear the new way, too!!!
       
  2579                 SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2580                               ENotLocalisedDest );                
       
  2581                 }
       
  2582             }
       
  2583             break;
       
  2584 
       
  2585         case ESnapMetadataDestinationIsLocalised:
       
  2586             {
       
  2587             // Check that aValue is within valid range.
       
  2588             if ( aValue > ELocalisedDestIntranet )
       
  2589                 {
       
  2590                 User::Leave( KErrArgument );
       
  2591                 }
       
  2592             
       
  2593             TUint32 oldVal = TUint32(iData->iMetaDataRec->iMetadata) & 
       
  2594                              ESnapMetadataInternet;
       
  2595             if ( aValue != ENotLocalisedDest )
       
  2596                 {
       
  2597                 // check if already exists...
       
  2598                 CheckIfLocalisedDestExistL( aValue );
       
  2599                 // does not exists, first clear original value
       
  2600                 // if old one was Internet, clear that, too:
       
  2601                 if ( oldVal )
       
  2602                     {
       
  2603                     // copied here to avoid recursivity!!!
       
  2604                     // SetMetadataL(ESnapMetadataInternet, 0 );
       
  2605                     iData->iMetaDataRec->iMetadata =
       
  2606                         ~ESnapMetadataInternet & iData->iMetaDataRec->iMetadata;
       
  2607                     }
       
  2608                 // clearing
       
  2609                 iData->iMetaDataRec->iMetadata =
       
  2610                                                 ~ESnapMetadataDestinationIsLocalised &
       
  2611                                                 iData->iMetaDataRec->iMetadata;
       
  2612                 // set new value
       
  2613                 TUint32 mask = aValue << 4; 
       
  2614                 iData->iMetaDataRec->iMetadata = 
       
  2615                                                 mask | 
       
  2616                                                 iData->iMetaDataRec->iMetadata;
       
  2617                 // for backward compatibility, if it is internet, 
       
  2618                 // set it the old way, too
       
  2619                 if ( aValue == ELocalisedDestInternet )
       
  2620                     {
       
  2621                     // copied here to avoid recursivity!!!
       
  2622                     iData->iMetaDataRec->iMetadata = 
       
  2623                         ESnapMetadataInternet | iData->iMetaDataRec->iMetadata;
       
  2624                     // SetMetadataL(ESnapMetadataInternet, 1 );
       
  2625                     }
       
  2626                 }
       
  2627             else
       
  2628                 {
       
  2629                 // not localised, set to ENotLocalisedDest = 0
       
  2630                 // for backward compatibility, if it was internet, 
       
  2631                 // set it the old way, too
       
  2632                 if ( oldVal )
       
  2633                     {
       
  2634                     SetMetadataL(ESnapMetadataInternet, 0 );
       
  2635                     }
       
  2636                 // clear the new way...
       
  2637                 iData->iMetaDataRec->iMetadata =
       
  2638                                                 ~ESnapMetadataDestinationIsLocalised &
       
  2639                                                 iData->iMetaDataRec->iMetadata;
       
  2640                 }
       
  2641 
       
  2642             break;
       
  2643             }
       
  2644 
       
  2645         case ESnapMetadataPurpose:
       
  2646             {
       
  2647             // Check that aValue is within valid range.
       
  2648             if ( aValue > ESnapPurposeIntranet )
       
  2649                 {
       
  2650                 User::Leave( KErrArgument );
       
  2651                 }
       
  2652             
       
  2653             // Check if destination with the given purpose already
       
  2654             // exists
       
  2655             CheckIfPurposeExistL( aValue );
       
  2656             
       
  2657             // ESnapPurposeInternet and ESnapPurposeMMS need special
       
  2658             // handling
       
  2659             switch( aValue )
       
  2660                 {
       
  2661                 case ESnapPurposeUnknown:
       
  2662                     {
       
  2663                     // This also clears ESnapMetadataInternet
       
  2664                     SetMetadataL( ESnapMetadataDestinationIsLocalised, ENotLocalisedDest );
       
  2665                     break;
       
  2666                     }
       
  2667                 case ESnapPurposeInternet:
       
  2668                     {
       
  2669                     // This sets ESnapMetadataInternet and
       
  2670                     // ELocalisedDestInternet
       
  2671                     SetMetadataL( ESnapMetadataInternet, 1 );
       
  2672                     }
       
  2673                     break;
       
  2674                 case ESnapPurposeOperator:
       
  2675                     {
       
  2676                     SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2677                                   ELocalisedDestWap );
       
  2678                     }
       
  2679                 	break;
       
  2680                 case ESnapPurposeMMS:
       
  2681                     {
       
  2682                     SetMetadataL( ESnapMetadataDestinationIsLocalised, 
       
  2683                                   ELocalisedDestMMS );
       
  2684                     iData->iMetaDataRec->iMetadata = 
       
  2685                         ESnapMetadataHiddenAgent | iData->iMetaDataRec->iMetadata;
       
  2686                     }
       
  2687                     break;
       
  2688                 case ESnapPurposeIntranet:
       
  2689                     {
       
  2690                     SetMetadataL( ESnapMetadataDestinationIsLocalised,
       
  2691                                   ELocalisedDestIntranet );
       
  2692                     }
       
  2693                     break;
       
  2694                 default:
       
  2695                     break;
       
  2696                 }
       
  2697             
       
  2698             TUint32 value = aValue << 8;
       
  2699             // reset the purpose bit
       
  2700             iData->iMetaDataRec->iMetadata = ~ESnapMetadataPurpose & iData->iMetaDataRec->iMetadata;
       
  2701             // set the purpose bit
       
  2702             iData->iMetaDataRec->iMetadata = value | iData->iMetaDataRec->iMetadata;
       
  2703             }
       
  2704             break;
       
  2705 
       
  2706         case ESnapMetadataHighlight:
       
  2707             {
       
  2708             if( aValue )
       
  2709                 {
       
  2710                 iData->iMetaDataRec->iMetadata = 
       
  2711                         ESnapMetadataHighlight | iData->iMetaDataRec->iMetadata;
       
  2712                 }
       
  2713             else
       
  2714                 {
       
  2715                 iData->iMetaDataRec->iMetadata =
       
  2716                         ~ESnapMetadataHighlight & iData->iMetaDataRec->iMetadata;
       
  2717                 }
       
  2718             }
       
  2719             break;
       
  2720             
       
  2721         case ESnapMetadataHiddenAgent:
       
  2722             {
       
  2723             TUint32 internet = iData->iMetaDataRec->iMetadata & ESnapMetadataInternet;
       
  2724             TUint32 internetLocal = ( iData->iMetaDataRec->iMetadata & ESnapMetadataDestinationIsLocalised ) >> 4;
       
  2725             TUint32 internetPurpose = ( iData->iMetaDataRec->iMetadata & ESnapMetadataPurpose ) >> 8;
       
  2726             if( aValue )
       
  2727                 {
       
  2728                 if ( internet
       
  2729                      || ( internetLocal == ELocalisedDestInternet )
       
  2730                      || ( internetPurpose == ESnapPurposeInternet ) )
       
  2731                     {
       
  2732                     User::Leave( KErrArgument );
       
  2733                     }
       
  2734 
       
  2735                 iData->iMetaDataRec->iMetadata = 
       
  2736                         ESnapMetadataHiddenAgent | iData->iMetaDataRec->iMetadata;
       
  2737                 }
       
  2738             else
       
  2739                 {
       
  2740                 iData->iMetaDataRec->iMetadata = 
       
  2741                         ~ESnapMetadataHiddenAgent & iData->iMetaDataRec->iMetadata;
       
  2742                 }
       
  2743             }
       
  2744             break;
       
  2745             
       
  2746         default:
       
  2747             {
       
  2748             User::Leave( KErrArgument );
       
  2749             }
       
  2750         }
       
  2751     }
       
  2752 // -----------------------------------------------------------------------------
       
  2753 // CCmDestinationImpl::CreateEmbeddedDestinationPluginL()
       
  2754 // -----------------------------------------------------------------------------
       
  2755 //      
       
  2756 void CCmDestinationImpl::CreateEmbeddedDestinationPluginL( 
       
  2757                                                         CPluginItem& aItem, 
       
  2758                                                         TInt aDestinationId )
       
  2759     {
       
  2760     LOGGER_ENTERFN( "CCmDestinationImpl::CreateEmbeddedDestinationPluginL" );
       
  2761 
       
  2762     aItem.iPlugin = iCmMgr.CreateConnectionMethodL(KUidEmbeddedDestination, this); 
       
  2763     CleanupStack::PushL( aItem.iPlugin );
       
  2764     // Load this destination
       
  2765     aItem.iPlugin->LoadL( aDestinationId );
       
  2766     CleanupStack::Pop( aItem.iPlugin );        
       
  2767     }
       
  2768 
       
  2769 // -----------------------------------------------------------------------------
       
  2770 // CCmDestinationImpl::LoadEmbeddedDestinationPluginL()
       
  2771 // -----------------------------------------------------------------------------
       
  2772 //      
       
  2773 void CCmDestinationImpl::LoadEmbeddedDestinationPluginL( 
       
  2774                                                         CPluginItem& aItem )
       
  2775     {
       
  2776     LOGGER_ENTERFN( "CCmDestinationImpl::LoadEmbeddedDestinationPluginL" );
       
  2777 
       
  2778     CreateEmbeddedDestinationPluginL(aItem, aItem.iDNRecord->ElementId());
       
  2779     }
       
  2780 
       
  2781 // -----------------------------------------------------------------------------
       
  2782 // CCmDestinationImpl::LoadPluginL()
       
  2783 // -----------------------------------------------------------------------------
       
  2784 //      
       
  2785 void CCmDestinationImpl::LoadPluginL( CPluginItem& aItem )
       
  2786     {
       
  2787     LOGGER_ENTERFN( "CCmDestinationImpl::LoadPluginL" );
       
  2788     
       
  2789     if( aItem.iPlugin )
       
  2790         {
       
  2791         return;
       
  2792         }
       
  2793         
       
  2794     TUint32 cmId;
       
  2795     if ( aItem.iDNRecord->iEmbeddedSNAP )
       
  2796         // This is an embedded destination
       
  2797         {
       
  2798         cmId = aItem.iDNRecord->iEmbeddedSNAP;
       
  2799         
       
  2800         }
       
  2801     else
       
  2802         // Normal IAP id
       
  2803         {
       
  2804         cmId = RECORD_FROM_ELEMENT_ID( aItem.iDNRecord->iIAP );
       
  2805         }
       
  2806 
       
  2807     aItem.iPlugin = iCmMgr.DoFindConnMethodL( 
       
  2808                         cmId, 
       
  2809                         this );
       
  2810                         
       
  2811     CLOG_ATTACH( aItem.iPlugin, this );
       
  2812     }    
       
  2813 
       
  2814 // -----------------------------------------------------------------------------
       
  2815 // CCmDestinationImpl::PluginClosed()
       
  2816 // -----------------------------------------------------------------------------
       
  2817 //
       
  2818 void CCmDestinationImpl::PluginClosed( CCmPluginBase* aPlugin )
       
  2819     {
       
  2820     LOGGER_ENTERFN( "CCmDestinationImpl::PluginClosed" );
       
  2821 
       
  2822     if (iData->iConnMethodArray)
       
  2823         {
       
  2824         for ( TInt i = 0; i < iData->iConnMethodArray->Count(); ++i )
       
  2825             {
       
  2826             if ( (*(iData->iConnMethodArray))[i]->iPlugin == aPlugin )
       
  2827                 {
       
  2828                 // Must NOT delete it here. Simply forget that
       
  2829                 // we had this plugin instance.
       
  2830                 (*(iData->iConnMethodArray))[i]->iPlugin = NULL;
       
  2831                 
       
  2832                 break;
       
  2833                 }
       
  2834             }        
       
  2835         }
       
  2836     }
       
  2837     
       
  2838 // -----------------------------------------------------------------------------
       
  2839 // CCmDestinationData::IsHiddenL()
       
  2840 // -----------------------------------------------------------------------------
       
  2841 //          
       
  2842 TBool CCmDestinationData::IsHiddenL()
       
  2843     {
       
  2844     TSnapMetadataField hiddenValue = ( TSnapMetadataField )MetadataL( ESnapMetadataHiddenAgent );
       
  2845     if ( hiddenValue == ESnapMetadataHiddenAgent )
       
  2846         {
       
  2847     	return ETrue;
       
  2848         }
       
  2849     else
       
  2850         {
       
  2851     	return EFalse;
       
  2852         }
       
  2853     }    
       
  2854     
       
  2855 // -----------------------------------------------------------------------------
       
  2856 // CCmDestinationImpl::IsHiddenL()
       
  2857 // -----------------------------------------------------------------------------
       
  2858 //          
       
  2859 EXPORT_C TBool CCmDestinationImpl::IsHidden()
       
  2860     {
       
  2861     TBool hidden( EFalse );
       
  2862     TRAPD( err, hidden = iData->IsHiddenL() );
       
  2863     __ASSERT_ALWAYS( err == KErrNone, User::Panic(_L( "CMManager" ), err ) );
       
  2864     
       
  2865     return hidden;
       
  2866     }    
       
  2867 
       
  2868 // -----------------------------------------------------------------------------
       
  2869 // CCmDestinationImpl::SetHiddenL()
       
  2870 // -----------------------------------------------------------------------------
       
  2871 //          
       
  2872 EXPORT_C void CCmDestinationImpl::SetHiddenL( TBool aHidden )
       
  2873     {
       
  2874     if( ProtectionLevel() == EProtLevel1 )
       
  2875         {
       
  2876         CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl );
       
  2877         }
       
  2878     SetMetadataL( ESnapMetadataHiddenAgent, aHidden );
       
  2879     }
       
  2880 
       
  2881 // -----------------------------------------------------------------------------
       
  2882 // CCmDestinationImpl::DeleteConnectionMethodsL
       
  2883 //
       
  2884 // Can be called only during opened transaction. 
       
  2885 // Array is emptied only after transaction commited!
       
  2886 //
       
  2887 // -----------------------------------------------------------------------------
       
  2888 //          
       
  2889 void CCmDestinationImpl::DeleteConnectionMethodsL()
       
  2890     {
       
  2891     LOGGER_ENTERFN( "DeleteConnectionMethodsL" );
       
  2892     
       
  2893     TInt i;
       
  2894     
       
  2895     for ( i = 0; i < iData->iDeleteCmArray->Count(); ++i )
       
  2896         {
       
  2897         CPluginItem* item = (*iData->iDeleteCmArray)[i];
       
  2898         
       
  2899         LoadPluginL( *item );   
       
  2900 
       
  2901         if( !(item->iFlags & CPluginItem::ERemoveCm) )
       
  2902             {
       
  2903             item->iPlugin->DeleteL( EFalse );
       
  2904             }
       
  2905             
       
  2906         item->iDNRecord->DeleteL( Session() );
       
  2907         }
       
  2908     }
       
  2909     
       
  2910 // -----------------------------------------------------------------------------
       
  2911 // CCmDestinationData::ResetAndDestroyArray
       
  2912 // -----------------------------------------------------------------------------
       
  2913 //          
       
  2914 void CCmDestinationData::ResetAndDestroyArray( CCmArray* &aArray, TBool aDestroy )
       
  2915     {
       
  2916     if( aArray )
       
  2917         {
       
  2918         for ( TInt i = 0; i < aArray->Count(); ++i )
       
  2919             {
       
  2920             CPluginItem* item = (*aArray)[i];
       
  2921             
       
  2922             delete item->iPlugin;
       
  2923             delete item->iDNRecord;
       
  2924             }
       
  2925             
       
  2926         aArray->ResetAndDestroy();
       
  2927         
       
  2928         if( aDestroy )
       
  2929             {
       
  2930             delete aArray; aArray = NULL;
       
  2931             }
       
  2932         }
       
  2933     }
       
  2934 
       
  2935 // -----------------------------------------------------------------------------
       
  2936 // CCmDestinationImpl::DeleteIAPRecordsL
       
  2937 // -----------------------------------------------------------------------------
       
  2938 //          
       
  2939 void CCmDestinationImpl::DeleteIAPRecordsL( CMDBRecordBase* aSnapRecord )
       
  2940     {
       
  2941     LOGGER_ENTERFN( "CCmDestinationImpl::DeleteIAPRecordsL" );
       
  2942 
       
  2943     // First delete the metadata record
       
  2944     CCDIAPMetadataRecord* metaRec = new (ELeave) CCDIAPMetadataRecord( 
       
  2945                                         iCmMgr.SeamlessnessTableId() );
       
  2946                                         
       
  2947     CleanupStack::PushL( metaRec );
       
  2948 
       
  2949     metaRec->iIAP = RECORD_FROM_ELEMENT_ID( 
       
  2950                                 QUERY_INT_FIELD( 
       
  2951                                        aSnapRecord, 
       
  2952                                        KCDTIdDataMobilitySelectionPolicyIAP ) );
       
  2953 
       
  2954     if( metaRec->FindL( Session() ) )
       
  2955         {
       
  2956         metaRec->DeleteL( Session() );
       
  2957         }
       
  2958         
       
  2959     CleanupStack::PopAndDestroy( metaRec );
       
  2960     
       
  2961     // and now delete the SNAP record
       
  2962     aSnapRecord->DeleteL( Session() );
       
  2963     }
       
  2964 
       
  2965 // -----------------------------------------------------------------------------
       
  2966 // CCmDestinationImpl::CheckIfNameModifiedL
       
  2967 // -----------------------------------------------------------------------------
       
  2968 void CCmDestinationImpl::CheckIfNameModifiedL( CCDSnapRecord* aRecord )
       
  2969     {
       
  2970     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfNameModifiedL" );
       
  2971             
       
  2972     if ( !TPtrC(iData->iDestAPRecord->iRecordName).CompareF( TPtrC(aRecord->iRecordName) ) )
       
  2973         // names matches
       
  2974         {
       
  2975         return;
       
  2976         }
       
  2977     
       
  2978     aRecord->iRecordName.SetL( TPtrC(iData->iDestAPRecord->iRecordName) );
       
  2979     }
       
  2980 
       
  2981 // -----------------------------------------------------------------------------
       
  2982 // CCmDestinationImpl::IsConnectedL
       
  2983 // -----------------------------------------------------------------------------
       
  2984 EXPORT_C TBool CCmDestinationImpl::IsConnectedL() const
       
  2985     {
       
  2986     LOGGER_ENTERFN( "CCmDestinationImpl::IsConnectedL" );
       
  2987 
       
  2988     CCmDestinationImpl* myThis = const_cast<CCmDestinationImpl*>( this );
       
  2989     TBool retVal( EFalse );
       
  2990     TInt i;
       
  2991     
       
  2992     for( i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  2993         {
       
  2994         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  2995         
       
  2996         myThis->LoadPluginL( *item );
       
  2997             
       
  2998         if( item->iPlugin->GetBoolAttributeL( ECmConnected ) )
       
  2999             {
       
  3000             retVal = ETrue;
       
  3001             break;
       
  3002             }
       
  3003         }
       
  3004         
       
  3005     return retVal;
       
  3006     }
       
  3007 
       
  3008 // -----------------------------------------------------------------------------
       
  3009 // CCmDestinationImpl::CheckIfInternetExistsL
       
  3010 //
       
  3011 // There can be only one SNAP with Internet metadata field set.
       
  3012 // -----------------------------------------------------------------------------
       
  3013 void CCmDestinationImpl::CheckIfInternetExistsL()
       
  3014     {
       
  3015     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfInternetExistsL" );
       
  3016 
       
  3017     OpenTransactionLC();
       
  3018 
       
  3019     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3020            new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( 
       
  3021                                                  iCmMgr.IconTableId() );
       
  3022     CleanupStack::PushL( metaSet );
       
  3023 
       
  3024     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3025 
       
  3026     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3027         {
       
  3028         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3029                                      KCDTIdSNAPMetadataMetadata );
       
  3030 
       
  3031         if( meta & ESnapMetadataInternet )
       
  3032             {
       
  3033             if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3034                                                 KCDTIdSNAPMetadataSNAP ) )
       
  3035                 {
       
  3036                 User::Leave( KErrAlreadyExists );
       
  3037                 }
       
  3038             }
       
  3039         }
       
  3040     
       
  3041     CleanupStack::PopAndDestroy( metaSet );
       
  3042     
       
  3043     RollbackTransaction();
       
  3044     }
       
  3045 
       
  3046 // -----------------------------------------------------------------------------
       
  3047 // CCmDestinationImpl::ConnectionMethodIndex
       
  3048 // -----------------------------------------------------------------------------
       
  3049 TInt CCmDestinationImpl::ConnectionMethodIndex( TUint32 aCmId )
       
  3050     {
       
  3051     LOGGER_ENTERFN( "CCmDestinationImpl::ConnectionMethodIndex" );
       
  3052 
       
  3053     TInt found( KErrNotFound );
       
  3054     
       
  3055     for ( TInt i = KCmInitIndex; i < iData->iConnMethodArray->Count(); ++i )
       
  3056         {
       
  3057         CPluginItem* item = (*(iData->iConnMethodArray))[i];
       
  3058         if ( RECORD_FROM_ELEMENT_ID(item->iDNRecord->iIAP) == aCmId ||
       
  3059              (item->iDNRecord->iEmbeddedSNAP == aCmId && aCmId != 0) )
       
  3060             {
       
  3061             found = i;
       
  3062             break;
       
  3063             }        
       
  3064         }
       
  3065         
       
  3066     return found;
       
  3067     }        
       
  3068 
       
  3069 // -----------------------------------------------------------------------------
       
  3070 // CCmDestinationImpl::IconIdL
       
  3071 // -----------------------------------------------------------------------------
       
  3072 CGulIcon* CCmDestinationImpl::IconIdL( CCmManagerImpl& aCmMgr,
       
  3073                                        TMDBElementId aId )
       
  3074     {
       
  3075     CGulIcon* retVal = NULL;
       
  3076     CCDSNAPMetadataRecord* metaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  3077                                                         aCmMgr.IconTableId() );
       
  3078     CleanupStack::PushL( metaDataRec );
       
  3079     metaDataRec->iSNAP = aId;
       
  3080                 
       
  3081     if ( metaDataRec->FindL( aCmMgr.Session() ) )
       
  3082         // Not found -> fill in with default values
       
  3083         {
       
  3084         retVal = IconL( metaDataRec->iIcon );
       
  3085         }
       
  3086     else
       
  3087         {
       
  3088         User::Leave( KErrNotFound );
       
  3089         }
       
  3090         
       
  3091     CleanupStack::PopAndDestroy( metaDataRec );
       
  3092     
       
  3093     return retVal;
       
  3094     }
       
  3095 
       
  3096 // -----------------------------------------------------------------------------
       
  3097 // CCmDestinationImpl::ProtectionLevelL
       
  3098 // -----------------------------------------------------------------------------
       
  3099 TProtectionLevel CCmDestinationImpl::ProtectionLevelL( CCmManagerImpl& aCmMgr, 
       
  3100                                                        TMDBElementId aId ) 
       
  3101     {
       
  3102     TProtectionLevel retVal( EProtLevel0 );
       
  3103     CCDSNAPMetadataRecord* metaDataRec = new (ELeave) CCDSNAPMetadataRecord( 
       
  3104                                                         aCmMgr.IconTableId() );
       
  3105     CleanupStack::PushL( metaDataRec );
       
  3106     metaDataRec->iSNAP = aId;
       
  3107                 
       
  3108     if ( metaDataRec->FindL( aCmMgr.Session() ) )
       
  3109         // Not found -> fill in with default values
       
  3110         {
       
  3111         retVal = ProtectionLevel( metaDataRec );
       
  3112         }
       
  3113     else
       
  3114         {
       
  3115         User::Leave( KErrNotFound );
       
  3116         }
       
  3117         
       
  3118     CleanupStack::PopAndDestroy( metaDataRec );
       
  3119     return retVal;
       
  3120     }
       
  3121 
       
  3122 // -----------------------------------------------------------------------------
       
  3123 // CCmDestinationImpl::ProtectionLevel
       
  3124 // -----------------------------------------------------------------------------
       
  3125 TProtectionLevel CCmDestinationImpl::ProtectionLevel( 
       
  3126                                            CCDSNAPMetadataRecord* aMetaDataRec )
       
  3127     {
       
  3128     TInt protection = TUint32(aMetaDataRec->iMetadata) & 
       
  3129                       KSnapMetadataProtecionLevelMask;
       
  3130     return TProtectionLevel(protection >> 28);
       
  3131     }
       
  3132 
       
  3133 // -----------------------------------------------------------------------------
       
  3134 // CCmDestinationImpl::ProtectionLevelL
       
  3135 // -----------------------------------------------------------------------------
       
  3136 CGulIcon* CCmDestinationImpl::IconL( TInt aIconIndex )
       
  3137     {
       
  3138     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
  3139            
       
  3140     TParse mbmFile;
       
  3141     User::LeaveIfError( mbmFile.Set( KManagerIconFilename, 
       
  3142                                      &KDC_BITMAP_DIR, 
       
  3143                                      NULL ) );
       
  3144                                      
       
  3145     TAknsItemID aknItemID;
       
  3146     aknItemID.Set( KDestinationIconConvTable[aIconIndex][0],
       
  3147                    KDestinationIconConvTable[aIconIndex][1] );
       
  3148            
       
  3149     CGulIcon* icon = AknsUtils::CreateGulIconL( 
       
  3150                             skinInstance, 
       
  3151                             aknItemID,
       
  3152                             mbmFile.FullName(), 
       
  3153                             KDestinationIconConvTable[aIconIndex][2], 
       
  3154                             KDestinationIconConvTable[aIconIndex][3] );
       
  3155                             
       
  3156     return icon;
       
  3157     }
       
  3158     
       
  3159 // -----------------------------------------------------------------------------
       
  3160 // CCmDestinationImpl::RemoveFromPool
       
  3161 // -----------------------------------------------------------------------------
       
  3162 EXPORT_C void CCmDestinationImpl::RemoveFromPool()
       
  3163     {
       
  3164     iCmMgr.RemoveDestFromPool(this);            
       
  3165     }
       
  3166     
       
  3167 // -----------------------------------------------------------------------------
       
  3168 // CCmDestinationImpl::IncrementRefCounter
       
  3169 // -----------------------------------------------------------------------------
       
  3170 void CCmDestinationImpl::IncrementRefCounter()
       
  3171     {
       
  3172     iData->IncrementRefCounter();
       
  3173     }
       
  3174 // -----------------------------------------------------------------------------
       
  3175 // CCmDestinationImpl::DecrementRefCounter
       
  3176 // -----------------------------------------------------------------------------
       
  3177 void CCmDestinationImpl::DecrementRefCounter()
       
  3178     {
       
  3179     iData->DecrementRefCounter();
       
  3180     }
       
  3181 // -----------------------------------------------------------------------------
       
  3182 // CCmDestinationData::IncrementRefCounter
       
  3183 // -----------------------------------------------------------------------------
       
  3184 void CCmDestinationData::IncrementRefCounter()
       
  3185     {
       
  3186     iRefCounter++;
       
  3187     }
       
  3188 // -----------------------------------------------------------------------------
       
  3189 // CCmDestinationData::DecrementRefCounter
       
  3190 // -----------------------------------------------------------------------------
       
  3191 void CCmDestinationData::DecrementRefCounter()
       
  3192     {
       
  3193     iRefCounter--;
       
  3194     }
       
  3195 
       
  3196 // -----------------------------------------------------------------------------
       
  3197 // CCmDestinationData::GetRefCounter
       
  3198 // -----------------------------------------------------------------------------
       
  3199 TInt CCmDestinationData::GetRefCounter()
       
  3200     {
       
  3201     return iRefCounter;
       
  3202     }
       
  3203 
       
  3204 // -----------------------------------------------------------------------------
       
  3205 // CCmDestinationImpl::GetRefCounter
       
  3206 // -----------------------------------------------------------------------------
       
  3207 TInt CCmDestinationImpl::GetRefCounter()
       
  3208     {
       
  3209     return iData->iRefCounter;
       
  3210     }
       
  3211 
       
  3212 // -----------------------------------------------------------------------------
       
  3213 // CCmDestinationImpl::GetData
       
  3214 // -----------------------------------------------------------------------------
       
  3215 CCmDestinationData* CCmDestinationImpl::GetData()
       
  3216     {
       
  3217     return iData;
       
  3218     }
       
  3219 // -----------------------------------------------------------------------------
       
  3220 // CCmDestinationImpl::SetData
       
  3221 // -----------------------------------------------------------------------------
       
  3222 void CCmDestinationImpl::SetData(CCmDestinationData* aData)
       
  3223     {
       
  3224     iData = aData;
       
  3225     }
       
  3226 
       
  3227 // -----------------------------------------------------------------------------
       
  3228 // CCmDestinationData::IdIsValid
       
  3229 // -----------------------------------------------------------------------------
       
  3230 TBool CCmDestinationData::IdIsValid()
       
  3231     {
       
  3232     return iIdIsValid;
       
  3233     }
       
  3234 
       
  3235 // -----------------------------------------------------------------------------
       
  3236 // CCmDestinationImpl::IdIsValid
       
  3237 // -----------------------------------------------------------------------------
       
  3238 TBool CCmDestinationImpl::IdIsValid()
       
  3239     {
       
  3240     return iData->iIdIsValid;
       
  3241     }
       
  3242 
       
  3243 // -----------------------------------------------------------------------------
       
  3244 // CCmDestinationImpl::Cmmgr
       
  3245 // -----------------------------------------------------------------------------
       
  3246 CCmManagerImpl* CCmDestinationData::Cmmgr()
       
  3247     {
       
  3248     return &iCmMgr;    
       
  3249     }
       
  3250 
       
  3251 // -----------------------------------------------------------------------------
       
  3252 // CCmDestinationImpl::Cmmgr
       
  3253 // -----------------------------------------------------------------------------
       
  3254 CCmManagerImpl* CCmDestinationImpl::Cmmgr()
       
  3255     {
       
  3256     return &iCmMgr;    
       
  3257     }
       
  3258 
       
  3259 // -----------------------------------------------------------------------------
       
  3260 // CCmDestinationImpl::CheckIfLocalisedDestExistL
       
  3261 //
       
  3262 // There can be only one SNAP with a certain localised metadata field set.
       
  3263 // -----------------------------------------------------------------------------
       
  3264 void CCmDestinationImpl::CheckIfLocalisedDestExistL( TUint32 aValue )
       
  3265     {
       
  3266     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfLocalisedDestExistL" );
       
  3267 
       
  3268     OpenTransactionLC();
       
  3269 
       
  3270     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3271                 new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( iCmMgr.IconTableId() );
       
  3272     CleanupStack::PushL( metaSet );
       
  3273 
       
  3274     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3275 
       
  3276     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3277         {
       
  3278         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3279                                      KCDTIdSNAPMetadataMetadata );
       
  3280 
       
  3281         if ( meta & ESnapMetadataDestinationIsLocalised )
       
  3282             {
       
  3283             TInt locval = (meta & ESnapMetadataDestinationIsLocalised) >> 4;
       
  3284             if ( aValue == locval )
       
  3285                 {
       
  3286                 if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], KCDTIdSNAPMetadataSNAP ) )
       
  3287                     {
       
  3288                     User::Leave( KErrAlreadyExists );
       
  3289                     }
       
  3290                 }
       
  3291             if ( aValue ==  ELocalisedDestInternet )
       
  3292                 { // internet might also be set the 'old way', check it!
       
  3293                 if( meta & ESnapMetadataInternet )
       
  3294                     {
       
  3295                     if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], KCDTIdSNAPMetadataSNAP ) )
       
  3296                         {
       
  3297                         User::Leave( KErrAlreadyExists );
       
  3298                         }
       
  3299                     }                
       
  3300                 }
       
  3301             }            
       
  3302         }
       
  3303 
       
  3304     CleanupStack::PopAndDestroy( metaSet );
       
  3305 
       
  3306     RollbackTransaction();
       
  3307     }
       
  3308 
       
  3309 // -----------------------------------------------------------------------------
       
  3310 // CCmDestinationImpl::CheckIfPurposeExistL
       
  3311 //
       
  3312 // There can be only one SNAP with a certain purpose metadata field set.
       
  3313 // -----------------------------------------------------------------------------
       
  3314 void CCmDestinationImpl::CheckIfPurposeExistL( TUint32 aValue )
       
  3315     {
       
  3316     LOGGER_ENTERFN( "CCmDestinationImpl::CheckIfPurposeExistL" );
       
  3317 
       
  3318     OpenTransactionLC();
       
  3319 
       
  3320     CMDBRecordSet<CCDSNAPMetadataRecord>* metaSet = 
       
  3321                 new ( ELeave ) CMDBRecordSet<CCDSNAPMetadataRecord>( iCmMgr.IconTableId() );
       
  3322     CleanupStack::PushL( metaSet );
       
  3323 
       
  3324     TRAP_IGNORE( metaSet->LoadL( Session() ) );
       
  3325 
       
  3326     for ( TInt i = 0; i < metaSet->iRecords.Count(); ++i )
       
  3327         {
       
  3328         TInt meta = QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3329                                      KCDTIdSNAPMetadataMetadata );
       
  3330 
       
  3331         if ( meta & ESnapMetadataPurpose )
       
  3332             {
       
  3333             TInt purVal = ( meta & ESnapMetadataPurpose ) >> 8;
       
  3334             if ( aValue == purVal )
       
  3335                 {
       
  3336                 if( Id() != QUERY_INT_FIELD( metaSet->iRecords[i], 
       
  3337                                         KCDTIdSNAPMetadataSNAP ) )
       
  3338                     {
       
  3339                     User::Leave( KErrAlreadyExists );
       
  3340                     }
       
  3341                 }
       
  3342             }            
       
  3343         }
       
  3344 
       
  3345     CleanupStack::PopAndDestroy( metaSet );
       
  3346 
       
  3347     RollbackTransaction();
       
  3348     }
       
  3349 
       
  3350 // -----------------------------------------------------------------------------
       
  3351 // CCmDestinationImpl::InitializeDestAPRecordL
       
  3352 //
       
  3353 // 
       
  3354 // -----------------------------------------------------------------------------
       
  3355 void CCmDestinationImpl::InitializeDestAPRecordL()
       
  3356     {
       
  3357     LOGGER_ENTERFN( "CCmDestinationImpl::InitializeDestAPRecordL" );
       
  3358 
       
  3359     SetDefaultTierManagerL();
       
  3360     SetDefaultMCprL();
       
  3361     SetDefaultCprL();
       
  3362     SetDefaultSCprL();
       
  3363     SetDefaultProtocolL();
       
  3364     iData->iDestAPRecord->iCustomSelectionPolicy = 0;
       
  3365     }
       
  3366 
       
  3367 // -----------------------------------------------------------------------------
       
  3368 // CCmDestinationImpl::SetDefaultTierManagerL
       
  3369 //
       
  3370 // 
       
  3371 // -----------------------------------------------------------------------------
       
  3372 void CCmDestinationImpl::SetDefaultTierManagerL()
       
  3373     {
       
  3374     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultTierManagerL" );
       
  3375 
       
  3376     CCDTierRecord* tierRec = static_cast<CCDTierRecord *>
       
  3377                                ( CCDRecordBase::RecordFactoryL( KCDTIdTierRecord ) );
       
  3378     CleanupStack::PushL( tierRec );
       
  3379 
       
  3380     tierRec->iRecordTag = KDefaultTierManagerTagId;
       
  3381 
       
  3382     if ( tierRec->FindL( Session() ) )
       
  3383         {
       
  3384         iData->iDestAPRecord->iTier = tierRec->ElementId();
       
  3385         }
       
  3386     else
       
  3387         {
       
  3388         User::Leave( KErrNotFound );
       
  3389         }
       
  3390 
       
  3391     CleanupStack::PopAndDestroy();
       
  3392     }
       
  3393 
       
  3394 // -----------------------------------------------------------------------------
       
  3395 // CCmDestinationImpl::SetDefaultMCprL
       
  3396 //
       
  3397 // 
       
  3398 // -----------------------------------------------------------------------------
       
  3399 void CCmDestinationImpl::SetDefaultMCprL()
       
  3400     {
       
  3401     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultMCprL" );
       
  3402 
       
  3403     CCDMCprRecord* mcprRec = static_cast<CCDMCprRecord *>
       
  3404                              ( CCDRecordBase::RecordFactoryL( KCDTIdMCprRecord ) );
       
  3405     CleanupStack::PushL( mcprRec );
       
  3406 
       
  3407     mcprRec->SetRecordId( 1 );
       
  3408 
       
  3409     mcprRec->LoadL( Session() );
       
  3410 	
       
  3411 	iData->iDestAPRecord->iMCpr = mcprRec->ElementId();
       
  3412 
       
  3413     CleanupStack::PopAndDestroy();
       
  3414     }
       
  3415 
       
  3416 // -----------------------------------------------------------------------------
       
  3417 // CCmDestinationImpl::SetDefaultCprL
       
  3418 //
       
  3419 // 
       
  3420 // -----------------------------------------------------------------------------
       
  3421 void CCmDestinationImpl::SetDefaultCprL()
       
  3422     {
       
  3423     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultCprL" );
       
  3424 
       
  3425     CCDCprRecord* cprRec = static_cast<CCDCprRecord *>
       
  3426                              ( CCDRecordBase::RecordFactoryL( KCDTIdCprRecord ) );
       
  3427     CleanupStack::PushL( cprRec );
       
  3428 
       
  3429     cprRec->SetRecordId( 1 );
       
  3430 
       
  3431     cprRec->LoadL( Session() );
       
  3432 	iData->iDestAPRecord->iCpr = cprRec->ElementId();
       
  3433 
       
  3434     CleanupStack::PopAndDestroy();
       
  3435     }
       
  3436 
       
  3437 // -----------------------------------------------------------------------------
       
  3438 // CCmDestinationImpl::SetDefaultSCprL
       
  3439 //
       
  3440 // 
       
  3441 // -----------------------------------------------------------------------------
       
  3442 void CCmDestinationImpl::SetDefaultSCprL()
       
  3443     {
       
  3444     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultSCprL" );
       
  3445 
       
  3446     CCDSCprRecord* scprRec = static_cast<CCDSCprRecord *>
       
  3447                              ( CCDRecordBase::RecordFactoryL( KCDTIdSCprRecord ) );
       
  3448     CleanupStack::PushL( scprRec );
       
  3449 
       
  3450     scprRec->SetRecordId( 1 );
       
  3451 
       
  3452     scprRec->LoadL( Session() );
       
  3453 	iData->iDestAPRecord->iSCpr = scprRec->ElementId();
       
  3454 
       
  3455     CleanupStack::PopAndDestroy();
       
  3456     }
       
  3457 
       
  3458 // -----------------------------------------------------------------------------
       
  3459 // CCmDestinationImpl::SetDefaultProtocolL
       
  3460 //
       
  3461 // 
       
  3462 // -----------------------------------------------------------------------------
       
  3463 void CCmDestinationImpl::SetDefaultProtocolL()
       
  3464     {
       
  3465     LOGGER_ENTERFN( "CCmDestinationImpl::SetDefaultProtocolL" );
       
  3466 
       
  3467     CCDProtocolRecord* protocolRec = static_cast<CCDProtocolRecord *>
       
  3468                              ( CCDRecordBase::RecordFactoryL( KCDTIdProtocolRecord ) );
       
  3469     CleanupStack::PushL( protocolRec );
       
  3470 
       
  3471     protocolRec->SetRecordId( 1 );
       
  3472 
       
  3473     protocolRec->LoadL( Session() );
       
  3474 	iData->iDestAPRecord->iProtocol = protocolRec->ElementId();
       
  3475 
       
  3476     CleanupStack::PopAndDestroy();
       
  3477     }
       
  3478 
       
  3479 // -----------------------------------------------------------------------------
       
  3480 // CCmDestinationImpl::CheckIfCMExists
       
  3481 //
       
  3482 // 
       
  3483 // -----------------------------------------------------------------------------
       
  3484 TBool CCmDestinationImpl::CheckIfCMExistsL( CCmPluginBase& aConnectionMethod )
       
  3485     {
       
  3486     TRAPD( err, (void)FindConnectionMethodL( aConnectionMethod ) );
       
  3487     if ( err )
       
  3488         {
       
  3489         if ( err == KErrNotFound )
       
  3490             {
       
  3491             return EFalse;
       
  3492             }
       
  3493         else
       
  3494             {
       
  3495             User::Leave( err );
       
  3496             }
       
  3497         }
       
  3498 
       
  3499     return ETrue;
       
  3500     }