harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp
branchRCL_3
changeset 63 e538444823de
parent 53 29d87345eaeb
equal deleted inserted replaced
57:2872ae438bf7 63:e538444823de
    58     
    58     
    59     if (iMMCMonitor)
    59     if (iMMCMonitor)
    60     	{
    60     	{
    61     	iMMCMonitor->StopMonitoring();
    61     	iMMCMonitor->StopMonitoring();
    62     	delete iMMCMonitor;
    62     	delete iMMCMonitor;
    63     	iMMCMonitor = NULL;
       
    64     	}
    63     	}
    65     
    64     
    66 	if (iUsbMonitor)
    65 	if (iUsbMonitor)
    67     	{
    66     	{
    68     	iUsbMonitor->StopMonitoring();
    67     	iUsbMonitor->StopMonitoring();
    69     	delete iUsbMonitor;
    68     	delete iUsbMonitor;
    70     	iUsbMonitor = NULL;
       
    71     	}
    69     	}
    72     
    70     
    73 	if (iMountTask)
    71 	if (iMountTask)
    74     	{
    72     	{
    75     	delete iMountTask;
    73     	delete iMountTask;
    76     	iMountTask = NULL;
       
    77     	}
    74     	}
    78 	
    75 	
    79 	delete iMmcScanner;
    76 	delete iMmcScanner;
    80 	iMmcScanner = NULL;
       
    81 	delete iHddScanner;
    77 	delete iHddScanner;
    82 	iHddScanner = NULL;
       
    83 	
    78 	
    84 	iFs.Close();
    79 	iFs.Close();
    85     }
    80     }
    86 
    81 
    87 TBool CMMCMonitorPlugin::StartMonitoring( MMonitorPluginObserver& aObserver,
    82 TBool CMMCMonitorPlugin::StartMonitoring( MMonitorPluginObserver& aObserver,
   114     
   109     
   115     TChar driveLetter( 0 );
   110     TChar driveLetter( 0 );
   116 	TBool presentState( EFalse );
   111 	TBool presentState( EFalse );
   117     
   112     
   118 	TUint32 hdMediaId( 0 );
   113 	TUint32 hdMediaId( 0 );
   119 	TBool hdPresent( EFalse );
   114     hdMediaId = iMountTask->GetInternalDriveMediaId();
   120     hdMediaId = iMountTask->GetInternalDriveMediaId( hdPresent );
       
   121     
   115     
   122     for( TInt i = medias.Count() - 1; i >=0; i-- )
   116     for( TInt i = medias.Count() - 1; i >=0; i-- )
   123     	{
   117     	{
   124     	TRAP_IGNORE( iMdEClient->GetMediaL( medias[i].iMediaId, driveLetter, presentState ) );
   118     	TRAP_IGNORE( iMdEClient->GetMediaL( medias[i].iMediaId, driveLetter, presentState ) );
   125     	
   119     	
   136     		TRAP_IGNORE( iMmcScanner = CMmcScannerAO::NewL( medias[i].iMediaId, iMdEClient, iObserver,
   130     		TRAP_IGNORE( iMmcScanner = CMmcScannerAO::NewL( medias[i].iMediaId, iMdEClient, iObserver,
   137     		    				aHarvesterPluginFactory, CActive::EPriorityUserInput ) );
   131     		    				aHarvesterPluginFactory, CActive::EPriorityUserInput ) );
   138     		}
   132     		}
   139     	}
   133     	}
   140  
   134  
   141     if( hdMediaId == 0 || !hdPresent )
   135     if( hdMediaId == 0 )
   142         {
   136         {
   143         // Try to fetch internall mass storage media id again if it was not mounted
   137         // Try to fetch internall mass storage media id again if it was not mounted
   144         hdMediaId = iMountTask->GetInternalDriveMediaId( hdPresent );
   138         hdMediaId = iMountTask->GetInternalDriveMediaId();
   145         }
   139         }
   146     
   140     
   147     // scan mass storage to catch all chances even if battery dies during operation that should  be catched
   141     // scan mass storage to catch all chances even if battery dies during operation that should  be catched
   148     if( hdMediaId )
   142     if( hdMediaId )
   149 		{
   143 		{
   150 		TBool exists( EFalse );
   144 		TBool exists( EFalse );
   151 		TRAP_IGNORE( exists= iMdEClient->GetMediaL( hdMediaId, driveLetter, presentState ) );
   145 		TRAP_IGNORE( exists= iMdEClient->GetMediaL( hdMediaId, driveLetter, presentState ) );
   152 		
   146 		
   153 		if ( exists && hdPresent )
   147 		if ( exists )
   154 			{
   148 			{
   155 			WRITELOG("CMMCMonitorPlugin::StartMonitoring - start mass storage scan");
   149 			WRITELOG("CMMCMonitorPlugin::StartMonitoring - start mass storage scan");
   156 			
   150 			
   157 			TMdEMediaInfo hdInfo;
   151 			TMdEMediaInfo hdInfo;
   158 			hdInfo.iMediaId = hdMediaId;
   152 			hdInfo.iMediaId = hdMediaId;
   223     {
   217     {
   224     WRITELOG( "CMMCMonitorPlugin::MountEvent" );
   218     WRITELOG( "CMMCMonitorPlugin::MountEvent" );
   225 
   219 
   226     TMountData* mountData = NULL;
   220     TMountData* mountData = NULL;
   227     mountData = new TMountData;
   221     mountData = new TMountData;
   228     
       
   229     if ( !mountData )
   222     if ( !mountData )
   230         {
   223         {
   231         return;
   224         return;
   232         }
   225         }
   233     if( aMediaID != 0 && aEventType == EMounted)
   226     if( aMediaID != 0 && aEventType == EMounted)
   253         {
   246         {
   254         case EMounted:
   247         case EMounted:
   255             {
   248             {
   256             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EMounted" );
   249             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EMounted" );
   257             mountData->iMountType = TMountData::EMount;
   250             mountData->iMountType = TMountData::EMount;
   258             
   251             iMountTask->StartMount( *mountData );
   259             // If mass storage mounting was delayed in boot so that mount event
       
   260             // occures in mmc monitor, update the mass storage media id in the
       
   261             // db in case factory settings were reseted and mass storage formatted
       
   262             TInt drive( -1 );
       
   263             TInt internalMassStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
       
   264             if( internalMassStorageError == KErrNone )
       
   265                 {
       
   266                 TVolumeInfo internalMassStorageVolumeInfo;
       
   267                 internalMassStorageError = iFs.Volume( internalMassStorageVolumeInfo, drive );
       
   268                 if( internalMassStorageError == KErrNone )
       
   269                     {
       
   270                     const TUint32 massStorageMediaId( internalMassStorageVolumeInfo.iUniqueID );
       
   271                     if( massStorageMediaId == aMediaID &&
       
   272                         massStorageMediaId != 0 )
       
   273                         {
       
   274                         TUint32 mmcMediaId( 0 );
       
   275                         TInt mmcDrive( -1 );
       
   276                         TInt mmcError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, mmcDrive ) );
       
   277                         if( mmcError == KErrNone )
       
   278                             {
       
   279                             if( drive != mmcDrive )
       
   280                                 {
       
   281                                 TVolumeInfo mmcVolumeInfo;
       
   282                                 mmcError = iFs.Volume( mmcVolumeInfo, mmcDrive );
       
   283                                 if( mmcError == KErrNone )
       
   284                                     {
       
   285                                     mmcMediaId = mmcVolumeInfo.iUniqueID;
       
   286                                     }                        
       
   287                                 }
       
   288                             else
       
   289                                 {
       
   290                                 mmcMediaId = massStorageMediaId;
       
   291                                 }
       
   292                             }
       
   293                     
       
   294                         // If removable storage is not found, assume internal mass storage was mounted
       
   295                         if( mmcError )
       
   296                             {
       
   297                             iMdEClient->CheckMassStorageMediaId( massStorageMediaId );              
       
   298                             }
       
   299                         else if( massStorageMediaId != mmcMediaId )
       
   300                             {
       
   301                             iMdEClient->CheckMassStorageMediaId( massStorageMediaId );
       
   302                             }          
       
   303                         }                    
       
   304                     }
       
   305                 }
       
   306             
       
   307             TRAPD(err, iMountTask->StartMountL( *mountData ))
       
   308 			
       
   309             if(err != KErrNone )
       
   310                 {
       
   311                 delete mountData;
       
   312                 mountData = NULL;
       
   313                 }
       
   314             }
   252             }
   315         break;
   253         break;
   316         
   254         
   317         case EDismounted:
   255         case EDismounted:
   318             {
   256             {
   322             	}
   260             	}
   323             if( mountData->iMediaID )
   261             if( mountData->iMediaID )
   324             	{
   262             	{
   325 	            WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EDismounted" );
   263 	            WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EDismounted" );
   326 	            mountData->iMountType = TMountData::EUnmount;
   264 	            mountData->iMountType = TMountData::EUnmount;
   327 	            TRAPD(err, iMountTask->StartUnmountL( *mountData ));
   265 	            iMountTask->StartUnmount( *mountData );
   328 	            
       
   329 	            if(err != KErrNone )
       
   330 	                {
       
   331 	                delete mountData;
       
   332 	                mountData = NULL;
       
   333 	                }
       
   334             	}
   266             	}
   335             else
   267             else
   336                 {
   268                 {
   337                 delete mountData;
   269                 delete mountData;
   338                 mountData = NULL;
   270                 mountData = NULL;
   342         
   274         
   343         case EFormatted:
   275         case EFormatted:
   344             {
   276             {
   345             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EFormatted" );
   277             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EFormatted" );
   346             mountData->iMountType = TMountData::EFormat;
   278             mountData->iMountType = TMountData::EFormat;
   347             TRAPD(err, iMountTask->StartUnmountL( *mountData ));
   279             iMountTask->StartUnmount( *mountData );
   348 			
       
   349             if(err != KErrNone)
       
   350                 {
       
   351                 delete mountData;
       
   352                 mountData = NULL;
       
   353                 }
       
   354             }
   280             }
   355         break;
   281         break;
   356         
   282         
   357         default:
   283         default:
   358             {
   284             {