memspy/Engine/Source/Helpers/MemSpyEngineHelperFileSystem.cpp
changeset 48 516af714ebb4
parent 45 185201be11b0
child 55 f2950aff7424
equal deleted inserted replaced
45:185201be11b0 48:516af714ebb4
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <memspy/engine/memspyenginehelperfilesystem.h>
       
    19 
       
    20 // System includes
       
    21 #include <f32file.h>
       
    22 
       
    23 // Driver includes
       
    24 #include <memspy/driver/memspydriverclient.h>
       
    25 
       
    26 // User includes
       
    27 #include <memspy/engine/memspyengine.h>
       
    28 #include <memspy/engine/memspyengineobjectthread.h>
       
    29 #include <memspy/engine/memspyengineobjectprocess.h>
       
    30 #include <memspy/engine/memspyengineutils.h>
       
    31 #include <memspy/engine/memspyenginehelperchunk.h>
       
    32 #include <memspy/engine/memspyengineoutputsink.h>
       
    33 #include <memspy/engine/memspyengineoutputlist.h>
       
    34 #include "MemSpyEngineOutputListItem.h"
       
    35 
       
    36 // Remap of E32 constant since this value only exists in recent v9.3 builds and MemSpy needs to build on v9.1
       
    37 const TUint KMemSpyDriveAttPageable = 0x100; // KDriveAttPageable
       
    38 const TUint KMemSpyMediaAttPageable = 0x200; // KMediaAttPageable
       
    39 
       
    40 // Literal constants
       
    41 _LIT( KMemSpyVolumeLabelNotSet, "None" );
       
    42 
       
    43 
       
    44 CMemSpyEngineHelperFileSystem::CMemSpyEngineHelperFileSystem( CMemSpyEngine& aEngine )
       
    45 :   iEngine( aEngine )
       
    46     {
       
    47     }
       
    48 
       
    49     
       
    50 CMemSpyEngineHelperFileSystem::~CMemSpyEngineHelperFileSystem()
       
    51     {
       
    52     }
       
    53 
       
    54 
       
    55 void CMemSpyEngineHelperFileSystem::ConstructL()
       
    56     {
       
    57     iFileServerProcessId = MemSpyEngineUtils::IdentifyFileServerProcessIdL();
       
    58     }
       
    59 
       
    60 
       
    61 CMemSpyEngineHelperFileSystem* CMemSpyEngineHelperFileSystem::NewL( CMemSpyEngine& aEngine )
       
    62     {
       
    63     CMemSpyEngineHelperFileSystem* self = new(ELeave) CMemSpyEngineHelperFileSystem( aEngine );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 EXPORT_C CMemSpyEngineDriveList* CMemSpyEngineHelperFileSystem::DriveListL()
       
    72     {
       
    73     CMemSpyEngineDriveList* list = CMemSpyEngineDriveList::NewLC( iEngine.FsSession() );
       
    74     CleanupStack::Pop( list );
       
    75     return list;
       
    76     }
       
    77 
       
    78 
       
    79 EXPORT_C TDriveNumber CMemSpyEngineHelperFileSystem::GetSystemDrive()
       
    80     {
       
    81     TDriveNumber ret = EDriveC;
       
    82 #ifndef __WINS__
       
    83     const TInt KRFsGetSystemDriveOrdinal = 336;
       
    84     typedef TDriveNumber(*TRFsGetSystemDriveFunc)();
       
    85     //
       
    86     RLibrary lib;
       
    87     const TInt loadErr = lib.Load( _L("EFSRV.DLL") );
       
    88 #ifdef _DEBUG
       
    89     RDebug::Printf( "CMemSpyEngineHelperFileSystem::GetSystemDrive() - dll load: %d", loadErr );
       
    90 #endif
       
    91     if  ( loadErr == KErrNone )
       
    92         {
       
    93         TLibraryFunction ordinal = lib.Lookup( KRFsGetSystemDriveOrdinal );
       
    94 #ifdef _DEBUG
       
    95         RDebug::Printf( "CMemSpyEngineHelperFileSystem::GetSystemDrive() - ordinal: 0x%08x", ordinal );
       
    96 #endif
       
    97         //
       
    98         if  ( ordinal )
       
    99             {
       
   100             TRFsGetSystemDriveFunc func = (TRFsGetSystemDriveFunc) ordinal;
       
   101             ret = (*func)();
       
   102 #ifdef _DEBUG
       
   103             RDebug::Printf( "CMemSpyEngineHelperFileSystem::GetSystemDrive() - drive: %c:\\", 'A' + ret);
       
   104 #endif
       
   105             }
       
   106         //
       
   107         lib.Close();
       
   108         }
       
   109 #endif
       
   110     //
       
   111     return ret;
       
   112     }
       
   113 
       
   114 
       
   115 EXPORT_C void CMemSpyEngineHelperFileSystem::ListOpenFilesL()
       
   116     {
       
   117     TOpenFileScan scanner( iEngine.FsSession() );
       
   118 
       
   119     _LIT( KMemSpyContext, "Open File Listing" );
       
   120     _LIT( KMemSpyFolder, "OpenFiles" );
       
   121     iEngine.Sink().DataStreamBeginL( KMemSpyContext, KMemSpyFolder );
       
   122 
       
   123     _LIT(KHeading, "OPEN FILES");
       
   124     iEngine.Sink().OutputSectionHeadingL( KHeading, '=' );
       
   125     
       
   126     // Set prefix for overall listing
       
   127     _LIT(KOverallPrefix, "OpenFiles - ");
       
   128     iEngine.Sink().OutputPrefixSetLC( KOverallPrefix );
       
   129 
       
   130     CFileList* list = NULL;
       
   131     scanner.NextL( list );
       
   132     while( list != NULL )
       
   133         {
       
   134         CleanupStack::PushL( list );
       
   135         ListOpenFilesL( *list, scanner.ThreadId() );
       
   136         CleanupStack::PopAndDestroy( list );
       
   137         //
       
   138         list = NULL;
       
   139         scanner.NextL( list );
       
   140         }
       
   141 
       
   142     CleanupStack::PopAndDestroy(); // prefix
       
   143     iEngine.Sink().DataStreamEndL();
       
   144     }
       
   145 
       
   146 
       
   147 EXPORT_C void CMemSpyEngineHelperFileSystem::ListOpenFilesL( const TThreadId& aThreadId )
       
   148     {
       
   149     TOpenFileScan scanner( iEngine.FsSession() );
       
   150 
       
   151     _LIT( KMemSpyContext, "Open File Listing" );
       
   152     _LIT( KMemSpyFolder, "OpenFiles" );
       
   153     iEngine.Sink().DataStreamBeginL( KMemSpyContext, KMemSpyFolder );
       
   154 
       
   155     _LIT(KHeading, "OPEN FILES");
       
   156     iEngine.Sink().OutputSectionHeadingL( KHeading, '=' );
       
   157     
       
   158     // Set prefix for overall listing
       
   159     _LIT(KOverallPrefix, "OpenFiles - ");
       
   160     iEngine.Sink().OutputPrefixSetLC( KOverallPrefix );
       
   161 
       
   162     CFileList* list = NULL;
       
   163     scanner.NextL( list );
       
   164     while( list != NULL )
       
   165         {
       
   166         if  ( scanner.ThreadId() == aThreadId )
       
   167             {
       
   168             CleanupStack::PushL( list );
       
   169             ListOpenFilesL( *list, scanner.ThreadId() );
       
   170             CleanupStack::Pop( list );
       
   171             }
       
   172         //
       
   173         delete list;
       
   174         list = NULL;
       
   175         scanner.NextL( list );
       
   176         }
       
   177 
       
   178     CleanupStack::PopAndDestroy(); // prefix
       
   179     iEngine.Sink().DataStreamEndL();
       
   180     }
       
   181 
       
   182 
       
   183 void CMemSpyEngineHelperFileSystem::GetDriveNumberText( TDriveNumber aDriveNumber, TDes& aText )
       
   184     {
       
   185     const TInt offset = aDriveNumber - EDriveA;
       
   186     const TChar driveChar = 'A' + offset;
       
   187     aText.Copy( _L("EDrive") );
       
   188     aText.Append( driveChar );
       
   189     }
       
   190 
       
   191 
       
   192 void CMemSpyEngineHelperFileSystem::ListOpenFilesL( const CFileList& aList, const TThreadId& aThreadId )
       
   193     {
       
   194     _LIT( KLineFormatSpec, "%d %S %S %S %S" );
       
   195     TBuf<64> timeBuf;
       
   196     TMemSpySizeText valueBuf;
       
   197 
       
   198     HBufC* itemBuf = HBufC::NewLC( 3 * KMaxFullName );
       
   199     TPtr item( itemBuf->Des() );
       
   200 
       
   201     TFullName threadName;
       
   202     RThread thread;
       
   203     if  ( iEngine.Driver().OpenThread( aThreadId, thread ) == KErrNone )
       
   204         {
       
   205         threadName = thread.FullName();
       
   206         thread.Close();
       
   207         }
       
   208 
       
   209     const TInt entryCount = aList.Count();
       
   210     for(TInt i=0; i<entryCount; i++)
       
   211         {
       
   212         const TEntry& entry = aList[ i ];
       
   213 
       
   214         // Get time and size format strings
       
   215         valueBuf = MemSpyEngineUtils::FormatSizeText( entry.iSize );
       
   216         MemSpyEngineUtils::FormatTimeL( timeBuf, entry.iModified );
       
   217 
       
   218         // Create item 
       
   219         item.Format( KLineFormatSpec, 0, &entry.iName, &valueBuf, &timeBuf, &threadName );
       
   220         iEngine.Sink().OutputLineL( item );
       
   221         }
       
   222 
       
   223     CleanupStack::PopAndDestroy( itemBuf );
       
   224     }
       
   225 
       
   226 
       
   227 CMemSpyEngineOpenFileList* CMemSpyEngineHelperFileSystem::ListOpenFilesLC()
       
   228     {
       
   229     CMemSpyEngineOpenFileList* list = CMemSpyEngineOpenFileList::NewLC( iEngine );
       
   230     return list;
       
   231     }
       
   232 
       
   233 
       
   234 TProcessId CMemSpyEngineHelperFileSystem::FileServerProcessId() const
       
   235     {
       
   236     return iFileServerProcessId;
       
   237     }
       
   238 
       
   239 
       
   240 const CMemSpyEngineChunkEntry* CMemSpyEngineHelperFileSystem::IdentifyCacheChunk( const CMemSpyEngineChunkList& aList, TInt& aIndex ) const
       
   241     {
       
   242     aIndex = KErrNotFound;
       
   243     const CMemSpyEngineChunkEntry* ret = NULL;
       
   244     //
       
   245     const TInt count = aList.Count();
       
   246     for( TInt i=0; i<count; i++ )
       
   247         {
       
   248         const CMemSpyEngineChunkEntry& entry = aList.At( i );
       
   249         const TMemSpyDriverChunkInfo& info = entry.Info();
       
   250         //
       
   251         if  ( info.iType == EMemSpyDriverChunkTypeLocal )
       
   252             {
       
   253 #ifdef _DEBUG
       
   254             RDebug::Print( _L("CMemSpyEngineHelperFileSystem::IdentifyCacheChunk() - name: %S, pid: 0x%04x, f32Pid: 0x%04x, size: %d, max: %d, attribs: %d"), &info.iName, info.iOwnerId, (TUint) iFileServerProcessId, info.iSize, info.iMaxSize, info.iAttributes );
       
   255 #endif
       
   256 
       
   257             if ( info.iOwnerId == FileServerProcessId() )
       
   258                 {
       
   259                 // Additionally, the chunk is disconnected.
       
   260                 const TBool isDisconnected = ( info.iAttributes & EMemSpyChunkAttributesDisconnected );
       
   261 #ifdef _DEBUG
       
   262                 RDebug::Printf( "CMemSpyEngineHelperFileSystem::IdentifyCacheChunk() - it is an f32 local chunk... isDisconnected: %d", isDisconnected );
       
   263 #endif
       
   264 
       
   265                 if  ( info.iSize > 0 && info.iMaxSize > 0 && isDisconnected )
       
   266                     {
       
   267                     aIndex = i;
       
   268                     ret = &entry;
       
   269 #ifdef _DEBUG
       
   270                     RDebug::Print( _L("CMemSpyEngineHelperFileSystem::IdentifyCacheChunk() - FOUND: %S, size: %d"), &info.iName, info.iSize );
       
   271 #endif
       
   272                     break;
       
   273                     }
       
   274                 }
       
   275             }
       
   276         }
       
   277     //
       
   278 #ifdef _DEBUG
       
   279     RDebug::Printf( "CMemSpyEngineHelperFileSystem::IdentifyCacheChunk() - END - ret: 0x%08x", ret );
       
   280 #endif
       
   281     return ret;
       
   282     }
       
   283 
       
   284 
       
   285 
       
   286 
       
   287 
       
   288 
       
   289 
       
   290 
       
   291 
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 
       
   302 
       
   303 
       
   304 CMemSpyEngineDriveList::CMemSpyEngineDriveList( RFs& aFsSession )
       
   305 :   CActive( EPriorityStandard ), iFsSession( aFsSession )
       
   306     {
       
   307     CActiveScheduler::Add( this );
       
   308     }
       
   309 
       
   310 
       
   311 EXPORT_C CMemSpyEngineDriveList::~CMemSpyEngineDriveList()
       
   312     {
       
   313     Cancel();
       
   314     //
       
   315     iItems.ResetAndDestroy();
       
   316     iItems.Close();
       
   317     }
       
   318 
       
   319 
       
   320 void CMemSpyEngineDriveList::ConstructL()
       
   321     {
       
   322     TDriveList drives;
       
   323     if  ( iFsSession.DriveList( drives ) == KErrNone )
       
   324         {
       
   325         for( TInt i=EDriveA; i<=EDriveZ; i++ )
       
   326             {
       
   327             const TDriveNumber drive = static_cast< TDriveNumber >( i );
       
   328             if  ( drives[ i ] != KDriveAbsent )
       
   329                 {
       
   330                 TRAP_IGNORE( 
       
   331                     CMemSpyEngineDriveEntry* driveEntry = CMemSpyEngineDriveEntry::NewLC( *this, drive );
       
   332                     iItems.AppendL( driveEntry );
       
   333                     CleanupStack::Pop( driveEntry );
       
   334                     );
       
   335                 }
       
   336             }
       
   337         }
       
   338 
       
   339     iFsSession.NotifyChange( ENotifyDisk, iStatus );
       
   340     SetActive();
       
   341     }
       
   342 
       
   343 
       
   344 CMemSpyEngineDriveList* CMemSpyEngineDriveList::NewLC( RFs& aFsSession )
       
   345     {
       
   346     CMemSpyEngineDriveList* self = new(ELeave) CMemSpyEngineDriveList( aFsSession );
       
   347     CleanupStack::PushL( self );
       
   348     self->ConstructL();
       
   349     return self;
       
   350     }
       
   351 
       
   352 
       
   353 void CMemSpyEngineDriveList::RunL()
       
   354     {
       
   355     iFsSession.NotifyChange( ENotifyDisk, iStatus );
       
   356     SetActive();
       
   357     //
       
   358     NotifyListChangedL();
       
   359     }
       
   360 
       
   361 
       
   362 void CMemSpyEngineDriveList::DoCancel()
       
   363     {
       
   364     iFsSession.NotifyChangeCancel();
       
   365     }
       
   366 
       
   367 
       
   368 EXPORT_C void CMemSpyEngineDriveList::SetObserver( MMemSpyEngineDriveListObserver* aObserver )
       
   369     {
       
   370     iObserver = aObserver;
       
   371     }
       
   372 
       
   373 
       
   374 EXPORT_C TInt CMemSpyEngineDriveList::Count() const
       
   375     {
       
   376     return iItems.Count();
       
   377     }
       
   378 
       
   379 
       
   380 EXPORT_C CMemSpyEngineDriveEntry& CMemSpyEngineDriveList::At( TInt aIndex )
       
   381     {
       
   382     return *iItems[ aIndex ];
       
   383     }
       
   384 
       
   385 
       
   386 EXPORT_C const CMemSpyEngineDriveEntry& CMemSpyEngineDriveList::At( TInt aIndex ) const
       
   387     {
       
   388     return *iItems[ aIndex ];
       
   389     }
       
   390 
       
   391 
       
   392 EXPORT_C TInt CMemSpyEngineDriveList::ItemIndex( const CMemSpyEngineDriveEntry& aEntry ) const
       
   393     {
       
   394     TInt ret = KErrNotFound;
       
   395     //
       
   396     const TInt count = Count();
       
   397     for( TInt i=0; i<count; i++ )
       
   398         {
       
   399         const CMemSpyEngineDriveEntry* item = iItems[ i ];
       
   400         //
       
   401         if  ( item == &aEntry )
       
   402             {
       
   403             ret = i;
       
   404             break;
       
   405             }
       
   406         }
       
   407     //
       
   408     return ret;
       
   409     }
       
   410 
       
   411 
       
   412 EXPORT_C CMemSpyEngineDriveEntry* CMemSpyEngineDriveList::EntryByDriveNumber( TDriveNumber aDrive )
       
   413     {
       
   414     CMemSpyEngineDriveEntry* ret = NULL;
       
   415     //
       
   416     const TInt count = Count();
       
   417     for( TInt i=0; i<count; i++ )
       
   418         {
       
   419         CMemSpyEngineDriveEntry* item = iItems[ i ];
       
   420         //
       
   421         if  ( item->DriveNumber() == aDrive )
       
   422             {
       
   423             ret = item;
       
   424             break;
       
   425             }
       
   426         }
       
   427     //
       
   428     return ret;
       
   429     }
       
   430 
       
   431 
       
   432 RFs& CMemSpyEngineDriveList::FsSession()
       
   433     {
       
   434     return iFsSession;
       
   435     }
       
   436 
       
   437 
       
   438 void CMemSpyEngineDriveList::NotifyListChangedL()
       
   439     {
       
   440     if  ( iObserver != NULL )
       
   441         {
       
   442         TRAP_IGNORE( iObserver->HandleDriveListChangedL( *this ) );
       
   443         }
       
   444     }
       
   445 
       
   446 
       
   447 EXPORT_C TInt CMemSpyEngineDriveList::MdcaCount() const
       
   448     {
       
   449     return Count();
       
   450     }
       
   451 
       
   452 
       
   453 EXPORT_C TPtrC CMemSpyEngineDriveList::MdcaPoint( TInt aIndex ) const
       
   454     {
       
   455     const CMemSpyEngineDriveEntry& item = At( aIndex );
       
   456     return TPtrC( item.Caption() );
       
   457     }
       
   458 
       
   459 
       
   460 
       
   461 
       
   462 
       
   463 
       
   464 
       
   465 
       
   466 
       
   467 
       
   468 
       
   469 
       
   470 
       
   471 
       
   472 
       
   473 
       
   474 
       
   475 
       
   476 CMemSpyEngineDriveEntry::CMemSpyEngineDriveEntry( CMemSpyEngineDriveList& aList, TDriveNumber aDriveNumber )
       
   477 :   CActive( CActive::EPriorityStandard), iList( aList ), iDriveNumber( aDriveNumber ), iDriveUnit( aDriveNumber )
       
   478     {
       
   479     CActiveScheduler::Add( this );
       
   480     }
       
   481 
       
   482 
       
   483 EXPORT_C CMemSpyEngineDriveEntry::~CMemSpyEngineDriveEntry()
       
   484     {
       
   485     Cancel();
       
   486     //
       
   487     delete iCaption;
       
   488     delete iItems;
       
   489     }
       
   490 
       
   491 
       
   492 void CMemSpyEngineDriveEntry::ConstructL()
       
   493     {
       
   494     RunL();
       
   495     }
       
   496 
       
   497 
       
   498 EXPORT_C void CMemSpyEngineDriveEntry::SetObserver( MMemSpyEngineDriveEntryObserver* aObserver )
       
   499     {
       
   500     iObserver = aObserver;
       
   501     }
       
   502 
       
   503 
       
   504 void CMemSpyEngineDriveEntry::RefreshL()
       
   505     {
       
   506     CMemSpyEngineOutputList* items = CMemSpyEngineOutputList::NewL();
       
   507     delete iItems;
       
   508     iItems = items;
       
   509 
       
   510     /*
       
   511 	RFs13VolumeIOParamEiR18TVolumeIOParamInfo @ 344 NONAME
       
   512 	RFs17FileSystemSubTypeEiR6TDes16 @ 345 NONAME
       
   513 	RFs18QueryVolumeInfoExtEi22TQueryVolumeInfoExtCmdR5TDes8 @ 346 NONAME
       
   514     */
       
   515     const TInt err1 = FsSession().Drive( iDriveInfo, iDriveNumber );
       
   516     const TInt err2 = FsSession().Volume( iVolumeInfo, iDriveNumber );
       
   517     if  ( err1 || err2 )
       
   518         {
       
   519         _LIT( KUnavailable, "Unavailable");
       
   520         iItems->AddItemL( KUnavailable );
       
   521 
       
   522         // Mostly empty caption
       
   523         CreateCaptionL( KNullDesC, KNullDesC );
       
   524         }
       
   525     else
       
   526         {
       
   527         // Literal constants
       
   528         TBuf<KMaxFileName * 2> temp;
       
   529         TBuf<KMaxFileName * 2> item;
       
   530 
       
   531         AddStandardFieldsL();
       
   532 
       
   533         _LIT( KEntry2a, "Media Type");
       
   534         TBuf<20> mediaType;
       
   535         GetMediaTypeText( iDriveInfo.iType, mediaType );
       
   536         iItems->AddItemL( KEntry2a, mediaType );
       
   537 
       
   538         _LIT( KEntry2b, "Battery Status");
       
   539         GetBatteryState( iDriveInfo.iBattery, temp );
       
   540         iItems->AddItemL( KEntry2b, temp );
       
   541 
       
   542         // Now have enough data to create caption
       
   543         CreateCaptionL( iVolumeInfo.iName, mediaType );
       
   544         
       
   545         CreateDriveAttributesL( item );
       
   546         CreateMediaAttributesL( item );
       
   547 
       
   548         _LIT( KEntry3a, "Volume Name");
       
   549         if  ( iVolumeInfo.iName.Length() )
       
   550             {
       
   551             iItems->AddItemL( KEntry3a, iVolumeInfo.iName );
       
   552             }
       
   553         else
       
   554             {
       
   555             iItems->AddItemL( KEntry3a, KMemSpyVolumeLabelNotSet );
       
   556             }
       
   557 
       
   558         _LIT( KEntry3, "Volume UID");
       
   559         iItems->AddItemHexL( KEntry3, iVolumeInfo.iUniqueID );
       
   560 
       
   561         _LIT( KEntry4, "Volume Size");
       
   562         temp = MemSpyEngineUtils::FormatSizeText( iVolumeInfo.iSize );
       
   563         iItems->AddItemL( KEntry4, temp );
       
   564 
       
   565         _LIT( KEntry5, "Volume Free");
       
   566         temp = MemSpyEngineUtils::FormatSizeText( iVolumeInfo.iFree );
       
   567         iItems->AddItemL( KEntry5, temp );
       
   568 
       
   569         TMediaSerialNumber serialNum;
       
   570         if  ( FsSession().GetMediaSerialNumber( serialNum, iDriveNumber ) == KErrNone )
       
   571             {
       
   572             _LIT( KEntry6, "Serial Number");
       
   573             TBuf<KMaxSerialNumLength> serialNumUnicode;
       
   574             serialNumUnicode.Copy( serialNum );
       
   575             iItems->AddItemL( KEntry6, serialNumUnicode );
       
   576             }
       
   577 
       
   578         if  ( FsSession().FileSystemName( temp, iDriveNumber ) == KErrNone )
       
   579             {
       
   580             _LIT( KEntry7, "File System");
       
   581             iItems->AddItemL( KEntry7, temp );
       
   582             }
       
   583         }
       
   584     }
       
   585 
       
   586 
       
   587 CMemSpyEngineDriveEntry* CMemSpyEngineDriveEntry::NewLC( CMemSpyEngineDriveList& aList, TDriveNumber aDriveNumber )
       
   588     {
       
   589     CMemSpyEngineDriveEntry* self = new(ELeave) CMemSpyEngineDriveEntry( aList, aDriveNumber );
       
   590     CleanupStack::PushL( self );
       
   591     self->ConstructL();
       
   592     return self;
       
   593     }
       
   594 
       
   595 
       
   596 void CMemSpyEngineDriveEntry::CreateDriveAttributesL( TDes& aItemBuf )
       
   597     {
       
   598     TInt driveAttribIndex = 0;
       
   599     _LIT( KEntryText, "Drive Attribute %d");
       
   600 
       
   601     if  ( iDriveInfo.iDriveAtt & KDriveAttLocal )
       
   602         {
       
   603         _LIT( KAttribName, "Local" );
       
   604         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   605         iItems->AddItemL( aItemBuf, KAttribName );
       
   606         }
       
   607     if  ( iDriveInfo.iDriveAtt & KDriveAttRom )
       
   608         {
       
   609         _LIT( KAttribName, "ROM" );
       
   610         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   611         iItems->AddItemL( aItemBuf, KAttribName );
       
   612         }
       
   613     if  ( iDriveInfo.iDriveAtt & KDriveAttRedirected )
       
   614         {
       
   615         _LIT( KAttribName, "Redirected" );
       
   616         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   617         iItems->AddItemL( aItemBuf, KAttribName );
       
   618         }
       
   619     if  ( iDriveInfo.iDriveAtt & KDriveAttSubsted )
       
   620         {
       
   621         _LIT( KAttribName, "Substed" );
       
   622         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   623         iItems->AddItemL( aItemBuf, KAttribName );
       
   624         }
       
   625     if  ( iDriveInfo.iDriveAtt & KDriveAttInternal )
       
   626         {
       
   627         _LIT( KAttribName, "Internal" );
       
   628         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   629         iItems->AddItemL( aItemBuf, KAttribName );
       
   630         }
       
   631     if  ( iDriveInfo.iDriveAtt & KDriveAttRemovable )
       
   632         {
       
   633         _LIT( KAttribName, "Removable" );
       
   634         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   635         iItems->AddItemL( aItemBuf, KAttribName );
       
   636         }
       
   637     if  ( iDriveInfo.iDriveAtt & KDriveAttRemote )
       
   638         {
       
   639         _LIT( KAttribName, "Remote" );
       
   640         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   641         iItems->AddItemL( aItemBuf, KAttribName );
       
   642         }
       
   643     if  ( iDriveInfo.iDriveAtt & KDriveAttTransaction )
       
   644         {
       
   645         _LIT( KAttribName, "Transaction" );
       
   646         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   647         iItems->AddItemL( aItemBuf, KAttribName );
       
   648         }
       
   649     if  ( iDriveInfo.iDriveAtt & KMemSpyDriveAttPageable )
       
   650         {
       
   651         _LIT( KAttribName, "Pageable" );
       
   652         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   653         iItems->AddItemL( aItemBuf, KAttribName );
       
   654         }
       
   655     if  ( iDriveInfo.iDriveAtt & KDriveAttRemovable )
       
   656         {
       
   657         _LIT( KAttribName, "Removable" );
       
   658         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   659         iItems->AddItemL( aItemBuf, KAttribName );
       
   660         }
       
   661     }
       
   662 
       
   663 
       
   664 void CMemSpyEngineDriveEntry::CreateMediaAttributesL( TDes& aItemBuf )
       
   665     {
       
   666     TInt driveAttribIndex = 0;
       
   667     _LIT( KEntryText, "Media Attribute %d");
       
   668 
       
   669     if  ( iDriveInfo.iMediaAtt & KMediaAttVariableSize )
       
   670         {
       
   671         _LIT( KAttribName, "Variable Size" );
       
   672         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   673         iItems->AddItemL( aItemBuf, KAttribName );
       
   674         }
       
   675     if  ( iDriveInfo.iMediaAtt & KMediaAttDualDensity )
       
   676         {
       
   677         _LIT( KAttribName, "Dual Density" );
       
   678         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   679         iItems->AddItemL( aItemBuf, KAttribName );
       
   680         }
       
   681     if  ( iDriveInfo.iMediaAtt & KMediaAttFormattable )
       
   682         {
       
   683         _LIT( KAttribName, "Formattable" );
       
   684         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   685         iItems->AddItemL( aItemBuf, KAttribName );
       
   686         }
       
   687     if  ( iDriveInfo.iMediaAtt & KMediaAttWriteProtected )
       
   688         {
       
   689         _LIT( KAttribName, "Write Protected" );
       
   690         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   691         iItems->AddItemL( aItemBuf, KAttribName );
       
   692         }
       
   693     if  ( iDriveInfo.iMediaAtt & KMediaAttLockable )
       
   694         {
       
   695         _LIT( KAttribName, "Lockable" );
       
   696         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   697         iItems->AddItemL( aItemBuf, KAttribName );
       
   698         }
       
   699     if  ( iDriveInfo.iMediaAtt & KMediaAttLocked )
       
   700         {
       
   701         _LIT( KAttribName, "Locked" );
       
   702         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   703         iItems->AddItemL( aItemBuf, KAttribName );
       
   704         }
       
   705     if  ( iDriveInfo.iMediaAtt & KMediaAttHasPassword )
       
   706         {
       
   707         _LIT( KAttribName, "Has Password" );
       
   708         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   709         iItems->AddItemL( aItemBuf, KAttribName );
       
   710         }
       
   711     if  ( iDriveInfo.iMediaAtt & KMediaAttReadWhileWrite )
       
   712         {
       
   713         _LIT( KAttribName, "Read-while-Write" );
       
   714         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   715         iItems->AddItemL( aItemBuf, KAttribName );
       
   716         }
       
   717     if  ( iDriveInfo.iMediaAtt & KMediaAttDeleteNotify )
       
   718         {
       
   719         _LIT( KAttribName, "Delete Notify" );
       
   720         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   721         iItems->AddItemL( aItemBuf, KAttribName );
       
   722         }
       
   723     if  ( iDriveInfo.iMediaAtt & KMemSpyMediaAttPageable )
       
   724         {
       
   725         _LIT( KAttribName, "Pageable" );
       
   726         aItemBuf.Format( KEntryText, ++driveAttribIndex );
       
   727         iItems->AddItemL( aItemBuf, KAttribName );
       
   728         }
       
   729     }
       
   730 
       
   731 
       
   732 void CMemSpyEngineDriveEntry::AddStandardFieldsL()
       
   733     {
       
   734     _LIT( KEntry1, "Unit Name");
       
   735     const TDriveName driveUnitName = iDriveUnit.Name();
       
   736     iItems->AddItemL( KEntry1, driveUnitName );
       
   737 
       
   738     _LIT( KEntry2, "Unit Number");
       
   739     TBuf<30> temp;
       
   740     CMemSpyEngineHelperFileSystem::GetDriveNumberText( iDriveNumber, temp );
       
   741     iItems->AddItemL( KEntry2, temp );
       
   742 
       
   743     const TDriveNumber sysDrive = GetSystemDrive();
       
   744     if  ( sysDrive == iDriveNumber )
       
   745         {
       
   746         _LIT( KEntry3, "System Drive");
       
   747         iItems->AddItemYesNoL( KEntry3, ETrue );
       
   748         }
       
   749     }
       
   750 
       
   751 
       
   752 void CMemSpyEngineDriveEntry::CreateCaptionL( const TDesC& aVolumeName, const TDesC& aMediaType )
       
   753     {
       
   754     TBuf<256 * 2> caption;
       
   755 
       
   756     // Always include drive unit name
       
   757     const TDriveName driveUnitName = iDriveUnit.Name();
       
   758     caption.AppendFormat( _L("\t%S"), &driveUnitName );
       
   759 
       
   760     // If we have a volume name, then include that too
       
   761     if  ( aVolumeName.Length() )
       
   762         {
       
   763         caption.AppendFormat( _L(" [%S]"), &aVolumeName );
       
   764         }
       
   765     
       
   766     // New line
       
   767     caption.Append( _L("\t\t") );
       
   768 
       
   769     // Include media type if known, or unknown otherwise
       
   770     if  ( aMediaType.Length() )
       
   771         {
       
   772         caption.Append( aMediaType );
       
   773         }
       
   774     else
       
   775         {
       
   776         _LIT( KUnknownMediaType, "Unknown" );
       
   777         caption.Append( KUnknownMediaType );
       
   778         }
       
   779 
       
   780     HBufC* finalCaption = caption.AllocL();
       
   781     delete iCaption;
       
   782     iCaption = finalCaption;
       
   783     }
       
   784 
       
   785 void CMemSpyEngineDriveEntry::GetMediaTypeText( TMediaType aType, TDes& aText )
       
   786     {
       
   787     switch( aType )
       
   788         {
       
   789     case EMediaNotPresent:
       
   790         aText.Copy( _L("Not Present") );
       
   791         break;
       
   792     case EMediaFloppy:
       
   793         aText.Copy( _L("Floppy") );
       
   794         break;
       
   795     case EMediaHardDisk:
       
   796         aText.Copy( _L("Hard Disk") );
       
   797         break;
       
   798     case EMediaCdRom:
       
   799         aText.Copy( _L("CD-ROM") );
       
   800         break;
       
   801     case EMediaRam:
       
   802         aText.Copy( _L("RAM") );
       
   803         break;
       
   804     case EMediaFlash:
       
   805         aText.Copy( _L("Flash") );
       
   806         break;
       
   807     case EMediaRom:
       
   808         aText.Copy( _L("ROM") );
       
   809         break;
       
   810     case EMediaRemote:
       
   811         aText.Copy( _L("Remote") );
       
   812         break;
       
   813     case EMediaNANDFlash:
       
   814         aText.Copy( _L("NAND Flash") );
       
   815         break;
       
   816     default:
       
   817     case EMediaUnknown:
       
   818         aText.Copy( _L("Unknown") );
       
   819         break;
       
   820         }
       
   821     }
       
   822 
       
   823 
       
   824 void CMemSpyEngineDriveEntry::GetBatteryState( TBatteryState aBatteryState, TDes& aText )
       
   825     {
       
   826     switch( aBatteryState )
       
   827         {
       
   828     case EBatNotSupported:
       
   829         aText.Copy( _L("Not Supported") );
       
   830         break;
       
   831     case EBatGood:
       
   832         aText.Copy( _L("Good") );
       
   833         break;
       
   834     case EBatLow:
       
   835         aText.Copy( _L("Low") );
       
   836         break;
       
   837     default:
       
   838         aText.Copy( _L("Unknown") );
       
   839         break;
       
   840         }
       
   841     }
       
   842 
       
   843 
       
   844 TDriveNumber CMemSpyEngineDriveEntry::GetSystemDrive()
       
   845     {
       
   846     return CMemSpyEngineHelperFileSystem::GetSystemDrive();
       
   847     }
       
   848 
       
   849 
       
   850 EXPORT_C TInt CMemSpyEngineDriveEntry::MdcaCount() const
       
   851     {
       
   852     return iItems->Count();
       
   853     }
       
   854 
       
   855 
       
   856 EXPORT_C TPtrC CMemSpyEngineDriveEntry::MdcaPoint( TInt aIndex ) const
       
   857     {
       
   858     return iItems->MdcaPoint( aIndex );
       
   859     }
       
   860 
       
   861 
       
   862 void CMemSpyEngineDriveEntry::RunL()
       
   863     {
       
   864     FsSession().NotifyChange( ENotifyDisk, iStatus );
       
   865     SetActive();
       
   866     //
       
   867     TRAP_IGNORE( RefreshL() );
       
   868     //
       
   869     if ( iObserver != NULL )
       
   870         {
       
   871         TRAP_IGNORE( iObserver->HandleDriveEntryChangedL( *this ) );
       
   872         }
       
   873     }
       
   874 
       
   875 
       
   876 void CMemSpyEngineDriveEntry::DoCancel()
       
   877     {
       
   878     FsSession().NotifyChangeCancel();
       
   879     }
       
   880 
       
   881 
       
   882 RFs& CMemSpyEngineDriveEntry::FsSession()
       
   883     {
       
   884     return iList.FsSession();
       
   885     }
       
   886 
       
   887 
       
   888 
       
   889 
       
   890 
       
   891 
       
   892 
       
   893 
       
   894 
       
   895 
       
   896 
       
   897 
       
   898 
       
   899 
       
   900 
       
   901 
       
   902 
       
   903 
       
   904 
       
   905 
       
   906 
       
   907 
       
   908 
       
   909 
       
   910 
       
   911 
       
   912 
       
   913 
       
   914 
       
   915 
       
   916 
       
   917 
       
   918 
       
   919 
       
   920 
       
   921 CMemSpyEngineOpenFileListEntry::CMemSpyEngineOpenFileListEntry()
       
   922     {
       
   923     }
       
   924 
       
   925 
       
   926 CMemSpyEngineOpenFileListEntry::~CMemSpyEngineOpenFileListEntry()
       
   927     {
       
   928     delete iFileName;
       
   929     }
       
   930 
       
   931 
       
   932 void CMemSpyEngineOpenFileListEntry::ConstructL( const TEntry& aEntry )
       
   933     {
       
   934     iFileName = aEntry.iName.AllocL();
       
   935     iAtt = aEntry.iAtt;
       
   936     iType = aEntry.iType;
       
   937     iSize = aEntry.iSize;
       
   938     iModified = aEntry.iModified;
       
   939     }
       
   940 
       
   941 
       
   942 CMemSpyEngineOpenFileListEntry* CMemSpyEngineOpenFileListEntry::NewLC( const TEntry& aEntry )
       
   943     {
       
   944     CMemSpyEngineOpenFileListEntry* self = new(ELeave) CMemSpyEngineOpenFileListEntry();
       
   945     CleanupStack::PushL( self );
       
   946     self->ConstructL( aEntry );
       
   947     return self;
       
   948     }
       
   949 
       
   950 
       
   951 EXPORT_C const TDesC& CMemSpyEngineOpenFileListEntry::FileName() const
       
   952     {
       
   953     return *iFileName;
       
   954     }
       
   955 
       
   956 
       
   957 EXPORT_C TInt CMemSpyEngineOpenFileListEntry::Size() const
       
   958     {
       
   959     return iSize;
       
   960     }
       
   961 
       
   962 
       
   963 TInt CMemSpyEngineOpenFileListEntry::UniqueFileId() const
       
   964     {
       
   965     return iUniqueFileIdentifier;
       
   966     }
       
   967 
       
   968 
       
   969 void CMemSpyEngineOpenFileListEntry::SetUniqueFileId( TInt aValue )
       
   970     {
       
   971     iUniqueFileIdentifier = aValue;
       
   972     }
       
   973 
       
   974 
       
   975 
       
   976 
       
   977 
       
   978 
       
   979 
       
   980 
       
   981 
       
   982 
       
   983 
       
   984 
       
   985 
       
   986 
       
   987 
       
   988 
       
   989 
       
   990 
       
   991 
       
   992 
       
   993 
       
   994 
       
   995 
       
   996 
       
   997 
       
   998 CMemSpyEngineOpenFileListForThread::CMemSpyEngineOpenFileListForThread( const TThreadId& aThreadId, const TProcessId& aProcessId )
       
   999 :   iThreadId( aThreadId ), iProcessId( aProcessId )
       
  1000     {
       
  1001     }
       
  1002 
       
  1003 
       
  1004 CMemSpyEngineOpenFileListForThread::~CMemSpyEngineOpenFileListForThread()
       
  1005     {
       
  1006     iItems.ResetAndDestroy();
       
  1007     iItems.Close();
       
  1008     delete iThreadName;
       
  1009     }
       
  1010 
       
  1011 
       
  1012 void CMemSpyEngineOpenFileListForThread::ConstructL( const TDesC& aThreadName, const CFileList& aList )
       
  1013     {
       
  1014     iThreadName = aThreadName.AllocL();
       
  1015 
       
  1016     // Create fs entries
       
  1017     const TInt entryCount = aList.Count();
       
  1018     for(TInt i=0; i<entryCount; i++)
       
  1019         {
       
  1020         const TEntry& fsEntry = (aList)[ i ];
       
  1021         //
       
  1022         CMemSpyEngineOpenFileListEntry* entry = CMemSpyEngineOpenFileListEntry::NewLC( fsEntry );
       
  1023         AddL( entry );
       
  1024         CleanupStack::Pop( entry );
       
  1025         }
       
  1026     }
       
  1027 
       
  1028 
       
  1029 CMemSpyEngineOpenFileListForThread* CMemSpyEngineOpenFileListForThread::NewLC( const TDesC& aThreadName, const TThreadId& aThreadId, const TProcessId& aProcessId, const CFileList& aList )
       
  1030     {
       
  1031     CMemSpyEngineOpenFileListForThread* self = new(ELeave) CMemSpyEngineOpenFileListForThread( aThreadId, aProcessId );
       
  1032     CleanupStack::PushL( self );
       
  1033     self->ConstructL( aThreadName, aList );
       
  1034     return self;
       
  1035     }
       
  1036 
       
  1037 
       
  1038 EXPORT_C const TDesC& CMemSpyEngineOpenFileListForThread::ThreadName() const
       
  1039     {
       
  1040     return *iThreadName;
       
  1041     }
       
  1042 
       
  1043 
       
  1044 EXPORT_C const TThreadId& CMemSpyEngineOpenFileListForThread::ThreadId() const
       
  1045     {
       
  1046     return iThreadId;
       
  1047     }
       
  1048 
       
  1049 
       
  1050 EXPORT_C const TProcessId& CMemSpyEngineOpenFileListForThread::ProcessId() const
       
  1051     {
       
  1052     return iProcessId;
       
  1053     }
       
  1054 
       
  1055 
       
  1056 EXPORT_C TInt CMemSpyEngineOpenFileListForThread::Count() const
       
  1057     {
       
  1058     return iItems.Count();
       
  1059     }
       
  1060 
       
  1061 
       
  1062 EXPORT_C const CMemSpyEngineOpenFileListEntry& CMemSpyEngineOpenFileListForThread::At( TInt aIndex ) const
       
  1063     {
       
  1064     return *iItems[ aIndex ];
       
  1065     }
       
  1066  
       
  1067 
       
  1068 void CMemSpyEngineOpenFileListForThread::AddL( CMemSpyEngineOpenFileListEntry* aEntry )
       
  1069     {
       
  1070     // Ensure we increment the unique filename counter if adding an entry where the same filename
       
  1071     // already is registered with the list.
       
  1072     CMemSpyEngineOpenFileListEntry* existingEntry = EntryByFileName( aEntry->FileName() );
       
  1073     if  ( existingEntry )
       
  1074         {
       
  1075         // EntryByFileName() always returns the most recent entry with the same name. The list
       
  1076         // itself is not sorted as entries are always appended to it.
       
  1077         const TInt lastUID = existingEntry->UniqueFileId();
       
  1078 #ifdef _DEBUG
       
  1079         RDebug::Print( _L("CMemSpyEngineOpenFileListForThread::AddL() - searched for %S and found existing entry with UID: %d"), &aEntry->FileName(), lastUID );
       
  1080 #endif
       
  1081 
       
  1082         aEntry->SetUniqueFileId( lastUID + 1 );
       
  1083         }
       
  1084 
       
  1085     iItems.AppendL( aEntry );
       
  1086     }
       
  1087 
       
  1088 
       
  1089 CMemSpyEngineOpenFileListEntry* CMemSpyEngineOpenFileListForThread::EntryByFileName( const TDesC& aFileName )
       
  1090     {
       
  1091     CMemSpyEngineOpenFileListEntry* ret = NULL;
       
  1092     //
       
  1093     const TInt count = iItems.Count();
       
  1094     for( TInt i=count-1; i>=0; i-- )
       
  1095         {
       
  1096         CMemSpyEngineOpenFileListEntry* item = iItems[ i ];
       
  1097         if  ( item->FileName().CompareF( aFileName ) == 0 )
       
  1098             {
       
  1099             ret = item;
       
  1100             break;
       
  1101             }
       
  1102         }
       
  1103     //
       
  1104     return ret;
       
  1105     }
       
  1106 
       
  1107 
       
  1108 
       
  1109 
       
  1110 
       
  1111 
       
  1112 
       
  1113 
       
  1114 
       
  1115 
       
  1116 CMemSpyEngineOpenFileList::CMemSpyEngineOpenFileList()
       
  1117     {
       
  1118     }
       
  1119 
       
  1120 
       
  1121 EXPORT_C CMemSpyEngineOpenFileList::~CMemSpyEngineOpenFileList()
       
  1122     {
       
  1123     iItems.ResetAndDestroy();
       
  1124     iItems.Close();
       
  1125     }
       
  1126 
       
  1127 
       
  1128 void CMemSpyEngineOpenFileList::ConstructL( CMemSpyEngine& aEngine )
       
  1129     {
       
  1130     _LIT( KUnknownThread, "Unknown Thread" );
       
  1131     TFullName threadName;
       
  1132     TOpenFileScan scanner( aEngine.FsSession() );
       
  1133     //
       
  1134     CFileList* list = NULL;
       
  1135     scanner.NextL( list );
       
  1136     while( list != NULL )
       
  1137         {
       
  1138         CleanupStack::PushL( list );
       
  1139 
       
  1140         // Reset name
       
  1141         threadName = KUnknownThread;
       
  1142         
       
  1143         // Try to get real thread name
       
  1144         TProcessId procId;
       
  1145         RThread thread;
       
  1146         if  ( aEngine.Driver().OpenThread( scanner.ThreadId(), thread ) == KErrNone )
       
  1147             {
       
  1148             RProcess process;
       
  1149             if ( thread.Process( process ) == KErrNone )
       
  1150                 {
       
  1151                 procId = process.Id();
       
  1152                 process.Close();
       
  1153                 }
       
  1154             //
       
  1155             thread.FullName( threadName );
       
  1156             thread.Close();
       
  1157             }
       
  1158 
       
  1159         // Create thread entry
       
  1160         CMemSpyEngineOpenFileListForThread* threadEntry = CMemSpyEngineOpenFileListForThread::NewLC( threadName, scanner.ThreadId(), procId, *list );
       
  1161         iItems.AppendL( threadEntry );
       
  1162         CleanupStack::Pop( threadEntry );
       
  1163 
       
  1164         // Destroy list and move on to next thread.
       
  1165         CleanupStack::PopAndDestroy( list );
       
  1166         list = NULL;
       
  1167         scanner.NextL( list );
       
  1168         }
       
  1169     }
       
  1170 
       
  1171 
       
  1172 CMemSpyEngineOpenFileList* CMemSpyEngineOpenFileList::NewLC( CMemSpyEngine& aEngine )
       
  1173     {
       
  1174     CMemSpyEngineOpenFileList* self = new(ELeave) CMemSpyEngineOpenFileList();
       
  1175     CleanupStack::PushL( self );
       
  1176     self->ConstructL( aEngine );
       
  1177     return self;
       
  1178     }
       
  1179 
       
  1180 
       
  1181 EXPORT_C TInt CMemSpyEngineOpenFileList::Count() const
       
  1182     {
       
  1183     return iItems.Count();
       
  1184     }
       
  1185 
       
  1186 
       
  1187 EXPORT_C const CMemSpyEngineOpenFileListForThread& CMemSpyEngineOpenFileList::At( TInt aIndex ) const
       
  1188     {
       
  1189     return *iItems[ aIndex ];
       
  1190     }
       
  1191