|
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 <bautils.h> |
|
22 #include <mtp/cmtpobjectmetadata.h> |
|
23 #include <mtp/cmtptypearray.h> |
|
24 #include <mtp/cmtptypeobjectproplist.h> |
|
25 #include <mtp/cmtptypestring.h> |
|
26 #include <mtp/mmtpdataproviderframework.h> |
|
27 #include <mtp/mmtpobjectmgr.h> |
|
28 #include <mtp/mtpdatatypeconstants.h> |
|
29 #include <mtp/tmtptyperequest.h> |
|
30 |
|
31 #include "mtpdpconst.h" |
|
32 #include "cmtpimagedpgetobjectproplist.h" |
|
33 #include "cmtpimagedpobjectpropertymgr.h" |
|
34 #include "mtpimagedpconst.h" |
|
35 #include "mtpimagedppanic.h" |
|
36 #include "cmtpimagedp.h" |
|
37 #include "mtpimagedputilits.h" |
|
38 |
|
39 __FLOG_STMT(_LIT8(KComponent,"ImageDpGetObjectPropList");) |
|
40 |
|
41 |
|
42 MMTPRequestProcessor* CMTPImageDpGetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, |
|
43 MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) |
|
44 { |
|
45 CMTPImageDpGetObjectPropList* self = new (ELeave) CMTPImageDpGetObjectPropList(aFramework, aConnection,aDataProvider); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 /* |
|
53 * Constructor |
|
54 */ |
|
55 CMTPImageDpGetObjectPropList::CMTPImageDpGetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) : |
|
56 CMTPRequestProcessor(aFramework, aConnection, 0,NULL), |
|
57 iPropertyMgr(aDataProvider.PropertyMgr()) |
|
58 { |
|
59 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
60 } |
|
61 |
|
62 /* |
|
63 * Constructor |
|
64 */ |
|
65 void CMTPImageDpGetObjectPropList::ConstructL() |
|
66 { |
|
67 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ConstructL")); |
|
68 |
|
69 iPropertyList = CMTPTypeObjectPropList::NewL(); |
|
70 iObjectMeta = CMTPObjectMetaData::NewL(); |
|
71 |
|
72 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ConstructL")); |
|
73 } |
|
74 |
|
75 /* |
|
76 * Destructor |
|
77 */ |
|
78 CMTPImageDpGetObjectPropList::~CMTPImageDpGetObjectPropList() |
|
79 { |
|
80 __FLOG(_L8("~CMTPImageDpGetObjectPropList")); |
|
81 Cancel(); |
|
82 |
|
83 iHandles.Close(); |
|
84 delete iPropertyList; |
|
85 delete iObjectMeta; |
|
86 __FLOG_CLOSE; |
|
87 } |
|
88 |
|
89 /* |
|
90 * |
|
91 */ |
|
92 void CMTPImageDpGetObjectPropList::ServiceL() |
|
93 { |
|
94 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ServiceL")); |
|
95 |
|
96 //get all the handles |
|
97 GetObjectHandlesL(); |
|
98 |
|
99 if ( iHandles.Count() > 0 ) |
|
100 { |
|
101 ServicePropertiesL( iHandles[0] ); |
|
102 iHandles.Remove( 0 ); |
|
103 } |
|
104 |
|
105 StartL(); |
|
106 |
|
107 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ServiceL")); |
|
108 } |
|
109 |
|
110 /* |
|
111 * Check object Handle, prop code and Depth, Group Code |
|
112 */ |
|
113 TMTPResponseCode CMTPImageDpGetObjectPropList::CheckRequestL() |
|
114 { |
|
115 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::CheckRequestL")); |
|
116 |
|
117 TMTPResponseCode result = EMTPRespCodeOK; |
|
118 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
119 |
|
120 //getobjectproplist support KMTPHandleAll and KMTPHandleNone |
|
121 if ( handle != KMTPHandleAll && handle != KMTPHandleNone ) |
|
122 { |
|
123 CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC()); |
|
124 result = MTPImageDpUtilits::VerifyObjectHandleL( iFramework, handle, *object ); |
|
125 CleanupStack::PopAndDestroy(object); |
|
126 } |
|
127 if (EMTPRespCodeOK == result) |
|
128 { |
|
129 result = CheckPropCode(); |
|
130 } |
|
131 |
|
132 if (EMTPRespCodeOK == result) |
|
133 { |
|
134 result = CheckDepth(); |
|
135 } |
|
136 |
|
137 __FLOG_VA((_L8("<< CMTPImageDpGetObjectPropList::CheckRequestL result: %d"), result)); |
|
138 return result; |
|
139 } |
|
140 |
|
141 TMTPResponseCode CMTPImageDpGetObjectPropList::CheckPropCode() const |
|
142 { |
|
143 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::CheckPropCode")); |
|
144 |
|
145 TMTPResponseCode response = EMTPRespCodeOK; |
|
146 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter3); |
|
147 if (propCode == 0) |
|
148 { |
|
149 TUint32 groupCode = Request().Uint32(TMTPTypeRequest::ERequestParameter4); |
|
150 if(groupCode != KMTPImageDpPropertyGroupOneNumber) |
|
151 { |
|
152 //Only supported group one |
|
153 response = EMTPRespCodeSpecificationByGroupUnsupported; |
|
154 } |
|
155 } |
|
156 else if (propCode != KMaxTUint) |
|
157 { |
|
158 const TInt count = sizeof(KMTPImageDpSupportedProperties)/sizeof(KMTPImageDpSupportedProperties[0]); |
|
159 TInt i(0); |
|
160 for (i = 0; i < count; i++) |
|
161 { |
|
162 if (KMTPImageDpSupportedProperties[i] == propCode) |
|
163 { |
|
164 break; |
|
165 } |
|
166 } |
|
167 if (i == count) |
|
168 { |
|
169 response = EMTPRespCodeInvalidObjectPropCode; |
|
170 } |
|
171 } |
|
172 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::CheckPropCode")); |
|
173 return response; |
|
174 } |
|
175 |
|
176 TMTPResponseCode CMTPImageDpGetObjectPropList::CheckDepth() const |
|
177 { |
|
178 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::CheckDepth")); |
|
179 |
|
180 TMTPResponseCode response = EMTPRespCodeSpecificationByDepthUnsupported; |
|
181 |
|
182 // We either support no depth at all, or 1 depth or (0xFFFFFFFF) with objecthandle as 0x00000000 |
|
183 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
184 TUint32 depth = Request().Uint32(TMTPTypeRequest::ERequestParameter5); |
|
185 if ( (depth == 0) || (depth == 1 ) || |
|
186 (depth == KMaxTUint && handle == KMTPHandleNone ) ) |
|
187 { |
|
188 response = EMTPRespCodeOK; |
|
189 } |
|
190 |
|
191 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::CheckDepth")); |
|
192 return response; |
|
193 } |
|
194 |
|
195 void CMTPImageDpGetObjectPropList::GetObjectHandlesL() |
|
196 { |
|
197 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::GetObjectHandlesL")); |
|
198 |
|
199 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
200 TUint32 formatCode(Request().Uint32(TMTPTypeRequest::ERequestParameter2)); |
|
201 TUint32 depth(Request().Uint32(TMTPTypeRequest::ERequestParameter5)); |
|
202 |
|
203 iHandles.Reset(); |
|
204 |
|
205 if (handle == KMTPHandleAll) |
|
206 { |
|
207 GetObjectHandlesL(KMTPStorageAll, formatCode, KMTPHandleNone); |
|
208 } |
|
209 else if (handle == KMTPHandleNone) |
|
210 { |
|
211 GetRootObjectHandlesL(formatCode, depth); |
|
212 } |
|
213 else |
|
214 { |
|
215 iHandles.Append( handle ); |
|
216 } |
|
217 |
|
218 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::GetObjectHandlesL")); |
|
219 } |
|
220 |
|
221 void CMTPImageDpGetObjectPropList::GetObjectHandlesL(TUint32 aStorageId, TUint32 aFormatCode, TUint32 aParentHandle) |
|
222 { |
|
223 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::GetObjectHandlesL")); |
|
224 |
|
225 RMTPObjectMgrQueryContext context; |
|
226 RArray<TUint> handles; |
|
227 TMTPObjectMgrQueryParams params(aStorageId, aFormatCode, aParentHandle, iFramework.DataProviderId()); |
|
228 CleanupClosePushL(context); |
|
229 CleanupClosePushL(handles); |
|
230 |
|
231 iHandles.Reset(); |
|
232 |
|
233 do |
|
234 { |
|
235 iFramework.ObjectMgr().GetObjectHandlesL(params, context, handles); |
|
236 for ( TInt i = 0; i < handles.Count(); i++ ) |
|
237 { |
|
238 iHandles.AppendL(handles[i]); |
|
239 } |
|
240 } |
|
241 while(!context.QueryComplete()); |
|
242 |
|
243 CleanupStack::PopAndDestroy(&handles); |
|
244 CleanupStack::PopAndDestroy(&context); |
|
245 |
|
246 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::GetObjectHandlesL")); |
|
247 } |
|
248 |
|
249 void CMTPImageDpGetObjectPropList::GetRootObjectHandlesL(TUint32 aFormatCode, TUint32 aDepth) |
|
250 { |
|
251 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::GetRootObjectHandlesL")); |
|
252 |
|
253 if (aDepth == KMaxTUint) |
|
254 { |
|
255 GetObjectHandlesL(KMTPStorageAll, aFormatCode, KMTPHandleNone); |
|
256 } |
|
257 else if (aDepth == 0) |
|
258 { |
|
259 __FLOG(_L8("depth is 0, iHandles is an empty array")); |
|
260 iHandles.Reset(); |
|
261 } |
|
262 else |
|
263 { |
|
264 GetObjectHandlesL(KMTPStorageAll, aFormatCode, KMTPHandleNoParent); |
|
265 } |
|
266 |
|
267 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::GetRootObjectHandlesL")); |
|
268 } |
|
269 |
|
270 void CMTPImageDpGetObjectPropList::ServicePropertiesL( TUint32 aHandle ) |
|
271 { |
|
272 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ServicePropertiesL")); |
|
273 |
|
274 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter3); |
|
275 TUint32 groupCode = Request().Uint32(TMTPTypeRequest::ERequestParameter4); |
|
276 |
|
277 iFramework.ObjectMgr().ObjectL(aHandle, *iObjectMeta); |
|
278 iPropertyMgr.SetCurrentObjectL(*iObjectMeta, EFalse); |
|
279 |
|
280 if (propCode == KMaxTUint) |
|
281 { |
|
282 ServiceAllPropertiesL(aHandle); |
|
283 } |
|
284 else if( propCode == 0) |
|
285 { |
|
286 ServiceGroupPropertiesL(aHandle, groupCode); |
|
287 } |
|
288 else |
|
289 { |
|
290 ServiceOneObjectPropertyL(aHandle, propCode); |
|
291 } |
|
292 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ServicePropertiesL")); |
|
293 } |
|
294 |
|
295 void CMTPImageDpGetObjectPropList::ServiceAllPropertiesL(TUint32 aHandle) |
|
296 { |
|
297 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ServiceAllPropertiesL")); |
|
298 |
|
299 if (iFramework.ObjectMgr().ObjectOwnerId(aHandle) == iFramework.DataProviderId()) |
|
300 { |
|
301 for (TUint i(0); (i < (sizeof(KMTPImageDpSupportedProperties) / sizeof(TUint16))); i++) |
|
302 { |
|
303 ServiceOneObjectPropertyL(aHandle, KMTPImageDpSupportedProperties[i]); |
|
304 } |
|
305 } |
|
306 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ServiceAllPropertiesL")); |
|
307 } |
|
308 |
|
309 void CMTPImageDpGetObjectPropList::ServiceGroupPropertiesL(TUint32 aHandle,TUint16 /*aGroupCode*/) |
|
310 { |
|
311 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ServiceGroupPropertiesL")); |
|
312 |
|
313 if (iFramework.ObjectMgr().ObjectOwnerId(aHandle) == iFramework.DataProviderId()) |
|
314 { |
|
315 for (TUint propCodeIndex(0); propCodeIndex < KMTPImageDpGroupOneSize; propCodeIndex++) |
|
316 { |
|
317 TUint16 propCode = KMTPImageDpGroupOneProperties[propCodeIndex]; |
|
318 if(propCode != 0) |
|
319 { |
|
320 ServiceOneObjectPropertyL(aHandle, propCode); |
|
321 } |
|
322 } |
|
323 } |
|
324 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ServiceGroupPropertiesL")); |
|
325 } |
|
326 |
|
327 void CMTPImageDpGetObjectPropList::ServiceOneObjectPropertyL(TUint32 aHandle, TUint32 aPropCode) |
|
328 { |
|
329 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::ServiceOneObjectPropertyL")); |
|
330 |
|
331 if (iFramework.ObjectMgr().ObjectOwnerId(aHandle) == iFramework.DataProviderId()) |
|
332 { |
|
333 TUint16 propCode(static_cast<TUint16>(aPropCode)); |
|
334 switch(aPropCode) |
|
335 { |
|
336 case EMTPObjectPropCodeObjectFormat: |
|
337 case EMTPObjectPropCodeRepresentativeSampleFormat: |
|
338 case EMTPObjectPropCodeProtectionStatus: |
|
339 { |
|
340 TUint16 value; |
|
341 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
342 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
343 propElem.SetUint16L(CMTPTypeObjectPropListElement::EValue, value); |
|
344 iPropertyList->CommitPropElemL(propElem); |
|
345 } |
|
346 break; |
|
347 case EMTPObjectPropCodeParentObject: |
|
348 { |
|
349 TUint32 value; |
|
350 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
351 if (value == KMTPHandleNoParent) |
|
352 { |
|
353 value = 0; |
|
354 } |
|
355 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
356 propElem.SetUint32L(CMTPTypeObjectPropListElement::EValue, value); |
|
357 iPropertyList->CommitPropElemL(propElem); |
|
358 } |
|
359 break; |
|
360 case EMTPObjectPropCodeStorageID: |
|
361 case EMTPObjectPropCodeWidth: |
|
362 case EMTPObjectPropCodeHeight: |
|
363 case EMTPObjectPropCodeImageBitDepth: |
|
364 case EMTPObjectPropCodeRepresentativeSampleSize: |
|
365 case EMTPObjectPropCodeRepresentativeSampleHeight: |
|
366 case EMTPObjectPropCodeRepresentativeSampleWidth: |
|
367 { |
|
368 TUint32 value; |
|
369 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
370 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
371 propElem.SetUint32L(CMTPTypeObjectPropListElement::EValue, value); |
|
372 iPropertyList->CommitPropElemL(propElem); |
|
373 } |
|
374 break; |
|
375 |
|
376 case EMTPObjectPropCodeObjectSize: |
|
377 { |
|
378 TUint64 value; |
|
379 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
380 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
381 propElem.SetUint64L(CMTPTypeObjectPropListElement::EValue, value); |
|
382 iPropertyList->CommitPropElemL(propElem); |
|
383 } |
|
384 break; |
|
385 |
|
386 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
387 { |
|
388 TMTPTypeUint128 value; |
|
389 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
390 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
391 propElem.SetUint128L(CMTPTypeObjectPropListElement::EValue, value.UpperValue(), value.LowerValue()); |
|
392 iPropertyList->CommitPropElemL(propElem); |
|
393 } |
|
394 break; |
|
395 |
|
396 case EMTPObjectPropCodeDateCreated: |
|
397 case EMTPObjectPropCodeDateModified: |
|
398 case EMTPObjectPropCodeObjectFileName: |
|
399 case EMTPObjectPropCodeName: |
|
400 { |
|
401 CMTPTypeString* value = CMTPTypeString::NewLC(); |
|
402 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), *value); |
|
403 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, propCode); |
|
404 propElem.SetStringL(CMTPTypeObjectPropListElement::EValue, value->StringChars()); |
|
405 iPropertyList->CommitPropElemL(propElem); |
|
406 CleanupStack::PopAndDestroy(value); |
|
407 } |
|
408 break; |
|
409 case EMTPObjectPropCodeNonConsumable: |
|
410 { |
|
411 |
|
412 TUint8 value; |
|
413 iPropertyMgr.GetPropertyL(TMTPObjectPropertyCode(aPropCode), value); |
|
414 CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode); |
|
415 propElem.SetUint8L(CMTPTypeObjectPropListElement::EValue, value); |
|
416 iPropertyList->CommitPropElemL(propElem); |
|
417 } |
|
418 break; |
|
419 default: |
|
420 //Leave |
|
421 { |
|
422 User::Leave(KErrGeneral); |
|
423 } |
|
424 break; |
|
425 } |
|
426 } |
|
427 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::ServiceOneObjectPropertyL")); |
|
428 } |
|
429 |
|
430 void CMTPImageDpGetObjectPropList::DoCancel() |
|
431 { |
|
432 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::DoCancel")); |
|
433 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::DoCancel")); |
|
434 } |
|
435 |
|
436 void CMTPImageDpGetObjectPropList::RunL() |
|
437 { |
|
438 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::RunL")); |
|
439 |
|
440 if ( iHandles.Count() > 0 ) |
|
441 { |
|
442 ServicePropertiesL( iHandles[0] ); |
|
443 iHandles.Remove( 0 ); |
|
444 } |
|
445 StartL(); |
|
446 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::RunL")); |
|
447 } |
|
448 |
|
449 TInt CMTPImageDpGetObjectPropList::RunError( TInt aError ) |
|
450 { |
|
451 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::RunError")); |
|
452 |
|
453 TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) ); |
|
454 |
|
455 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::RunError")); |
|
456 return aError; |
|
457 } |
|
458 |
|
459 void CMTPImageDpGetObjectPropList::StartL() |
|
460 { |
|
461 __FLOG(_L8(">> CMTPImageDpGetObjectPropList::StartL")); |
|
462 |
|
463 if ( iHandles.Count() > 0 ) |
|
464 { |
|
465 TRequestStatus* status = &iStatus; |
|
466 User::RequestComplete( status, iStatus.Int() ); |
|
467 SetActive(); |
|
468 } |
|
469 else |
|
470 { |
|
471 SendDataL(*iPropertyList); |
|
472 } |
|
473 |
|
474 __FLOG(_L8("<< CMTPImageDpGetObjectPropList::StartL")); |
|
475 } |