|
1 /* |
|
2 * Copyright (c) 2006-2009 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: Thread which actually performs the harvesting of the files* |
|
15 */ |
|
16 |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include <caf/caf.h> |
|
20 |
|
21 #include <rlocationobjectmanipulator.h> |
|
22 #include <placeholderdata.h> |
|
23 #include <harvesterclientdata.h> |
|
24 |
|
25 using namespace ContentAccess; |
|
26 |
|
27 #include "harvesterao.h" |
|
28 #include "harvesterlog.h" |
|
29 #include "harvesterblacklist.h" |
|
30 #include "mdeobject.h" |
|
31 #include "mdsutils.h" |
|
32 #include "mdeconstants.h" |
|
33 #include "harvesterdata.h" |
|
34 #include "ondemandao.h" |
|
35 #include "harvestercommon.h" |
|
36 #include "processoriginmapperinterface.h" |
|
37 #include "mdeobjecthandler.h" |
|
38 #include "harvestereventmanager.h" |
|
39 #include "harvestercenreputil.h" |
|
40 #include "restorewatcher.h" |
|
41 #include "backupsubscriber.h" |
|
42 |
|
43 // constants |
|
44 const TInt32 KFileMonitorPluginUid = 0x20007186; // file monitor plugin implementation uid |
|
45 |
|
46 const TInt KPlaceholderQueueSize = 99; |
|
47 const TInt KContainerPlaceholderQueueSize = 10; |
|
48 const TInt KObjectDefStrSize = 20; |
|
49 |
|
50 const TInt KCacheItemCountForEventCaching = 1; |
|
51 |
|
52 _LIT( KTAGDaemonName, "ThumbAGDaemon" ); |
|
53 _LIT( KTAGDaemonExe, "thumbagdaemon.exe" ); |
|
54 |
|
55 _LIT(KInUse, "InUse"); |
|
56 |
|
57 CHarvesterAoPropertyDefs::CHarvesterAoPropertyDefs() : CBase() |
|
58 { |
|
59 } |
|
60 |
|
61 void CHarvesterAoPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef) |
|
62 { |
|
63 CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef(); |
|
64 |
|
65 // Common property definitions |
|
66 CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject ); |
|
67 iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty ); |
|
68 iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ); |
|
69 iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty ); |
|
70 iOriginPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KOriginProperty ); |
|
71 |
|
72 CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject ); |
|
73 iPreinstalledPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KPreinstalledProperty ); |
|
74 } |
|
75 |
|
76 CHarvesterAoPropertyDefs* CHarvesterAoPropertyDefs::NewL(CMdEObjectDef& aObjectDef) |
|
77 { |
|
78 CHarvesterAoPropertyDefs* self = |
|
79 new (ELeave) CHarvesterAoPropertyDefs(); |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL( aObjectDef ); |
|
82 CleanupStack::Pop( self ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // NewLC |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CHarvesterAO* CHarvesterAO::NewLC() |
|
91 { |
|
92 WRITELOG( "CHarvesterAO::NewLC() - begin" ); |
|
93 |
|
94 CHarvesterAO* self = new (ELeave) CHarvesterAO(); |
|
95 CleanupStack::PushL( self ); |
|
96 self->ConstructL(); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // NewL |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CHarvesterAO* CHarvesterAO::NewL() |
|
105 { |
|
106 WRITELOG( "CHarvesterAO::NewL() - begin" ); |
|
107 |
|
108 CHarvesterAO* self = CHarvesterAO::NewLC(); |
|
109 CleanupStack::Pop( self ); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CHarvesterAO |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 CHarvesterAO::CHarvesterAO() : CActive( CActive::EPriorityStandard ) |
|
118 { |
|
119 WRITELOG( "CHarvesterAO::CHarvesterAO() - begin" ); |
|
120 |
|
121 iServerPaused = ETrue; |
|
122 iNextRequest = ERequestIdle; |
|
123 |
|
124 iContextEngineInitialized = EFalse; |
|
125 iMdeSessionInitialized = EFalse; |
|
126 iHarvesting = EFalse; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // ~CHarvesterAO |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 CHarvesterAO::~CHarvesterAO() |
|
134 { |
|
135 WRITELOG( "CHarvesterAO::~CHarvesterAO()" ); |
|
136 |
|
137 Cancel(); |
|
138 |
|
139 iFs.Close(); |
|
140 |
|
141 if (iCtxEngine) |
|
142 { |
|
143 iCtxEngine->ReleaseInstance(); |
|
144 } |
|
145 |
|
146 if (iHarvesterEventManager) |
|
147 { |
|
148 iHarvesterEventManager->ReleaseInstance(); |
|
149 } |
|
150 |
|
151 StopMonitoring(); |
|
152 DeleteMonitorPlugins(); |
|
153 |
|
154 StopComposers(); |
|
155 DeleteComposers(); |
|
156 |
|
157 delete iBackupSubscriber; |
|
158 |
|
159 if (iBlacklist) |
|
160 { |
|
161 iBlacklist->CloseDatabase(); |
|
162 delete iBlacklist; |
|
163 } |
|
164 delete iReHarvester; |
|
165 |
|
166 if ( iHarvestFileMessages.Count() > 0 ) |
|
167 { |
|
168 for ( TInt i = iHarvestFileMessages.Count()-1; i >= 0; --i ) |
|
169 { |
|
170 RMessage2& msg = iHarvestFileMessages[i].iMessage; |
|
171 if (!msg.IsNull()) |
|
172 { |
|
173 msg.Complete( KErrCancel ); |
|
174 } |
|
175 iHarvestFileMessages.Remove( i ); |
|
176 } |
|
177 } |
|
178 iHarvestFileMessages.Close(); |
|
179 |
|
180 iMonitorPluginArray.ResetAndDestroy(); |
|
181 iMonitorPluginArray.Close(); |
|
182 |
|
183 iPHArray.ResetAndDestroy(); |
|
184 iPHArray.Close(); |
|
185 |
|
186 iReadyPHArray.ResetAndDestroy(); |
|
187 iReadyPHArray.Close(); |
|
188 |
|
189 iContainerPHArray.ResetAndDestroy(); |
|
190 iContainerPHArray.Close(); |
|
191 |
|
192 delete iRestoreWatcher; |
|
193 delete iOnDemandAO; |
|
194 delete iMdEHarvesterSession; |
|
195 delete iMdESession; |
|
196 delete iQueue; |
|
197 delete iHarvesterPluginFactory; |
|
198 delete iMdeObjectHandler; |
|
199 delete iUnmountHandlerAO; |
|
200 |
|
201 delete iPropDefs; |
|
202 |
|
203 RMediaIdUtil::ReleaseInstance(); |
|
204 |
|
205 REComSession::FinalClose(); |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // ConstructL |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void CHarvesterAO::ConstructL() |
|
213 { |
|
214 WRITELOG( "CHarvesterAO::ConstructL() - begin" ); |
|
215 |
|
216 CActiveScheduler::Add( this ); |
|
217 |
|
218 User::LeaveIfError( iFs.Connect() ); |
|
219 |
|
220 // Setting up MdE Session |
|
221 iMdESession = CMdESession::NewL( *this ); |
|
222 |
|
223 RProcess process; |
|
224 process.SetPriority( EPriorityBackground ); |
|
225 process.Close(); |
|
226 |
|
227 // Setting up context Engine (initialization is ready when ContextInitializationStatus -callback is called) |
|
228 iCtxEngine = CContextEngine::GetInstanceL( this ); // Create the context engine |
|
229 |
|
230 iBackupSubscriber = CBackupSubscriber::NewL( *this ); |
|
231 |
|
232 iUnmountHandlerAO = CUnmountHandlerAO::NewL( *this ); |
|
233 iUnmountHandlerAO->WaitForUnmountL(); |
|
234 |
|
235 iHarvesterEventManager = CHarvesterEventManager::GetInstanceL(); |
|
236 |
|
237 iRestoreWatcher = CRestoreWatcher::NewL(); |
|
238 |
|
239 iHarvesterOomAO = CHarvesterOomAO::NewL( *this ); |
|
240 |
|
241 iMediaIdUtil = &RMediaIdUtil::GetInstanceL(); |
|
242 |
|
243 iBlacklist = CHarvesterBlacklist::NewL(); |
|
244 iBlacklist->OpenDatabase(); |
|
245 |
|
246 // Setting up Harvester queue |
|
247 iQueue = CHarvesterQueue::NewL( this, iBlacklist ); |
|
248 |
|
249 // Setting up reharvester |
|
250 iReHarvester = CReHarvesterAO::NewL(); |
|
251 iReHarvester->SetHarvesterQueue( iQueue ); |
|
252 |
|
253 iHarvesterPluginFactory = CHarvesterPluginFactory::NewL(); |
|
254 iHarvesterPluginFactory->SetBlacklist( *iBlacklist ); |
|
255 |
|
256 WRITELOG( "CHarvesterAO::ConstructL() - end" ); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // LoadMonitorPluginsL |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CHarvesterAO::LoadMonitorPluginsL() |
|
264 { |
|
265 WRITELOG( "CHarvesterAO::LoadMonitorPluginsL()" ); |
|
266 |
|
267 RImplInfoPtrArray infoArray; |
|
268 |
|
269 TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray ); |
|
270 CleanupStack::PushL( cleanupItem ); |
|
271 |
|
272 CMonitorPlugin::ListImplementationsL( infoArray ); |
|
273 TInt count( 0 ); |
|
274 count = infoArray.Count(); |
|
275 CMonitorPlugin* plugin = NULL; |
|
276 |
|
277 for ( TInt i = 0; i < count; i++ ) |
|
278 { |
|
279 TUid uid = infoArray[i]->ImplementationUid(); // Create the plug-ins |
|
280 plugin = NULL; |
|
281 TRAPD( err, plugin = CMonitorPlugin::NewL( uid ) ); |
|
282 if ( err == KErrNone && plugin ) |
|
283 { |
|
284 CleanupStack::PushL( plugin ); |
|
285 iMonitorPluginArray.AppendL( plugin ); // and add them to array |
|
286 CleanupStack::Pop( plugin ); |
|
287 if ( uid.iUid == KFileMonitorPluginUid ) |
|
288 { |
|
289 void* ptr = plugin; |
|
290 iProcessOriginMapper = STATIC_CAST( MProcessOriginMapperInterface*, ptr ); |
|
291 } |
|
292 } |
|
293 else |
|
294 { |
|
295 WRITELOG( "CHarvesterAO::LoadMonitorPlugins() - Failed to load a monitor plugin!" ); |
|
296 delete plugin; |
|
297 plugin = NULL; |
|
298 } |
|
299 } |
|
300 |
|
301 CleanupStack::PopAndDestroy( &infoArray ); // infoArray, results in a call to CleanupEComArray |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // DeleteMonitorPlugins |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 void CHarvesterAO::DeleteMonitorPlugins() |
|
309 { |
|
310 WRITELOG( "CHarvesterAO::DeleteMonitorPlugins()" ); |
|
311 |
|
312 iMonitorPluginArray.ResetAndDestroy(); |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // StartMonitoring |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CHarvesterAO::StartMonitoring() |
|
320 { |
|
321 WRITELOG( "CHarvesterAO::StartMonitoring()" ); |
|
322 |
|
323 TInt count( iMonitorPluginArray.Count() ); |
|
324 |
|
325 for ( TInt i = 0; i < count; i++ ) |
|
326 { |
|
327 iMonitorPluginArray[i]->StartMonitoring( *iQueue, iMdESession, NULL, |
|
328 iHarvesterPluginFactory ); |
|
329 } |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------------------------- |
|
333 // StopMonitoring |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 void CHarvesterAO::StopMonitoring() |
|
337 { |
|
338 WRITELOG( "CHarvesterAO::StopMonitoring()" ); |
|
339 |
|
340 TInt count( iMonitorPluginArray.Count() ); |
|
341 |
|
342 for ( TInt i = 0; i < count; i++ ) |
|
343 { |
|
344 iMonitorPluginArray[i]->StopMonitoring(); |
|
345 } |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // PauseMonitoring |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CHarvesterAO::PauseMonitoring() |
|
353 { |
|
354 WRITELOG( "CHarvesterAO::PauseMonitoring()" ); |
|
355 TInt count( iMonitorPluginArray.Count() ); |
|
356 |
|
357 for ( TInt i = 0; i<count; i++ ) |
|
358 { |
|
359 iMonitorPluginArray[i]->PauseMonitoring(); |
|
360 } |
|
361 WRITELOG( "CHarvesterAO::PauseMonitoring() - end" ); |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // ResumeMonitoring |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CHarvesterAO::ResumeMonitoring() |
|
369 { |
|
370 WRITELOG( "CHarvesterAO::ResumeMonitoring()" ); |
|
371 |
|
372 TInt count( iMonitorPluginArray.Count() ); |
|
373 |
|
374 for ( TInt i=0; i < count; i++ ) |
|
375 { |
|
376 iMonitorPluginArray[i]->ResumeMonitoring( *iQueue, iMdESession, NULL, |
|
377 iHarvesterPluginFactory ); |
|
378 } |
|
379 WRITELOG( "CHarvesterAO::ResumeMonitoring() - end" ); |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // HandleUnmount |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 void CHarvesterAO::HandleUnmount( TUint32 aMediaId ) |
|
387 { |
|
388 WRITELOG1( "CHarvesterAO::HandleUnmount(%d)", aMediaId ); |
|
389 |
|
390 TUint32 mediaId(0); |
|
391 TUint removed(0); |
|
392 TInt err(0); |
|
393 CHarvesterData* hd = NULL; |
|
394 |
|
395 #ifdef _DEBUG |
|
396 WRITELOG1( "CHarvesterAO::HandleUnmount() iReadyPHArray.Count() = %d", iReadyPHArray.Count() ); |
|
397 #endif |
|
398 if( iReadyPHArray.Count() > 0 ) |
|
399 { |
|
400 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, iReadyPHArray.Count() ) ); |
|
401 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, iReadyPHArray.Count()) ); |
|
402 iReadyPHArray.ResetAndDestroy(); |
|
403 } |
|
404 |
|
405 #ifdef _DEBUG |
|
406 WRITELOG1( "CHarvesterAO::HandleUnmount() iPHArray.Count() = %d", iPHArray.Count() ); |
|
407 #endif |
|
408 if( iPHArray.Count() > 0 ) |
|
409 { |
|
410 for( TInt i=iPHArray.Count()-1; i>= 0; i--) |
|
411 { |
|
412 hd = iPHArray[i]; |
|
413 err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId ); |
|
414 |
|
415 if( err == KErrNone && mediaId == aMediaId ) |
|
416 { |
|
417 WRITELOG1( "CHarvesterAO::HandleUnmount() remove iPHArray %d", i); |
|
418 delete hd; |
|
419 hd = NULL; |
|
420 iPHArray.Remove( i ); |
|
421 removed++; |
|
422 } |
|
423 } |
|
424 WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iPHArray %d", removed); |
|
425 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) ); |
|
426 } |
|
427 |
|
428 removed = 0; |
|
429 |
|
430 #ifdef _DEBUG |
|
431 WRITELOG1( "CHarvesterAO::HandleUnmount() iContainerPHArray.Count() = %d", iContainerPHArray.Count() ); |
|
432 #endif |
|
433 if( iContainerPHArray.Count() > 0 ) |
|
434 { |
|
435 for( TInt i=iContainerPHArray.Count()-1; i>= 0; i--) |
|
436 { |
|
437 hd = iContainerPHArray[i]; |
|
438 err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId ); |
|
439 |
|
440 if( err == KErrNone && mediaId == aMediaId ) |
|
441 { |
|
442 WRITELOG1( "CHarvesterAO::HandleUnmount() remove iContainerPHArray %d", i); |
|
443 delete hd; |
|
444 hd = NULL; |
|
445 iContainerPHArray.Remove( i ); |
|
446 removed++; |
|
447 } |
|
448 } |
|
449 WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iContainerPHArray %d", removed); |
|
450 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) ); |
|
451 } |
|
452 |
|
453 TUint count = iQueue->ItemsInQueue(); |
|
454 WRITELOG1( "CHarvesterAO::HandleUnmount() iQueue.Count() = %d", count ); |
|
455 if( count > 0 ) |
|
456 { |
|
457 WRITELOG( "CHarvesterAO::HandleUnmount() remove iQueue" ); |
|
458 TUint removed = iQueue->RemoveItems( aMediaId ); |
|
459 WRITELOG1( "CHarvesterAO::HandleUnmount() removed iQueue = %d", removed ); |
|
460 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed ) ); |
|
461 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, removed ) ); |
|
462 } |
|
463 |
|
464 iMediaIdUtil->RemoveMediaId( aMediaId ); |
|
465 |
|
466 removed = 0; |
|
467 |
|
468 RPointerArray<CHarvesterPluginInfo>& hpiArray = iHarvesterPluginFactory->GetPluginInfos(); |
|
469 if( hpiArray.Count() > 0 ) |
|
470 { |
|
471 RArray<TItemId> placeholders; |
|
472 |
|
473 TUint32 mediaId(0); |
|
474 TInt err(0); |
|
475 |
|
476 for( TInt i = hpiArray.Count(); --i >= 0; ) |
|
477 { |
|
478 CHarvesterPluginInfo* hpi = hpiArray[i]; |
|
479 for( TInt j = hpi->iQueue.Count(); --j >= 0; ) |
|
480 { |
|
481 CHarvesterData* hd = hpi->iQueue[j]; |
|
482 CMdEObject& mdeobj = hd->MdeObject(); |
|
483 |
|
484 err = iMediaIdUtil->GetMediaId( mdeobj.Uri(), mediaId ); |
|
485 |
|
486 if( mdeobj.Placeholder() && ( aMediaId == mediaId || err != KErrNone )) |
|
487 { |
|
488 removed++; |
|
489 |
|
490 TItemId id = mdeobj.Id(); |
|
491 placeholders.Append( id ); |
|
492 TRAP_IGNORE( iMdESession->CancelObjectL( mdeobj ) ); |
|
493 |
|
494 delete hd; |
|
495 hd = NULL; |
|
496 hpi->iQueue.Remove(j); |
|
497 |
|
498 if( hpi->iQueue.Count() == 0 ) |
|
499 { |
|
500 hpi->iQueue.Compress(); |
|
501 } |
|
502 } |
|
503 } |
|
504 } |
|
505 |
|
506 if( removed ) |
|
507 { |
|
508 WRITELOG1( "CHarvesterAO::HandleUnmount() remove from plugins = %d", removed); |
|
509 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed ) ); |
|
510 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, removed ) ); |
|
511 } |
|
512 |
|
513 RArray<TItemId> results; |
|
514 TRAP_IGNORE( iMdESession->RemoveObjectsL( placeholders, results, NULL ) ); |
|
515 results.Close(); |
|
516 placeholders.Close(); |
|
517 } |
|
518 } |
|
519 |
|
520 // --------------------------------------------------------------------------- |
|
521 // StartComposersL |
|
522 // --------------------------------------------------------------------------- |
|
523 // |
|
524 void CHarvesterAO::StartComposersL() |
|
525 { |
|
526 WRITELOG( "CHarvesterAO::StartComposersL()" ); |
|
527 |
|
528 RImplInfoPtrArray infoArray; |
|
529 TCleanupItem cleanupItem( MdsUtils::CleanupEComArray, &infoArray ); |
|
530 CleanupStack::PushL( cleanupItem ); |
|
531 CComposerPlugin::ListImplementationsL( infoArray ); |
|
532 TInt count( 0 ); |
|
533 count = infoArray.Count(); |
|
534 |
|
535 for ( TInt i=0; i < count; i++ ) |
|
536 { |
|
537 TUid uid = infoArray[i]->ImplementationUid(); |
|
538 CComposerPlugin* plugin = NULL; |
|
539 TRAPD(trapError, plugin = CComposerPlugin::NewL( uid ) ); |
|
540 if ( trapError != KErrNone ) |
|
541 { |
|
542 WRITELOG( "CHarvesterAO::StartComposersL() - failed to create new composer" ); |
|
543 } |
|
544 else |
|
545 { |
|
546 plugin->SetSession( iMdEHarvesterSession->SessionRef() ); |
|
547 iComposerPluginArray.AppendL( plugin ); |
|
548 } |
|
549 } |
|
550 |
|
551 CleanupStack::PopAndDestroy( &infoArray ); |
|
552 WRITELOG( "CHarvesterAO::StartComposersL() - end" ); |
|
553 } |
|
554 |
|
555 // --------------------------------------------------------------------------- |
|
556 // StopComposers |
|
557 // --------------------------------------------------------------------------- |
|
558 // |
|
559 void CHarvesterAO::StopComposers() |
|
560 { |
|
561 WRITELOG( "CHarvesterAO::StopComposers()" ); |
|
562 |
|
563 for ( TInt i = iComposerPluginArray.Count(); --i >= 0; ) |
|
564 { |
|
565 iComposerPluginArray[i]->RemoveSession(); |
|
566 } |
|
567 |
|
568 WRITELOG( "CHarvesterAO::StopComposers() - end" ); |
|
569 } |
|
570 |
|
571 // --------------------------------------------------------------------------- |
|
572 // DeleteComposers |
|
573 // --------------------------------------------------------------------------- |
|
574 // |
|
575 void CHarvesterAO::DeleteComposers() |
|
576 { |
|
577 WRITELOG( "CHarvesterAO::DeleteComposers()" ); |
|
578 |
|
579 iComposerPluginArray.ResetAndDestroy(); |
|
580 |
|
581 WRITELOG( "CHarvesterAO::DeleteComposers() - end" ); |
|
582 } |
|
583 |
|
584 // --------------------------------------------------------------------------- |
|
585 // IsComposingReady |
|
586 // --------------------------------------------------------------------------- |
|
587 // |
|
588 TBool CHarvesterAO::IsComposingReady() |
|
589 { |
|
590 WRITELOG( "CHarvesterAO::IsComposingReady()" ); |
|
591 |
|
592 for ( TInt i = iComposerPluginArray.Count(); --i >= 0; ) |
|
593 { |
|
594 if ( iComposerPluginArray[i]->IsComposingComplete() == EFalse ) |
|
595 { |
|
596 return EFalse; |
|
597 } |
|
598 } |
|
599 |
|
600 WRITELOG( "CHarvesterAO::IsComposingReady() - end" ); |
|
601 return ETrue; |
|
602 } |
|
603 |
|
604 // --------------------------------------------------------------------------- |
|
605 // ReadItemFromQueueL |
|
606 // --------------------------------------------------------------------------- |
|
607 // |
|
608 void CHarvesterAO::ReadItemFromQueueL() |
|
609 { |
|
610 WRITELOG( "CHarvesterAO::ReadItemFromQueueL()" ); |
|
611 |
|
612 CHarvesterData* hd = iQueue->GetNextItem(); |
|
613 |
|
614 if ( hd->ObjectType() == EPlaceholder ) |
|
615 { |
|
616 while( hd != NULL && |
|
617 iPHArray.Count() < KPlaceholderQueueSize && |
|
618 hd->ObjectType() == EPlaceholder ) |
|
619 { |
|
620 iPHArray.Append( hd ); |
|
621 hd = iQueue->GetNextItem(); |
|
622 } |
|
623 |
|
624 if( hd ) |
|
625 { |
|
626 if( hd->ObjectType() == EPlaceholder ) |
|
627 { |
|
628 iPHArray.Append( hd ); |
|
629 } |
|
630 else |
|
631 { |
|
632 CheckFileExtensionAndHarvestL( hd ); |
|
633 } |
|
634 } |
|
635 |
|
636 if( iPHArray.Count() > 0 ) |
|
637 { |
|
638 TRAPD( err, HandlePlaceholdersL( ETrue ) ); |
|
639 |
|
640 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
|
641 if ( err != KErrNone ) |
|
642 { |
|
643 iPHArray.ResetAndDestroy(); |
|
644 User::Leave( err ); |
|
645 } |
|
646 } |
|
647 } |
|
648 else |
|
649 { |
|
650 CheckFileExtensionAndHarvestL( hd ); |
|
651 } |
|
652 } |
|
653 |
|
654 // --------------------------------------------------------------------------- |
|
655 // HandlePlaceholdersL |
|
656 // --------------------------------------------------------------------------- |
|
657 // |
|
658 void CHarvesterAO::HandlePlaceholdersL( TBool aCheck ) |
|
659 { |
|
660 WRITELOG( "CHarvesterAO::HandlePlaceholdersL()" ); |
|
661 |
|
662 RPointerArray<CMdEObject> mdeObjectArray; |
|
663 CleanupClosePushL( mdeObjectArray ); |
|
664 |
|
665 TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset(); |
|
666 |
|
667 TInt fastHarvestPlaceholderCount = 0; |
|
668 |
|
669 for (TInt i = iPHArray.Count() ; --i >= 0;) |
|
670 { |
|
671 CHarvesterData* hd = iPHArray[i]; |
|
672 |
|
673 if( aCheck && iHarvesterPluginFactory->IsContainerFileL( hd->Uri() ) ) |
|
674 { |
|
675 iContainerPHArray.Append( hd ); |
|
676 iPHArray.Remove( i ); |
|
677 continue; |
|
678 } |
|
679 TBuf<KObjectDefStrSize> objDefStr; |
|
680 iHarvesterPluginFactory->GetObjectDefL( *hd, objDefStr ); |
|
681 |
|
682 if( objDefStr.Length() == 0 || |
|
683 ( objDefStr == KInUse ) ) |
|
684 { |
|
685 const TInt error( KErrUnknown ); |
|
686 // notify observer, notification is needed even if file is not supported |
|
687 HarvestCompleted( hd->ClientId(), hd->Uri(), error ); |
|
688 delete hd; |
|
689 hd = NULL; |
|
690 iPHArray.Remove( i ); |
|
691 iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ); |
|
692 continue; |
|
693 } |
|
694 |
|
695 CMdENamespaceDef& defNS = iMdESession->GetDefaultNamespaceDefL(); |
|
696 CMdEObjectDef& mdeObjectDef = defNS.GetObjectDefL( objDefStr ); |
|
697 |
|
698 CMdEObject* mdeObject = iMdESession->NewObjectL( mdeObjectDef, hd->Uri() ); |
|
699 |
|
700 CPlaceholderData* phData = NULL; |
|
701 |
|
702 if( hd->TakeSnapshot() ) |
|
703 { |
|
704 phData = CPlaceholderData::NewL(); |
|
705 CleanupStack::PushL( phData ); |
|
706 TEntry* entry = new (ELeave) TEntry(); |
|
707 CleanupStack::PushL( entry ); |
|
708 const TDesC& uri = hd->Uri(); |
|
709 TInt err = iFs.Entry( uri, *entry ); |
|
710 if ( err != KErrNone ) |
|
711 { |
|
712 WRITELOG( "CHarvesterAO::HandlePlaceholdersL() - cannot create placeholder data object for camera. file does not exists" ); |
|
713 // notify observer |
|
714 HarvestCompleted( hd->ClientId(), hd->Uri(), err ); |
|
715 delete hd; |
|
716 hd = NULL; |
|
717 iPHArray.Remove( i ); |
|
718 iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ); |
|
719 CleanupStack::PopAndDestroy( entry ); |
|
720 CleanupStack::PopAndDestroy( phData ); |
|
721 continue; |
|
722 } |
|
723 phData->SetUri( uri ); |
|
724 phData->SetModified( entry->iModified ); |
|
725 phData->SetFileSize( entry->iSize ); |
|
726 CleanupStack::PopAndDestroy( entry ); |
|
727 |
|
728 TUint32 mediaId( 0 ); |
|
729 User::LeaveIfError( iMediaIdUtil->GetMediaId( uri, mediaId ) ); |
|
730 phData->SetMediaId( mediaId ); |
|
731 } |
|
732 else |
|
733 { |
|
734 phData = static_cast<CPlaceholderData*> ( hd->ClientData() ); |
|
735 if( !phData ) |
|
736 { |
|
737 WRITELOG( "CHarvesterAO::HandlePlaceholdersL() - Placeholder data object NULL - abort" ); |
|
738 const TInt error( KErrUnknown ); |
|
739 // notify observer |
|
740 HarvestCompleted( hd->ClientId(), hd->Uri(), error ); |
|
741 delete hd; |
|
742 hd = NULL; |
|
743 iPHArray.Remove( i ); |
|
744 iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ); |
|
745 continue; |
|
746 } |
|
747 CleanupStack::PushL( phData ); |
|
748 } |
|
749 |
|
750 // set media id |
|
751 mdeObject->SetMediaId( phData->MediaId() ); |
|
752 |
|
753 // set placeholder |
|
754 mdeObject->SetPlaceholder( ETrue ); |
|
755 |
|
756 if( !iPropDefs ) |
|
757 { |
|
758 iPropDefs = CHarvesterAoPropertyDefs::NewL( mdeObjectDef ); |
|
759 } |
|
760 |
|
761 // set file size |
|
762 mdeObject->AddUint32PropertyL( *iPropDefs->iSizePropertyDef, phData->FileSize() ); |
|
763 |
|
764 // set creation date |
|
765 TTime localModifiedDate = phData->Modified() + timeOffsetSeconds; |
|
766 mdeObject->AddTimePropertyL( *iPropDefs->iCreationDatePropertyDef, localModifiedDate ); |
|
767 |
|
768 // set modification date |
|
769 mdeObject->AddTimePropertyL( *iPropDefs->iLastModifiedDatePropertyDef, phData->Modified() ); |
|
770 |
|
771 // set origin |
|
772 mdeObject->AddUint8PropertyL( *iPropDefs->iOriginPropertyDef, hd->Origin() ); |
|
773 |
|
774 CPlaceholderData* ph = static_cast<CPlaceholderData*>( hd->ClientData() ); |
|
775 TInt isPreinstalled = ph->Preinstalled(); |
|
776 if( isPreinstalled == MdeConstants::MediaObject::EPreinstalled ) |
|
777 { |
|
778 WRITELOG("CHarvesterAO::HandlePlaceholdersL() - preinstalled"); |
|
779 mdeObject->AddInt32PropertyL( *iPropDefs->iPreinstalledPropertyDef, isPreinstalled ); |
|
780 } |
|
781 |
|
782 hd->SetEventType( EHarvesterEdit ); |
|
783 |
|
784 // skip |
|
785 if( hd->TakeSnapshot() ) |
|
786 { |
|
787 fastHarvestPlaceholderCount++; |
|
788 hd->SetObjectType( EFastHarvest ); |
|
789 } |
|
790 else |
|
791 { |
|
792 hd->SetClientData( NULL ); |
|
793 hd->SetObjectType( ENormal ); |
|
794 } |
|
795 |
|
796 hd->SetMdeObject( mdeObject ); |
|
797 |
|
798 mdeObjectArray.Append( mdeObject ); |
|
799 |
|
800 CleanupStack::PopAndDestroy( phData ); |
|
801 |
|
802 iReadyPHArray.Append( hd ); |
|
803 iPHArray.Remove( i ); |
|
804 } |
|
805 |
|
806 TInt objectCount = mdeObjectArray.Count(); |
|
807 |
|
808 if( objectCount > 0 ) |
|
809 { |
|
810 // add object to mde |
|
811 iMdEHarvesterSession->AutoLockL( mdeObjectArray ); |
|
812 const TInt addError( iMdESession->AddObjectsL( mdeObjectArray ) ); |
|
813 if( addError != KErrNone ) |
|
814 { |
|
815 // If some error occures, retry |
|
816 iMdESession->AddObjectsL( mdeObjectArray ); |
|
817 } |
|
818 |
|
819 const TInt eventObjectCount = objectCount - fastHarvestPlaceholderCount; |
|
820 |
|
821 if( eventObjectCount > 0 ) |
|
822 { |
|
823 iHarvesterEventManager->IncreaseItemCount( EHEObserverTypePlaceholder, |
|
824 eventObjectCount ); |
|
825 iHarvesterEventManager->SendEventL( EHEObserverTypePlaceholder, EHEStateStarted, |
|
826 iHarvesterEventManager->ItemCount( EHEObserverTypePlaceholder ) ); |
|
827 } |
|
828 |
|
829 #ifdef _DEBUG |
|
830 for (TInt i = 0; i < mdeObjectArray.Count(); ++i) |
|
831 { |
|
832 CMdEObject* mdeObject = mdeObjectArray[i]; |
|
833 if(mdeObject->Id() == 0) |
|
834 { |
|
835 WRITELOG1( "CHarvesterAO::HandlePlaceholdersL() - failed to add: %S", &mdeObject->Uri() ); |
|
836 } |
|
837 } |
|
838 #endif |
|
839 } |
|
840 |
|
841 iPHArray.ResetAndDestroy(); |
|
842 |
|
843 CleanupStack::PopAndDestroy( &mdeObjectArray ); |
|
844 } |
|
845 |
|
846 // --------------------------------------------------------------------------- |
|
847 // CheckFileExtensionAndHarvestL |
|
848 // --------------------------------------------------------------------------- |
|
849 // |
|
850 void CHarvesterAO::CheckFileExtensionAndHarvestL( CHarvesterData* aHD ) |
|
851 { |
|
852 TBool isError = EFalse; |
|
853 CMdEObject* mdeObject = &aHD->MdeObject(); |
|
854 const TDesC& uri = aHD->Uri(); |
|
855 TBool objectExisted = ETrue; |
|
856 |
|
857 if( ! mdeObject ) |
|
858 { |
|
859 objectExisted = EFalse; |
|
860 WRITELOG1( "CHarvesterAO::CheckFileExtensionAndHarvestL() - no mdeobject. URI: %S", &uri ); |
|
861 TBuf<KObjectDefStrSize> objDefStr; |
|
862 iHarvesterPluginFactory->GetObjectDefL( *aHD, objDefStr ); |
|
863 |
|
864 if( objDefStr.Length() == 0 ) |
|
865 { |
|
866 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - cannot get object definition" ); |
|
867 isError = ETrue; |
|
868 } |
|
869 else if( objDefStr == KInUse ) |
|
870 { |
|
871 aHD->SetErrorCode( KMdEErrHarvestingFailed ); |
|
872 HarvestingCompleted( aHD ); |
|
873 return; |
|
874 } |
|
875 else |
|
876 { |
|
877 TInt mdeError( KErrNone ); |
|
878 |
|
879 // Check if non-binary object (messages) already exists in db |
|
880 if ( !aHD->IsBinary() ) |
|
881 { |
|
882 CMdENamespaceDef& defNS = iMdESession->GetDefaultNamespaceDefL(); |
|
883 CMdEObjectDef& mdeObjectDef = defNS.GetObjectDefL( objDefStr ); |
|
884 TRAP( mdeError, mdeObject = iMdESession->OpenObjectL( aHD->Uri(), mdeObjectDef )); |
|
885 } |
|
886 |
|
887 if ( mdeObject ) |
|
888 { |
|
889 aHD->SetTakeSnapshot( EFalse ); |
|
890 aHD->SetEventType( EHarvesterEdit ); |
|
891 } |
|
892 else |
|
893 { |
|
894 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - getting mdeobject" ); |
|
895 TRAP( mdeError, mdeObject = iMdeObjectHandler->GetMetadataObjectL( *aHD, objDefStr ) ); |
|
896 } |
|
897 TInt harvesterError = KErrNone; |
|
898 if( mdeError != KErrNone) |
|
899 { |
|
900 WRITELOG1( "CHarvesterAO::CheckFileExtensionAndHarvestL() - cannot get mde object. error: %d", mdeError ); |
|
901 MdsUtils::ConvertTrapError( mdeError, harvesterError ); |
|
902 if( harvesterError == KMdEErrHarvestingFailedPermanent ) |
|
903 { |
|
904 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - permanent fail" ); |
|
905 isError = ETrue; |
|
906 } |
|
907 else if ( harvesterError == KMdEErrHarvestingFailed ) |
|
908 { |
|
909 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - KMdEErrHarvestingFailed"); |
|
910 aHD->SetErrorCode( KMdEErrHarvestingFailed ); |
|
911 HarvestingCompleted( aHD ); |
|
912 return; |
|
913 } |
|
914 } |
|
915 |
|
916 if( !mdeObject ) |
|
917 { |
|
918 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - mde object is null. stop harvesting" ); |
|
919 isError = ETrue; |
|
920 } |
|
921 } |
|
922 if( isError ) |
|
923 { |
|
924 aHD->SetErrorCode( KMdEErrHarvestingFailedPermanent ); |
|
925 HarvestingCompleted( aHD ); |
|
926 return; |
|
927 } |
|
928 |
|
929 CleanupStack::PushL( aHD ); |
|
930 |
|
931 TUint32 mediaId( 0 ); |
|
932 if ( aHD->IsBinary() ) |
|
933 { |
|
934 User::LeaveIfError( iMediaIdUtil->GetMediaId( uri, mediaId ) ); |
|
935 } |
|
936 mdeObject->SetMediaId( mediaId ); |
|
937 |
|
938 aHD->SetMdeObject( mdeObject ); |
|
939 CleanupStack::Pop( aHD ); |
|
940 } |
|
941 |
|
942 #ifdef _DEBUG |
|
943 WRITELOG1("CHarvesterAO::CheckFileExtensionAndHarvestL() - mdeobject URI: %S", &mdeObject->Uri() ); |
|
944 #endif |
|
945 |
|
946 aHD->SetPluginObserver( *this ); |
|
947 |
|
948 if( objectExisted && aHD->EventType() == EHarvesterAdd ) |
|
949 { |
|
950 iMdESession->RemoveObjectL( aHD->Uri() ); |
|
951 } |
|
952 |
|
953 TInt pluginErr = KErrNone; |
|
954 TRAPD( err, pluginErr = iHarvesterPluginFactory->HarvestL( aHD )); |
|
955 if ( err != KErrNone ) |
|
956 { |
|
957 WRITELOG1( "CHarvesterAO::CheckFileExtensionAndHarvestL() - plugin error: %d", err ); |
|
958 if ( err == KErrInUse ) |
|
959 { |
|
960 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - item in use" ); |
|
961 aHD->SetErrorCode( KMdEErrHarvestingFailed ); |
|
962 HarvestingCompleted( aHD ); |
|
963 return; |
|
964 } |
|
965 |
|
966 aHD->SetErrorCode( KMdEErrHarvestingFailedUnknown ); |
|
967 HarvestingCompleted( aHD ); |
|
968 return; |
|
969 } |
|
970 |
|
971 if( pluginErr != KErrNone ) |
|
972 { |
|
973 aHD->SetErrorCode( KMdEErrHarvestingFailedUnknown ); |
|
974 HarvestingCompleted( aHD ); |
|
975 return; |
|
976 } |
|
977 |
|
978 WRITELOG1("CHarvesterAO::CheckFileExtensionAndHarvestL() - ends with error %d", pluginErr ); |
|
979 SetNextRequest( ERequestHarvest ); |
|
980 } |
|
981 |
|
982 // --------------------------------------------------------------------------- |
|
983 // HarvestingCompleted |
|
984 // --------------------------------------------------------------------------- |
|
985 // |
|
986 void CHarvesterAO::HarvestingCompleted( CHarvesterData* aHD ) |
|
987 { |
|
988 WRITELOG( "CHarvesterAO::HarvestingCompleted()" ); |
|
989 |
|
990 if ( aHD->ErrorCode() == KErrNone ) |
|
991 { |
|
992 iReHarvester->CheckItem( *aHD ); |
|
993 |
|
994 TInt mdeError = KErrNone; |
|
995 if( !aHD->TakeSnapshot() ) |
|
996 { |
|
997 WRITELOG( "CHarvesterAO::HarvestingCompleted() origin is not camera or clf" ); |
|
998 aHD->MdeObject().SetPlaceholder( EFalse ); |
|
999 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder ) ); |
|
1000 TRAP( mdeError, iMdeObjectHandler->SetMetadataObjectL( *aHD ) ); |
|
1001 } |
|
1002 |
|
1003 if(mdeError != KErrNone) |
|
1004 { |
|
1005 WRITELOG( "==============================ERROR===============================" ); |
|
1006 WRITELOG( "CHarvesterAO::HarvestingCompleted() - cannot set metadata object" ); |
|
1007 WRITELOG( "==============================ERROR done =========================" ); |
|
1008 delete aHD; |
|
1009 aHD = NULL; |
|
1010 |
|
1011 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ) ); |
|
1012 } |
|
1013 else |
|
1014 { |
|
1015 WRITELOG( "CHarvesterAO::HarvestingCompleted() mdeError == KErrNone" ); |
|
1016 if ( aHD->TakeSnapshot() && iCtxEngine ) |
|
1017 { |
|
1018 WRITELOG( "CHarvesterAO::HarvestingCompleted() - Taking a context snapshot." ); |
|
1019 iCtxEngine->ContextSnapshot( *this, *aHD ); |
|
1020 } |
|
1021 else |
|
1022 { |
|
1023 TLocationData* locData = aHD->LocationData(); |
|
1024 if( locData ) |
|
1025 { |
|
1026 WRITELOG( "CHarvesterAO::HarvestingCompleted() - Creating location object. " ); |
|
1027 RLocationObjectManipulator lo; |
|
1028 |
|
1029 TInt loError = KErrNone; |
|
1030 loError = lo.Connect(); |
|
1031 |
|
1032 if (loError == KErrNone) |
|
1033 { |
|
1034 TInt err = lo.CreateLocationObject( *locData, aHD->MdeObject().Id() ); |
|
1035 if( err != KErrNone ) |
|
1036 { |
|
1037 WRITELOG( "CHarvesterAO::HarvestingCompleted() - Location object creation failed!!!" ); |
|
1038 } |
|
1039 } |
|
1040 else |
|
1041 { |
|
1042 WRITELOG( "CHarvesterAO::HarvestingCompleted() - LocationObjectManipulator connect failed!!!" ); |
|
1043 } |
|
1044 |
|
1045 lo.Close(); |
|
1046 } |
|
1047 |
|
1048 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ) ); |
|
1049 |
|
1050 delete aHD; |
|
1051 aHD = NULL; |
|
1052 } |
|
1053 } |
|
1054 } |
|
1055 else |
|
1056 { |
|
1057 #ifdef _DEBUG |
|
1058 WRITELOG( "==============================ERROR===============================" ); |
|
1059 WRITELOG1( "CHarvesterAO::HarvestingCompleted() - not OK! Error: %d", aHD->ErrorCode() ); |
|
1060 #endif |
|
1061 |
|
1062 const TInt errorCode( aHD->ErrorCode() ); |
|
1063 if ( errorCode== KMdEErrHarvestingFailed ) |
|
1064 { |
|
1065 #ifdef _DEBUG |
|
1066 WRITELOG1("CHarvesterAO::HarvestingCompleted() - KMdEErrHarvestingFailed - %S - reharvesting", &aHD->Uri() ); |
|
1067 #endif |
|
1068 iReHarvester->AddItem( aHD ); |
|
1069 } |
|
1070 else if ( errorCode == KMdEErrHarvestingFailedPermanent || |
|
1071 errorCode == KMdEErrHarvestingFailedUnknown ) |
|
1072 { |
|
1073 WRITELOG( "CHarvesterAO::HarvestingCompleted() - KMdEErrHarvestingFailedPermanent - no need to re-harvest!" ); |
|
1074 |
|
1075 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeMMC, 1 ) ); |
|
1076 |
|
1077 delete aHD; |
|
1078 aHD = NULL; |
|
1079 return; |
|
1080 } |
|
1081 else |
|
1082 { |
|
1083 WRITELOG1( "CHarvesterAO::HarvestingCompleted() - unknown error: %d", errorCode ); |
|
1084 } |
|
1085 |
|
1086 WRITELOG( "==============================ERROR done =========================" ); |
|
1087 } |
|
1088 |
|
1089 SetNextRequest( ERequestHarvest ); |
|
1090 } |
|
1091 |
|
1092 // --------------------------------------------------------------------------- |
|
1093 // HandleSessionOpened |
|
1094 // --------------------------------------------------------------------------- |
|
1095 // |
|
1096 void CHarvesterAO::HandleSessionOpened( CMdESession& aSession, TInt aError ) |
|
1097 { |
|
1098 WRITELOG( "HarvesterThread::HandleSessionOpened()" ); |
|
1099 if ( KErrNone == aError ) |
|
1100 { |
|
1101 TBool isTNMDaemonEnabled( EFalse ); |
|
1102 TRAP_IGNORE( CHarvesterCenRepUtil::IsThumbnailDaemonEnabledL( isTNMDaemonEnabled ) ); |
|
1103 |
|
1104 if( isTNMDaemonEnabled ) |
|
1105 { |
|
1106 StartThumbAGDaemon(); |
|
1107 } |
|
1108 |
|
1109 TRAPD( errorTrap, iMdEHarvesterSession = CMdEHarvesterSession::NewL( *iMdESession ) ); |
|
1110 if ( errorTrap == KErrNone ) |
|
1111 { |
|
1112 iMdeSessionInitialized = ETrue; |
|
1113 } |
|
1114 else |
|
1115 { |
|
1116 WRITELOG( "CHarvesterAO::HandleSessionOpened() - error creating mde harvester session" ); |
|
1117 } |
|
1118 #ifdef _DEBUG |
|
1119 TRAP( errorTrap, PreallocateNamespaceL( aSession.GetDefaultNamespaceDefL() ) ); |
|
1120 if ( errorTrap != KErrNone ) |
|
1121 { |
|
1122 WRITELOG( "CHarvesterAO::HandleSessionOpened() - error loading default schema" ); |
|
1123 } |
|
1124 |
|
1125 // Setting up monitor plugins |
|
1126 TRAP( errorTrap, LoadMonitorPluginsL() ); |
|
1127 if ( errorTrap != KErrNone ) |
|
1128 { |
|
1129 WRITELOG( "CHarvesterAO::HandleSessionOpened() - error loading monitor plugins" ); |
|
1130 } |
|
1131 |
|
1132 TRAP( errorTrap, StartComposersL() ); |
|
1133 if ( errorTrap != KErrNone ) |
|
1134 { |
|
1135 WRITELOG( "CHarvesterAO::HandleSessionOpened() - couldn't start composer plugins" ); |
|
1136 } |
|
1137 #else |
|
1138 // The idea here is that all of these three methods needs to be called, |
|
1139 // even if some leave, thus the three TRAPs |
|
1140 TRAP_IGNORE( PreallocateNamespaceL( aSession.GetDefaultNamespaceDefL() ) ); |
|
1141 TRAP_IGNORE( LoadMonitorPluginsL() ); |
|
1142 TRAP_IGNORE( StartComposersL() ); |
|
1143 |
|
1144 #endif |
|
1145 |
|
1146 if ( iContextEngineInitialized ) |
|
1147 { |
|
1148 iCtxEngine->SetMdeSession( iMdESession ); |
|
1149 } |
|
1150 |
|
1151 // Starting monitor plugins |
|
1152 StartMonitoring(); |
|
1153 |
|
1154 TRAP( errorTrap, iOnDemandAO = COnDemandAO::NewL( *iMdESession, *iQueue, |
|
1155 *iHarvesterPluginFactory, &iReadyPHArray ) ); |
|
1156 if ( errorTrap == KErrNone ) |
|
1157 { |
|
1158 TRAP( errorTrap, iOnDemandAO->StartL() ); |
|
1159 if ( errorTrap != KErrNone ) |
|
1160 { |
|
1161 WRITELOG( "CHarvesterAO::HandleSessionOpened() - couldn't start on demand observer" ); |
|
1162 } |
|
1163 } |
|
1164 else |
|
1165 { |
|
1166 WRITELOG( "CHarvesterAO::HandleSessionOpened() - couldn't create on demand observer" ); |
|
1167 } |
|
1168 |
|
1169 TRAPD( ohTrap, iMdeObjectHandler = CMdeObjectHandler::NewL( *iMdESession ) ); |
|
1170 if ( ohTrap != KErrNone ) |
|
1171 { |
|
1172 WRITELOG( "CHarvesterAO::HandleSessionOpened() - ObjectHandler creation failed" ); |
|
1173 } |
|
1174 |
|
1175 // Initializing pause indicator |
|
1176 iServerPaused = EFalse; |
|
1177 #ifdef _DEBUG |
|
1178 WRITELOG( "HarvesterThread::HandleSessionOpened() - Succeeded!" ); |
|
1179 |
|
1180 TBool isRomScanEnabled( EFalse ); |
|
1181 TRAP_IGNORE( CHarvesterCenRepUtil::IsRomScanEnabledL( isRomScanEnabled ) ); |
|
1182 |
|
1183 if( isRomScanEnabled ) |
|
1184 { |
|
1185 TRAP( errorTrap, BootRomScanL() ); |
|
1186 if( errorTrap != KErrNone ) |
|
1187 { |
|
1188 WRITELOG1( "CHarvesterAO::HandleSessionOpened() - BootRomScanL() returned error: %d", errorTrap ); |
|
1189 } |
|
1190 } |
|
1191 |
|
1192 TRAP( errorTrap, BootPartialRestoreScanL() ); |
|
1193 if( errorTrap != KErrNone ) |
|
1194 { |
|
1195 WRITELOG1( "CHarvesterAO::HandleSessionOpened() - BootPartialRestoreScanL() returned error: %d", errorTrap ); |
|
1196 } |
|
1197 #else |
|
1198 // The idea here is that all of these three methods needs to be called, |
|
1199 // even if some leave, thus the two TRAPs |
|
1200 TBool isRomScanEnabled( EFalse ); |
|
1201 TRAP_IGNORE( CHarvesterCenRepUtil::IsRomScanEnabledL( isRomScanEnabled ) ); |
|
1202 |
|
1203 if( isRomScanEnabled ) |
|
1204 { |
|
1205 TRAP_IGNORE( BootRomScanL() ); |
|
1206 } |
|
1207 TRAP_IGNORE( BootPartialRestoreScanL() ); |
|
1208 #endif |
|
1209 } |
|
1210 else |
|
1211 { |
|
1212 iServerPaused = ETrue; |
|
1213 WRITELOG1( "HarvesterThread::HandleSessionOpened() - Failed: %d!", aError ); |
|
1214 } |
|
1215 } |
|
1216 |
|
1217 // --------------------------------------------------------------------------- |
|
1218 // HandleSessionError |
|
1219 // --------------------------------------------------------------------------- |
|
1220 // |
|
1221 void CHarvesterAO::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
|
1222 { |
|
1223 if ( KErrNone != aError ) |
|
1224 { |
|
1225 WRITELOG1( "HarvesterThread::HandleSessionError() - Error: %d!", aError ); |
|
1226 } |
|
1227 } |
|
1228 |
|
1229 // --------------------------------------------------------------------------- |
|
1230 // ContextInitializationStatus |
|
1231 // --------------------------------------------------------------------------- |
|
1232 // |
|
1233 void CHarvesterAO::ContextInitializationStatus( TInt aErrorCode ) |
|
1234 { |
|
1235 WRITELOG( "CHarvesterAO::ContextInitializationStatus()" ); |
|
1236 |
|
1237 if ( KErrNone == aErrorCode ) |
|
1238 { |
|
1239 WRITELOG( "HarvesterThread::ContextInitializationStatus() - Succeeded!" ); |
|
1240 iContextEngineInitialized = ETrue; |
|
1241 if ( iMdeSessionInitialized ) |
|
1242 { |
|
1243 iCtxEngine->SetMdeSession( iMdESession ); |
|
1244 } |
|
1245 } |
|
1246 else |
|
1247 { |
|
1248 WRITELOG1( "HarvesterThread::ContextInitializationStatus() - Failed: %d!", aErrorCode ); |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 // --------------------------------------------------------------------------- |
|
1253 // PauseHarvester |
|
1254 // --------------------------------------------------------------------------- |
|
1255 // |
|
1256 TInt CHarvesterAO::PauseHarvester() |
|
1257 { |
|
1258 WRITELOG( "CHarvesterAO::PauseHarvester()" ); |
|
1259 |
|
1260 iServerPaused = ETrue; |
|
1261 |
|
1262 // Everything is paused |
|
1263 WRITELOG( "CHarvesterAO::PauseHarvester() - Moving paused state paused" ); |
|
1264 |
|
1265 return KErrNone; |
|
1266 } |
|
1267 |
|
1268 // --------------------------------------------------------------------------- |
|
1269 // ResumeHarvester |
|
1270 // --------------------------------------------------------------------------- |
|
1271 // |
|
1272 void CHarvesterAO::ResumeHarvesterL() |
|
1273 { |
|
1274 WRITELOG( "CHarvesterAO::ResumeHarvesterL()" ); |
|
1275 |
|
1276 iServerPaused = EFalse; |
|
1277 |
|
1278 SetNextRequest( ERequestHarvest ); |
|
1279 } |
|
1280 |
|
1281 // --------------------------------------------------------------------------- |
|
1282 // RunL |
|
1283 // --------------------------------------------------------------------------- |
|
1284 // |
|
1285 void CHarvesterAO::RunL() |
|
1286 { |
|
1287 WRITELOG( "CHarvesterAO::RunL" ); |
|
1288 // check if pause is requested |
|
1289 if ( this->iServerPaused && iNextRequest != ERequestPause && iNextRequest != ERequestResume) |
|
1290 { |
|
1291 iNextRequest = ERequestIdle; |
|
1292 } |
|
1293 User::LeaveIfError( iStatus.Int() ); |
|
1294 switch( iNextRequest ) |
|
1295 { |
|
1296 // no more items in queue |
|
1297 case ERequestIdle: |
|
1298 { |
|
1299 WRITELOG( "CHarvesterAO::RunL - ERequestIdle" ); |
|
1300 } |
|
1301 break; |
|
1302 |
|
1303 // data added to harvester queue |
|
1304 case ERequestHarvest: |
|
1305 { |
|
1306 WRITELOG( "CHarvesterAO::RunL - ERequestHarvest" ); |
|
1307 |
|
1308 // harvest new items first... |
|
1309 if ( iQueue->ItemsInQueue() > 0 ) |
|
1310 { |
|
1311 if ( !iHarvesting ) |
|
1312 { |
|
1313 iHarvesting = ETrue; |
|
1314 iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateStarted ); |
|
1315 // This next line is for caching the harvester started event for observers registering |
|
1316 // after harvesting has already started |
|
1317 iHarvesterEventManager->IncreaseItemCount( EHEObserverTypeOverall, KCacheItemCountForEventCaching ); |
|
1318 } |
|
1319 |
|
1320 ReadItemFromQueueL(); |
|
1321 SetNextRequest( ERequestHarvest ); |
|
1322 } |
|
1323 |
|
1324 // no more items to harvest |
|
1325 else |
|
1326 { |
|
1327 |
|
1328 // if container files to harvest, handle those |
|
1329 if( iContainerPHArray.Count() > 0 ) |
|
1330 { |
|
1331 SetNextRequest( ERequestContainerPlaceholder ); |
|
1332 break; |
|
1333 } |
|
1334 |
|
1335 if(iReadyPHArray.Count() > 0) |
|
1336 { |
|
1337 #ifdef _DEBUG |
|
1338 WRITELOG1("CHarvesterAO::RunL - items in ready pharray: %d", iReadyPHArray.Count() ); |
|
1339 #endif |
|
1340 for ( TInt i = iReadyPHArray.Count(); --i >= 0; ) |
|
1341 { |
|
1342 CheckFileExtensionAndHarvestL( iReadyPHArray[i] ); |
|
1343 iReadyPHArray.Remove( i ); |
|
1344 } |
|
1345 iReadyPHArray.Reset(); |
|
1346 } |
|
1347 |
|
1348 if ( iHarvesting && !UnharvestedItemsLeftInPlugins() && |
|
1349 !iReHarvester->ItemsInQueue() ) |
|
1350 { |
|
1351 iHarvesting = EFalse; |
|
1352 iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateFinished ); |
|
1353 iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypeOverall, KCacheItemCountForEventCaching ); |
|
1354 iReadyPHArray.Compress(); |
|
1355 iContainerPHArray.Compress(); |
|
1356 iPHArray.Compress(); |
|
1357 } |
|
1358 |
|
1359 SetNextRequest( ERequestIdle ); |
|
1360 } |
|
1361 } |
|
1362 break; |
|
1363 |
|
1364 case ERequestContainerPlaceholder: |
|
1365 { |
|
1366 #ifdef _DEBUG |
|
1367 WRITELOG( "CHarvesterAO::RunL - ERequestContainerPlaceholder" ); |
|
1368 WRITELOG1( "CHarvesterAO::RunL - Items in container pharray: %d", iContainerPHArray.Count() ); |
|
1369 #endif |
|
1370 TInt count = iContainerPHArray.Count() > KContainerPlaceholderQueueSize ? KContainerPlaceholderQueueSize : iContainerPHArray.Count(); |
|
1371 TInt i = 0; |
|
1372 while( i < count ) |
|
1373 { |
|
1374 CHarvesterData* hd = iContainerPHArray[0]; |
|
1375 iPHArray.Append( hd ); |
|
1376 iContainerPHArray.Remove( 0 ); |
|
1377 i++; |
|
1378 } |
|
1379 TRAPD( err, HandlePlaceholdersL( EFalse ) ); |
|
1380 |
|
1381 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
|
1382 if ( err != KErrNone ) |
|
1383 { |
|
1384 iPHArray.ResetAndDestroy(); |
|
1385 User::Leave( err ); |
|
1386 } |
|
1387 SetNextRequest( ERequestHarvest ); |
|
1388 } |
|
1389 break; |
|
1390 |
|
1391 // pause request |
|
1392 case ERequestPause: |
|
1393 { |
|
1394 WRITELOG( "CHarvesterAO::RunL - ERequestPause" ); |
|
1395 User::LeaveIfError( PauseHarvester() ); |
|
1396 iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStatePaused ); |
|
1397 if( iHarvesterStatusObserver ) |
|
1398 { |
|
1399 iHarvesterStatusObserver->PauseReady( KErrNone ); |
|
1400 } |
|
1401 } |
|
1402 break; |
|
1403 |
|
1404 // resume request |
|
1405 case ERequestResume: |
|
1406 { |
|
1407 WRITELOG( "CHarvesterAO::RunL - ERequestResume" ); |
|
1408 ResumeHarvesterL(); |
|
1409 iHarvesterEventManager->SendEventL( EHEObserverTypeOverall, EHEStateResumed ); |
|
1410 if( iHarvesterStatusObserver ) |
|
1411 { |
|
1412 iHarvesterStatusObserver->ResumeReady( KErrNone ); |
|
1413 } |
|
1414 SetNextRequest( ERequestHarvest ); |
|
1415 } |
|
1416 break; |
|
1417 |
|
1418 default: |
|
1419 { |
|
1420 WRITELOG( "CHarvesterAO::RunL - Not supported request" ); |
|
1421 User::Leave( KErrNotSupported ); |
|
1422 } |
|
1423 break; |
|
1424 } |
|
1425 } |
|
1426 |
|
1427 // --------------------------------------------------------------------------- |
|
1428 // DoCancel |
|
1429 // --------------------------------------------------------------------------- |
|
1430 // |
|
1431 void CHarvesterAO::DoCancel() |
|
1432 { |
|
1433 WRITELOG( "CHarvesterAO::DoCancel()" ); |
|
1434 } |
|
1435 |
|
1436 // --------------------------------------------------------------------------- |
|
1437 // RunError |
|
1438 // --------------------------------------------------------------------------- |
|
1439 // |
|
1440 TInt CHarvesterAO::RunError( TInt aError ) |
|
1441 { |
|
1442 WRITELOG( "CHarvesterAO::RunError" ); |
|
1443 switch( iNextRequest ) |
|
1444 { |
|
1445 case ERequestHarvest: |
|
1446 { |
|
1447 WRITELOG( "CHarvesterAO::RunError - state ERequestHarvest" ); |
|
1448 } |
|
1449 break; |
|
1450 |
|
1451 case ERequestPause: |
|
1452 { |
|
1453 WRITELOG( "CHarvesterAO::RunError - state ERequestPause" ); |
|
1454 if ( aError == KErrNotReady ) |
|
1455 { |
|
1456 SetNextRequest( ERequestPause ); |
|
1457 } |
|
1458 else if( iHarvesterStatusObserver ) |
|
1459 { |
|
1460 iHarvesterStatusObserver->PauseReady( aError ); |
|
1461 } |
|
1462 } |
|
1463 break; |
|
1464 |
|
1465 case ERequestResume: |
|
1466 { |
|
1467 WRITELOG( "CHarvesterAO::RunError - state ERequestResume" ); |
|
1468 if( iHarvesterStatusObserver ) |
|
1469 { |
|
1470 iHarvesterStatusObserver->ResumeReady( aError ); |
|
1471 } |
|
1472 } |
|
1473 break; |
|
1474 |
|
1475 default: |
|
1476 { |
|
1477 WRITELOG( "CHarvesterAO::RunError - unknown state" ); |
|
1478 } |
|
1479 break; |
|
1480 } |
|
1481 |
|
1482 return KErrNone; |
|
1483 } |
|
1484 |
|
1485 // --------------------------------------------------------------------------- |
|
1486 // SetNextRequest |
|
1487 // --------------------------------------------------------------------------- |
|
1488 // |
|
1489 void CHarvesterAO::SetNextRequest( TRequest aRequest ) |
|
1490 { |
|
1491 WRITELOG( "CHarvesterAO::SetNextRequest" ); |
|
1492 iNextRequest = aRequest; |
|
1493 |
|
1494 if ( !IsActive() ) |
|
1495 { |
|
1496 iStatus = KRequestPending; |
|
1497 SetActive(); |
|
1498 TRequestStatus* ptrStatus = &iStatus; |
|
1499 User::RequestComplete( ptrStatus, KErrNone ); |
|
1500 } |
|
1501 } |
|
1502 |
|
1503 // --------------------------------------------------------------------------- |
|
1504 // IsServerPaused |
|
1505 // --------------------------------------------------------------------------- |
|
1506 // |
|
1507 TBool CHarvesterAO::IsServerPaused() |
|
1508 { |
|
1509 WRITELOG( "CHarvesterAO::IsServerPaused" ); |
|
1510 return iServerPaused; |
|
1511 } |
|
1512 |
|
1513 // --------------------------------------------------------------------------- |
|
1514 // From MBackupRestoreObserver. |
|
1515 // Called by CBlacklistBackupSubscriberAO when |
|
1516 // Backup&Restore is backing up or restoring. |
|
1517 // --------------------------------------------------------------------------- |
|
1518 // |
|
1519 void CHarvesterAO::BackupRestoreStart() |
|
1520 { |
|
1521 // close blacklist database connection |
|
1522 WRITELOG( "CHarvesterAO::BackupRestoreStart" ); |
|
1523 iBlacklist->CloseDatabase(); |
|
1524 } |
|
1525 |
|
1526 // --------------------------------------------------------------------------- |
|
1527 // From MBackupRestoreObserver. |
|
1528 // Called by CBlacklistBackupSubscriberAO when |
|
1529 // Backup&Restore has finished backup or restore. |
|
1530 // --------------------------------------------------------------------------- |
|
1531 // |
|
1532 void CHarvesterAO::BackupRestoreReady() |
|
1533 { |
|
1534 // restart blacklist database connection |
|
1535 WRITELOG( "CHarvesterAO::BackupRestoreReady" ); |
|
1536 iBlacklist->OpenDatabase(); |
|
1537 } |
|
1538 |
|
1539 // --------------------------------------------------------------------------- |
|
1540 // HarvestFile |
|
1541 // --------------------------------------------------------------------------- |
|
1542 // |
|
1543 void CHarvesterAO::HarvestFile( const RMessage2& aMessage ) |
|
1544 { |
|
1545 WRITELOG( "CHarvesterAO::HarvestFile" ); |
|
1546 const TInt KParamUri = 0; |
|
1547 const TInt KParamAlbumIds = 1; |
|
1548 const TInt KParamAddLocation = 2; |
|
1549 |
|
1550 // read uri |
|
1551 HBufC* uri = HBufC::New( KMaxFileName ); |
|
1552 |
|
1553 if ( ! uri ) |
|
1554 { |
|
1555 WRITELOG( "CHarvesterAO::HarvestFile - out of memory creating uri container" ); |
|
1556 if (!aMessage.IsNull()) |
|
1557 { |
|
1558 aMessage.Complete( KErrNoMemory ); |
|
1559 } |
|
1560 return; |
|
1561 } |
|
1562 |
|
1563 TPtr uriPtr( uri->Des() ); |
|
1564 TInt err = aMessage.Read( KParamUri, uriPtr ); |
|
1565 if ( err != KErrNone ) |
|
1566 { |
|
1567 WRITELOG1( "CHarvesterAO::HarvestFile - error in reading aMessage (uri): %d", err ); |
|
1568 if (!aMessage.IsNull()) |
|
1569 { |
|
1570 aMessage.Complete( err ); |
|
1571 } |
|
1572 delete uri; |
|
1573 uri = NULL; |
|
1574 return; |
|
1575 } |
|
1576 WRITELOG1( "CHarvesterAO::HarvestFile - uri: %S", uri ); |
|
1577 |
|
1578 // read album ids |
|
1579 RArray<TItemId> albumIds; |
|
1580 const TInt KAlbumIdsLength = aMessage.GetDesLength( KParamAlbumIds ); |
|
1581 if ( KAlbumIdsLength > 0 ) |
|
1582 { |
|
1583 HBufC8* albumIdBuf = HBufC8::New( KAlbumIdsLength ); |
|
1584 if ( !albumIdBuf ) |
|
1585 { |
|
1586 WRITELOG( "CHarvesterAO::HarvestFile - error creating album id buffer." ); |
|
1587 if (!aMessage.IsNull()) |
|
1588 { |
|
1589 aMessage.Complete( KErrNoMemory ); |
|
1590 } |
|
1591 delete uri; |
|
1592 uri = NULL; |
|
1593 return; |
|
1594 } |
|
1595 TPtr8 ptr( albumIdBuf->Des() ); |
|
1596 err = aMessage.Read( KParamAlbumIds, ptr ); |
|
1597 if ( err != KErrNone ) |
|
1598 { |
|
1599 WRITELOG1( "CHarvesterAO::HarvestFile - error in reading aMessage (albumIds): %d", err ); |
|
1600 delete albumIdBuf; |
|
1601 albumIdBuf = NULL; |
|
1602 delete uri; |
|
1603 uri = NULL; |
|
1604 if (!aMessage.IsNull()) |
|
1605 { |
|
1606 aMessage.Complete( err ); |
|
1607 } |
|
1608 return; |
|
1609 } |
|
1610 |
|
1611 TRAPD( err, DeserializeArrayL( ptr, albumIds ) ); |
|
1612 if ( err != KErrNone ) |
|
1613 { |
|
1614 WRITELOG1( "CHarvesterAO::HarvestFile - error in reading album id array: %d", err ); |
|
1615 delete albumIdBuf; |
|
1616 albumIdBuf = NULL; |
|
1617 delete uri; |
|
1618 uri = NULL; |
|
1619 if (!aMessage.IsNull()) |
|
1620 { |
|
1621 aMessage.Complete( err ); |
|
1622 } |
|
1623 return; |
|
1624 } |
|
1625 |
|
1626 #ifdef _DEBUG |
|
1627 const TInt count = albumIds.Count(); |
|
1628 for (TInt i = 0; i < count; ++i) |
|
1629 { |
|
1630 WRITELOG2( "RHarvesterClient::HarvestFile - album id[%d]: %d", i, albumIds[i] ); |
|
1631 } |
|
1632 #endif |
|
1633 |
|
1634 delete albumIdBuf; |
|
1635 albumIdBuf = NULL; |
|
1636 |
|
1637 WRITELOG1( "CHarvesterAO::HarvestFile - album id count: %d", albumIds.Count() ); |
|
1638 } |
|
1639 |
|
1640 TBool addLocation; |
|
1641 TPckg<TBool> location( addLocation ); |
|
1642 err = aMessage.Read(KParamAddLocation, location); |
|
1643 if ( err != KErrNone ) |
|
1644 { |
|
1645 WRITELOG1( "CHarvesterAO::HarvestFile - error in reading aMessage (addLocation): %d", err ); |
|
1646 delete uri; |
|
1647 uri = NULL; |
|
1648 if (!aMessage.IsNull()) |
|
1649 { |
|
1650 aMessage.Complete( err ); |
|
1651 } |
|
1652 return; |
|
1653 } |
|
1654 |
|
1655 WRITELOG1( "RHarvesterClient::HarvestFile - add location: %d", addLocation ); |
|
1656 |
|
1657 CHarvesterData* hd = NULL; |
|
1658 TRAP( err, hd = CHarvesterData::NewL( uri ) ); |
|
1659 if ( err != KErrNone ) |
|
1660 { |
|
1661 WRITELOG( "CHarvesterAO::HarvestFile - creating harvUri failed" ); |
|
1662 albumIds.Close(); |
|
1663 delete uri; |
|
1664 uri = NULL; |
|
1665 if (!aMessage.IsNull()) |
|
1666 { |
|
1667 aMessage.Complete( err ); |
|
1668 } |
|
1669 return; |
|
1670 } |
|
1671 |
|
1672 hd->SetEventType( EHarvesterAdd ); |
|
1673 hd->SetOrigin( MdeConstants::Object::ECamera ); |
|
1674 hd->SetObjectType( EPlaceholder ); |
|
1675 hd->SetTakeSnapshot( ETrue ); |
|
1676 hd->SetClientId( aMessage.Identity() ); |
|
1677 hd->SetAddLocation( addLocation ); |
|
1678 |
|
1679 CHarvestClientData* clientData = CHarvestClientData::New(); |
|
1680 if ( clientData ) |
|
1681 { |
|
1682 clientData->SetAlbumIds( albumIds ); |
|
1683 hd->SetClientData( clientData ); // ownership is transferred |
|
1684 } |
|
1685 else |
|
1686 { |
|
1687 WRITELOG( "CHarvesterAO::HarvestFile - creating clientData failed" ); |
|
1688 } |
|
1689 |
|
1690 if( iQueue && hd ) |
|
1691 { |
|
1692 iQueue->Append( hd ); |
|
1693 |
|
1694 // signal to start harvest if harvester idles |
|
1695 if ( !IsServerPaused() ) |
|
1696 { |
|
1697 SetNextRequest( CHarvesterAO::ERequestHarvest ); |
|
1698 } |
|
1699 } |
|
1700 else |
|
1701 { |
|
1702 err = KErrUnknown; |
|
1703 } |
|
1704 |
|
1705 if (!aMessage.IsNull()) |
|
1706 { |
|
1707 aMessage.Complete( err ); |
|
1708 } |
|
1709 |
|
1710 albumIds.Close(); |
|
1711 } |
|
1712 |
|
1713 // --------------------------------------------------------------------------- |
|
1714 // HarvestFileWithUID |
|
1715 // --------------------------------------------------------------------------- |
|
1716 // |
|
1717 void CHarvesterAO::HarvestFileWithUID( const RMessage2& aMessage ) |
|
1718 { |
|
1719 WRITELOG( "CHarvesterAO::HarvestFileWithUID" ); |
|
1720 const TInt KParamUri = 0; |
|
1721 const TInt KParamAlbumIds = 1; |
|
1722 const TInt KParamAddLocation = 2; |
|
1723 |
|
1724 // read uri |
|
1725 HBufC* uri = HBufC::New( KMaxFileName ); |
|
1726 |
|
1727 if ( ! uri ) |
|
1728 { |
|
1729 WRITELOG( "CHarvesterAO::HarvestFileWithUID - out of memory creating uri container" ); |
|
1730 if (!aMessage.IsNull()) |
|
1731 { |
|
1732 aMessage.Complete( KErrNoMemory ); |
|
1733 } |
|
1734 return; |
|
1735 } |
|
1736 |
|
1737 TPtr uriPtr( uri->Des() ); |
|
1738 TInt err = aMessage.Read( KParamUri, uriPtr ); |
|
1739 if ( err != KErrNone ) |
|
1740 { |
|
1741 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - error in reading aMessage (uri): %d", err ); |
|
1742 if (!aMessage.IsNull()) |
|
1743 { |
|
1744 aMessage.Complete( err ); |
|
1745 } |
|
1746 delete uri; |
|
1747 uri = NULL; |
|
1748 return; |
|
1749 } |
|
1750 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - uri: %S", uri ); |
|
1751 |
|
1752 // read album ids |
|
1753 RArray<TItemId> albumIds; |
|
1754 const TInt KAlbumIdsLength = aMessage.GetDesLength( KParamAlbumIds ); |
|
1755 if ( KAlbumIdsLength > 0 ) |
|
1756 { |
|
1757 HBufC8* albumIdBuf = HBufC8::New( KAlbumIdsLength ); |
|
1758 if ( !albumIdBuf ) |
|
1759 { |
|
1760 WRITELOG( "CHarvesterAO::HarvestFileWithUID - error creating album id buffer." ); |
|
1761 if (!aMessage.IsNull()) |
|
1762 { |
|
1763 aMessage.Complete( KErrNoMemory ); |
|
1764 } |
|
1765 delete uri; |
|
1766 uri = NULL; |
|
1767 return; |
|
1768 } |
|
1769 TPtr8 ptr( albumIdBuf->Des() ); |
|
1770 err = aMessage.Read( KParamAlbumIds, ptr ); |
|
1771 if ( err != KErrNone ) |
|
1772 { |
|
1773 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - error in reading aMessage (albumIds): %d", err ); |
|
1774 delete albumIdBuf; |
|
1775 albumIdBuf = NULL; |
|
1776 delete uri; |
|
1777 uri = NULL; |
|
1778 if (!aMessage.IsNull()) |
|
1779 { |
|
1780 aMessage.Complete( err ); |
|
1781 } |
|
1782 return; |
|
1783 } |
|
1784 |
|
1785 TRAPD( err, DeserializeArrayL( ptr, albumIds ) ); |
|
1786 if ( err != KErrNone ) |
|
1787 { |
|
1788 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - error in reading album id array: %d", err ); |
|
1789 delete albumIdBuf; |
|
1790 albumIdBuf = NULL; |
|
1791 delete uri; |
|
1792 uri = NULL; |
|
1793 if (!aMessage.IsNull()) |
|
1794 { |
|
1795 aMessage.Complete( err ); |
|
1796 } |
|
1797 return; |
|
1798 } |
|
1799 |
|
1800 #ifdef _DEBUG |
|
1801 const TInt count = albumIds.Count(); |
|
1802 for (TInt i = 0; i < count; ++i) |
|
1803 { |
|
1804 WRITELOG2( "RHarvesterClient::HarvestFileWithUID - album id[%d]: %d", i, albumIds[i] ); |
|
1805 } |
|
1806 #endif |
|
1807 |
|
1808 delete albumIdBuf; |
|
1809 albumIdBuf = NULL; |
|
1810 |
|
1811 #ifdef _DEBUG |
|
1812 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - album id count: %d", albumIds.Count() ); |
|
1813 #endif |
|
1814 } |
|
1815 |
|
1816 TBool addLocation; |
|
1817 TPckg<TBool> location( addLocation ); |
|
1818 err = aMessage.Read(KParamAddLocation, location); |
|
1819 if ( err != KErrNone ) |
|
1820 { |
|
1821 WRITELOG1( "CHarvesterAO::HarvestFileWithUID - error in reading aMessage (addLocation): %d", err ); |
|
1822 delete uri; |
|
1823 uri = NULL; |
|
1824 if (!aMessage.IsNull()) |
|
1825 { |
|
1826 aMessage.Complete( err ); |
|
1827 } |
|
1828 return; |
|
1829 } |
|
1830 |
|
1831 WRITELOG1( "RHarvesterClient::HarvestFileWithUID - add location: %d", addLocation ); |
|
1832 |
|
1833 CHarvesterData* hd = NULL; |
|
1834 TRAP( err, hd = CHarvesterData::NewL( uri ) ); |
|
1835 if ( err != KErrNone ) |
|
1836 { |
|
1837 WRITELOG( "CHarvesterAO::HarvestFileWithUID - creating harvUri failed" ); |
|
1838 albumIds.Close(); |
|
1839 delete uri; |
|
1840 uri = NULL; |
|
1841 if (!aMessage.IsNull()) |
|
1842 { |
|
1843 aMessage.Complete( err ); |
|
1844 } |
|
1845 return; |
|
1846 } |
|
1847 |
|
1848 hd->SetEventType( EHarvesterAdd ); |
|
1849 hd->SetOrigin( MdeConstants::Object::EOther ); |
|
1850 hd->SetObjectType( EPlaceholder ); |
|
1851 hd->SetTakeSnapshot( ETrue ); |
|
1852 hd->SetClientId( aMessage.Identity() ); |
|
1853 hd->SetAddLocation( addLocation ); |
|
1854 |
|
1855 CHarvestClientData* clientData = CHarvestClientData::New(); |
|
1856 if ( clientData ) |
|
1857 { |
|
1858 clientData->SetAlbumIds( albumIds ); |
|
1859 hd->SetClientData( clientData ); // ownership is transferred |
|
1860 } |
|
1861 else |
|
1862 { |
|
1863 WRITELOG( "CHarvesterAO::HarvestFileWithUID - creating clientData failed" ); |
|
1864 } |
|
1865 |
|
1866 if( iQueue && hd ) |
|
1867 { |
|
1868 iQueue->Append( hd ); |
|
1869 |
|
1870 // signal to start harvest if harvester idles |
|
1871 if ( !IsServerPaused() ) |
|
1872 { |
|
1873 SetNextRequest( CHarvesterAO::ERequestHarvest ); |
|
1874 } |
|
1875 } |
|
1876 else |
|
1877 { |
|
1878 err = KErrUnknown; |
|
1879 } |
|
1880 |
|
1881 if (!aMessage.IsNull()) |
|
1882 { |
|
1883 aMessage.Complete( err ); |
|
1884 } |
|
1885 |
|
1886 albumIds.Close(); |
|
1887 } |
|
1888 |
|
1889 // --------------------------------------------------------------------------- |
|
1890 // RegisterProcessOrigin() |
|
1891 // --------------------------------------------------------------------------- |
|
1892 // |
|
1893 void CHarvesterAO::RegisterProcessOrigin( const RMessage2& aMessage ) |
|
1894 { |
|
1895 WRITELOG( "CHarvesterAO::RegisterProcessOrigin" ); |
|
1896 |
|
1897 if ( !iProcessOriginMapper ) |
|
1898 { |
|
1899 WRITELOG( "CHarvesterAO::RegisterProcessOrigin - mapper not available." ); |
|
1900 if (!aMessage.IsNull()) |
|
1901 { |
|
1902 aMessage.Complete( KErrNotSupported ); |
|
1903 } |
|
1904 return; |
|
1905 } |
|
1906 |
|
1907 TUid processId = { 0 }; |
|
1908 processId.iUid = aMessage.Int0(); |
|
1909 if ( MdsUtils::IsValidProcessId( processId ) ) |
|
1910 { |
|
1911 WRITELOG1( "CHarvesterAO::RegisterProcessOrigin - error reading processId. Read: %d", processId.iUid ); |
|
1912 if (!aMessage.IsNull()) |
|
1913 { |
|
1914 aMessage.Complete( KErrCorrupt ); |
|
1915 } |
|
1916 return; |
|
1917 } |
|
1918 |
|
1919 // read origin |
|
1920 |
|
1921 TOrigin origin = STATIC_CAST( TOrigin, aMessage.Int1() ); |
|
1922 WRITELOG1( "CHarvesterAO::RegisterProcessOrigin - origin: %d", origin ); |
|
1923 if ( origin < 0 ) |
|
1924 { |
|
1925 WRITELOG( "CHarvesterAO::RegisterProcessOrigin - error reading origin from aMessage (negative)." ); |
|
1926 if (!aMessage.IsNull()) |
|
1927 { |
|
1928 aMessage.Complete( KErrCorrupt ); |
|
1929 } |
|
1930 return; |
|
1931 } |
|
1932 |
|
1933 TRAPD( err, iProcessOriginMapper->RegisterProcessL( processId, origin ) ); |
|
1934 if ( err != KErrNone ) |
|
1935 { |
|
1936 WRITELOG1( "CHarvesterAO::RegisterProcessOrigin - error registering mapping: %d", err ); |
|
1937 if (!aMessage.IsNull()) |
|
1938 { |
|
1939 aMessage.Complete( err ); |
|
1940 } |
|
1941 return; |
|
1942 } |
|
1943 if (!aMessage.IsNull()) |
|
1944 { |
|
1945 aMessage.Complete( KErrNone ); |
|
1946 } |
|
1947 } |
|
1948 |
|
1949 // --------------------------------------------------------------------------- |
|
1950 // UnregisterProcessOrigin() |
|
1951 // --------------------------------------------------------------------------- |
|
1952 // |
|
1953 void CHarvesterAO::UnregisterProcessOrigin( const RMessage2& aMessage ) |
|
1954 { |
|
1955 WRITELOG( "CHarvesterAO::UnregisterProcessOrigin" ); |
|
1956 |
|
1957 if ( !iProcessOriginMapper ) |
|
1958 { |
|
1959 WRITELOG( "CHarvesterAO::RegisterProcessOrigin - mapper not available." ); |
|
1960 if (!aMessage.IsNull()) |
|
1961 { |
|
1962 aMessage.Complete( KErrNotSupported ); |
|
1963 } |
|
1964 return; |
|
1965 } |
|
1966 |
|
1967 TUid processId = { 0 }; |
|
1968 processId.iUid = aMessage.Int0(); |
|
1969 if ( MdsUtils::IsValidProcessId( processId ) ) |
|
1970 { |
|
1971 WRITELOG1( "CHarvesterAO::UnregisterProcessOrigin - error reading processId. Read: %d", processId.iUid ); |
|
1972 if (!aMessage.IsNull()) |
|
1973 { |
|
1974 aMessage.Complete( KErrCorrupt ); |
|
1975 } |
|
1976 return; |
|
1977 } |
|
1978 |
|
1979 TRAPD( err, iProcessOriginMapper->UnregisterProcessL( processId ) ); |
|
1980 if ( err != KErrNone ) |
|
1981 { |
|
1982 WRITELOG1( "CHarvesterAO::UnregisterProcessOrigin - error unregistering mapping: %d", err ); |
|
1983 if (!aMessage.IsNull()) |
|
1984 { |
|
1985 aMessage.Complete( err ); |
|
1986 } |
|
1987 return; |
|
1988 } |
|
1989 if (!aMessage.IsNull()) |
|
1990 { |
|
1991 aMessage.Complete( KErrNone ); |
|
1992 } |
|
1993 } |
|
1994 |
|
1995 // --------------------------------------------------------------------------- |
|
1996 // RegisterHarvestComplete() |
|
1997 // --------------------------------------------------------------------------- |
|
1998 // |
|
1999 TInt CHarvesterAO::RegisterHarvestComplete( const CHarvesterServerSession& aSession, const RMessage2& aMessage ) |
|
2000 { |
|
2001 WRITELOG( "CHarvesterAO::RegisterHarvestComplete" ); |
|
2002 |
|
2003 return iHarvestFileMessages.Append( |
|
2004 THarvestFileRequest( aSession, aMessage ) ); |
|
2005 } |
|
2006 |
|
2007 // --------------------------------------------------------------------------- |
|
2008 // UnregisterHarvestComplete() |
|
2009 // --------------------------------------------------------------------------- |
|
2010 // |
|
2011 TInt CHarvesterAO::UnregisterHarvestComplete( const CHarvesterServerSession& aSession ) |
|
2012 { |
|
2013 WRITELOG( "CHarvesterAO::UnregisterHarvestComplete" ); |
|
2014 |
|
2015 TInt err( KErrNotFound ); |
|
2016 if ( iHarvestFileMessages.Count() > 0 ) |
|
2017 { |
|
2018 for ( TInt i = iHarvestFileMessages.Count()-1; i >= 0; --i ) |
|
2019 { |
|
2020 THarvestFileRequest& req = iHarvestFileMessages[i]; |
|
2021 |
|
2022 if ( req.iMessage.IsNull() ) |
|
2023 { |
|
2024 iHarvestFileMessages.Remove( i ); |
|
2025 continue; |
|
2026 } |
|
2027 |
|
2028 //if (aMessage.Identity() == msg.Identity()) |
|
2029 if( &req.iSession == &aSession ) |
|
2030 { |
|
2031 err = KErrNone; |
|
2032 if (!req.iMessage.IsNull()) |
|
2033 { |
|
2034 // cancels found request |
|
2035 req.iMessage.Complete( KErrCancel ); |
|
2036 } |
|
2037 iHarvestFileMessages.Remove( i ); |
|
2038 |
|
2039 if( iHarvestFileMessages.Count() == 0 ) |
|
2040 { |
|
2041 iHarvestFileMessages.Compress(); |
|
2042 } |
|
2043 } |
|
2044 } |
|
2045 } |
|
2046 |
|
2047 return err; |
|
2048 } |
|
2049 |
|
2050 // --------------------------------------------------------------------------- |
|
2051 // RegisterHarvesterEvent() |
|
2052 // --------------------------------------------------------------------------- |
|
2053 // |
|
2054 void CHarvesterAO::RegisterHarvesterEvent( const RMessage2& aMessage ) |
|
2055 { |
|
2056 WRITELOG( "CHarvesterAO::RegisterHarvesterEvent" ); |
|
2057 |
|
2058 TRAPD( err, iHarvesterEventManager->RegisterEventObserverL( aMessage ) ); |
|
2059 aMessage.Complete( err ); |
|
2060 } |
|
2061 |
|
2062 // --------------------------------------------------------------------------- |
|
2063 // UnregisterHarvesterEvent() |
|
2064 // --------------------------------------------------------------------------- |
|
2065 // |
|
2066 void CHarvesterAO::UnregisterHarvesterEvent( const RMessage2& aMessage ) |
|
2067 { |
|
2068 WRITELOG( "CHarvesterAO::UnregisterHarvesterEvent" ); |
|
2069 |
|
2070 const TInt err = iHarvesterEventManager->UnregisterEventObserver( aMessage ); |
|
2071 aMessage.Complete( err ); |
|
2072 } |
|
2073 |
|
2074 void CHarvesterAO::GetLastObserverId( const RMessage2& aMessage ) |
|
2075 { |
|
2076 WRITELOG( "CHarvesterAO::GetLastObserverId" ); |
|
2077 |
|
2078 TUint observerId = iHarvesterEventManager->GetLastClientId(); |
|
2079 |
|
2080 TPckg<TUint> pckgId( observerId ); |
|
2081 aMessage.Write( 0, pckgId ); |
|
2082 aMessage.Complete( KErrNone ); |
|
2083 } |
|
2084 |
|
2085 // --------------------------------------------------------------------------- |
|
2086 // ContextSnapshotStatus |
|
2087 // --------------------------------------------------------------------------- |
|
2088 // |
|
2089 void CHarvesterAO::ContextSnapshotStatus( CHarvesterData* aHD ) |
|
2090 { |
|
2091 WRITELOG( "CHarvesterAO::ContextSnapshotStatus()" ); |
|
2092 |
|
2093 HarvestCompleted( aHD->ClientId(), aHD->Uri(), aHD->ErrorCode() ); |
|
2094 |
|
2095 const TInt errorCode = aHD->ErrorCode(); |
|
2096 if( errorCode != KErrNone ) |
|
2097 { |
|
2098 WRITELOG1( "CHarvesterAO::ContextSnapshotStatus() - error occurred: %d", errorCode ); |
|
2099 } |
|
2100 else |
|
2101 { |
|
2102 WRITELOG( "CHarvesterAO::ContextSnapshotStatus() - successfully completed" ); |
|
2103 if( aHD->Origin() == MdeConstants::Object::ECamera ) |
|
2104 { |
|
2105 aHD->MdeObject().SetPlaceholder( EFalse ); |
|
2106 TRAPD(mdeError, iMdeObjectHandler->SetMetadataObjectL( *aHD ) ); |
|
2107 if(mdeError != KErrNone) |
|
2108 { |
|
2109 WRITELOG( "==============================ERROR===============================" ); |
|
2110 WRITELOG( "CHarvesterAO::HarvestingCompleted() - cannot set metadata object" ); |
|
2111 WRITELOG( "==============================ERROR done =========================" ); |
|
2112 } |
|
2113 } |
|
2114 } |
|
2115 |
|
2116 delete aHD; |
|
2117 } |
|
2118 |
|
2119 // --------------------------------------------------------------------------- |
|
2120 // IsConnectedToMde |
|
2121 // --------------------------------------------------------------------------- |
|
2122 // |
|
2123 TBool CHarvesterAO::IsConnectedToMde() |
|
2124 { |
|
2125 return iMdESession != NULL; |
|
2126 } |
|
2127 |
|
2128 // --------------------------------------------------------------------------- |
|
2129 // HarvestCompleted |
|
2130 // --------------------------------------------------------------------------- |
|
2131 // |
|
2132 void CHarvesterAO::HarvestCompleted( TUid aClientId, const TDesC& aUri, TInt aErr ) |
|
2133 { |
|
2134 const TInt KParamUri = 0; |
|
2135 // check if fast harvested file |
|
2136 if ( iHarvestFileMessages.Count() > 0 ) |
|
2137 { |
|
2138 for ( TInt i = iHarvestFileMessages.Count()-1; i >= 0; --i ) |
|
2139 { |
|
2140 RMessage2& msg = iHarvestFileMessages[i].iMessage; |
|
2141 if ( aClientId == msg.Identity() ) |
|
2142 { |
|
2143 WRITELOG1( "CHarvesterAO::HarvestingCompleted() - Completing Fast Harvest request! Error code: %d", aErr ); |
|
2144 if (!msg.IsNull()) |
|
2145 { |
|
2146 msg.Write( KParamUri, aUri ); |
|
2147 msg.Complete( aErr ); |
|
2148 } |
|
2149 else |
|
2150 { |
|
2151 WRITELOG("CHarvesterAO::HarvestingCompleted() NOT COMPLETING AS msg->iMessage->IsNull returns ETrue"); |
|
2152 } |
|
2153 iHarvestFileMessages.Remove( i ); |
|
2154 } |
|
2155 } |
|
2156 } |
|
2157 } |
|
2158 |
|
2159 void CHarvesterAO::BootRomScanL() |
|
2160 { |
|
2161 WRITELOG("CHarvesterAO::BootRomScanL()"); |
|
2162 |
|
2163 if( !iMdeSessionInitialized ) |
|
2164 { |
|
2165 return; |
|
2166 } |
|
2167 |
|
2168 RPointerArray<TScanItem> scanItems; |
|
2169 TCleanupItem cleanupItem( MdsUtils::CleanupPtrArray<TScanItem>, &scanItems ); |
|
2170 CleanupStack::PushL( cleanupItem ); |
|
2171 |
|
2172 CHarvesterCenRepUtil::GetScanItemsL( scanItems ); |
|
2173 |
|
2174 RPointerArray<HBufC> ignorePaths; |
|
2175 TCleanupItem cleanupItem2( MdsUtils::CleanupPtrArray<HBufC>, &ignorePaths ); |
|
2176 CleanupStack::PushL( cleanupItem2 ); |
|
2177 |
|
2178 CHarvesterCenRepUtil::GetIgnoredScanPathsL( ignorePaths ); |
|
2179 |
|
2180 BootScanL( scanItems, ignorePaths, ETrue ); |
|
2181 |
|
2182 CleanupStack::PopAndDestroy( &ignorePaths ); |
|
2183 CleanupStack::PopAndDestroy( &scanItems ); |
|
2184 } |
|
2185 |
|
2186 void CHarvesterAO::BootPartialRestoreScanL() |
|
2187 { |
|
2188 // check if partial restore was done before last boot |
|
2189 TBool partialRestore = iRestoreWatcher->Register(); |
|
2190 |
|
2191 if ( !partialRestore ) |
|
2192 { |
|
2193 return; |
|
2194 } |
|
2195 |
|
2196 if( !iMdeSessionInitialized ) |
|
2197 { |
|
2198 return; |
|
2199 } |
|
2200 |
|
2201 iMdEHarvesterSession->ChangeCDriveMediaId(); |
|
2202 |
|
2203 WRITELOG("CHarvesterAO::BootPartialRestoreScanL() - partial restore"); |
|
2204 |
|
2205 RPointerArray<TScanItem> scanItems; |
|
2206 TCleanupItem cleanupItem( MdsUtils::CleanupPtrArray<TScanItem>, &scanItems ); |
|
2207 CleanupStack::PushL( cleanupItem ); |
|
2208 |
|
2209 CHarvesterCenRepUtil::GetPartialRestorePathsL( scanItems ); |
|
2210 |
|
2211 RPointerArray<HBufC> ignorePaths; |
|
2212 TCleanupItem cleanupItem2( MdsUtils::CleanupPtrArray<HBufC>, &ignorePaths ); |
|
2213 CleanupStack::PushL( cleanupItem2 ); |
|
2214 |
|
2215 CHarvesterCenRepUtil::GetIgnoredPartialRestorePathsL( ignorePaths ); |
|
2216 |
|
2217 BootScanL( scanItems, ignorePaths, EFalse ); |
|
2218 |
|
2219 WRITELOG("CHarvesterAO::BootPartialRestoreScanL() - iRestoreWatcher->UnregisterL()"); |
|
2220 iRestoreWatcher->UnregisterL(); |
|
2221 |
|
2222 CleanupStack::PopAndDestroy( &ignorePaths ); |
|
2223 CleanupStack::PopAndDestroy( &scanItems ); |
|
2224 } |
|
2225 |
|
2226 TBool CHarvesterAO::IsDescInArray(const TPtrC& aSearch, const RPointerArray<HBufC>& aArray) |
|
2227 { |
|
2228 const TInt count = aArray.Count(); |
|
2229 |
|
2230 for( TInt i = 0; i < count; i++ ) |
|
2231 { |
|
2232 const TDesC& ignorePath = aArray[i]->Des(); |
|
2233 |
|
2234 TInt result = MdsUtils::Compare( aSearch, ignorePath ); |
|
2235 |
|
2236 if( result == 0 ) |
|
2237 { |
|
2238 return ETrue; |
|
2239 } |
|
2240 } |
|
2241 |
|
2242 return EFalse; |
|
2243 } |
|
2244 |
|
2245 void CHarvesterAO::BootScanL( RPointerArray<TScanItem>& aScanItems, |
|
2246 const RPointerArray<HBufC>& aIgnorePaths, |
|
2247 TBool aCheckDrive ) |
|
2248 { |
|
2249 WRITELOG("CHarvesterAO::BootScanL() - begin"); |
|
2250 |
|
2251 TVolumeInfo volumeInfo; |
|
2252 iFs.Volume( volumeInfo, EDriveC ); |
|
2253 |
|
2254 iMdEHarvesterSession->SetFilesToNotPresent( volumeInfo.iUniqueID, ETrue ); |
|
2255 |
|
2256 _LIT( KDirectorySeparator, "\\" ); |
|
2257 |
|
2258 #ifdef _DEBUG |
|
2259 WRITELOG1("CHarvesterAO::BootScanL() - item count: %d", aScanItems.Count() ); |
|
2260 #endif |
|
2261 |
|
2262 RPointerArray<CHarvesterData> hdArray; |
|
2263 CleanupClosePushL( hdArray ); |
|
2264 |
|
2265 while( aScanItems.Count() > 0 ) |
|
2266 { |
|
2267 HBufC* folder = aScanItems[0]->iPath; |
|
2268 TUint32 preinstalled = aScanItems[0]->iPreinstalled; |
|
2269 |
|
2270 CDir* directory = NULL; |
|
2271 TInt error = iFs.GetDir( folder->Des(), KEntryAttDir, KHarvesterGetDirFlags, directory ); |
|
2272 |
|
2273 if ( error == KErrNone ) |
|
2274 { |
|
2275 CleanupStack::PushL( directory ); |
|
2276 |
|
2277 TInt count = directory->Count(); |
|
2278 |
|
2279 TUint32 mediaId( 0 ); |
|
2280 |
|
2281 if( count > 0 ) |
|
2282 { |
|
2283 TInt drive = 0; |
|
2284 if( iFs.CharToDrive( (folder->Des())[0], drive ) == KErrNone ) |
|
2285 { |
|
2286 TVolumeInfo volInfo; |
|
2287 if( iFs.Volume( volInfo, drive ) == KErrNone ) |
|
2288 { |
|
2289 mediaId = volInfo.iUniqueID; |
|
2290 } |
|
2291 } |
|
2292 } |
|
2293 |
|
2294 for ( TInt i = 0; i < count; i++ ) |
|
2295 { |
|
2296 TEntry entry = (*directory)[i]; |
|
2297 |
|
2298 TInt length = folder->Length() + entry.iName.Length() + KDirectorySeparator().Length(); |
|
2299 HBufC* name = HBufC::NewLC( length ); |
|
2300 name->Des().Append( *folder ); |
|
2301 TPtrC ptr = *folder; |
|
2302 if( ptr[ ptr.Length() - 1 ] == TChar('\\') ) |
|
2303 { |
|
2304 name->Des().Append( entry.iName ); |
|
2305 } |
|
2306 |
|
2307 if ( entry.IsDir() ) |
|
2308 { |
|
2309 name->Des().Append( KDirectorySeparator ); |
|
2310 TPtrC path = *name; |
|
2311 if( !aCheckDrive ) |
|
2312 { |
|
2313 path.Set( (*name).Mid( 2 ) ); |
|
2314 } |
|
2315 if( !IsDescInArray( path, aIgnorePaths ) ) |
|
2316 { |
|
2317 WRITELOG("CHarvesterAO::BootScanL() - scanFolders.AppendL"); |
|
2318 TScanItem* item = new (ELeave) TScanItem(); |
|
2319 item->iPath = name->AllocL(); |
|
2320 item->iPreinstalled = MdeConstants::MediaObject::ENotPreinstalled; |
|
2321 aScanItems.AppendL( item ); |
|
2322 } |
|
2323 } |
|
2324 else |
|
2325 { |
|
2326 TPtrC filename = *name; |
|
2327 if( !aCheckDrive ) |
|
2328 { |
|
2329 filename.Set( (*name).Mid( 2 ) ); |
|
2330 } |
|
2331 if( !IsDescInArray( filename, aIgnorePaths ) ) |
|
2332 { |
|
2333 WRITELOG("CHarvesterAO::BootScanL() - check files"); |
|
2334 |
|
2335 RArray<TPtrC> uris; |
|
2336 RArray<TMdSFileInfo> fileInfos; |
|
2337 RArray<TFilePresentStates> results; |
|
2338 CleanupClosePushL( uris ); |
|
2339 CleanupClosePushL( fileInfos ); |
|
2340 CleanupClosePushL( results ); |
|
2341 |
|
2342 TMdSFileInfo fileInfo; |
|
2343 fileInfo.iModifiedTime = entry.iModified.Int64(); |
|
2344 fileInfo.iSize = entry.iSize; |
|
2345 fileInfos.Append( fileInfo ); |
|
2346 uris.Append( name->Des() ); |
|
2347 |
|
2348 TFilePresentStates found; |
|
2349 |
|
2350 if( mediaId == volumeInfo.iUniqueID ) |
|
2351 { |
|
2352 iMdEHarvesterSession->SetFilesToPresentL( volumeInfo.iUniqueID, uris, fileInfos, results ); |
|
2353 found = results[ 0 ]; |
|
2354 } |
|
2355 else |
|
2356 { |
|
2357 found = EMdsNotFound; |
|
2358 } |
|
2359 |
|
2360 // scan file if it was not found from DB, or if it has been modified |
|
2361 if( found == EMdsNotFound || |
|
2362 found == EMdsPlaceholder || |
|
2363 found == EMdsModified ) |
|
2364 { |
|
2365 CPlaceholderData* phData = CPlaceholderData::NewL(); |
|
2366 CleanupStack::PushL( phData ); |
|
2367 phData->SetUri( *name ); |
|
2368 phData->SetModified( entry.iModified ); |
|
2369 phData->SetFileSize( entry.iSize ); |
|
2370 phData->SetMediaId( mediaId ); |
|
2371 phData->SetPreinstalled( preinstalled ); |
|
2372 |
|
2373 CHarvesterData* hd = CHarvesterData::NewL( name->AllocL() ); |
|
2374 hd->SetEventType( EHarvesterAdd ); |
|
2375 hd->SetObjectType( EPlaceholder ); |
|
2376 hd->SetOrigin( MdeConstants::Object::EOther ); |
|
2377 hd->SetClientData( phData ); |
|
2378 |
|
2379 CleanupStack::Pop( phData ); |
|
2380 hdArray.Append( hd ); |
|
2381 } |
|
2382 CleanupStack::PopAndDestroy( &results ); |
|
2383 CleanupStack::PopAndDestroy( &fileInfos ); |
|
2384 CleanupStack::PopAndDestroy( &uris ); |
|
2385 } |
|
2386 } |
|
2387 CleanupStack::PopAndDestroy( name ); |
|
2388 } |
|
2389 |
|
2390 CleanupStack::PopAndDestroy( directory ); |
|
2391 } |
|
2392 folder = NULL; |
|
2393 delete aScanItems[0]; |
|
2394 aScanItems.Remove( 0 ); |
|
2395 } |
|
2396 |
|
2397 WRITELOG("CHarvesterAO::BootScanL() - iQueue->Append"); |
|
2398 iQueue->MonitorEvent( hdArray ); |
|
2399 CleanupStack::PopAndDestroy( &hdArray ); |
|
2400 |
|
2401 iMdEHarvesterSession->RemoveFilesNotPresent( volumeInfo.iUniqueID, ETrue ); |
|
2402 |
|
2403 WRITELOG("CHarvesterAO::BootScanL() - end"); |
|
2404 } |
|
2405 |
|
2406 void CHarvesterAO::SetHarvesterStatusObserver( MHarvesterStatusObserver* aObserver ) |
|
2407 { |
|
2408 iHarvesterStatusObserver = aObserver; |
|
2409 } |
|
2410 |
|
2411 TBool CHarvesterAO::UnharvestedItemsLeftInPlugins() |
|
2412 { |
|
2413 RPointerArray<CHarvesterPluginInfo>& infos = iHarvesterPluginFactory->GetPluginInfos(); |
|
2414 TInt count = infos.Count(); |
|
2415 for ( TInt i = count; --i >= 0; ) |
|
2416 { |
|
2417 if ( infos[i]->iQueue.Count() > 0 ) |
|
2418 { |
|
2419 return ETrue; |
|
2420 } |
|
2421 } |
|
2422 |
|
2423 return EFalse; |
|
2424 } |
|
2425 |
|
2426 void CHarvesterAO::PreallocateNamespaceL( CMdENamespaceDef& aNamespaceDef ) |
|
2427 { |
|
2428 const TInt objectDefCount = aNamespaceDef.ObjectDefCount(); |
|
2429 |
|
2430 for( TInt i = 0; i < objectDefCount; i++ ) |
|
2431 { |
|
2432 CMdEObjectDef& objectDef = aNamespaceDef.ObjectDefL( i ); |
|
2433 |
|
2434 const TInt propertyDefCount = objectDef.PropertyDefCount(); |
|
2435 |
|
2436 for( TInt j = 0; j < propertyDefCount; j++ ) |
|
2437 { |
|
2438 CMdEPropertyDef& propertyDef = objectDef.PropertyDefL( j ); |
|
2439 } |
|
2440 } |
|
2441 } |
|
2442 |
|
2443 void CHarvesterAO::StartThumbAGDaemon() |
|
2444 { |
|
2445 TInt res( KErrNone ); |
|
2446 |
|
2447 // create server - if one does not already exist |
|
2448 TFindServer findServer( KTAGDaemonName ); |
|
2449 TFullName name; |
|
2450 if ( findServer.Next( name ) != KErrNone ) |
|
2451 { |
|
2452 RProcess server; |
|
2453 // Create the server process |
|
2454 // KNullDesC param causes server's E32Main() to be run |
|
2455 res = server.Create( KTAGDaemonExe, KNullDesC ); |
|
2456 if ( res != KErrNone ) |
|
2457 { |
|
2458 return; |
|
2459 } |
|
2460 |
|
2461 // Process created successfully |
|
2462 TRequestStatus status; |
|
2463 server.Rendezvous( status ); |
|
2464 |
|
2465 if ( status != KRequestPending ) |
|
2466 { |
|
2467 server.Kill( 0 ); // abort startup |
|
2468 } |
|
2469 else |
|
2470 { |
|
2471 server.Resume(); // logon OK - start the server |
|
2472 } |
|
2473 |
|
2474 // Wait until the completion of the server creation |
|
2475 User::WaitForRequest( status ); |
|
2476 |
|
2477 server.Close(); // we're no longer interested in the other process |
|
2478 } |
|
2479 } |
|
2480 |
|
2481 void CHarvesterAO::MemoryLow() |
|
2482 { |
|
2483 WRITELOG("CHarvesterAO::MemoryLow()"); |
|
2484 // cache monitored events |
|
2485 PauseMonitoring(); |
|
2486 |
|
2487 PauseHarvester(); |
|
2488 } |
|
2489 |
|
2490 void CHarvesterAO::MemoryGood() |
|
2491 { |
|
2492 WRITELOG("CHarvesterAO::MemoryGood()"); |
|
2493 // resume monitoring |
|
2494 ResumeMonitoring(); |
|
2495 |
|
2496 TRAP_IGNORE( ResumeHarvesterL() ); |
|
2497 } |
|
2498 |