os/kernelhwsrv/userlibandfileserver/fileserver/inc/f32notification.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description: 
sl@0
    14
// fileserver/inc/f32notification.h
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef __F32NOTIFICATION_H__
sl@0
    18
#define __F32NOTIFICATION_H__
sl@0
    19
sl@0
    20
/*
sl@0
    21
 * This class is not intended for instantiation neither on the stack
sl@0
    22
 * nor on the heap.
sl@0
    23
 * 
sl@0
    24
 * Clients wishing to use this class should use a pointer provided by 
sl@0
    25
 * CFsNotify::NextNotification().
sl@0
    26
 * 
sl@0
    27
 * @publishedAll
sl@0
    28
 * @released
sl@0
    29
 */
sl@0
    30
class TFsNotification
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	enum TFsNotificationType
sl@0
    34
		{
sl@0
    35
		EFileChange		= 0x0001,	// File contents have changed or/and file has changed size
sl@0
    36
		ERename 		= 0x0002,	// File/directory renamed, or file replaced using RFs::Replace()
sl@0
    37
		ECreate 		= 0x0004,	// File/directory created, or file recreated using RFile::Replace()
sl@0
    38
		EAttribute 		= 0x0008,	// File attribute(s) changed
sl@0
    39
		EDelete 		= 0x0010, 	// File/directory deleted
sl@0
    40
		EVolumeName		= 0x0020, 	// Volume name modified
sl@0
    41
		EDriveName		= 0x0040, 	// Drive name modified
sl@0
    42
		EMediaChange 	= 0x0080, 	// File system mounted/dismounted, media inserted/removed or device formatted
sl@0
    43
		EOverflow		= 0x0100,	// Sent by the file server to notify when a buffer overflow occurs
sl@0
    44
		EAllOps 		= KMaxTUint
sl@0
    45
		};
sl@0
    46
sl@0
    47
	/*
sl@0
    48
	 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
sl@0
    49
	 * completed and before the next call to RequestNotifications. 
sl@0
    50
	 * 
sl@0
    51
	 * @returns the type of notification as TFsNotificationType.
sl@0
    52
	 * @publishedAll
sl@0
    53
	 * @released
sl@0
    54
	 */
sl@0
    55
	IMPORT_C TFsNotificationType NotificationType() const;
sl@0
    56
	
sl@0
    57
	/*
sl@0
    58
	 * Returns via the aPath parameter
sl@0
    59
	 * the path of the file or directory that this notification is notifying about.
sl@0
    60
	 * 
sl@0
    61
	 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
sl@0
    62
	 * completed and before the next call to RequestNotifications. 
sl@0
    63
	 * 
sl@0
    64
	 * @returns KErrNone upon success, otherwise one of the system wide errors
sl@0
    65
	 * @param aPath - TPtrC& which is assigned to the path that was changed as notified by this notification.
sl@0
    66
	 * @publishedAll
sl@0
    67
	 * @released
sl@0
    68
	 */
sl@0
    69
	IMPORT_C TInt Path(TPtrC& aPath) const;
sl@0
    70
	
sl@0
    71
	/*
sl@0
    72
	 * Certain notification types such as Rename, can provide 2 paths.
sl@0
    73
	 * The first path will be the file that has changed, whilst the second path
sl@0
    74
	 * with be the new name. (New filename in the case of rename).
sl@0
    75
	 * 
sl@0
    76
	 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
sl@0
    77
	 * completed and before the next call to RequestNotifications. 
sl@0
    78
	 * 
sl@0
    79
	 * @returns KErrNone upon success, else one of the system wide errors
sl@0
    80
	 * @param aNewName - TPtrC& which is set to the newname as described.
sl@0
    81
	 * @publishedAll
sl@0
    82
	 * @released
sl@0
    83
	 */
sl@0
    84
	IMPORT_C TInt NewName(TPtrC& aNewName) const; 
sl@0
    85
	
sl@0
    86
	/*
sl@0
    87
	 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
sl@0
    88
	 * completed and before the next call to RequestNotifications. 
sl@0
    89
	 * 
sl@0
    90
	 * @returns KErrNone upon success, else one of the system wide error codes
sl@0
    91
	 * @param aSetAtt - In the case of the NotificationType being EAttributes, for the path that was changed
sl@0
    92
	 * 					aSetAtt will return the attributes that were set.
sl@0
    93
	 * @param aClearAtt - In the case of the NotificationType being EAttributes,
sl@0
    94
	 * 					  returns the attributes that were cleared.
sl@0
    95
	 * @publishedAll
sl@0
    96
	 * @released
sl@0
    97
	 */
