harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp
branchRCL_3
changeset 47 b73252188534
parent 27 4a4892eec172
child 49 f23c07ec56e2
--- a/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Thu Jul 15 19:07:24 2010 +0300
+++ b/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Thu Aug 19 10:20:41 2010 +0300
@@ -60,21 +60,26 @@
     	{
     	iMMCMonitor->StopMonitoring();
     	delete iMMCMonitor;
+    	iMMCMonitor = NULL;
     	}
     
 	if (iUsbMonitor)
     	{
     	iUsbMonitor->StopMonitoring();
     	delete iUsbMonitor;
+    	iUsbMonitor = NULL;
     	}
     
 	if (iMountTask)
     	{
     	delete iMountTask;
+    	iMountTask = NULL;
     	}
 	
 	delete iMmcScanner;
+	iMmcScanner = NULL;
 	delete iHddScanner;
+	iHddScanner = NULL;
 	
 	iFs.Close();
     }
@@ -219,6 +224,7 @@
 
     TMountData* mountData = NULL;
     mountData = new TMountData;
+    
     if ( !mountData )
         {
         return;
@@ -248,7 +254,56 @@
             {
             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EMounted" );
             mountData->iMountType = TMountData::EMount;
-            iMountTask->StartMount( *mountData );
+            
+            // If mass storage mounting was delayed in boot so that mount event
+            // occures in mmc monitor, update the mass storage media id in the
+            // db in case factory settings were reseted and mass storage formatted
+            TInt drive( -1 );
+            TInt internalMassStorageError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, drive ) );
+            if( internalMassStorageError == KErrNone )
+                {
+                TVolumeInfo internalMassStorageVolumeInfo;
+                internalMassStorageError = iFs.Volume( internalMassStorageVolumeInfo, drive );
+                if( internalMassStorageError == KErrNone )
+                    {
+                    const TUint32 massStorageMediaId( internalMassStorageVolumeInfo.iUniqueID );
+                    TUint32 mmcMediaId( 0 );
+                    TInt mmcError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, drive ) );
+                    if( mmcError == KErrNone )
+                        {
+                        TVolumeInfo mmcVolumeInfo;
+                        mmcError = iFs.Volume( mmcVolumeInfo, drive );
+                        if( mmcError == KErrNone )
+                            {
+                            mmcMediaId = mmcVolumeInfo.iUniqueID;
+                            }
+                        }
+                    
+                    // If removable storage is not found, assume internal mass storage was mounted
+                    if( mmcError )
+                        {
+                        if( massStorageMediaId != 0 && 
+                            massStorageMediaId == aMediaID )
+                            {
+                            iMdEClient->CheckMassStorageMediaId( massStorageMediaId );
+                            }                    
+                        }
+                    else if( massStorageMediaId != mmcMediaId && 
+                                massStorageMediaId != 0 && 
+                                massStorageMediaId == aMediaID )
+                        {
+                        iMdEClient->CheckMassStorageMediaId( massStorageMediaId );
+                        }          
+                    }
+                }
+            
+            TRAPD(err, iMountTask->StartMountL( *mountData ))
+			
+            if(err != KErrNone )
+                {
+                delete mountData;
+                mountData = NULL;
+                }
             }
         break;
         
@@ -262,7 +317,13 @@
             	{
 	            WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EDismounted" );
 	            mountData->iMountType = TMountData::EUnmount;
-	            iMountTask->StartUnmount( *mountData );
+	            TRAPD(err, iMountTask->StartUnmountL( *mountData ));
+	            
+	            if(err != KErrNone )
+	                {
+	                delete mountData;
+	                mountData = NULL;
+	                }
             	}
             else
                 {
@@ -276,7 +337,13 @@
             {
             WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EFormatted" );
             mountData->iMountType = TMountData::EFormat;
-            iMountTask->StartUnmount( *mountData );
+            TRAPD(err, iMountTask->StartUnmountL( *mountData ));
+			
+            if(err != KErrNone)
+                {
+                delete mountData;
+                mountData = NULL;
+                }
             }
         break;