phonebookui/Phonebook2/remotecontactlookup/engine/src/cpbk2remotecontactlookupaccounts.cpp
branchRCL_3
changeset 45 34879f5cfc63
parent 32 2828b4d142c0
child 64 c1e8ba0c2b16
equal deleted inserted replaced
39:a6539d1e8e43 45:34879f5cfc63
   120 
   120 
   121     // Now create all the protocol adapters.
   121     // Now create all the protocol adapters.
   122     // The actual ECom loading is implemented in CPbkxRemoteContactLookupProtocolAdapter.
   122     // The actual ECom loading is implemented in CPbkxRemoteContactLookupProtocolAdapter.
   123     for ( TInt i = 0; i < implArray.Count(); i++ )
   123     for ( TInt i = 0; i < implArray.Count(); i++ )
   124         {
   124         {
   125         CPbkxRemoteContactLookupProtocolAdapter* adapter = NULL;
   125         CPbkxRemoteContactLookupProtocolAdapter* volatile adapter = NULL;
   126         adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL(
   126         
   127             implArray[i]->ImplementationUid(), *iProtocolEnv );
   127         // Trap the error code of loading one specific protocal adapter, if the error is not 
   128         CleanupStack::PushL( adapter );
   128         // extremly harmful like "No memory", then go on loading remaining possibly working 
   129         User::LeaveIfError( iAdapters.Append( adapter ) );
   129         // adapters.
   130         CleanupStack::Pop( adapter );
   130         TRAPD(err,
       
   131         		{
       
   132                 adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL(
       
   133                 implArray[i]->ImplementationUid(), *iProtocolEnv );
       
   134         		}
       
   135         );
       
   136         
       
   137         if( err == KErrNoMemory )
       
   138             {
       
   139             User::Leave( KErrNoMemory );
       
   140             }
       
   141         
       
   142         if ( adapter )
       
   143         	{
       
   144             CleanupStack::PushL( adapter );
       
   145             User::LeaveIfError( iAdapters.Append( adapter ) );
       
   146             CleanupStack::Pop( adapter );
       
   147         	}
   131         }
   148         }
   132     CleanupStack::PopAndDestroy(); // cleanupItem 
   149     CleanupStack::PopAndDestroy(); // cleanupItem 
   133     }
   150     }
   134 
   151 
   135 
   152 
   151         CPbkxRemoteContactLookupProtocolAdapter& adapter = *iAdapters[n];
   168         CPbkxRemoteContactLookupProtocolAdapter& adapter = *iAdapters[n];
   152         // Using a temp array, just to avoid an adapter resetting the main array
   169         // Using a temp array, just to avoid an adapter resetting the main array
   153         RPointerArray<CPbkxRemoteContactLookupProtocolAccount> protocolAccountsTmp;
   170         RPointerArray<CPbkxRemoteContactLookupProtocolAccount> protocolAccountsTmp;
   154         TCleanupItem cleanupItemAcc(CleanupResetAndDestroyAccArray, &protocolAccountsTmp);
   171         TCleanupItem cleanupItemAcc(CleanupResetAndDestroyAccArray, &protocolAccountsTmp);
   155         CleanupStack::PushL(cleanupItemAcc);
   172         CleanupStack::PushL(cleanupItemAcc);
   156         adapter.GetAllProtocolAccountsL( protocolAccountsTmp );
   173         
       
   174         TRAPD( err,
       
   175         		{
       
   176                 adapter.GetAllProtocolAccountsL( protocolAccountsTmp );
       
   177         		}
       
   178         );
       
   179         
       
   180         if( err == KErrNoMemory )
       
   181             {
       
   182             User::Leave( KErrNoMemory );
       
   183             }
   157         
   184         
   158         // Move accounts from temp array to main array
   185         // Move accounts from temp array to main array
   159         
   186         
   160         // First expand the main array so that we can move ownership in one go.
   187         // First expand the main array so that we can move ownership in one go.
   161         // TODO OOPS, METHOD NOT AVAILABLE iAdapters.SetReserveL( iAdapters.Count() + protocolAccountsTmp.Count() );
   188         // TODO OOPS, METHOD NOT AVAILABLE iAdapters.SetReserveL( iAdapters.Count() + protocolAccountsTmp.Count() );
   162 
   189 
   163         
   190         const TInt count = protocolAccountsTmp.Count();
   164         // Don't need the cleanup item anymore since iAdapters will take ownership,
   191         for ( TInt x = 0; x < count; x++ )
   165         // and the iAdapters has already been expanded.
       
   166         CleanupStack::Pop(); // cleanupItemAcc
       
   167         for ( TInt x = 0; x < protocolAccountsTmp.Count(); x++ )
       
   168             {
   192             {
   169             // Ownership is passed
   193             // Ownership is passed
   170             User::LeaveIfError( aAccounts.Append( protocolAccountsTmp[ x ] ) );
   194             User::LeaveIfError( aAccounts.Append( protocolAccountsTmp[ 0 ] ) );
   171             }
   195             protocolAccountsTmp.Remove( 0 );
   172         // just let protocolAccountsTmp pass out of scope. It doesn't own anything now.
   196             }
       
   197         
       
   198         CleanupStack::PopAndDestroy( &protocolAccountsTmp );
   173         }
   199         }
   174     CleanupStack::Pop();
   200     CleanupStack::Pop();
   175     }
   201     }
   176 
   202 
   177 
   203