67 /** |
70 /** |
68 Destructor |
71 Destructor |
69 */ |
72 */ |
70 CMTPImageDpCopyObject::~CMTPImageDpCopyObject() |
73 CMTPImageDpCopyObject::~CMTPImageDpCopyObject() |
71 { |
74 { |
72 __FLOG(_L8(">> CMTPImageDpCopyObject::~CMTPImageDpCopyObject")); |
75 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_CMTPIMAGEDPCOPYOBJECT_DES_ENTRY ); |
73 delete iDest; |
76 delete iDest; |
74 delete iFileMan; |
77 delete iFileMan; |
75 delete iSrcObjectInfo; |
78 delete iSrcObjectInfo; |
76 delete iTargetObjectInfo; |
79 delete iTargetObjectInfo; |
77 iRollbackActionL.Close(); |
80 iRollbackActionL.Close(); |
78 __FLOG(_L8("<< CMTPImageDpCopyObject::~CMTPImageDpCopyObject")); |
81 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_CMTPIMAGEDPCOPYOBJECT_DES_EXIT ); |
79 __FLOG_CLOSE; |
|
80 |
|
81 } |
82 } |
82 |
83 |
83 /** |
84 /** |
84 Standard c++ constructor |
85 Standard c++ constructor |
85 */ |
86 */ |
86 CMTPImageDpCopyObject::CMTPImageDpCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) : |
87 CMTPImageDpCopyObject::CMTPImageDpCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) : |
87 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy), |
88 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy), |
88 iFramework(aFramework), |
89 iFramework(aFramework), |
89 iDataProvider(aDataProvider) |
90 iDataProvider(aDataProvider) |
90 { |
91 { |
91 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
92 } |
92 } |
93 |
93 |
94 /** |
94 /** |
95 Second phase constructor |
95 Second phase constructor |
96 */ |
96 */ |
97 void CMTPImageDpCopyObject::ConstructL() |
97 void CMTPImageDpCopyObject::ConstructL() |
98 { |
98 { |
99 __FLOG(_L8(">> CMTPImageDpCopyObject::ConstructL")); |
99 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_CONSTRUCTL_ENTRY ); |
100 iFileMan = CFileMan::NewL(iFramework.Fs()); |
100 iFileMan = CFileMan::NewL(iFramework.Fs()); |
101 iSrcObjectInfo = CMTPObjectMetaData::NewL(); |
101 iSrcObjectInfo = CMTPObjectMetaData::NewL(); |
102 iRollbackActionL.ReserveL(RollbackFuncCnt); |
102 iRollbackActionL.ReserveL(RollbackFuncCnt); |
103 __FLOG(_L8("<< CMTPImageDpCopyObject::ConstructL")); |
103 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_CONSTRUCTL_EXIT ); |
104 } |
104 } |
105 |
105 |
106 TMTPResponseCode CMTPImageDpCopyObject::CheckRequestL() |
106 TMTPResponseCode CMTPImageDpCopyObject::CheckRequestL() |
107 { |
107 { |
108 __FLOG(_L8(">> CMTPImageDpCopyObject::CheckRequestL")); |
108 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_CHECKREQUESTL_ENTRY ); |
109 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
109 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
110 if (EMTPRespCodeOK == responseCode) |
110 if (EMTPRespCodeOK == responseCode) |
111 { |
111 { |
112 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
112 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
113 // Check whether object handle is valid |
113 // Check whether object handle is valid |
116 else if(EMTPRespCodeInvalidObjectHandle == responseCode) //we only check the parent handle |
116 else if(EMTPRespCodeInvalidObjectHandle == responseCode) //we only check the parent handle |
117 { |
117 { |
118 responseCode = EMTPRespCodeInvalidParentObject; |
118 responseCode = EMTPRespCodeInvalidParentObject; |
119 } |
119 } |
120 |
120 |
121 __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode)); |
121 OstTrace1( TRACE_FLOW, CMTPIMAGEDPCOPYOBJECT_CHECKREQUESTL, |
122 __FLOG(_L8("<< CMTPImageDpCopyObject::CheckRequestL")); |
122 "CheckRequestL - Exit with responseCode = 0x%04X", responseCode ); |
|
123 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_CHECKREQUESTL_EXIT ); |
123 return responseCode; |
124 return responseCode; |
124 } |
125 } |
125 |
126 |
126 /** |
127 /** |
127 CopyObject request handler |
128 CopyObject request handler |
128 */ |
129 */ |
129 void CMTPImageDpCopyObject::ServiceL() |
130 void CMTPImageDpCopyObject::ServiceL() |
130 { |
131 { |
131 __FLOG(_L8(">> CMTPImageDpCopyObject::ServiceL")); |
132 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_SERVICEL_ENTRY ); |
132 TUint32 handle = KMTPHandleNone; |
133 TUint32 handle = KMTPHandleNone; |
133 TMTPResponseCode responseCode = CopyObjectL(handle); |
134 TMTPResponseCode responseCode = CopyObjectL(handle); |
134 if(responseCode == EMTPRespCodeOK) |
135 if(responseCode == EMTPRespCodeOK) |
135 { |
136 { |
136 SendResponseL(EMTPRespCodeOK, 1, &handle); |
137 SendResponseL(EMTPRespCodeOK, 1, &handle); |
137 } |
138 } |
138 else |
139 else |
139 { |
140 { |
140 SendResponseL(responseCode); |
141 SendResponseL(responseCode); |
141 } |
142 } |
142 __FLOG(_L8("<< CMTPImageDpCopyObject::ServiceL")); |
143 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_SERVICEL_EXIT ); |
143 } |
144 } |
144 |
145 |
145 /** |
146 /** |
146 Copy object operation |
147 Copy object operation |
147 @return the object handle of the resulting object. |
148 @return the object handle of the resulting object. |
148 */ |
149 */ |
149 TMTPResponseCode CMTPImageDpCopyObject::CopyObjectL(TUint32& aNewHandle) |
150 TMTPResponseCode CMTPImageDpCopyObject::CopyObjectL(TUint32& aNewHandle) |
150 { |
151 { |
151 __FLOG(_L8(">> CMTPImageDpCopyObject::CopyObjectL")); |
152 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_COPYOBJECTL_ENTRY ); |
152 TMTPResponseCode responseCode = EMTPRespCodeOK; |
153 TMTPResponseCode responseCode = EMTPRespCodeOK; |
153 aNewHandle = KMTPHandleNone; |
154 aNewHandle = KMTPHandleNone; |
154 |
155 |
155 GetParametersL(); |
156 GetParametersL(); |
156 |
157 |
171 |
172 |
172 if(responseCode == EMTPRespCodeOK) |
173 if(responseCode == EMTPRespCodeOK) |
173 { |
174 { |
174 aNewHandle = CopyFileL(oldFileName, iNewFileName); |
175 aNewHandle = CopyFileL(oldFileName, iNewFileName); |
175 } |
176 } |
176 __FLOG(_L8("<< CMTPImageDpCopyObject::CopyObjectL")); |
177 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_COPYOBJECTL_EXIT ); |
177 return responseCode; |
178 return responseCode; |
178 } |
179 } |
179 |
180 |
180 /** |
181 /** |
181 A helper function of CopyObjectL. |
182 A helper function of CopyObjectL. |
182 @param aNewFileName the new full filename after copy. |
183 @param aNewFileName the new full filename after copy. |
183 @return objectHandle of new copy of object. |
184 @return objectHandle of new copy of object. |
184 */ |
185 */ |
185 TUint32 CMTPImageDpCopyObject::CopyFileL(const TDesC& aOldFileName, const TDesC& aNewFileName) |
186 TUint32 CMTPImageDpCopyObject::CopyFileL(const TDesC& aOldFileName, const TDesC& aNewFileName) |
186 { |
187 { |
187 __FLOG(_L8(">> CMTPImageDpCopyObject::CopyFileL")); |
188 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_COPYFILEL_ENTRY ); |
188 TCleanupItem anItem(FailRecover, reinterpret_cast<TAny*>(this)); |
189 TCleanupItem anItem(FailRecover, reinterpret_cast<TAny*>(this)); |
189 CleanupStack::PushL(anItem); |
190 CleanupStack::PushL(anItem); |
190 |
191 |
191 GetPreviousPropertiesL(aOldFileName); |
192 GetPreviousPropertiesL(aOldFileName); |
192 User::LeaveIfError(iFileMan->Copy(aOldFileName, *iDest)); |
193 LEAVEIFERROR(iFileMan->Copy(aOldFileName, *iDest), |
|
194 OstTraceExt3( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_COPYFILEL, |
|
195 "Copy %S to %S failed! error code %d", aOldFileName, *iDest, munged_err)); |
|
196 |
193 iRollbackActionL.AppendL(RollBackFromFsL); |
197 iRollbackActionL.AppendL(RollBackFromFsL); |
194 SetPreviousPropertiesL(aNewFileName); |
198 SetPreviousPropertiesL(aNewFileName); |
195 |
199 |
196 iFramework.ObjectMgr().InsertObjectL(*iTargetObjectInfo); |
200 iFramework.ObjectMgr().InsertObjectL(*iTargetObjectInfo); |
197 //check object whether it is a new image object |
201 //check object whether it is a new image object |
229 delete iDest; |
233 delete iDest; |
230 iDest = NULL; |
234 iDest = NULL; |
231 iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL(); |
235 iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL(); |
232 iNewParentHandle = parentObjectHandle; |
236 iNewParentHandle = parentObjectHandle; |
233 } |
237 } |
234 __FLOG(_L8("<< CMTPImageDpCopyObject::GetParametersL")); |
238 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_GETPARAMETERSL_EXIT ); |
235 } |
239 } |
236 |
240 |
237 /** |
241 /** |
238 Get a default parent object, ff the request does not specify a parent object, |
242 Get a default parent object, ff the request does not specify a parent object, |
239 */ |
243 */ |
240 void CMTPImageDpCopyObject::SetDefaultParentObjectL() |
244 void CMTPImageDpCopyObject::SetDefaultParentObjectL() |
241 { |
245 { |
242 __FLOG(_L8(">> CMTPImageDpCopyObject::SetDefaultParentObjectL")); |
246 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_ENTRY ); |
243 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); |
247 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); |
244 User::LeaveIfError(drive); |
248 LEAVEIFERROR(drive, |
|
249 OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL, "No driver number for %d! error code %d",iStorageId, munged_err)); |
245 TChar driveLetter; |
250 TChar driveLetter; |
246 iFramework.Fs().DriveToChar(drive, driveLetter); |
251 iFramework.Fs().DriveToChar(drive, driveLetter); |
247 TFileName driveBuf; |
252 TFileName driveBuf; |
248 driveBuf.Append(driveLetter); |
253 driveBuf.Append(driveLetter); |
249 driveBuf = BaflUtils::RootFolderPath(driveBuf.Left(1)); |
254 driveBuf = BaflUtils::RootFolderPath(driveBuf.Left(1)); |
250 delete iDest; |
255 delete iDest; |
251 iDest = NULL; |
256 iDest = NULL; |
252 iDest = driveBuf.AllocL(); |
257 iDest = driveBuf.AllocL(); |
253 iNewParentHandle = KMTPHandleNoParent; |
258 iNewParentHandle = KMTPHandleNoParent; |
254 __FLOG(_L8("<< CMTPImageDpCopyObject::SetDefaultParentObjectL")); |
259 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_EXIT ); |
255 } |
260 } |
256 |
261 |
257 /** |
262 /** |
258 Check if we can copy the file to the new location |
263 Check if we can copy the file to the new location |
259 */ |
264 */ |
260 TMTPResponseCode CMTPImageDpCopyObject::CanCopyObjectL(const TDesC& aOldName, const TDesC& aNewName) const |
265 TMTPResponseCode CMTPImageDpCopyObject::CanCopyObjectL(const TDesC& aOldName, const TDesC& aNewName) const |
261 { |
266 { |
262 __FLOG(_L8(">> CMTPImageDpCopyObject::CanCopyObjectL")); |
267 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL_ENTRY ); |
263 TMTPResponseCode result = EMTPRespCodeOK; |
268 TMTPResponseCode result = EMTPRespCodeOK; |
264 |
269 |
265 TEntry fileEntry; |
270 TEntry fileEntry; |
266 User::LeaveIfError(iFramework.Fs().Entry(aOldName, fileEntry)); |
271 LEAVEIFERROR(iFramework.Fs().Entry(aOldName, fileEntry), |
|
272 OstTraceExt2( TRACE_ERROR, DUP1_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, |
|
273 "Gets the entry details for %S failed! error code %d", aOldName, munged_err )); |
267 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); |
274 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); |
268 User::LeaveIfError(drive); |
275 LEAVEIFERROR(drive, |
|
276 OstTraceExt2( TRACE_ERROR, DUP2_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, |
|
277 "Gets drive for storage %d failed! error code %d", iStorageId, munged_err )); |
269 TVolumeInfo volumeInfo; |
278 TVolumeInfo volumeInfo; |
270 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
279 LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive), |
|
280 OstTraceExt2( TRACE_ERROR, DUP3_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, |
|
281 "Gets volume information for driver %d failed! error code %d", drive, munged_err )); |
271 |
282 |
272 if(volumeInfo.iFree < fileEntry.FileSize()) |
283 if(volumeInfo.iFree < fileEntry.FileSize()) |
273 { |
284 { |
274 result = EMTPRespCodeStoreFull; |
285 result = EMTPRespCodeStoreFull; |
275 } |
286 } |
276 else if (BaflUtils::FileExists(iFramework.Fs(), aNewName)) |
287 else if (BaflUtils::FileExists(iFramework.Fs(), aNewName)) |
277 { |
288 { |
278 result = EMTPRespCodeInvalidParentObject; |
289 result = EMTPRespCodeInvalidParentObject; |
279 } |
290 } |
280 __FLOG_VA((_L8("CanCopyObjectL - Exit with response code 0x%04X"), result)); |
291 OstTrace1( TRACE_NORMAL, CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, |
281 __FLOG(_L8("<< CMTPImageDpCopyObject::CanCopyObjectL")); |
292 "CanCopyObjectL - Exit with response code 0x%04X", result ); |
|
293 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL_EXIT ); |
282 return result; |
294 return result; |
283 } |
295 } |
284 |
296 |
285 /** |
297 /** |
286 Save the object properties before doing the copy |
298 Save the object properties before doing the copy |
287 */ |
299 */ |
288 void CMTPImageDpCopyObject::GetPreviousPropertiesL(const TDesC& aOldFileName) |
300 void CMTPImageDpCopyObject::GetPreviousPropertiesL(const TDesC& aOldFileName) |
289 { |
301 { |
290 __FLOG(_L8("GetPreviousPropertiesL - Entry")); |
302 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_GETPREVIOUSPROPERTIESL_ENTRY ); |
291 User::LeaveIfError(iFramework.Fs().Modified(aOldFileName, iDateModified)); |
303 LEAVEIFERROR(iFramework.Fs().Modified(aOldFileName, iDateModified), |
292 __FLOG(_L8("GetPreviousPropertiesL - Exit")); |
304 OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_GETPREVIOUSPROPERTIESL, |
|
305 "Gets the last modification date and time failed for %S! error code %d", aOldFileName, munged_err )); |
|
306 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_GETPREVIOUSPROPERTIESL_EXIT ); |
293 } |
307 } |
294 |
308 |
295 /** |
309 /** |
296 Set the object properties after doing the copy |
310 Set the object properties after doing the copy |
297 */ |
311 */ |
298 void CMTPImageDpCopyObject::SetPreviousPropertiesL(const TDesC& aNewFileName) |
312 void CMTPImageDpCopyObject::SetPreviousPropertiesL(const TDesC& aNewFileName) |
299 { |
313 { |
300 __FLOG(_L8("SetPreviousPropertiesL - Entry")); |
314 OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_SETPREVIOUSPROPERTIESL_ENTRY ); |
301 User::LeaveIfError(iFramework.Fs().SetModified(aNewFileName, iDateModified)); |
315 LEAVEIFERROR(iFramework.Fs().SetModified(aNewFileName, iDateModified), |
302 |
316 OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPCOPYOBJECT_SETPREVIOUSPROPERTIESL, |
|
317 "Sets the date and time for %S failed. Error code %d", aNewFileName, munged_err)); |
303 iTargetObjectInfo = CMTPObjectMetaData::NewL(); |
318 iTargetObjectInfo = CMTPObjectMetaData::NewL(); |
304 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EDataProviderId, iSrcObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId)); |
319 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EDataProviderId, iSrcObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId)); |
305 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EFormatCode, iSrcObjectInfo->Uint(CMTPObjectMetaData::EFormatCode)); |
320 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EFormatCode, iSrcObjectInfo->Uint(CMTPObjectMetaData::EFormatCode)); |
306 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EFormatSubCode, iSrcObjectInfo->Uint(CMTPObjectMetaData::EFormatSubCode)); |
321 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EFormatSubCode, iSrcObjectInfo->Uint(CMTPObjectMetaData::EFormatSubCode)); |
307 iTargetObjectInfo->SetDesCL(CMTPObjectMetaData::EName, iSrcObjectInfo->DesC(CMTPObjectMetaData::EName)); |
322 iTargetObjectInfo->SetDesCL(CMTPObjectMetaData::EName, iSrcObjectInfo->DesC(CMTPObjectMetaData::EName)); |
308 iTargetObjectInfo->SetUint(CMTPObjectMetaData::ENonConsumable, iSrcObjectInfo->Uint(CMTPObjectMetaData::ENonConsumable)); |
323 iTargetObjectInfo->SetUint(CMTPObjectMetaData::ENonConsumable, iSrcObjectInfo->Uint(CMTPObjectMetaData::ENonConsumable)); |
309 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
324 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EParentHandle, iNewParentHandle); |
310 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
325 iTargetObjectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
311 iTargetObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName); |
326 iTargetObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, aNewFileName); |
312 __FLOG(_L8("SetPreviousPropertiesL - Exit")); |
327 OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_SETPREVIOUSPROPERTIESL_EXIT ); |
313 } |
328 } |
314 |
329 |
315 void CMTPImageDpCopyObject::FailRecover(TAny* aCopyOperation) |
330 void CMTPImageDpCopyObject::FailRecover(TAny* aCopyOperation) |
316 { |
331 { |
317 reinterpret_cast<CMTPImageDpCopyObject*>(aCopyOperation)->RollBack(); |
332 reinterpret_cast<CMTPImageDpCopyObject*>(aCopyOperation)->RollBack(); |