59 |
60 |
60 /** |
61 /** |
61 Destructor |
62 Destructor |
62 */ |
63 */ |
63 EXPORT_C CMTPMoveObject::~CMTPMoveObject() |
64 EXPORT_C CMTPMoveObject::~CMTPMoveObject() |
64 { |
65 { |
|
66 Cancel(); |
|
67 iDpSingletons.Close(); |
|
68 iSingletons.Close(); |
|
69 |
|
70 delete iTimer; |
|
71 delete iNewFileName; |
65 delete iDest; |
72 delete iDest; |
66 delete iFileMan; |
73 delete iFileMan; |
67 delete iPathToMove; |
74 delete iPathToMove; |
68 delete iNewRootFolder; |
75 delete iNewRootFolder; |
69 iSingletons.Close(); |
|
70 __FLOG_CLOSE; |
76 __FLOG_CLOSE; |
71 } |
77 } |
72 |
78 |
73 /** |
79 /** |
74 Standard c++ constructor |
80 Standard c++ constructor |
75 */ |
81 */ |
76 CMTPMoveObject::CMTPMoveObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
82 CMTPMoveObject::CMTPMoveObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
77 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy), |
83 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPMoveObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPMoveObjectPolicy), |
78 iMoveObjectIndex(0) |
84 iMoveObjectIndex(0), iTimer(NULL) |
79 { |
85 { |
80 __FLOG_OPEN(KMTPSubsystem, KComponent); |
86 __FLOG_OPEN(KMTPSubsystem, KComponent); |
81 } |
87 } |
82 |
88 |
83 TMTPResponseCode CMTPMoveObject::CheckRequestL() |
89 TMTPResponseCode CMTPMoveObject::CheckRequestL() |
102 if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) ) |
108 if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) ) |
103 { |
109 { |
104 result = EMTPRespCodeStoreReadOnly; |
110 result = EMTPRespCodeStoreReadOnly; |
105 } |
111 } |
106 |
112 |
|
113 if(result == EMTPRespCodeOK) |
|
114 { |
|
115 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
116 iIsFolder = EFalse; |
|
117 User::LeaveIfError(BaflUtils::IsFolder(iFramework.Fs(), suid, iIsFolder)); |
|
118 if(!iIsFolder) |
|
119 { |
|
120 if(iDpSingletons.MovingBigFileCache().IsOnGoing()) |
|
121 { |
|
122 __FLOG(_L8("CheckRequestL - A big file moving is ongoing, respond with access denied")); |
|
123 result = EMTPRespCodeAccessDenied; |
|
124 } |
|
125 } |
|
126 } |
|
127 |
107 __FLOG(_L8("CheckRequestL - Exit")); |
128 __FLOG(_L8("CheckRequestL - Exit")); |
108 return result; |
129 return result; |
109 } |
130 } |
110 |
131 |
111 /** |
132 /** |
112 MoveObject request handler |
133 MoveObject request handler |
113 */ |
134 */ |
114 void CMTPMoveObject::ServiceL() |
135 void CMTPMoveObject::ServiceL() |
115 { |
136 { |
|
137 __FLOG(_L8("ServiceL - Entry")); |
116 TMTPResponseCode ret = EMTPRespCodeOK; |
138 TMTPResponseCode ret = EMTPRespCodeOK; |
117 TRAPD(err, ret = MoveObjectL()); |
139 TRAPD(err, ret = MoveObjectL()); |
118 if (err != KErrNone) |
140 if (err != KErrNone) |
119 { |
141 { |
120 SendResponseL(EMTPRespCodeAccessDenied); |
142 SendResponseL(EMTPRespCodeAccessDenied); |
121 } |
143 } |
122 else if (EMTPRespCodeOK != ret) |
144 else if (EMTPRespCodeOK != ret) |
123 { |
145 { |
124 SendResponseL(ret); |
146 SendResponseL(ret); |
125 } |
147 } |
|
148 __FLOG(_L8("ServiceL - Exit")); |
126 } |
149 } |
127 |
150 |
128 /** |
151 /** |
129 Second phase constructor |
152 Second phase constructor |
130 */ |
153 */ |
131 void CMTPMoveObject::ConstructL() |
154 void CMTPMoveObject::ConstructL() |
132 { |
155 { |
133 iSingletons.OpenL(); |
156 iSingletons.OpenL(); |
|
157 iDpSingletons.OpenL(iFramework); |
134 } |
158 } |
135 |
159 |
136 |
160 |
137 /** |
161 /** |
138 A helper function of MoveObjectL. |
162 A helper function of MoveObjectL. |
141 void CMTPMoveObject::MoveFileL(const TDesC& aNewFileName) |
165 void CMTPMoveObject::MoveFileL(const TDesC& aNewFileName) |
142 { |
166 { |
143 __FLOG(_L8("MoveFileL - Entry")); |
167 __FLOG(_L8("MoveFileL - Entry")); |
144 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
168 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
145 GetPreviousPropertiesL(suid); |
169 GetPreviousPropertiesL(suid); |
146 User::LeaveIfError(iFileMan->Move(suid, *iDest)); |
170 |
147 SetPreviousPropertiesL(aNewFileName); |
171 if(iFramework.StorageMgr().DriveNumber(iObjectInfo->Uint(CMTPObjectMetaData::EStorageId)) == |
148 iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName); |
172 iFramework.StorageMgr().DriveNumber(iStorageId)) |
149 iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
173 //Move file to the same storage |
150 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
174 { |
151 iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); |
175 User::LeaveIfError(iFileMan->Move(suid, *iDest)); |
|
176 SetPreviousPropertiesL(aNewFileName); |
|
177 iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName); |
|
178 iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
|
179 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
|
180 iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); |
|
181 SendResponseL(EMTPRespCodeOK); |
|
182 } |
|
183 else |
|
184 //Move file between different storages |
|
185 { |
|
186 delete iNewFileName; |
|
187 iNewFileName = NULL; |
|
188 iNewFileName = aNewFileName.AllocL(); // Store the new file name |
|
189 |
|
190 User::LeaveIfError(iFileMan->Move(suid, *iDest, CFileMan::EOverWrite, iStatus)); |
|
191 if ( !IsActive() ) |
|
192 { |
|
193 SetActive(); |
|
194 } |
|
195 |
|
196 delete iTimer; |
|
197 iTimer = NULL; |
|
198 iTimer = CPeriodic::NewL(EPriorityStandard); |
|
199 TTimeIntervalMicroSeconds32 KMoveObjectIntervalNone = 0; |
|
200 iTimer->Start(TTimeIntervalMicroSeconds32(KMoveObjectTimeOut), KMoveObjectIntervalNone, TCallBack(CMTPMoveObject::OnTimeoutL, this)); |
|
201 } |
152 __FLOG(_L8("MoveFileL - Exit")); |
202 __FLOG(_L8("MoveFileL - Exit")); |
153 } |
203 } |
154 |
204 |
155 /** |
205 /** |
156 A helper function of MoveObjectL. |
206 A helper function of MoveObjectL. |
345 __FLOG(_L8("SetPreviousPropertiesL - Entry")); |
391 __FLOG(_L8("SetPreviousPropertiesL - Entry")); |
346 User::LeaveIfError(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime)); |
392 User::LeaveIfError(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime)); |
347 __FLOG(_L8("SetPreviousPropertiesL - Exit")); |
393 __FLOG(_L8("SetPreviousPropertiesL - Exit")); |
348 } |
394 } |
349 |
395 |
350 |
396 /** |
351 |
397 Call back function, called when the timer expired for big file moving. |
352 |
398 Send response to initiator and cache the target file entry info, which is used to send response |
353 |
399 to getobjectproplist and getobjectinfo. |
|
400 */ |
|
401 TInt CMTPMoveObject::OnTimeoutL(TAny* aPtr) |
|
402 { |
|
403 CMTPMoveObject* moveObjectProcessor = static_cast<CMTPMoveObject*>(aPtr); |
|
404 moveObjectProcessor->DoOnTimeoutL(); |
|
405 return KErrNone; |
|
406 } |
|
407 |
|
408 void CMTPMoveObject::DoOnTimeoutL() |
|
409 { |
|
410 __FLOG(_L8("DoOnTimeoutL - Entry")); |
|
411 |
|
412 if (iTimer) |
|
413 { |
|
414 if (iTimer->IsActive()) |
|
415 { |
|
416 iTimer->Cancel(); |
|
417 } |
|
418 delete iTimer; |
|
419 iTimer = NULL; |
|
420 } |
|
421 |
|
422 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
423 TEntry fileEntry; |
|
424 User::LeaveIfError(iFramework.Fs().Entry(suid, fileEntry)); |
|
425 TUint32 handle = iObjectInfo->Uint(CMTPObjectMetaData::EHandle); |
|
426 |
|
427 iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, *iNewFileName); |
|
428 iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
|
429 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
|
430 iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); |
|
431 |
|
432 CMTPFSEntryCache& aCache = iDpSingletons.MovingBigFileCache(); |
|
433 |
|
434 // Cache the target file entry info, which is used to send response to getobjectproplist and getobjectinfo |
|
435 aCache.SetOnGoing(ETrue); |
|
436 aCache.SetTargetHandle(handle); |
|
437 aCache.SetFileEntry(fileEntry); |
|
438 |
|
439 __FLOG(_L8("UpdateFSEntryCache, sending response with respond code OK for a big file move")); |
|
440 SendResponseL(EMTPRespCodeOK); |
|
441 |
|
442 __FLOG(_L8("DoOnTimeoutL - Exit")); |
|
443 } |
|
444 |
|
445 /** |
|
446 CMTPMoveObject::RunL |
|
447 */ |
|
448 void CMTPMoveObject::RunL() |
|
449 { |
|
450 __FLOG(_L8("RunL - Entry")); |
|
451 |
|
452 User::LeaveIfError(iStatus.Int()); |
|
453 SetPreviousPropertiesL(*iNewFileName); |
|
454 CMTPFSEntryCache& aCache = iDpSingletons.MovingBigFileCache(); |
|
455 // Check to see if we are moving a big file |
|
456 if(aCache.IsOnGoing()) |
|
457 { |
|
458 __FLOG(_L8("RunL - Big file move complete")); |
|
459 aCache.SetOnGoing(EFalse); |
|
460 aCache.SetTargetHandle(KMTPHandleNone); |
|
461 } |
|
462 else |
|
463 { |
|
464 //Cancel the timer |
|
465 if(iTimer) |
|
466 { |
|
467 if(iTimer->IsActive()) |
|
468 { |
|
469 iTimer->Cancel(); |
|
470 } |
|
471 delete iTimer; |
|
472 iTimer = NULL; |
|
473 } |
|
474 |
|
475 iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, *iNewFileName); |
|
476 iObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
|
477 iObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
|
478 iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo); |
|
479 |
|
480 __FLOG(_L8("RunL, sending response with respond code OK for a normal file move")); |
|
481 SendResponseL(EMTPRespCodeOK); |
|
482 } |
|
483 __FLOG(_L8("RunL - Exit")); |
|
484 } |
|
485 |
|
486 /** |
|
487 Override to handle the complete phase of move object |
|
488 */ |
|
489 TBool CMTPMoveObject::DoHandleCompletingPhaseL() |
|
490 { |
|
491 CMTPRequestProcessor::DoHandleCompletingPhaseL(); |
|
492 |
|
493 CMTPFSEntryCache& aCache = iDpSingletons.MovingBigFileCache(); |
|
494 if(aCache.IsOnGoing()) |
|
495 { |
|
496 return EFalse; |
|
497 } |
|
498 else |
|
499 { |
|
500 return ETrue; |
|
501 } |
|
502 } |
|
503 |
|
504 /** |
|
505 Override to match MoveObject request |
|
506 @param aRequest The request to match |
|
507 @param aConnection The connection from which the request comes |
|
508 @return ETrue if the processor can handle the request, otherwise EFalse |
|
509 */ |
|
510 TBool CMTPMoveObject::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const |
|
511 { |
|
512 __FLOG(_L8("Match - Entry")); |
|
513 TBool result = EFalse; |
|
514 TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode); |
|
515 if ((operationCode == EMTPOpCodeMoveObject) && &iConnection == &aConnection) |
|
516 { |
|
517 result = ETrue; |
|
518 } |
|
519 __FLOG_VA((_L8("Match -- Exit with result = %d"), result)); |
|
520 return result; |
|
521 } |