harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp
changeset 54 a3cc46f37772
parent 28 c461c7fa72c2
--- a/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Tue Jul 06 14:44:37 2010 +0300
+++ b/harvester/monitorplugins/mmcplugin/src/mmcmonitorplugin.cpp	Fri Sep 17 16:54:49 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();
     }
@@ -111,7 +116,8 @@
 	TBool presentState( EFalse );
     
 	TUint32 hdMediaId( 0 );
-    hdMediaId = iMountTask->GetInternalDriveMediaId();
+	TBool hdPresent( EFalse );
+    hdMediaId = iMountTask->GetInternalDriveMediaId( hdPresent );
     
     for( TInt i = medias.Count() - 1; i >=0; i-- )
     	{
@@ -132,10 +138,10 @@
     		}
     	}
  
-    if( hdMediaId == 0 )
+    if( hdMediaId == 0 || !hdPresent )
         {
         // Try to fetch internall mass storage media id again if it was not mounted
-        hdMediaId = iMountTask->GetInternalDriveMediaId();
+        hdMediaId = iMountTask->GetInternalDriveMediaId( hdPresent );
         }
     
     // scan mass storage to catch all chances even if battery dies during operation that should  be catched
@@ -144,7 +150,7 @@
 		TBool exists( EFalse );
 		TRAP_IGNORE( exists= iMdEClient->GetMediaL( hdMediaId, driveLetter, presentState ) );
 		
-		if ( exists )
+		if ( exists && hdPresent )
 			{
 			WRITELOG("CMMCMonitorPlugin::StartMonitoring - start mass storage scan");
 			
@@ -219,6 +225,7 @@
 
     TMountData* mountData = NULL;
     mountData = new TMountData;
+    
     if ( !mountData )
         {
         return;
@@ -248,7 +255,62 @@
             {
             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 );
+                    if( massStorageMediaId == aMediaID &&
+                        massStorageMediaId != 0 )
+                        {
+                        TUint32 mmcMediaId( 0 );
+                        TInt mmcDrive( -1 );
+                        TInt mmcError( DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, mmcDrive ) );
+                        if( mmcError == KErrNone )
+                            {
+                            if( drive != mmcDrive )
+                                {
+                                TVolumeInfo mmcVolumeInfo;
+                                mmcError = iFs.Volume( mmcVolumeInfo, mmcDrive );
+                                if( mmcError == KErrNone )
+                                    {
+                                    mmcMediaId = mmcVolumeInfo.iUniqueID;
+                                    }                        
+                                }
+                            else
+                                {
+                                mmcMediaId = massStorageMediaId;
+                                }
+                            }
+                    
+                        // If removable storage is not found, assume internal mass storage was mounted
+                        if( mmcError )
+                            {
+                            iMdEClient->CheckMassStorageMediaId( massStorageMediaId );              
+                            }
+                        else if( massStorageMediaId != mmcMediaId )
+                            {
+                            iMdEClient->CheckMassStorageMediaId( massStorageMediaId );
+                            }          
+                        }                    
+                    }
+                }
+            
+            TRAPD(err, iMountTask->StartMountL( *mountData ))
+			
+            if(err != KErrNone )
+                {
+                delete mountData;
+                mountData = NULL;
+                }
             }
         break;
         
@@ -262,7 +324,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 +344,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;