devencdiskutils/DevEncCommonUtils/src/DevEncDiskStatusObserver.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     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 *              Implements a watcher for disk status change events.   
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include <DevEncEngineConstants.h>
       
    24 #include "DevEncDiskStatusObserver.h"
       
    25 #include "DevEncLog.h"
       
    26 #include "DevEncProtectedPSKey.h"
       
    27 
       
    28 
       
    29 EXPORT_C CDiskStatusObserver* CDiskStatusObserver::NewL( MDiskStatusObserver* aObserver, TDriveNumber aDriveNumber )
       
    30     {
       
    31     DFLOG( "CDiskStatusObserver::NewL" );
       
    32     CDiskStatusObserver* self = new (ELeave) CDiskStatusObserver();
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL( aObserver, aDriveNumber );
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 void CDiskStatusObserver::ConstructL( MDiskStatusObserver* aObserver, TDriveNumber aDriveNumber )
       
    40     {
       
    41     DFLOG( "CDiskStatusObserver::ConstructL" );
       
    42     TInt err = iNfeStatus.Attach( KEncUtility, ENC_KEY( aDriveNumber, KDEStatusToUiKey ) );
       
    43     if ( err )
       
    44         {
       
    45         DFLOG2( "ERROR: Attach failed, err %d", err );
       
    46         }
       
    47     iObserver = aObserver;
       
    48     iDrive = aDriveNumber;
       
    49     CActiveScheduler::Add( this );
       
    50     iNfeStatus.Subscribe( iStatus );
       
    51     SetActive();
       
    52     }
       
    53 
       
    54 CDiskStatusObserver::CDiskStatusObserver() : CActive( EPriorityIdle )
       
    55     {
       
    56     }
       
    57 
       
    58 CDiskStatusObserver::~CDiskStatusObserver()
       
    59     {
       
    60     DFLOG( "CDiskStatusObserver::~CDiskStatusObserver" );
       
    61     Cancel();
       
    62     iNfeStatus.Close();
       
    63     }
       
    64 
       
    65 void CDiskStatusObserver::DoCancel()
       
    66     {
       
    67     DFLOG( "CDiskStatusObserver::DoCancel" );
       
    68     iNfeStatus.Cancel();
       
    69     }
       
    70 
       
    71 void CDiskStatusObserver::RunL()
       
    72     {
       
    73     DFLOG( "CDiskStatusObserver::RunL" );
       
    74     iNfeStatus.Subscribe( iStatus );
       
    75     SetActive();
       
    76     
       
    77     TInt nfeStatus;
       
    78     TInt err = iNfeStatus.Get( nfeStatus );
       
    79     if( !err )
       
    80         {
       
    81         TInt status;
       
    82         switch( nfeStatus )
       
    83         	{
       
    84         	case EDecrypting: status = EOpDecrypting;
       
    85         		              break;
       
    86         	case EEncrypting: status = EOpEncrypting;
       
    87         		              break;
       
    88         	default: status = EOpIdle;
       
    89         		     break;
       
    90             }
       
    91         //if a multidrive encryption/decryption is ongoing we cannot change the status of the ps key until
       
    92         //all the drives have concluded the operation. 
       
    93         if( ( status == EOpIdle && !IsEncryptionOperationOngoing() ) || status != EOpIdle )
       
    94             {
       
    95             RProperty::Set( KDevEncProtectedUid, KDevEncOperationKey, status );
       
    96             }
       
    97         iObserver->DiskStatusChangedL( nfeStatus );
       
    98         }
       
    99     }
       
   100 
       
   101 TBool CDiskStatusObserver::IsEncryptionOperationOngoing()
       
   102     {
       
   103     DFLOG( "CDiskStatusObserver::IsEncryptionOperationOngoing" );
       
   104     TBool ret( EFalse );
       
   105     TBool cont( ETrue );
       
   106     for( TInt i = EDriveA; ( i < KMaxDrives ) && cont; i++ )
       
   107         {
       
   108         TInt status;
       
   109         TInt err = RProperty::Get( KEncUtility, ENC_KEY( (TDriveNumber) i, KDEStatusToUiKey ), status );
       
   110         if( !err )
       
   111             {
       
   112             if( status == EDecrypting || status == EEncrypting )
       
   113                 {
       
   114                 DFLOG2( "drive %d has an encryption or decryption operation ongoing", i );
       
   115             	ret = ETrue;
       
   116             	cont = EFalse;
       
   117                 }
       
   118             else
       
   119                 {
       
   120                 DFLOG2( "drive %d is in Idle", i );
       
   121                 }
       
   122             }
       
   123         else
       
   124         	{
       
   125         	DFLOG3( "ERROR: Get failed for drive %d, err %d", i, err );
       
   126             }
       
   127         }    
       
   128     return ret;
       
   129     }
       
   130 
       
   131 // End of File