commsfwtools/preparedefaultcommsdatabase/src/CommsDatMapperAndValidatorUtils.cpp
changeset 0 dfb7c4ff071f
child 12 8b5d60ce1e94
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // CommsDatMapperAndValidatorUtils.h
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
    19 
       
    20 
       
    21 #include "CommsDatMapperAndValidatorUtils.h"
       
    22 
       
    23 #include <metadatabase.h>
       
    24 #include <commsdattypesv1_1.h>
       
    25 
       
    26 #include <commsdattypesv1_1_partner.h>
       
    27 
       
    28 #include "CommsDatInternalDefs.h"
       
    29 #include "MetaDatabaseVisitor.h"
       
    30 #include <commsdatutils.h>
       
    31 #include <comms-infras/commsdatschema.h>
       
    32 
       
    33 using namespace Meta;
       
    34 using namespace CommsDatInternal;
       
    35 using namespace CommsDat;
       
    36 
       
    37 TInt CommsDatMapperAndValidator::GenerateTagIdL(TInt aBaseTagId, CMDBSession& aSession)
       
    38     {
       
    39     TInt tagId = aBaseTagId;
       
    40     CMDBField<TInt>* possibleTagId = new(ELeave) CMDBField<TInt>(KCDTIdAccessPointRecord | KCDTIdRecordTag);
       
    41     CleanupStack::PushL(possibleTagId);
       
    42     *possibleTagId = tagId;
       
    43     
       
    44     //as we don't know anything about the AccessPoints in the AccessPointTable we have to try the 
       
    45     //uniqueness of the given tagId... 
       
    46     while ( possibleTagId->FindL(aSession) )
       
    47         {
       
    48         *possibleTagId = ++tagId;
       
    49     
       
    50         }
       
    51     CleanupStack::PopAndDestroy(possibleTagId);
       
    52     return tagId;
       
    53     }
       
    54 
       
    55 void CommsDatMapperAndValidator::GenerateRecordName(TDes& aBuffer, TInt aUniqueNumber)
       
    56     {
       
    57     aBuffer.Append(KIPProtoTag());
       
    58     
       
    59     TBuf<MAX_BUFFER_LEN_FOR_NAMING> buf;
       
    60     buf.Format(_L("%D"), aUniqueNumber);
       
    61     
       
    62     aBuffer.Append(buf);
       
    63     }
       
    64 
       
    65 TInt CommsDatMapperAndValidator::GetDefAPPrioritySelPolLinkValueL(CMDBSession& aSession)
       
    66     {
       
    67     // Search for the default Tier in the GlobalSettings Record 
       
    68     // (The Global Settings record has to be stored before inserting 
       
    69     // the ConnectionPreferences record!!!!).
       
    70     CMDBRecordLink<CCDTierRecord>* defaultTierField = new(ELeave) CMDBRecordLink<CCDTierRecord>(KCDTIdGlobalSettingsRecord | KCDTIdDefaultTier);
       
    71     defaultTierField->SetRecordId(1);
       
    72     CleanupStack::PushL(defaultTierField);
       
    73     
       
    74     // this field HAS to be in the GlobalSettings table as we are in 399 config...
       
    75     defaultTierField->LoadL(aSession);
       
    76     
       
    77     // Follow the defaultAccessPoint link in the defaultTier record which points to
       
    78     // the default AP record on the Network level.
       
    79     TInt recId = (*defaultTierField) << 8;
       
    80     CMDBRecordLink<CCDAccessPointRecord>* networkDefAPField = 
       
    81                     new(ELeave) CMDBRecordLink<CCDAccessPointRecord>(recId |
       
    82                                                                      KCDTIdDefaultAccessPoint);
       
    83     CleanupStack::PushL(networkDefAPField);
       
    84     
       
    85     networkDefAPField->LoadL(aSession);
       
    86     
       
    87     //Follow the link from the default AP record to the linked APPrioritySelPol record.
       
    88     CMDBRecordLink<CCDAPPrioritySelectionPolicyRecord>* networkSelPolField = 
       
    89                     new(ELeave) CMDBRecordLink<CCDAPPrioritySelectionPolicyRecord>(((*networkDefAPField) & KCDMaskShowRecordId) |
       
    90                                                                                    KCDTIdSelectionPolicy);
       
    91     CleanupStack::PushL(networkSelPolField);
       
    92     
       
    93     networkSelPolField->LoadL(aSession);
       
    94     
       
    95     TInt defSelPolLinkValue = *networkSelPolField;
       
    96     
       
    97     CleanupStack::PopAndDestroy(networkSelPolField);
       
    98     CleanupStack::PopAndDestroy(networkDefAPField);
       
    99     CleanupStack::PopAndDestroy(defaultTierField);
       
   100     
       
   101     return defSelPolLinkValue;
       
   102     }
       
   103 
       
   104 CCDAPPrioritySelectionPolicyRecord* CommsDatMapperAndValidator::FindTheAPPrioritySelPolRecL(CMDBSession& aSession)
       
   105     {
       
   106     TInt defSelPolLinkValue = GetDefAPPrioritySelPolLinkValueL(aSession);
       
   107     //at this point we already know the complete elementId of the default APPrioritySelPol record.
       
   108     //Read the whole record because it will be needed by the IPProto AP generation logic...
       
   109     
       
   110     CCDAPPrioritySelectionPolicyRecord* defAPSelPolRec = static_cast<CCDAPPrioritySelectionPolicyRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdApPrioritySelectionPolicyRecord));
       
   111                     
       
   112     CleanupStack::PushL(defAPSelPolRec);
       
   113     
       
   114     defAPSelPolRec->SetElementId(defSelPolLinkValue);
       
   115     defAPSelPolRec->LoadL(aSession);
       
   116     
       
   117     //we will transfer the ownership of this object to the caller method
       
   118     CleanupStack::Pop(defAPSelPolRec);
       
   119     
       
   120     return defAPSelPolRec;
       
   121     }
       
   122 
       
   123 CCDAccessPointRecord* CommsDatMapperAndValidator::GenerateIPProtoAPL(TInt aTagGenerationBase, 
       
   124                                                                      TInt aLinkLevelAPTagId,
       
   125                                                                      CMDBSession& aSession)
       
   126     {
       
   127     CCDAccessPointRecord* apRecordToBeCreated = static_cast<CCDAccessPointRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdAccessPointRecord));
       
   128     CleanupStack::PushL(apRecordToBeCreated);
       
   129     
       
   130     CCDBearerTypeRecord* templateForTheAPRec = static_cast<CCDBearerTypeRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdBearerTypeRecord));
       
   131     CleanupStack::PushL(templateForTheAPRec);
       
   132     
       
   133     templateForTheAPRec->iRecordName.SetMaxLengthL(KIPProtoTemplateRecName().Length());
       
   134     templateForTheAPRec->iRecordName = KIPProtoTemplateRecName();
       
   135         
       
   136     if (!templateForTheAPRec->FindL(aSession))
       
   137         {
       
   138         User::Leave(KErrNotFound);
       
   139         }
       
   140     
       
   141     //buffer for the record name
       
   142     TBuf<KMaxName> recordName;
       
   143     
       
   144     //as the IAP and AP records are inserted before it won't cause 
       
   145     //any problem to use the 'KCDNewRecordRequest' for the record IDs.
       
   146     apRecordToBeCreated->SetRecordId(KCDNewRecordRequest);
       
   147     
       
   148     apRecordToBeCreated->iRecordTag = GenerateTagIdL(aTagGenerationBase, aSession);
       
   149 	
       
   150 	GenerateRecordName(recordName, apRecordToBeCreated->iRecordTag);
       
   151 	
       
   152 	apRecordToBeCreated->iRecordName.SetMaxLengthL(recordName.Length());
       
   153     apRecordToBeCreated->iRecordName = recordName;
       
   154     apRecordToBeCreated->iSelectionPolicy = 0;
       
   155 	apRecordToBeCreated->iTier.SetL(templateForTheAPRec->iTier);
       
   156 	apRecordToBeCreated->iMCpr.SetL(templateForTheAPRec->iMCpr);
       
   157 	apRecordToBeCreated->iCpr.SetL(templateForTheAPRec->iCpr);
       
   158 	apRecordToBeCreated->iSCpr.SetL(templateForTheAPRec->iSCpr);
       
   159 	apRecordToBeCreated->iProtocol.SetL(templateForTheAPRec->iProtocol);
       
   160     CMDBField<TInt>* custFiel = &(apRecordToBeCreated->iCustomSelectionPolicy);
       
   161     *custFiel = aLinkLevelAPTagId;
       
   162     apRecordToBeCreated->iCprConfig.SetL(aLinkLevelAPTagId);
       
   163     
       
   164     CleanupStack::PopAndDestroy(templateForTheAPRec);
       
   165     
       
   166     //the ownership will be transferred
       
   167     CleanupStack::Pop(apRecordToBeCreated);
       
   168     
       
   169     return apRecordToBeCreated;
       
   170     }
       
   171 
       
   172 /**
       
   173     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
   174     
       
   175     The basic assumption here is that the ConnectionPreferences table (if there is one in the config 
       
   176     file) and the IAPPrioritySelectionPolicy table are consistent. This means that if the ConnPref table
       
   177     contains ranking2 IAP too then the IAPPrioritySelPol table contanins the same number of the IAP
       
   178     links. So here in this method the only cases which are handled are that this record contains 1 or 2
       
   179     links.
       
   180     
       
   181     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       
   182 */
       
   183 void CommsDatMapperAndValidator::ModifyAPPrioritySelPolRecL(CMDBRecordLink<CCDAccessPointRecord>*& aFieldInRecord,
       
   184                                                            CCDAPPrioritySelectionPolicyRecord*& aAPSelPolRec,
       
   185                                                            TInt aAPElementId)
       
   186     {
       
   187     //the link update  
       
   188     *aFieldInRecord = aAPElementId;
       
   189     
       
   190     //The APCount update
       
   191     TMetaVTableIterator attribIter(aAPSelPolRec);
       
   192     SVDataTableEntry const* entry = 0;
       
   193     TInt fieldCounter(1);
       
   194     CMDBRecordLink<CCDAccessPointRecord>* apPrioritySelPolLink = NULL;
       
   195     
       
   196     while ( (entry = attribIter++) != NULL && 
       
   197             fieldCounter <= 2 )
       
   198         {
       
   199         apPrioritySelPolLink = reinterpret_cast<CMDBRecordLink<CCDAccessPointRecord>*>(aAPSelPolRec->GetAttribPtr(entry->iOffset));
       
   200         ++fieldCounter;        
       
   201         }
       
   202     
       
   203     if (0 != (*apPrioritySelPolLink))
       
   204     	{
       
   205     	//the 2nd AP link is filled in the APPrioritySelPol rec -> the APCount is 2
       
   206     	aAPSelPolRec->iApCount.SetL(MaxNumberOfLinks);
       
   207     	}
       
   208     else
       
   209     	{
       
   210     	aAPSelPolRec->iApCount.SetL(1);
       
   211     	}
       
   212     
       
   213     }
       
   214 
       
   215 void CommsDatMapperAndValidator::CheckTheAPPrioritySelPolFromConnPrefModL(CCDAPPrioritySelectionPolicyRecord*& aAPSelPolRec)
       
   216     {
       
   217     //TBool modified = EFalse;
       
   218     
       
   219     TMetaVTableIterator attribIter(aAPSelPolRec);
       
   220     SVDataTableEntry const* entry = 0;
       
   221     TInt fieldCounter(1);
       
   222     CMDBRecordLink<CCDAccessPointRecord>* apPrioritySelPolLink = NULL;
       
   223     
       
   224     while ( (entry = attribIter++) != NULL && 
       
   225             fieldCounter <= 15 )
       
   226         {
       
   227         apPrioritySelPolLink = reinterpret_cast<CMDBRecordLink<CCDAccessPointRecord>*>(aAPSelPolRec->GetAttribPtr(entry->iOffset));
       
   228         
       
   229         if (apPrioritySelPolLink &&
       
   230             *apPrioritySelPolLink &&
       
   231             fieldCounter > MaxNumberOfLinks)
       
   232             //This branch is executed if there is inconsistency between the ConnPref and the IAPPrioritySelPol
       
   233             //table. Now we are processing a ConnectionPreference table and the default APPrioritySelPol record
       
   234             //contains more the 2 AP links. This means that earlier an IAPPrioritySelPol record was converted
       
   235             //to this APPrioritySelPol record (meaning a SNAP configuration) and that record contains more than
       
   236             //2 IAP links. At the same time the configuration contains a ConnPref table too which can contain
       
   237             //maximum 2 IAP links. So here the previosly stored APPrioritySelPol record will be modified to
       
   238             //contain only 2 AP links - according to the ConnPref table.
       
   239             {
       
   240             /**
       
   241                 the link is lost.
       
   242                 e.g. if it was an AP3 link, which is not valid in the default APPriotySelPol record, it will be 0ed.
       
   243             */
       
   244             *apPrioritySelPolLink = 0;
       
   245             __FLOG_STATIC0(KLogComponent, KCDInfoLog, _L("CommsDatMapperAndValidator::CheckTheAPPrioritySelPolFromConnPrefMod - inconsistency between the ConnPref and IAPPrioritySelPol table!!"));
       
   246             aAPSelPolRec->iApCount.SetL(MaxNumberOfLinks);
       
   247             //modified = ETrue;
       
   248             }
       
   249             
       
   250         ++fieldCounter;
       
   251         
       
   252         }
       
   253     //return modified;
       
   254     }
       
   255 
       
   256 //this method will read and modify (storing the modified record)    
       
   257 void CommsDatMapperAndValidator::ModifyDefaultTierRecordL(TInt aAPElementId, 
       
   258                                                           CommsDat::CMDBSession& aSession)
       
   259     {
       
   260     CCDTierRecord* ipProtoTierRec = static_cast<CCDTierRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdTierRecord));
       
   261     CleanupStack::PushL(ipProtoTierRec);
       
   262     
       
   263     ipProtoTierRec->SetRecordId(GetIPProtoTierRecordIdL(aSession));
       
   264     
       
   265     ipProtoTierRec->LoadL(aSession);
       
   266     
       
   267     ipProtoTierRec->iDefaultAccessPoint.SetL(aAPElementId);
       
   268     
       
   269     //save the modified IPProto Tier Record
       
   270     ipProtoTierRec->ModifyL(aSession);
       
   271         
       
   272     CleanupStack::PopAndDestroy(ipProtoTierRec);
       
   273     }
       
   274 
       
   275 //this function returns the record id of the network tier record
       
   276 TInt CommsDatMapperAndValidator::GetNetworkTierRecordIdL(CommsDat::CMDBSession& aSession)
       
   277 	{
       
   278 	CMDBField<TInt>* networkTierTag = new(ELeave)CMDBField<TInt>(KCDTIdTierRecord | KCDTIdRecordTag);
       
   279 	CleanupStack::PushL(networkTierTag);
       
   280 	
       
   281 	*networkTierTag = ENetworkLevelTierId;
       
   282 	
       
   283 	TInt recId = 0;
       
   284 	if(networkTierTag->FindL(aSession))
       
   285 		{
       
   286 		recId = networkTierTag->RecordId();
       
   287 		}
       
   288 	
       
   289 	CleanupStack::PopAndDestroy(networkTierTag);
       
   290 	
       
   291 	return recId;
       
   292 	}
       
   293 
       
   294 TInt CommsDatMapperAndValidator::GetIPProtoTierRecordIdL(CommsDat::CMDBSession& aSession)
       
   295 	{
       
   296 	CMDBField<TInt>* ipprotoTierTag = new(ELeave)CMDBField<TInt>(KCDTIdTierRecord | KCDTIdRecordTag);
       
   297 	CleanupStack::PushL(ipprotoTierTag);
       
   298 	
       
   299 	*ipprotoTierTag = EIPProtoTierId;
       
   300 	
       
   301 	TInt recId = 0;
       
   302 	if(ipprotoTierTag->FindL(aSession))
       
   303 		{
       
   304 		recId = ipprotoTierTag->RecordId();
       
   305 		}
       
   306 	
       
   307 	CleanupStack::PopAndDestroy(ipprotoTierTag);
       
   308 	
       
   309 	return recId;
       
   310 	}
       
   311 
       
   312 TBool CommsDatMapperAndValidator::IsIPProtoAPAlreadyExistL(TInt aLinkLevelTagId,
       
   313 														  CommsDat::CMDBSession& aSession)
       
   314 	{
       
   315 	TBool ret = EFalse;
       
   316 	
       
   317 	CMDBField<TInt>* ipprotoCustSelPolField = new(ELeave)CMDBField<TInt>(KCDTIdCustomSelectionPolicy);
       
   318 	CleanupStack::PushL(ipprotoCustSelPolField);
       
   319 	
       
   320 	*ipprotoCustSelPolField = aLinkLevelTagId;
       
   321 	
       
   322 	if (ipprotoCustSelPolField->FindL(aSession))
       
   323 		{
       
   324 		ret = ETrue;
       
   325 		}
       
   326 	
       
   327 	CleanupStack::PopAndDestroy(ipprotoCustSelPolField);
       
   328 	
       
   329 	return ret;
       
   330 	}
       
   331 
       
   332 TBool CommsDatMapperAndValidator::IsIPProtoAPAlreadyExistL(TInt aLinkLevelTagId, 
       
   333 														   TInt aConnPrefElementId, 
       
   334 														   CommsDat::CMDBSession& aSession)
       
   335 	{
       
   336 	TBool ret = EFalse;
       
   337 	
       
   338 	CCDAccessPointRecord* apRec = static_cast<CCDAccessPointRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdAccessPointRecord));
       
   339 	CleanupStack::PushL(apRec);
       
   340 	
       
   341 	apRec->iCprConfig = aConnPrefElementId;
       
   342 	apRec->iCustomSelectionPolicy = aLinkLevelTagId;
       
   343 	
       
   344 	if (apRec->FindL(aSession))
       
   345 		{
       
   346 		ret = ETrue;
       
   347 		}
       
   348 	
       
   349 	CleanupStack::PopAndDestroy(apRec);
       
   350 	
       
   351 	return ret;
       
   352 	}
       
   353 
       
   354 CommsDat::CCDAccessPointRecord* CommsDatMapperAndValidator::LoadTheAPL(TInt aLinkLevelTagId,
       
   355 										   							   CommsDat::CMDBSession& aSession)
       
   356 	{
       
   357     CCDAccessPointRecord* apRec = static_cast<CCDAccessPointRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdAccessPointRecord));
       
   358     CleanupStack::PushL(apRec);
       
   359     
       
   360     apRec->iCustomSelectionPolicy = aLinkLevelTagId;
       
   361     
       
   362     if(!apRec->FindL(aSession))
       
   363     	{
       
   364     	//no records were found with the given customSelectionPolicy value
       
   365     	User::Leave(KErrNotFound);
       
   366     	}
       
   367     
       
   368     CleanupStack::Pop(apRec);
       
   369     
       
   370     return apRec;
       
   371 	}
       
   372 
       
   373 /* All of the APPrioritySelectionPolicy fields are exemined checking that how many
       
   374  * fields, in different APPrioritySelPol records, are referencing the given AP
       
   375  * record. The recordSet->FindL with a primed record is not suitable here because
       
   376  * the link can occur in any field of the APPrioritySelPol record.
       
   377  */
       
   378 TInt CommsDatMapperAndValidator::CountReferenceToThisIPProtoAPL(TUint aElementId, CommsDat::CMDBSession& aSession)
       
   379 	{
       
   380 	TInt refCount = 0;
       
   381 	
       
   382 	CMDBRecordSet<CCDAPPrioritySelectionPolicyRecord>* apprioritySelPolRecSet = new(ELeave)CMDBRecordSet<CCDAPPrioritySelectionPolicyRecord>(KCDTIdApPrioritySelectionPolicyRecord);
       
   383 	CleanupStack::PushL(apprioritySelPolRecSet);
       
   384 	
       
   385 	//do the hard work and read all of the appriorityselpol recs...
       
   386 	apprioritySelPolRecSet->LoadL(aSession);
       
   387 	
       
   388 	TInt recCount = apprioritySelPolRecSet->iRecords.Count();
       
   389 	
       
   390 	CCDAPPrioritySelectionPolicyRecord* curAPPrioritySelPolRec = NULL;
       
   391 
       
   392 	TInt fieldCounter = 0;
       
   393     
       
   394 	for (TInt i = 0; i < recCount; ++i)
       
   395 		{
       
   396 		//loop for the records
       
   397 		curAPPrioritySelPolRec = static_cast<CCDAPPrioritySelectionPolicyRecord*>(apprioritySelPolRecSet->iRecords[i]);
       
   398 		
       
   399         TMetaVTableIterator inputAttribIter(curAPPrioritySelPolRec);
       
   400         SVDataTableEntry const* inputEntry = NULL;
       
   401         
       
   402         fieldCounter = CCDAPPrioritySelectionPolicyRecord::EMaxNrOfAps;
       
   403         
       
   404         while ( (inputEntry = inputAttribIter++)    != NULL &&
       
   405                 fieldCounter-- > 0 )
       
   406             {
       
   407             //loop for the fields
       
   408             CMDBField<TUint32>* inputFieldPtr = reinterpret_cast<CMDBField<TUint32>*>(curAPPrioritySelPolRec->GetAttribPtr(inputEntry->iOffset));
       
   409             if ( inputFieldPtr && 
       
   410             	 aElementId == *inputFieldPtr )
       
   411                 {
       
   412                 ++refCount;
       
   413                 }
       
   414             }
       
   415 		}
       
   416 	
       
   417 	CleanupStack::PopAndDestroy(apprioritySelPolRecSet);
       
   418 	
       
   419 	return refCount;
       
   420 	}
       
   421 
       
   422 //Note - the ownership of the 'aTheAlreadyDeletedRecord' is transferred here!!!!!!
       
   423 TInt CommsDatMapperAndValidator::CountReferenceToThisIPProtoAPL(TUint aElementId, 
       
   424 										   						CommsDat::CCDAPPrioritySelectionPolicyRecord* aTheAlreadyDeletedRecord,
       
   425 										   						CommsDat::CMDBSession& aSession)
       
   426 	{
       
   427 	CleanupStack::PushL(aTheAlreadyDeletedRecord);
       
   428 	
       
   429 	TInt refCount = 0;
       
   430 		
       
   431 	CMDBRecordSet<CCDAPPrioritySelectionPolicyRecord>* apprioritySelPolRecSet = new(ELeave)CMDBRecordSet<CCDAPPrioritySelectionPolicyRecord>(KCDTIdApPrioritySelectionPolicyRecord);
       
   432 	CleanupStack::PushL(apprioritySelPolRecSet);
       
   433 	
       
   434 	//do the hard work and read all of the appriorityselpol recs...
       
   435 	apprioritySelPolRecSet->LoadL(aSession);
       
   436 	
       
   437 	//and add the already deleted APPrioritySelPol record to the list
       
   438 	//note that the ownership of the pointer is now at the recordset!!!!!
       
   439 	apprioritySelPolRecSet->iRecords.AppendL(aTheAlreadyDeletedRecord);
       
   440 	
       
   441 	/* here as the ownership of the 'aTheAlreadyDeletedRecord' pointer is transferred
       
   442 	 * to the recordset so we have to pop it from the CleanupStack. BUT there is already
       
   443 	 * another pointer 'apprioritySelPolRecSet'. So in order to pop the 'aTheAlreadyDeletedRecord'
       
   444 	 * we have to pop the 'apprioritySelPolRecSet' too and push it back again...
       
   445 	 */
       
   446 	CleanupStack::Pop(apprioritySelPolRecSet);
       
   447 	CleanupStack::Pop(aTheAlreadyDeletedRecord);
       
   448 	
       
   449 	CleanupStack::PushL(apprioritySelPolRecSet);
       
   450 	
       
   451 	TInt recCount = apprioritySelPolRecSet->iRecords.Count();
       
   452 	
       
   453 	CCDAPPrioritySelectionPolicyRecord* curAPPrioritySelPolRec = NULL;
       
   454 
       
   455 	TInt fieldCounter = 0;
       
   456     
       
   457 	for (TInt i = 0; i < recCount; ++i)
       
   458 		{
       
   459 		//loop for the records
       
   460 		curAPPrioritySelPolRec = static_cast<CCDAPPrioritySelectionPolicyRecord*>(apprioritySelPolRecSet->iRecords[i]);
       
   461 		
       
   462         TMetaVTableIterator inputAttribIter(curAPPrioritySelPolRec);
       
   463         SVDataTableEntry const* inputEntry = NULL;
       
   464         
       
   465         fieldCounter = CCDAPPrioritySelectionPolicyRecord::EMaxNrOfAps;
       
   466         
       
   467         while ( (inputEntry = inputAttribIter++)    != NULL &&
       
   468                 fieldCounter-- > 0 )
       
   469             {
       
   470             //loop for the fields
       
   471             CMDBField<TUint32>* inputFieldPtr = reinterpret_cast<CMDBField<TUint32>*>(curAPPrioritySelPolRec->GetAttribPtr(inputEntry->iOffset));
       
   472             if ( inputFieldPtr && 
       
   473             	 aElementId == *inputFieldPtr )
       
   474                 {
       
   475                 ++refCount;
       
   476                 }
       
   477             }
       
   478 		}
       
   479 	
       
   480 	CleanupStack::PopAndDestroy(apprioritySelPolRecSet);
       
   481 	
       
   482 	return refCount;
       
   483 	}
       
   484 
       
   485 TBool CommsDatMapperAndValidator::IsIAPRecInDB(CommsDat::CMDBSession& aSession)
       
   486 	{
       
   487 	TBool ret = EFalse;
       
   488 	
       
   489 	CMDBRecordSet<CCDIAPRecord>* iapRecSet = new(ELeave)CMDBRecordSet<CCDIAPRecord>(KCDTIdIAPRecord);
       
   490 	CleanupStack::PushL(iapRecSet);
       
   491 	
       
   492 	TRAPD(err, iapRecSet->LoadL(aSession));
       
   493 	
       
   494 	if (KErrNone == err &&
       
   495 		iapRecSet->iRecords.Count() > 0)
       
   496 		{
       
   497 		ret = ETrue;
       
   498 		}
       
   499 	
       
   500 	CleanupStack::PopAndDestroy(iapRecSet);
       
   501 	
       
   502 	return ret;
       
   503 	}
       
   504 
       
   505 TBool CommsDatMapperAndValidator::IsDefIPProtoAPInDB(CommsDat::CMDBSession& aSession)
       
   506 	{
       
   507 	TBool ret = EFalse;
       
   508 	
       
   509 	CMDBField<TInt>* customSelPolField = new(ELeave)CMDBField<TInt>(KCDTIdCustomSelectionPolicy);
       
   510 	CleanupStack::PushL(customSelPolField);
       
   511 	
       
   512 	*customSelPolField = CCDAccessPointRecord::KNoPolicy;
       
   513 	if (customSelPolField->FindL(aSession))
       
   514 		{
       
   515 		ret = ETrue;
       
   516 		}
       
   517 	
       
   518 	CleanupStack::PopAndDestroy(customSelPolField);
       
   519 	
       
   520 	return ret;
       
   521 	}
       
   522 
       
   523 CommsDat::CCDAccessPointRecord* CommsDatMapperAndValidator::GetTheDefIPProtoAP(CommsDat::CMDBSession& aSession)
       
   524 	{
       
   525     CCDAccessPointRecord* apRec = static_cast<CCDAccessPointRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdAccessPointRecord));
       
   526     CleanupStack::PushL(apRec);
       
   527 	
       
   528     apRec->iCustomSelectionPolicy = CCDAccessPointRecord::KNoPolicy;
       
   529 	
       
   530 	if(!apRec->FindL(aSession))
       
   531 		{
       
   532 		//no records were found with the given customSelectionPolicy value
       
   533 		User::Leave(KErrNotFound);
       
   534 		}
       
   535 	
       
   536 	CleanupStack::Pop(apRec);
       
   537 	
       
   538 	return apRec;
       
   539 	}
       
   540 
       
   541 TInt CommsDatMapperAndValidator::GetNumberOfThisIPProtoAPL(CommsDat::CCDAccessPointRecord* aAPRecToBeDeleted, CommsDat::CMDBSession& aSession)
       
   542 	{
       
   543 	CMDBRecordSet<CCDAccessPointRecord>* apRecSet = new(ELeave)CMDBRecordSet<CCDAccessPointRecord>(KCDTIdAccessPointRecord);
       
   544 	CleanupStack::PushL(apRecSet);
       
   545 	
       
   546 	CCDAccessPointRecord* apForPriming = static_cast<CCDAccessPointRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdAccessPointRecord));
       
   547 	CleanupStack::PushL(apForPriming);
       
   548 	
       
   549 	apForPriming->iTier.SetL(aAPRecToBeDeleted->iTier);
       
   550 	apForPriming->iCprConfig.SetL(aAPRecToBeDeleted->iCprConfig);
       
   551 	apForPriming->iCustomSelectionPolicy.SetL(aAPRecToBeDeleted->iCustomSelectionPolicy);
       
   552 	
       
   553 	apRecSet->iRecords.AppendL(apForPriming);
       
   554 	//ownership of the primed record is now at the recordset
       
   555 	CleanupStack::Pop(apForPriming);
       
   556 	
       
   557 	TInt recCount=0;
       
   558 	if(apRecSet->FindL(aSession))
       
   559 		{
       
   560 		recCount = apRecSet->iRecords.Count();
       
   561 		}
       
   562 	CleanupStack::PopAndDestroy(apRecSet);
       
   563 	
       
   564 	return recCount;
       
   565 	}
       
   566 
       
   567 void CommsDatMapperAndValidator::CorrectLinksL(TUint aElementIdToBeDeleted, CommsDat::CMDBSession& aSession)
       
   568 	{
       
   569 	//1st correct the apprioritySelPol rec
       
   570 	TInt defSelPolElemId = GetDefAPPrioritySelPolLinkValueL(aSession);
       
   571 	CCDAPPrioritySelectionPolicyRecord* defAPPrioritySelPolRec = static_cast<CCDAPPrioritySelectionPolicyRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdApPrioritySelectionPolicyRecord));
       
   572 	CleanupStack::PushL(defAPPrioritySelPolRec);
       
   573 	
       
   574 	defAPPrioritySelPolRec->SetElementId(defSelPolElemId);
       
   575 	defAPPrioritySelPolRec->LoadL(aSession);
       
   576 
       
   577 	TInt fieldCounter(defAPPrioritySelPolRec->iApCount);
       
   578 	
       
   579     TMetaVTableIterator inputAttribIter(defAPPrioritySelPolRec);
       
   580     SVDataTableEntry const* inputEntry = NULL;
       
   581     
       
   582     //this fieldpointer will point to the link in the APPrioritySelPol record
       
   583     //which will not be deleted.
       
   584     CMDBField<TUint32>* apLinkWhichWontBeDeleted = NULL;
       
   585     
       
   586     //as this call is from the connpref mapping logic we can assume that this record
       
   587     //contains only 2 links maximum (rank1, rank2)
       
   588     while ( (inputEntry = inputAttribIter++)    != NULL &&
       
   589             fieldCounter-- > 0 )
       
   590         {
       
   591         //loop for the fields
       
   592         apLinkWhichWontBeDeleted = reinterpret_cast<CMDBField<TUint32>*>(defAPPrioritySelPolRec->GetAttribPtr(inputEntry->iOffset));
       
   593         if ( apLinkWhichWontBeDeleted && 
       
   594         	 aElementIdToBeDeleted != *apLinkWhichWontBeDeleted )
       
   595             {
       
   596             //ok got the link to the AP which WON'T be deleted
       
   597             break;
       
   598             }
       
   599         }
       
   600 	
       
   601 	//modify the links in the APPrioritySelPol rec
       
   602     TMetaVTableIterator inputAttribIter1(defAPPrioritySelPolRec);
       
   603     SVDataTableEntry const* inputEntry1 = NULL;
       
   604     
       
   605     CMDBField<TUint32>* inputFieldPtr = NULL;
       
   606     
       
   607     fieldCounter = defAPPrioritySelPolRec->iApCount;
       
   608     
       
   609     //set all of the links to point the AP which won't be deleted
       
   610     while ( (inputEntry1 = inputAttribIter1++)    != NULL &&
       
   611             fieldCounter-- > 0 )
       
   612         {
       
   613         //loop for the fields
       
   614         inputFieldPtr = reinterpret_cast<CMDBField<TUint32>*>(defAPPrioritySelPolRec->GetAttribPtr(inputEntry1->iOffset));
       
   615         
       
   616         if ( inputFieldPtr &&
       
   617         	 *apLinkWhichWontBeDeleted != *inputFieldPtr )
       
   618         	{
       
   619     		//modify the link
       
   620     		inputFieldPtr->SetL(*apLinkWhichWontBeDeleted);
       
   621     		break;
       
   622             }
       
   623         }
       
   624 	
       
   625     //now modify the ipproto Tier too
       
   626     TInt ipprotoTierRecId = GetIPProtoTierRecordIdL(aSession);
       
   627     CCDTierRecord* ipprotoTierRec = static_cast<CCDTierRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdTierRecord));
       
   628     CleanupStack::PushL(ipprotoTierRec);
       
   629 	
       
   630     ipprotoTierRec->SetRecordId(ipprotoTierRecId);
       
   631     ipprotoTierRec->LoadL(aSession);
       
   632     ipprotoTierRec->iDefaultAccessPoint.SetL(*apLinkWhichWontBeDeleted);
       
   633     ipprotoTierRec->ModifyL(aSession);
       
   634     
       
   635     defAPPrioritySelPolRec->ModifyL(aSession);
       
   636     
       
   637     CleanupStack::PopAndDestroy(ipprotoTierRec);
       
   638     CleanupStack::PopAndDestroy(defAPPrioritySelPolRec);
       
   639 	}
       
   640 
       
   641 
       
   642 #endif //SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   643