camerauis/cameraapp/generic/src/CamDriveChangeNotifier.cpp
changeset 0 1ddebce53859
child 13 38fb6f7eacd5
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     1 /*
       
     2 * Copyright (c) 2008 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 
       
    20 // INCLUDE FILES
       
    21 #include    <pathinfo.h>
       
    22 
       
    23 #include    "CamDriveChangeNotifier.h"
       
    24 #include    "camlogging.h"
       
    25 #include    "CamUtility.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CCamDriveChangeNotifier::CCamDiskChangeListener::NewL
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CCamDriveChangeNotifier::CCamDiskChangeListener* 
       
    35     CCamDriveChangeNotifier::CCamDiskChangeListener::NewLC(
       
    36                   RFs& aFs,
       
    37                   TDriveNumber aDrive,                                         
       
    38                   MCamDriveChangeNotifierObserver::TCamDriveChangeType aType,
       
    39                   CCamDriveChangeNotifier& aObserver )
       
    40   {
       
    41   PRINT( _L( "Camera => CCamDiskChangeListener::NewLC" ) );
       
    42 
       
    43   CCamDiskChangeListener* self = 
       
    44         new( ELeave ) CCamDiskChangeListener( aFs, aDrive, aType, aObserver );
       
    45   CleanupStack::PushL( self );
       
    46 
       
    47   PRINT( _L( "Camera <= CCamDiskChangeListener::NewLC" ) );
       
    48   return self;
       
    49   }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CCamDriveChangeNotifier::CCamDiskChangeListener::~CCamDiskChangeListener
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CCamDriveChangeNotifier::CCamDiskChangeListener::~CCamDiskChangeListener()
       
    56   {
       
    57   PRINT( _L( "Camera => CCamDiskChangeListener::~CCamDiskChangeListener" ) );
       
    58   Cancel();
       
    59   PRINT( _L( "Camera <= CCamDiskChangeListener::~CCamDiskChangeListener" ) );
       
    60   }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCamDriveChangeNotifier::CCamDiskChangeListener::CCamDiskChangeListener
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CCamDriveChangeNotifier::CCamDiskChangeListener::CCamDiskChangeListener(
       
    67                   RFs& aFs,
       
    68                   TDriveNumber aDrive,                                         
       
    69                   MCamDriveChangeNotifierObserver::TCamDriveChangeType aType,
       
    70                   CCamDriveChangeNotifier& aObserver )
       
    71     : CActive( CActive::EPriorityIdle ),
       
    72       iFs( aFs ),
       
    73       iDrive( aDrive ),
       
    74       iType( aType ),
       
    75       iObserver( aObserver )                                          
       
    76   {
       
    77   CActiveScheduler::Add( this );
       
    78   }
       
    79     
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCamDriveChangeNotifier::CCamDiskChangeListener::Start
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CCamDriveChangeNotifier::CCamDiskChangeListener::Start()
       
    85   {
       
    86   PRINT( _L( "Camera => CCamDiskChangeListener::Start" ) );
       
    87   if ( !IsActive() )
       
    88     {
       
    89     PRINT( _L( "Camera <> CCamDiskChangeListener::Start SetActive()" ) );
       
    90         
       
    91     // Start listening for change events
       
    92     iFs.NotifyChange( ENotifyDisk, iStatus );
       
    93     SetActive();
       
    94     }
       
    95   PRINT( _L( "Camera <= CCamDiskChangeListener::Start" ) );
       
    96   }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CCamDriveChangeNotifier::CCamDiskChangeListener::Stop
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CCamDriveChangeNotifier::CCamDiskChangeListener::Stop()
       
   103   {
       
   104   PRINT( _L( "Camera => CCamDiskChangeListener::Stop" ) );
       
   105   Cancel();
       
   106   PRINT( _L( "Camera <= CCamDiskChangeListener::Stop" ) );
       
   107   }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CCamDriveChangeNotifier:::CCamDiskChangeListener::DoCancel
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CCamDriveChangeNotifier::CCamDiskChangeListener::DoCancel()
       
   114   {
       
   115   PRINT( _L( "Camera => CCamDiskChangeListener::DoCancel" ) );
       
   116   iFs.NotifyChangeCancel();
       
   117   PRINT( _L( "Camera <= CCamDiskChangeListener::DoCancel" ) );
       
   118   }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CCamDriveChangeNotifier::CCamDiskChangeListener::RunL
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CCamDriveChangeNotifier::CCamDiskChangeListener::RunL()
       
   125   {
       
   126   PRINT2( _L( "Camera => CCamDiskChangeListener::RunL iType: %d, iStatus: %d" ), iType, iStatus.Int() );
       
   127   TInt ret = KErrNone;
       
   128   
       
   129   if ( iStatus == KErrNone )
       
   130     {
       
   131     ret = iObserver.NotifyChangeL( iType );
       
   132         
       
   133     if( ret == KErrNone )
       
   134       {
       
   135       Start();
       
   136       }
       
   137     }
       
   138   else if ( iStatus == KErrNotReady )
       
   139     {
       
   140     // Give other threads chance to run	
       
   141     User::After( 0 );	
       
   142     Start();
       
   143     }	
       
   144 
       
   145   PRINT( _L( "Camera <= CCamDiskChangeListener::RunL" ) );
       
   146   }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CCamDriveChangeNotifier::CCamDriveChangeNotifier
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 CCamDriveChangeNotifier::CCamDriveChangeNotifier(
       
   153                                     RFs& aFs,
       
   154                                     MCamDriveChangeNotifierObserver& aObserver )
       
   155     : iObserver( aObserver ),
       
   156       iFs( aFs )
       
   157   {
       
   158   }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CCamDriveChangeNotifier::NewL
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CCamDriveChangeNotifier* CCamDriveChangeNotifier::NewL(
       
   165                                   RFs& aFs,
       
   166                                   MCamDriveChangeNotifierObserver& aObserver )
       
   167   {
       
   168   PRINT( _L( "Camera => CCamDriveChangeNotifier::NewL" ) );
       
   169 
       
   170   CCamDriveChangeNotifier* self =
       
   171                       new( ELeave ) CCamDriveChangeNotifier( aFs, aObserver );
       
   172   
       
   173   self->iListeners.AppendL( CCamDiskChangeListener::NewLC( self->iFs, EDriveE, 
       
   174                       MCamDriveChangeNotifierObserver::EDriveMount, *self ) );
       
   175     
       
   176   self->iListeners.AppendL( CCamDiskChangeListener::NewLC( self->iFs, EDriveD, 
       
   177                       MCamDriveChangeNotifierObserver::EDriveMount, *self ) );
       
   178   
       
   179   CleanupStack::Pop(); // listener
       
   180   CleanupStack::Pop(); // listener 2
       
   181     
       
   182   self->StartMonitoring();
       
   183 
       
   184   PRINT( _L( "Camera <= CCamDriveChangeNotifier::NewL" ) );
       
   185   return self;
       
   186   }
       
   187 
       
   188 
       
   189 // Destructor
       
   190 CCamDriveChangeNotifier::~CCamDriveChangeNotifier()
       
   191   {
       
   192   PRINT( _L( "Camera => CCamDriveChangeNotifier::~CCamDriveChangeNotifier" ) );
       
   193   CancelMonitoring();
       
   194   iListeners.ResetAndDestroy();
       
   195   PRINT( _L( "Camera <= CCamDriveChangeNotifier::~CCamDriveChangeNotifier" ) );
       
   196   }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CCamDriveChangeNotifier::StartMonitoring
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CCamDriveChangeNotifier::StartMonitoring()
       
   203   {
       
   204   PRINT( _L( "Camera => CCamDriveChangeNotifier::StartMonitoring" ) );
       
   205 
       
   206   for ( TInt i = iListeners.Count(); --i >= 0; )
       
   207     {
       
   208     iListeners[i]->Start();
       
   209     }
       
   210 
       
   211   PRINT( _L( "Camera <= CCamDriveChangeNotifier::StartMonitoring" ) );
       
   212   }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CCamDriveChangeNotifier::CancelMonitoring
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CCamDriveChangeNotifier::CancelMonitoring()
       
   219   {
       
   220   PRINT( _L( "Camera => CCamDriveChangeNotifier::CancelMonitoring" ) );
       
   221 
       
   222   for ( TInt i = iListeners.Count(); --i >= 0; )
       
   223     {
       
   224     iListeners[i]->Stop();
       
   225     }
       
   226 
       
   227   PRINT( _L( "Camera <= CCamDriveChangeNotifier::CancelMonitoring" ) );
       
   228   }
       
   229     
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCamDriveChangeNotifier::NotifyChangeL
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CCamDriveChangeNotifier::NotifyChangeL( 
       
   235                   MCamDriveChangeNotifierObserver::TCamDriveChangeType aType )
       
   236   {
       
   237   PRINT( _L( "Camera => CCamDriveChangeNotifier::NotifyChangeL" ) );
       
   238   TInt ret = iObserver.DriveChangeL( aType );
       
   239   if ( ret == KErrNone && aType == 
       
   240                             MCamDriveChangeNotifierObserver::EDriveDismount )
       
   241     {
       
   242     PRINT( _L("Camera <> iFs.AllowDismount( EDriveE )") )
       
   243     iFs.AllowDismount( EDriveE );
       
   244     PRINT( _L("Camera <> iFs.AllowDismount( EDriveD )") )
       
   245     iFs.AllowDismount( EDriveD );
       
   246     }
       
   247         
       
   248   PRINT( _L( "Camera <= CCamDriveChangeNotifier::NotifyChangeL" ) );        
       
   249   return ret;
       
   250   }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CCamDriveChangeNotifier::SendAllowDismount
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CCamDriveChangeNotifier::SendAllowDismount()
       
   257   {
       
   258   PRINT( _L( "Camera => CCamDriveChangeNotifier::SendAllowDismount" ) );
       
   259   iFs.AllowDismount( EDriveE );
       
   260   iFs.AllowDismount( EDriveD );
       
   261   StartMonitoring();
       
   262   PRINT( _L( "Camera <= CCamDriveChangeNotifier::SendAllowDismount" ) );
       
   263   }    
       
   264 //  End of File