testexecfw/useremul/src/NotifyFileChange.cpp
changeset 0 3e07fef1e154
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*------------------------------------------------------------------
       
     2  -
       
     3  * Software Name : UserEmulator
       
     4  * Version       : v4.2.1309
       
     5  * 
       
     6  * Copyright (c) 2009 France Telecom. All rights reserved.
       
     7  * This software is distributed under the License 
       
     8  * "Eclipse Public License - v 1.0" the text of which is available
       
     9  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    10  *
       
    11  * Initial Contributors:
       
    12  * France Telecom 
       
    13  *
       
    14  * Contributors:
       
    15  *------------------------------------------------------------------
       
    16  -
       
    17  * File Name: NotifyFileChange.cpp
       
    18  * 
       
    19  * Created: 13/08/2009
       
    20  * Author(s): Marcell Kiss, Reshma Sandeep Das
       
    21  *   
       
    22  * Description:
       
    23  * Active object implementation for notification of file changes
       
    24  *------------------------------------------------------------------
       
    25  -
       
    26  *
       
    27  */
       
    28 
       
    29 //System Includes
       
    30 #include <e32std.h>
       
    31 #include <f32file.h>
       
    32 #include <eikenv.h>
       
    33 
       
    34 //User Includes
       
    35 #include "NotifyFileChange.h"
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CNotifyFileChange::NewL
       
    39 // Creates the instance of class and returns it.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CNotifyFileChange* CNotifyFileChange::NewL( MFileChangeObserver& aObserver, const TDesC& aPath)
       
    43 	{
       
    44 	CNotifyFileChange* self = CNotifyFileChange::NewLC(aObserver, aPath);
       
    45 	CleanupStack::Pop( self );
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CNotifyFileChange::NewLC
       
    51 // Creates the instance of class and pushes it to the CleanupStack and return
       
    52 // it.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CNotifyFileChange* CNotifyFileChange::NewLC( MFileChangeObserver& aObserver, const TDesC& aPath)
       
    56 	{
       
    57 	CNotifyFileChange* self = new ( ELeave ) CNotifyFileChange( aObserver, aPath );
       
    58 	CleanupStack::PushL( self );
       
    59 	self->ConstructL();
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CNotifyFileChange::CNotifyFileChange
       
    65 // Calls base classes constructor with priority value. 
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CNotifyFileChange::CNotifyFileChange( MFileChangeObserver& aObserver, const TDesC& aPath )
       
    69   :	CActive(EPriorityStandard), iObserver( aObserver ),iPath((TDes16&)aPath)
       
    70 	{}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CNotifyFileChange::ConstructL
       
    74 // Add class to the active sheduler and issue request for any file or directory 
       
    75 // change notifications
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CNotifyFileChange::ConstructL()
       
    79 	{	
       
    80 		CActiveScheduler::Add( this );  
       
    81 		User::LeaveIfError(iFs.Connect());
       
    82 		
       
    83 		iStatus = KRequestPending;
       
    84 		iFs.NotifyChange(ENotifyAll, iStatus, iPath);
       
    85 		SetActive();
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CNotifyFileChange::~CNotifyFileChange
       
    90 // Destructor
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CNotifyFileChange::~CNotifyFileChange()
       
    94 	{
       
    95 		Cancel();
       
    96 		iFs.Close();
       
    97 	}
       
    98 // -----------------------------------------------------------------------------
       
    99 // CNotifyFileChange::RefreshPath
       
   100 // Function that requests a notification of change to files or directories
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CNotifyFileChange::RefreshPath(TDes& aPath)
       
   104 	{
       
   105 		Cancel();
       
   106 		User::After(KWait001);
       
   107 		iPath.Copy(aPath);
       
   108 		iFs.NotifyChange(ENotifyAll, iStatus, iPath);
       
   109 		SetActive();	
       
   110 	}
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CNotifyFileChange::RunL
       
   114 // Handles the completion of the active request and re-issues the notification 
       
   115 // request
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CNotifyFileChange::RunL()
       
   119 	{	
       
   120 		if (iStatus == KErrNone)
       
   121 		{
       
   122 			if(!IsActive())
       
   123 				{
       
   124 				iObserver.FileChangeEventL();
       
   125 				iFs.NotifyChange(ENotifyAll, iStatus, iPath);
       
   126 				SetActive();
       
   127 				}
       
   128 		}
       
   129 	}
       
   130 	
       
   131 // -----------------------------------------------------------------------------
       
   132 // CNotifyFileChange::DoCancel
       
   133 // Cancels any outstanding requests
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CNotifyFileChange::DoCancel()
       
   137 	{		
       
   138 		if (IsActive())
       
   139 		{
       
   140 			iFs.NotifyChangeCancel();
       
   141 		}
       
   142 	}	
       
   143 // -----------------------------------------------------------------------------
       
   144 // CNotifyFileChange::RunError
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TInt CNotifyFileChange::RunError(TInt /*aError*/)
       
   148 	{
       
   149 		return KErrNone;
       
   150 	}