|
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: Handles mount tasks* |
|
15 */ |
|
16 |
|
17 #include <driveinfo.h> |
|
18 |
|
19 #include <placeholderdata.h> |
|
20 #include "mmcmounttaskao.h" |
|
21 #include "mmcmonitorplugin.h" |
|
22 #include "harvesterlog.h" |
|
23 #include "mdsfileserverpluginclient.h" |
|
24 #include "mdeharvestersession.h" |
|
25 #include "harvesterdata.h" |
|
26 #include "mdsutils.h" |
|
27 #include "harvestercenreputil.h" |
|
28 #include "fsutil.h" |
|
29 #include "harvesterplugininfo.h" |
|
30 #include "harvesterpluginfactory.h" |
|
31 |
|
32 const TInt KEntryBufferSize = 100; |
|
33 |
|
34 //----------------------------------------------------------------------------- |
|
35 // CMMCMountTaskAO |
|
36 //----------------------------------------------------------------------------- |
|
37 CMMCMountTaskAO* CMMCMountTaskAO::NewL() |
|
38 { |
|
39 WRITELOG( "CMMCMountTaskAO::NewL" ); |
|
40 |
|
41 CMMCMountTaskAO* self = new (ELeave) CMMCMountTaskAO(); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 void CMMCMountTaskAO::ConstructL() |
|
49 { |
|
50 WRITELOG("CMMCMountTaskAO::ConstructL"); |
|
51 |
|
52 CActiveScheduler::Add( this ); |
|
53 User::LeaveIfError( iFs.Connect() ); |
|
54 iNextRequest = ERequestIdle; |
|
55 iMmcFileList = CMmcFileList::NewL(); |
|
56 iCacheEvents = EFalse; |
|
57 iHEM = CHarvesterEventManager::GetInstanceL(); |
|
58 } |
|
59 |
|
60 CMMCMountTaskAO::CMMCMountTaskAO() : |
|
61 CActive( KHarvesterPriorityMonitorPlugin ) |
|
62 { |
|
63 WRITELOG( "CMMCMountTaskAO::CMMCMountTaskAO" ); |
|
64 } |
|
65 |
|
66 CMMCMountTaskAO::~CMMCMountTaskAO() |
|
67 { |
|
68 WRITELOG( "CMMCMountTaskAO::~CMMCMountTaskAO" ); |
|
69 Cancel(); |
|
70 iFs.Close(); |
|
71 |
|
72 iMountDataQueue.ResetAndDestroy(); |
|
73 |
|
74 delete iMdeSession; |
|
75 |
|
76 Deinitialize(); |
|
77 |
|
78 if (iHEM) |
|
79 { |
|
80 iHEM->ReleaseInstance(); |
|
81 } |
|
82 |
|
83 delete iMmcFileList; |
|
84 } |
|
85 |
|
86 void CMMCMountTaskAO::SetMonitorObserver( MMonitorPluginObserver& aObserver ) |
|
87 { |
|
88 WRITELOG( "CMMCMountTaskAO::SetMonitorObserver" ); |
|
89 iObserver = &aObserver; |
|
90 } |
|
91 |
|
92 void CMMCMountTaskAO::SetMdeSession( CMdEHarvesterSession* aMdeSession ) |
|
93 { |
|
94 iMdeSession = aMdeSession; |
|
95 } |
|
96 |
|
97 void CMMCMountTaskAO::SetHarvesterPluginFactory( CHarvesterPluginFactory* aPluginFactory ) |
|
98 { |
|
99 iHarvesterPluginFactory = aPluginFactory; |
|
100 } |
|
101 |
|
102 void CMMCMountTaskAO::StartMount( TMountData& aMountData ) |
|
103 { |
|
104 WRITELOG("CMMCMountTaskAO::StartMount"); |
|
105 iMountDataQueue.Append( &aMountData ); |
|
106 if ( iNextRequest == ERequestIdle ) |
|
107 { |
|
108 SetNextRequest( ERequestStartTask ); |
|
109 } |
|
110 } |
|
111 |
|
112 void CMMCMountTaskAO::StartUnmount(TMountData& aMountData) |
|
113 { |
|
114 WRITELOG("CMMCMountTaskAO::StartUnmount"); |
|
115 |
|
116 // make sure that drive is not currently mounting |
|
117 if ( iMountData ) |
|
118 { |
|
119 if ( iMountData->iDrivePath.Compare( aMountData.iDrivePath ) == 0 ) |
|
120 { |
|
121 Cancel(); |
|
122 Deinitialize(); |
|
123 iNextRequest = ERequestIdle; |
|
124 } |
|
125 } |
|
126 |
|
127 iMountDataQueue.Append( &aMountData ); |
|
128 SetNextRequest( ERequestStartTask ); |
|
129 } |
|
130 |
|
131 void CMMCMountTaskAO::RunL() |
|
132 { |
|
133 WRITELOG1( "CMMCMountTaskAO::RunL iStatus: %d", iStatus.Int() ); |
|
134 |
|
135 User::LeaveIfError( iStatus.Int() ); |
|
136 |
|
137 if ( iCacheEvents ) |
|
138 { |
|
139 if ( iMountData ) |
|
140 { |
|
141 iMountDataQueue.Insert( iMountData, 0 ); |
|
142 iMountData = NULL; |
|
143 } |
|
144 Deinitialize(); |
|
145 return; |
|
146 } |
|
147 |
|
148 switch( iNextRequest ) |
|
149 { |
|
150 case ERequestStartTask: |
|
151 { |
|
152 WRITELOG( "CMMCMountTaskAO::RunL - ERequestStartTask" ); |
|
153 if ( iMountData ) |
|
154 { |
|
155 delete iMountData; |
|
156 iMountData = NULL; |
|
157 } |
|
158 |
|
159 if( iMountDataQueue.Count() > 0 ) |
|
160 { |
|
161 iMountData = iMountDataQueue[0]; |
|
162 iMountDataQueue.Remove(0); |
|
163 |
|
164 WRITELOG1( "iMountData.iMountType: %d", iMountData->iMountType ); |
|
165 WRITELOG1( "iMountData.iDrivePath: %S", &iMountData->iDrivePath ); |
|
166 WRITELOG1( "iMountData.iMediaID: %d", iMountData->iMediaID ); |
|
167 |
|
168 if ( iMountData->iMountType == TMountData::EMount ) |
|
169 { |
|
170 SetNextRequest( ERequestMount ); |
|
171 } |
|
172 else if ( iMountData->iMountType == TMountData::EUnmount ) |
|
173 { |
|
174 SetNextRequest( ERequestUnmount ); |
|
175 } |
|
176 else if ( iMountData->iMountType == TMountData::EFormat ) |
|
177 { |
|
178 SetNextRequest( ERequestFormat ); |
|
179 } |
|
180 } |
|
181 else |
|
182 { |
|
183 SetNextRequest( ERequestIdle ); |
|
184 iMountDataQueue.Compress(); |
|
185 } |
|
186 } |
|
187 break; |
|
188 |
|
189 case ERequestMount: |
|
190 { |
|
191 WRITELOG( "CMMCMountTaskAO::RunL - ERequestMount" ); |
|
192 Initialize(); |
|
193 StartNotifyL(); |
|
194 SetNotPresentToMDE(); |
|
195 TRAPD( err, iMmcFileList->BuildFileListL( iFs, iMountData->iDrivePath, iEntryArray )); |
|
196 if ( err == KErrNoMemory ) |
|
197 { |
|
198 iMountDataQueue.Insert( iMountData, 0 ); |
|
199 iMountData = NULL; |
|
200 Deinitialize(); |
|
201 SetNextRequest( ERequestStartTask ); |
|
202 break; |
|
203 } |
|
204 |
|
205 // send start event |
|
206 const TInt entryCount = iEntryArray.Count(); |
|
207 if( entryCount > 0 ) |
|
208 { |
|
209 iHEM->IncreaseItemCount( EHEObserverTypeMMC, entryCount ); |
|
210 iHEM->SendEventL( EHEObserverTypeMMC, EHEStateStarted, iHEM->ItemCount( EHEObserverTypeMMC ) ); |
|
211 } |
|
212 |
|
213 SetNextRequest( ERequestHandleFileEntry ); |
|
214 } |
|
215 break; |
|
216 |
|
217 case ERequestUnmount: |
|
218 { |
|
219 WRITELOG( "CMMCMountTaskAO::RunL - ERequestUnmount" ); |
|
220 |
|
221 const TUint entryCount = iEntryArray.Count(); |
|
222 WRITELOG1( "CMMCMountTaskAO::RunL - ERequestUnmount entryCount = %d", entryCount ); |
|
223 if( entryCount ) |
|
224 { |
|
225 iHEM->DecreaseItemCountL( EHEObserverTypeMMC, entryCount ); |
|
226 } |
|
227 |
|
228 const TUint harvestEntryCount = iHarvestEntryArray.Count(); |
|
229 WRITELOG1( "CMMCMountTaskAO::RunL - ERequestUnmount harvestEntryCount = %d", harvestEntryCount ); |
|
230 if( harvestEntryCount ) |
|
231 { |
|
232 iHEM->DecreaseItemCountL( EHEObserverTypeMMC, harvestEntryCount ); |
|
233 } |
|
234 |
|
235 RMsgQueue<TInt> unmountQueue; |
|
236 _LIT( KUnmountHandlerAOString, "unmounthandlerao" ); |
|
237 TInt err = unmountQueue.OpenGlobal( KUnmountHandlerAOString ); |
|
238 if( err == KErrNone ) |
|
239 { |
|
240 unmountQueue.Send( iMountData->iMediaID ); |
|
241 } |
|
242 |
|
243 SetNotPresentToMDE(); |
|
244 StopNotifyL(); |
|
245 SetNextRequest( ERequestCleanup ); |
|
246 } |
|
247 break; |
|
248 |
|
249 case ERequestFormat: |
|
250 { |
|
251 WRITELOG( "CMMCMountTaskAO::RunL - ERequestFormat" ); |
|
252 SetNotPresentToMDE(); |
|
253 RemoveNotPresentFromMDE(); |
|
254 StopNotifyL(); |
|
255 SetNextRequest( ERequestCleanup ); |
|
256 } |
|
257 break; |
|
258 |
|
259 case ERequestHandleFileEntry: |
|
260 { |
|
261 WRITELOG( "CMMCMountTaskAO::RunL - ERequestHandleFileEntry" ); |
|
262 |
|
263 if( iNextRequest == ERequestStartTask ) |
|
264 { |
|
265 WRITELOG( "CMMCMountTaskAO::RunL - ERequestHandleFileEntry stop processing media is unmounted"); |
|
266 SetNextRequest( ERequestStartTask ); |
|
267 return; |
|
268 } |
|
269 else if ( iEntryArray.Count() > 0 ) |
|
270 { |
|
271 TRAPD( err, iMmcFileList->HandleFileEntryL( *iMdeSession, iEntryArray, |
|
272 iHarvestEntryArray, iMountData->iMediaID, iHarvesterPluginFactory )); |
|
273 if ( err != KErrNone ) |
|
274 { |
|
275 if( err == KErrNoMemory ) |
|
276 { |
|
277 iMountDataQueue.Insert( iMountData, 0 ); |
|
278 iMountData = NULL; |
|
279 } |
|
280 Deinitialize(); |
|
281 SetNextRequest( ERequestStartTask ); |
|
282 break; |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 RemoveNotPresentFromMDE(); |
|
288 SetNextRequest( ERequestCleanup ); |
|
289 break; |
|
290 } |
|
291 |
|
292 if ( iHarvestEntryArray.Count() > 0 ) |
|
293 { |
|
294 SetNextRequest( ERequestHandleReharvest ); |
|
295 } |
|
296 else |
|
297 { |
|
298 SetNextRequest( ERequestHandleFileEntry ); |
|
299 } |
|
300 } |
|
301 break; |
|
302 |
|
303 case ERequestHandleReharvest: |
|
304 { |
|
305 WRITELOG( "CMMCMountTaskAO::RunL - ERequestHandleReharvest" ); |
|
306 |
|
307 if( iNextRequest == ERequestStartTask ) |
|
308 { |
|
309 WRITELOG( "CMMCMountTaskAO::RunL - ERequestHandleReharvest stop processing media is unmounted"); |
|
310 SetNextRequest( ERequestStartTask ); |
|
311 return; |
|
312 } |
|
313 else if ( iHarvestEntryArray.Count() > 0 ) |
|
314 { |
|
315 HandleReharvestL( iHarvestEntryArray ); |
|
316 SetNextRequest( ERequestHandleReharvest ); |
|
317 } |
|
318 else |
|
319 { |
|
320 SetNextRequest( ERequestHandleFileEntry ); |
|
321 } |
|
322 } |
|
323 break; |
|
324 |
|
325 case ERequestCleanup: |
|
326 { |
|
327 WRITELOG( "CMMCMountTaskAO::RunL - ERequestCleanup" ); |
|
328 TBool present = (iMountData->iMountType == TMountData::EMount); |
|
329 iMdeSession->SetMediaL( iMountData->iMediaID, iMountData->iDrivePath[0], present ); |
|
330 Deinitialize(); |
|
331 SetNextRequest( ERequestStartTask ); |
|
332 } |
|
333 break; |
|
334 |
|
335 case ERequestIdle: |
|
336 { |
|
337 WRITELOG( "CMMCMountTaskAO::RunL - ERequestIdle" ); |
|
338 // all done |
|
339 } |
|
340 break; |
|
341 |
|
342 default: |
|
343 User::Leave( KErrNotSupported ); |
|
344 break; |
|
345 } |
|
346 } |
|
347 |
|
348 #ifdef _DEBUG |
|
349 TInt CMMCMountTaskAO::RunError( TInt aError ) |
|
350 #else |
|
351 TInt CMMCMountTaskAO::RunError( TInt ) |
|
352 #endif |
|
353 { |
|
354 WRITELOG1( "CMMCMountTaskAO::RunError with error code: %d", aError ); |
|
355 Deinitialize(); |
|
356 return KErrNone; |
|
357 } |
|
358 |
|
359 void CMMCMountTaskAO::DoCancel() |
|
360 { |
|
361 WRITELOG( "CMMCMountTaskAO::DoCancel" ); |
|
362 } |
|
363 |
|
364 void CMMCMountTaskAO::SetNextRequest( TRequest aRequest ) |
|
365 { |
|
366 WRITELOG("CMMCMountTaskAO::SetNextRequest" ); |
|
367 if ( !IsActive() ) |
|
368 { |
|
369 iNextRequest = aRequest; |
|
370 TRequestStatus* ptrStatus = &iStatus; |
|
371 User::RequestComplete( ptrStatus, KErrNone ); |
|
372 SetActive(); |
|
373 } |
|
374 } |
|
375 |
|
376 void CMMCMountTaskAO::SetNotPresentToMDE() |
|
377 { |
|
378 WRITELOG1("CMMCMountTaskAO::SetNotPresentToMDE - MediaID %d", iMountData->iMediaID); |
|
379 if ( iMountData->iMediaID ) |
|
380 { |
|
381 iMdeSession->SetFilesToNotPresent( iMountData->iMediaID ); |
|
382 } |
|
383 else |
|
384 { |
|
385 WRITELOG("CMMCMountTaskAO::SetNotPresentToMDE - MediaID 0, not setting"); |
|
386 } |
|
387 } |
|
388 |
|
389 void CMMCMountTaskAO::HandleReharvestL( RPointerArray<CPlaceholderData>& aArray ) |
|
390 { |
|
391 WRITELOG("CMMCMountTaskAO::HandleReharvestL"); |
|
392 |
|
393 TInt batchSize( 0 ); |
|
394 RPointerArray<CHarvesterData> hdArray; |
|
395 CleanupClosePushL( hdArray ); |
|
396 |
|
397 if ( aArray.Count() >= KEntryBufferSize ) |
|
398 { |
|
399 batchSize = KEntryBufferSize; |
|
400 } |
|
401 else |
|
402 { |
|
403 batchSize = aArray.Count(); |
|
404 } |
|
405 |
|
406 for ( TInt i = 0; i < batchSize; i++ ) |
|
407 { |
|
408 CPlaceholderData* ei = aArray[0]; |
|
409 |
|
410 HBufC* fileName = ei->Uri().AllocLC(); |
|
411 CHarvesterData* hd = CHarvesterData::NewL( fileName ); |
|
412 hd->SetOrigin( MdeConstants::Object::EOther ); |
|
413 CleanupStack::Pop( fileName ); |
|
414 |
|
415 if ( ei->PresentState() == EMdsPlaceholder || |
|
416 ei->PresentState() == EMdsModified ) |
|
417 { |
|
418 hd->SetEventType( EHarvesterEdit ); |
|
419 hd->SetObjectType( ENormal ); |
|
420 delete ei; |
|
421 } |
|
422 else |
|
423 { |
|
424 hd->SetEventType( EHarvesterAdd ); |
|
425 hd->SetObjectType( EPlaceholder ); |
|
426 hd->SetClientData( ei ); |
|
427 } |
|
428 |
|
429 hdArray.Append( hd ); |
|
430 aArray.Remove( 0 ); |
|
431 } |
|
432 |
|
433 aArray.Compress(); |
|
434 |
|
435 if ( iObserver ) |
|
436 { |
|
437 if( hdArray.Count() > 0) |
|
438 { |
|
439 iObserver->MonitorEvent( hdArray ); |
|
440 } |
|
441 } |
|
442 |
|
443 CleanupStack::PopAndDestroy( &hdArray ); |
|
444 } |
|
445 |
|
446 void CMMCMountTaskAO::RemoveNotPresentFromMDE() |
|
447 { |
|
448 WRITELOG( "CMMCMountTaskAO::RemoveNotPresentFromMDE" ); |
|
449 |
|
450 iMdeSession->RemoveFilesNotPresent( iMountData->iMediaID ); |
|
451 } |
|
452 |
|
453 void CMMCMountTaskAO::StartNotifyL() |
|
454 { |
|
455 WRITELOG( "CMMCMountTaskAO::StartNotify" ); |
|
456 |
|
457 CHarvesterCenRepUtil* cenRepoUtil = CHarvesterCenRepUtil::NewLC(); |
|
458 cenRepoUtil->AddIgnorePathsToFspL( iMountData->iDrivePath ); |
|
459 cenRepoUtil->FspEngine().AddNotificationPath( iMountData->iDrivePath ); |
|
460 CleanupStack::PopAndDestroy( cenRepoUtil ); |
|
461 } |
|
462 |
|
463 void CMMCMountTaskAO::StopNotifyL() |
|
464 { |
|
465 WRITELOG( "CMMCMountTaskAO::StopNotify" ); |
|
466 |
|
467 CHarvesterCenRepUtil* cenRepoUtil = CHarvesterCenRepUtil::NewLC(); |
|
468 cenRepoUtil->RemoveIgnorePathsFromFspL( iMountData->iDrivePath ); |
|
469 cenRepoUtil->FspEngine().RemoveNotificationPath( iMountData->iDrivePath ); |
|
470 CleanupStack::PopAndDestroy( cenRepoUtil ); |
|
471 } |
|
472 |
|
473 void CMMCMountTaskAO::Initialize() |
|
474 { |
|
475 WRITELOG( "CMMCMountTaskAO::Initialize" ); |
|
476 iEntryArray.Reset(); |
|
477 iHarvestEntryArray.Reset(); |
|
478 } |
|
479 |
|
480 void CMMCMountTaskAO::Deinitialize() |
|
481 { |
|
482 WRITELOG( "CMMCMountTaskAO::Deinitialize" ); |
|
483 |
|
484 WRITELOG1( "CMMCMountTaskAO::Deinitialize - iEntryArray.Count() = %d", iEntryArray.Count() ); |
|
485 if( iEntryArray.Count() > 0) |
|
486 { |
|
487 TRAP_IGNORE( iHEM->DecreaseItemCountL( EHEObserverTypeMMC, iEntryArray.Count() ) ); |
|
488 } |
|
489 |
|
490 WRITELOG1( "CMMCMountTaskAO::Deinitialize - iHarvestEntryArray.Count() = %d", iHarvestEntryArray.Count() ); |
|
491 if( iHarvestEntryArray.Count() > 0) |
|
492 { |
|
493 TRAP_IGNORE( iHEM->DecreaseItemCountL( EHEObserverTypeMMC, iHarvestEntryArray.Count() ) ); |
|
494 } |
|
495 |
|
496 iEntryArray.ResetAndDestroy(); |
|
497 iHarvestEntryArray.ResetAndDestroy(); |
|
498 |
|
499 if ( iMountData ) |
|
500 { |
|
501 delete iMountData; |
|
502 iMountData = NULL; |
|
503 } |
|
504 } |
|
505 |
|
506 TUint32 CMMCMountTaskAO::GetInternalDriveMediaId() |
|
507 { |
|
508 WRITELOG( "CMMCMountTaskAO::GetInternalDriveMediaId" ); |
|
509 |
|
510 TDriveInfo driveInfo; |
|
511 TDriveList driveList; |
|
512 TInt numOfElements( 0 ); |
|
513 |
|
514 TInt err = DriveInfo::GetUserVisibleDrives( |
|
515 iFs, driveList, numOfElements, |
|
516 KDriveAttExclude | KDriveAttRemote | KDriveAttRom ); |
|
517 if( err != KErrNone ) |
|
518 { |
|
519 return 0; |
|
520 } |
|
521 |
|
522 TUint32 hdMediaId = 0; |
|
523 TInt i( 0 ); |
|
524 |
|
525 for ( i = 0; i < driveList.Length(); i++ ) |
|
526 { |
|
527 if ( driveList[i] > 0 ) |
|
528 { |
|
529 iFs.Drive( driveInfo, i ); |
|
530 if ( driveInfo.iType == EMediaHardDisk ) |
|
531 { |
|
532 // check if disk is internal |
|
533 TUint driveStatus; |
|
534 TInt err = DriveInfo::GetDriveStatus( iFs, i, driveStatus ); |
|
535 if ( (err == KErrNone ) && ( driveStatus & DriveInfo::EDriveInternal ) ) |
|
536 { |
|
537 // get media id |
|
538 hdMediaId = FSUtil::MediaID( iFs, i ); |
|
539 break; |
|
540 } |
|
541 } |
|
542 } |
|
543 } |
|
544 |
|
545 return hdMediaId; |
|
546 } |
|
547 |
|
548 void CMMCMountTaskAO::SetCachingStatus( TBool aCachingStatus ) |
|
549 { |
|
550 iCacheEvents = aCachingStatus; |
|
551 if( !iCacheEvents ) |
|
552 { |
|
553 SetNextRequest( ERequestStartTask ); |
|
554 } |
|
555 } |