|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include <f32file.h> |
|
22 #include <bautils.h> |
|
23 |
|
24 #include <mtp/mmtpdataproviderframework.h> |
|
25 |
|
26 #include <mtp/cmtpobjectmetadata.h> |
|
27 #include <mtp/cmtptypefile.h> |
|
28 #include <mtp/cmtptypeobjectinfo.h> |
|
29 #include <mtp/cmtptypeobjectproplist.h> |
|
30 #include <mtp/cmtptypestring.h> |
|
31 #include <mtp/mmtpobjectmgr.h> |
|
32 #include <mtp/mmtpstoragemgr.h> |
|
33 #include <mtp/mtpprotocolconstants.h> |
|
34 #include <mtp/mmtpconnection.h> |
|
35 #include <mtp/tmtptyperequest.h> |
|
36 |
|
37 #include "mtpdebug.h" |
|
38 #include "cmtpimagedpobjectpropertymgr.h" |
|
39 #include "cmtpimagedpsendobjectinfo.h" |
|
40 #include "mtpimagedppanic.h" |
|
41 #include "mtpimagedpconst.h" |
|
42 #include "cmtpimagedpthumbnailcreator.h" |
|
43 #include "mtpimagedputilits.h" |
|
44 #include "cmtpimagedp.h" |
|
45 |
|
46 // Class constants. |
|
47 __FLOG_STMT(_LIT8(KComponent, "ImageDPSendObjectInfo");) |
|
48 |
|
49 const TInt RollbackFuncCnt = 3; |
|
50 |
|
51 const TMTPRequestElementInfo KMTPSendObjectPropListPolicy[] = |
|
52 { |
|
53 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeStorageId, EMTPElementAttrWrite, 1, 0, 0}, |
|
54 {TMTPTypeRequest::ERequestParameter2, EMTPElementTypeObjectHandle, EMTPElementAttrDir, 2, KMTPHandleAll, KMTPHandleNone} |
|
55 }; |
|
56 /** |
|
57 Two-phase construction method |
|
58 @param aFramework The data provider framework |
|
59 @param aConnection The connection from which the request comes |
|
60 @return a pointer to the created request processor object |
|
61 */ |
|
62 MMTPRequestProcessor* CMTPImageDpSendObjectInfo::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) |
|
63 { |
|
64 CMTPImageDpSendObjectInfo* self = new (ELeave) CMTPImageDpSendObjectInfo(aFramework, aConnection,aDataProvider); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 /** |
|
72 Destructor |
|
73 */ |
|
74 CMTPImageDpSendObjectInfo::~CMTPImageDpSendObjectInfo() |
|
75 { |
|
76 __FLOG(_L8("CMTPImageDpSendObjectInfo::~CMTPImageDpSendObjectInfo - Entry")); |
|
77 |
|
78 Rollback(); |
|
79 iRollbackList.Close(); |
|
80 |
|
81 delete iDateMod; |
|
82 delete iDateCreated; |
|
83 delete iFileReceived; |
|
84 delete iParentSuid; |
|
85 delete iReceivedObject; |
|
86 delete iObjectInfo; |
|
87 delete iObjectPropList; |
|
88 |
|
89 __FLOG(_L8("CMTPImageDpSendObjectInfo::~CMTPImageDpSendObjectInfo - Exit")); |
|
90 __FLOG_CLOSE; |
|
91 } |
|
92 |
|
93 /** |
|
94 Standard c++ constructor |
|
95 @param aFramework The data provider framework |
|
96 @param aConnection The connection from which the request comes |
|
97 */ |
|
98 CMTPImageDpSendObjectInfo::CMTPImageDpSendObjectInfo(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, CMTPImageDataProvider& aDataProvider) : |
|
99 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
100 iDataProvider(aDataProvider), |
|
101 iObjectPropertyMgr(aDataProvider.PropertyMgr()) |
|
102 { |
|
103 |
|
104 } |
|
105 |
|
106 #define ADD_FSM_ENTRY(currentstate, event, nextstate, failedstate, action) \ |
|
107 iStateMachine[currentstate][event].iNextSuccessState = nextstate; \ |
|
108 iStateMachine[currentstate][event].iNextFailedState = failedstate; \ |
|
109 iStateMachine[currentstate][event].iFsmAction = action |
|
110 |
|
111 /** |
|
112 Second-phase construction |
|
113 */ |
|
114 void CMTPImageDpSendObjectInfo::ConstructL() |
|
115 { |
|
116 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
117 __FLOG(_L8("CMTPImageDpSendObjectInfo::ConstructL - Entry")); |
|
118 |
|
119 iRollbackList.ReserveL(RollbackFuncCnt); |
|
120 iExpectedSendObjectRequest.SetUint16(TMTPTypeRequest::ERequestOperationCode, EMTPOpCodeSendObject); |
|
121 iReceivedObject = CMTPObjectMetaData::NewL(); |
|
122 iReceivedObject->SetUint(CMTPObjectMetaData::EDataProviderId, iFramework.DataProviderId()); |
|
123 |
|
124 // build FSM matrix |
|
125 // process sendobjectinfo/sendobjectproplist operation |
|
126 ADD_FSM_ENTRY(EStateIdle, EObjectInfoEvent, EObjectInfoCheck, EStateIdle, FsmCheckObjectInfoParamsL); |
|
127 ADD_FSM_ENTRY(EStateIdle, EObjectPropListEvent, EObjectInfoCheck, EStateIdle, FsmCheckObjectPropListParamsL); |
|
128 ADD_FSM_ENTRY(EStateIdle, EObjectEvent, EStateIdle, EStateIdle, FsmCheckObjectParams); |
|
129 |
|
130 ADD_FSM_ENTRY(EObjectInfoCheck, EObjectInfoEvent, EObjectInfoServ, EStateIdle, FsmServiceSendObjectInfoL); |
|
131 ADD_FSM_ENTRY(EObjectInfoCheck, EObjectPropListEvent, EObjectInfoServ, EStateIdle, FsmServiceSendObjectPropListL); |
|
132 ADD_FSM_ENTRY(EObjectInfoCheck, EObjectEvent, EStateEnd, EStateEnd, NULL); |
|
133 |
|
134 ADD_FSM_ENTRY(EObjectInfoServ, EObjectInfoEvent, EObjectInfoSucceed, EStateIdle, FsmDoHandleSendObjectInfoCompleteL); |
|
135 ADD_FSM_ENTRY(EObjectInfoServ, EObjectPropListEvent, EObjectInfoSucceed, EStateIdle, FsmDoHandleSendObjectPropListCompleteL); |
|
136 ADD_FSM_ENTRY(EObjectInfoServ, EObjectEvent, EStateEnd, EStateEnd, NULL); |
|
137 |
|
138 // process sendobject operation |
|
139 ADD_FSM_ENTRY(EObjectInfoSucceed, EObjectInfoEvent, EObjectInfoCheck, EStateIdle, FsmCheckObjectInfoParamsL); |
|
140 ADD_FSM_ENTRY(EObjectInfoSucceed, EObjectPropListEvent, EObjectInfoCheck, EStateIdle, FsmCheckObjectPropListParamsL); |
|
141 ADD_FSM_ENTRY(EObjectInfoSucceed, EObjectEvent, EObjectCheck, EObjectInfoSucceed, FsmCheckObjectParams); |
|
142 |
|
143 ADD_FSM_ENTRY(EObjectCheck, EObjectInfoEvent, EStateEnd, EStateEnd, NULL); |
|
144 ADD_FSM_ENTRY(EObjectCheck, EObjectPropListEvent, EStateEnd, EStateEnd, NULL); |
|
145 ADD_FSM_ENTRY(EObjectCheck, EObjectEvent, EObjectServ, EObjectInfoSucceed, FsmServiceSendObjectL); |
|
146 |
|
147 ADD_FSM_ENTRY(EObjectServ, EObjectInfoEvent, EStateEnd, EStateEnd, NULL); |
|
148 ADD_FSM_ENTRY(EObjectServ, EObjectPropListEvent, EStateEnd, EStateEnd, NULL); |
|
149 ADD_FSM_ENTRY(EObjectServ, EObjectEvent, EStateIdle, EObjectInfoSucceed, FsmDoHandleSendObjectCompleteL); |
|
150 |
|
151 __FLOG(_L8("CMTPImageEnumerator::ConstructL - Exit")); |
|
152 } |
|
153 |
|
154 TBool CMTPImageDpSendObjectInfo::FsmCheckObjectInfoParamsL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
155 { |
|
156 return aObject->CheckObjectInfoParamsL(aPtr); |
|
157 } |
|
158 |
|
159 TBool CMTPImageDpSendObjectInfo::FsmCheckObjectPropListParamsL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
160 { |
|
161 return aObject->CheckObjectPropListParamsL(aPtr); |
|
162 } |
|
163 |
|
164 TBool CMTPImageDpSendObjectInfo::FsmCheckObjectParams(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
165 { |
|
166 return aObject->CheckObjectParams(aPtr); |
|
167 } |
|
168 |
|
169 TBool CMTPImageDpSendObjectInfo::FsmServiceSendObjectInfoL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
170 { |
|
171 return aObject->ServiceSendObjectInfoL(aPtr); |
|
172 } |
|
173 |
|
174 TBool CMTPImageDpSendObjectInfo::FsmServiceSendObjectPropListL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
175 { |
|
176 return aObject->ServiceSendObjectPropListL(aPtr); |
|
177 } |
|
178 |
|
179 TBool CMTPImageDpSendObjectInfo::FsmServiceSendObjectL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
180 { |
|
181 return aObject->ServiceSendObjectL(aPtr); |
|
182 } |
|
183 |
|
184 TBool CMTPImageDpSendObjectInfo::FsmDoHandleSendObjectInfoCompleteL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
185 { |
|
186 return aObject->DoHandleSendObjectInfoCompleteL(aPtr); |
|
187 } |
|
188 |
|
189 TBool CMTPImageDpSendObjectInfo::FsmDoHandleSendObjectPropListCompleteL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
190 { |
|
191 return aObject->DoHandleSendObjectPropListCompleteL(aPtr); |
|
192 } |
|
193 |
|
194 TBool CMTPImageDpSendObjectInfo::FsmDoHandleSendObjectCompleteL(CMTPImageDpSendObjectInfo* aObject, TAny *aPtr) |
|
195 { |
|
196 return aObject->DoHandleSendObjectCompleteL(aPtr); |
|
197 } |
|
198 |
|
199 /** |
|
200 Verify the request |
|
201 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
|
202 */ |
|
203 TMTPResponseCode CMTPImageDpSendObjectInfo::CheckRequestL() |
|
204 { |
|
205 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckRequestL - Entry")); |
|
206 |
|
207 iOperationCode = Request().Uint16(TMTPTypeRequest::ERequestOperationCode); |
|
208 |
|
209 switch (iOperationCode) |
|
210 { |
|
211 case EMTPOpCodeSendObjectInfo: |
|
212 iEvent = EObjectInfoEvent; |
|
213 iElementCount = sizeof(KMTPSendObjectPropListPolicy) / sizeof(TMTPRequestElementInfo); //for the checker |
|
214 iElements = KMTPSendObjectPropListPolicy; |
|
215 break; |
|
216 |
|
217 case EMTPOpCodeSendObjectPropList: |
|
218 iEvent = EObjectPropListEvent; |
|
219 iElementCount = sizeof(KMTPSendObjectPropListPolicy) / sizeof(TMTPRequestElementInfo); //for the checker |
|
220 iElements = KMTPSendObjectPropListPolicy; |
|
221 break; |
|
222 |
|
223 case EMTPOpCodeSendObject: |
|
224 //In ParseRouter everytime SendObject gets resolved then will be removed from Registry |
|
225 //Right away therefore we need reRegister it here again in case possible cancelRequest |
|
226 //Against this SendObject being raised. |
|
227 iExpectedSendObjectRequest.SetUint32(TMTPTypeRequest::ERequestSessionID, iSessionId); |
|
228 iFramework.RouteRequestRegisterL(iExpectedSendObjectRequest, iConnection); |
|
229 iEvent = EObjectEvent; |
|
230 iElementCount = 0; //for the checker |
|
231 iElements = NULL; |
|
232 break; |
|
233 |
|
234 default: |
|
235 // Nothing to do |
|
236 break; |
|
237 } |
|
238 |
|
239 FsmAction pCheck = iStateMachine[iCurrentState][iEvent].iFsmAction; |
|
240 __ASSERT_ALWAYS((pCheck != NULL), Panic(EMTPImageDpNoMatchingProcessor)); |
|
241 |
|
242 //coverity[var_deref_model] |
|
243 TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL(); |
|
244 if(EMTPRespCodeOK == result) |
|
245 { |
|
246 TBool ret = EFalse; |
|
247 TRAPD(err, ret = (*pCheck)(this, &result)); |
|
248 if (ret) |
|
249 { |
|
250 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextSuccessState; |
|
251 } |
|
252 else |
|
253 { |
|
254 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextFailedState; |
|
255 } |
|
256 User::LeaveIfError(err); |
|
257 } |
|
258 __FLOG_1(_L8("CheckRequestL - Result: 0x%04x"), result); |
|
259 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckRequestL - Exit")); |
|
260 |
|
261 return result; |
|
262 } |
|
263 |
|
264 TBool CMTPImageDpSendObjectInfo::HasDataphase() const |
|
265 { |
|
266 return ETrue; |
|
267 } |
|
268 |
|
269 TBool CMTPImageDpSendObjectInfo::CheckObjectInfoParamsL(TAny *aPtr) |
|
270 { |
|
271 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectInfoParamsL - Entry")); |
|
272 |
|
273 TMTPResponseCode* ret = static_cast<TMTPResponseCode*>(aPtr); |
|
274 *ret = EMTPRespCodeOK; |
|
275 |
|
276 const TUint32 storeId(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
277 const TUint32 parentHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter2)); |
|
278 |
|
279 // this checking is only valid when the second parameter is not a special value. |
|
280 if (parentHandle != KMTPHandleAll && parentHandle != KMTPHandleNone) |
|
281 { |
|
282 //does not take owernship |
|
283 CMTPObjectMetaData* parentObjInfo = CMTPObjectMetaData::NewLC(); |
|
284 if (iFramework.ObjectMgr().ObjectL(parentHandle, *parentObjInfo)) |
|
285 { |
|
286 TUint32 storageId = parentObjInfo->Uint(CMTPObjectMetaData::EStorageId); |
|
287 if (storeId != storageId) |
|
288 { |
|
289 *ret = EMTPRespCodeInvalidObjectHandle; |
|
290 } |
|
291 } |
|
292 else |
|
293 { |
|
294 *ret = EMTPRespCodeInvalidObjectHandle; |
|
295 } |
|
296 CleanupStack::PopAndDestroy(parentObjInfo); |
|
297 } |
|
298 |
|
299 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectInfoParamsL - Exit")); |
|
300 return (*ret == EMTPRespCodeOK) ? ETrue : EFalse; |
|
301 } |
|
302 |
|
303 TBool CMTPImageDpSendObjectInfo::CheckObjectPropListParamsL(TAny *aPtr) |
|
304 { |
|
305 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectPropListParamsL - Entry")); |
|
306 TMTPResponseCode* ret = static_cast<TMTPResponseCode*>(aPtr); |
|
307 *ret = EMTPRespCodeOK; |
|
308 |
|
309 TMTPFormatCode formatCode = static_cast<TMTPFormatCode>(Request().Uint32(TMTPTypeRequest::ERequestParameter3)); |
|
310 if (!IsFormatValid(formatCode)) |
|
311 { |
|
312 *ret = EMTPRespCodeInvalidObjectFormatCode; |
|
313 } |
|
314 else |
|
315 { |
|
316 iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
317 TUint32 objectSizeHigh = Request().Uint32(TMTPTypeRequest::ERequestParameter4); |
|
318 TUint32 objectSizeLow = Request().Uint32(TMTPTypeRequest::ERequestParameter5); |
|
319 iObjectSize = MAKE_TUINT64(objectSizeHigh, objectSizeLow); |
|
320 |
|
321 if (iStorageId == KMTPStorageDefault) |
|
322 { |
|
323 iStorageId = iFramework.StorageMgr().DefaultStorageId(); |
|
324 } |
|
325 |
|
326 //if the object size is more,then report this error. |
|
327 if (!CanStoreFileL(iStorageId, iObjectSize)) |
|
328 { |
|
329 *ret = EMTPRespCodeStoreFull; |
|
330 } |
|
331 } |
|
332 |
|
333 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectPropListParamsL - Exit")); |
|
334 return (*ret == EMTPRespCodeOK) ? ETrue : EFalse; |
|
335 } |
|
336 |
|
337 TBool CMTPImageDpSendObjectInfo::CheckObjectParams(TAny *aPtr) |
|
338 { |
|
339 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectParamsL - Entry")); |
|
340 TMTPResponseCode* ret = static_cast<TMTPResponseCode*>(aPtr); |
|
341 *ret = EMTPRespCodeOK; |
|
342 |
|
343 /** |
|
344 * If the previous request is not the SendObjectInfo/SendObjectPropList/UpdateObjectPropList operation, |
|
345 * the SendObject operation should failed. |
|
346 */ |
|
347 if ( (iPreviousTransactionID + 1) != Request().Uint32(TMTPTypeRequest::ERequestTransactionID)) |
|
348 { |
|
349 *ret = EMTPRespCodeNoValidObjectInfo; |
|
350 } |
|
351 |
|
352 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckObjectParamsL - Exit")); |
|
353 return (*ret == EMTPRespCodeOK) ? ETrue : EFalse; |
|
354 } |
|
355 |
|
356 /** |
|
357 SendObjectInfo/SendObject request handler |
|
358 NOTE: SendObjectInfo has to be comes before SendObject requests. To maintain the state information |
|
359 between the two requests, the two requests are combined together in one request processor. |
|
360 */ |
|
361 void CMTPImageDpSendObjectInfo::ServiceL() |
|
362 { |
|
363 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceL - Entry")); |
|
364 |
|
365 FsmAction pService = iStateMachine[iCurrentState][iEvent].iFsmAction; |
|
366 __ASSERT_DEBUG(pService, Panic(EMTPImageDpNoMatchingProcessor)); |
|
367 |
|
368 TBool ret = EFalse; |
|
369 TRAPD(err, ret = (*pService)(this, NULL)); |
|
370 if (ret) |
|
371 { |
|
372 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextSuccessState; |
|
373 } |
|
374 else |
|
375 { |
|
376 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextFailedState; |
|
377 } |
|
378 |
|
379 if (err != KErrNone) |
|
380 { |
|
381 Rollback(); |
|
382 } |
|
383 User::LeaveIfError(err); |
|
384 |
|
385 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceL - Exit")); |
|
386 } |
|
387 |
|
388 /** |
|
389 Override to match both the SendObjectInfo and SendObject requests |
|
390 @param aRequest The request to match |
|
391 @param aConnection The connection from which the request comes |
|
392 @return ETrue if the processor can handle the request, otherwise EFalse |
|
393 */ |
|
394 TBool CMTPImageDpSendObjectInfo::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const |
|
395 { |
|
396 __FLOG(_L8("CMTPImageDpSendObjectInfo::Match - Entry")); |
|
397 TBool result = EFalse; |
|
398 TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode); |
|
399 if ((operationCode == EMTPOpCodeSendObjectInfo || |
|
400 operationCode == EMTPOpCodeSendObject || |
|
401 operationCode == EMTPOpCodeSendObjectPropList) && |
|
402 &iConnection == &aConnection) |
|
403 { |
|
404 result = ETrue; |
|
405 } |
|
406 __FLOG(_L8("CMTPImageDpSendObjectInfo::Match - Exit")); |
|
407 return result; |
|
408 } |
|
409 |
|
410 /** |
|
411 Override to handle the response phase of SendObjectInfo and SendObject requests |
|
412 @return EFalse |
|
413 */ |
|
414 TBool CMTPImageDpSendObjectInfo::DoHandleResponsePhaseL() |
|
415 { |
|
416 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleResponsePhaseL - Entry")); |
|
417 |
|
418 //to check if the sending/receiving data is successful |
|
419 iSuccessful = !iCancelled; |
|
420 |
|
421 FsmAction pResponse = iStateMachine[iCurrentState][iEvent].iFsmAction; |
|
422 __ASSERT_DEBUG(pResponse, Panic(EMTPImageDpNoMatchingProcessor)); |
|
423 |
|
424 TBool ret = EFalse; |
|
425 TRAPD(err, ret = (*pResponse)(this, &iSuccessful)) |
|
426 if (ret) |
|
427 { |
|
428 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextSuccessState; |
|
429 } |
|
430 else |
|
431 { |
|
432 iCurrentState = iStateMachine[iCurrentState][iEvent].iNextFailedState; |
|
433 } |
|
434 |
|
435 if (err != KErrNone) |
|
436 { |
|
437 Rollback(); |
|
438 } |
|
439 User::LeaveIfError(err); |
|
440 |
|
441 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleResponsePhaseL - Exit")); |
|
442 return EFalse; |
|
443 } |
|
444 |
|
445 /** |
|
446 Override to handle the completing phase of SendObjectInfo and SendObject requests |
|
447 @return ETrue if succesfully received the file, otherwise EFalse |
|
448 */ |
|
449 TBool CMTPImageDpSendObjectInfo::DoHandleCompletingPhaseL() |
|
450 { |
|
451 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleCompletingPhaseL - Entry")); |
|
452 TBool result = ETrue; |
|
453 CMTPRequestProcessor::DoHandleCompletingPhaseL(); |
|
454 |
|
455 if (iSuccessful) |
|
456 { |
|
457 if (iOperationCode == EMTPOpCodeSendObjectInfo || iOperationCode == EMTPOpCodeSendObjectPropList) |
|
458 { |
|
459 iPreviousTransactionID = Request().Uint32(TMTPTypeRequest::ERequestTransactionID); |
|
460 result = EFalse; |
|
461 } |
|
462 } |
|
463 else |
|
464 { |
|
465 if (iOperationCode == EMTPOpCodeSendObject) |
|
466 { |
|
467 iPreviousTransactionID++; |
|
468 } |
|
469 result = EFalse; |
|
470 } |
|
471 |
|
472 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleCompletingPhaseL - Exit")); |
|
473 return result; |
|
474 } |
|
475 |
|
476 /** |
|
477 SendObjectInfo request handler |
|
478 */ |
|
479 TBool CMTPImageDpSendObjectInfo::ServiceSendObjectInfoL(TAny* /*aPtr*/) |
|
480 { |
|
481 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectInfoL - Entry")); |
|
482 |
|
483 delete iObjectInfo; |
|
484 iObjectInfo = NULL; |
|
485 iObjectInfo = CMTPTypeObjectInfo::NewL(); |
|
486 ReceiveDataL(*iObjectInfo); |
|
487 |
|
488 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectInfoL - Exit")); |
|
489 return ETrue; |
|
490 } |
|
491 |
|
492 /** |
|
493 SendObjectPropList request handler |
|
494 */ |
|
495 TBool CMTPImageDpSendObjectInfo::ServiceSendObjectPropListL(TAny* /*aPtr*/) |
|
496 { |
|
497 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectPropListL - Entry")); |
|
498 |
|
499 delete iObjectPropList; |
|
500 iObjectPropList = NULL; |
|
501 iObjectPropList = CMTPTypeObjectPropList::NewL(); |
|
502 iReceivedObject->SetUint(CMTPObjectMetaData::EFormatCode, iRequest->Uint32(TMTPTypeRequest::ERequestParameter3)); |
|
503 ReceiveDataL(*iObjectPropList); |
|
504 |
|
505 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectPropListL - Exit")); |
|
506 return ETrue; |
|
507 } |
|
508 |
|
509 /** |
|
510 SendObject request handler |
|
511 */ |
|
512 TBool CMTPImageDpSendObjectInfo::ServiceSendObjectL(TAny* /*aPtr*/) |
|
513 { |
|
514 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Entry")); |
|
515 |
|
516 iFramework.ObjectMgr().CommitReservedObjectHandleL(*iReceivedObject); |
|
517 //prepare for rollback |
|
518 iRollbackList.Append(RemoveObjectFromDb); |
|
519 |
|
520 delete iFileReceived; |
|
521 iFileReceived = NULL; |
|
522 iFileReceived = CMTPTypeFile::NewL(iFramework.Fs(), iFullPath, EFileWrite); |
|
523 iFileReceived->SetSizeL(iObjectSize); |
|
524 |
|
525 //prepare for rollback |
|
526 iRollbackList.Append(RemoveObjectFromFs); |
|
527 ReceiveDataL(*iFileReceived); |
|
528 |
|
529 __FLOG(_L8("CMTPImageDpSendObjectInfo::ServiceSendObjectL - Exit")); |
|
530 return ETrue; |
|
531 } |
|
532 |
|
533 /** |
|
534 Get a default parent object, if the request does not specify a parent object. |
|
535 */ |
|
536 void CMTPImageDpSendObjectInfo::GetDefaultParentObjectL() |
|
537 { |
|
538 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetDefaultParentObjectL - Entry")); |
|
539 |
|
540 if (iStorageId == KMTPStorageDefault) |
|
541 { |
|
542 iStorageId = iFramework.StorageMgr().DefaultStorageId(); |
|
543 } |
|
544 TInt drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); |
|
545 User::LeaveIfError(drive); |
|
546 |
|
547 delete iParentSuid; |
|
548 iParentSuid = NULL; |
|
549 iParentSuid = (iFramework.StorageMgr().StorageL(iStorageId).DesC(CMTPStorageMetaData::EStorageSuid)).AllocL(); |
|
550 iReceivedObject->SetUint(CMTPObjectMetaData::EParentHandle, KMTPHandleNoParent); |
|
551 |
|
552 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetDefaultParentObjectL - Exit")); |
|
553 } |
|
554 |
|
555 /** |
|
556 Get parent object and storage id |
|
557 @return EMTPRespCodeOK if successful, otherwise, EMTPRespCodeInvalidParentObject |
|
558 */ |
|
559 TMTPResponseCode CMTPImageDpSendObjectInfo::GetParentObjectAndStorageIdL() |
|
560 { |
|
561 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetParentObjectAndStorageIdL - Entry")); |
|
562 __ASSERT_DEBUG(iRequestChecker, Panic(EMTPImageDpRequestCheckNull)); |
|
563 |
|
564 iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
565 iParentHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
566 //does not take ownership |
|
567 CMTPObjectMetaData* parentObjectInfo = iRequestChecker->GetObjectInfo(iParentHandle); |
|
568 |
|
569 if (!parentObjectInfo) |
|
570 { |
|
571 GetDefaultParentObjectL(); |
|
572 } |
|
573 else |
|
574 { |
|
575 delete iParentSuid; |
|
576 iParentSuid = NULL; |
|
577 iParentSuid = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL(); |
|
578 iReceivedObject->SetUint(CMTPObjectMetaData::EParentHandle, iParentHandle); |
|
579 } |
|
580 |
|
581 __FLOG_VA((_L8("ParentSuid = %S"), iParentSuid)); |
|
582 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetParentObjectAndStorageIdL - Exit")); |
|
583 return EMTPRespCodeOK; |
|
584 } |
|
585 |
|
586 /** |
|
587 Handling the completing phase of SendObjectInfo request |
|
588 @return ETrue if the specified object can be saved on the specified location, otherwise, EFalse |
|
589 */ |
|
590 TBool CMTPImageDpSendObjectInfo::DoHandleSendObjectInfoCompleteL(TAny* /*aPtr*/) |
|
591 { |
|
592 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectInfoCompleteL - Entry")); |
|
593 |
|
594 TBool result(ETrue); |
|
595 TUint16 format(iObjectInfo->Uint16L(CMTPTypeObjectInfo::EObjectFormat)); |
|
596 |
|
597 result = IsFormatValid(TMTPFormatCode(format)); |
|
598 |
|
599 if (result) |
|
600 { |
|
601 delete iDateMod; |
|
602 iDateMod = NULL; |
|
603 iDateMod = iObjectInfo->StringCharsL(CMTPTypeObjectInfo::EDateModified).AllocL(); |
|
604 delete iDateCreated; |
|
605 iDateCreated = NULL; |
|
606 iDateCreated = iObjectInfo->StringCharsL(CMTPTypeObjectInfo::EDateCreated).AllocL(); |
|
607 |
|
608 TMTPResponseCode responseCode(GetParentObjectAndStorageIdL()); |
|
609 if (responseCode != EMTPRespCodeOK) |
|
610 { |
|
611 SendResponseL(responseCode); |
|
612 result = EFalse; |
|
613 } |
|
614 } |
|
615 else |
|
616 { |
|
617 SendResponseL(EMTPRespCodeInvalidObjectFormatCode); |
|
618 } |
|
619 |
|
620 if (result) |
|
621 { |
|
622 iObjectSize = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EObjectCompressedSize); |
|
623 if(!CanStoreFileL(iStorageId, iObjectSize)) |
|
624 { |
|
625 SendResponseL(EMTPRespCodeStoreFull); |
|
626 result = EFalse; |
|
627 } |
|
628 } |
|
629 |
|
630 if (result) |
|
631 { |
|
632 iProtectionStatus = iObjectInfo->Uint16L(CMTPTypeObjectInfo::EProtectionStatus); |
|
633 if (iProtectionStatus != EMTPProtectionNoProtection && |
|
634 iProtectionStatus != EMTPProtectionReadOnly) |
|
635 { |
|
636 SendResponseL(EMTPRespCodeParameterNotSupported); |
|
637 result = EFalse; |
|
638 } |
|
639 } |
|
640 |
|
641 if (result) |
|
642 { |
|
643 result = GetFullPathName(iObjectInfo->StringCharsL(CMTPTypeObjectInfo::EFilename)); |
|
644 if (!result) |
|
645 { |
|
646 // File and/or parent pathname invalid. |
|
647 SendResponseL(EMTPRespCodeInvalidDataset); |
|
648 } |
|
649 } |
|
650 |
|
651 if (result) |
|
652 { |
|
653 result = !Exists(iFullPath); |
|
654 if (!result) |
|
655 { |
|
656 SendResponseL(EMTPRespCodeAccessDenied); |
|
657 } |
|
658 else |
|
659 { |
|
660 ReserveObjectL(); |
|
661 imageWidth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixWidth); |
|
662 imageHeight = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImagePixHeight); |
|
663 imageBitDepth = iObjectInfo->Uint32L(CMTPTypeObjectInfo::EImageBitDepth); |
|
664 iReceivedObject->SetUint(CMTPObjectMetaData::EFormatCode, format); |
|
665 SetPropertiesL(); |
|
666 ReturnResponseL(); |
|
667 } |
|
668 } |
|
669 |
|
670 iSuccessful = result; |
|
671 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectInfoCompleteL - Exit")); |
|
672 return result; |
|
673 } |
|
674 |
|
675 /** |
|
676 Handling the completing phase of SendObjectPropList request |
|
677 @return ETrue if the specified object can be saved on the specified location, otherwise, EFalse |
|
678 */ |
|
679 TBool CMTPImageDpSendObjectInfo::DoHandleSendObjectPropListCompleteL(TAny* /*aPtr*/) |
|
680 { |
|
681 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectPropListCompleteL - Entry")); |
|
682 TBool result(ETrue); |
|
683 |
|
684 TMTPResponseCode responseCode(GetParentObjectAndStorageIdL()); |
|
685 if (responseCode != EMTPRespCodeOK) |
|
686 { |
|
687 SendResponseL(responseCode); |
|
688 result = EFalse; |
|
689 } |
|
690 |
|
691 if (result) |
|
692 { |
|
693 // Any kind of association is treated as a folder |
|
694 const TUint32 formatCode(Request().Uint32(TMTPTypeRequest::ERequestParameter3)); |
|
695 |
|
696 TInt invalidParameterIndex = KErrNotFound; |
|
697 responseCode = VerifyObjectPropListL(invalidParameterIndex); |
|
698 result = (responseCode == EMTPRespCodeOK); |
|
699 if (!result) |
|
700 { |
|
701 TUint32 parameters[4]; |
|
702 parameters[0] = 0; |
|
703 parameters[1] = 0; |
|
704 parameters[2] = 0; |
|
705 parameters[3] = invalidParameterIndex; |
|
706 SendResponseL(responseCode, 4, parameters); |
|
707 } |
|
708 } |
|
709 |
|
710 if (result) |
|
711 { |
|
712 result = !Exists(iFullPath); |
|
713 if (!result) |
|
714 { |
|
715 // Object with the same name already exists. |
|
716 SendResponseL(EMTPRespCodeAccessDenied); |
|
717 } |
|
718 } |
|
719 |
|
720 if (result) |
|
721 { |
|
722 //the EFormatCode property has been set in ServiceSendObjectPropListL() function |
|
723 ReserveObjectL(); |
|
724 SetPropertiesL(); |
|
725 ReturnResponseL(); |
|
726 } |
|
727 |
|
728 iSuccessful = result; |
|
729 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectPropListCompleteL - Exit")); |
|
730 return result; |
|
731 } |
|
732 |
|
733 /** |
|
734 Handling the completing phase of SendObject request |
|
735 @return ETrue if the object has been successfully saved on the device, otherwise, EFalse |
|
736 */ |
|
737 TBool CMTPImageDpSendObjectInfo::DoHandleSendObjectCompleteL(TAny* /*aPtr*/) |
|
738 { |
|
739 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectCompleteL - Entry")); |
|
740 TBool result(ETrue); |
|
741 |
|
742 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
743 TInt64 objectsize = 0; |
|
744 #else |
|
745 TInt objectsize = 0; |
|
746 #endif |
|
747 |
|
748 iFileReceived->File().Size(objectsize); |
|
749 |
|
750 if (objectsize != iObjectSize) |
|
751 { |
|
752 __FLOG_VA((_L8("object sizes differ %lu != %lu"), objectsize, iObjectSize)); |
|
753 iFramework.RouteRequestUnregisterL(iExpectedSendObjectRequest, iConnection); |
|
754 Rollback(); |
|
755 |
|
756 TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge; |
|
757 if (objectsize < iObjectSize) |
|
758 { |
|
759 responseCode = EMTPRespCodeInvalidDataset; |
|
760 } |
|
761 SendResponseL(responseCode); |
|
762 result = EFalse; |
|
763 } |
|
764 |
|
765 // SendObject is cancelled or connection is dropped. |
|
766 if(result && iCancelled) |
|
767 { |
|
768 __FLOG(_L8("It is a cancel for sendObject.")); |
|
769 iFramework.RouteRequestUnregisterL(iExpectedSendObjectRequest, iConnection); |
|
770 Rollback(); |
|
771 SendResponseL(EMTPRespCodeTransactionCancelled); |
|
772 } |
|
773 else if (result && !iCancelled) |
|
774 { |
|
775 if (iProtectionStatus == EMTPProtectionNoProtection || |
|
776 iProtectionStatus == EMTPProtectionReadOnly) |
|
777 { |
|
778 TUint attValue = 0; |
|
779 User::LeaveIfError(iFileReceived->File().Att(attValue)); |
|
780 attValue &= ~(KEntryAttNormal | KEntryAttReadOnly); |
|
781 |
|
782 if (iProtectionStatus == EMTPProtectionNoProtection) |
|
783 { |
|
784 attValue |= KEntryAttNormal; |
|
785 } |
|
786 else |
|
787 { |
|
788 attValue |= KEntryAttReadOnly; |
|
789 } |
|
790 User::LeaveIfError(iFileReceived->File().SetAtt(attValue, ~attValue)); |
|
791 } |
|
792 |
|
793 //update datemodified property. |
|
794 if(iDateMod != NULL && iDateMod->Length()) |
|
795 { |
|
796 TTime modifiedTime; |
|
797 iObjectPropertyMgr.ConvertMTPTimeStr2TTimeL(*iDateMod, modifiedTime); |
|
798 User::LeaveIfError(iFileReceived->File().SetModified(modifiedTime)); |
|
799 } |
|
800 |
|
801 iFramework.RouteRequestUnregisterL(iExpectedSendObjectRequest, iConnection); |
|
802 |
|
803 //The MTP spec states that it is not mandatory for SendObjectInfo/SendObjectPropList |
|
804 //to be followed by a SendObject. An object is reserved in the ObjectStore on |
|
805 //receiving a SendObjectInfo/SendObjectPropList request, but we only commit it |
|
806 //on receiving the corresponding SendObject request. With Associations however |
|
807 //we commit the object straight away as the SendObject phase is often absent |
|
808 //with folder creation. |
|
809 |
|
810 CleanUndoList(); |
|
811 SendResponseL(EMTPRespCodeOK); |
|
812 } |
|
813 |
|
814 delete iFileReceived; |
|
815 iFileReceived = NULL; |
|
816 |
|
817 iSuccessful = result; |
|
818 __FLOG(_L8("CMTPImageDpSendObjectInfo::DoHandleSendObjectCompleteL - Exit")); |
|
819 return result; |
|
820 } |
|
821 |
|
822 void CMTPImageDpSendObjectInfo::UnreserveObject(CMTPImageDpSendObjectInfo* aObject) |
|
823 { |
|
824 aObject->UnreserveObject(); |
|
825 } |
|
826 |
|
827 void CMTPImageDpSendObjectInfo::RemoveObjectFromFs(CMTPImageDpSendObjectInfo* aObject) |
|
828 { |
|
829 aObject->RemoveObjectFromFs(); |
|
830 } |
|
831 |
|
832 void CMTPImageDpSendObjectInfo::RemoveObjectFromDb(CMTPImageDpSendObjectInfo* aObject) |
|
833 { |
|
834 aObject->RemoveObjectFromDb(); |
|
835 } |
|
836 |
|
837 void CMTPImageDpSendObjectInfo::UnreserveObject() |
|
838 { |
|
839 __ASSERT_DEBUG(iReceivedObject, Panic(EMTPImageDpObjectNull)); |
|
840 TRAP_IGNORE(iFramework.ObjectMgr().UnreserveObjectHandleL(*iReceivedObject)); |
|
841 } |
|
842 |
|
843 void CMTPImageDpSendObjectInfo::RemoveObjectFromFs() |
|
844 { |
|
845 delete iFileReceived; |
|
846 iFileReceived = NULL; |
|
847 TInt err = iFramework.Fs().Delete(iFullPath); |
|
848 if (err != KErrNone) |
|
849 { |
|
850 //add Suid to deleteobjectlist |
|
851 iDataProvider.AppendDeleteObjectsArrayL(iFullPath); |
|
852 } |
|
853 } |
|
854 |
|
855 void CMTPImageDpSendObjectInfo::RemoveObjectFromDb() |
|
856 { |
|
857 /** |
|
858 * remove all cached properties if rollback occured. |
|
859 */ |
|
860 TRAP_IGNORE( |
|
861 iFramework.ObjectMgr().RemoveObjectL(iReceivedObject->Uint(CMTPObjectMetaData::EHandle)); |
|
862 iObjectPropertyMgr.ClearCacheL(); |
|
863 ); |
|
864 } |
|
865 |
|
866 void CMTPImageDpSendObjectInfo::ReturnResponseL() |
|
867 { |
|
868 iExpectedSendObjectRequest.SetUint32(TMTPTypeRequest::ERequestSessionID, iSessionId); |
|
869 iFramework.RouteRequestRegisterL(iExpectedSendObjectRequest, iConnection); |
|
870 |
|
871 TUint32 parameters[3]; |
|
872 parameters[0] = iStorageId; |
|
873 parameters[1] = iParentHandle; |
|
874 parameters[2] = iReceivedObject->Uint(CMTPObjectMetaData::EHandle); |
|
875 SendResponseL(EMTPRespCodeOK, (sizeof(parameters) / sizeof(parameters[0])), parameters); |
|
876 } |
|
877 |
|
878 /** |
|
879 */ |
|
880 TBool CMTPImageDpSendObjectInfo::IsFormatValid(TMTPFormatCode aFormat) const |
|
881 { |
|
882 __FLOG_1(_L8("CMTPImageDpSendObjectInfo::IsFormatValid - Format: 0x%04x"), aFormat); |
|
883 TInt count(sizeof(KMTPValidCodeExtensionMappings) / sizeof(KMTPValidCodeExtensionMappings[0])); |
|
884 for(TInt i=0; i < count; i++) |
|
885 { |
|
886 if (KMTPValidCodeExtensionMappings[i].iFormatCode == aFormat) |
|
887 { |
|
888 return ETrue; |
|
889 } |
|
890 } |
|
891 __FLOG(_L8("CMTPImageDpSendObjectInfo::IsFormatValid - Exit")); |
|
892 return EFalse; |
|
893 } |
|
894 |
|
895 /** |
|
896 Get the full path name of the object to be saved |
|
897 @param aFileName, on entry, contains the file name of the object, |
|
898 on return, contains the full path name of the object to be saved |
|
899 @return ETrue if the name is valid, EFalse otherwise |
|
900 */ |
|
901 TBool CMTPImageDpSendObjectInfo::GetFullPathName(const TDesC& aFileName) |
|
902 { |
|
903 __FLOG_1(_L8("CMTPImageDpSendObjectInfo::GetFullPathNameL - FileName: %S"), &aFileName); |
|
904 TBool result(EFalse); |
|
905 if (aFileName.Length() > 0) |
|
906 { |
|
907 iFullPath = *iParentSuid; |
|
908 if (iFullPath.Length() + aFileName.Length() < iFullPath.MaxLength()) |
|
909 { |
|
910 iFullPath.Append(aFileName); |
|
911 result = iFramework.Fs().IsValidName(iFullPath); |
|
912 } |
|
913 __FLOG_1(_L16("FullPath: %S"), &iFullPath); |
|
914 } |
|
915 |
|
916 __FLOG(_L8("CMTPImageDpSendObjectInfo::GetFullPathNameL - Exit")); |
|
917 return result; |
|
918 } |
|
919 |
|
920 /** |
|
921 Check if we can store the file on the storage |
|
922 @return ETrue if yes, otherwise EFalse |
|
923 */ |
|
924 TBool CMTPImageDpSendObjectInfo::CanStoreFileL(TUint32 aStorageId, TInt64 aObjectSize) const |
|
925 { |
|
926 __FLOG(_L8("CMTPImageDpSendObjectInfo::CanStoreFileL - Entry")); |
|
927 TBool result(ETrue); |
|
928 if (aStorageId == KMTPStorageDefault) |
|
929 { |
|
930 aStorageId = iFramework.StorageMgr().DefaultStorageId(); |
|
931 } |
|
932 |
|
933 TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(aStorageId))); |
|
934 User::LeaveIfError(drive); |
|
935 TVolumeInfo volumeInfo; |
|
936 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
|
937 if (volumeInfo.iFree < aObjectSize) |
|
938 { |
|
939 result = EFalse; |
|
940 } |
|
941 __FLOG(_L8("CMTPImageDpSendObjectInfo::CanStoreFileL - Exit")); |
|
942 return result; |
|
943 } |
|
944 |
|
945 /** |
|
946 Check if the file already exists on the storage. |
|
947 @return ETrue if file is exists, otherwise EFalse |
|
948 */ |
|
949 TBool CMTPImageDpSendObjectInfo::Exists(const TDesC& aName) const |
|
950 { |
|
951 __FLOG(_L8("CMTPImageDpSendObjectInfo::Exists - Entry")); |
|
952 // This detects both files and folders |
|
953 TBool ret(EFalse); |
|
954 ret = BaflUtils::FileExists(iFramework.Fs(), aName); |
|
955 __FLOG_VA((_L16("Exists: %S (%d)"), &aName, ret)); |
|
956 __FLOG(_L8("CMTPImageDpSendObjectInfo::IsTooLarge - Exit")); |
|
957 return ret; |
|
958 } |
|
959 |
|
960 /** |
|
961 Check if the property list is valid and extract properties (file name) |
|
962 @param aInvalidParameterIndex if invalid, contains the index of the property. Undefined, if it is valid. |
|
963 @return if error, one of the error response code; otherwise EMTPRespCodeOK |
|
964 */ |
|
965 TMTPResponseCode CMTPImageDpSendObjectInfo::VerifyObjectPropListL(TInt& aInvalidParameterIndex) |
|
966 { |
|
967 __FLOG(_L8("CMTPImageDpSendObjectInfo::VerifyObjectPropListL - Entry")); |
|
968 |
|
969 TMTPResponseCode responseCode(EMTPRespCodeOK); |
|
970 const TUint KCount(iObjectPropList->NumberOfElements()); |
|
971 iObjectPropList->ResetCursor(); |
|
972 for (TUint i(0); (i < KCount); i++) |
|
973 { |
|
974 CMTPTypeObjectPropListElement& KElement=iObjectPropList->GetNextElementL(); |
|
975 const TUint32 KHandle(KElement.Uint32L(CMTPTypeObjectPropListElement::EObjectHandle)); |
|
976 aInvalidParameterIndex = i; |
|
977 if (KHandle != KMTPHandleNone) |
|
978 { |
|
979 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
980 break; |
|
981 } |
|
982 |
|
983 responseCode = CheckPropCodeL(KElement); |
|
984 if (responseCode != EMTPRespCodeOK) |
|
985 { |
|
986 break; |
|
987 } |
|
988 responseCode = ExtractPropertyL(KElement); |
|
989 if (responseCode != EMTPRespCodeOK) |
|
990 { |
|
991 break; |
|
992 } |
|
993 } |
|
994 __FLOG_VA((_L8("Result = 0x%04X"), responseCode)); |
|
995 __FLOG(_L8("CMTPImageDpSendObjectInfo::VerifyObjectPropListL - Exit")); |
|
996 return responseCode; |
|
997 } |
|
998 |
|
999 /** |
|
1000 Extracts the file information from the object property list element |
|
1001 @param aElement an object property list element |
|
1002 @param aPropertyCode MTP property code for the element |
|
1003 @return MTP response code |
|
1004 */ |
|
1005 TMTPResponseCode CMTPImageDpSendObjectInfo::ExtractPropertyL(const CMTPTypeObjectPropListElement& aElement) |
|
1006 { |
|
1007 __FLOG(_L8("CMTPImageDpSendObjectInfo::ExtractPropertyL - Entry")); |
|
1008 TMTPResponseCode responseCode(EMTPRespCodeOK); |
|
1009 switch (aElement.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode)) |
|
1010 { |
|
1011 case EMTPObjectPropCodeObjectFileName: |
|
1012 { |
|
1013 const TDesC& KFileName = aElement.StringL(CMTPTypeObjectPropListElement::EValue); |
|
1014 if (!GetFullPathName(KFileName)) |
|
1015 { |
|
1016 responseCode = EMTPRespCodeInvalidDataset; |
|
1017 } |
|
1018 } |
|
1019 break; |
|
1020 |
|
1021 case EMTPObjectPropCodeProtectionStatus: |
|
1022 { |
|
1023 iProtectionStatus = aElement.Uint16L(CMTPTypeObjectPropListElement::EValue); |
|
1024 if (iProtectionStatus != EMTPProtectionNoProtection && |
|
1025 iProtectionStatus != EMTPProtectionReadOnly) |
|
1026 { |
|
1027 responseCode = EMTPRespCodeParameterNotSupported; |
|
1028 } |
|
1029 } |
|
1030 break; |
|
1031 |
|
1032 case EMTPObjectPropCodeDateModified: |
|
1033 delete iDateMod; |
|
1034 iDateMod = NULL; |
|
1035 iDateMod = aElement.StringL(CMTPTypeObjectPropListElement::EValue).AllocL(); |
|
1036 break; |
|
1037 |
|
1038 case EMTPObjectPropCodeDateCreated: |
|
1039 delete iDateCreated; |
|
1040 iDateCreated = NULL; |
|
1041 iDateCreated = aElement.StringL(CMTPTypeObjectPropListElement::EValue).AllocL(); |
|
1042 break; |
|
1043 |
|
1044 case EMTPObjectPropCodeName: |
|
1045 iName = aElement.StringL(CMTPTypeObjectPropListElement::EValue); |
|
1046 break; |
|
1047 |
|
1048 case EMTPObjectPropCodeObjectFormat: |
|
1049 iFormatCode = aElement.Uint16L(CMTPTypeObjectPropListElement::EValue); |
|
1050 if (iFormatCode != EMTPFormatCodeEXIFJPEG) |
|
1051 { |
|
1052 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1053 } |
|
1054 break; |
|
1055 |
|
1056 case EMTPObjectPropCodeWidth: |
|
1057 imageWidth = aElement.Uint32L(CMTPTypeObjectPropListElement::EValue); |
|
1058 break; |
|
1059 |
|
1060 case EMTPObjectPropCodeHeight: |
|
1061 imageHeight = aElement.Uint32L(CMTPTypeObjectPropListElement::EValue); |
|
1062 break; |
|
1063 |
|
1064 case EMTPObjectPropCodeImageBitDepth: |
|
1065 imageBitDepth = aElement.Uint32L(CMTPTypeObjectPropListElement::EValue); |
|
1066 break; |
|
1067 |
|
1068 case EMTPObjectPropCodeNonConsumable: |
|
1069 iNonConsumable = aElement.Uint8L(CMTPTypeObjectPropListElement::EValue); |
|
1070 break; |
|
1071 |
|
1072 default: |
|
1073 break; |
|
1074 } |
|
1075 __FLOG_VA((_L8("Result = 0x%04X"), responseCode)); |
|
1076 __FLOG(_L8("CMTPImageDpSendObjectInfo::ExtractPropertyL - Exit")); |
|
1077 return responseCode; |
|
1078 } |
|
1079 |
|
1080 /** |
|
1081 Validates the data type for a given property code. |
|
1082 @param aElement an object property list element |
|
1083 @param aPropertyCode MTP property code for the element |
|
1084 @return EMTPRespCodeOK if the combination is valid, or another MTP response code if not |
|
1085 */ |
|
1086 TMTPResponseCode CMTPImageDpSendObjectInfo::CheckPropCodeL(const CMTPTypeObjectPropListElement& aElement) const |
|
1087 { |
|
1088 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckPropCode - Entry")); |
|
1089 TMTPResponseCode responseCode(EMTPRespCodeOK); |
|
1090 switch(aElement.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode)) |
|
1091 { |
|
1092 case EMTPObjectPropCodeStorageID: |
|
1093 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT32) |
|
1094 { |
|
1095 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1096 } |
|
1097 else if (iStorageId != aElement.Uint32L(CMTPTypeObjectPropListElement::EValue)) |
|
1098 { |
|
1099 responseCode = EMTPRespCodeInvalidDataset; |
|
1100 } |
|
1101 break; |
|
1102 |
|
1103 case EMTPObjectPropCodeObjectFormat: |
|
1104 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT16) |
|
1105 { |
|
1106 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1107 } |
|
1108 else if (Request().Uint32(TMTPTypeRequest::ERequestParameter3) != aElement.Uint16L(CMTPTypeObjectPropListElement::EValue)) |
|
1109 { |
|
1110 responseCode = EMTPRespCodeInvalidDataset; |
|
1111 } |
|
1112 break; |
|
1113 |
|
1114 case EMTPObjectPropCodeObjectSize: |
|
1115 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT64) |
|
1116 { |
|
1117 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1118 } |
|
1119 else if (iObjectSize != aElement.Uint64L(CMTPTypeObjectPropListElement::EValue)) |
|
1120 { |
|
1121 responseCode = EMTPRespCodeInvalidDataset; |
|
1122 } |
|
1123 break; |
|
1124 |
|
1125 case EMTPObjectPropCodeParentObject: |
|
1126 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT32) |
|
1127 { |
|
1128 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1129 } |
|
1130 else if (Request().Uint32(TMTPTypeRequest::ERequestParameter2) != aElement.Uint32L(CMTPTypeObjectPropListElement::EValue)) |
|
1131 { |
|
1132 responseCode = EMTPRespCodeInvalidDataset; |
|
1133 } |
|
1134 break; |
|
1135 |
|
1136 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
1137 responseCode = EMTPRespCodeAccessDenied; |
|
1138 break; |
|
1139 |
|
1140 case EMTPObjectPropCodeRepresentativeSampleFormat: |
|
1141 case EMTPObjectPropCodeProtectionStatus: |
|
1142 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT16) |
|
1143 { |
|
1144 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1145 } |
|
1146 break; |
|
1147 |
|
1148 case EMTPObjectPropCodeDateCreated: |
|
1149 case EMTPObjectPropCodeDateModified: |
|
1150 case EMTPObjectPropCodeObjectFileName: |
|
1151 case EMTPObjectPropCodeName: |
|
1152 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeString) |
|
1153 { |
|
1154 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1155 } |
|
1156 break; |
|
1157 |
|
1158 case EMTPObjectPropCodeWidth: |
|
1159 case EMTPObjectPropCodeHeight: |
|
1160 case EMTPObjectPropCodeImageBitDepth: |
|
1161 case EMTPObjectPropCodeRepresentativeSampleSize: |
|
1162 case EMTPObjectPropCodeRepresentativeSampleHeight: |
|
1163 case EMTPObjectPropCodeRepresentativeSampleWidth: |
|
1164 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT32) |
|
1165 { |
|
1166 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1167 } |
|
1168 break; |
|
1169 case EMTPObjectPropCodeNonConsumable: |
|
1170 if (aElement.Uint16L(CMTPTypeObjectPropListElement::EDatatype) != EMTPTypeUINT8) |
|
1171 { |
|
1172 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
1173 } |
|
1174 break; |
|
1175 default: |
|
1176 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
1177 break; |
|
1178 } |
|
1179 __FLOG_VA((_L8("Result = 0x%04X"), responseCode)); |
|
1180 __FLOG(_L8("CMTPImageDpSendObjectInfo::CheckPropCode - Exit")); |
|
1181 return responseCode; |
|
1182 } |
|
1183 |
|
1184 /** |
|
1185 Reserves space for and assigns an object handle to the received object, then |
|
1186 sends a success response. |
|
1187 */ |
|
1188 void CMTPImageDpSendObjectInfo::ReserveObjectL() |
|
1189 { |
|
1190 __FLOG(_L8("CMTPImageDpSendObjectInfo::ReserveObjectL - Entry")); |
|
1191 |
|
1192 iReceivedObject->SetUint(CMTPObjectMetaData::EStorageId, iStorageId); |
|
1193 iFramework.ObjectMgr().ReserveObjectHandleL(*iReceivedObject, iObjectSize); |
|
1194 |
|
1195 // prepare for rollback |
|
1196 iRollbackList.Append(UnreserveObject); |
|
1197 __FLOG(_L8("CMTPImageDpSendObjectInfo::ReserveObjectL - Exit")); |
|
1198 } |
|
1199 |
|
1200 /** |
|
1201 Sets the read only status on the current file to match the sent object. |
|
1202 */ |
|
1203 void CMTPImageDpSendObjectInfo::SetPropertiesL() |
|
1204 { |
|
1205 __FLOG(_L8("CMTPImageDpSendObjectInfo::SetPropertiesL - Entry")); |
|
1206 |
|
1207 iObjectPropertyMgr.SetCurrentObjectL(*iReceivedObject, ETrue, ETrue); |
|
1208 iReceivedObject->SetDesCL(CMTPObjectMetaData::ESuid, iFullPath); |
|
1209 if (iName.Length() == 0) |
|
1210 { |
|
1211 TParsePtrC pathParser(iFullPath); |
|
1212 iName = pathParser.Name(); |
|
1213 } |
|
1214 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeName, iName); |
|
1215 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeProtectionStatus, iProtectionStatus); |
|
1216 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeWidth, imageWidth); |
|
1217 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeHeight, imageHeight); |
|
1218 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeImageBitDepth, imageBitDepth); |
|
1219 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeNonConsumable, iNonConsumable); |
|
1220 |
|
1221 if(iDateCreated != NULL && iDateCreated->Length()) |
|
1222 {//currently image dp can not support this property |
|
1223 iObjectPropertyMgr.SetPropertyL(EMTPObjectPropCodeDateCreated, *iDateCreated); |
|
1224 } |
|
1225 |
|
1226 __FLOG(_L8("CMTPImageDpSendObjectInfo::SetPropertiesL - Exit")); |
|
1227 } |
|
1228 |
|
1229 void CMTPImageDpSendObjectInfo::Rollback() |
|
1230 { |
|
1231 __FLOG(_L8("CMTPImageDpSendObjectInfo::Rollback - Entry")); |
|
1232 |
|
1233 TInt count = iRollbackList.Count(); |
|
1234 while(--count >= 0) |
|
1235 { |
|
1236 TRAP_IGNORE((*iRollbackList[count])(this)); |
|
1237 } |
|
1238 iRollbackList.Reset(); |
|
1239 |
|
1240 __FLOG(_L8("CMTPImageDpSendObjectInfo::Rollback - Exit")); |
|
1241 } |
|
1242 |
|
1243 void CMTPImageDpSendObjectInfo::CleanUndoList() |
|
1244 { |
|
1245 __FLOG(_L8("CMTPImageDpSendObjectInfo::CleanUndoList - Entry")); |
|
1246 |
|
1247 iRollbackList.Reset(); |
|
1248 |
|
1249 __FLOG(_L8("CMTPImageDpSendObjectInfo::CleanUndoList - Exit")); |
|
1250 } |