mmappcomponents/harvester/filehandler/src/mpxdiskspacewatcher.cpp
changeset 0 a2952bb97e68
child 9 bee149131e4b
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Low disk space watcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <mpxlog.h>
       
    21 #include "mpxdiskspacewatcher.h"
       
    22 #include "mpxdiskspacewatcherobserver.h"
       
    23 
       
    24 // CONSTANTS
       
    25 const TInt KLowDiskThreshold  = 131072 * 4; // 128k *4
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CMPXDiskSpaceWatcher::CMPXDiskSpaceWatcher( RFs& aFs, TInt aDrive,
       
    32                                             MMPXDiskSpaceObserver& aObs  )
       
    33                                            : CActive( CActive::EPriorityHigh ),
       
    34                                              iFs( aFs ),
       
    35                                              iDriveToMonitor( aDrive ),
       
    36                                              iObs( aObs )
       
    37 
       
    38     {
       
    39     CActiveScheduler::Add( this );
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // ConstructL
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void CMPXDiskSpaceWatcher::ConstructL()
       
    48     {
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Two-Phased Constructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CMPXDiskSpaceWatcher* CMPXDiskSpaceWatcher::NewL( RFs& aFs, TInt aDrive,
       
    57                                                   MMPXDiskSpaceObserver& aObs  )
       
    58     {
       
    59     CMPXDiskSpaceWatcher* self = new( ELeave ) CMPXDiskSpaceWatcher( aFs,
       
    60                                                                      aDrive,
       
    61                                                                      aObs );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // destructor
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CMPXDiskSpaceWatcher::~CMPXDiskSpaceWatcher()
       
    73     {
       
    74     Cancel();
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // Start the watcher
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CMPXDiskSpaceWatcher::StartL()
       
    82     {
       
    83     TVolumeInfo volInfo;
       
    84     TInt err = iFs.Volume( volInfo, iDriveToMonitor );
       
    85 
       
    86     // Only start if the disk is actually working
       
    87     //
       
    88     if (!IsActive() && err == KErrNone )
       
    89         {
       
    90         MPX_DEBUG2("CMPXDiskSpaceWatcher::Start monitor drive %d",
       
    91                    iDriveToMonitor);
       
    92         iFs.NotifyDiskSpace( KLowDiskThreshold, iDriveToMonitor, iStatus );  //lint !e747
       
    93         SetActive();
       
    94         }
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Check if the disk is low on memory
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TBool CMPXDiskSpaceWatcher::IsLowOnDisk()
       
   102     {
       
   103     TVolumeInfo volInfo;
       
   104     TInt err = iFs.Volume( volInfo, iDriveToMonitor );
       
   105 
       
   106     MPX_DEBUG3("CMPXDiskSpaceWatcher::IsLowOnDisk disk %i free %i",
       
   107                iDriveToMonitor, volInfo.iFree );
       
   108 
       
   109     // Can only trust disk space amount if we could get volume info
       
   110     //
       
   111     if( (volInfo.iFree < KLowDiskThreshold) && err == KErrNone )
       
   112         {
       
   113         MPX_DEBUG1("LOW DISK SPACE");
       
   114         return ETrue;
       
   115         }
       
   116     else
       
   117         {
       
   118         MPX_DEBUG1("DISK SPACE OK");
       
   119         return EFalse;
       
   120         }
       
   121 
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Gets the currently monitored drive number
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CMPXDiskSpaceWatcher::CurrentDrive()
       
   129     {
       
   130     return iDriveToMonitor;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Cancel the disk notification
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CMPXDiskSpaceWatcher::DoCancel()
       
   138     {
       
   139     // Cancel the disk space monitoring
       
   140     iFs.NotifyDiskSpaceCancel();
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Active Object callback
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CMPXDiskSpaceWatcher::RunL()
       
   148     {
       
   149     // Callback to observer about which drive is low on disk space
       
   150     //
       
   151     iObs.HandleLowDiskEvent( iDriveToMonitor );
       
   152     }
       
   153 
       
   154 // END OF FILE