sl@0
    98
	IMPORT_C TInt Attributes(TUint& aSetAtt,TUint& aClearAtt) const;
sl@0
    99
	
sl@0
   100
	/*
sl@0
   101
	 * In the case of the file size having changed, such as in calls to file write and set size,
sl@0
   102
	 * aSize returns the new size of the file.
sl@0
   103
	 * 
sl@0
   104
	 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
sl@0
   105
	 * completed and before the next call to RequestNotifications. 
sl@0
   106
	 * 
sl@0
   107
	 * @returns KErrNone upon success, else one of the system wide error codes
sl@0
   108
	 * @param aSize - The new size of the file being notified about.
sl@0
   109
	 * @publishedAll
sl@0
   110
	 * @released
sl@0
   111
	 */
sl@0
   112
	IMPORT_C TInt FileSize(TInt64& aSize) const; 
sl@0
   113
sl@0
   114
	/*
sl@0
   115
	 * @returns The Drive Number associated with the Path.
sl@0
   116
	IMPORT_C TInt DriveNumber(TInt& aDriveNumber) const;
sl@0
   117
	 */
sl@0
   118
	
sl@0
   119
	/*
sl@0
   120
	 * @returns the UID of the process that caused this change.
sl@0
   121
	IMPORT_C TInt UID(TUid& aUID) const;
sl@0
   122
	 */
sl@0
   123
private:
sl@0
   124
	//Declared private to prevent construction
sl@0
   125
	TFsNotification();
sl@0
   126
	~TFsNotification();
sl@0
   127
	//To prevent copying.  No implementation is provided.
sl@0
   128
	TFsNotification& operator=(TFsNotification& aNotification);
sl@0
   129
	
sl@0
   130
	TInt PathSize() const;
sl@0
   131
	TInt NewNameSize() const;
sl@0
   132
	TInt NotificationSize() const;
sl@0
   133
sl@0
   134
	friend class CFsNotify;
sl@0
   135
	friend class CFsNotificationList;
sl@0
   136
	};
sl@0
   137
sl@0
   138
class RFsNotify; //incomplete decl
sl@0
   139
class CFsNotifyBody; //incomplete decl
sl@0
   140
sl@0
   141
/*
sl@0
   142
 * CFsNotify is a class which allows changes to file and directories to be monitored
sl@0
   143
 *
sl@0
   144
 * The notification framework supported by CFsNotify is able to keep track of multiple notifications,
sl@0
   145
 * whilst ensuring that notifications cannot be missed (unlike RFs::NotifyChange which can miss changes).
sl@0
   146
 *
sl@0
   147
 * CFsNotify encapsulates the client-side sub-session associated with
sl@0
   148
 * the file server notification framework.
sl@0
   149
 * 
sl@0
   150
 * In order to recieve notifications of changes to a file system, a 
sl@0
   151
 * client may use this class in order to set up notification 'filters' and
sl@0
   152
 * request notifications.
sl@0
   153
 * 
sl@0
   154
 * Filters can be set for specific types of operations on specific (and wildcard) paths.
sl@0
   155
 * 
sl@0
   156
 * The difference between using this framework and RFs::NotifyChange is that
sl@0
   157
 * this framework will provide significant performance improvements, especially so
sl@0
   158
 * when operating on a large number of files.
sl@0
   159
 * 
sl@0
   160
 * In addition, this framework will provide verbose information about each
sl@0
   161
 * change that occurs, meaning that from a user's perspective they no longer have
sl@0
   162
 * to perform expensive directory scans in order to acertain what has changed.
sl@0
   163
 *
sl@0
   164
 * Notifications can also provide additional information:
sl@0
   165
 * EFileChange provides the new file size
sl@0
   166
 * ERename provide the new name of the affected file.
sl@0
   167
 * EDriveName/EVolumeName provides the name of the drive which has changed
sl@0
   168
 * EAttribute provides the attributes which were set and cleared on the affected file. 
sl@0
   169
 * 
sl@0
   170
 * @publishedAll
sl@0
   171
 * @released
sl@0
   172
 */
sl@0
   173
