mtpfws/mtpfw/src/cmtpdataprovidercontroller.cpp
changeset 0 d0791faffa3f
child 1 f8e15b44d440
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include <barsc.h> 
       
    17 #include <barsread.h> 
       
    18 #include <e32property.h>
       
    19 #include <mtp/cmtpdataproviderplugin.h>
       
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include <mtp/rmtpclient.h>
       
    22 
       
    23 #include "cmtpdataprovider.h"
       
    24 #include "cmtpdataproviderconfig.h"
       
    25 #include "cmtpdataprovidercontroller.h"
       
    26 #include "cmtpobjectmgr.h"
       
    27 #include "mtpframeworkconst.h"
       
    28 #include "cmtpframeworkconfig.h"
       
    29 #include "cmtpstoragemgr.h"
       
    30 
       
    31 
       
    32 // Class constants.
       
    33 _LIT(KMTPDpResourceDirectory, "z:\\resource\\mtp\\");
       
    34 _LIT(KMTPDpDummyResourcefile, "z:\\resource\\mtp\\dummydp.rsc");
       
    35 
       
    36 // Class constants.
       
    37 __FLOG_STMT(_LIT8(KComponent,"DataProviderController");)
       
    38 
       
    39 static const TUint KOpaqueDataLength(64);
       
    40 
       
    41 /**
       
    42 CMTPDataProviderController panics
       
    43 */
       
    44 _LIT(KMTPPanicCategory, "CMTPDataProviderController");
       
    45 enum TMTPPanicReasons
       
    46     {
       
    47     EMTPPanicStorageEnumeration = 0,
       
    48     EMTPPanicFrameworkEnumeration = 1,
       
    49     EMTPPanicDataProviderStorageEnumeration = 2,
       
    50     EMTPPanicDataProviderEnumeration = 3
       
    51     };
       
    52     
       
    53 LOCAL_C void Panic(TInt aReason)
       
    54     {
       
    55     User::Panic(KMTPPanicCategory, aReason);
       
    56     }
       
    57 
       
    58 /**
       
    59 CMTPDataProviderController factory method. 
       
    60 @return A pointer to a new CMTPDataProviderController instance. Ownership IS 
       
    61 transfered.
       
    62 @leave One of the system wide error codes if a processing failure occurs.
       
    63 */
       
    64 CMTPDataProviderController* CMTPDataProviderController::NewL()
       
    65     {
       
    66     CMTPDataProviderController* self = new (ELeave) CMTPDataProviderController();
       
    67     CleanupStack::PushL(self);
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop(self);
       
    70     return self;
       
    71     }
       
    72 
       
    73 /**
       
    74 Destructor.
       
    75 */
       
    76 CMTPDataProviderController::~CMTPDataProviderController()
       
    77     {
       
    78     __FLOG(_L8("~CMTPDataProviderController - Entry"));
       
    79     Cancel();
       
    80     UnloadDataProviders();
       
    81     iDataProviderIds.Close();
       
    82     iEnumeratingDps.Close();
       
    83     iEnumeratingStorages.Close();
       
    84     iSingletons.Close();
       
    85     CloseRegistrySessionAndEntryL();
       
    86     delete iOpenSessionWaiter;
       
    87     __FLOG(_L8("~CMTPDataProviderController - Exit"));
       
    88     __FLOG_CLOSE;
       
    89     }
       
    90     
       
    91 /**
       
    92 Loads the set of available data providers and initiates the data provider
       
    93 enumeration sequence.
       
    94 @leave One of the system wide error codes, if a processing failure occurs.
       
    95 */
       
    96 EXPORT_C void CMTPDataProviderController::LoadDataProvidersL()
       
    97     {
       
    98     __FLOG(_L8("LoadDataProvidersL - Entry"));
       
    99     // Retrieve the ECOM data provider implementations list
       
   100     RImplInfoPtrArray   implementations;
       
   101     TCleanupItem        cleanup(ImplementationsCleanup, reinterpret_cast<TAny*>(&implementations));
       
   102     CleanupStack::PushL(cleanup);
       
   103     REComSession::ListImplementationsL(KMTPDataProviderPluginInterfaceUid, implementations);
       
   104     implementations.Sort(TLinearOrder<CImplementationInformation>(ImplementationsLinearOrderUid));
       
   105     
       
   106     // Retrieve the data provider registration resource file list.
       
   107     CDir* registrations;
       
   108     User::LeaveIfError(iSingletons.Fs().GetDir(KMTPDpResourceDirectory, KEntryAttNormal, ESortByName, registrations));
       
   109     CleanupStack::PushL(registrations);
       
   110 
       
   111     // Load the registered data providers. 
       
   112     const TUint KCount(registrations->Count());
       
   113     TInt index = 0; 
       
   114     for (TInt i = 0; i < KCount; ++i)
       
   115         {
       
   116         TUint uid = 0;
       
   117         if(Uid((*registrations)[i].iName, uid) != KErrNone)
       
   118         	{
       
   119         	__FLOG_1(_L8("LoadDataProvidersL - Fail to get UID = %s"),&((*registrations)[i].iName) );
       
   120         	continue;
       
   121         	}
       
   122         index = implementations.FindInOrder(TUid::Uid(uid), ImplementationsLinearOrderUid);
       
   123         if (KErrNotFound == index)
       
   124         	{
       
   125         	continue;
       
   126         	}
       
   127 		if( uid != KMTPImplementationUidDeviceDp && uid != KMTPImplementationUidProxyDp && uid != KMTPImplementationUidFileDp )
       
   128 			{
       
   129 	        //get the dpid for the uid from dpidstore table
       
   130 	        TBool tFlag;
       
   131 		    iNextDpId = iSingletons.ObjectMgr().DPIDL(uid, tFlag);
       
   132 		    if(tFlag == EFalse)
       
   133 		    	{
       
   134 		    	iSingletons.ObjectMgr().InsertDPIDObjectL(iNextDpId,uid);
       
   135 		    	}	       	
       
   136 			}
       
   137 		else
       
   138 			{
       
   139 			switch (uid)
       
   140 				{
       
   141 				case KMTPImplementationUidDeviceDp : 
       
   142 					iNextDpId = KMTPDeviceDPID;
       
   143 					break;
       
   144 
       
   145 				case KMTPImplementationUidFileDp   : 
       
   146 					iNextDpId = KMTPFileDPID;
       
   147 					break;
       
   148 
       
   149 				case KMTPImplementationUidProxyDp  : 
       
   150 					iNextDpId = KMTPProxyDPID;
       
   151 					break;				
       
   152 				}
       
   153 			}
       
   154 		LoadROMDataProvidersL((*registrations)[i].iName, implementations);
       
   155 		delete implementations[index];
       
   156 		implementations.Remove(index);
       
   157         }
       
   158 
       
   159     //Load installed DPs on non-ROM drives.
       
   160     for (index = 0; index < implementations.Count(); ++index)
       
   161         {
       
   162         TRAPD(err, LoadInstalledDataProvidersL(implementations[index]));
       
   163         if (KErrNone != err)
       
   164             {
       
   165             __FLOG_VA((_L8("Load installed data provider[0x%x] failed."),implementations[index]->ImplementationUid().iUid));
       
   166             }
       
   167         }
       
   168 
       
   169     CleanupStack::PopAndDestroy(registrations);
       
   170     CleanupStack::PopAndDestroy(&implementations);    
       
   171 
       
   172     // Verify that the framework data providers are loaded.
       
   173     User::LeaveIfError(DpId(KMTPImplementationUidDeviceDp));
       
   174     User::LeaveIfError(DpId(KMTPImplementationUidProxyDp));
       
   175     User::LeaveIfError(DpId(KMTPImplementationUidFileDp));
       
   176 
       
   177 	// Sort the data provider set on enumeration phase order.
       
   178 	iDataProviders.Sort(TLinearOrder<CMTPDataProvider>(CMTPDataProvider::LinearOrderEnumerationPhase));
       
   179 	// Add the DP IDs into DP ID array, except for device DP, File DP and proxy DP
       
   180 	for (TUint index=0; index < iDataProviders.Count(); index++)
       
   181 	  {
       
   182 	  if ((iDataProviders[index]->DataProviderId() != iDpIdDeviceDp)
       
   183 	  	  && (iDataProviders[index]->DataProviderId() != iDpIdFileDp)
       
   184 	  	  && (iDataProviders[index]->DataProviderId() != iDpIdProxyDp))
       
   185 	    {
       
   186 	    iDataProviderIds.Append(iDataProviders[index]->DataProviderId());
       
   187 	    }
       
   188 	  }
       
   189 	
       
   190     // Ensure that the data provider set is ordered on DataProvider Id.
       
   191     iDataProviders.Sort(TLinearOrder<CMTPDataProvider>(CMTPDataProvider::LinearOrderDPId));
       
   192     
       
   193     // Start enumerating.
       
   194     iEnumeratingStorages.AppendL(KMTPStorageAll);
       
   195     iEnumerationState = EEnumerationStarting;
       
   196     Schedule();
       
   197     __FLOG(_L8("LoadDataProvidersL - Exit"));
       
   198     }
       
   199     
       
   200 /**
       
   201 Unloads all active data providers.
       
   202 @leave One of the system wide error codes, if a processing failure occurs.
       
   203 */
       
   204 EXPORT_C void CMTPDataProviderController::UnloadDataProviders()
       
   205     {
       
   206     __FLOG(_L8("UnloadDataProviders - Entry"));
       
   207     TRAP_IGNORE(iSingletons.ObjectMgr().ObjectStore().CleanL());
       
   208     iDataProviders.ResetAndDestroy();
       
   209     iDataProviderIds.Reset();
       
   210     __FLOG(_L8("UnloadDataProviders - Exit"));
       
   211     }
       
   212     
       
   213 /**
       
   214 Issues the specified notification to all loaded data providers.
       
   215 @param aNotification The notification type identifier.
       
   216 @param aParams The notification type specific parameter block
       
   217 @leave One of the system wide error code if a processing failure occurs
       
   218 in the data provider.
       
   219 */
       
   220 EXPORT_C void CMTPDataProviderController::NotifyDataProvidersL(TMTPNotification aNotification, const TAny* aParams)
       
   221     {
       
   222     NotifyDataProvidersL(KMTPDataProviderAll, aNotification, aParams);
       
   223     }
       
   224 
       
   225 EXPORT_C void CMTPDataProviderController::NotifyDataProvidersL(TUint aDPId, TMTPNotification aNotification, const TAny* aParams)
       
   226     {
       
   227     __FLOG(_L8("NotifyDataProvidersL - Entry"));
       
   228     // Schedule any long running operations.
       
   229     switch (aNotification)
       
   230         {
       
   231     case EMTPStorageAdded:
       
   232         {
       
   233         // Queue a storage enumeration operation.
       
   234         __ASSERT_DEBUG(aParams, User::Invariant());
       
   235         const TMTPNotificationParamsStorageChange* params(static_cast<const TMTPNotificationParamsStorageChange*>(aParams));
       
   236         iEnumeratingStorages.AppendL(params->iStorageId);
       
   237         
       
   238         // Only schedule the operation start if there is not one currently underway.
       
   239         if (iEnumerationState == EEnumerated)
       
   240             {
       
   241             iNextDpId           = iDpIdDeviceDp;
       
   242             iEnumerationState   = EEnumeratingFrameworkObjects;
       
   243             Schedule();
       
   244             }
       
   245         }
       
   246         break;
       
   247 	case EMTPStorageRemoved:
       
   248 		{
       
   249 		// Dequeue an unhandled storage enumeration operations if existed.
       
   250         // If not existed, just ignore the remove event, since the logical storageId already removed from StorageMgr
       
   251         // by the caller, i.e. CMTPStorageWatcher. 
       
   252         __ASSERT_DEBUG(aParams, User::Invariant());
       
   253         const TMTPNotificationParamsStorageChange* params(static_cast<const TMTPNotificationParamsStorageChange*>(aParams));
       
   254         //Start checking from the second event, since iEnumeratingStorages[0] is the event being handled by DPs.
       
   255         TUint32 storageId = params->iStorageId;
       
   256         for(TInt i=1; i<iEnumeratingStorages.Count(); i++)
       
   257             {
       
   258             if(storageId==iEnumeratingStorages[i])
       
   259                 {
       
   260                 iEnumeratingStorages.Remove(i);
       
   261                 __FLOG_VA((_L8("Unhandle memory card add event removed, storageId: %d"), storageId));
       
   262                 }
       
   263             }
       
   264         }
       
   265         break;
       
   266     case EMTPObjectAdded:
       
   267         break;
       
   268     default:
       
   269         break;        
       
   270         }
       
   271         
       
   272     // Issue the notification.    
       
   273     const TUint KLoadedDps(iDataProviders.Count());
       
   274     if(aDPId == KMTPDataProviderAll)
       
   275         {
       
   276         for (TUint i(0); i < KLoadedDps; ++i)
       
   277             {
       
   278             CMTPDataProvider *dp = iDataProviders[i];
       
   279             if ((dp->DataProviderId() != iDpIdDeviceDp) &&
       
   280                 (dp->DataProviderId() != iDpIdProxyDp))
       
   281                 {
       
   282                 dp->Plugin().ProcessNotificationL(aNotification, aParams);
       
   283                 }
       
   284             }
       
   285         }
       
   286     else
       
   287         {
       
   288         for (TUint i(0); i < KLoadedDps; ++i)
       
   289             {
       
   290             CMTPDataProvider *dp = iDataProviders[i];
       
   291             if ( dp->DataProviderId() == aDPId )
       
   292                 {
       
   293                 dp->Plugin().ProcessNotificationL(aNotification, aParams);
       
   294                 break;
       
   295                 }
       
   296             }
       
   297         }    
       
   298     __FLOG(_L8("NotifyDataProvidersL - Exit"));
       
   299     }
       
   300 
       
   301 /**
       
   302 Provides the number of active data providers.
       
   303 @return the number of active data providers.
       
   304 */
       
   305 EXPORT_C TUint CMTPDataProviderController::Count()
       
   306     {
       
   307     return iDataProviders.Count();
       
   308     }
       
   309 
       
   310 /**
       
   311 Provides a reference to the data provider with the specified identifier.
       
   312 @param aId The data provider identifier.
       
   313 @return The data provider reference.
       
   314 */
       
   315 EXPORT_C CMTPDataProvider& CMTPDataProviderController::DataProviderL(TUint aId)
       
   316     {
       
   317     return DataProviderByIndexL(iDataProviders.FindInOrder(aId, CMTPDataProvider::LinearOrderDPId));
       
   318     }  
       
   319 
       
   320 /**
       
   321 Provides a reference to the data provider with the specified index.
       
   322 @param aIndex The data provider index.
       
   323 @return The data provider reference.
       
   324 */
       
   325 EXPORT_C CMTPDataProvider& CMTPDataProviderController::DataProviderByIndexL(TUint aIndex)
       
   326     {
       
   327     __ASSERT_DEBUG((aIndex < iDataProviders.Count()), User::Invariant());
       
   328     return *(iDataProviders[aIndex]);
       
   329     }  
       
   330 
       
   331 /**
       
   332  * Determine whether a data provider with the specified data provider id has been loaded
       
   333  * @param aId the id of the data provider to be checked
       
   334  * @return true if the data provider has been loaded, otherwise false
       
   335  */
       
   336 EXPORT_C TBool CMTPDataProviderController::IsDataProviderLoaded(TUint aId) const
       
   337 	{
       
   338 	TInt index = iDataProviders.FindInOrder(aId, CMTPDataProvider::LinearOrderDPId);
       
   339 	if (index >= 0 && index < iDataProviders.Count())
       
   340 		{
       
   341 		return ETrue;
       
   342 		}
       
   343 	else
       
   344 		{
       
   345 		return EFalse;
       
   346 		}
       
   347 	}
       
   348 
       
   349 /**
       
   350 Provides the identifier of the device data provider.
       
   351 @return TInt The device data provider identifier.
       
   352 */
       
   353 EXPORT_C TInt CMTPDataProviderController::DeviceDpId()
       
   354     {
       
   355     return iDpIdDeviceDp;
       
   356     }
       
   357     
       
   358 /**
       
   359 Provides the identifier of the data provider with the specified implementation 
       
   360 UID.
       
   361 @param aUid The implementation UID.
       
   362 @return TInt The proxy data provider identifier.
       
   363 */  
       
   364 EXPORT_C TInt CMTPDataProviderController::DpId(TUint aUid)
       
   365     {
       
   366     return iDataProviders.FindInOrder(TUid::Uid(aUid), CMTPDataProvider::LinearOrderUid);
       
   367     }
       
   368 
       
   369 /**
       
   370 Provides the identifier of the proxy data provider.
       
   371 @return TInt The proxy data provider identifier.
       
   372 */  
       
   373 EXPORT_C TInt CMTPDataProviderController::ProxyDpId()
       
   374     {
       
   375     return iDpIdProxyDp;
       
   376     }
       
   377 
       
   378 EXPORT_C TInt CMTPDataProviderController::FileDpId()
       
   379     {
       
   380     return iDpIdFileDp;
       
   381     }
       
   382 
       
   383 /**
       
   384 Wait for the enumeration complete.
       
   385 */ 
       
   386 EXPORT_C void CMTPDataProviderController::WaitForEnumerationComplete()
       
   387 {
       
   388 	if(EnumerateState() != CMTPDataProviderController::EEnumerated)
       
   389 		{
       
   390 		iOpenSessionWaiter->Start();
       
   391 		}
       
   392 }
       
   393 TBool CMTPDataProviderController::FreeEnumerationWaiter()
       
   394 	{
       
   395 	if(iOpenSessionWaiter->IsStarted())
       
   396 		{
       
   397 		iOpenSessionWaiter->AsyncStop();
       
   398 		return ETrue;
       
   399 		}
       
   400 	return EFalse;
       
   401 	}
       
   402 /**
       
   403 Data provider enumeration state change notification callback.
       
   404 @param aDp The notifying data provider.
       
   405 */    
       
   406 void CMTPDataProviderController::EnumerationStateChangedL(const CMTPDataProvider& aDp)
       
   407     {
       
   408     __FLOG(_L8("EnumerationStateChangedL - Entry"));
       
   409     switch (iEnumerationState)
       
   410         {        
       
   411     case EEnumeratingFrameworkStorages:
       
   412     	switch (aDp.ImplementationUid().iUid)
       
   413             {
       
   414         case KMTPImplementationUidDeviceDp:
       
   415             iNextDpId = iDpIdProxyDp;
       
   416             break;
       
   417 
       
   418             
       
   419         case KMTPImplementationUidProxyDp:
       
   420             iNextDpId = iDpIdFileDp;
       
   421             break;
       
   422             
       
   423         case KMTPImplementationUidFileDp:
       
   424             iEnumerationState   = EEnumeratingDataProviderStorages;
       
   425             iDpIdArrayIndex     = 0;
       
   426             break;
       
   427             }
       
   428         Schedule();
       
   429         break;    
       
   430         
       
   431     case EEnumeratingDataProviderStorages:
       
   432         // Data provider storage enumerations execute sequentially.
       
   433         if (++iDpIdArrayIndex >= iDataProviderIds.Count())
       
   434             {
       
   435             iNextDpId           = iDpIdDeviceDp;
       
   436             iEnumerationState   = EEnumeratingFrameworkObjects;
       
   437             }
       
   438         Schedule();
       
   439         break;
       
   440           
       
   441     case EEnumeratingFrameworkObjects:
       
   442         switch (aDp.ImplementationUid().iUid)
       
   443             {
       
   444         case KMTPImplementationUidDeviceDp:
       
   445             iSingletons.ObjectMgr().RemoveNonPersistentObjectsL(aDp.DataProviderId());
       
   446             iNextDpId = iDpIdProxyDp;
       
   447             Schedule();
       
   448             break;
       
   449             
       
   450         case KMTPImplementationUidProxyDp:
       
   451             //iNextDpId = iDpIdFileDp;
       
   452             if ( iDataProviderIds.Count()>0 )
       
   453                 {
       
   454                 iEnumerationState   = EEnumeratingDataProviderObjects;
       
   455                 iEnumerationPhase   = DataProviderL(iDataProviderIds[0]).DataProviderConfig().UintValue(MMTPDataProviderConfig::EEnumerationPhase);
       
   456                 iDpIdArrayIndex     = 0;                
       
   457                 }
       
   458             else
       
   459                 {
       
   460                 iNextDpId = iDpIdFileDp;
       
   461                 }
       
   462             Schedule();
       
   463             break;
       
   464             
       
   465         case KMTPImplementationUidFileDp:
       
   466             iSingletons.ObjectMgr().RemoveNonPersistentObjectsL(aDp.DataProviderId());
       
   467             // No other data providers
       
   468             iNextDpId = 0;
       
   469             iEnumeratingStorages.Remove(0);
       
   470             if (iEnumeratingStorages.Count() == 0)
       
   471                 {
       
   472                 // No queued enumerations.
       
   473                 iSingletons.ObjectMgr().ObjectStore().CleanDBSnapshotL();
       
   474                 iEnumerationState   = EEnumerated;
       
   475                 Cancel();
       
   476                 if(iOpenSessionWaiter->IsStarted())
       
   477                     {
       
   478                     iOpenSessionWaiter->AsyncStop();
       
   479                     }
       
   480                 }
       
   481             else
       
   482                 {
       
   483                 // Queued enumerations.
       
   484                 iNextDpId           = iDpIdDeviceDp;
       
   485                 Schedule();
       
   486                 }
       
   487             }
       
   488         break;
       
   489         
       
   490     case EEnumeratingDataProviderObjects:
       
   491         // Enumerate non-framework data providers concurrently.
       
   492         iEnumeratingDps.Remove(iEnumeratingDps.FindInOrderL(aDp.DataProviderId()));
       
   493         // Remove any non-persistent objects that are still marked.
       
   494         iSingletons.ObjectMgr().RemoveNonPersistentObjectsL(aDp.DataProviderId());
       
   495 
       
   496         if ((iEnumeratingDps.Count() == 0) && iDpIdArrayIndex >= iDataProviderIds.Count())
       
   497             {
       
   498             // Enumeration complete.
       
   499             iNextDpId = 0;
       
   500             iNextDpId           = iDpIdFileDp;
       
   501             iEnumerationState   = EEnumeratingFrameworkObjects;
       
   502             }
       
   503         else
       
   504             {
       
   505             if ((iEnumeratingDps.Count() == 0) && (iEnumerationPhase != DataProviderL(iDataProviderIds[iDpIdArrayIndex]).DataProviderConfig().UintValue(MMTPDataProviderConfig::EEnumerationPhase)))
       
   506                 {
       
   507                 // Enter next enumeration phase
       
   508                 iEnumerationPhase = DataProviderL(iDataProviderIds[iDpIdArrayIndex]).DataProviderConfig().UintValue(MMTPDataProviderConfig::EEnumerationPhase);
       
   509                 }
       
   510             }
       
   511         Schedule();        
       
   512         break;
       
   513         
       
   514     case EUnenumerated:
       
   515     case EEnumerationStarting:
       
   516     case EEnumerated:
       
   517     default:
       
   518         __DEBUG_ONLY(User::Invariant());
       
   519         break;
       
   520         }
       
   521     __FLOG(_L8("EnumerationStateChangedL - Exit"));
       
   522     }
       
   523 
       
   524 void CMTPDataProviderController::DoCancel()
       
   525     {
       
   526     __FLOG(_L8("DoCancel - Entry"));
       
   527     __FLOG(_L8("DoCancel - Exit"));
       
   528     }
       
   529     
       
   530 void CMTPDataProviderController::RunL()
       
   531     {
       
   532     __FLOG(_L8("RunL - Entry"));
       
   533     __FLOG_VA((_L8("iEnumerationState: 0x%x iNextDpId: %d"), iEnumerationState, iNextDpId));
       
   534     switch (iEnumerationState)
       
   535         {
       
   536     case EEnumerationStarting:
       
   537         iEnumerationState   = EEnumeratingFrameworkStorages;
       
   538         iNextDpId           = iDpIdDeviceDp;
       
   539         // Fall through to issue the StartStorageEnumerationL signal.
       
   540         
       
   541     case EEnumeratingFrameworkStorages:
       
   542         // Enumerate storages sequentially.
       
   543     	DataProviderL(iNextDpId).EnumerateStoragesL();
       
   544         break;
       
   545         
       
   546     case EEnumeratingDataProviderStorages:
       
   547         // Enumerate storages sequentially.
       
   548             
       
   549         // In case there was no DPs other than devdp and proxydp.
       
   550         if (iDpIdArrayIndex < iDataProviderIds.Count())
       
   551             {
       
   552             DataProviderL(iDataProviderIds[iDpIdArrayIndex]).EnumerateStoragesL();
       
   553             }
       
   554         else
       
   555             {
       
   556             iNextDpId           = iDpIdDeviceDp;
       
   557             iEnumerationState   = EEnumeratingFrameworkObjects;
       
   558 	
       
   559             
       
   560         
       
   561             Schedule();
       
   562             }
       
   563         break;
       
   564         
       
   565     case EEnumeratingFrameworkObjects:
       
   566         {
       
   567         TUint32 storageId = iEnumeratingStorages[0];
       
   568         if( ( KMTPStorageAll != storageId ) && (!iSingletons.StorageMgr().ValidStorageId(storageId)))
       
   569             {
       
   570             iNextDpId = 0;
       
   571             //Specified storage not existed, not necessary to start enumeration on this stroage.
       
   572             //Do this check will save enumeration time, i.e. avoid unnecessary enumeration, since memory card removed before enumeration starts.
       
   573             iEnumeratingStorages.Remove(0);
       
   574             if (iEnumeratingStorages.Count() == 0)
       
   575                 {
       
   576                 iEnumerationState = EEnumerated;
       
   577                 }
       
   578             else
       
   579                 {
       
   580                 //deal next storage
       
   581                 iNextDpId = iDpIdDeviceDp;
       
   582                 Schedule();
       
   583                 }
       
   584             }
       
   585         else
       
   586         	{
       
   587             // Enumerate framework data providers sequentially.
       
   588             if(iNextDpId == iDpIdDeviceDp)
       
   589                 {
       
   590                 if(KMTPStorageAll == storageId)
       
   591                     {
       
   592                     iSingletons.ObjectMgr().ObjectStore().EstablishDBSnapshotL(storageId);
       
   593                     }
       
   594                 else
       
   595                     {
       
   596                     const CMTPStorageMetaData& storage(iSingletons.StorageMgr().StorageL(storageId));
       
   597                     if(storage.Uint(CMTPStorageMetaData::EStorageSystemType) == CMTPStorageMetaData::ESystemTypeDefaultFileSystem)
       
   598                         {
       
   599                         const RArray<TUint>& logicalIds(storage.UintArray(CMTPStorageMetaData::EStorageLogicalIds));
       
   600                         const TUint KCountLogicalIds(logicalIds.Count());
       
   601                         for (TUint i(0); (i < KCountLogicalIds); i++)
       
   602                             {
       
   603                             __FLOG_VA((_L8("Establish snapshot for storage: 0x%x"), storageId));
       
   604                             iSingletons.ObjectMgr().ObjectStore().EstablishDBSnapshotL(storageId);
       
   605                             }
       
   606                         }
       
   607                     }
       
   608                 }
       
   609             EnumerateDataProviderObjectsL(iNextDpId);          
       
   610             }
       
   611         	}
       
   612         break;
       
   613         
       
   614     case EEnumeratingDataProviderObjects:
       
   615         {
       
   616         TUint currentDp = 0;
       
   617         
       
   618         // Enumerate non-framework data providers concurrently.
       
   619         const TUint KLoadedDps(iDataProviderIds.Count());
       
   620         while ((iEnumeratingDps.Count() < KMTPMaxEnumeratingDataProviders) && (iDpIdArrayIndex < KLoadedDps)
       
   621                && (iEnumerationPhase == DataProviderL(iDataProviderIds[iDpIdArrayIndex]).DataProviderConfig().UintValue(MMTPDataProviderConfig::EEnumerationPhase)))
       
   622             {
       
   623             currentDp = iDataProviderIds[iDpIdArrayIndex++];
       
   624             iEnumeratingDps.InsertInOrderL(currentDp);
       
   625             EnumerateDataProviderObjectsL(currentDp);
       
   626             }
       
   627         }
       
   628         break;
       
   629         
       
   630     case EUnenumerated:
       
   631     case EEnumerated:
       
   632     default:
       
   633         __DEBUG_ONLY(User::Invariant());
       
   634         break;
       
   635         }
       
   636     __FLOG(_L8("RunL - Exit"));
       
   637     }
       
   638 
       
   639 #ifdef __FLOG_ACTIVE
       
   640 TInt CMTPDataProviderController::RunError(TInt aError)
       
   641 #else
       
   642 TInt CMTPDataProviderController::RunError(TInt /*aError*/)
       
   643 #endif
       
   644     {
       
   645     __FLOG(_L8("RunError - Entry"));
       
   646     __FLOG_VA((_L8("Error = %d"), aError));
       
   647     
       
   648     // If a RunL error happens, there's no point in trying to continue.
       
   649     switch (iEnumerationState)
       
   650         {
       
   651     case EEnumerationStarting:
       
   652     case EEnumeratingFrameworkStorages:
       
   653         Panic(EMTPPanicStorageEnumeration);
       
   654         break;
       
   655         
       
   656     case EEnumeratingFrameworkObjects:
       
   657         Panic(EMTPPanicFrameworkEnumeration);
       
   658         break;
       
   659         
       
   660     case EEnumeratingDataProviderStorages:
       
   661         Panic(EMTPPanicDataProviderStorageEnumeration);
       
   662         break;
       
   663         
       
   664     case EEnumeratingDataProviderObjects:
       
   665         Panic(EMTPPanicDataProviderEnumeration);
       
   666         break;
       
   667         
       
   668     case EUnenumerated:
       
   669     case EEnumerated:
       
   670     default:
       
   671         User::Invariant();
       
   672         break;
       
   673         }
       
   674 
       
   675     // This code is never reached
       
   676     __FLOG(_L8("RunError - Exit"));
       
   677     return KErrNone;
       
   678     }
       
   679 
       
   680 /**
       
   681 Constructor.
       
   682 */
       
   683 CMTPDataProviderController::CMTPDataProviderController() :
       
   684     CActive(EPriorityNormal)
       
   685     {
       
   686     CActiveScheduler::Add(this);
       
   687     }
       
   688 
       
   689 /**
       
   690 Second-phase constructor.
       
   691 @leave One of the system wide error codes if a processing failure occurs.
       
   692 */
       
   693 void CMTPDataProviderController::ConstructL()
       
   694     {
       
   695     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   696     __FLOG(_L8("ConstructL - Entry"));
       
   697     iSingletons.OpenL();
       
   698 	TInt tMTPMode;
       
   699 	TInt err = RProperty::Get(KUidSystemCategory, KUidMTPModeKeyValue, tMTPMode);
       
   700 	if(err != KErrNone)
       
   701 		{
       
   702 		tMTPMode = KMTPModeMTP;		
       
   703 		}
       
   704 	else
       
   705 		{
       
   706 		if(tMTPMode != KMTPModeMTP && tMTPMode != KMTPModePTP && tMTPMode != KMTPModePictBridge)
       
   707 		tMTPMode = KMTPModeMTP;
       
   708 		}
       
   709 	iMode = (TMTPOperationalMode)tMTPMode;
       
   710 	CreateRegistrySessionAndEntryL();
       
   711     
       
   712 	iFlagDb = 0;
       
   713 	
       
   714     iOpenSessionWaiter = new(ELeave) CActiveSchedulerWait();
       
   715     __FLOG(_L8("ConstructL - Exit"));
       
   716     }
       
   717     
       
   718 /**
       
   719 Creates a data provider configurability parameter data instance on the cleanup 
       
   720 stack.
       
   721 @param aResourceFilename The data provider configuration data resource filename.
       
   722 @return A pointer to the data provider configurability parameter data instance, 
       
   723 which is also placed on the cleanup stack. Ownership is transferred.
       
   724 @leave One of the system wide error codes, if a processing failure occurs.
       
   725 */    
       
   726 CMTPDataProviderConfig* CMTPDataProviderController::CreateConfigLC(const TDesC& aResourceFilename)
       
   727     {
       
   728     __FLOG(_L8("CreateConfigLC - Entry"));
       
   729     // Open the configuration data resource file
       
   730     RResourceFile file;
       
   731     CleanupClosePushL(file);
       
   732     file.OpenL(iSingletons.Fs(), aResourceFilename);    
       
   733     
       
   734     // Create the resource reader.
       
   735     const TInt KDefaultResourceId(1);
       
   736     HBufC8* buffer(file.AllocReadLC(KDefaultResourceId));
       
   737     TResourceReader reader;
       
   738     reader.SetBuffer(buffer);
       
   739     
       
   740     // Load the data provider configurability parameter data.
       
   741     CMTPDataProviderConfig* config(CMTPDataProviderConfig::NewL(reader, aResourceFilename));
       
   742     CleanupStack::PopAndDestroy(buffer);
       
   743     CleanupStack::PopAndDestroy(&file);
       
   744     CleanupStack::PushL(config);
       
   745     __FLOG(_L8("CreateConfigLC - Exit"));
       
   746     return config;
       
   747     }
       
   748 
       
   749 /**
       
   750 Check the  necessity of objects enumeration as given the data provider 
       
   751 @param dp CMTPDataProvider reference
       
   752 */
       
   753 TBool CMTPDataProviderController::IsObjectsEnumerationNeededL(CMTPDataProvider& dp)
       
   754 {
       
   755     __FLOG(_L8("CheckEnumerateDPObjectsL - Entry"));
       
   756 
       
   757 	CMTPStorageMgr& storages = iSingletons.StorageMgr();
       
   758 	TUint32 aStorageId = iEnumeratingStorages[0];
       
   759 	
       
   760     TBool doEnumeration = true;
       
   761 	
       
   762 	if (aStorageId != KMTPStorageAll && storages.PhysicalStorageId(aStorageId))
       
   763 		{
       
   764 		TBool isFSBased(false);
       
   765 		RArray<TUint> storageTypes = dp.SupportedCodes( EStorageSystemTypes );
       
   766                 // check whether the storage type of the dp is file system based.
       
   767 		for (TInt i = 0; i < storageTypes.Count() && !isFSBased; i++)
       
   768 			{
       
   769 			   isFSBased= (storageTypes[i] == CMTPStorageMetaData::ESystemTypeDefaultFileSystem);
       
   770 			}
       
   771 		// As given physical storage id, only fs based dp need to do the enumeration.
       
   772 		if (!isFSBased)
       
   773 			{
       
   774 			  doEnumeration = false;
       
   775 			}
       
   776 	    }
       
   777 	__FLOG(_L8("CheckEnumerateDPObjectsL - Exit"));
       
   778 	return doEnumeration;
       
   779 }
       
   780 
       
   781 /**
       
   782 Requests that the given data provider enumerate its objects.
       
   783 @param aId data provider ID
       
   784 */
       
   785 void CMTPDataProviderController::EnumerateDataProviderObjectsL(TUint aId)
       
   786     {
       
   787     __FLOG(_L8("EnumerateDataProviderObjectsL - Entry"));
       
   788     CMTPDataProvider& dp(DataProviderL(aId));
       
   789 
       
   790 	if (IsObjectsEnumerationNeededL(dp))
       
   791 		{   
       
   792 		TBool abnormaldown = ETrue;
       
   793 		iSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::EAbnormalDown , abnormaldown);
       
   794 		if ( (!abnormaldown) && (dp.DataProviderConfig().BoolValue(MMTPDataProviderConfig::EObjectEnumerationPersistent)))
       
   795 			{       
       
   796 			// Initialize persistent objects store.
       
   797             iSingletons.ObjectMgr().RestorePersistentObjectsL(aId);
       
   798 			}
       
   799         else
       
   800         	{
       
   801 			// Mark all non-persistent objects.    
       
   802 			iSingletons.ObjectMgr().MarkNonPersistentObjectsL(aId,iEnumeratingStorages[0]);
       
   803 		    }
       
   804     
       
   805         // Initiate the data provider enumeration sequence.
       
   806         dp.EnumerateObjectsL(iEnumeratingStorages[0]);
       
   807 		}
       
   808 	else 
       
   809 		{
       
   810 		//The DP does not need enumeration this time, so just change the state to go on.
       
   811 		EnumerationStateChangedL(dp);
       
   812 		}
       
   813 
       
   814     __FLOG(_L8("EnumerateDataProviderObjectsL - Exit"));
       
   815     }
       
   816     
       
   817 /**
       
   818 Loads the dataprovider on ROM drives depending upon the mode and activates the specified ECOM data provider.
       
   819 @param aResourceFilename The data provider registration and configuration data 
       
   820 resource filename.
       
   821 @param aImplementations The ECOM data provider implementations list (ordered by 
       
   822 implementation UID).
       
   823 @return ETrue if data provider is successfully loaded, EFalse otherwise.
       
   824 @leave One of the system wide error codes, if a processing failure occurs. 
       
   825 */
       
   826 TBool CMTPDataProviderController::LoadROMDataProvidersL(const TDesC& aResourceFilename, const RImplInfoPtrArray& aImplementations)
       
   827     {
       
   828     __FLOG(_L8("LoadROMDataProvidersL - Entry"));
       
   829     // Retrieve the implementation UID
       
   830     TUint uid(0);
       
   831     User::LeaveIfError(Uid(aResourceFilename, uid));
       
   832     TBool success(EFalse);
       
   833 
       
   834     // Check for a corresponding plug-in implementation.
       
   835     TInt index = aImplementations.FindInOrder(TUid::Uid(uid), ImplementationsLinearOrderUid);
       
   836     if (index >= 0)
       
   837         {       	
       
   838         // Construct the configuration data resource file full path name.
       
   839         RBuf filename;
       
   840         CleanupClosePushL(filename);  
       
   841         filename.CreateL(KMTPDpResourceDirectory.BufferSize + aResourceFilename.Length());
       
   842         filename.Append(KMTPDpResourceDirectory);
       
   843         filename.Append(aResourceFilename); 
       
   844         if(iStubFound)
       
   845             {
       
   846             RPointerArray<HBufC> files;
       
   847             CleanupClosePushL(files);
       
   848             iSisEntry.FilesL(files);
       
   849             for (TInt i = 0; i< files.Count(); ++i)
       
   850                 {
       
   851                 TPtrC resourceFileName = files[i]->Des();
       
   852                 TPtrC fileName = resourceFileName.Mid(resourceFileName.LocateReverse('\\') + 1);
       
   853                 if(fileName.MatchF(aResourceFilename) != KErrNotFound)
       
   854                     {
       
   855                     TDriveName drive = aImplementations[index]->Drive().Name();
       
   856                     //replace "z:" with "c:" or "d:" or ...
       
   857                     filename.Replace(0,2,drive);
       
   858                     break;
       
   859                     }
       
   860                 }
       
   861             CleanupStack::Pop(&files);
       
   862             files.ResetAndDestroy();  	        	
       
   863             }
       
   864         success = LoadDataProviderL(filename);
       
   865         CleanupStack::PopAndDestroy(&filename);
       
   866         }    	
       
   867     __FLOG(_L8("LoadROMDataProvidersL - Exit"));
       
   868     return success;
       
   869     }
       
   870 
       
   871 /**
       
   872 Load all data providers installed on non-ROM drives depending upon the mode and activates 
       
   873 the specified ECOM data provider.
       
   874 @param aImplementations The installed ECOM data provider implementations list (ordered by 
       
   875 implementation UID).
       
   876 @leave One of the system wide error codes, if a processing failure occurs. 
       
   877 */
       
   878 void CMTPDataProviderController::LoadInstalledDataProvidersL(const CImplementationInformation* aImplementations)
       
   879     {
       
   880     __FLOG(_L8("LoadInstalledDataProvidersL - Entry"));
       
   881     TUint uid = aImplementations->ImplementationUid().iUid;
       
   882     TBool tFlag(EFalse);
       
   883     iNextDpId = iSingletons.ObjectMgr().DPIDL(uid, tFlag);
       
   884     if(!tFlag)
       
   885         {
       
   886         iSingletons.ObjectMgr().InsertDPIDObjectL(iNextDpId, uid);
       
   887         }   
       
   888 
       
   889     HBufC8 *OpaqData = HBufC8::NewLC(KOpaqueDataLength);
       
   890     *OpaqData = aImplementations->OpaqueData();
       
   891     TBuf16<KOpaqueDataLength> pkgIDstr;
       
   892     pkgIDstr.Copy(*OpaqData);
       
   893     CleanupStack::PopAndDestroy(OpaqData);
       
   894     pkgIDstr.Trim();
       
   895     _LIT(prefix, "0x");
       
   896     TInt searchindex = pkgIDstr.FindC(prefix);
       
   897     if(KErrNotFound != searchindex)
       
   898         {
       
   899         //Skip "0x".
       
   900         pkgIDstr = pkgIDstr.Mid(searchindex + 2);
       
   901         }
       
   902     if (0 == pkgIDstr.Length())
       
   903         {
       
   904         User::Leave(KErrArgument);
       
   905         }
       
   906     
       
   907     TUint aUid(0);
       
   908     User::LeaveIfError(Uid(pkgIDstr, aUid));
       
   909     
       
   910     iSingletons.ObjectMgr().InsertPkgIDObjectL(iNextDpId, aUid);
       
   911     TDriveName drive = aImplementations->Drive().Name();
       
   912     RBuf resourcefilename;
       
   913     CleanupClosePushL(resourcefilename);  
       
   914     resourcefilename.CreateL(KMaxFileName);
       
   915     resourcefilename.Copy(KMTPDpResourceDirectory);
       
   916     //Replace "z:"(at 0 position) with "c:" or "d:" or ...
       
   917     resourcefilename.Replace(0,2,drive);
       
   918 
       
   919     RBuf rscfile;
       
   920     CleanupClosePushL(rscfile);
       
   921     rscfile.CreateL(KMaxFileName);
       
   922     rscfile.NumUC(uid,EHex);
       
   923     _LIT(postfix, ".rsc");
       
   924     rscfile.Append(postfix);
       
   925     resourcefilename.Append(rscfile);
       
   926     CleanupStack::PopAndDestroy(&rscfile);
       
   927    
       
   928     LoadDataProviderL(resourcefilename);
       
   929 
       
   930     CleanupStack::PopAndDestroy(&resourcefilename);
       
   931     __FLOG(_L8("LoadInstalledDataProvidersL - Exit"));
       
   932     }
       
   933 
       
   934 /**
       
   935 Load data providers
       
   936 @param aImplementations The installed ECOM data provider implementations list (ordered by 
       
   937 implementation UID).
       
   938 @return ETrue if data provider is successfully loaded, EFalse otherwise.
       
   939 @leave One of the system wide error codes, if a processing failure occurs. 
       
   940 */
       
   941 TBool CMTPDataProviderController::LoadDataProviderL(const TDesC& aResourceFilename)
       
   942     {
       
   943     __FLOG(_L8("LoadDataProviderL - Entry"));
       
   944     // Load the configurability parameter data.
       
   945     CMTPDataProviderConfig* config(CreateConfigLC(aResourceFilename));
       
   946     
       
   947     
       
   948     TBool success(EFalse);
       
   949     TBool supported(ETrue);
       
   950     TUint aUid(0);
       
   951     if ( Uid(aResourceFilename,aUid) != KErrNone )
       
   952        	{
       
   953         return success;	
       
   954        	}
       
   955     TUint uid(aUid);
       
   956     if ((uid != KMTPImplementationUidDeviceDp) && (uid != KMTPImplementationUidProxyDp) && (uid != KMTPImplementationUidFileDp))
       
   957         {
       
   958         supported = EFalse;
       
   959         RArray<TUint> supportedModeArray;			
       
   960         config->GetArrayValue(MMTPDataProviderConfig::ESupportedModes, supportedModeArray);
       
   961         TInt i=0;
       
   962         while (i < supportedModeArray.Count())
       
   963             {
       
   964             if(iMode == supportedModeArray[i])
       
   965                 {
       
   966                 supported = ETrue;
       
   967                 break;
       
   968                 }
       
   969             i++;
       
   970             }
       
   971         supportedModeArray.Close();
       
   972         if(!supported)
       
   973             {
       
   974             //Update the Database table last IsDploaded filed with Efalse;
       
   975             /* create dummy  DP which is just new of Dervied DataPRoviderClass
       
   976             update the DataBase  so that DPIP which this was get then set handle Store DB */
       
   977             iSingletons.ObjectMgr().MarkDPLoadedL(iNextDpId,EFalse);
       
   978             RBuf dummyfilename;
       
   979             CleanupClosePushL(dummyfilename);
       
   980             dummyfilename.CreateL(KMTPDpDummyResourcefile.BufferSize);        		
       
   981             dummyfilename.Append(KMTPDpDummyResourcefile);							
       
   982             CMTPDataProviderConfig* aDummyConfig(CreateConfigLC(dummyfilename));
       
   983             CMTPDataProvider* dummyDp(NULL);		
       
   984             dummyDp = CMTPDataProvider::NewLC(iNextDpId, TUid::Uid(uid), aDummyConfig);
       
   985             iDataProviders.InsertInOrderL(dummyDp, TLinearOrder<CMTPDataProvider>(CMTPDataProvider::LinearOrderUid));			
       
   986             CleanupStack::Pop(dummyDp);          						
       
   987             CleanupStack::Pop(aDummyConfig);
       
   988             CleanupStack::PopAndDestroy(&dummyfilename);			
       
   989             }
       
   990         }
       
   991     CMTPDataProvider* dp(NULL);
       
   992     if(supported)
       
   993         {
       
   994         // Load the data provider.        	
       
   995         switch (config->UintValue(MMTPDataProviderConfig::EDataProviderType))
       
   996             {
       
   997         case EEcom:
       
   998             {
       
   999             // Configurability parameter data ownership is passed to the data provider.
       
  1000             iSingletons.ObjectMgr().MarkDPLoadedL(iNextDpId, ETrue);
       
  1001             dp = CMTPDataProvider::NewLC(iNextDpId, TUid::Uid(uid), config);
       
  1002             }
       
  1003             break;
       
  1004 
       
  1005         default:
       
  1006             __DEBUG_ONLY(User::Invariant());
       
  1007             break;
       
  1008             }
       
  1009     	}
       
  1010     if (dp)
       
  1011         {
       
  1012         // Register the data provider.
       
  1013         switch (uid)
       
  1014             {
       
  1015             case KMTPImplementationUidDeviceDp:
       
  1016                 iDpIdDeviceDp = iNextDpId;
       
  1017                 break;
       
  1018 
       
  1019             case KMTPImplementationUidFileDp:
       
  1020                 iDpIdFileDp = iNextDpId;
       
  1021                 break;
       
  1022 
       
  1023             case KMTPImplementationUidProxyDp:
       
  1024                 iDpIdProxyDp = iNextDpId;
       
  1025                 break;
       
  1026 
       
  1027             default:
       
  1028                 break;
       
  1029             }
       
  1030         iDataProviders.InsertInOrderL(dp,  TLinearOrder<CMTPDataProvider>(CMTPDataProvider::LinearOrderUid));
       
  1031         CleanupStack::Pop(dp);
       
  1032         CleanupStack::Pop(config);
       
  1033         success = ETrue;
       
  1034         }
       
  1035     else
       
  1036         {
       
  1037         // No data provider was created.
       
  1038         CleanupStack::PopAndDestroy(config);
       
  1039         }
       
  1040     __FLOG(_L8("LoadDataProviderL - Exit"));
       
  1041     return success;
       
  1042     }
       
  1043 
       
  1044 /**
       
  1045 Provides the implemetation UID associated with the specified data provider 
       
  1046 configuration data resource filename.
       
  1047 @param aResourceFilename The data provider configuration data resource
       
  1048 filename.
       
  1049 @param aUid On completion, the implemetation UID.
       
  1050 */
       
  1051 TInt CMTPDataProviderController::Uid(const TDesC& aResourceFilename, TUint& aUid)
       
  1052     {
       
  1053     __FLOG(_L8("Uid - Entry"));
       
  1054     // Extract the implemetation UID from the filename.
       
  1055     TParsePtrC parser(aResourceFilename);
       
  1056     TLex lex(parser.Name());
       
  1057     TInt err = lex.Val(aUid, EHex);
       
  1058     __FLOG(_L8("Uid - Exit"));
       
  1059     return err;
       
  1060     }
       
  1061 
       
  1062 /**
       
  1063 Schedules an enumeration iteration.
       
  1064 */
       
  1065 void CMTPDataProviderController::Schedule()
       
  1066     {
       
  1067     __FLOG(_L8("Schedule - Entry"));
       
  1068     if (!IsActive())
       
  1069         {
       
  1070         TRequestStatus* status(&iStatus);
       
  1071         *status = KRequestPending;
       
  1072         SetActive();
       
  1073         User::RequestComplete(status, KErrNone);
       
  1074         }
       
  1075     __FLOG(_L8("Schedule - Exit"));
       
  1076     }
       
  1077 /**
       
  1078 Get the mtpkey mode.
       
  1079 */    
       
  1080 TMTPOperationalMode CMTPDataProviderController::Mode()
       
  1081 	{
       
  1082 	return iMode;
       
  1083 	}
       
  1084      
       
  1085 void CMTPDataProviderController::ImplementationsCleanup(TAny* aData)
       
  1086     {
       
  1087     reinterpret_cast<RImplInfoPtrArray*>(aData)->ResetAndDestroy();
       
  1088     }
       
  1089     
       
  1090 /**
       
  1091 Implements a linear order relation for @see CImplementationInformation 
       
  1092 objects based on relative @see CImplementationInformation::ImplementationUid.
       
  1093 @param aUid The implementation UID object to match.
       
  1094 @param aObject The object instance to match.
       
  1095 @return Zero, if the two objects are equal; A negative value, if the first 
       
  1096 object is less than the second, or; A positive value, if the first object is 
       
  1097 greater than the second.
       
  1098 */     
       
  1099 TInt CMTPDataProviderController::ImplementationsLinearOrderUid(const TUid* aUid, const CImplementationInformation& aObject)
       
  1100     {
       
  1101     return (aUid->iUid - aObject.ImplementationUid().iUid);
       
  1102     }
       
  1103     
       
  1104 /**
       
  1105 Implements a @see TLinearOrder for @see CImplementationInformation objects 
       
  1106 based on relative @see CImplementationInformation::ImplementationUid.
       
  1107 @param aL The first object instance.
       
  1108 @param aR The second object instance.
       
  1109 @return Zero, if the two objects are equal; A negative value, if the first 
       
  1110 object is less than the second, or; A positive value, if the first object is 
       
  1111 greater than the second.
       
  1112 */   
       
  1113 TInt CMTPDataProviderController::ImplementationsLinearOrderUid(const CImplementationInformation& aL, const CImplementationInformation& aR)
       
  1114     {
       
  1115     return (aL.ImplementationUid().iUid - aR.ImplementationUid().iUid);
       
  1116     }
       
  1117 
       
  1118 /**
       
  1119 Provides the enumeration state
       
  1120 @return iEnumerationState
       
  1121 */
       
  1122 EXPORT_C TUint CMTPDataProviderController::EnumerateState()
       
  1123     {
       
  1124     return iEnumerationState;
       
  1125     } 
       
  1126 
       
  1127 void CMTPDataProviderController::CreateRegistrySessionAndEntryL()
       
  1128 	{
       
  1129 	User::LeaveIfError(iSisSession.Connect());
       
  1130     CleanupClosePushL(iSisSession);
       
  1131     TInt err = KErrNone;
       
  1132     TUint stubuid;
       
  1133     iSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::EPackageStubUID , stubuid);
       
  1134  	TRAP_IGNORE(err=iSisEntry.Open(iSisSession, TUid::Uid(stubuid) ));
       
  1135 	if(err == KErrNone)
       
  1136 		{
       
  1137 		iStubFound = ETrue;	
       
  1138 		}
       
  1139 	CleanupStack::Pop();	
       
  1140 	}
       
  1141 	
       
  1142 void  CMTPDataProviderController::CloseRegistrySessionAndEntryL()
       
  1143 	{
       
  1144 	if (&iSisEntry != NULL)
       
  1145 		{
       
  1146 		iSisEntry.Close();	
       
  1147 		}
       
  1148 	iSisSession.Close();
       
  1149 	}
       
  1150