58 /** |
60 /** |
59 Destructor |
61 Destructor |
60 */ |
62 */ |
61 EXPORT_C CMTPCopyObject::~CMTPCopyObject() |
63 EXPORT_C CMTPCopyObject::~CMTPCopyObject() |
62 { |
64 { |
|
65 __FLOG(_L8("~CMTPCopyObject - Entry")); |
|
66 Cancel(); |
|
67 iDpSingletons.Close(); |
|
68 iSingletons.Close(); |
|
69 |
|
70 delete iTimer; |
63 delete iDest; |
71 delete iDest; |
|
72 delete iNewFileName; |
64 delete iFileMan; |
73 delete iFileMan; |
65 |
74 |
|
75 __FLOG(_L8("~CMTPCopyObject - Exit")); |
66 __FLOG_CLOSE; |
76 __FLOG_CLOSE; |
67 } |
77 } |
68 |
78 |
69 /** |
79 /** |
70 Standard c++ constructor |
80 Standard c++ constructor |
71 */ |
81 */ |
72 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
82 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
73 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy) |
83 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy), |
|
84 iTimer(NULL) |
74 { |
85 { |
75 __FLOG_OPEN(KMTPSubsystem, KComponent); |
86 __FLOG_OPEN(KMTPSubsystem, KComponent); |
76 } |
87 } |
77 |
88 |
|
89 |
|
90 |
|
91 TMTPResponseCode CMTPCopyObject::CheckRequestL() |
|
92 { |
|
93 __FLOG(_L8("CheckRequestL - Entry")); |
|
94 TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL(); |
|
95 if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) ) |
|
96 { |
|
97 result = EMTPRespCodeStoreReadOnly; |
|
98 } |
|
99 if(result == EMTPRespCodeOK) |
|
100 { |
|
101 const TUint32 KHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
102 CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC()); |
|
103 if(iFramework.ObjectMgr().ObjectL(KHandle, *object)) |
|
104 { |
|
105 const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid)); |
|
106 iIsFolder = EFalse; |
|
107 User::LeaveIfError(BaflUtils::IsFolder(iFramework.Fs(), suid, iIsFolder)); |
|
108 if(!iIsFolder) |
|
109 { |
|
110 if(iDpSingletons.CopyingBigFileCache().IsOnGoing()) |
|
111 { |
|
112 __FLOG(_L8("CheckRequestL - A big file copying is ongoing, respond with access denied")); |
|
113 result = EMTPRespCodeAccessDenied; |
|
114 } |
|
115 } |
|
116 } |
|
117 CleanupStack::PopAndDestroy(object); |
|
118 } |
|
119 __FLOG(_L8("CheckRequestL - Exit")); |
|
120 return result; |
|
121 } |
78 |
122 |
79 /** |
123 /** |
80 CopyObject request handler |
124 CopyObject request handler |
81 */ |
125 */ |
82 void CMTPCopyObject::ServiceL() |
126 void CMTPCopyObject::ServiceL() |
83 { |
127 { |
|
128 __FLOG(_L8("ServiceL - Entry")); |
84 TUint32 handle = KMTPHandleNone; |
129 TUint32 handle = KMTPHandleNone; |
85 TMTPResponseCode responseCode = CopyObjectL(handle); |
130 TMTPResponseCode responseCode = CopyObjectL(handle); |
86 if(responseCode == EMTPRespCodeOK) |
131 if(responseCode != EMTPRespCodeOK) |
87 { |
132 { |
|
133 __FLOG_VA((_L8("ServiceL, sending response with respond code %d"), responseCode)); |
|
134 SendResponseL(responseCode); |
|
135 } |
|
136 else if (iIsFolder) |
|
137 { |
|
138 __FLOG_VA((_L8("ServiceL, sending response with handle=%d, respond code OK"), handle)); |
88 SendResponseL(EMTPRespCodeOK, 1, &handle); |
139 SendResponseL(EMTPRespCodeOK, 1, &handle); |
89 } |
140 } |
90 else |
141 __FLOG(_L8("ServiceL - Exit")); |
91 { |
|
92 SendResponseL(responseCode); |
|
93 } |
|
94 } |
142 } |
95 |
143 |
96 |
144 |
97 /** |
145 /** |
98 Second phase constructor |
146 Second phase constructor |
99 */ |
147 */ |
100 void CMTPCopyObject::ConstructL() |
148 void CMTPCopyObject::ConstructL() |
101 { |
149 { |
102 |
150 iSingletons.OpenL(); |
103 } |
151 iDpSingletons.OpenL(iFramework); |
|
152 } |
104 |
153 |
105 |
154 |
106 /** |
155 /** |
107 A helper function of CopyObjectL. |
156 A helper function of CopyObjectL. |
108 @param aNewFileName the new full filename after copy. |
157 @param aNewFileName the new full filename after copy. |
109 @return objectHandle of new copy of object. |
158 @return objectHandle of new copy of object. |
110 */ |
159 */ |
111 TUint32 CMTPCopyObject::CopyFileL(const TDesC& aNewFileName) |
160 void CMTPCopyObject::CopyFileL(const TDesC& aNewFileName) |
112 { |
161 { |
113 __FLOG(_L8("CopyFileL - Entry")); |
162 __FLOG(_L8("CopyFileL - Entry")); |
|
163 delete iNewFileName; |
|
164 iNewFileName = NULL; |
|
165 iNewFileName = aNewFileName.AllocL(); // Store the new file name |
114 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
166 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
115 GetPreviousPropertiesL(suid); |
167 GetPreviousPropertiesL(suid); |
116 User::LeaveIfError(iFileMan->Copy(suid, *iDest)); |
168 |
117 SetPreviousPropertiesL(aNewFileName); |
169 User::LeaveIfError(iFileMan->Copy(suid, *iDest, CFileMan::EOverWrite, iStatus)); |
118 |
170 if ( !IsActive() ) |
119 TUint32 handle = UpdateObjectInfoL(aNewFileName); |
171 { |
|
172 SetActive(); |
|
173 } |
|
174 |
|
175 delete iTimer; |
|
176 iTimer = NULL; |
|
177 iTimer = CPeriodic::NewL(EPriorityStandard); |
|
178 TTimeIntervalMicroSeconds32 KCopyObjectIntervalNone = 0; |
|
179 iTimer->Start(TTimeIntervalMicroSeconds32(KCopyObjectTimeOut), KCopyObjectIntervalNone, TCallBack(CMTPCopyObject::OnTimeoutL, this)); |
120 |
180 |
121 __FLOG(_L8("CopyFileL - Exit")); |
181 __FLOG(_L8("CopyFileL - Exit")); |
122 |
|
123 return handle; |
|
124 } |
182 } |
125 |
183 |
126 /** |
184 /** |
127 A helper function of CopyObjectL. |
185 A helper function of CopyObjectL. |
128 @param aNewFolderName the new full file folder name after copy. |
186 @param aNewFolderName the new full file folder name after copy. |
340 |
394 |
341 __FLOG(_L8("UpdateObjectInfoL - Exit")); |
395 __FLOG(_L8("UpdateObjectInfoL - Exit")); |
342 |
396 |
343 return handle; |
397 return handle; |
344 } |
398 } |
|
399 |
|
400 /** |
|
401 Call back function, called when the timer expired for big file copying. |
|
402 Send response to initiator and cache the target file entry info, which is used to send response |
|
403 to getobjectproplist and getobjectinfo. |
|
404 */ |
|
405 TInt CMTPCopyObject::OnTimeoutL(TAny* aPtr) |
|
406 { |
|
407 CMTPCopyObject* copyObjectProcessor = static_cast<CMTPCopyObject*>(aPtr); |
|
408 copyObjectProcessor->DoOnTimeoutL(); |
|
409 return KErrNone; |
|
410 } |
|
411 |
|
412 void CMTPCopyObject::DoOnTimeoutL() |
|
413 { |
|
414 __FLOG(_L8("DoOnTimeoutL - Entry")); |
|
415 |
|
416 if (iTimer) |
|
417 { |
|
418 if (iTimer->IsActive()) |
|
419 { |
|
420 iTimer->Cancel(); |
|
421 } |
|
422 delete iTimer; |
|
423 iTimer = NULL; |
|
424 } |
|
425 |
|
426 const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
427 TEntry fileEntry; |
|
428 User::LeaveIfError(iFramework.Fs().Entry(suid, fileEntry)); |
|
429 TUint32 handle = KMTPHandleNone; |
|
430 handle = UpdateObjectInfoL(*iNewFileName); |
|
431 CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache(); |
|
432 |
|
433 // Cache the target file entry info, which is used to send response to getobjectproplist and getobjectinfo |
|
434 aCache.SetOnGoing(ETrue); |
|
435 aCache.SetTargetHandle(handle); |
|
436 aCache.SetFileEntry(fileEntry); |
|
437 |
|
438 __FLOG_VA((_L8("UpdateFSEntryCache, sending response with handle=%d, respond code OK for a big file copy"), handle)); |
|
439 SendResponseL(EMTPRespCodeOK, 1, &handle); |
|
440 |
|
441 __FLOG(_L8("DoOnTimeoutL - Exit")); |
|
442 } |
|
443 |
|
444 /** |
|
445 CMTPCopyObject::RunL |
|
446 */ |
|
447 void CMTPCopyObject::RunL() |
|
448 { |
|
449 __FLOG(_L8("RunL - Entry")); |
|
450 |
|
451 User::LeaveIfError(iStatus.Int()); |
|
452 SetPreviousPropertiesL(*iNewFileName); |
|
453 CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache(); |
|
454 // Check to see if we are copying a big file |
|
455 if(aCache.IsOnGoing()) |
|
456 { |
|
457 __FLOG(_L8("RunL - Big file copy complete")); |
|
458 aCache.SetOnGoing(EFalse); |
|
459 aCache.SetTargetHandle(KMTPHandleNone); |
|
460 } |
|
461 else |
|
462 { |
|
463 //Cancel the timer |
|
464 if(iTimer) |
|
465 { |
|
466 if (iTimer->IsActive()) |
|
467 { |
|
468 iTimer->Cancel(); |
|
469 } |
|
470 delete iTimer; |
|
471 iTimer = NULL; |
|
472 } |
|
473 |
|
474 TUint32 handle = UpdateObjectInfoL(*iNewFileName); |
|
475 __FLOG_VA((_L8("RunL, sending response with handle=%d, respond code OK for a normal file copy"), handle)); |
|
476 SendResponseL(EMTPRespCodeOK, 1, &handle); |
|
477 } |
|
478 __FLOG(_L8("RunL - Exit")); |
|
479 } |
|
480 |
|
481 /** |
|
482 Override to handle the complete phase of copy object |
|
483 @return EFalse |
|
484 */ |
|
485 TBool CMTPCopyObject::DoHandleCompletingPhaseL() |
|
486 { |
|
487 CMTPRequestProcessor::DoHandleCompletingPhaseL(); |
|
488 |
|
489 CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache(); |
|
490 if(aCache.IsOnGoing()) |
|
491 { |
|
492 return EFalse; |
|
493 } |
|
494 else |
|
495 { |
|
496 return ETrue; |
|
497 } |
|
498 } |
|
499 |
|
500 /** |
|
501 Override to match CopyObject request |
|
502 @param aRequest The request to match |
|
503 @param aConnection The connection from which the request comes |
|
504 @return ETrue if the processor can handle the request, otherwise EFalse |
|
505 */ |
|
506 TBool CMTPCopyObject::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const |
|
507 { |
|
508 __FLOG(_L8("Match - Entry")); |
|
509 TBool result = EFalse; |
|
510 TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode); |
|
511 if ((operationCode == EMTPOpCodeCopyObject) && &iConnection == &aConnection) |
|
512 { |
|
513 result = ETrue; |
|
514 } |
|
515 __FLOG_VA((_L8("Match -- Exit with result = %d"), result)); |
|
516 return result; |
|
517 } |