mtpfws/mtpfw/dataproviders/devdp/src/cmtpstoragewatcher.cpp
changeset 47 63cf70d3ecd8
parent 17 aabe5387f5ce
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    23 #include "cmtpframeworkconfig.h"
    23 #include "cmtpframeworkconfig.h"
    24 #include "cmtpstoragemgr.h"
    24 #include "cmtpstoragemgr.h"
    25 #include "cmtpobjectmgr.h"
    25 #include "cmtpobjectmgr.h"
    26 #include "cmtpstoragewatcher.h"
    26 #include "cmtpstoragewatcher.h"
    27 #include "cmtpdevicedpconfigmgr.h"
    27 #include "cmtpdevicedpconfigmgr.h"
       
    28 #include "mtpdebug.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "cmtpstoragewatcherTraces.h"
       
    32 #endif
       
    33 
    28 
    34 
    29 
    35 
    30 // Class constants.
    36 // Class constants.
    31 __FLOG_STMT(_LIT8(KComponent,"StorageWatcher");)
       
    32 static const TBool KAllDrives(ETrue);
    37 static const TBool KAllDrives(ETrue);
    33 static const TBool KAvailableDrives(EFalse);
    38 static const TBool KAvailableDrives(EFalse);
    34 
    39 
    35 const TInt KFolderExclusionGranularity = 8;
    40 const TInt KFolderExclusionGranularity = 8;
    36 
    41 
    52 /**
    57 /**
    53 Destructor.
    58 Destructor.
    54 */    
    59 */    
    55 CMTPStorageWatcher::~CMTPStorageWatcher()
    60 CMTPStorageWatcher::~CMTPStorageWatcher()
    56     {
    61     {
    57     __FLOG(_L8("~CMTPStorageWatcher - Entry"));
    62     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_CMTPSTORAGEWATCHER_ENTRY );
    58     Cancel();
    63     Cancel();
    59     delete iFolderExclusionList;
    64     delete iFolderExclusionList;
    60     iDpSingletons.Close();
    65     iDpSingletons.Close();
    61     iDrivesExcluded.Close();
    66     iDrivesExcluded.Close();
    62     iFrameworkSingletons.Close();
    67     iFrameworkSingletons.Close();
    63     iDevDpSingletons.Close();
    68     iDevDpSingletons.Close();
    64     __FLOG(_L8("~CMTPStorageWatcher - Exit"));
    69     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_CMTPSTORAGEWATCHER_EXIT );
    65     __FLOG_CLOSE;
       
    66     }
    70     }
    67     
    71     
    68 void CMTPStorageWatcher::EnumerateStoragesL()
    72 void CMTPStorageWatcher::EnumerateStoragesL()
    69     {
    73     {
    70     __FLOG(_L8("EnumerateStoragesL - Entry"));
    74     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_ENUMERATESTORAGESL_ENTRY );
    71 
    75 
    72     //Use Hash to replace it
    76     //Use Hash to replace it
    73     AppendFolderExclusionListL();
    77     AppendFolderExclusionListL();
    74     
    78     
    75     // Retrieve the drive exclusion list.
    79     // Retrieve the drive exclusion list.
    97         {
   101         {
    98         const TUint32 mask(1 << drive);
   102         const TUint32 mask(1 << drive);
    99         if (iDrivesConfig & mask)
   103         if (iDrivesConfig & mask)
   100             {
   104             {
   101             TChar driveChar;
   105             TChar driveChar;
   102             User::LeaveIfError(iFramework.Fs().DriveToChar(drive, driveChar));
   106             LEAVEIFERROR(iFramework.Fs().DriveToChar(drive, driveChar),
       
   107                     OstTrace1( TRACE_ERROR, CMTPSTORAGEWATCHER_ENUMERATESTORAGESL, "drive %d convert to char error!", drive ));
   103             suid[0] = driveChar;
   108             suid[0] = driveChar;
   104             storage->SetDesCL(CMTPStorageMetaData::EStorageSuid, suid);
   109             storage->SetDesCL(CMTPStorageMetaData::EStorageSuid, suid);
   105                     
   110                     
   106             TUint32 id(mgr.AllocatePhysicalStorageIdL(iFramework.DataProviderId(), *storage));
   111             TUint32 id(mgr.AllocatePhysicalStorageIdL(iFramework.DataProviderId(), *storage));
   107             mgr.SetDriveMappingL(static_cast<TDriveNumber>(drive), id);
   112             mgr.SetDriveMappingL(static_cast<TDriveNumber>(drive), id);
   149        {
   154        {
   150        // Default drive is specified by storage number
   155        // Default drive is specified by storage number
   151        mgr.SetDefaultStorageId(defaultDrive);
   156        mgr.SetDefaultStorageId(defaultDrive);
   152        }
   157        }
   153        
   158        
   154     __FLOG(_L8("EnumerateStoragesL - Exit"));
   159     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_ENUMERATESTORAGESL_EXIT );
   155     }
   160     }
   156 
   161 
   157 /**
   162 /**
   158 Initiates storage change notice subscription.
   163 Initiates storage change notice subscription.
   159 */
   164 */
   160 void CMTPStorageWatcher::Start()
   165 void CMTPStorageWatcher::Start()
   161     {
   166     {
   162     __FLOG(_L8("Start - Entry"));
   167     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_START_ENTRY );
   163     if (!(iState & EStarted))
   168     if (!(iState & EStarted))
   164         {
   169         {
   165         __FLOG(_L8("Starting RFs notifier"));
   170         OstTrace0( TRACE_NORMAL, CMTPSTORAGEWATCHER_START, "Starting RFs notifier" );
   166         TRequestStatus* status(&iStatus);
   171         TRequestStatus* status(&iStatus);
   167         User::RequestComplete(status, KErrNone);
   172         User::RequestComplete(status, KErrNone);
   168         SetActive();
   173         SetActive();
   169         iState |= EStarted;
   174         iState |= EStarted;
   170         }
   175         }
   171     __FLOG(_L8("Start - Exit"));    
   176     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_START_EXIT );
   172     }
   177     }
   173     
   178     
   174 void CMTPStorageWatcher::DoCancel()
   179 void CMTPStorageWatcher::DoCancel()
   175     {
   180     {
   176     __FLOG(_L8("DoCancel - Entry"));
   181     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_DOCANCEL_ENTRY );
   177     __FLOG(_L8("Stopping RFs notifier"));
   182     OstTrace0( TRACE_NORMAL, CMTPSTORAGEWATCHER_DOCANCEL, "Stopping RFs notifier" );
   178     iFrameworkSingletons.Fs().NotifyChangeCancel();
   183     iFrameworkSingletons.Fs().NotifyChangeCancel();
   179     iState &= (!EStarted);
   184     iState &= (!EStarted);
   180     __FLOG(_L8("DoCancel - Exit"));
   185     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_DOCANCEL_EXIT );
   181     }
   186     }
   182 
   187 
   183 /**
   188 /**
   184 Append all DPs folder exclusion list strings in Device DP
   189 Append all DPs folder exclusion list strings in Device DP
   185  */
   190  */
   210 /**
   215 /**
   211 Handles leaves occurring in RunL.
   216 Handles leaves occurring in RunL.
   212 @param aError leave error code
   217 @param aError leave error code
   213 @return KErrNone
   218 @return KErrNone
   214 */
   219 */
   215 #ifdef __FLOG_ACTIVE
   220 #ifdef OST_TRACE_COMPILER_IN_USE
   216 TInt CMTPStorageWatcher::RunError(TInt aError)
   221 TInt CMTPStorageWatcher::RunError(TInt aError)
   217 #else
   222 #else
   218 TInt CMTPStorageWatcher::RunError(TInt /*aError*/)
   223 TInt CMTPStorageWatcher::RunError(TInt /*aError*/)
   219 #endif
   224 #endif
   220     {
   225     {
   221     __FLOG(_L8("RunError - Entry"));
   226     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_RUNERROR_ENTRY );
   222     __FLOG_VA((_L8("Error = %d"), aError));
   227     OstTrace1( TRACE_NORMAL, CMTPSTORAGEWATCHER_RUNERROR, "Error = %d", aError );    
   223 
   228 
   224     // Ignore the error, meaning that the storages may not be accurately accounted for
   229     // Ignore the error, meaning that the storages may not be accurately accounted for
   225     RequestNotification();
   230     RequestNotification();
   226 
   231 
   227     __FLOG(_L8("RunError - Exit"));
   232     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_RUNERROR_EXIT );
   228     return KErrNone;
   233     return KErrNone;
   229     }
   234     }
   230     
   235     
   231 void CMTPStorageWatcher::RunL()
   236 void CMTPStorageWatcher::RunL()
   232     {
   237     {
   233     __FLOG(_L8("RunL - Entry"));
   238     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_RUNL_ENTRY );
   234     const TUint32 previous(iDrivesConfig);
   239     const TUint32 previous(iDrivesConfig);
   235     const TUint32 current(DriveConfigurationL(KAvailableDrives));
   240     const TUint32 current(DriveConfigurationL(KAvailableDrives));
   236     if (current != previous)
   241     if (current != previous)
   237         {        
   242         {        
   238         const TUint32 changed(current ^ previous);
   243         const TUint32 changed(current ^ previous);
   252                 }
   257                 }
   253             }
   258             }
   254         }
   259         }
   255     iDrivesConfig = current;
   260     iDrivesConfig = current;
   256     RequestNotification();
   261     RequestNotification();
   257     __FLOG(_L8("RunL - Exit"));
   262     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_RUNL_EXIT );
   258     }
   263     }
   259     
   264     
   260 /**
   265 /**
   261 Constructor.
   266 Constructor.
   262 @param aConnectionMgr The MTP connection manager interface.
   267 @param aConnectionMgr The MTP connection manager interface.
   271 /**
   276 /**
   272 Second phase constructor.
   277 Second phase constructor.
   273 */
   278 */
   274 void CMTPStorageWatcher::ConstructL()
   279 void CMTPStorageWatcher::ConstructL()
   275     {
   280     {
   276     __FLOG_OPEN(KMTPSubsystem, KComponent);
   281     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_CONSTRUCTL_ENTRY );
   277     __FLOG(_L8("ConstructL - Entry"));
       
   278     iFrameworkSingletons.OpenL();
   282     iFrameworkSingletons.OpenL();
   279     iFrameworkSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::ELogicalStorageIdsAllocationEnable, iAllocateLogicalStorages);
   283     iFrameworkSingletons.FrameworkConfig().GetValueL(CMTPFrameworkConfig::ELogicalStorageIdsAllocationEnable, iAllocateLogicalStorages);
   280     
   284     
   281     iDpSingletons.OpenL(iFramework);
   285     iDpSingletons.OpenL(iFramework);
   282     iDevDpSingletons.OpenL(iFramework);
   286     iDevDpSingletons.OpenL(iFramework);
   283     iFolderExclusionList = iDevDpSingletons.ConfigMgr().GetArrayValueL(CMTPDeviceDpConfigMgr::EFolderExclusionList); 
   287     iFolderExclusionList = iDevDpSingletons.ConfigMgr().GetArrayValueL(CMTPDeviceDpConfigMgr::EFolderExclusionList); 
   284 
   288 
   285     __FLOG(_L8("ConstructL - Exit"));
   289     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_CONSTRUCTL_EXIT );
   286     }
   290     }
   287     
   291     
   288 TUint32 CMTPStorageWatcher::DriveConfigurationL(TBool aAllDrives) const
   292 TUint32 CMTPStorageWatcher::DriveConfigurationL(TBool aAllDrives) const
   289     {
   293     {
   290     __FLOG(_L8("DriveConfigurationL - Entry"));
   294     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_DRIVECONFIGURATIONL_ENTRY );
   291     TUint32     config(0);
   295     TUint32     config(0);
   292     TDriveList  drives;
   296     TDriveList  drives;
   293     RFs&        fs(iFrameworkSingletons.Fs());
   297     RFs&        fs(iFrameworkSingletons.Fs());
   294     User::LeaveIfError(fs.DriveList(drives));
   298     User::LeaveIfError(fs.DriveList(drives));
   295     TInt i(KMaxDrives);
   299     TInt i(KMaxDrives);
   296     while (i--)
   300     while (i--)
   297         {        
   301         {        
   298         __FLOG_VA((_L8("Drive number %d, available = 0x%02d"), i, drives [i]));
   302         OstTraceExt2( TRACE_NORMAL, CMTPSTORAGEWATCHER_DRIVECONFIGURATIONL, 
       
   303                 "Drive number %d, available = 0x%02d", i, drives[i] );
   299         if ((drives[i]) &&
   304         if ((drives[i]) &&
   300             (!Excluded(static_cast<TDriveNumber>(i))))
   305             (!Excluded(static_cast<TDriveNumber>(i))))
   301             {
   306             {
   302             TDriveInfo info;
   307             TDriveInfo info;
   303             User::LeaveIfError(fs.Drive(info, i));
   308             LEAVEIFERROR(fs.Drive(info, i),
       
   309                     OstTrace1( TRACE_ERROR, DUP2_CMTPSTORAGEWATCHER_DRIVECONFIGURATIONL, "can't get info for drive %d", i ));
       
   310                     
   304             if ((info.iType != EMediaNotPresent) || (aAllDrives))
   311             if ((info.iType != EMediaNotPresent) || (aAllDrives))
   305                 {
   312                 {
   306                 TVolumeInfo volumeInfo;
   313                 TVolumeInfo volumeInfo;
   307                 if(KErrNone == fs.Volume(volumeInfo,i))
   314                 if(KErrNone == fs.Volume(volumeInfo,i))
   308                 	{
   315                 	{
   309                 	config |=  (1 << i);
   316                 	config |=  (1 << i);
   310                 	}
   317                 	}
   311                 }
   318                 }
   312             }
   319             }
   313         }
   320         }
   314     __FLOG_VA((_L8("Drives list = 0x%08X, AllDrives = %d"), config, aAllDrives));
   321     OstTraceExt2( TRACE_NORMAL, DUP1_CMTPSTORAGEWATCHER_DRIVECONFIGURATIONL, 
   315     __FLOG(_L8("DriveConfigurationL - Exit"));
   322             "Drives list = 0x%08X, AllDrives = %d", config, (TUint32)aAllDrives );    
       
   323     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_DRIVECONFIGURATIONL_EXIT );
   316     return config;
   324     return config;
   317     }
   325     }
   318 
   326 
   319 TBool CMTPStorageWatcher::Excluded(TDriveNumber aDriveNumber) const
   327 TBool CMTPStorageWatcher::Excluded(TDriveNumber aDriveNumber) const
   320     {
   328     {
   321     __FLOG(_L8("Excluded - Entry"));
   329     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_EXCLUDED_ENTRY );
   322     TBool ret(iDrivesExcluded.FindInOrder(aDriveNumber) != KErrNotFound);
   330     TBool ret(iDrivesExcluded.FindInOrder(aDriveNumber) != KErrNotFound);
   323     __FLOG_VA((_L8("Drive = %d, excluded = %d"), aDriveNumber, ret));
   331     OstTraceExt2( TRACE_NORMAL, CMTPSTORAGEWATCHER_EXCLUDED, 
   324     __FLOG(_L8("Excluded - Exit"));
   332             "Drive = %d, excluded = %d", aDriveNumber, ret );      
       
   333     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_EXCLUDED_EXIT );
   325     return ret;
   334     return ret;
   326     }
   335     }
   327     
   336     
   328 void CMTPStorageWatcher::RequestNotification()
   337 void CMTPStorageWatcher::RequestNotification()
   329     {
   338     {
   330     __FLOG(_L8("RequestNotification - Entry"));
   339     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_REQUESTNOTIFICATION_ENTRY );
   331     _LIT(KPath, "?:\\..");
   340     _LIT(KPath, "?:\\..");
   332     iFrameworkSingletons.Fs().NotifyChange(ENotifyEntry, iStatus, KPath);
   341     iFrameworkSingletons.Fs().NotifyChange(ENotifyEntry, iStatus, KPath);
   333     SetActive();
   342     SetActive();
   334     __FLOG(_L8("RequestNotification - Exit"));
   343     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_REQUESTNOTIFICATION_EXIT );
   335     }
   344     }
   336  
   345  
   337 void CMTPStorageWatcher::SendEventL(TUint16 aEvent, TUint32 aStorageId)
   346 void CMTPStorageWatcher::SendEventL(TUint16 aEvent, TUint32 aStorageId)
   338     {
   347     {
   339     __FLOG(_L8("SendEventL - Entry"));
   348     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_SENDEVENTL_ENTRY );
   340     if (iState & EStarted)
   349     if (iState & EStarted)
   341         {
   350         {
   342         __FLOG_VA((_L8("Sending event 0x%04X for StorageID 0x%08X"), aEvent, aStorageId));
   351         OstTraceExt2( TRACE_NORMAL, CMTPSTORAGEWATCHER_SENDEVENTL, 
       
   352                 "Sending event 0x%04X for StorageID 0x%08X", (TUint32)aEvent, aStorageId );  
   343         iEvent.Reset();
   353         iEvent.Reset();
   344         iEvent.SetUint16(TMTPTypeEvent::EEventCode, aEvent);
   354         iEvent.SetUint16(TMTPTypeEvent::EEventCode, aEvent);
   345         iEvent.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll);
   355         iEvent.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll);
   346         iEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone);
   356         iEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone);
   347         iEvent.SetUint32(TMTPTypeEvent::EEventParameter1, aStorageId);
   357         iEvent.SetUint32(TMTPTypeEvent::EEventParameter1, aStorageId);
   348         iFramework.SendEventL(iEvent);
   358         iFramework.SendEventL(iEvent);
   349         }
   359         }
   350     __FLOG(_L8("SendEventL - Exit"));
   360     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_SENDEVENTL_EXIT );
   351     }
   361     }
   352 
   362 
   353 /**
   363 /**
   354 Configures the specified drive as an available MTP storage.
   364 Configures the specified drive as an available MTP storage.
   355 @param aDriveNumber The Symbian OS file system drive number.
   365 @param aDriveNumber The Symbian OS file system drive number.
   356 @leave One of the system wide error codes, if a processing failure occurs.
   366 @leave One of the system wide error codes, if a processing failure occurs.
   357 */    
   367 */    
   358 void CMTPStorageWatcher::StorageAvailableL(TDriveNumber aDriveNumber)
   368 void CMTPStorageWatcher::StorageAvailableL(TDriveNumber aDriveNumber)
   359     {
   369     {
   360     __FLOG(_L8("StorageAvailableL - Entry"));
   370     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_STORAGEAVAILABLEL_ENTRY );
   361     __FLOG_VA((_L8("Drive = %d is available."), aDriveNumber));
   371     OstTrace1( TRACE_NORMAL, CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "Drive = %d is available.", aDriveNumber);
   362     CMTPStorageMgr& mgr(iFrameworkSingletons.StorageMgr());
   372     CMTPStorageMgr& mgr(iFrameworkSingletons.StorageMgr());
   363     TInt32 physical(mgr.PhysicalStorageId(aDriveNumber));
   373     TInt32 physical(mgr.PhysicalStorageId(aDriveNumber));
   364     _LIT(KSuidTemplate, "?:");
   374     _LIT(KSuidTemplate, "?:");
   365     // Generate the storage SUID as the drive root folder.
   375     // Generate the storage SUID as the drive root folder.
   366     RBuf suid;
   376     RBuf suid;
   367     suid.CleanupClosePushL();
   377     suid.CleanupClosePushL();
   368     suid.Assign((KSuidTemplate().AllocL()));
   378     suid.Assign((KSuidTemplate().AllocL()));
   369     TChar driveChar;
   379     TChar driveChar;
   370     User::LeaveIfError(iFramework.Fs().DriveToChar(aDriveNumber, driveChar));
   380     LEAVEIFERROR(iFramework.Fs().DriveToChar(aDriveNumber, driveChar),
       
   381             OstTrace1( TRACE_ERROR, DUP6_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "driver %d convert to char error!", aDriveNumber ));       
   371     driveChar.LowerCase();
   382     driveChar.LowerCase();
   372     suid[0] = driveChar;
   383     suid[0] = driveChar;
   373     // Create the storage meta-data.
   384     // Create the storage meta-data.
   374     CMTPStorageMetaData* storage = CMTPStorageMetaData::NewLC();
   385     CMTPStorageMetaData* storage = CMTPStorageMetaData::NewLC();
   375     storage->SetUint(CMTPStorageMetaData::EStorageSystemType, CMTPStorageMetaData::ESystemTypeDefaultFileSystem);
   386     storage->SetUint(CMTPStorageMetaData::EStorageSystemType, CMTPStorageMetaData::ESystemTypeDefaultFileSystem);
   378     	{
   389     	{
   379         TUint32 id(mgr.AllocatePhysicalStorageIdL(iFramework.DataProviderId(), *storage));
   390         TUint32 id(mgr.AllocatePhysicalStorageIdL(iFramework.DataProviderId(), *storage));
   380         mgr.SetDriveMappingL(aDriveNumber, id);
   391         mgr.SetDriveMappingL(aDriveNumber, id);
   381     	}
   392     	}
   382     physical = mgr.PhysicalStorageId(aDriveNumber);
   393     physical = mgr.PhysicalStorageId(aDriveNumber);
   383 
   394     LEAVEIFERROR(physical, 
   384     User::LeaveIfError(physical);
   395             OstTrace1( TRACE_ERROR, DUP7_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "can't get physical storage id for drive %d", aDriveNumber));
       
   396             
   385     TUint32 logical(physical);
   397     TUint32 logical(physical);
   386 
   398 
   387     // If configured to do so, assign a logical storage ID mapping.
   399     // If configured to do so, assign a logical storage ID mapping.
   388     if (iAllocateLogicalStorages)
   400     if (iAllocateLogicalStorages)
   389         {
   401         {
   390         __FLOG(_L8("Assigning local storage ID mapping"));
   402         OstTrace0( TRACE_NORMAL, DUP1_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "Assigning local storage ID mapping" );       
   391         
   403         
   392         // Try to read from resource file to use a specified root dir path, if available.
   404         // Try to read from resource file to use a specified root dir path, if available.
   393         RBuf rootDirPath;
   405         RBuf rootDirPath;
   394         rootDirPath.CreateL(KMaxFileName);
   406         rootDirPath.CreateL(KMaxFileName);
   395         rootDirPath.CleanupClosePushL();
   407         rootDirPath.CleanupClosePushL();
   396         RMTPDeviceDpSingletons devSingletons;
   408         RMTPDeviceDpSingletons devSingletons;
   397         devSingletons.OpenL(iFramework);
   409         devSingletons.OpenL(iFramework);
   398         CleanupClosePushL(devSingletons);
   410         CleanupClosePushL(devSingletons);
   399         TRAPD(resError, devSingletons.ConfigMgr().GetRootDirPathL(aDriveNumber, rootDirPath));
   411         TRAPD(resError, devSingletons.ConfigMgr().GetRootDirPathL(aDriveNumber, rootDirPath));
   400         __FLOG_VA((_L8("ResError = %d"), resError));
   412         OstTrace1( TRACE_NORMAL, DUP2_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "ResError = %d", resError);    
   401         if ((KErrNone == resError) && (0 < rootDirPath.Length()))
   413         if ((KErrNone == resError) && (0 < rootDirPath.Length()))
   402             {
   414             {
   403             __FLOG(_L8("Reading resource file succeeded"));
   415             OstTrace0(TRACE_NORMAL, DUP3_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "Reading resource file succeeded");
   404             // If there is a root directory information in rss file then check the directory exist or not. 
   416             // If there is a root directory information in rss file then check the directory exist or not. 
   405             // If not exists, then create it. 
   417             // If not exists, then create it. 
   406             // Before doing anything, delete the leading and trailing white space.
   418             // Before doing anything, delete the leading and trailing white space.
   407             rootDirPath.Trim();       
   419             rootDirPath.Trim();       
   408             TBuf<KMaxFileName> buffer;
   420             TBuf<KMaxFileName> buffer;
   417             driveChar.LowerCase();
   429             driveChar.LowerCase();
   418             suid[0] = driveChar;
   430             suid[0] = driveChar;
   419 
   431 
   420             if ((KErrNone == error) || (KErrAlreadyExists == error))
   432             if ((KErrNone == error) || (KErrAlreadyExists == error))
   421                 {
   433                 {
   422                 __FLOG(_L8("Overwriting SUID to specified root dir path from resource file"));  
   434                 OstTrace0( TRACE_NORMAL, DUP4_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, "Overwriting SUID to specified root dir path from resource file" );                
   423                 //if dir already existed or created, make that as root directory
   435                 //if dir already existed or created, make that as root directory
   424                 suid.ReAllocL(buffer.Length());
   436                 suid.ReAllocL(buffer.Length());
   425                 suid = buffer;
   437                 suid = buffer;
   426                 }
   438                 }
   427             }
   439             }
   459 
   471 
   460         // Create the logical StorageID and drive mapping.
   472         // Create the logical StorageID and drive mapping.
   461         logical = mgr.AllocateLogicalStorageIdL(iFramework.DataProviderId(), physical, *storage);
   473         logical = mgr.AllocateLogicalStorageIdL(iFramework.DataProviderId(), physical, *storage);
   462         mgr.SetDriveMappingL(aDriveNumber, logical);
   474         mgr.SetDriveMappingL(aDriveNumber, logical);
   463 
   475 
   464         __FLOG_VA((_L8("Drive = %d mapped as storage 0x%08X"), aDriveNumber, logical));
   476         OstTraceExt2( TRACE_NORMAL, DUP5_CMTPSTORAGEWATCHER_STORAGEAVAILABLEL, 
       
   477                 "Drive = %d mapped as storage 0x%08X", (TUint32)aDriveNumber, logical);
   465         }
   478         }
   466 
   479 
   467     CleanupStack::PopAndDestroy(storage);
   480     CleanupStack::PopAndDestroy(storage);
   468     CleanupStack::PopAndDestroy(&suid);
   481     CleanupStack::PopAndDestroy(&suid);
   469     
   482     
   483     if (iAllocateLogicalStorages)
   496     if (iAllocateLogicalStorages)
   484         {
   497         {
   485         SendEventL(EMTPEventCodeStoreAdded, logical);
   498         SendEventL(EMTPEventCodeStoreAdded, logical);
   486         }
   499         }
   487         
   500         
   488     __FLOG(_L8("StorageAvailableL - Exit"));
   501     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_STORAGEAVAILABLEL_EXIT );
   489     }
   502     }
   490 
   503 
   491 /**
   504 /**
   492 Configures the specified drive as an unavailable MTP storage.
   505 Configures the specified drive as an unavailable MTP storage.
   493 @param aDriveNumber The Symbian OS file system drive number.
   506 @param aDriveNumber The Symbian OS file system drive number.
   494 @leave One of the system wide error codes, if a processing failure occurs.
   507 @leave One of the system wide error codes, if a processing failure occurs.
   495 */    
   508 */    
   496 void CMTPStorageWatcher::StorageUnavailableL(TDriveNumber aDriveNumber)
   509 void CMTPStorageWatcher::StorageUnavailableL(TDriveNumber aDriveNumber)
   497 {
   510 {
   498     __FLOG(_L8("StorageUnavailableL - Entry"));
   511     OstTraceFunctionEntry0( CMTPSTORAGEWATCHER_STORAGEUNAVAILABLEL_ENTRY );
   499     __FLOG_VA((_L8("Drive = %d is unavailable."), aDriveNumber));
   512     OstTrace1( TRACE_NORMAL, CMTPSTORAGEWATCHER_STORAGEUNAVAILABLEL, "Drive = %d is unavailable.", aDriveNumber );
       
   513     
   500     CMTPStorageMgr& mgr(iFrameworkSingletons.StorageMgr());
   514     CMTPStorageMgr& mgr(iFrameworkSingletons.StorageMgr());
   501     TInt32 physical(mgr.PhysicalStorageId(aDriveNumber));
   515     TInt32 physical(mgr.PhysicalStorageId(aDriveNumber));
   502     User::LeaveIfError(physical);
   516     LEAVEIFERROR(physical,
       
   517             OstTrace1( TRACE_ERROR, DUP2_CMTPSTORAGEWATCHER_STORAGEUNAVAILABLEL, "can't get physical storage id for drive %d", aDriveNumber));
   503     TUint32 logical(0);
   518     TUint32 logical(0);
   504     
   519     
   505     // If configured to do so, assign a logical storage ID mapping.
   520     // If configured to do so, assign a logical storage ID mapping.
   506     if (iAllocateLogicalStorages)
   521     if (iAllocateLogicalStorages)
   507         {
   522         {
   508         logical = mgr.FrameworkStorageId(aDriveNumber);
   523         logical = mgr.FrameworkStorageId(aDriveNumber);
   509 
   524 
   510         // Deassign the logical storage ID mapping.
   525         // Deassign the logical storage ID mapping.
   511         mgr.DeallocateLogicalStorageIds(iFramework.DataProviderId(), physical);
   526         mgr.DeallocateLogicalStorageIds(iFramework.DataProviderId(), physical);
   512         mgr.SetDriveMappingL(aDriveNumber, physical);
   527         mgr.SetDriveMappingL(aDriveNumber, physical);
   513         __FLOG_VA((_L8("Drive = %d unmapped as storage 0x%08X"), aDriveNumber, logical));
   528         OstTraceExt2( TRACE_NORMAL, DUP1_CMTPSTORAGEWATCHER_STORAGEUNAVAILABLEL, 
       
   529                 "Drive = %d unmapped as storage 0x%08X", (TUint32)aDriveNumber, logical);        
   514         }
   530         }
   515 
   531 
   516     // Notify the active data providers.
   532     // Notify the active data providers.
   517     TMTPNotificationParamsStorageChange params = {physical};
   533     TMTPNotificationParamsStorageChange params = {physical};
   518     iFrameworkSingletons.DpController().NotifyDataProvidersL(EMTPStorageRemoved, static_cast<TAny*>(&params));
   534     iFrameworkSingletons.DpController().NotifyDataProvidersL(EMTPStorageRemoved, static_cast<TAny*>(&params));
   526     // Notify any connected Initiator(s).
   542     // Notify any connected Initiator(s).
   527     if (iAllocateLogicalStorages)
   543     if (iAllocateLogicalStorages)
   528         {
   544         {
   529         SendEventL(EMTPEventCodeStoreRemoved, logical);
   545         SendEventL(EMTPEventCodeStoreRemoved, logical);
   530         }   
   546         }   
   531     __FLOG(_L8("StorageUnavailableL - Exit"));
   547     OstTraceFunctionExit0( CMTPSTORAGEWATCHER_STORAGEUNAVAILABLEL_EXIT );
   532     }
   548     }