cmmanager/cmmgr/cmmserver/src/cmmdestinationinstance.cpp
changeset 20 9c97ad6591ae
child 27 489cf6208544
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Session side object representing a destination.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <cmpluginbaseeng.h>
       
    21 #include <datamobilitycommsdattypes.h>
       
    22 #include <cmpluginembdestinationdef.h>
       
    23 
       
    24 #include "cmmdestinationinstance.h"
       
    25 #include "cmmsession.h"
       
    26 #include "cmmcache.h"
       
    27 #include "cmmconnmethodinstance.h"
       
    28 #include "cmmconnmethoditem.h"
       
    29 #include "cmmanagertextresolver.h"
       
    30 
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "cmmdestinationinstanceTraces.h"
       
    34 #endif
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Two phased construction.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CCmmDestinationInstance* CCmmDestinationInstance::NewL( CCmmSession* aCmmSession, CCmmCache* aCache )
       
    42     {
       
    43     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_NEWL_ENTRY );
       
    44 
       
    45     CCmmDestinationInstance* self = CCmmDestinationInstance::NewLC( aCmmSession, aCache );
       
    46     CleanupStack::Pop( self );
       
    47 
       
    48     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_NEWL_EXIT );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Two phased construction.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CCmmDestinationInstance* CCmmDestinationInstance::NewLC( CCmmSession* aCmmSession, CCmmCache* aCache )
       
    57     {
       
    58     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_NEWLC_ENTRY );
       
    59 
       
    60     CCmmDestinationInstance* self = new( ELeave ) CCmmDestinationInstance( aCmmSession, aCache );
       
    61     CleanupClosePushL( *self );
       
    62     self->ConstructL();
       
    63 
       
    64     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_NEWLC_EXIT );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Destructor.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CCmmDestinationInstance::~CCmmDestinationInstance()
       
    73     {
       
    74     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_CCMMDESTINATIONINSTANCE_ENTRY );
       
    75 
       
    76     // Tell cache this handle is beeing closed. Cache will update it's own
       
    77     // bookkeeping accordingly.
       
    78     if ( iCache )
       
    79         {
       
    80         iCache->CloseDestination( *this );
       
    81         }
       
    82     delete iNetworkRecord;
       
    83     delete iDestApRecord;
       
    84     delete iMetadataRecord;
       
    85 
       
    86     iConnMethodItemArray.Close();
       
    87     iConnMethodsToBeDeleted.Close();
       
    88 
       
    89     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_CCMMDESTINATIONINSTANCE_EXIT );
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Constructor.
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CCmmDestinationInstance::CCmmDestinationInstance(
       
    97         CCmmSession* aCmmSession,
       
    98         CCmmCache* aCache )
       
    99         :
       
   100         iCmmSession( aCmmSession ),
       
   101         iCache( aCache )
       
   102     {
       
   103     OstTraceFunctionEntry0( DUP1_CCMMDESTINATIONINSTANCE_CCMMDESTINATIONINSTANCE_ENTRY );
       
   104 
       
   105     iNetworkRecord = NULL;
       
   106     iDestApRecord = NULL;
       
   107     iMetadataRecord = NULL;
       
   108 
       
   109     iNetworkRecordStatus = ECmmRecordStatusBlank;
       
   110     iDestApRecordStatus = ECmmRecordStatusBlank;
       
   111     iMetadataRecordStatus = ECmmRecordStatusBlank;
       
   112 
       
   113     iStatus = ECmmDestinationStatusChanged;
       
   114     iId = 0;
       
   115     iHandle = 0;
       
   116 
       
   117     iProtectionChanged = EFalse;
       
   118     iLastProtectionLevel = CMManager::EProtLevel0;
       
   119     iCurrentProtectionLevel = CMManager::EProtLevel0;
       
   120 
       
   121     OstTraceFunctionExit0( DUP1_CCMMDESTINATIONINSTANCE_CCMMDESTINATIONINSTANCE_EXIT );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Second phase constructor.
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CCmmDestinationInstance::ConstructL()
       
   129     {
       
   130     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_CONSTRUCTL_ENTRY );
       
   131     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_CONSTRUCTL_EXIT );
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Set the destination ID.
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CCmmDestinationInstance::SetId( const TUint32& aId )
       
   139     {
       
   140     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETID_ENTRY );
       
   141 
       
   142     iId = aId;
       
   143 
       
   144     // If this is the real ID (not the temporary ID of a new unsaved destination),
       
   145     // write it also into network record.
       
   146     if ( aId > KCmmDestIdIntervalMin && aId < KCmmDestIdIntervalMax )
       
   147         {
       
   148         iNetworkRecord->SetRecordId( aId - KCmDefaultDestinationAPTagId );
       
   149         iDestApRecord->iRecordTag = aId;
       
   150         iDestApRecord->iCustomSelectionPolicy = ( aId - KCmDefaultDestinationAPTagId );
       
   151         iMetadataRecord->iSNAP = aId;
       
   152         }
       
   153 
       
   154     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETID_EXIT );
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Get the destination ID.
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 TUint32 CCmmDestinationInstance::GetId() const
       
   162     {
       
   163     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETID_ENTRY );
       
   164     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETID_EXIT );
       
   165     return iId;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Set the current status of this destination.
       
   170 // ECmmDestinationStatusValid: Contents in sync with database.
       
   171 // ECmmDestinationStatusChanged: Contents differ from database contents.
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CCmmDestinationInstance::SetStatus( const TCmmDestinationStatus& aStatus )
       
   175     {
       
   176     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETSTATUS_ENTRY );
       
   177 
       
   178     switch ( aStatus )
       
   179         {
       
   180         // Fallthrough intended
       
   181         case ECmmDestinationStatusValid:
       
   182         case ECmmDestinationStatusChanged:
       
   183             iStatus = aStatus;
       
   184             break;
       
   185         default:
       
   186             ASSERT(0); // Error, invalid status.
       
   187             break;
       
   188         }
       
   189 
       
   190     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETSTATUS_EXIT );
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Gets the current status of this destination instance.
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 TCmmDestinationStatus CCmmDestinationInstance::GetStatus() const
       
   198     {
       
   199     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETSTATUS_ENTRY );
       
   200     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETSTATUS_EXIT );
       
   201     return iStatus;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Get handle ID.
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 TInt CCmmDestinationInstance::GetHandle() const
       
   209     {
       
   210     return iHandle;
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Set handle ID.
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CCmmDestinationInstance::SetHandle( const TInt& aHandle )
       
   218     {
       
   219     iHandle = aHandle;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Set the record status for all records.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CCmmDestinationInstance::SetStatusForAllRecords( const TCmmRecordStatus& aStatus )
       
   227     {
       
   228     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETSTATUSFORALLRECORDS_ENTRY );
       
   229 
       
   230     iDestApRecordStatus = aStatus;
       
   231     iNetworkRecordStatus = aStatus;
       
   232     iMetadataRecordStatus = aStatus;
       
   233 
       
   234     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETSTATUSFORALLRECORDS_EXIT );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // Get the destination element ID.
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TUint32 CCmmDestinationInstance::GetElementIdL()
       
   242     {
       
   243     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETELEMENTIDL_ENTRY );
       
   244 
       
   245     RefreshRecordL( ECmmDestNetworkRecord );
       
   246 
       
   247     if ( !iNetworkRecord )
       
   248         {
       
   249         User::Leave( KErrCorrupt );
       
   250         }
       
   251 
       
   252     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETELEMENTIDL_EXIT );
       
   253     return iNetworkRecord->ElementId() & KCDMaskShowField;
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // Get the destination access point record's record tag (destination ID).
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 TUint32 CCmmDestinationInstance::GetRecordTagFromApRecordL()
       
   261     {
       
   262     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETRECORDTAGFROMAPRECORDL_ENTRY );
       
   263 
       
   264     RefreshRecordL( ECmmDestApRecord );
       
   265 
       
   266     if ( !iDestApRecord )
       
   267         {
       
   268         User::Leave( KErrCorrupt );
       
   269         }
       
   270 
       
   271     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETRECORDTAGFROMAPRECORDL_EXIT );
       
   272     return iDestApRecord->iRecordTag;
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Sets a record pointer to the one given as parameter, Ownership is
       
   277 // transfered. Also deletes the previous pointer and sets the record status
       
   278 // to 'ECmmRecordStatusLoaded'.
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 TInt CCmmDestinationInstance::SetRecordPointer(
       
   282         const TCmmDbRecords& aDestRecord,
       
   283         CommsDat::CCDRecordBase* aRecordPointer )
       
   284     {
       
   285     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETRECORDPOINTER_ENTRY );
       
   286 
       
   287     TInt ret( KErrNone );
       
   288     switch ( aDestRecord )
       
   289         {
       
   290         case ECmmDestNetworkRecord:
       
   291             {
       
   292             delete iNetworkRecord;
       
   293             iNetworkRecord = static_cast<CommsDat::CCDNetworkRecord*>( aRecordPointer );
       
   294             iNetworkRecordStatus = ECmmRecordStatusLoaded;
       
   295             }
       
   296             break;
       
   297         case ECmmDestApRecord:
       
   298             {
       
   299             delete iDestApRecord;
       
   300             iDestApRecord = static_cast<CommsDat::CCDAccessPointRecord*>( aRecordPointer );
       
   301             iDestApRecordStatus = ECmmRecordStatusLoaded;
       
   302             }
       
   303             break;
       
   304         case ECmmDestMetadataRecord:
       
   305             {
       
   306             delete iMetadataRecord;
       
   307             iMetadataRecord = static_cast<CCDSNAPMetadataRecord*>( aRecordPointer );
       
   308             iMetadataRecordStatus = ECmmRecordStatusLoaded;
       
   309             }
       
   310             break;
       
   311         default:
       
   312             {
       
   313             ret = KErrNotFound;
       
   314             }
       
   315             break;
       
   316         }
       
   317 
       
   318     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETRECORDPOINTER_EXIT );
       
   319     return ret;
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // Gets a reference to the requested record pointer.
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 TInt CCmmDestinationInstance::GetRecordPointer(
       
   327         const TCmmDbRecords& aDestRecord,
       
   328         CommsDat::CCDRecordBase*& aRecordPointer )
       
   329     {
       
   330     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETRECORDPOINTER_ENTRY );
       
   331 
       
   332     TInt ret( KErrNone );
       
   333     aRecordPointer = NULL;
       
   334     switch ( aDestRecord )
       
   335         {
       
   336         case ECmmDestNetworkRecord:
       
   337             {
       
   338             aRecordPointer = static_cast<CommsDat::CCDRecordBase*>( iNetworkRecord );
       
   339             }
       
   340             break;
       
   341         case ECmmDestApRecord:
       
   342             {
       
   343             aRecordPointer = static_cast<CommsDat::CCDRecordBase*>( iDestApRecord );
       
   344             }
       
   345             break;
       
   346         case ECmmDestMetadataRecord:
       
   347             {
       
   348             aRecordPointer = static_cast<CommsDat::CCDRecordBase*>( iMetadataRecord );
       
   349             }
       
   350             break;
       
   351         default:
       
   352             {
       
   353             ASSERT( 0 );
       
   354             ret = KErrNotFound;
       
   355             }
       
   356             break;
       
   357         }
       
   358 
       
   359     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETRECORDPOINTER_EXIT );
       
   360     return ret;
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // Save the contents of this destination into database. All connection methods
       
   365 // including embedded destination, that the client has open handles to, are
       
   366 // also updated.
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 void CCmmDestinationInstance::UpdateL()
       
   370     {
       
   371     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_UPDATEL_ENTRY );
       
   372 
       
   373     if ( AllMandatoryRecordsContainData() )
       
   374         {
       
   375         // Check for metadata conflicts.
       
   376         if ( ConflictingMetadataFoundL() )
       
   377             {
       
   378             OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_UPDATEL_EXIT );
       
   379 
       
   380             User::Leave( KErrAlreadyExists );
       
   381             }
       
   382 
       
   383         // Check that the destination name is still valid and not in use already.
       
   384         if ( iCache->DestinationExistsWithNameL( iNetworkRecord->iRecordName.GetL(), iId ) )
       
   385             {
       
   386             OstTraceFunctionExit0( DUP1_CCMMDESTINATIONINSTANCE_UPDATEL_EXIT );
       
   387 
       
   388             User::Leave( KErrAlreadyExists );
       
   389             }
       
   390 
       
   391         iCache->UpdateDestinationL( *this );
       
   392         }
       
   393     else
       
   394         {
       
   395         User::Leave( KErrCorrupt );
       
   396         }
       
   397 
       
   398     OstTraceFunctionExit0( DUP2_CCMMDESTINATIONINSTANCE_UPDATEL_EXIT );
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // Get the destination name.
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 TDesC& CCmmDestinationInstance::GetDestinationNameL()
       
   406     {
       
   407     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETDESTINATIONNAMEL_ENTRY );
       
   408 
       
   409     RefreshRecordL( ECmmDestNetworkRecord );
       
   410 
       
   411     if ( !iNetworkRecord )
       
   412         {
       
   413         OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETDESTINATIONNAMEL_EXIT );
       
   414 
       
   415         User::Leave( KErrCorrupt );
       
   416         }
       
   417 
       
   418     OstTraceFunctionExit0( DUP1_CCMMDESTINATIONINSTANCE_GETDESTINATIONNAMEL_EXIT );
       
   419     return iNetworkRecord->iRecordName.GetL();
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // Get the localised destination name.
       
   424 // ---------------------------------------------------------------------------
       
   425 //
       
   426 HBufC* CCmmDestinationInstance::GetLocalisedDestinationNameL()
       
   427     {
       
   428     RefreshRecordL( ECmmDestNetworkRecord );
       
   429 
       
   430     if ( !iNetworkRecord )
       
   431         {
       
   432         User::Leave( KErrCorrupt );
       
   433         }
       
   434 
       
   435     TUint32 purpose( 0 );
       
   436     GetMetadataL( CMManager::ESnapMetadataPurpose, purpose );
       
   437     HBufC* resolvedText( NULL );
       
   438     TBool isLocalised( EFalse );
       
   439     switch ( purpose )
       
   440         {
       
   441         case CMManager::ESnapPurposeInternet:
       
   442             {
       
   443             _LIT( KDestinationTextId, "txt_occ_dblist_internet");
       
   444             resolvedText = CCmManagerTextResolver::ResolveTextL( KDestinationTextId );
       
   445             isLocalised = ETrue;
       
   446             }
       
   447             break;
       
   448         case CMManager::ESnapPurposeOperator:
       
   449             {
       
   450             _LIT( KDestinationTextId, "txt_occ_dblist_operator_services");
       
   451             resolvedText = CCmManagerTextResolver::ResolveTextL( KDestinationTextId );
       
   452             isLocalised = ETrue;
       
   453             }
       
   454             break;
       
   455         case CMManager::ESnapPurposeIntranet:
       
   456             {
       
   457             _LIT( KDestinationTextId, "txt_occ_dblist_intranet");
       
   458             resolvedText = CCmManagerTextResolver::ResolveTextL( KDestinationTextId );
       
   459             isLocalised = ETrue;
       
   460             }
       
   461             break;
       
   462         default:
       
   463             break;
       
   464         }
       
   465 
       
   466     // Not Internet, operator or intranet...or something went wrong 
       
   467     if ( !isLocalised || ( isLocalised && !resolvedText ) )
       
   468         {
       
   469         resolvedText = ( iNetworkRecord->iRecordName.GetL() ).AllocL();
       
   470         }
       
   471     
       
   472     return resolvedText;
       
   473     }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 // Set the destination name.
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 void CCmmDestinationInstance::SetDestinationNameL( const TDesC& aDestinationName )
       
   480     {
       
   481     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETDESTINATIONNAMEL_ENTRY );
       
   482 
       
   483     //TODO, capability check depending on destination protection level, or if it is internet destination. Internet destination should be protected always?
       
   484 
       
   485     // Write action, load all records.
       
   486     LoadAllRecordsL();
       
   487 
       
   488     iNetworkRecord->iRecordName.SetL( aDestinationName );
       
   489     iDestApRecord->iRecordName.SetL( aDestinationName );
       
   490 
       
   491     iNetworkRecordStatus = ECmmRecordStatusModified;
       
   492     iDestApRecordStatus = ECmmRecordStatusModified;
       
   493     iStatus = ECmmDestinationStatusChanged;
       
   494 
       
   495     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETDESTINATIONNAMEL_EXIT );
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // Get metadata of specified type.
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 void CCmmDestinationInstance::GetMetadataL(
       
   503         const CMManager::TSnapMetadataField& aMetadataField,
       
   504         TUint32& aMetadata )
       
   505     {
       
   506     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETMETADATAL_ENTRY );
       
   507 
       
   508     RefreshRecordL( ECmmDestMetadataRecord );
       
   509 
       
   510     if ( !iMetadataRecord )
       
   511         {
       
   512         OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETMETADATAL_EXIT );
       
   513 
       
   514         User::Leave( KErrCorrupt );
       
   515         }
       
   516 
       
   517     switch ( aMetadataField )
       
   518         {
       
   519         case CMManager::ESnapMetadataInternet:
       
   520             aMetadata = ( TUint32 )( iMetadataRecord->iMetadata ) & CMManager::ESnapMetadataInternet;
       
   521             break;
       
   522         case CMManager::ESnapMetadataHighlight:
       
   523             aMetadata = ( TUint32 )( iMetadataRecord->iMetadata ) & CMManager::ESnapMetadataHighlight;
       
   524             break;
       
   525         case CMManager::ESnapMetadataHiddenAgent:
       
   526             aMetadata = ( TUint32 )( iMetadataRecord->iMetadata ) & CMManager::ESnapMetadataHiddenAgent;
       
   527             break;
       
   528         case CMManager::ESnapMetadataDestinationIsLocalised:
       
   529             aMetadata = ( ( TUint32 )( iMetadataRecord->iMetadata ) & CMManager::ESnapMetadataDestinationIsLocalised ) >> 4;
       
   530             break;
       
   531         case CMManager::ESnapMetadataPurpose:
       
   532             aMetadata = ( ( TUint32 )( iMetadataRecord->iMetadata ) & CMManager::ESnapMetadataPurpose ) >> 8;
       
   533             break;
       
   534         default:
       
   535             User::Leave( KErrArgument );
       
   536             break;
       
   537         }
       
   538 
       
   539     OstTraceFunctionExit0( DUP1_CCMMDESTINATIONINSTANCE_GETMETADATAL_EXIT );
       
   540     }
       
   541 
       
   542 // ---------------------------------------------------------------------------
       
   543 // Set metadata of specified type.
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CCmmDestinationInstance::SetMetadataL(
       
   547         const CMManager::TSnapMetadataField& aMetadataField,
       
   548         const TUint32& aMetadata )
       
   549     {
       
   550     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATAL_ENTRY );
       
   551 
       
   552     // Write action, load all records.
       
   553     LoadAllRecordsL();
       
   554 
       
   555     switch ( aMetadataField )
       
   556         {
       
   557         case CMManager::ESnapMetadataInternet:
       
   558             SetMetadataInternetL( aMetadata );
       
   559             break;
       
   560         case CMManager::ESnapMetadataHighlight:
       
   561             SetMetadataHighlight( aMetadata );
       
   562             break;
       
   563         case CMManager::ESnapMetadataHiddenAgent:
       
   564             SetMetadataHiddenAgentL( aMetadata );
       
   565             break;
       
   566         case CMManager::ESnapMetadataDestinationIsLocalised:
       
   567             SetMetadataLocalizationL( aMetadata );
       
   568             break;
       
   569         case CMManager::ESnapMetadataPurpose:
       
   570             SetMetadataPurposeL( aMetadata );
       
   571             break;
       
   572         default:
       
   573             User::Leave( KErrArgument );
       
   574             break;
       
   575         }
       
   576 
       
   577     iMetadataRecordStatus = ECmmRecordStatusModified;
       
   578     iStatus = ECmmDestinationStatusChanged;
       
   579 
       
   580     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATAL_EXIT );
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // Get destination protection level.
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 void CCmmDestinationInstance::GetProtectionL( CMManager::TProtectionLevel& aProtectionLevel )
       
   588     {
       
   589     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_GETPROTECTIONL_ENTRY );
       
   590 
       
   591     RefreshRecordL( ECmmDestMetadataRecord );
       
   592 
       
   593     if ( !iMetadataRecord )
       
   594         {
       
   595         User::Leave( KErrCorrupt );
       
   596         }
       
   597 
       
   598     TUint32 value = ( ( TUint32 )( iMetadataRecord->iMetadata ) & KDestProtectionLevelMask ) >> KBitsToShiftDestProtectionLevel;
       
   599     switch ( value )
       
   600         {
       
   601         case CMManager::EProtLevel0:
       
   602             aProtectionLevel = CMManager::EProtLevel0;
       
   603             break;
       
   604         case CMManager::EProtLevel1:
       
   605             aProtectionLevel = CMManager::EProtLevel1;
       
   606             break;
       
   607         case CMManager::EProtLevel2:
       
   608             aProtectionLevel = CMManager::EProtLevel2;
       
   609             break;
       
   610         case CMManager::EProtLevel3:
       
   611             aProtectionLevel = CMManager::EProtLevel3;
       
   612             break;
       
   613         default:
       
   614             User::Leave( KErrCorrupt );
       
   615             break;
       
   616         }
       
   617 
       
   618     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_GETPROTECTIONL_EXIT );
       
   619     }
       
   620 
       
   621 // ---------------------------------------------------------------------------
       
   622 // Set destination protection level.
       
   623 // ---------------------------------------------------------------------------
       
   624 //
       
   625 void CCmmDestinationInstance::SetProtectionL(
       
   626         CMManager::TProtectionLevel aProtectionLevel )
       
   627     {
       
   628     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETPROTECTIONL_ENTRY );
       
   629 
       
   630     // Write action, load all records.
       
   631     LoadAllRecordsL();
       
   632 
       
   633     //TODO, verify capability check is done (NetworkControl).
       
   634 
       
   635     iCurrentProtectionLevel = aProtectionLevel;
       
   636     if ( !iProtectionChanged )
       
   637         {
       
   638         GetProtectionL( iLastProtectionLevel );
       
   639         }
       
   640     if ( aProtectionLevel == iLastProtectionLevel )
       
   641         {
       
   642         iProtectionChanged = EFalse;
       
   643         }
       
   644     else
       
   645         {
       
   646         iProtectionChanged = ETrue;
       
   647         }
       
   648 
       
   649     // Read current metadata without protection bits.
       
   650     TUint32 currentMetadata =
       
   651             ( ( TUint32 )( iMetadataRecord->iMetadata ) & ( ~KDestProtectionLevelMask ) );
       
   652     // Add new protection bits.
       
   653     iMetadataRecord->iMetadata =
       
   654             currentMetadata | ( aProtectionLevel << KBitsToShiftDestProtectionLevel );
       
   655 
       
   656     iMetadataRecordStatus = ECmmRecordStatusModified;
       
   657     iStatus = ECmmDestinationStatusChanged;
       
   658 
       
   659     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETPROTECTIONL_EXIT );
       
   660     }
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 // Return true if protection level has been changed. 
       
   664 // ---------------------------------------------------------------------------
       
   665 //
       
   666 TBool CCmmDestinationInstance::ProtectionChanged()
       
   667     {
       
   668     return iProtectionChanged;
       
   669     }
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // Return the previous valid protection level of this connection method
       
   673 // instance.
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 CMManager::TProtectionLevel CCmmDestinationInstance::LastProtectionLevel()
       
   677     {
       
   678     return iLastProtectionLevel;
       
   679     }
       
   680 
       
   681 // ---------------------------------------------------------------------------
       
   682 // Return the protection level currently set into this destination instance.
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 CMManager::TProtectionLevel CCmmDestinationInstance::CurrentProtectionLevel()
       
   686     {
       
   687     return iCurrentProtectionLevel;
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------------------------
       
   691 // Adds a connection method into this destination. Returns the index (priority)
       
   692 // in the connection method array where the connection method was added.
       
   693 // Embedded destinations can not be added with this method, use
       
   694 // AddEmbeddedDestinationL() instead.
       
   695 // ---------------------------------------------------------------------------
       
   696 //
       
   697 TInt CCmmDestinationInstance::AddConnMethodL(
       
   698         const CCmmConnMethodInstance& aConnMethodInstance )
       
   699     {
       
   700     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_ADDCONNMETHODL_ENTRY );
       
   701 
       
   702     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
   703     TUint32 bearerType( aConnMethodInstance.GetBearerType() );
       
   704 
       
   705     // Check that the connection method is not an embedded destination.
       
   706     if ( bearerType == KUidEmbeddedDestination )
       
   707         {
       
   708         User::Leave( KErrArgument );
       
   709         }
       
   710 
       
   711     // Check that the connection method is not already inside this destination.
       
   712     for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
   713         {
       
   714         if ( connMethodId == iConnMethodItemArray[i].iId )
       
   715             {
       
   716             User::Leave( KErrAlreadyExists );
       
   717             }
       
   718         }
       
   719 
       
   720     // Remove the connection method from delete list, if found there.
       
   721     for ( TInt i = 0; i < iConnMethodsToBeDeleted.Count(); i++ )
       
   722         {
       
   723         if ( connMethodId == iConnMethodsToBeDeleted[i] )
       
   724             {
       
   725             iConnMethodsToBeDeleted.Remove( i );
       
   726             break;
       
   727             }
       
   728         }
       
   729 
       
   730     // Get the priority value of this connection method according to bearer.
       
   731     TUint bearerPriority( 0 );
       
   732     iCache->BearerPriorityFromIapRecordL(
       
   733             ( CommsDat::CCDIAPRecord* )aConnMethodInstance.GetPluginDataInstance()->iGenRecordArray[KIapRecordIndex],
       
   734             bearerPriority );
       
   735     TCmmConnMethodItem item( connMethodId, bearerType, bearerPriority, 0 );
       
   736 
       
   737     // Find out the correct position for the connection method inside this
       
   738     // destination.
       
   739     TInt index = iConnMethodItemArray.Count();
       
   740     for ( TInt i = index - 1; i >= 0; i-- )
       
   741         {
       
   742         if ( iConnMethodItemArray[i].iBearerPriority ==
       
   743                 CMManager::KDataMobilitySelectionPolicyPriorityWildCard )
       
   744             {
       
   745             index = i;
       
   746             continue;
       
   747             }
       
   748         if ( iConnMethodItemArray[i].iBearerPriority == bearerPriority )
       
   749             {
       
   750             break;
       
   751             }
       
   752         if ( iConnMethodItemArray[i].iBearerPriority > bearerPriority )
       
   753             {
       
   754             index = i;
       
   755             }
       
   756         }
       
   757     // Add the connection method item into this destination at the correct
       
   758     // position (priority).
       
   759     iConnMethodItemArray.InsertL( item, index );
       
   760 
       
   761     SetStatus( ECmmDestinationStatusChanged );
       
   762 
       
   763     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_ADDCONNMETHODL_EXIT );
       
   764     return index;
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // Adds an embedded destination into this destination. Returns the index in
       
   769 // the connection method array where the connection method was added.
       
   770 // ---------------------------------------------------------------------------
       
   771 //
       
   772 TInt CCmmDestinationInstance::AddEmbeddedDestinationL(
       
   773         const CCmmDestinationInstance& aEmbeddedDestinationInstance )
       
   774     {
       
   775     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_ADDEMBEDDEDDESTINATIONL_ENTRY );
       
   776 
       
   777     TUint32 embeddedDestinationId( aEmbeddedDestinationInstance.GetId() );
       
   778 
       
   779     // Check that not adding itself.
       
   780     if ( embeddedDestinationId == iId )
       
   781         {
       
   782         User::Leave( KErrArgument );
       
   783         }
       
   784 
       
   785     // Check that the embedded destination is not already an embedded
       
   786     // destination in this destination.
       
   787     if ( HasEmbeddedWithId( embeddedDestinationId ) )
       
   788         {
       
   789         User::Leave( KErrAlreadyExists );
       
   790         }
       
   791 
       
   792     // A destination can not be added into a destination that is itself an
       
   793     // embedded destination.
       
   794     if ( iCache->DestinationIsEmbedded( iId ) )
       
   795         {
       
   796         User::Leave( KErrNotSupported );
       
   797         }
       
   798 
       
   799     // A destination can not be added into a destination that already has an
       
   800     // embedded destination.
       
   801     if ( HasEmbedded() || iCache->DestinationHasEmbedded( iId ) )
       
   802         {
       
   803         User::Leave( KErrNotSupported );
       
   804         }
       
   805 
       
   806     // A destination that already has an embedded destination can not be added
       
   807     // into a destination.
       
   808     if ( aEmbeddedDestinationInstance.HasEmbedded() ||
       
   809             iCache->DestinationHasEmbedded( embeddedDestinationId ) )
       
   810         {
       
   811         User::Leave( KErrNotSupported );
       
   812         }
       
   813 
       
   814     // Check session side destination instances for all clients.
       
   815     // - Check that any destination instance does not contain aDestinationId as
       
   816     //   embedded destination.
       
   817     // - Check that any destination instance for aEmbeddedDestinationId does
       
   818     //   not contain an embedded destination.
       
   819     if ( iCmmSession->EmbeddedDestinationConflictsFromAllSessions( iId, embeddedDestinationId ) )
       
   820         {
       
   821         User::Leave( KErrAlreadyExists );
       
   822         }
       
   823 
       
   824     // Add the embedded destination at the end of the connection method item array.
       
   825     TInt index = iConnMethodItemArray.Count();
       
   826     TCmmConnMethodItem item(
       
   827             embeddedDestinationId,
       
   828             KUidEmbeddedDestination,
       
   829             CMManager::KDataMobilitySelectionPolicyPriorityWildCard,
       
   830             0 );
       
   831     iConnMethodItemArray.AppendL( item );
       
   832 
       
   833     SetStatus( ECmmDestinationStatusChanged );
       
   834 
       
   835     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_ADDEMBEDDEDDESTINATIONL_EXIT );
       
   836     return index;
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // Delete a connection method that belongs to this destination. If the
       
   841 // connection method belongs to any other destination, it is only removed from
       
   842 // this destination and not deleted. Does not call update.
       
   843 // ---------------------------------------------------------------------------
       
   844 //
       
   845 void CCmmDestinationInstance::DeleteConnMethodFromDestinationL(
       
   846         const CCmmConnMethodInstance& aConnMethodInstance )
       
   847     {
       
   848     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_DELETECONNMETHODFROMDESTINATIONL_ENTRY );
       
   849 
       
   850     // Check that the connection method is inside this destination.
       
   851     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
   852     TInt index( KErrNotFound );
       
   853     for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
   854         {
       
   855         if ( connMethodId == iConnMethodItemArray[i].iId )
       
   856             {
       
   857             index = i;
       
   858             break;
       
   859             }
       
   860         }
       
   861     if ( index < 0 )
       
   862         {
       
   863         User::Leave( KErrArgument );
       
   864         }
       
   865 
       
   866     // Check if the connection method removal is blocked by any virtual IAPs.
       
   867     if ( ConnMethodInDestinationButLocked( connMethodId ) )
       
   868         {
       
   869         User::Leave( KErrLocked );
       
   870         }
       
   871 
       
   872     // Check if any virtual IAP points to this connection method, thus blocking
       
   873     // the delete.
       
   874     if ( iCache->ConnMethodPointedToByVirtualIap( connMethodId ) )
       
   875         {
       
   876         User::Leave( KErrLocked );
       
   877         }
       
   878 
       
   879     // Check that the connection method is not in use by an active connection.
       
   880     if ( iCache->CheckIfCmConnected( connMethodId ) )
       
   881         {
       
   882         User::Leave( KErrInUse );
       
   883         }
       
   884 
       
   885     // This will also remove an embedded destination.
       
   886     iConnMethodItemArray.Remove( index );
       
   887     SetStatus( ECmmDestinationStatusChanged );
       
   888 
       
   889     // If this connection method is an embedded destination, then removing it
       
   890     // from this destination is enough. The destination is not deleted.
       
   891     if ( aConnMethodInstance.GetBearerType() != KUidEmbeddedDestination )
       
   892         {
       
   893         // Add connection method to delete list only if not referenced from any
       
   894         // other destination (in database or in any destination handles for the
       
   895         // client currently beeing served).
       
   896         if ( !iCache->ConnMethodInOtherDestination( connMethodId, iId ) &&
       
   897                 !iCmmSession->ConnMethodInOtherDestination( connMethodId, iId ) )
       
   898             {
       
   899             if ( iConnMethodsToBeDeleted.Find( connMethodId ) == KErrNotFound )
       
   900                 {
       
   901                 iConnMethodsToBeDeleted.AppendL( connMethodId );
       
   902                 }
       
   903             }
       
   904         }
       
   905 
       
   906     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_DELETECONNMETHODFROMDESTINATIONL_EXIT );
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // Remove a connection method from this destination. If the second attribute
       
   911 // aTestIfConnected is false, the test to check if connection method is in use
       
   912 // is skipped. In this case this should have been already tested by the caller.
       
   913 // ---------------------------------------------------------------------------
       
   914 //
       
   915 void CCmmDestinationInstance::RemoveConnMethodFromDestinationL(
       
   916         const CCmmConnMethodInstance& aConnMethodInstance,
       
   917         const TBool& aTestIfConnected )
       
   918     {
       
   919     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_REMOVECONNMETHODFROMDESTINATIONL_ENTRY );
       
   920 
       
   921     // Check that the connection method is inside this destination.
       
   922     TUint32 connMethodId( aConnMethodInstance.GetId() );
       
   923     TInt index( KErrNotFound );
       
   924     for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
   925         {
       
   926         if ( connMethodId == iConnMethodItemArray[i].iId )
       
   927             {
       
   928             index = i;
       
   929             break;
       
   930             }
       
   931         }
       
   932     if ( index < 0 )
       
   933         {
       
   934         User::Leave( KErrArgument );
       
   935         }
       
   936 
       
   937     // Check if the connection method removal is blocked by any virtual IAPs.
       
   938     if ( ConnMethodInDestinationButLocked( connMethodId ) )
       
   939         {
       
   940         User::Leave( KErrLocked );
       
   941         }
       
   942 
       
   943     if ( aTestIfConnected )
       
   944         {
       
   945         // Check that the connection method is not in use by an active connection.
       
   946         if ( iCache->CheckIfCmConnected( connMethodId ) )
       
   947             {
       
   948             User::Leave( KErrInUse );
       
   949             }
       
   950         }
       
   951 
       
   952     // This will also remove an embedded destination.
       
   953     iConnMethodItemArray.Remove( index );
       
   954     SetStatus( ECmmDestinationStatusChanged );
       
   955 
       
   956     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_REMOVECONNMETHODFROMDESTINATIONL_EXIT );
       
   957     }
       
   958 
       
   959 // ---------------------------------------------------------------------------
       
   960 // Modifies the priority of a connection method inside this destination.
       
   961 // ---------------------------------------------------------------------------
       
   962 //
       
   963 void CCmmDestinationInstance::ModifyConnMethodPriorityL(
       
   964         const CCmmConnMethodInstance& aConnMethodInstance,
       
   965         TUint aIndex )
       
   966     {
       
   967     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_MODIFYCONNMETHODPRIORITYL_ENTRY );
       
   968 
       
   969     // Check if the connection method is in this destination. Also store the
       
   970     // current index of the connection method.
       
   971     TInt oldIndex( KErrNotFound );
       
   972     for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
   973         {
       
   974         if ( iConnMethodItemArray[i].iId == aConnMethodInstance.GetId() )
       
   975             {
       
   976             oldIndex = i;
       
   977             break;
       
   978             }
       
   979         }
       
   980     if ( oldIndex < 0 )
       
   981         {
       
   982         User::Leave( KErrArgument );
       
   983         }
       
   984 
       
   985     // If connection method is an embedded destination, just return silently.
       
   986     if ( aConnMethodInstance.GetBearerType() == KUidEmbeddedDestination )
       
   987         {
       
   988         OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_MODIFYCONNMETHODPRIORITYL_EXIT );
       
   989         return;
       
   990         }
       
   991 
       
   992     //TODO, if CM is virtual IAP that points into DESTINATION, just return silently.
       
   993     //
       
   994     //
       
   995 
       
   996     // Check index range.
       
   997     if ( aIndex >= iConnMethodItemArray.Count() )
       
   998         {
       
   999         User::Leave( KErrArgument );
       
  1000         }
       
  1001 
       
  1002     // If the given index points to any wildcard priority connection method,
       
  1003     // adjust it so it points to the last priority position.
       
  1004     TUint numberOfConnMethodsWithPriority( NumberOfConnMethodsWithPriority() );
       
  1005     if ( aIndex >= numberOfConnMethodsWithPriority )
       
  1006         {
       
  1007         if ( numberOfConnMethodsWithPriority == 0 )
       
  1008             {
       
  1009             // Can't be 0, since aConnMethodInstance is not a wildcard IAP and
       
  1010             // is in the array.
       
  1011             ASSERT( 0 );
       
  1012             User::Leave( KErrCorrupt );
       
  1013             }
       
  1014         aIndex = numberOfConnMethodsWithPriority--;
       
  1015         }
       
  1016 
       
  1017     // Check if the priority is changing from current.
       
  1018     if ( oldIndex == aIndex )
       
  1019         {
       
  1020         OstTraceFunctionExit0( DUP1_CCMMDESTINATIONINSTANCE_MODIFYCONNMETHODPRIORITYL_EXIT );
       
  1021         return;
       
  1022         }
       
  1023 
       
  1024     // Change the location of the connection method to reflect the new priority.
       
  1025     TCmmConnMethodItem item = iConnMethodItemArray[oldIndex];
       
  1026     iConnMethodItemArray.Remove( oldIndex );
       
  1027     iConnMethodItemArray.InsertL( item, ( TInt )aIndex );
       
  1028 
       
  1029     SetStatus( ECmmDestinationStatusChanged );
       
  1030 
       
  1031     OstTraceFunctionExit0( DUP2_CCMMDESTINATIONINSTANCE_MODIFYCONNMETHODPRIORITYL_EXIT );
       
  1032     }
       
  1033 
       
  1034 // ---------------------------------------------------------------------------
       
  1035 // Finds a connection method instance that belongs to the same session and
       
  1036 // matches the provided ID. Return NULL if no match is found.
       
  1037 // ---------------------------------------------------------------------------
       
  1038 //
       
  1039 CCmmConnMethodInstance* CCmmDestinationInstance::FindConnMethodInstanceFromSessionById(
       
  1040         const TUint32& aConnMethodId ) const
       
  1041     {
       
  1042     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_FINDCONNMETHODINSTANCEFROMSESSIONBYID_ENTRY );
       
  1043 
       
  1044     CCmmConnMethodInstance* connMethodInstance = iCmmSession->
       
  1045             FindConnMethodInstanceById( aConnMethodId );
       
  1046 
       
  1047     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_FINDCONNMETHODINSTANCEFROMSESSIONBYID_EXIT );
       
  1048     return connMethodInstance;
       
  1049     }
       
  1050 
       
  1051 // ---------------------------------------------------------------------------
       
  1052 // Finds a destination instance that belongs to the same session and matches
       
  1053 // the provided ID. Return NULL if no match is found.
       
  1054 // ---------------------------------------------------------------------------
       
  1055 //
       
  1056 CCmmDestinationInstance* CCmmDestinationInstance::FindDestinationInstanceFromSessionById(
       
  1057         const TUint32& aDestinationId ) const
       
  1058     {
       
  1059     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_FINDDESTINATIONINSTANCEFROMSESSIONBYID_ENTRY );
       
  1060 
       
  1061     CCmmDestinationInstance* destInstance =
       
  1062             iCmmSession->FindDestinationInstanceById( aDestinationId );
       
  1063 
       
  1064     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_FINDDESTINATIONINSTANCEFROMSESSIONBYID_EXIT );
       
  1065     return destInstance;
       
  1066     }
       
  1067 
       
  1068 // ---------------------------------------------------------------------------
       
  1069 // Check from all open destination handles in the same session if the given
       
  1070 // connection method is inside any of them. The given destination is skipped.
       
  1071 // ---------------------------------------------------------------------------
       
  1072 //
       
  1073 TBool CCmmDestinationInstance::ConnMethodInOtherDestinationInSession(
       
  1074         const TUint32& aConnMethodId,
       
  1075         const TUint32& aDestinationId ) const
       
  1076     {
       
  1077     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_CONNMETHODINOTHERDESTINATIONINSESSION_ENTRY );
       
  1078 
       
  1079     TBool inOtherSession = iCmmSession->
       
  1080             ConnMethodInOtherDestination( aConnMethodId, aDestinationId );
       
  1081 
       
  1082     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_CONNMETHODINOTHERDESTINATIONINSESSION_EXIT );
       
  1083     return inOtherSession;
       
  1084     }
       
  1085 
       
  1086 // ---------------------------------------------------------------------------
       
  1087 // Check if the given connection method is in this destination. Include
       
  1088 // embedded destinations.
       
  1089 // ---------------------------------------------------------------------------
       
  1090 //
       
  1091 TBool CCmmDestinationInstance::ValidConnMethodIdInDestinationIncludeEmbedded( const TUint32& aConnMethodId ) const
       
  1092     {
       
  1093     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_VALIDCONNMETHODIDINDESTINATIONINCLUDEEMBEDDED_ENTRY );
       
  1094 
       
  1095     TBool validity( EFalse );
       
  1096     if ( aConnMethodId > 0 )
       
  1097         {
       
  1098         for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
  1099             {
       
  1100             if ( iConnMethodItemArray[i].iId == aConnMethodId )
       
  1101                 {
       
  1102                 validity = ETrue;
       
  1103                 break;
       
  1104                 }
       
  1105             }
       
  1106         }
       
  1107 
       
  1108     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_VALIDCONNMETHODIDINDESTINATIONINCLUDEEMBEDDED_EXIT );
       
  1109     return validity;
       
  1110     }
       
  1111 
       
  1112 // ---------------------------------------------------------------------------
       
  1113 // Check if the given connection method is inside this destination and if it
       
  1114 // is in a 'locked' status. A locked connection method can't be deleted nor
       
  1115 // removed from the destination. A connection method becomes locked if it is
       
  1116 // the only remaining connection method in a destination and a virtual IAP
       
  1117 // points into that destination.
       
  1118 // ---------------------------------------------------------------------------
       
  1119 //
       
  1120 TBool CCmmDestinationInstance::ConnMethodInDestinationButLocked(
       
  1121         const TUint32& aConnMethodId ) const
       
  1122     {
       
  1123     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_CONNMETHODINDESTINATIONBUTLOCKED_ENTRY );
       
  1124 
       
  1125     TBool result( EFalse );
       
  1126     if ( iConnMethodItemArray.Count() == 1 )
       
  1127         {
       
  1128         if ( iConnMethodItemArray[0].iId == aConnMethodId )
       
  1129             {
       
  1130             if ( iCache->DestinationPointedToByVirtualIap( iId ) )
       
  1131                 {
       
  1132                 result = ETrue;
       
  1133                 }
       
  1134             }
       
  1135         }
       
  1136 
       
  1137     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_CONNMETHODINDESTINATIONBUTLOCKED_EXIT );
       
  1138     return result;
       
  1139     }
       
  1140 
       
  1141 // ---------------------------------------------------------------------------
       
  1142 // Counts how many connection methods that require priority information are
       
  1143 // currently in this destination. This excludes any virtual IAPs that point to
       
  1144 // a destination or any embedded destinations from the count. Assumes the
       
  1145 // connection method array is in order so all wildcard priority IAPs are at the
       
  1146 // end of the list.
       
  1147 // ---------------------------------------------------------------------------
       
  1148 //
       
  1149 TUint CCmmDestinationInstance::NumberOfConnMethodsWithPriority() const
       
  1150     {
       
  1151     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_NUMBEROFCONNMETHODSWITHPRIORITY_ENTRY );
       
  1152 
       
  1153     TUint count( iConnMethodItemArray.Count() );
       
  1154 
       
  1155     for ( TUint i = 0; i < iConnMethodItemArray.Count(); i++ )
       
  1156         {
       
  1157         //TODO, add virtual IAP pointing to SNAP check.
       
  1158         if ( iConnMethodItemArray[i].iBearerType == KUidEmbeddedDestination )
       
  1159             {
       
  1160             count = i;
       
  1161             break;
       
  1162             }
       
  1163         }
       
  1164 
       
  1165     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_NUMBEROFCONNMETHODSWITHPRIORITY_EXIT );
       
  1166     return count;
       
  1167     }
       
  1168 
       
  1169 // ---------------------------------------------------------------------------
       
  1170 // Check if this destination has an embedded destination. Checks the current
       
  1171 // (possibly unsaved) status of this destination handle, not the current status
       
  1172 // in database.
       
  1173 // ---------------------------------------------------------------------------
       
  1174 //
       
  1175 TBool CCmmDestinationInstance::HasEmbedded() const
       
  1176     {
       
  1177     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_HASEMBEDDED_ENTRY );
       
  1178 
       
  1179     TBool result( EFalse );
       
  1180 
       
  1181     // If there is an embedded destination, it will be at the very last
       
  1182     // position in the connection method item array.
       
  1183     TInt index = iConnMethodItemArray.Count() - 1;
       
  1184     if ( index >= 0 )
       
  1185         {
       
  1186         if ( iConnMethodItemArray[index].iBearerType == KUidEmbeddedDestination )
       
  1187             {
       
  1188             result = ETrue;
       
  1189             }
       
  1190         }
       
  1191 
       
  1192     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_HASEMBEDDED_EXIT );
       
  1193     return result;
       
  1194     }
       
  1195 
       
  1196 // ---------------------------------------------------------------------------
       
  1197 // Check if this destination has an embedded destination with the specified ID.
       
  1198 // Checks the current (possibly unsaved) status of this destination handle, not
       
  1199 // the current status in database.
       
  1200 // ---------------------------------------------------------------------------
       
  1201 //
       
  1202 TBool CCmmDestinationInstance::HasEmbeddedWithId( const TUint32& aDestinationId ) const
       
  1203     {
       
  1204     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_HASEMBEDDEDWITHID_ENTRY );
       
  1205 
       
  1206     TBool result( EFalse );
       
  1207 
       
  1208     // If there is an embedded destination, it will be at the very last
       
  1209     // position in the connection method item array.
       
  1210     TInt index = iConnMethodItemArray.Count() - 1;
       
  1211     if ( index >= 0 )
       
  1212         {
       
  1213         // No need to check bearer, since ID will not match anyway if the last
       
  1214         // item is not an embedded destination.
       
  1215         if ( iConnMethodItemArray[index].iId == aDestinationId )
       
  1216             {
       
  1217             result = ETrue;
       
  1218             }
       
  1219         }
       
  1220 
       
  1221     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_HASEMBEDDEDWITHID_EXIT );
       
  1222     return result;
       
  1223     }
       
  1224 
       
  1225 // ---------------------------------------------------------------------------
       
  1226 // After update/delete to database, refresh temporary ID to real ID if
       
  1227 // necessary and refresh status information for any related handles for
       
  1228 // all client sessions.
       
  1229 // ---------------------------------------------------------------------------
       
  1230 //
       
  1231 void CCmmDestinationInstance::RefreshHandlesForAllSessions( const TCmmIdStruct& aIdStruct )
       
  1232     {
       
  1233     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_REFRESHHANDLESFORALLSESSIONS_ENTRY );
       
  1234 
       
  1235     iCmmSession->RefreshHandlesForAllSessions( aIdStruct );
       
  1236 
       
  1237     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_REFRESHHANDLESFORALLSESSIONS_EXIT );
       
  1238     }
       
  1239 
       
  1240 // ---------------------------------------------------------------------------
       
  1241 // If the destination contains a connection method with matching temporary ID,
       
  1242 // updates the ID to real ID. This is done after the connection method has been
       
  1243 // successfully saved into the database.
       
  1244 // ---------------------------------------------------------------------------
       
  1245 //
       
  1246 void CCmmDestinationInstance::RefreshConnMethodId( const TCmmIdStruct& aIdStruct )
       
  1247     {
       
  1248     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_REFRESHCONNMETHODID_ENTRY );
       
  1249 
       
  1250     for ( TInt i = 0; i < iConnMethodItemArray.Count(); i++ )
       
  1251         {
       
  1252         if ( iConnMethodItemArray[i].iId == aIdStruct.iTemporaryId )
       
  1253             {
       
  1254             iConnMethodItemArray[i].iId = aIdStruct.iRealId;
       
  1255             break;
       
  1256             }
       
  1257         }
       
  1258 
       
  1259     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_REFRESHCONNMETHODID_EXIT );
       
  1260     }
       
  1261 
       
  1262 // ---------------------------------------------------------------------------
       
  1263 // Called after this destination has been updated and database transaction has
       
  1264 // completed successfully. Sets the internal state of this destination instance
       
  1265 // to reflect the new valid state.
       
  1266 // ---------------------------------------------------------------------------
       
  1267 //
       
  1268 void CCmmDestinationInstance::UpdateSuccessful()
       
  1269     {
       
  1270     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_UPDATESUCCESSFUL_ENTRY );
       
  1271 
       
  1272     SetStatus( ECmmDestinationStatusValid );
       
  1273     SetStatusForAllRecords( ECmmRecordStatusLoaded );
       
  1274     iConnMethodsToBeDeleted.Reset();
       
  1275     iProtectionChanged = EFalse;
       
  1276 
       
  1277     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_UPDATESUCCESSFUL_EXIT );
       
  1278     }
       
  1279 
       
  1280 // ---------------------------------------------------------------------------
       
  1281 // Checks if all mandatory records contain data and are ready to be saved into
       
  1282 // database.
       
  1283 // ---------------------------------------------------------------------------
       
  1284 //
       
  1285 TBool CCmmDestinationInstance::AllMandatoryRecordsContainData() const
       
  1286     {
       
  1287     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_ALLMANDATORYRECORDSCONTAINDATA_ENTRY );
       
  1288 
       
  1289     TBool result( ETrue );
       
  1290 
       
  1291     if ( iNetworkRecordStatus != ECmmRecordStatusLoaded &&
       
  1292             iNetworkRecordStatus != ECmmRecordStatusExpired &&
       
  1293             iNetworkRecordStatus != ECmmRecordStatusModified )
       
  1294         {
       
  1295         result = EFalse;
       
  1296         }
       
  1297     if ( iDestApRecordStatus != ECmmRecordStatusLoaded &&
       
  1298             iDestApRecordStatus != ECmmRecordStatusExpired &&
       
  1299             iDestApRecordStatus != ECmmRecordStatusModified )
       
  1300         {
       
  1301         result = EFalse;
       
  1302         }
       
  1303     if ( iMetadataRecordStatus != ECmmRecordStatusLoaded &&
       
  1304             iMetadataRecordStatus != ECmmRecordStatusExpired &&
       
  1305             iMetadataRecordStatus != ECmmRecordStatusModified )
       
  1306         {
       
  1307         result = EFalse;
       
  1308         }
       
  1309     if ( !iNetworkRecord || !iDestApRecord || !iMetadataRecord )
       
  1310         {
       
  1311         result = EFalse;
       
  1312         }
       
  1313 
       
  1314     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_ALLMANDATORYRECORDSCONTAINDATA_EXIT );
       
  1315     return result;
       
  1316     }
       
  1317 
       
  1318 // ---------------------------------------------------------------------------
       
  1319 // Loads a certain type of record from database if it is not up-to-date.
       
  1320 // ---------------------------------------------------------------------------
       
  1321 //
       
  1322 void CCmmDestinationInstance::RefreshRecordL( TCmmDbRecords aRecordType )
       
  1323     {
       
  1324     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_REFRESHRECORDL_ENTRY );
       
  1325 
       
  1326     TCmmRecordStatus status( ECmmRecordStatusBlank );
       
  1327     switch ( aRecordType )
       
  1328         {
       
  1329         case ECmmDestNetworkRecord:
       
  1330             status = iNetworkRecordStatus;
       
  1331             break;
       
  1332         case ECmmDestApRecord:
       
  1333             status = iDestApRecordStatus;
       
  1334             break;
       
  1335         case ECmmDestMetadataRecord:
       
  1336             status = iMetadataRecordStatus;
       
  1337             break;
       
  1338         default:
       
  1339             User::Leave( KErrCorrupt ); // Error, unknown type.
       
  1340             break;
       
  1341         }
       
  1342 
       
  1343     switch ( status )
       
  1344         {
       
  1345         // Fallthrough intended
       
  1346         case ECmmRecordStatusBlank:
       
  1347         case ECmmRecordStatusExpired:
       
  1348             iCache->LoadDestinationRecordL( *this, aRecordType );
       
  1349             break;
       
  1350         case ECmmRecordStatusLoaded:
       
  1351         case ECmmRecordStatusModified:
       
  1352             // Record is up-to-date.
       
  1353             break;
       
  1354         case ECmmRecordStatusUnsaved:
       
  1355         default:
       
  1356             User::Leave( KErrCorrupt ); // Error, unknown status.
       
  1357             break;
       
  1358         }
       
  1359 
       
  1360     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_REFRESHRECORDL_EXIT );
       
  1361     }
       
  1362 
       
  1363 // ---------------------------------------------------------------------------
       
  1364 // Loads all records from database that are not up-to-date.
       
  1365 // ---------------------------------------------------------------------------
       
  1366 //
       
  1367 void CCmmDestinationInstance::LoadAllRecordsL()
       
  1368     {
       
  1369     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_LOADALLRECORDSL_ENTRY );
       
  1370 
       
  1371     RefreshRecordL( ECmmDestNetworkRecord );
       
  1372     RefreshRecordL( ECmmDestApRecord );
       
  1373     RefreshRecordL( ECmmDestMetadataRecord );
       
  1374 
       
  1375     if ( !iNetworkRecord || !iDestApRecord || !iMetadataRecord )
       
  1376         {
       
  1377         User::Leave( KErrCorrupt );
       
  1378         }
       
  1379 
       
  1380     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_LOADALLRECORDSL_EXIT );
       
  1381     }
       
  1382 
       
  1383 // ---------------------------------------------------------------------------
       
  1384 // Set metadata of type ESnapMetadataInternet.
       
  1385 // ---------------------------------------------------------------------------
       
  1386 //
       
  1387 void CCmmDestinationInstance::SetMetadataInternetL( const TUint32& aMetadata )
       
  1388     {
       
  1389     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATAINTERNETL_ENTRY );
       
  1390 
       
  1391     if ( aMetadata )
       
  1392         {
       
  1393         if ( iCache->DestinationExistsWithMetadataLocalizedL( *this, CMManager::ELocalisedDestInternet ) )
       
  1394             {
       
  1395             User::Leave( KErrAlreadyExists );
       
  1396             }
       
  1397         // Clear ESnapMetadataHiddenAgent-bit.
       
  1398         TUint32 value = iMetadataRecord->iMetadata & ( ~CMManager::ESnapMetadataHiddenAgent );
       
  1399 
       
  1400         // Set old ESnapMetadataInternet-bit.
       
  1401         value = value | CMManager::ESnapMetadataInternet;
       
  1402 
       
  1403         // Clear ESnapMetadataDestinationIsLocalised-bits.
       
  1404         value = value & ( ~CMManager::ESnapMetadataDestinationIsLocalised );
       
  1405         // Set ELocalisedDestInternet-value.
       
  1406         iMetadataRecord->iMetadata = value | ( CMManager::ELocalisedDestInternet << 4 );
       
  1407         value = value | ( CMManager::ELocalisedDestInternet << 4 );
       
  1408 
       
  1409         // Clear ESnapMetadataPurpose-bits.
       
  1410         value = value & ( ~CMManager::ESnapMetadataPurpose );
       
  1411         // Set ESnapPurposeInternet-value.
       
  1412         iMetadataRecord->iMetadata = value | ( CMManager::ESnapPurposeInternet << 8 );
       
  1413         }
       
  1414     else
       
  1415         {
       
  1416         // Clear old ESnapMetadataInternet-bit, ESnapMetadataDestinationIsLocalised-bits and CMManager::ESnapMetadataPurpose-bits.
       
  1417         TUint32 temp = ~( CMManager::ESnapMetadataInternet | CMManager::ESnapMetadataDestinationIsLocalised | CMManager::ESnapMetadataPurpose );
       
  1418         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata & temp;
       
  1419         }
       
  1420 
       
  1421     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATAINTERNETL_EXIT );
       
  1422     }
       
  1423 
       
  1424 // ---------------------------------------------------------------------------
       
  1425 // Set metadata of type ESnapMetadataHighlight.
       
  1426 // ---------------------------------------------------------------------------
       
  1427 //
       
  1428 void CCmmDestinationInstance::SetMetadataHighlight( const TUint32& aMetadata )
       
  1429     {
       
  1430     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATAHIGHLIGHTL_ENTRY );
       
  1431 
       
  1432     // TODO: Old CmManager does not perform any duplicate checks when setting highlight.
       
  1433     // Now with single click this is not used anymore anyway. So I suggest we don't add any checks here.
       
  1434     if ( aMetadata )
       
  1435         {
       
  1436         // Set ESnapMetadataHighlight-bit.
       
  1437         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata | CMManager::ESnapMetadataHighlight;
       
  1438         }
       
  1439     else
       
  1440         {
       
  1441         // Clear ESnapMetadataHighlight-bit.
       
  1442         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata & ( ~CMManager::ESnapMetadataHighlight );
       
  1443         }
       
  1444 
       
  1445     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATAHIGHLIGHTL_EXIT );
       
  1446     }
       
  1447 
       
  1448 // ---------------------------------------------------------------------------
       
  1449 // Set metadata of type ESnapMetadataHiddenAgent.
       
  1450 // ---------------------------------------------------------------------------
       
  1451 //
       
  1452 void CCmmDestinationInstance::SetMetadataHiddenAgentL( const TUint32& aMetadata )
       
  1453     {
       
  1454     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATAHIDDENAGENTL_ENTRY );
       
  1455 
       
  1456     if ( aMetadata )
       
  1457         {
       
  1458         TUint32 metadataInternet(    iMetadataRecord->iMetadata & CMManager::ESnapMetadataInternet                      );
       
  1459         TUint32 metadataLocalized( ( iMetadataRecord->iMetadata & CMManager::ESnapMetadataDestinationIsLocalised ) >> 4 );
       
  1460         TUint32 metadataPurpose(   ( iMetadataRecord->iMetadata & CMManager::ESnapMetadataPurpose                ) >> 8 );
       
  1461         if ( metadataInternet ||
       
  1462                 ( metadataLocalized == CMManager::ELocalisedDestInternet ) ||
       
  1463                 ( metadataPurpose == CMManager::ESnapPurposeInternet ) )
       
  1464             {
       
  1465             // Not allowed to set ESnapMetadataHiddenAgent if destination is localized or has purpose set.
       
  1466             User::Leave( KErrArgument );
       
  1467             }
       
  1468         // Set ESnapMetadataHiddenAgent-bit.
       
  1469         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata | CMManager::ESnapMetadataHiddenAgent;
       
  1470         }
       
  1471     else
       
  1472         {
       
  1473         // Clear ESnapMetadataHiddenAgent-bit.
       
  1474         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata & ( ~CMManager::ESnapMetadataHiddenAgent );
       
  1475         }
       
  1476 
       
  1477     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATAHIDDENAGENTL_EXIT );
       
  1478     }
       
  1479 
       
  1480 // ---------------------------------------------------------------------------
       
  1481 // Set metadata of type ESnapMetadataDestinationIsLocalised.
       
  1482 // ---------------------------------------------------------------------------
       
  1483 //
       
  1484 void CCmmDestinationInstance::SetMetadataLocalizationL( const TUint32& aMetadata )
       
  1485     {
       
  1486     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATALOCALIZATIONL_ENTRY );
       
  1487 
       
  1488     // Check that aMetadata is within valid range.
       
  1489     if ( aMetadata > CMManager::ELocalisedDestIntranet )
       
  1490         {
       
  1491         User::Leave( KErrArgument );
       
  1492         }
       
  1493 
       
  1494     TUint32 temp = ~( CMManager::ESnapMetadataInternet | CMManager::ESnapMetadataDestinationIsLocalised | CMManager::ESnapMetadataPurpose );
       
  1495     if ( aMetadata == CMManager::ENotLocalisedDest )
       
  1496         {
       
  1497         // Clear old ESnapMetadataInternet-bit, ESnapMetadataDestinationIsLocalised-bits and ESnapMetadataPurpose-bits.
       
  1498         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata & temp;
       
  1499         }
       
  1500     else
       
  1501         {
       
  1502         if ( iCache->DestinationExistsWithMetadataLocalizedL( *this, aMetadata ) )
       
  1503             {
       
  1504             User::Leave( KErrAlreadyExists );
       
  1505             }
       
  1506 
       
  1507         // Clear old ESnapMetadataInternet-bit, ESnapMetadataDestinationIsLocalised-bits and ESnapMetadataPurpose-bits.
       
  1508         TUint32 value = iMetadataRecord->iMetadata & temp;
       
  1509         switch ( aMetadata )
       
  1510             {
       
  1511             case CMManager::ELocalisedDestInternet:
       
  1512                 {
       
  1513                 // Clear ESnapMetadataHiddenAgent-bit.
       
  1514                 value = value & ( ~CMManager::ESnapMetadataHiddenAgent );
       
  1515                 // Set old ESnapMetadataInternet-bit.
       
  1516                 value = value | CMManager::ESnapMetadataInternet;
       
  1517                 // Set ESnapPurposeInternet-value.
       
  1518                 value = value | ( CMManager::ESnapPurposeInternet << 8 );
       
  1519                 }
       
  1520                 break;
       
  1521             case CMManager::ELocalisedDestWap:
       
  1522                 {
       
  1523                 // Set ESnapPurposeOperator-value.
       
  1524                 value = value | ( CMManager::ESnapPurposeOperator << 8 );
       
  1525                 }
       
  1526                 break;
       
  1527             case CMManager::ELocalisedDestMMS:
       
  1528                 {
       
  1529                 // Set ESnapMetadataHiddenAgent-bit.
       
  1530                 value = value | CMManager::ESnapMetadataHiddenAgent;
       
  1531                 // Set ESnapPurposeMMS-value.
       
  1532                 value = value | ( CMManager::ESnapPurposeMMS << 8 );
       
  1533                 }
       
  1534                 break;
       
  1535             case CMManager::ELocalisedDestIntranet:
       
  1536                 {
       
  1537                 // Set ESnapPurposeIntranet-value.
       
  1538                 value = value | ( CMManager::ESnapPurposeIntranet << 8 );
       
  1539                 }
       
  1540                 break;
       
  1541             default:
       
  1542                 User::Leave( KErrArgument );
       
  1543                 break;
       
  1544             }
       
  1545         // Set ESnapMetadataDestinationIsLocalised-value.
       
  1546         iMetadataRecord->iMetadata = value | ( aMetadata << 4 );
       
  1547         }
       
  1548 
       
  1549     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATALOCALIZATIONL_EXIT );
       
  1550     }
       
  1551 
       
  1552 // ---------------------------------------------------------------------------
       
  1553 // Set metadata of type ESnapMetadataPurpose.
       
  1554 // ---------------------------------------------------------------------------
       
  1555 //
       
  1556 void CCmmDestinationInstance::SetMetadataPurposeL( const TUint32& aMetadata )
       
  1557     {
       
  1558     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_SETMETADATAPURPOSEL_ENTRY );
       
  1559 
       
  1560     // Check that aMetadata is within valid range.
       
  1561     if ( aMetadata > CMManager::ESnapPurposeIntranet )
       
  1562         {
       
  1563         User::Leave( KErrArgument );
       
  1564         }
       
  1565 
       
  1566     TUint32 temp = ~( CMManager::ESnapMetadataInternet | CMManager::ESnapMetadataDestinationIsLocalised | CMManager::ESnapMetadataPurpose );
       
  1567     if ( aMetadata == CMManager::ESnapPurposeUnknown )
       
  1568         {
       
  1569         // Clear old ESnapMetadataInternet-bit, ESnapMetadataDestinationIsLocalised-bits and ESnapMetadataPurpose-bits.
       
  1570         iMetadataRecord->iMetadata = iMetadataRecord->iMetadata & temp;
       
  1571         }
       
  1572     else
       
  1573         {
       
  1574         if ( iCache->DestinationExistsWithMetadataPurposeL( *this, aMetadata ) )
       
  1575             {
       
  1576             User::Leave( KErrAlreadyExists );
       
  1577             }
       
  1578 
       
  1579         // Clear old ESnapMetadataInternet-bit, ESnapMetadataDestinationIsLocalised-bits and ESnapMetadataPurpose-bits.
       
  1580         TUint32 value = iMetadataRecord->iMetadata & temp;
       
  1581 
       
  1582         switch ( aMetadata )
       
  1583             {
       
  1584             case CMManager::ESnapPurposeInternet:
       
  1585                 {
       
  1586                 // Clear ESnapMetadataHiddenAgent-bit.
       
  1587                 value = value & ( ~CMManager::ESnapMetadataHiddenAgent );
       
  1588                 // Set old ESnapMetadataInternet-bit.
       
  1589                 value = value | CMManager::ESnapMetadataInternet;
       
  1590                 // Set ELocalisedDestInternet-value.
       
  1591                 value = value | ( CMManager::ELocalisedDestInternet << 4 );
       
  1592                 }
       
  1593                 break;
       
  1594             case CMManager::ESnapPurposeOperator:
       
  1595                 {
       
  1596                 // Set ELocalisedDestWap-value.
       
  1597                 value = value | ( CMManager::ELocalisedDestWap << 4 );
       
  1598                 }
       
  1599                 break;
       
  1600             case CMManager::ESnapPurposeMMS:
       
  1601                 {
       
  1602                 // Set ESnapMetadataHiddenAgent-bit.
       
  1603                 value = value | CMManager::ESnapMetadataHiddenAgent;
       
  1604                 // Set ELocalisedDestMMS-value.
       
  1605                 value = value | ( CMManager::ELocalisedDestMMS << 4 );
       
  1606                 }
       
  1607                 break;
       
  1608             case CMManager::ESnapPurposeIntranet:
       
  1609                 {
       
  1610                 // Set ELocalisedDestIntranet-value.
       
  1611                 value = value | ( CMManager::ELocalisedDestIntranet << 4 );
       
  1612                 }
       
  1613                 break;
       
  1614             default:
       
  1615                 User::Leave( KErrArgument );
       
  1616                 break;
       
  1617             }
       
  1618         // Set ESnapMetadataPurpose-value.
       
  1619         iMetadataRecord->iMetadata = value | ( aMetadata << 8 );
       
  1620         }
       
  1621 
       
  1622     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_SETMETADATAPURPOSEL_EXIT );
       
  1623     }
       
  1624 
       
  1625 // ---------------------------------------------------------------------------
       
  1626 // Checks the current metadata for this destination, and verifies there is no
       
  1627 // other conflicting destinations in the database.
       
  1628 // ---------------------------------------------------------------------------
       
  1629 //
       
  1630 TBool CCmmDestinationInstance::ConflictingMetadataFoundL()
       
  1631     {
       
  1632     OstTraceFunctionEntry0( CCMMDESTINATIONINSTANCE_CONFLICTINGMETADATAFOUNDL_ENTRY );
       
  1633 
       
  1634     TBool result( EFalse );
       
  1635     TUint32 metadataInternet(    iMetadataRecord->iMetadata & CMManager::ESnapMetadataInternet                      );
       
  1636     TUint32 metadataLocalized( ( iMetadataRecord->iMetadata & CMManager::ESnapMetadataDestinationIsLocalised ) >> 4 );
       
  1637     TUint32 metadataPurpose(   ( iMetadataRecord->iMetadata & CMManager::ESnapMetadataPurpose                ) >> 8 );
       
  1638 
       
  1639     if ( metadataPurpose )
       
  1640         {
       
  1641         // Some metadata is set, need to check conflicts in database.
       
  1642         switch ( metadataPurpose )
       
  1643             {
       
  1644             // Fallthrough intended.
       
  1645             case CMManager::ESnapPurposeInternet:
       
  1646             case CMManager::ESnapPurposeOperator:
       
  1647             case CMManager::ESnapPurposeMMS:
       
  1648             case CMManager::ESnapPurposeIntranet:
       
  1649                 result = iCache->DestinationExistsWithMetadataPurposeL( *this, metadataPurpose );
       
  1650                 break;
       
  1651             default:
       
  1652                 User::Leave( KErrCorrupt ); // Invalid metadata.
       
  1653                 break;
       
  1654             }
       
  1655         }
       
  1656     else if ( metadataLocalized )
       
  1657         {
       
  1658         // Error, metadataPurpose was not set. Continue anyway.
       
  1659         switch ( metadataLocalized )
       
  1660             {
       
  1661             // Fallthrough intended.
       
  1662             case CMManager::ELocalisedDestInternet:
       
  1663             case CMManager::ELocalisedDestWap:
       
  1664             case CMManager::ELocalisedDestMMS:
       
  1665             case CMManager::ELocalisedDestIntranet:
       
  1666                 result = iCache->DestinationExistsWithMetadataLocalizedL( *this, metadataLocalized );
       
  1667                 break;
       
  1668             default:
       
  1669                 User::Leave( KErrCorrupt ); // Invalid metadata.
       
  1670                 break;
       
  1671             }
       
  1672         }
       
  1673     else if ( metadataInternet )
       
  1674         {
       
  1675         // Error, metadataPurpose and metadataLocalized was not set. Continue anyway.
       
  1676         result = iCache->DestinationExistsWithMetadataLocalizedL( *this, CMManager::ELocalisedDestInternet );
       
  1677         }
       
  1678 
       
  1679     OstTraceFunctionExit0( CCMMDESTINATIONINSTANCE_CONFLICTINGMETADATAFOUNDL_EXIT );
       
  1680     return result;
       
  1681     }
       
  1682 
       
  1683 // End of file