videocollection/hgmyvideos/src/CIptvDriveMonitor.cpp
branchRCL_3
changeset 8 ce5ada96ab30
equal deleted inserted replaced
6:7d91903f795f 8:ce5ada96ab30
       
     1 /*
       
     2 * Copyright (c) 2010 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 the License "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 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "CIptvDriveMonitor.h"
       
    24 #include "MIptvDriveMonitorObserver.h"
       
    25 #include "TIptvDriveMonitorEvent.h"
       
    26 #include <bldvariant.hrh>
       
    27 #ifdef RD_MULTIPLE_DRIVE_ENABLERS
       
    28 #include <driveinfo.h>
       
    29 #endif
       
    30 #include <centralrepository.h>
       
    31 
       
    32 // EXTERNAL DATA STRUCTURES
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES  
       
    35 
       
    36 // CONSTANTS
       
    37 #if IPTV_LOGGING_METHOD != 0
       
    38 _LIT( KIptvMediaNotPresentDes, "EMediaNotPresent");
       
    39 _LIT( KIptvMediaUnknownDes, "EMediaUnknown");
       
    40 _LIT( KIptvMediaFloppyDes, "EMediaFloppy");
       
    41 _LIT( KIptvMediaHardDiskDes, "EMediaHardDisk");
       
    42 _LIT( KIptvMediaCdRomDes, "EMediaCdRom");
       
    43 _LIT( KIptvMediaRamDes, "EMediaRam");
       
    44 _LIT( KIptvMediaFlashDes, "EMediaFlash");
       
    45 _LIT( KIptvMediaRomDes, "EMediaRom");
       
    46 _LIT( KIptvMediaRemoteDes, "EMediaRemote");
       
    47 _LIT( KIptvMediaNANDFlashDes, "EMediaNANDFlash");
       
    48 #endif
       
    49 
       
    50 // MACROS
       
    51 
       
    52 // LOCAL CONSTANTS AND MACROS
       
    53 
       
    54 // MODULE DATA STRUCTURES
       
    55 
       
    56 // LOCAL FUNCTION PROTOTYPES
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 
       
    60 // ============================= LOCAL FUNCTIONS ===============================
       
    61 
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CIptvDriveMonitor::CIptvDriveMonitor
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CIptvDriveMonitor::CIptvDriveMonitor()
       
    72 : CActive( EPriorityStandard )
       
    73     {
       
    74     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::CIptvDriveMonitor() start");
       
    75     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::CIptvDriveMonitor() exit");
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CIptvEvents::ConstructL
       
    80 // Symbian 2nd phase constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CIptvDriveMonitor::ConstructL( const RFs& aFileSession )
       
    84     {
       
    85     iFs                  = aFileSession;
       
    86     iIfsIsProvidedByUser = ETrue;
       
    87    
       
    88     ConstructL();    
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CIptvEvents::ConstructL
       
    93 // Symbian 2nd phase constructor can leave.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CIptvDriveMonitor::ConstructL()
       
    97     {
       
    98     iObservers.Reset();
       
    99     iAvailableDrives.Reset();
       
   100     iPreviousAvailableDrives.Reset();
       
   101     
       
   102     if ( !iIfsIsProvidedByUser )
       
   103         {
       
   104         User::LeaveIfError( iFs.Connect() );
       
   105         }
       
   106 
       
   107     iSystemDrive = iFs.GetSystemDrive();
       
   108     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, iDefaultMassStorageDrive );
       
   109     if ( err != KErrNone )
       
   110         {
       
   111         iDefaultMassStorageDrive = KErrNotFound;        
       
   112         }
       
   113     err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRemovableMassStorage, iDefaultMemoryCardDrive );
       
   114     if ( err != KErrNone )
       
   115         {
       
   116         iDefaultMassStorageDrive = KErrNotFound;        
       
   117         }
       
   118             
       
   119     CActiveScheduler::Add( this );
       
   120     RefreshAvailableDrivesL();
       
   121 
       
   122     IPTVLOGSTRING2_HIGH_LEVEL("CIptvDriveMonitor:: PhoneMemoryDrive() returns %d",
       
   123         PhoneMemoryDrive());
       
   124     IPTVLOGSTRING2_HIGH_LEVEL("CIptvDriveMonitor:: MemoryCardDrive() returns %d",
       
   125         MemoryCardDrive());
       
   126     IPTVLOGSTRING2_HIGH_LEVEL("CIptvDriveMonitor:: MassStorageDrive() returns %d",
       
   127         MassStorageDrive());
       
   128     IPTVLOGSTRING2_HIGH_LEVEL("CIptvDriveMonitor:: FixedDrive(c-drive excluded) returns %d",
       
   129         FixedDrive( ETrue ));
       
   130     
       
   131 #if IPTV_LOGGING_METHOD != 0
       
   132     PrintAvailableDrives();
       
   133 #endif
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CIptvDriveMonitor::NewL
       
   138 // Two-phased constructor.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 CIptvDriveMonitor* CIptvDriveMonitor::NewL()
       
   142     {
       
   143     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::NewL() start");
       
   144 
       
   145     CIptvDriveMonitor* self = new( ELeave ) CIptvDriveMonitor();
       
   146         
       
   147     CleanupStack::PushL( self );
       
   148     self->ConstructL();
       
   149     CleanupStack::Pop(self);
       
   150 
       
   151     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::NewL() exit");
       
   152 
       
   153     return self;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CIptvDriveMonitor::NewL
       
   158 // Two-phased constructor.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 CIptvDriveMonitor* CIptvDriveMonitor::NewL( const RFs& aFileSession )
       
   162     {
       
   163     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::NewL(RFs&) start");
       
   164 
       
   165     CIptvDriveMonitor* self = new( ELeave ) CIptvDriveMonitor();
       
   166         
       
   167     CleanupStack::PushL( self );
       
   168     self->ConstructL( aFileSession );
       
   169     CleanupStack::Pop(self);
       
   170 
       
   171     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::NewL(RFs&) exit");
       
   172 
       
   173     return self;
       
   174     }
       
   175     
       
   176 // Destructor
       
   177 CIptvDriveMonitor::~CIptvDriveMonitor()
       
   178     {
       
   179     iObservers.Close();
       
   180     iAvailableDrives.Close();
       
   181     iPreviousAvailableDrives.Close();
       
   182     Cancel();
       
   183     
       
   184     if ( !iIfsIsProvidedByUser )
       
   185         {
       
   186         iFs.Close();
       
   187         }
       
   188     }
       
   189 
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CIptvDriveMonitor::RegisterObserverL
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CIptvDriveMonitor::RegisterObserverL( MIptvDriveMonitorObserver* aObserver )
       
   196     {
       
   197     iObservers.AppendL( aObserver );
       
   198 
       
   199     if ( !IsActive() )
       
   200         {
       
   201         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   202         SetActive();
       
   203         }
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CIptvDriveMonitor::RemoveObserverL
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CIptvDriveMonitor::RemoveObserverL( MIptvDriveMonitorObserver* aObserver )
       
   211     {
       
   212     TInt i;
       
   213     for ( i = 0; i < iObservers.Count(); i++ )
       
   214         {
       
   215         if ( aObserver == iObservers[i] )
       
   216             {
       
   217             iObservers.Remove( i );
       
   218             iObservers.Compress();
       
   219             break;
       
   220             }
       
   221         }
       
   222         
       
   223     if ( iObservers.Count() == 0 )
       
   224         {
       
   225         iFs.NotifyChangeCancel();
       
   226         }    
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CIptvDriveMonitor::RefreshAvailableDrivesL
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CIptvDriveMonitor::RefreshAvailableDrivesL()
       
   234     {
       
   235     IPTVLOGSTRING_LOW_LEVEL("CIptvDriveMonitor::RefreshAvailableDrivesL() start");
       
   236     
       
   237     TDriveList driveList;
       
   238     User::LeaveIfError( iFs.DriveList( driveList ) );
       
   239 
       
   240     iPreviousAvailableDrives.Reset();
       
   241     TInt i;
       
   242     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   243         {
       
   244         iPreviousAvailableDrives.Append( iAvailableDrives[i] );
       
   245         }
       
   246             
       
   247     iAvailableDrives.Reset();
       
   248     
       
   249     for ( i = 0; i < driveList.Length(); i++ )
       
   250         {
       
   251         if ( driveList[i] != 0 )
       
   252             {
       
   253             TDriveInfo driveInfo;
       
   254             User::LeaveIfError( iFs.Drive( driveInfo, i ) );
       
   255             
       
   256             IPTVLOGSTRING3_LOW_LEVEL("CIptvDriveMonitor:: drive[%d]: type = %S",
       
   257                                      i,
       
   258                                      &DriveTypeDes( driveInfo.iType ));
       
   259 
       
   260             IPTVLOGSTRING3_LOW_LEVEL(
       
   261                 "CIptvDriveMonitor::           MediaAtt flags = %x DriveAtt flags = %x",
       
   262                     driveInfo.iMediaAtt,
       
   263                     driveInfo.iDriveAtt );
       
   264 
       
   265 #ifdef __WINSCW__
       
   266             // (2) c-drive is EMediaRam
       
   267             // (3) d-drive is EMediaHardDisk
       
   268             // (4) e-drive is EMediaHardDisk or EMediaNotPresent
       
   269             // (25) z-drive is EMediaRom
       
   270             if ( (driveInfo.iType == EMediaRam) ||                                     // c
       
   271                  ((driveInfo.iType == EMediaHardDisk) && i != EDriveD /* skip d */) || // e
       
   272                  (driveInfo.iType == EMediaNANDFlash) ||                               // nothing
       
   273                  (driveInfo.iType == EMediaNotPresent) )                               // e
       
   274 #else
       
   275             // (2) c-drive is EMediaNANDFlash
       
   276             // (3) d-drive is EMediaRam
       
   277             // (4) e-drive is EMediaHardDisk or EMediaNotPresent
       
   278             // (5) f-drive is EMediaHardDisk or EMediaNotPresent
       
   279             // (25) z-drive is EMediaRom
       
   280             if ( (driveInfo.iType == EMediaHardDisk) ||  // e,f
       
   281                  (driveInfo.iType == EMediaNANDFlash) || // c
       
   282                  (driveInfo.iType == EMediaNotPresent) ) // e,f
       
   283 #endif // __WINSCW__
       
   284                 {                
       
   285                 if ( !(driveInfo.iMediaAtt & KMediaAttWriteProtected) &&
       
   286                       (driveInfo.iDriveAtt & KDriveAttLocal) )
       
   287                     {
       
   288                     TIptvDriveInfo iptvDriveInfo;
       
   289                     TVolumeInfo volumeInfo;
       
   290                     TChar ch;
       
   291 
       
   292                     iFs.DriveToChar( i, ch );
       
   293 
       
   294                     iptvDriveInfo.iDrive     = i;
       
   295                     iptvDriveInfo.iDriveChar = ch;
       
   296                     iptvDriveInfo.iType      = driveInfo.iType;
       
   297                     
       
   298                     TUint driveStatus;
       
   299                     TInt err = DriveInfo::GetDriveStatus( iFs, i, driveStatus );
       
   300                     if ( err == KErrNone )
       
   301                         {
       
   302                         if ( driveStatus & DriveInfo::EDriveRemovable )
       
   303                             {
       
   304                             iptvDriveInfo.iFlags |= TIptvDriveInfo::ERemovable;
       
   305                             }
       
   306                         }
       
   307 
       
   308                     TInt massStorageDrive;
       
   309                     err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage,
       
   310                                                       massStorageDrive );
       
   311                     if ( err == KErrNone )
       
   312                         {
       
   313                         if ( i == massStorageDrive )
       
   314                             {
       
   315                             iptvDriveInfo.iFlags |= TIptvDriveInfo::EMassStorage;
       
   316                             }                        
       
   317                         }
       
   318 
       
   319                     if ( driveInfo.iMediaAtt & KMediaAttLocked )
       
   320                         {
       
   321                         iptvDriveInfo.iFlags |= TIptvDriveInfo::ELocked;
       
   322                         }
       
   323                     if ( driveInfo.iType == EMediaNotPresent )
       
   324                         {
       
   325                         iptvDriveInfo.iFlags |= TIptvDriveInfo::EMediaNotPresent;
       
   326                         }
       
   327 
       
   328                     // When mass storage mode is activated while application is running,
       
   329                     // the only hint about that is the TVolumeInfo not being available. 
       
   330                     // Therefore we mark drive as EMediaNotPresent if that structure
       
   331                     // is not available.
       
   332                     if ( iFs.Volume( volumeInfo, i ) != KErrNone )
       
   333                         {
       
   334                         iptvDriveInfo.iFlags |= TIptvDriveInfo::EMediaNotPresent;
       
   335                         iptvDriveInfo.iVolumeName.Zero();
       
   336                         }
       
   337                     else
       
   338                         {
       
   339                         iptvDriveInfo.iVolumeName = volumeInfo.iName;
       
   340                         }
       
   341 
       
   342                     if ( iptvDriveInfo.iFlags & TIptvDriveInfo::EMediaNotPresent )
       
   343                         {
       
   344                         iptvDriveInfo.iFlags |= TIptvDriveInfo::ERemovable;
       
   345                         }
       
   346                                             
       
   347                     iAvailableDrives.AppendL( iptvDriveInfo );
       
   348                     }
       
   349                 }
       
   350             }
       
   351         } // for
       
   352 
       
   353     // if e and f-drives are available, then c-drive is removed from the available drives list
       
   354     if ( ArrayPos( EDriveE ) != KErrNotFound &&
       
   355          ArrayPos( EDriveF ) != KErrNotFound )
       
   356         {
       
   357         TInt cDrivePos = ArrayPos( EDriveC );
       
   358         if ( cDrivePos != KErrNotFound )
       
   359             {
       
   360             IPTVLOGSTRING_LOW_LEVEL(
       
   361                 "CIptvDriveMonitor:: e & f-drives available -> removing c from available drives");
       
   362             iAvailableDrives.Remove( cDrivePos );
       
   363             iAvailableDrives.Compress();
       
   364             }
       
   365         }
       
   366     
       
   367     IPTVLOGSTRING_LOW_LEVEL("CIptvDriveMonitor::RefreshAvailableDrivesL() exit");
       
   368     }
       
   369     
       
   370 // -----------------------------------------------------------------------------
       
   371 // CIptvDriveMonitor::ArrayPos
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 TInt CIptvDriveMonitor::ArrayPos( TInt aDrive )
       
   375     {
       
   376     TInt i;
       
   377     for (i = 0; i < iAvailableDrives.Count(); i++ )
       
   378         {
       
   379         if ( iAvailableDrives[i].iDrive == aDrive )
       
   380             {
       
   381             return i;
       
   382             }
       
   383         }
       
   384     return KErrNotFound;
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CIptvDriveMonitor::ArrayPosL
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 TInt CIptvDriveMonitor::ArrayPosL( TInt aDrive )
       
   392     {
       
   393     TInt pos;
       
   394     User::LeaveIfError( pos = ArrayPos( aDrive ) );
       
   395     return pos;
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CIptvDriveMonitor::MemoryCardDriveL
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 TInt CIptvDriveMonitor::MemoryCardDriveL()
       
   403     {
       
   404     TInt drive;
       
   405     User::LeaveIfError( drive = MemoryCardDrive() );
       
   406     return drive;
       
   407     }
       
   408 
       
   409 // -----------------------------------------------------------------------------
       
   410 // CIptvDriveMonitor::MemoryCardDrive
       
   411 // -----------------------------------------------------------------------------
       
   412 //
       
   413 TInt CIptvDriveMonitor::MemoryCardDrive()
       
   414     {
       
   415     TInt i;
       
   416     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   417         {
       
   418         if ( iAvailableDrives[i].iDrive == iDefaultMemoryCardDrive )
       
   419             {
       
   420             return iAvailableDrives[i].iDrive;
       
   421             }
       
   422         }
       
   423     return KErrNotFound;
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CIptvDriveMonitor::MassStorageDriveL
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 TInt CIptvDriveMonitor::MassStorageDriveL()
       
   431     {
       
   432     TInt drive;
       
   433     User::LeaveIfError( drive = MassStorageDrive() );
       
   434     return drive;
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CIptvDriveMonitor::MassStorageDrive
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 TInt CIptvDriveMonitor::MassStorageDrive()
       
   442     {
       
   443     TInt i;
       
   444     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   445         {
       
   446         if ( iAvailableDrives[i].iDrive == iDefaultMassStorageDrive )
       
   447             {
       
   448             return iAvailableDrives[i].iDrive;
       
   449             }
       
   450         }
       
   451     return KErrNotFound;
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // CIptvDriveMonitor::PhoneMemoryDriveL
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 TInt CIptvDriveMonitor::PhoneMemoryDriveL()
       
   459     {
       
   460     TInt drive;
       
   461     User::LeaveIfError( drive = PhoneMemoryDrive() );
       
   462     return drive;
       
   463     }
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CIptvDriveMonitor::PhoneMemoryDrive
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 TInt CIptvDriveMonitor::PhoneMemoryDrive()
       
   470     {
       
   471     TInt i;
       
   472     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   473         {
       
   474         if ( iAvailableDrives[i].iDrive == iSystemDrive )
       
   475             {
       
   476             return iAvailableDrives[i].iDrive;
       
   477             }
       
   478         }
       
   479     return KErrNotFound;
       
   480     }
       
   481 
       
   482 // -----------------------------------------------------------------------------
       
   483 // CIptvDriveMonitor::FixedDriveL
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 TInt CIptvDriveMonitor::FixedDriveL( TBool aExcludeCDrive )
       
   487     {
       
   488     TInt drive;
       
   489     User::LeaveIfError( drive = FixedDrive( aExcludeCDrive ) );
       
   490     return drive;
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CIptvDriveMonitor::FixedDrive
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TInt CIptvDriveMonitor::FixedDrive( TBool aExcludeCDrive )
       
   498     {
       
   499     TInt i;
       
   500     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   501         {
       
   502         IPTVLOGSTRING2_LOW_LEVEL("CIptvDriveMonitor:: iAvailableDrives[%d]", i);
       
   503 
       
   504         if ( !(iAvailableDrives[i].iFlags & TIptvDriveInfo::ERemovable) )
       
   505             {
       
   506             if ( iAvailableDrives[i].iDrive != EDriveC )
       
   507                 {
       
   508                 IPTVLOGSTRING2_LOW_LEVEL("CIptvDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive);
       
   509                 return iAvailableDrives[i].iDrive;
       
   510                 }
       
   511             else
       
   512                 {
       
   513                 if ( !aExcludeCDrive )
       
   514                     {
       
   515                     IPTVLOGSTRING2_LOW_LEVEL("CIptvDriveMonitor:: FixedDrive() returning drive %d", iAvailableDrives[i].iDrive);
       
   516                     return iAvailableDrives[i].iDrive;
       
   517                     }   
       
   518                 }
       
   519             }
       
   520         }
       
   521     IPTVLOGSTRING_LOW_LEVEL("CIptvDriveMonitor:: FixedDrive() fixed drive not found");
       
   522     return KErrNotFound;
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CIptvDriveMonitor::IsMassStorageDriveL
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 TBool CIptvDriveMonitor::IsMassStorageDriveL( TInt aDrive )
       
   530     {
       
   531     if ( aDrive == iDefaultMassStorageDrive )
       
   532         {
       
   533         return ETrue;
       
   534         }
       
   535     return EFalse;
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // CIptvDriveMonitor::IsMemoryCardDriveL
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 TBool CIptvDriveMonitor::IsMemoryCardDriveL( TInt aDrive )
       
   543     {
       
   544     TInt pos = ArrayPosL( aDrive );
       
   545     if ( iAvailableDrives[pos].iFlags & TIptvDriveInfo::ERemovable )
       
   546         {
       
   547         return ETrue;
       
   548         }
       
   549     return EFalse;
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CIptvDriveMonitor::IsPresentL()
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 TBool CIptvDriveMonitor::IsPresentL( TInt aDrive )
       
   557     {
       
   558     TInt pos = ArrayPosL( aDrive );
       
   559     TUint32 flags = iAvailableDrives[pos].iFlags;
       
   560     if ( (flags & TIptvDriveInfo::ELocked) || (flags & TIptvDriveInfo::EMediaNotPresent) )
       
   561         {
       
   562         return ETrue;
       
   563         }
       
   564     return EFalse;
       
   565     }
       
   566 
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CIptvDriveMonitor::SystemDrive()
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 TInt CIptvDriveMonitor::SystemDrive()
       
   573     {
       
   574     return iSystemDrive;
       
   575     }
       
   576     
       
   577 // -----------------------------------------------------------------------------
       
   578 // CIptvDriveMonitor::IsMmcInserted()
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 TBool CIptvDriveMonitor::IsMmcInserted()
       
   582     {   
       
   583     TInt drive = MemoryCardDrive();
       
   584     
       
   585     if ( drive == KErrNotFound )
       
   586         {
       
   587         return EFalse;
       
   588         }
       
   589         
       
   590     TInt arrayPos = ArrayPos( drive );
       
   591     
       
   592     if ( arrayPos == KErrNotFound )
       
   593         {
       
   594         return EFalse;
       
   595         }
       
   596     
       
   597     TUint32 flags = iAvailableDrives[arrayPos].iFlags;
       
   598     
       
   599     if ( (flags & TIptvDriveInfo::ELocked) || (flags & TIptvDriveInfo::EMediaNotPresent) )
       
   600         {
       
   601         return EFalse;
       
   602         } 
       
   603     
       
   604     return ETrue;
       
   605     }
       
   606     
       
   607 // -----------------------------------------------------------------------------
       
   608 // CIptvDriveMonitor::RunL()
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 void CIptvDriveMonitor::RunL()
       
   612     {
       
   613     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::RunL() start");
       
   614     
       
   615     if ( iStatus == KErrNone )
       
   616         {        
       
   617         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   618         
       
   619         TRAPD( err, RefreshAvailableDrivesL() );
       
   620         if ( err != KErrNone )
       
   621             {
       
   622             IPTVLOGSTRING2_HIGH_LEVEL("CIptvDriveMonitor:: RefreshAvailableDrivesL leaved with error code %d, ignoring", err);
       
   623             } 
       
   624         CompareOldAndNewAvailableDrives();
       
   625         SetActive();
       
   626         }
       
   627     else
       
   628         {
       
   629         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   630         SetActive();
       
   631         }
       
   632 
       
   633     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::RunL() exit");
       
   634     }
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CIptvDriveMonitor::DoCancel()
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CIptvDriveMonitor::DoCancel()
       
   641     {
       
   642     iFs.NotifyChangeCancel( iStatus );
       
   643     }       
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CIptvDriveMonitor::RunError()
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 TInt CIptvDriveMonitor::RunError( TInt /* aError */ )
       
   650     {
       
   651     IPTVLOGSTRING_HIGH_LEVEL("CIptvDriveMonitor::RunL() leaved (should never happen).");
       
   652     return KErrNone;
       
   653     }       
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CIptvDriveMonitor::SendEvent()
       
   657 // -----------------------------------------------------------------------------
       
   658 //
       
   659 void CIptvDriveMonitor::SendEvent( TIptvDriveMonitorEvent::TEvent aEvent,
       
   660     TInt aDrive )
       
   661     {
       
   662     IPTVLOGSTRING4_HIGH_LEVEL("CIptvDriveMonitor:: Sending event: %S(%d), drive: %d",
       
   663         &TIptvDriveMonitorEvent::EventDes( aEvent ),
       
   664         aEvent,
       
   665         aDrive );
       
   666 
       
   667     TIptvDriveMonitorEvent event;
       
   668         
       
   669     for ( TInt i = 0; i < iObservers.Count(); i++ )
       
   670         {
       
   671         event.iEvent = static_cast<TInt>(aEvent);
       
   672         event.iDrive = aDrive;
       
   673         iObservers[i]->HandleDriveMonitorEvent( event );
       
   674         }
       
   675 
       
   676 #if IPTV_LOGGING_METHOD != 0
       
   677     PrintAvailableDrives();
       
   678 #endif
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CIptvDriveMonitor::CompareOldAndNewAvailableDrives
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 void CIptvDriveMonitor::CompareOldAndNewAvailableDrives()
       
   686     {
       
   687     // Run through old drives list to detect changes
       
   688     TInt i;
       
   689     for ( i = 0; i < iPreviousAvailableDrives.Count(); i++ )
       
   690         {
       
   691         TInt pos = ArrayPos( iPreviousAvailableDrives[i].iDrive );
       
   692         if ( pos == KErrNotFound )
       
   693             {
       
   694             // drive was dismounted
       
   695             SendEvent( TIptvDriveMonitorEvent::EDriveDismounted,
       
   696                 iPreviousAvailableDrives[i].iDrive );
       
   697             }
       
   698         else 
       
   699             {
       
   700             // drive still present
       
   701             if ( iPreviousAvailableDrives[i].iFlags != iAvailableDrives[pos].iFlags )
       
   702                 {
       
   703                 // drive was changed
       
   704                 if ( (iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent) && 
       
   705                      !(iAvailableDrives[pos].iFlags & EMediaNotPresent) )
       
   706                     {
       
   707                     SendEvent( TIptvDriveMonitorEvent::EMediaInserted,
       
   708                         iAvailableDrives[pos].iDrive );
       
   709                     }
       
   710                     
       
   711                 if ( !(iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent) && 
       
   712                      (iAvailableDrives[pos].iFlags & TIptvDriveInfo::EMediaNotPresent) )
       
   713                     {
       
   714                     SendEvent( TIptvDriveMonitorEvent::EMediaRemoved,
       
   715                         iAvailableDrives[pos].iDrive );
       
   716                     }
       
   717 
       
   718                 if ( !(iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked) && 
       
   719                      (iAvailableDrives[pos].iFlags & TIptvDriveInfo::ELocked) )
       
   720                     {
       
   721                     SendEvent( TIptvDriveMonitorEvent::EDriveLocked,
       
   722                         iAvailableDrives[pos].iDrive );
       
   723                     }
       
   724 
       
   725                 if ( (iPreviousAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked) && 
       
   726                      !(iAvailableDrives[pos].iFlags & TIptvDriveInfo::ELocked) )
       
   727                     {
       
   728                     SendEvent( TIptvDriveMonitorEvent::EDriveUnlocked,
       
   729                         iAvailableDrives[pos].iDrive );
       
   730                     }               
       
   731                 }
       
   732             // drive volume name was changed
       
   733             if ( iPreviousAvailableDrives[i].iVolumeName.Compare( 
       
   734                  iAvailableDrives[pos].iVolumeName ) != 0 )
       
   735                 {
       
   736                 SendEvent( TIptvDriveMonitorEvent::EDriveVolumeNameChanged, 
       
   737                     iAvailableDrives[pos].iDrive ); 
       
   738                 }
       
   739             }
       
   740         }
       
   741 
       
   742     // Run through new drives list to detect mounted drives
       
   743     for ( i = 0; i < iAvailableDrives.Count(); i++ )
       
   744         {
       
   745         TBool found = EFalse;
       
   746         for ( TInt j = 0; j < iPreviousAvailableDrives.Count(); j++ )
       
   747             {
       
   748             if ( iPreviousAvailableDrives[j].iDrive == iAvailableDrives[i].iDrive )
       
   749                 {
       
   750                 found = ETrue;
       
   751                 break;
       
   752                 }
       
   753             }
       
   754         if ( !found )
       
   755             {
       
   756             SendEvent( TIptvDriveMonitorEvent::EDriveMounted,
       
   757                 iAvailableDrives[i].iDrive );
       
   758             }
       
   759         }
       
   760     }
       
   761 
       
   762 // -----------------------------------------------------------------------------
       
   763 // CIptvDriveMonitor::DriveType()
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 #if IPTV_LOGGING_METHOD != 0 
       
   767 const TDesC& CIptvDriveMonitor::DriveTypeDes( TInt aType )
       
   768     {
       
   769     switch (aType)
       
   770         {     
       
   771         case EMediaNotPresent:
       
   772             return KIptvMediaNotPresentDes;
       
   773 	      case EMediaUnknown:
       
   774             return KIptvMediaUnknownDes;
       
   775         case EMediaFloppy:
       
   776             return KIptvMediaFloppyDes;
       
   777         case EMediaHardDisk:
       
   778             return KIptvMediaHardDiskDes;
       
   779         case EMediaCdRom:
       
   780             return KIptvMediaCdRomDes;
       
   781         case EMediaRam:
       
   782             return KIptvMediaRamDes;
       
   783         case EMediaFlash:
       
   784             return KIptvMediaFlashDes;
       
   785         case EMediaRom:
       
   786             return KIptvMediaRomDes;
       
   787         case EMediaRemote:
       
   788             return KIptvMediaRemoteDes;
       
   789         case EMediaNANDFlash:
       
   790             return KIptvMediaNANDFlashDes;
       
   791         default:
       
   792             return KIptvMediaUnknownDes;
       
   793         }
       
   794     }
       
   795 #else
       
   796 const TDesC& CIptvDriveMonitor::DriveTypeDes( TInt /*aType*/ )
       
   797     {
       
   798     return KIptvEmptyDes;
       
   799     }
       
   800 #endif
       
   801     
       
   802 // -----------------------------------------------------------------------------
       
   803 // CIptvDriveMonitor::PrintAvailableDrives()
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 void CIptvDriveMonitor::PrintAvailableDrives()
       
   807     {
       
   808 #if IPTV_LOGGING_METHOD != 0 
       
   809     for ( TInt i = 0; i < iAvailableDrives.Count(); i++ )
       
   810         {
       
   811         IPTVLOGSTRING3_HIGH_LEVEL("CIptvDriveMonitor:: iAvailableDrives[%d].iDrive = %d",
       
   812             i, iAvailableDrives[i].iDrive);
       
   813         IPTVLOGSTRING2_HIGH_LEVEL("    ERemovableDrive  = %d",
       
   814             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::ERemovable));
       
   815         IPTVLOGSTRING2_HIGH_LEVEL("    EMassStorage     = %d",
       
   816             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::EMassStorage));
       
   817         IPTVLOGSTRING2_HIGH_LEVEL("    ELockedDrive     = %d",
       
   818             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::ELocked));
       
   819         IPTVLOGSTRING2_HIGH_LEVEL("    EMediaNotPresent = %d",
       
   820             !!(iAvailableDrives[i].iFlags & TIptvDriveInfo::EMediaNotPresent));
       
   821         }
       
   822 #endif
       
   823     }
       
   824     
       
   825 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   826 
       
   827 
       
   828 //  End of File