phonebookengines/contactsmodel/cntsrv/src/CCntLowDiskManager.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <f32file.h> // For RFs
       
    17 
       
    18 #include "CCntLowDiskManager.h"
       
    19 
       
    20 #include "CCntLogger.h"
       
    21 
       
    22 /** Object factory method for CCntLowDiskManager.
       
    23 */
       
    24 CCntLowDiskManager* CCntLowDiskManager::NewL(MContactLowDiskObserver& aObserver,
       
    25 	TInt64 aThreshold, TInt aDrive, RFs& aFs)
       
    26 	{
       
    27 	CCntLowDiskManager* self = new(ELeave) CCntLowDiskManager(aObserver,
       
    28 		aThreshold, aDrive, aFs);
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 
       
    33 /** Destructor. 
       
    34 */
       
    35 CCntLowDiskManager::~CCntLowDiskManager()
       
    36 	{
       
    37 	Cancel();
       
    38 	}
       
    39 
       
    40 
       
    41 /** Request notification of disk space events from File Server.  This method
       
    42 	covers the scenario where we start with low disk (i.e. already below the
       
    43 	threshold).  We won't get a notification from the File Server session in
       
    44 	this case (need to cross threshold).  Rather than repeat the code in RunL(),
       
    45 	manually complete the request here to force a call of RunL().  The actual
       
    46 	registration for disk space events takes place at the end of RunL().
       
    47 */
       
    48 void CCntLowDiskManager::Start()
       
    49 	{
       
    50 	SetActive();
       
    51 	TRequestStatus* status = &iStatus;
       
    52 	User::RequestComplete(status, KErrNone);
       
    53 	}
       
    54 
       
    55 
       
    56 TBool CCntLowDiskManager::LowDiskL()
       
    57 	{
       
    58 	TVolumeInfo volumeInfo;	
       
    59 	User::LeaveIfError(iFs.Volume(volumeInfo, iDrive));
       
    60 	return (volumeInfo.iFree <= iThreshold);
       
    61 	}
       
    62 
       
    63 
       
    64 /** First phase default constructor.
       
    65 */
       
    66 CCntLowDiskManager::CCntLowDiskManager(MContactLowDiskObserver& aObserver,
       
    67 	TInt64 aThreshold, TInt aDrive, RFs& aFs)
       
    68 	:
       
    69 	CActive(EPriorityHigh), iObserver(aObserver), iThreshold(aThreshold),
       
    70 	iDrive(aDrive), iFs(aFs), iWasLowDisk(EFalse)
       
    71 	{
       
    72 	CActiveScheduler::Add(this);
       
    73 	}
       
    74 
       
    75 
       
    76 /** Receives a disk space event and notifies the observer.
       
    77 	@see CActive
       
    78 */
       
    79 void CCntLowDiskManager::RunL()
       
    80 	{
       
    81 	TInt ret = iStatus.Int();
       
    82 	if (ret != KErrNone)
       
    83 		{
       
    84 		return;
       
    85 		}
       
    86 
       
    87 	if (LowDiskL())
       
    88 		{
       
    89 		iWasLowDisk = ETrue;
       
    90 		iObserver.HandleLowDiskL(ETrue);
       
    91 		}
       
    92 	else if (iWasLowDisk)
       
    93 		{
       
    94 		iWasLowDisk = EFalse;
       
    95 		iObserver.HandleLowDiskL(EFalse);
       
    96 		}
       
    97 		
       
    98 	// Request notification again.
       
    99 	iFs.NotifyDiskSpace(iThreshold, iDrive, iStatus);
       
   100 	SetActive();
       
   101 	}
       
   102 
       
   103 
       
   104 /** Recover if RunL() leaves.
       
   105 	@see CActive
       
   106 */
       
   107 TInt CCntLowDiskManager::RunError(TInt /*aError*/)
       
   108 	{
       
   109 	
       
   110 	DEBUG_PRINT1(__VERBOSE_DEBUG__,_L("[CNTMODEL] CCntLowDiskManager::RunError(): RunL() has left!\n"));
       
   111 
       
   112 	return (KErrNone);
       
   113 	}
       
   114 
       
   115 
       
   116 /**
       
   117 	@see CActive
       
   118 */
       
   119 void CCntLowDiskManager::DoCancel()
       
   120 	{
       
   121 	iFs.NotifyDiskSpaceCancel(iStatus);
       
   122 	}