mmsharing/mmshui/src/musuimmcmonitor.cpp
changeset 0 f0cf47e981f9
child 21 ce86b6d44a6d
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     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 // -----------------------------------------------------------------------------
       
   116 //
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CMusUiMmcMonitor::DoCancel()
       
   120     {
       
   121     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::DoCancel" );
       
   122     iFs.NotifyChangeCancel();
       
   123     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::DoCancel" );
       
   124     }
       
   125 
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CMusUiMmcMonitor::MonitorMmc()
       
   132     {
       
   133     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::MonitorMmc" );
       
   134     if( !IsActive() && iRemovableDrive && !iDriveRemoved )
       
   135         {
       
   136         MUS_LOG( "mus: [MUSUI ]     CMusUiMmcMonitor::MonitorMmc: calling iFs.NotifyChange" );
       
   137         iFs.NotifyChange( ENotifyDisk, iStatus );
       
   138         SetActive();
       
   139         }
       
   140     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::MonitorMmc" );
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TBool CMusUiMmcMonitor::DriveRemoved()
       
   149     {
       
   150     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::DriveRemoved" );
       
   151     if ( iDriveRemoved )
       
   152         {
       
   153         return iDriveRemoved;
       
   154         }
       
   155 
       
   156     TDriveInfo driveInfo;
       
   157     iFs.Drive( driveInfo, iDriveNumber ); 
       
   158 
       
   159     if ( driveInfo.iType == EMediaNotPresent )
       
   160         {
       
   161         iDriveRemoved = ETrue;
       
   162         }
       
   163 
       
   164     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::DriveRemoved" );
       
   165     return iDriveRemoved;
       
   166     }
       
   167 
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 TBool CMusUiMmcMonitor::IsRemovableDrive( TDriveNumber aDriveNumber )
       
   174     {
       
   175     MUS_LOG( "mus: [MUSUI ]  -> CMusUiMmcMonitor::IsRemovableDrive" );
       
   176     TDriveInfo driveInfo;
       
   177     iFs.Drive( driveInfo, aDriveNumber );
       
   178     MUS_LOG( "mus: [MUSUI ]  <- CMusUiMmcMonitor::IsRemovableDrive" );
       
   179     return ( driveInfo.iDriveAtt & KDriveAttRemovable );
       
   180     }
       
   181 
       
   182 //  End of File