harvesterplugins/file/src/cmmcmonitor.cpp
changeset 0 ccd0fd43f247
child 2 208a4ba3894c
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     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 "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:  Mmc monitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cmmcmonitor.h"
       
    21 #include "cfileplugin.h"
       
    22 #include "harvesterserverlogger.h"
       
    23 
       
    24 #include <pathinfo.h>
       
    25 #include <s32file.h>
       
    26 #include <f32file.h> // TDriveNumber
       
    27 #include <driveinfo.h> // TDriveInfo
       
    28 
       
    29 #include <uikoninternalpskeys.h>
       
    30 
       
    31 // CONSTANTS
       
    32 // 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CMMCMonitor::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CMMCMonitor* CMMCMonitor::NewL( CFilePlugin& aFilePlugin, RFs* aFsSession )
       
    41     {
       
    42     CMMCMonitor* self = new ( ELeave ) CMMCMonitor( aFilePlugin );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL( aFsSession );
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMMCMonitor::CMMCMonitor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMMCMonitor::CMMCMonitor( CFilePlugin& aFilePlugin )
       
    55     : CActive( CActive::EPriorityStandard ),
       
    56       iFilePlugin( aFilePlugin )
       
    57     {
       
    58     CPIXLOGSTRING("ENTER CMMCMonitor::CMMCMonitor");
       
    59     CActiveScheduler::Add( this );
       
    60     CPIXLOGSTRING("END CMMCMonitor::CMMCMonitor");
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMMCMonitor::~CMMCMonitor
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMMCMonitor::~CMMCMonitor()
       
    69     {
       
    70     CPIXLOGSTRING("ENTER ~CMMCMonitor");
       
    71 
       
    72     Cancel();
       
    73     iProperty.Close();
       
    74     CPIXLOGSTRING("END ~CMMCMonitor");
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMMCMonitor::ConstructL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMMCMonitor::ConstructL( RFs* aFsSession )
       
    83     {
       
    84     CPIXLOGSTRING("ENTER CMMCMonitor::ConstructL Foobar");
       
    85     iFsSession = aFsSession;
       
    86     
       
    87     TInt error = iProperty.Attach( KPSUidUikon, KUikMMCInserted );
       
    88     if ( error != KErrNone ) CPIXLOGSTRING("END CMMCMonitor::Attach to MMCInserted failed");
       
    89     
       
    90     error = iProperty.Get( KPSUidUikon, KUikMMCInserted, iMmcStatus );
       
    91     if ( error != KErrNone ) 
       
    92     	{
       
    93 		CPIXLOGSTRING("CMMCMonitor::Get MMCInserted failed");
       
    94     	} 
       
    95     else if ( iMmcStatus ) 	 
       
    96     	{
       
    97     	CPIXLOGSTRING("CMMCMonitor::MMC card is in");
       
    98     	}
       
    99     else 
       
   100     	{
       
   101     	CPIXLOGSTRING("CMMCMonitor::no MMC card");
       
   102     	}
       
   103 
       
   104     // The CFilePlugin::StartMonitoring() will call
       
   105     // CMMCMonitor::StartMonitoring() which will call
       
   106     // CMMCMonitor::RunL().
       
   107     //
       
   108     CPIXLOGSTRING("END CMMCMonitor::ConstructL");
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CMMCMonitor::StartMonitoring
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TBool CMMCMonitor::StartMonitoring()
       
   117     {
       
   118     CPIXLOGSTRING("ENTER CMMCMonitor::StartMonitoring");
       
   119     TRAP_IGNORE( RunL() ); // Need to TRAP this rather than use RunError
       
   120     CPIXLOGSTRING("END CMMCMonitor::StartMonitoring");
       
   121     return ETrue;
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMMCMonitor::MmcStatus
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TBool CMMCMonitor::MmcStatus( TInt aDriveNumber )
       
   130     {
       
   131     TBool isMmcPresent(EFalse);
       
   132 
       
   133     if ( iFsSession->IsValidDrive( aDriveNumber ) )
       
   134         {
       
   135         TUint drvStatus( 0 );
       
   136         TInt err = DriveInfo::GetDriveStatus( *iFsSession, aDriveNumber, drvStatus );
       
   137         if ( err )
       
   138             {
       
   139             return EFalse;
       
   140             }
       
   141         // MMC drives are removable and user visible
       
   142         if ( ( drvStatus & DriveInfo::EDriveRemovable ) &&
       
   143              ( drvStatus & DriveInfo::EDriveUserVisible ) )
       
   144                 {
       
   145                 CPIXLOGSTRING2("CMMCMonitor::MmcStatus Drive Number %d", aDriveNumber);
       
   146                 isMmcPresent = ETrue;
       
   147                 }
       
   148         }
       
   149     return isMmcPresent;
       
   150     }
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CMMCMonitor::RunError
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TInt CMMCMonitor::RunError( TInt aError )
       
   158     {
       
   159     CPIXLOGSTRING2("CMMCMonitor::RunError Error:",aError);
       
   160     return KErrNone;
       
   161     }
       
   162 
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CMMCMonitor::DoCancel
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CMMCMonitor::DoCancel()
       
   169     {
       
   170     CPIXLOGSTRING("ENTER CMMCMonitor::DoCancel");
       
   171     iProperty.Cancel();
       
   172     CPIXLOGSTRING("END CMMCMonitor::DoCancel");
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CMMCMonitor::RunL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CMMCMonitor::RunL()
       
   181     {
       
   182     CPIXLOGSTRING("ENTER CMMCMonitor::RunL");
       
   183     iProperty.Subscribe( iStatus );
       
   184     SetActive();
       
   185     User::LeaveIfError( iProperty.Get( KPSUidUikon, KUikMMCInserted, iMmcStatus ) );
       
   186     
       
   187     if ( iMmcStatus )
       
   188     	{
       
   189     	CPIXLOGSTRING("CMMCMonitor::MMC card is in");
       
   190     	}
       
   191     else 
       
   192     	{
       
   193 		CPIXLOGSTRING("CMMCMonitor::no MMC card");
       
   194     	}
       
   195 
       
   196     for ( TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ )
       
   197         {
       
   198         const TBool foundMmc = MmcStatus( driveNumber );
       
   199         if ( !foundMmc )
       
   200             {
       
   201             continue;
       
   202             }
       
   203 
       
   204         // This drive has been recognized as MMC. 
       
   205         TDriveNumber drv = TDriveNumber( driveNumber );
       
   206 
       
   207         TUint drvStatus( 0 );
       
   208 
       
   209         const TInt err = DriveInfo::GetDriveStatus( *iFsSession, driveNumber, drvStatus );
       
   210         if ( err ) 
       
   211             {
       
   212             continue;  // should not happen
       
   213             }
       
   214 
       
   215         if ( drvStatus & DriveInfo::EDrivePresent )
       
   216             {
       
   217             CPIXLOGSTRING("CMMCMonitor::RunL insert event");
       
   218             // Mount MMC and force reharvest
       
   219             iFilePlugin.MountL(drv, ETrue);
       
   220             }
       
   221         else
       
   222             {
       
   223             CPIXLOGSTRING("CMMCMonitor::RunL eject event");
       
   224             // If the MMC has been ejected, then need to dismount 
       
   225             // and undefine the volume
       
   226             iFilePlugin.UnMount(drv, ETrue);
       
   227             }
       
   228         }
       
   229     CPIXLOGSTRING("END CMMCMonitor::RunL");
       
   230     }
       
   231 
       
   232 // End Of File