Update contrib.
1 // Copyright (c) 1995-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // fileserver/inc/f32notification.h
17 #ifndef __F32NOTIFICATION_H__
18 #define __F32NOTIFICATION_H__
21 * This class is not intended for instantiation neither on the stack
24 * Clients wishing to use this class should use a pointer provided by
25 * CFsNotify::NextNotification().
33 enum TFsNotificationType
35 EFileChange = 0x0001, // File contents have changed or/and file has changed size
36 ERename = 0x0002, // File/directory renamed, or file replaced using RFs::Replace()
37 ECreate = 0x0004, // File/directory created, or file recreated using RFile::Replace()
38 EAttribute = 0x0008, // File attribute(s) changed
39 EDelete = 0x0010, // File/directory deleted
40 EVolumeName = 0x0020, // Volume name modified
41 EDriveName = 0x0040, // Drive name modified
42 EMediaChange = 0x0080, // File system mounted/dismounted, media inserted/removed or device formatted
43 EOverflow = 0x0100, // Sent by the file server to notify when a buffer overflow occurs
48 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
49 * completed and before the next call to RequestNotifications.
51 * @returns the type of notification as TFsNotificationType.
55 IMPORT_C TFsNotificationType NotificationType() const;
58 * Returns via the aPath parameter
59 * the path of the file or directory that this notification is notifying about.
61 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
62 * completed and before the next call to RequestNotifications.
64 * @returns KErrNone upon success, otherwise one of the system wide errors
65 * @param aPath - TPtrC& which is assigned to the path that was changed as notified by this notification.
69 IMPORT_C TInt Path(TPtrC& aPath) const;
72 * Certain notification types such as Rename, can provide 2 paths.
73 * The first path will be the file that has changed, whilst the second path
74 * with be the new name. (New filename in the case of rename).
76 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
77 * completed and before the next call to RequestNotifications.
79 * @returns KErrNone upon success, else one of the system wide errors
80 * @param aNewName - TPtrC& which is set to the newname as described.
84 IMPORT_C TInt NewName(TPtrC& aNewName) const;
87 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
88 * completed and before the next call to RequestNotifications.
90 * @returns KErrNone upon success, else one of the system wide error codes
91 * @param aSetAtt - In the case of the NotificationType being EAttributes, for the path that was changed
92 * aSetAtt will return the attributes that were set.
93 * @param aClearAtt - In the case of the NotificationType being EAttributes,
94 * returns the attributes that were cleared.
98 IMPORT_C TInt Attributes(TUint& aSetAtt,TUint& aClearAtt) const;
101 * In the case of the file size having changed, such as in calls to file write and set size,
102 * aSize returns the new size of the file.
104 * Any data returned is only valid after the previous asynchronous call to RequestNotifications has
105 * completed and before the next call to RequestNotifications.
107 * @returns KErrNone upon success, else one of the system wide error codes
108 * @param aSize - The new size of the file being notified about.
112 IMPORT_C TInt FileSize(TInt64& aSize) const;
115 * @returns The Drive Number associated with the Path.
116 IMPORT_C TInt DriveNumber(TInt& aDriveNumber) const;
120 * @returns the UID of the process that caused this change.
121 IMPORT_C TInt UID(TUid& aUID) const;
124 //Declared private to prevent construction
127 //To prevent copying. No implementation is provided.
128 TFsNotification& operator=(TFsNotification& aNotification);
130 TInt PathSize() const;
131 TInt NewNameSize() const;
132 TInt NotificationSize() const;
134 friend class CFsNotify;
135 friend class CFsNotificationList;
138 class RFsNotify; //incomplete decl
139 class CFsNotifyBody; //incomplete decl
142 * CFsNotify is a class which allows changes to file and directories to be monitored
144 * The notification framework supported by CFsNotify is able to keep track of multiple notifications,
145 * whilst ensuring that notifications cannot be missed (unlike RFs::NotifyChange which can miss changes).
147 * CFsNotify encapsulates the client-side sub-session associated with
148 * the file server notification framework.
150 * In order to recieve notifications of changes to a file system, a
151 * client may use this class in order to set up notification 'filters' and
152 * request notifications.
154 * Filters can be set for specific types of operations on specific (and wildcard) paths.
156 * The difference between using this framework and RFs::NotifyChange is that
157 * this framework will provide significant performance improvements, especially so
158 * when operating on a large number of files.
160 * In addition, this framework will provide verbose information about each
161 * change that occurs, meaning that from a user's perspective they no longer have
162 * to perform expensive directory scans in order to acertain what has changed.
164 * Notifications can also provide additional information:
165 * EFileChange provides the new file size
166 * ERename provide the new name of the affected file.
167 * EDriveName/EVolumeName provides the name of the drive which has changed
168 * EAttribute provides the attributes which were set and cleared on the affected file.
173 class CFsNotify : public CBase
178 * Factory function. Creates a new CFsNotify and returns a pointer to it.
180 * CFsNotify stores notifications in a buffer.
181 * Clients of CFsNotify must specify how large this buffer should be.
183 * As a guideline: Notification objects in the buffer typically have a 8byte header,
184 * followed by a word aligned string containing the fullname of the file that has changed.
185 * In the case of a rename notification both the original and the new fullnames are stored.
187 * However, clients must not assume to know the exact size of notifications when determining the size of their buffer,
188 * as it is not possible to know how often a client will be able to read the notifications from the buffer.
189 * In addition, if further notification types are added, then the header size or maximum data could increase.
191 * Thus, clients must ensure that their notification handling code appropriately deals with an overflow notification, whereby the
192 * buffer was not large enough to store all of the notifications.
194 * If aBufferSize is greater than (KMaxTInt/2) then it will return KErrArgument.
195 * If aBufferSize is less than KMinNotificationBufferSize (which is an internal constant but is approximately equal to 1KB) then aBufferSize will be
196 * set to KMinNotificationBufferSize.
198 * @param aFs - RFs session. Must be connected.
199 * @param aBufferSize - Size of buffer in which to store notification objects.
200 * @return CFsNotify* - Pointer to newly created CFsNotify.
204 IMPORT_C static CFsNotify* NewL(RFs& aFs, TInt aBufferSize);
207 * CFsNotify Destructor.
211 IMPORT_C virtual ~CFsNotify();
214 * Clients are able to set-up notifications for changes based on Notification filters.
216 * Filters can be set according to the type of notification required and the path to monitor.
217 * Notification types are set up as a bitmask of TFsNotification::TNotificationType.
218 * e.g. (TUint) TFsNotification::ECreate | TFsNotification::EFileChange
220 * So long as clients have filters set for a particular drive, they will automatically
221 * receive TFsNotification::EMediaChange notifications regardless
222 * of whether they are registered for EMediaChange or not.
223 * This notification can be caused by media card removal, the file system being dismounted or
224 * the media being formatted.
226 * If clients set the EOverflow notification type then AddNotification will return an error.
227 * The exception to this is when using EAllOps which is used as a convenience notification type
228 * which matches all of the notification types.
230 * aPath specifies which path should be monitored for changes.
231 * aFilename specifies which filename should be monitored for changes.
233 * Either aPath or aFilename may be zero-length strings:
234 * If you want to match a specific filename in every directory, you can leave aPath blank.
235 * Leaving aFilename blank results in matching against aPath only (i.e. a directory).
237 * '*' and '?' wild cards are allowed in the path and filename.
240 * Specified directory only : (This is the specified directly only, not its contents.)
241 * - aPath == drive:\\[path\\]directory\\
242 * aFilename == (zero length descriptor)
244 * Specified file only :
245 * - aPath == drive:\\[path\\]directory\\
246 * aFilename == file.txt (or *, *.*, or *.txt)
248 * To enable matching against directories recursively:
249 * - aPath == drive:\\[path\\]directory\\* (NB: trailing * denotes directory recursion)
250 * - aFilename == file.txt (or *, *.*, or *.txt)
253 * @param aNotificationType - A Bitmask of the type of change to be monitored for based on the values of TFsNotification::TNotifyType
254 * @param aPath - The directory to monitor
255 * @param aFilename - The filename to monitor
256 * @return KErrNone upon success, else one of the system wide error codes
260 IMPORT_C TInt AddNotification(TUint aNotificationType, const TDesC& aPath, const TDesC& aFilename);
263 * Remove Notifications will remove all of the filters that have been
264 * set by calls to AddNotification.
266 * This does not cancel any ongoing requests, but any on going requests will not complete until
267 * filters have been added via calls to AddNotification
268 * @return KErrNone or a system-wide error code.
272 IMPORT_C TInt RemoveNotifications();
275 * This is an Asynchronous function.
277 * RequestNotification will issue a notification request asynchronously.
278 * When this request has completed, aStatus's value will be set something other than KRequestPending.
280 * Completion means that at least 1 notification has been put in the notification buffer.
281 * Clients should call NextNotification() until it returns NULL.
283 * When all the notifications have been read, the client should call RequestNotifications to set up another request.
285 * Notifications will continue to be stored by the file server
286 * until CancelNotifications is called, meaning that notifications that occur
287 * whilst the client is processing the current notifications are not lost.
288 * @param aStatus - A TRequestStatus that shall be completed when the Asynchronous request is completed.
289 * @return KErrNone or a system-wide error code.
293 IMPORT_C TInt RequestNotifications(TRequestStatus& aStatus);
296 * Cancels the outstanding Asynchronous notification request that was set up
297 * in the call to RequestNotifications.
298 * @param aStatus - The TRequestStatus that was used in the call to RequestNotification
299 * @return KErrNone or a system-wide error code.
303 IMPORT_C TInt CancelNotifications(TRequestStatus& aStatus);
306 * Once a notification request has completed, the client should call
307 * NextNotification in order to access the notifications that have been stored in a notification buffer.
309 * NextNotification returns a pointer to a TFsNotification. Each TFsNotification
310 * represents a single notification.
312 * When NULL is returned, there are no more Notifications to read and RequestNotification must be called.
314 * @return const TFsNotification* - A pointer to a notification
318 IMPORT_C const TFsNotification * NextNotification();
322 void ConstructL(RFs& aFs,TInt aBufferSize);
326 CFsNotifyBody* iBody;
328 friend class RFsNotify;
331 #endif //__F32NOTIFICATION_H__