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