|
1 // Copyright (c) 2008-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 // mw/remoteconn/mtpfws/mtpfw/dataproviders/dputility/src/cmtpsvcgetobjectproplist.cpp |
|
15 |
|
16 #include <mtp/cmtpobjectmetadata.h> |
|
17 #include <mtp/cmtptypeobjectproplist.h> |
|
18 #include <mtp/mmtpdataproviderframework.h> |
|
19 #include <mtp/mmtpobjectmgr.h> |
|
20 #include <mtp/mtpdatatypeconstants.h> |
|
21 |
|
22 #include "cmtpsvcgetobjectproplist.h" |
|
23 #include "mtpsvcdpconst.h" |
|
24 #include "mmtpservicedataprovider.h" |
|
25 #include "mmtpsvcobjecthandler.h" |
|
26 |
|
27 // Class constants. |
|
28 __FLOG_STMT(_LIT8(KComponent,"SvcGetObjPL");) |
|
29 |
|
30 EXPORT_C MMTPRequestProcessor* CMTPSvcGetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) |
|
31 { |
|
32 CMTPSvcGetObjectPropList* self = new (ELeave) CMTPSvcGetObjectPropList(aFramework, aConnection, aDataProvider); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 EXPORT_C CMTPSvcGetObjectPropList::~CMTPSvcGetObjectPropList() |
|
40 { |
|
41 __FLOG(_L8("~CMTPSvcGetObjectPropList - Entry")); |
|
42 delete iPropertyList; |
|
43 delete iReceivedObjectMetaData; |
|
44 iObjectHandles.Close(); |
|
45 __FLOG(_L8("~CMTPSvcGetObjectPropList - Exit")); |
|
46 __FLOG_CLOSE; |
|
47 } |
|
48 |
|
49 CMTPSvcGetObjectPropList::CMTPSvcGetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) : |
|
50 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
51 iError(KErrNone), |
|
52 iDataProvider(aDataProvider), |
|
53 iResponseCode(EMTPRespCodeOK) |
|
54 { |
|
55 } |
|
56 |
|
57 void CMTPSvcGetObjectPropList::ConstructL() |
|
58 { |
|
59 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
60 __FLOG(_L8("ConstructL - Entry")); |
|
61 iPropertyList = CMTPTypeObjectPropList::NewL(); |
|
62 __FLOG(_L8("ConstructL - Exit")); |
|
63 } |
|
64 |
|
65 TMTPResponseCode CMTPSvcGetObjectPropList::CheckRequestL() |
|
66 { |
|
67 __FLOG(_L8("CheckRequestL - Entry")); |
|
68 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
69 if (EMTPRespCodeOK == responseCode) |
|
70 { |
|
71 responseCode = CheckObjectHandleAndFormatL(); |
|
72 } |
|
73 |
|
74 if (EMTPRespCodeOK == responseCode) |
|
75 { |
|
76 responseCode = CheckDepth(); |
|
77 } |
|
78 |
|
79 __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode)); |
|
80 return responseCode; |
|
81 } |
|
82 |
|
83 TMTPResponseCode CMTPSvcGetObjectPropList::CheckObjectHandleAndFormatL() |
|
84 { |
|
85 __FLOG(_L8("CheckObjectHandleAndFormatL - Entry")); |
|
86 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
87 |
|
88 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
89 TUint32 formatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
90 iPropCode = Request().Uint32(TMTPTypeRequest::ERequestParameter3); |
|
91 iReceivedObjectMetaData = CMTPObjectMetaData::NewL(); |
|
92 // Object is a specified handle |
|
93 if (objectHandle != KMTPHandleAll && objectHandle != KMTPHandleAllRootLevel) |
|
94 { |
|
95 MMTPObjectMgr& objects(iFramework.ObjectMgr()); |
|
96 //Check whether object handle is valid |
|
97 if (objects.ObjectL(objectHandle, *iReceivedObjectMetaData)) |
|
98 { |
|
99 if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId()) |
|
100 { |
|
101 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
102 __FLOG(_L8("CheckRequestL - DataProviderId dismatch")); |
|
103 } |
|
104 else |
|
105 { |
|
106 // If handle is ok, ignore format code parameter |
|
107 formatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode); |
|
108 iObjectHandler = iDataProvider.ObjectHandler(formatCode); |
|
109 if (!iObjectHandler) |
|
110 { |
|
111 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
112 } |
|
113 else |
|
114 { |
|
115 responseCode = CheckPropertyCodeForFormatL(formatCode); |
|
116 } |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
122 } |
|
123 } |
|
124 // If object handle is 0x0000000 or 0xFFFFFFFF |
|
125 else |
|
126 { |
|
127 // A formatCode value of 0x00000000 indicates that this parameter is not being used and properties |
|
128 // of all Object Formats are desired. |
|
129 if (formatCode != KMTPNotSpecified32) |
|
130 { |
|
131 iObjectHandler = iDataProvider.ObjectHandler(formatCode); |
|
132 if (!iObjectHandler) |
|
133 { |
|
134 responseCode = EMTPRespCodeSpecificationByFormatUnsupported; |
|
135 } |
|
136 else |
|
137 { |
|
138 responseCode = CheckPropertyCodeForFormatL(formatCode); |
|
139 } |
|
140 } |
|
141 } |
|
142 __FLOG_VA((_L8("CheckObjectHandleAndFormatL - Exit with response code = 0x%04X"), responseCode)); |
|
143 return responseCode; |
|
144 } |
|
145 |
|
146 TMTPResponseCode CMTPSvcGetObjectPropList::CheckPropertyCodeForFormatL(TUint32 aFormatCode) const |
|
147 { |
|
148 __FLOG(_L8("CheckPropertyCodeForFormatL - Entry")); |
|
149 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
150 if (iPropCode != KMTPObjectPropCodeAll && iPropCode != KMTPNotSpecified32) |
|
151 { |
|
152 if (!iDataProvider.IsValidObjectPropCodeL(aFormatCode, iPropCode)) |
|
153 { |
|
154 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
155 } |
|
156 } |
|
157 __FLOG_VA((_L8("CheckPropertyCodeForFormatL - Exit with response code = 0x%04X"), responseCode)); |
|
158 return responseCode; |
|
159 } |
|
160 |
|
161 /** |
|
162 Ensures that the requested object depth is one we support. |
|
163 @return EMTPRespCodeOK, or EMTPRespCodeSpecificationByDepthUnsupported if the depth is unsupported |
|
164 */ |
|
165 TMTPResponseCode CMTPSvcGetObjectPropList::CheckDepth() const |
|
166 { |
|
167 __FLOG(_L8("CheckDepth - Entry")); |
|
168 TMTPResponseCode responseCode = EMTPRespCodeSpecificationByDepthUnsupported; |
|
169 // Support depth 0 or 1 or 0xFFFFFFFF |
|
170 TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
171 TUint32 depth = Request().Uint32(TMTPTypeRequest::ERequestParameter5); |
|
172 if (depth == 0 || depth == 1 || depth == KMTPHandleNoParent) |
|
173 { |
|
174 responseCode = EMTPRespCodeOK; |
|
175 } |
|
176 __FLOG_VA((_L8("CheckDepth - Exit with response code = 0x%04X"), responseCode)); |
|
177 return responseCode; |
|
178 } |
|
179 |
|
180 void CMTPSvcGetObjectPropList::ServiceL() |
|
181 { |
|
182 __FLOG(_L8("ServiceL - Entry")); |
|
183 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
184 TUint32 formatCode(Request().Uint32(TMTPTypeRequest::ERequestParameter2)); |
|
185 TUint32 depth(Request().Uint32(TMTPTypeRequest::ERequestParameter5)); |
|
186 iGroupId = Request().Uint32(TMTPTypeRequest::ERequestParameter4); |
|
187 // Get all objects or root objects |
|
188 if (handle == KMTPHandleAll || handle == KMTPHandleAllRootLevel) |
|
189 { |
|
190 // For service DP, the two cases are the same, need all handles with format code. |
|
191 RMTPObjectMgrQueryContext context; |
|
192 CleanupClosePushL(context); |
|
193 do |
|
194 { |
|
195 TUint32 storageId = iDataProvider.StorageId(); |
|
196 TMTPObjectMgrQueryParams params(storageId, formatCode, KMTPHandleNoParent); |
|
197 iFramework.ObjectMgr().GetObjectHandlesL(params, context, iObjectHandles); |
|
198 } |
|
199 while (!context.QueryComplete()); |
|
200 CleanupStack::PopAndDestroy(&context); |
|
201 iHandleIndex = 0; |
|
202 CompleteSelf(KErrNone); |
|
203 } |
|
204 else |
|
205 { |
|
206 GetObjectPropertyHelperL(); |
|
207 SendDataL(*iPropertyList); |
|
208 } |
|
209 __FLOG(_L8("ServiceL - Exit")); |
|
210 } |
|
211 |
|
212 /** |
|
213 Handle the response phase of the current request |
|
214 @return EFalse |
|
215 */ |
|
216 TBool CMTPSvcGetObjectPropList::DoHandleResponsePhaseL() |
|
217 { |
|
218 __FLOG(_L8("DoHandleResponsePhaseL - Entry")); |
|
219 TMTPResponseCode responseCode = (iCancelled ? EMTPRespCodeIncompleteTransfer : iResponseCode); |
|
220 SendResponseL(responseCode); |
|
221 __FLOG_VA((_L8("DoHandleResponsePhaseL - Exit with response code = 0x%04X"), responseCode)); |
|
222 return EFalse; |
|
223 } |
|
224 |
|
225 void CMTPSvcGetObjectPropList::RunL() |
|
226 { |
|
227 __FLOG(_L8("RunL - Entry")); |
|
228 __FLOG_VA((_L8("the number of objects to be queried is %d, iHandleIndex is %d"), iObjectHandles.Count(), iHandleIndex)); |
|
229 |
|
230 TInt count = iObjectHandles.Count(); |
|
231 const TUint32 granularity = iDataProvider.OperationGranularity(); |
|
232 for (TInt i = 0; iHandleIndex < count && i < granularity; i++) |
|
233 { |
|
234 TUint handle = iObjectHandles[iHandleIndex++]; |
|
235 iFramework.ObjectMgr().ObjectL(handle, *iReceivedObjectMetaData); |
|
236 // Process for each object |
|
237 TUint16 formatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode); |
|
238 iObjectHandler = iDataProvider.ObjectHandler(formatCode); |
|
239 if (iObjectHandler) |
|
240 { |
|
241 GetObjectPropertyHelperL(); |
|
242 } |
|
243 else |
|
244 { |
|
245 // An unsupport object got from object mgr. |
|
246 iResponseCode = EMTPRespCodeInvalidObjectHandle; |
|
247 } |
|
248 __FLOG_VA((_L8("Get a object property list, SUID:%S, response code: 0x%4x"), &(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid)), iResponseCode)); |
|
249 } |
|
250 |
|
251 if (iHandleIndex >= count) |
|
252 { |
|
253 ProcessFinalPhaseL(); |
|
254 } |
|
255 else |
|
256 { |
|
257 CompleteSelf(KErrNone); |
|
258 } |
|
259 __FLOG(_L8("RunL - Exit")); |
|
260 } |
|
261 |
|
262 TInt CMTPSvcGetObjectPropList::RunError(TInt aError) |
|
263 { |
|
264 __FLOG(_L8("RunError - Entry")); |
|
265 CompleteSelf(aError); |
|
266 __FLOG(_L8("RunError - Exit")); |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 /** |
|
271 Complete myself |
|
272 */ |
|
273 void CMTPSvcGetObjectPropList::CompleteSelf(TInt aError) |
|
274 { |
|
275 __FLOG(_L8("CompleteSelf - Entry")); |
|
276 SetActive(); |
|
277 TRequestStatus* status = &iStatus; |
|
278 *status = KRequestPending; |
|
279 User::RequestComplete(status, aError); |
|
280 __FLOG(_L8("CompleteSelf - Exit")); |
|
281 } |
|
282 |
|
283 /** |
|
284 Signal to the initiator that the deletion operation has finished with or without error |
|
285 */ |
|
286 void CMTPSvcGetObjectPropList::ProcessFinalPhaseL() |
|
287 { |
|
288 __FLOG(_L8("ProcessFinalPhaseL - Entry")); |
|
289 SendDataL(*iPropertyList); |
|
290 __FLOG(_L8("ProcessFinalPhaseL - Exit")); |
|
291 } |
|
292 |
|
293 void CMTPSvcGetObjectPropList::GetObjectPropertyHelperL() |
|
294 { |
|
295 if (iPropCode == KMTPObjectPropCodeAll) |
|
296 { |
|
297 // A value of 0xFFFFFFFF indicates that all properties are requested except those |
|
298 // with a group code of 0xFFFFFFFF |
|
299 iGroupId = 0; // Get all object prop codes |
|
300 } |
|
301 if (iPropCode == KMTPNotSpecified32 || iPropCode == KMTPObjectPropCodeAll) |
|
302 { |
|
303 // A value of 0x00000000 in the third parameter indicates that the fourth |
|
304 // parameter should be used |
|
305 RArray<TUint32> objectPropCodes; |
|
306 CleanupClosePushL(objectPropCodes); |
|
307 iResponseCode = iObjectHandler->GetAllObjectPropCodeByGroupL(iGroupId, objectPropCodes); |
|
308 if (iResponseCode == EMTPRespCodeOK) |
|
309 { |
|
310 TInt count = objectPropCodes.Count(); |
|
311 for (TInt i = 0; i < count && iResponseCode == EMTPRespCodeOK; i++) |
|
312 { |
|
313 iResponseCode = iObjectHandler->GetObjectPropertyL(*iReceivedObjectMetaData, objectPropCodes[i], *iPropertyList); |
|
314 } |
|
315 } |
|
316 CleanupStack::PopAndDestroy(&objectPropCodes); |
|
317 } |
|
318 else |
|
319 { |
|
320 // Get one prop info into objectproplist. |
|
321 iResponseCode = iObjectHandler->GetObjectPropertyL(*iReceivedObjectMetaData, iPropCode, *iPropertyList); |
|
322 } |
|
323 } |