|
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 <e32base.h> |
|
20 #include <ccpixindexer.h> |
|
21 #include <csearchdocument.h> |
|
22 #include <QtGlobal> |
|
23 #include "cemailplugin.h" |
|
24 #include "harvesterserverlogger.h" |
|
25 #include "qtemailfetcher.h" |
|
26 |
|
27 // maximum length that the fully qualified msg Plugin base app class descriptor can be |
|
28 // e.g. "@c:root msg email" |
|
29 const TInt KMsgPluginBaseAppClassMaxLen = 64; |
|
30 |
|
31 |
|
32 // local declarations and functions |
|
33 namespace { |
|
34 |
|
35 _LIT(KCPixSearchServerPrivateDirectory, "\\Private\\2001f6f7\\"); |
|
36 _LIT(KPathIndexDbPath, CPIX_INDEVICE_INDEXDB); |
|
37 |
|
38 _LIT(KPathTrailer, "\\root\\msg\\email"); |
|
39 _LIT(KMsgBaseAppClassGeneric, ":root msg email"); |
|
40 _LIT(KAtSign, "@"); |
|
41 _LIT(KColon, ":"); |
|
42 |
|
43 /** |
|
44 * MapFileToDrive - gets the TDriveNumber associated with the aBaseAppClass. |
|
45 * @aBaseAppClass e.g. "@c:root file" |
|
46 * @aDrive returns the TDriveNumber for the aBaseAppClass |
|
47 * returns KErrNone on success or a standard error code |
|
48 */ |
|
49 TInt MapBaseAppClassToDrive(const TDesC& aBaseAppClass, TDriveNumber& aDrive) |
|
50 { |
|
51 if (KErrNone != aBaseAppClass.Left(1).Compare(KAtSign)) |
|
52 { |
|
53 return KErrGeneral; |
|
54 } |
|
55 |
|
56 TPtrC drvChar = aBaseAppClass.Left(2).Right(1); |
|
57 TChar d(drvChar[0]); |
|
58 TInt drive; |
|
59 const TInt ret = RFs::CharToDrive(d, drive); |
|
60 if (!ret) |
|
61 { |
|
62 aDrive = TDriveNumber(drive); |
|
63 } |
|
64 |
|
65 return ret; |
|
66 } |
|
67 |
|
68 }// anonymous namespace |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CEmailPlugin::NewL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CEmailPlugin* CEmailPlugin::NewL() |
|
76 { |
|
77 CEmailPlugin* instance = CEmailPlugin::NewLC(); |
|
78 CleanupStack::Pop(instance); |
|
79 return instance; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CEmailPlugin::NewLC |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CEmailPlugin* CEmailPlugin::NewLC() |
|
87 { |
|
88 CEmailPlugin* instance = new (ELeave)CEmailPlugin(); |
|
89 CleanupStack::PushL(instance); |
|
90 instance->ConstructL(); |
|
91 return instance; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CEmailPlugin::CEmailPlugin |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 CEmailPlugin::CEmailPlugin() |
|
99 { |
|
100 |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CEmailPlugin::~CEmailPlugin |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 CEmailPlugin::~CEmailPlugin() |
|
108 { |
|
109 // remove notification paths before destroying iMonitor |
|
110 for (TInt i=EDriveA; i<=EDriveZ; i++) |
|
111 UnMount(TDriveNumber(i), EFalse); |
|
112 iFs.Close(); |
|
113 delete iQEmailFetcher; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CEmailPlugin::ConstructL |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CEmailPlugin::ConstructL() |
|
121 { |
|
122 TInt err = iFs.Connect(); |
|
123 CPIXLOGSTRING2("CEmailPlugin::ConstructL, iFs.Connect: %i", err); |
|
124 User::LeaveIfError(err); |
|
125 iCurrentDrive = EDriveC; //Default drive is C drive |
|
126 for (TInt i=EDriveA; i<=EDriveZ; i++) |
|
127 { |
|
128 iIndexer[i] = NULL; //Initialize to NULL |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CEmailPlugin::StartPluginL |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CEmailPlugin::StartPluginL() |
|
137 { |
|
138 CPIXLOGSTRING2("currentDrive used is : %d", iCurrentDrive ); |
|
139 MountL(TDriveNumber(iCurrentDrive)); //Mount current drive |
|
140 //create instance of QEmailFetcher |
|
141 QT_TRYCATCH_LEAVING(iQEmailFetcher = QEmailFetcher::newInstance(*this)); |
|
142 // Define this base application class, use default location |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CEmailPlugin::StartHarvestingL |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CEmailPlugin::StartHarvestingL(const TDesC& aQualifiedBaseAppClass) |
|
150 { |
|
151 CPIXLOGSTRING("START CEmailPlugin::StartHarvestingL"); |
|
152 // Map base app class to a drive number |
|
153 TDriveNumber drive ( EDriveA );//Initialize to silence compiler warnings. |
|
154 if (KErrNone != MapBaseAppClassToDrive(aQualifiedBaseAppClass, drive)) |
|
155 User::Leave(KErrGeneral); |
|
156 |
|
157 // Leave if no indexer for this drive |
|
158 if (!iIndexer[drive]) |
|
159 User::Leave(KErrGeneral); |
|
160 |
|
161 //Complete harvesting here only for time being |
|
162 //HarvestingCompleted(KErrNone); |
|
163 // Reset the database |
|
164 iIndexer[drive]->ResetL(); |
|
165 #ifdef __PERFORMANCE_DATA |
|
166 iStartTime.UniversalTime(); |
|
167 #endif |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // CEmailPlugin::HandleDocumentL |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CEmailPlugin::HandleDocumentL(const CSearchDocument* aSearchDocument, |
|
175 TCPixActionType aActionType) |
|
176 { |
|
177 CPIXLOGSTRING("START CEmailPlugin::HandleDocumentL"); |
|
178 // Index an empty item if removal action |
|
179 if (aActionType == ECPixRemoveAction) |
|
180 { |
|
181 if (GetIndexer()) |
|
182 { |
|
183 TRAPD(err, GetIndexer()->DeleteL(aSearchDocument->Id())); |
|
184 if (err == KErrNone) |
|
185 { |
|
186 CPIXLOGSTRING("CEmailPlugin::HandleDocumentL: Document deleted."); |
|
187 } |
|
188 else |
|
189 { |
|
190 CPIXLOGSTRING2("CEmailPlugin::HandleDocumentL: Error %d in deleting the document.", err); |
|
191 } |
|
192 } |
|
193 return; |
|
194 } |
|
195 //Add or update action do accordingly |
|
196 if (GetIndexer()) |
|
197 { |
|
198 if (aActionType == ECPixAddAction) |
|
199 { |
|
200 TRAPD(err, GetIndexer()->AddL(*aSearchDocument)); |
|
201 if (err == KErrNone) |
|
202 { |
|
203 CPIXLOGSTRING("CEmailPlugin::HandleDocumentL(): Added."); |
|
204 } |
|
205 else |
|
206 { |
|
207 CPIXLOGSTRING2("CEmailPlugin::HandleDocumentL(): Error %d in adding.", err); |
|
208 } |
|
209 } |
|
210 else if (aActionType == ECPixUpdateAction) |
|
211 { |
|
212 TRAPD(err, GetIndexer()->UpdateL(*aSearchDocument)); |
|
213 if (err == KErrNone) |
|
214 { |
|
215 CPIXLOGSTRING("CEmailPlugin::HandleDocumentL(): Updated."); |
|
216 } |
|
217 else |
|
218 { |
|
219 CPIXLOGSTRING2("CEmailPlugin::HandleDocumentL(): Error %d in updating.", err); |
|
220 } |
|
221 } |
|
222 } |
|
223 else |
|
224 { |
|
225 CPIXLOGSTRING("END CEmailPlugin::HandleDocumentL(): No indexer present."); |
|
226 } |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CEmailPlugin::MountL |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CEmailPlugin::MountL(TDriveNumber aMedia,TBool aForceReharvesting) |
|
234 { |
|
235 CPIXLOGSTRING("START CEmailPlugin::MountL"); |
|
236 // Check if already exists |
|
237 if (iIndexer[aMedia]) |
|
238 return; |
|
239 |
|
240 // Form the baseappclass for this media |
|
241 TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass; |
|
242 FormBaseAppClass(aMedia, baseAppClass); |
|
243 |
|
244 // Define this volume |
|
245 HBufC* path = DatabasePathLC(aMedia); |
|
246 User::LeaveIfError(iSearchSession.DefineVolume(baseAppClass, *path)); |
|
247 CleanupStack::PopAndDestroy(path); |
|
248 |
|
249 // construct and open the database |
|
250 TRAPD(err,iIndexer[aMedia] = CCPixIndexer::NewL(iSearchSession)); |
|
251 CPIXLOGSTRING2("CCPixIndexer::NewL returned : %d", err ); |
|
252 TRAP(err,iIndexer[aMedia]->OpenDatabaseL(baseAppClass)); |
|
253 |
|
254 // Add to harvesting queue |
|
255 iObserver->AddHarvestingQueue(this, baseAppClass,aForceReharvesting); |
|
256 CPIXLOGSTRING("END CEmailPlugin::MountL"); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CEmailPlugin::UnMount |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CEmailPlugin::UnMount(TDriveNumber aMedia, TBool aUndefineAsWell) |
|
264 { |
|
265 CPIXLOGSTRING("START CEmailPlugin::UnMount"); |
|
266 // Check if already exists |
|
267 if (!iIndexer[aMedia]) |
|
268 return; |
|
269 |
|
270 // Form the baseappclass for this media |
|
271 TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass; |
|
272 FormBaseAppClass(aMedia, baseAppClass); |
|
273 |
|
274 // Remove from harvesting queue |
|
275 iObserver->RemoveHarvestingQueue(this, baseAppClass); |
|
276 |
|
277 // Delete the index object |
|
278 if (iIndexer[aMedia]) |
|
279 { |
|
280 delete iIndexer[aMedia]; |
|
281 iIndexer[aMedia] = NULL; |
|
282 } |
|
283 |
|
284 // if the aActionType is EFFMmcDismount, then the |
|
285 // parameter aFilename is the baseAppClass of the Index database |
|
286 // to be dropped. |
|
287 if (aUndefineAsWell) |
|
288 iSearchSession.UnDefineVolume(baseAppClass); |
|
289 } |
|
290 |
|
291 |
|
292 // --------------------------------------------------------------------------- |
|
293 // CEmailPlugin::FormBaseAppClass |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 TInt CEmailPlugin::FormBaseAppClass(TDriveNumber aMedia, TDes& aBaseAppClass) |
|
297 { |
|
298 TChar chr; |
|
299 const TInt ret = RFs::DriveToChar(aMedia, chr); |
|
300 if (KErrNone == ret) |
|
301 { |
|
302 aBaseAppClass.Copy(KAtSign); |
|
303 aBaseAppClass.Append(chr); |
|
304 aBaseAppClass.LowerCase(); |
|
305 aBaseAppClass.Append(KMsgBaseAppClassGeneric); |
|
306 } |
|
307 |
|
308 return ret; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CEmailPlugin::DatabasePathLC |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 HBufC* CEmailPlugin::DatabasePathLC(TDriveNumber aMedia) |
|
316 { |
|
317 CPIXLOGSTRING("START CEmailPlugin::DatabasePathLC"); |
|
318 // Allocate extra space for root path e.g. "C:\\Private\\2001f6f7\\" |
|
319 const TInt KRootPathMaxLength = 30; |
|
320 HBufC* indexDbPath = HBufC::NewLC(KRootPathMaxLength + KPathIndexDbPath().Length() + KPathTrailer().Length()); |
|
321 TPtr indexDbPathPtr = indexDbPath->Des(); |
|
322 |
|
323 #if 1 // Data caging implementation |
|
324 iFs.CreatePrivatePath(aMedia); |
|
325 |
|
326 TChar chr; |
|
327 RFs::DriveToChar(aMedia, chr); |
|
328 indexDbPathPtr.Append(chr); |
|
329 indexDbPathPtr.Append(KColon); |
|
330 |
|
331 TFileName pathWithoutDrive; |
|
332 iFs.PrivatePath(pathWithoutDrive); |
|
333 indexDbPathPtr.Append(KCPixSearchServerPrivateDirectory); |
|
334 #else // here is the way to calculate the path if data caging is not being used. |
|
335 TFileName rootPath; |
|
336 PathInfo::GetRootPath(rootPath, aMedia); |
|
337 indexDbPathPtr.Append(rootPath); |
|
338 #endif |
|
339 |
|
340 indexDbPathPtr.Append(KPathIndexDbPath); |
|
341 indexDbPathPtr.Append(KPathTrailer); |
|
342 |
|
343 return indexDbPath; |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // CEmailPlugin::GetIndexer |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 CCPixIndexer* CEmailPlugin::GetIndexer() |
|
351 { |
|
352 return iIndexer[iCurrentDrive]; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // CEmailPlugin::HarvestingCompleted |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void CEmailPlugin::HarvestingCompleted(TInt aError) |
|
360 { |
|
361 // Notifies the indexing manager of completed harvesting, called by CMessageHarvester |
|
362 Flush( *GetIndexer() ); |
|
363 TBuf<KMsgPluginBaseAppClassMaxLen> baseAppClass; |
|
364 FormBaseAppClass(TDriveNumber(iCurrentDrive), baseAppClass); |
|
365 #ifdef __PERFORMANCE_DATA |
|
366 TRAP_IGNORE( UpdatePerformaceDataL() ); |
|
367 #endif |
|
368 iObserver->HarvestingCompleted(this, baseAppClass, aError); |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------------------------- |
|
372 // CEmailPlugin::UpdatePerformaceDataL |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 #ifdef __PERFORMANCE_DATA |
|
376 void CEmailPlugin::UpdatePerformaceDataL() |
|
377 { |
|
378 TTime now; |
|
379 |
|
380 |
|
381 iCompleteTime.UniversalTime(); |
|
382 TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime); |
|
383 |
|
384 RFs fileSession; |
|
385 RFile perfFile; |
|
386 User::LeaveIfError( fileSession.Connect () ); |
|
387 |
|
388 |
|
389 /* Open file if it exists, otherwise create it and write content in it */ |
|
390 |
|
391 if(perfFile.Open(fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite)) |
|
392 User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite)); |
|
393 |
|
394 HBufC8 *heap = HBufC8::NewL(100); |
|
395 TPtr8 ptr = heap->Des(); |
|
396 now.HomeTime(); |
|
397 TBuf<50> timeString; |
|
398 |
|
399 _LIT(KOwnTimeFormat,"%:0%H%:1%T%:2%S"); |
|
400 now.FormatL(timeString,KOwnTimeFormat); |
|
401 ptr.AppendNum(now.DateTime().Day()); |
|
402 ptr.Append(_L("/")); |
|
403 ptr.AppendNum(now.DateTime().Month()); |
|
404 ptr.Append(_L("/")); |
|
405 ptr.AppendNum(now.DateTime().Year()); |
|
406 ptr.Append(_L(":")); |
|
407 ptr.Append(timeString); |
|
408 ptr.Append( _L("Time taken for Harvesting Message is : ")); |
|
409 ptr.AppendNum(timeDiff.Int64()/1000) ; |
|
410 ptr.Append(_L(" MilliSeonds \n")); |
|
411 TInt myInt = 0; |
|
412 perfFile.Seek(ESeekEnd,myInt); |
|
413 perfFile.Write (ptr); |
|
414 perfFile.Close (); |
|
415 fileSession.Close (); |
|
416 delete heap; |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // CEmailPlugin::UpdatePerformaceDataL |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 void CEmailPlugin::UpdatePerformaceDataL(TMsvSessionEvent action) { |
|
424 |
|
425 iCompleteTime.UniversalTime(); |
|
426 TTimeIntervalMicroSeconds timeDiff = iCompleteTime.MicroSecondsFrom(iStartTime); |
|
427 |
|
428 RFs fileSession; |
|
429 RFile perfFile; |
|
430 User::LeaveIfError( fileSession.Connect () ); |
|
431 |
|
432 |
|
433 /* Open file if it exists, otherwise create it and write content in it */ |
|
434 |
|
435 if(perfFile.Open(fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite)) |
|
436 User::LeaveIfError(perfFile.Create (fileSession, _L("c:\\data\\MessagePerf.txt"), EFileWrite)); |
|
437 |
|
438 HBufC8 *heap = HBufC8::NewL(100); |
|
439 TPtr8 ptr = heap->Des(); |
|
440 |
|
441 switch (action) { |
|
442 case EMsvEntriesDeleted: ptr.Append( _L("del "));break; |
|
443 case EMsvEntriesChanged: ptr.Append( _L("upd "));break; |
|
444 case EMsvEntriesMoved: ptr.Append( _L("mov "));break; |
|
445 } |
|
446 ptr.AppendNum(timeDiff.Int64()/1000) ; |
|
447 ptr.Append(_L("\n")); |
|
448 TInt myInt = 0; |
|
449 perfFile.Seek(ESeekEnd,myInt); |
|
450 perfFile.Write (ptr); |
|
451 perfFile.Close (); |
|
452 fileSession.Close (); |
|
453 delete heap; |
|
454 } |
|
455 |
|
456 #endif |