|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <pathinfo.h> |
|
21 |
|
22 #include "cfilemonitor.h" |
|
23 #include "cfolderrenamedharvester.h" |
|
24 #include "harvesterserverlogger.h" |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CFileMonitor::NewL |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CFileMonitor* CFileMonitor::NewL( CFilePlugin& aFilePlugin, RFs* aFsSession ) |
|
31 { |
|
32 CFileMonitor* self = new ( ELeave ) CFileMonitor( aFilePlugin, aFsSession ); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(aFilePlugin, aFsSession); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CFileMonitor::CFileMonitor |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CFileMonitor::CFileMonitor( CFilePlugin& aFilePlugin, RFs* aFsSession ) : |
|
44 CActive(CActive::EPriorityStandard), |
|
45 iFilePlugin( aFilePlugin ) |
|
46 { |
|
47 CPIXLOGSTRING("ENTER CFileMonitor::CFileMonitor"); |
|
48 CActiveScheduler::Add(this); |
|
49 iFsSession = aFsSession; |
|
50 CPIXLOGSTRING("END CFileMonitor::CFileMonitor"); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CFileMonitor::~CFileMonitor |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CFileMonitor::~CFileMonitor() |
|
58 { |
|
59 CPIXLOGSTRING("ENTER ~CFileMonitor"); |
|
60 Cancel(); |
|
61 iEngine.Disable(); |
|
62 iEngine.Close(); |
|
63 delete iFolderRenamedHarvester; |
|
64 CPIXLOGSTRING("END ~CFileMonitor"); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CFileMonitor::ConstructL |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CFileMonitor::ConstructL( CFilePlugin& aFilePlugin, RFs* aFsSession ) |
|
72 { |
|
73 iFolderRenamedHarvester = CFolderRenamedHarvester::NewL(aFilePlugin, *aFsSession); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CFileMonitor::RunError |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 TInt CFileMonitor::RunError( TInt aError ) |
|
81 { |
|
82 CPIXLOGSTRING2( "CFileMonitor::RunError %d", aError ); |
|
83 return KErrNone; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CFileMonitor::DoCancel |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CFileMonitor::DoCancel() |
|
91 { |
|
92 iEngine.NotificationCancel(); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CFileMonitor::RunL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CFileMonitor::RunL() |
|
100 { |
|
101 CPIXLOGSTRING("ENTER CFileMonitor::RunL"); |
|
102 Deque(); |
|
103 CActiveScheduler::Add( this ); |
|
104 |
|
105 /* |
|
106 Handle pkg here |
|
107 It has event type and other stuff |
|
108 Execute event and pass params to FilePlugin |
|
109 */ |
|
110 |
|
111 // TODO TFileName on stack twice - consider allocating on heap! |
|
112 TFastFindFSPStatus& status = iPckg(); |
|
113 const TDesC& fileNameOld = status.iFileName; |
|
114 const TDesC& fileNameNew = status.iNewFileName; |
|
115 |
|
116 /* |
|
117 * IMPORTANT: |
|
118 * Rename of whole directory happens as change to every file in dir. |
|
119 * We get an event of every file in dir. |
|
120 */ |
|
121 CPIXLOGSTRING2("CFileMonitor::RunL, status.iFileEventType: %i", status.iFileEventType ); |
|
122 switch(status.iFileEventType) |
|
123 { |
|
124 case EFastFindFileCreated: |
|
125 { |
|
126 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileCreated old = %S", &fileNameOld); |
|
127 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileCreated new = %S", &fileNameNew); |
|
128 // File creation (for example over PC suite) gives fileNameOld as the created files, fileNameOld is empty. |
|
129 iFilePlugin.CreateFileIndexItemL(fileNameOld, ECPixAddAction); |
|
130 } |
|
131 break; |
|
132 |
|
133 case EFastFindFileModified: |
|
134 { |
|
135 // This event can be generated by some file manager applications |
|
136 // when copying a file to a new destination. |
|
137 // Introduce a small delay, so that file copying can complete before |
|
138 // cpix opens the file for indexing. Without the delay, sometimes file |
|
139 // indexing fails as CLucene cannot open the file for indexing. |
|
140 |
|
141 // Decided to block the CPiXHarvesterServer thread rather than introduce |
|
142 // new active object state into the CFileMonitor. |
|
143 User::After(50000); // 0.05 seconds |
|
144 |
|
145 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileModified old = %S", &fileNameOld); |
|
146 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileModified new = %S", &fileNameNew); |
|
147 // File copy, fileNameOld contains the file name, fileNameNew is empty |
|
148 iFilePlugin.CreateFileIndexItemL(fileNameOld, ECPixUpdateAction); |
|
149 } |
|
150 break; |
|
151 |
|
152 case EFastFindFileRenamed: |
|
153 { |
|
154 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileRenamed old = %S", &fileNameOld); |
|
155 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileRenamed new = %S", &fileNameNew); |
|
156 TEntry entry; |
|
157 if ( iFsSession->Entry( fileNameNew, entry ) == KErrNone ) |
|
158 { |
|
159 if ( !entry.IsDir() ) |
|
160 { |
|
161 if (fileNameOld.Length()>0 && fileNameOld.Compare(fileNameNew)!=0) |
|
162 { |
|
163 iFilePlugin.CreateFileIndexItemL(fileNameOld, ECPixRemoveAction); |
|
164 } |
|
165 iFilePlugin.CreateFileIndexItemL(fileNameNew, ECPixUpdateAction); |
|
166 } |
|
167 else |
|
168 { |
|
169 iFolderRenamedHarvester->StartL(fileNameOld, fileNameNew); |
|
170 } |
|
171 } |
|
172 } |
|
173 break; |
|
174 |
|
175 case EFastFindFileReplaced: |
|
176 { |
|
177 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileReplaced old = %S", &fileNameOld); |
|
178 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileReplaced new = %S", &fileNameNew); |
|
179 // File rename (funnily), fileNameOld contains the old file name, fileNameNew the new name |
|
180 if (fileNameOld.Length()>0 && fileNameOld.Compare(fileNameNew)!=0) |
|
181 iFilePlugin.CreateFileIndexItemL(fileNameOld, ECPixRemoveAction); |
|
182 iFilePlugin.CreateFileIndexItemL(fileNameNew, ECPixUpdateAction); |
|
183 } |
|
184 break; |
|
185 |
|
186 case EFastFindFileDeleted: |
|
187 { |
|
188 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileDeleted old = %S", &fileNameOld); |
|
189 CPIXLOGSTRING2("CFileMonitor::RunL, EFastFindFileDeleted new = %S", &fileNameNew); |
|
190 // File delete, fileNameOld contains the name of the deleted file |
|
191 iFilePlugin.CreateFileIndexItemL(fileNameOld, ECPixRemoveAction); |
|
192 } |
|
193 break; |
|
194 |
|
195 default: |
|
196 { |
|
197 CPIXLOGSTRING2("CFileMonitor::RunL, unknown event old = %S", &fileNameOld); |
|
198 CPIXLOGSTRING2("CFileMonitor::RunL, unknown event new = %S", &fileNameNew); |
|
199 } |
|
200 break; |
|
201 } |
|
202 ResetStatus(); |
|
203 iEngine.RegisterNotification(iPckg, iStatus); |
|
204 CPIXLOGSTRING("END CFileMonitor::RunL"); |
|
205 SetActive(); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CFileMonitor::StartMonitoring |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CFileMonitor::StartMonitoring() |
|
213 { |
|
214 CPIXLOGSTRING("ENTER CFileMonitor::StartMonitoring") |
|
215 |
|
216 if ( !IsActive() ) |
|
217 { |
|
218 CPIXLOGSTRING("CFileMonitor::StartMonitoring - IF ") |
|
219 iEngine.Enable(); |
|
220 ResetStatus(); |
|
221 iEngine.RegisterNotification( iPckg, iStatus ); |
|
222 SetActive(); |
|
223 } |
|
224 |
|
225 CPIXLOGSTRING("END CFileMonitor::StartMonitoring"); |
|
226 |
|
227 return ETrue; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CFileMonitor::ResetStatus |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CFileMonitor::ResetStatus() |
|
235 { |
|
236 CPIXLOGSTRING( "CFileMonitor::ResetStatus" ); |
|
237 |
|
238 TFastFindFSPStatus& status = iPckg(); |
|
239 |
|
240 status.iDriveNumber = 0; |
|
241 status.iFileEventType = EFastFindFileUnknown; |
|
242 status.iFileName.Zero(); |
|
243 status.iNewFileName.Zero(); |
|
244 status.iProcessId = TUid::Null(); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CFileMonitor::Initialize |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CFileMonitor::Initialize() |
|
252 { |
|
253 CPIXLOGSTRING("ENTER CFileMonitor::Initialize"); |
|
254 TInt err = OpenEngine(); |
|
255 CPIXLOGSTRING2("CFileMonitor::Initialize - OpenEngine: %i", err ); |
|
256 if ( err != KErrNone ) |
|
257 { |
|
258 CPIXLOGSTRING("CFileMonitor::Initialize if( err != KErrNone ) "); |
|
259 return err; |
|
260 } |
|
261 |
|
262 CPIXLOGSTRING("END CFileMonitor::Initialize"); |
|
263 return err; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CFileMonitor::Release |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 TInt CFileMonitor::Release() |
|
271 { |
|
272 iEngine.Disable(); |
|
273 iEngine.Close(); |
|
274 |
|
275 return KErrNone; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CFileMonitor::OpenEngine |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 TInt CFileMonitor::OpenEngine() |
|
283 { |
|
284 TInt err = iEngine.Open( *iFsSession, KFastFindFSPluginPosition ); |
|
285 return err; |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CFileMonitor::AddNotificationPathsL |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 void CFileMonitor::AddNotificationPathsL( const TDriveNumber aDriveNumber ) |
|
293 { |
|
294 TFileName notificationPath; |
|
295 TChar chr; |
|
296 User::LeaveIfError( RFs::DriveToChar( aDriveNumber, chr ) ); |
|
297 |
|
298 notificationPath.Append( chr ); |
|
299 notificationPath.Append( KExcludePathSystem ); |
|
300 iEngine.AddIgnorePath( notificationPath ); |
|
301 CPIXLOGSTRING2("CFileMonitor::AddNotificationPathsL - AddIgnorePath: %S", ¬ificationPath ); |
|
302 |
|
303 notificationPath.Zero(); |
|
304 |
|
305 // As index databases are located under \\Private\\ path, |
|
306 // this ignore path will mean index databases are also ignored. |
|
307 notificationPath.Append( chr ); |
|
308 notificationPath.Append( KExcludePathPrivate ); |
|
309 iEngine.AddIgnorePath( notificationPath ); |
|
310 CPIXLOGSTRING2("CFileMonitor::AddNotificationPathsL - AddIgnorePath: %S", ¬ificationPath ); |
|
311 |
|
312 notificationPath.Zero(); |
|
313 |
|
314 // Maps data must not be indexed |
|
315 notificationPath.Append( chr ); |
|
316 notificationPath.Append( KExcludePathMapsCities ); |
|
317 iEngine.AddIgnorePath( notificationPath ); |
|
318 CPIXLOGSTRING2("CFileMonitor::AddNotificationPathsL - AddIgnorePath: %S", ¬ificationPath ); |
|
319 |
|
320 notificationPath.Zero(); |
|
321 |
|
322 User::LeaveIfError( PathInfo::GetRootPath( notificationPath, aDriveNumber ) ); |
|
323 iEngine.AddNotificationPath( notificationPath ); |
|
324 CPIXLOGSTRING2("CFileMonitor::AddNotificationPathsL - AddNotificationPath: %S", ¬ificationPath ); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CFileMonitor::RemoveNotificationPaths |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CFileMonitor::RemoveNotificationPaths( const TDriveNumber aDriveNumber ) |
|
332 { |
|
333 TFileName ignorePath; |
|
334 TChar chr; |
|
335 RFs::DriveToChar( aDriveNumber, chr ); |
|
336 |
|
337 ignorePath.Append( chr ); |
|
338 ignorePath.Append( KExcludePathSystem ); |
|
339 iEngine.RemoveIgnorePath( ignorePath ); |
|
340 CPIXLOGSTRING2("CFileMonitor::RemoveNotificationPaths - RemoveIgnorePath: %S", &ignorePath ); |
|
341 |
|
342 ignorePath.Zero(); |
|
343 |
|
344 // As index databases are located under \\Private\\ path, |
|
345 // this ignore path will mean index databases are also ignored. |
|
346 ignorePath.Append( chr ); |
|
347 ignorePath.Append( KExcludePathPrivate ); |
|
348 iEngine.RemoveIgnorePath( ignorePath ); |
|
349 CPIXLOGSTRING2("CFileMonitor::RemoveNotificationPaths - RemoveIgnorePath: %S", &ignorePath ); |
|
350 |
|
351 ignorePath.Zero(); |
|
352 |
|
353 // Maps |
|
354 ignorePath.Append( chr ); |
|
355 ignorePath.Append( KExcludePathMapsCities ); |
|
356 iEngine.RemoveIgnorePath( ignorePath ); |
|
357 CPIXLOGSTRING2("CFileMonitor::RemoveNotificationPaths - RemoveIgnorePath: %S", &ignorePath ); |
|
358 |
|
359 ignorePath.Zero(); |
|
360 |
|
361 PathInfo::GetRootPath( ignorePath, aDriveNumber ); |
|
362 iEngine.RemoveNotificationPath( ignorePath ); |
|
363 CPIXLOGSTRING2("CFileMonitor::RemoveNotificationPaths - RemoveNotificationPath: %S", &ignorePath ); |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CFileMonitor::Enable |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 TInt CFileMonitor::Enable() |
|
371 { |
|
372 return iEngine.Enable(); |
|
373 } |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // CFileMonitor::Disable |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CFileMonitor::Disable() |
|
380 { |
|
381 return iEngine.Disable(); |
|
382 } |
|
383 |
|
384 // End Of File |