class CFsNotify : public CBase
sl@0
   174
	{
sl@0
   175
	public:
sl@0
   176
		
sl@0
   177
		/*
sl@0
   178
		 * Factory function. Creates a new CFsNotify and returns a pointer to it.
sl@0
   179
		 *
sl@0
   180
		 * CFsNotify stores notifications in a buffer. 
sl@0
   181
		 * Clients of CFsNotify must specify how large this buffer should be.
sl@0
   182
		 * 
sl@0
   183
		 * As a guideline: Notification objects in the buffer typically have a 8byte header,
sl@0
   184
		 * followed by a word aligned string containing the fullname of the file that has changed.
sl@0
   185
		 * In the case of a rename notification both the original and the new fullnames are stored.
sl@0
   186
		 *
sl@0
   187
		 * However, clients must not assume to know the exact size of notifications when determining the size of their buffer,
sl@0
   188
		 * as it is not possible to know how often a client will be able to read the notifications from the buffer.
sl@0
   189
		 * In addition, if further notification types are added, then the header size or maximum data could increase.
sl@0
   190
		 * 
sl@0
   191
		 * Thus, clients must ensure that their notification handling code appropriately deals with an overflow notification, whereby the
sl@0
   192
		 * buffer was not large enough to store all of the notifications.
sl@0
   193
		 *
sl@0
   194
		 * If aBufferSize is greater than (KMaxTInt/2) then it will return KErrArgument.
sl@0
   195
		 * If aBufferSize is less than KMinNotificationBufferSize (which is an internal constant but is approximately equal to 1KB) then aBufferSize will be 
sl@0
   196
		 * set to KMinNotificationBufferSize.
sl@0
   197
		 * 
sl@0
   198
		 * @param aFs - RFs session. Must be connected.
sl@0
   199
		 * @param aBufferSize  - Size of buffer in which to store notification objects.
sl@0
   200
		 * @return CFsNotify* - Pointer to newly created CFsNotify.
sl@0
   201
		 * @publishedAll
sl@0
   202
		 * @released
sl@0
   203
		 */
sl@0
   204
		IMPORT_C static CFsNotify* NewL(RFs& aFs, TInt aBufferSize);
sl@0
   205
		
sl@0
   206
		/*
sl@0
   207
		 * CFsNotify Destructor.
sl@0
   208
		 * @publishedAll
sl@0
   209
		 * @released
sl@0
   210
		 */
sl@0
   211
		IMPORT_C virtual ~CFsNotify();
sl@0
   212
sl@0
   213
		/*
sl@0
   214
		 * Clients are able to set-up notifications for changes based on Notification filters.
sl@0
   215
		 * 
sl@0
   216
		 * Filters can be set according to the type of notification required and the path to monitor.
sl@0
   217
		 * Notification types are set up as a bitmask of TFsNotification::TNotificationType.
sl@0
   218
		 * 		e.g.  (TUint) TFsNotification::ECreate | TFsNotification::EFileChange
sl@0
   219
		 * 
sl@0
   220
		 * So long as clients have filters set for a particular drive, they will automatically
sl@0
   221
		 * receive TFsNotification::EMediaChange notifications regardless 
sl@0
   222
		 * of whether they are registered for EMediaChange or not.
sl@0
   223
		 * This notification can be caused by media card removal, the file system being dismounted or 
sl@0
   224
		 * the media being formatted.
sl@0
   225
		 *
sl@0
   226
		 * If clients set the EOverflow notification type then AddNotification will return an error.
sl@0
   227
		 * The exception to this is when using EAllOps which is used as a convenience notification type
sl@0
   228
		 * which matches all of the notification types.
sl@0
   229
		 * 
sl@0
   230
		 * aPath specifies which path should be monitored for changes.
sl@0
   231
		 * aFilename specifies which filename should be monitored for changes.
sl@0
   232
		 * 
sl@0
   233
		 * Either aPath or aFilename may be zero-length strings:
sl@0
   234
		 * 	If you want to match a specific filename in every directory, you can leave aPath blank.
sl@0
   235
		 *	Leaving aFilename blank results in matching against aPath only (i.e. a directory).
sl@0
   236
		 * 
sl@0
   237
		 * '*' and '?' wild cards are allowed in the path and filename.
sl@0
   238
		 * 
sl@0
   239
		 * To match against:
sl@0
   240
		 * Specified directory only : (This is the specified directly only, not its contents.)
sl@0
   241
		 * 		- aPath 	== drive:\\[path\\]directory\\
sl@0
   242
		 * 		  aFilename == 					(zero length descriptor)
sl@0
   243
		 *
sl@0
   244
		 * Specified file only : 
sl@0
   245
		 * 		- aPath		== drive:\\[path\\]directory\\
sl@0
   246
		 * 		  aFilename == file.txt (or *, *.*, or *.txt)
sl@0
   247
		 *
sl@0
   248
		 * To enable matching against directories recursively:
sl@0
   249
		 * 		- aPath		== drive:\\[path\\]directory\\*    (NB: trailing * denotes directory recursion)
sl@0
   250
		 * 		- aFilename == file.txt (or *, *.*, or *.txt)
sl@0
   251
		 *
sl@0
   252
		 * 
sl@0
   253
		 * @param aNotificationType - A Bitmask of the type of change to be monitored for based on the values of TFsNotification::TNotifyType
sl@0
   254
		 * @param aPath - The directory to monitor
sl@0
   255
		 * @param aFilename - The filename to monitor
sl@0
   256
		 * @return KErrNone upon success, else one of the system wide error codes
sl@0
   257
		 * @publishedAll
sl@0
   258
		 * @released 
sl@0
   259
		 */
sl@0
   260
		IMPORT_C TInt AddNotification(TUint aNotificationType, const TDesC& aPath, const TDesC& aFilename);
sl@0
   261
		
sl@0
   262
		/*
sl@0
   263
		 * Remove Notifications will remove all of the filters that have been 
sl@0
   264
		 * set by calls to AddNotification.
sl@0
   265
		 * 
sl@0
   266
		 * This does not cancel any ongoing requests, but any on going requests will not complete until
sl@0
   267
		 * filters have been added via calls to AddNotification
sl@0
   268
		 * @return KErrNone or a system-wide error code.
sl@0
   269
		 * @publishedAll
sl@0
   270
		 * @released
sl@0
   271
		 */
sl@0
   272
		IMPORT_C TInt RemoveNotifications();
sl@0
   273
		
sl@0
   274
		/*
sl@0
   275
		 * This is an Asynchronous function.
sl@0
   276
		 * 
sl@0
   277
		 * RequestNotification will issue a notification request asynchronously.
sl@0
   278
		 * When this request has completed, aStatus's value will be set something other than KRequestPending.
sl@0
   279
		 * 
sl@0
   280
		 * Completion means that at least 1 notification has been put in the notification buffer.
sl@0
   281
		 * Clients should call NextNotification() until it returns NULL.
sl@0
   282
		 * 
sl@0
   283
		 * When all the notifications have been read, the client should call RequestNotifications to set up another request.
sl@0
   284
		 * 
sl@0
   285
		 * Notifications will continue to be stored by the file server 
sl@0
   286
		 * until CancelNotifications is called, meaning that notifications that occur 
sl@0
   287
		 * whilst the client is processing the current notifications are not lost.
sl@0
   288
		 * @param aStatus - A TRequestStatus that shall be completed when the Asynchronous request is completed.
sl@0
   289
		 * @return KErrNone or a system-wide error code.
sl@0
   290
		 * @publishedAll
sl@0
   291
		 * @released
sl@0
   292
		 */
sl@0
   293
		IMPORT_C TInt RequestNotifications(TRequestStatus& aStatus);
sl@0
   294
		
sl@0
   295
		/*
sl@0
   296
		 * Cancels the outstanding Asynchronous notification request that was set up
sl@0
   297
		 * in the call to RequestNotifications.
sl@0
   298
		 * @param aStatus - The TRequestStatus that was used in the call to RequestNotification
sl@0
   299
		 * @return KErrNone or a system-wide error code.
sl@0
   300
		 * @publishedAll
sl@0
   301
		 * @released
sl@0
   302
		 */
sl@0
   303
		IMPORT_C TInt CancelNotifications(TRequestStatus& aStatus);
sl@0
   304
		
sl@0
   305
		/*
sl@0
   306
		 * Once a notification request has completed, the client should call
sl@0
   307
		 * NextNotification in order to access the notifications that have been stored in a notification buffer.
sl@0
   308
		 * 
sl@0
   309
		 * NextNotification returns a pointer to a TFsNotification. Each TFsNotification
sl@0
   310
		 * represents a single notification.
sl@0
   311
		 * 
sl@0
   312
		 * When NULL is returned, there are no more Notifications to read and RequestNotification must be called.
sl@0
   313
		 * 
sl@0
   314
		 * @return const TFsNotification* - A pointer to a notification
sl@0
   315
		 * @publishedAll
sl@0
   316
		 * @released
sl@0
   317
		 */
sl@0
   318
		IMPORT_C const TFsNotification * NextNotification();
sl@0
   319
		
sl@0
   320
	private:
sl@0
   321
		// Allocates buffer.
sl@0
   322
		void ConstructL(RFs& aFs,TInt aBufferSize);
sl@0
   323
		CFsNotify();
sl@0
   324
sl@0
   325
		//Hide internals
sl@0
   326
		CFsNotifyBody* iBody;
sl@0
   327
		
sl@0
   328
		friend class RFsNotify;
sl@0
   329
		};
sl@0
   330
sl@0
   331
#endif //__F32NOTIFICATION_H__
sl@0
   332