mmsharing/mmshui/src/musuimmcmonitor.cpp
branchRCL_3
changeset 33 bc78a40cd63c
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
       
     1 /*
       
     2 * Copyright (c) 2005 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 
       
    19 #include "musuimmcmonitor.h"
       
    20 #include "muslogger.h" // debug logging
       
    21 
       
    22 #include <pathinfo.h>
       
    23 
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CMusUiMmcMonitor* CMusUiMmcMonitor::NewL( MMusUiMmcObserver& aObserver )
       
    30     {
       
    31     CMusUiMmcMonitor* self = new ( ELeave ) CMusUiMmcMonitor( aObserver );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CMusUiMmcMonitor::ConstructL()
       
    44     {
       
    45     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::ConstructL" );
       
    46     User::LeaveIfError( iFs.Connect() );
       
    47     const TDesC& memoryCardPath = PathInfo::MemoryCardRootPath();
       
    48     TInt driveNumber = 0;
       
    49     if ( memoryCardPath.Length() > 0 )
       
    50         {
       
    51         MUS_LOG( "mus: [MUSUI ]     CMusUiMmcMonitor::ConstructL: \
       
    52                                 ( memoryCardPath.Length() > 0 )" );
       
    53         TChar driveChar( memoryCardPath[0] );
       
    54         iFs.CharToDrive( driveChar, driveNumber );
       
    55         iDriveNumber = static_cast<TDriveNumber>(driveNumber);
       
    56         }
       
    57     else
       
    58         {
       
    59         MUS_LOG( "mus: [MUSUI ]     CMusUiMmcMonitor::ConstructL: else" );
       
    60         TParsePtrC parser( RProcess().FileName() );
       
    61         TChar driveChar( parser.Drive()[0] );
       
    62         iFs.CharToDrive( driveChar, driveNumber );
       
    63         iDriveNumber = static_cast<TDriveNumber>(driveNumber);
       
    64         }
       
    65         
       
    66     iRemovableDrive = IsRemovableDrive( iDriveNumber );
       
    67     iDriveRemoved = DriveRemoved();
       
    68     MonitorMmc();
       
    69     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::ConstructL" );
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CMusUiMmcMonitor::CMusUiMmcMonitor( MMusUiMmcObserver& aObserver )  
       
    78     : CActive( CActive::EPriorityStandard ),
       
    79       iObserver( aObserver )
       
    80     {
       
    81     CActiveScheduler::Add( this );
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CMusUiMmcMonitor::~CMusUiMmcMonitor()
       
    90     {
       
    91     Cancel();
       
    92     iFs.Close();
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMusUiMmcMonitor::RunL()
       
   101     {
       
   102     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::RunL" );
       
   103     if( DriveRemoved() )
       
   104         {
       
   105         iObserver.MmcRemoved();
       
   106         }
       
   107     else // continue monitoring
       
   108         {
       
   109         MonitorMmc();
       
   110         }    
       
   111     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::RunL" );
       
   112     }
       
   113 
       
   114 // -------------------------------------------------------------------------
       
   115 //  If RunL() leaves,It should be handled here.
       
   116 // -------------------------------------------------------------------------
       
   117 //
       
   118 TInt CMusUiMmcMonitor::RunError( TInt aError )
       
   119     {
       
   120 	MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::RunError" );
       
   121     // Nothing can be done here.
       
   122     aError = KErrNone;
       
   123 
       
   124     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::RunError" );
       
   125     return aError;
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CMusUiMmcMonitor::DoCancel()
       
   134     {
       
   135     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::DoCancel" );
       
   136     iFs.NotifyChangeCancel();
       
   137     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::DoCancel" );
       
   138     }
       
   139 
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CMusUiMmcMonitor::MonitorMmc()
       
   146     {
       
   147     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::MonitorMmc" );
       
   148     if( !IsActive() && iRemovableDrive && !iDriveRemoved )
       
   149         {
       
   150         MUS_LOG( "mus: [MUSUI ]     CMusUiMmcMonitor::MonitorMmc: calling iFs.NotifyChange" );
       
   151         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   152         SetActive();
       
   153         }
       
   154     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::MonitorMmc" );
       
   155     }
       
   156 
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool CMusUiMmcMonitor::DriveRemoved()
       
   163     {
       
   164     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::DriveRemoved" );
       
   165     if ( iDriveRemoved )
       
   166         {
       
   167         return iDriveRemoved;
       
   168         }
       
   169 
       
   170     TDriveInfo driveInfo;
       
   171     iFs.Drive( driveInfo, iDriveNumber ); 
       
   172 
       
   173     if ( driveInfo.iType == EMediaNotPresent )
       
   174         {
       
   175         iDriveRemoved = ETrue;
       
   176         }
       
   177 
       
   178     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::DriveRemoved" );
       
   179     return iDriveRemoved;
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 TBool CMusUiMmcMonitor::IsRemovableDrive( TDriveNumber aDriveNumber )
       
   188     {
       
   189     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::IsRemovableDrive" );
       
   190     TDriveInfo driveInfo;
       
   191     iFs.Drive( driveInfo, aDriveNumber );
       
   192     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::IsRemovableDrive" );
       
   193     return ( driveInfo.iDriveAtt & KDriveAttRemovable );
       
   194     }
       
   195 
       
   196 //  End of File