|
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/cmtpsvcdeleteobjectproplist.cpp |
|
15 |
|
16 #include <mtp/mmtpdataproviderframework.h> |
|
17 #include <mtp/mmtpobjectmgr.h> |
|
18 #include <mtp/cmtpobjectmetadata.h> |
|
19 #include <mtp/cmtptypedeleteobjectproplist.h> |
|
20 #include <mtp/tmtptypedatapair.h> |
|
21 |
|
22 #include "cmtpsvcdeleteobjectproplist.h" |
|
23 #include "mmtpservicedataprovider.h" |
|
24 #include "mmtpsvcobjecthandler.h" |
|
25 |
|
26 // Class constants. |
|
27 __FLOG_STMT(_LIT8(KComponent,"SvcDelObjPropList");) |
|
28 |
|
29 EXPORT_C MMTPRequestProcessor* CMTPSvcDeleteObjectPropList::NewL(MMTPDataProviderFramework& aFramework, |
|
30 MMTPConnection& aConnection, |
|
31 MMTPServiceDataProvider& aDataProvider) |
|
32 { |
|
33 CMTPSvcDeleteObjectPropList* self = new (ELeave) CMTPSvcDeleteObjectPropList(aFramework, aConnection, aDataProvider); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 EXPORT_C CMTPSvcDeleteObjectPropList::~CMTPSvcDeleteObjectPropList() |
|
41 { |
|
42 __FLOG(_L8("~CMTPSvcDeleteObjectPropList - Entry")); |
|
43 delete iPropertyList; |
|
44 delete iReceivedObjectMetaData; |
|
45 __FLOG(_L8("~CMTPSvcDeleteObjectPropList - Exit")); |
|
46 __FLOG_CLOSE; |
|
47 } |
|
48 |
|
49 CMTPSvcDeleteObjectPropList::CMTPSvcDeleteObjectPropList(MMTPDataProviderFramework& aFramework, |
|
50 MMTPConnection& aConnection, |
|
51 MMTPServiceDataProvider& aDataProvider) : |
|
52 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
53 iDataProvider(aDataProvider) |
|
54 { |
|
55 } |
|
56 |
|
57 void CMTPSvcDeleteObjectPropList::ConstructL() |
|
58 { |
|
59 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
60 __FLOG(_L8("ConstructL - Entry")); |
|
61 iPropertyList = CMTPTypeDeleteObjectPropList::NewL(); |
|
62 __FLOG(_L8("ConstructL - Exit")); |
|
63 } |
|
64 |
|
65 TMTPResponseCode CMTPSvcDeleteObjectPropList::CheckRequestL() |
|
66 { |
|
67 __FLOG(_L8("CheckRequestL - Entry")); |
|
68 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
69 if (EMTPRespCodeOK == responseCode) |
|
70 { |
|
71 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
72 iReceivedObjectMetaData = CMTPObjectMetaData::NewL(); |
|
73 // Check object handle |
|
74 if (objectHandle != KMTPHandleAll) |
|
75 { |
|
76 MMTPObjectMgr& objMgr(iFramework.ObjectMgr()); |
|
77 // Check whether object handle is valid |
|
78 if (objMgr.ObjectL(objectHandle, *iReceivedObjectMetaData)) |
|
79 { |
|
80 // Check whether the owner of this object is correct service data provider |
|
81 if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId()) |
|
82 { |
|
83 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
84 __FLOG(_L8("CheckRequestL - DataProviderId dismatch")); |
|
85 } |
|
86 else |
|
87 { |
|
88 // Check format code |
|
89 TUint16 formatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode); |
|
90 if (!iDataProvider.ObjectHandler(formatCode)) |
|
91 { |
|
92 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
93 } |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
99 } |
|
100 } |
|
101 else |
|
102 { |
|
103 iReceivedObjectMetaData->SetUint(CMTPObjectMetaData::EHandle, KMTPHandleAll); |
|
104 } |
|
105 } |
|
106 __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode)); |
|
107 return responseCode; |
|
108 } |
|
109 |
|
110 void CMTPSvcDeleteObjectPropList::ServiceL() |
|
111 { |
|
112 __FLOG(_L8("ServiceL - Entry")); |
|
113 ReceiveDataL(*iPropertyList); |
|
114 __FLOG(_L8("ServiceL - Exit")); |
|
115 } |
|
116 |
|
117 TBool CMTPSvcDeleteObjectPropList::DoHandleResponsePhaseL() |
|
118 { |
|
119 __FLOG(_L8("DoHandleResponsePhaseL - Entry")); |
|
120 TUint32 parameter(0); |
|
121 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
122 |
|
123 responseCode = DeleteObjectPropListL(*iReceivedObjectMetaData, *iPropertyList, parameter); |
|
124 |
|
125 SendResponseL(responseCode, 1, ¶meter); |
|
126 __FLOG_VA((_L8("DeleteObjectPropListL responseCode = 0x%x, failed index = %u"), responseCode, parameter)); |
|
127 return EFalse; |
|
128 } |
|
129 |
|
130 TBool CMTPSvcDeleteObjectPropList::HasDataphase() const |
|
131 { |
|
132 return ETrue; |
|
133 } |
|
134 |
|
135 TMTPResponseCode CMTPSvcDeleteObjectPropList::DeleteObjectPropListL(CMTPObjectMetaData& aObjectMetaData, |
|
136 const CMTPTypeDeleteObjectPropList& aPropList, |
|
137 TUint32& aParameter) |
|
138 { |
|
139 __FLOG(_L8("DeleteObjectPropList- Entry")); |
|
140 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
141 TUint handle = aObjectMetaData.Uint(CMTPObjectMetaData::EHandle); |
|
142 MMTPSvcObjectHandler* lastHandler = NULL; |
|
143 TUint errIndex = 0; |
|
144 |
|
145 if (handle == KMTPHandleAll) |
|
146 { |
|
147 TUint32 lastHandle = 0; |
|
148 // In this case, all object handles specified in the dataset, can be multiple objects |
|
149 const TUint count(aPropList.NumberOfElements()); |
|
150 CMTPObjectMetaData* objectMetaData = CMTPObjectMetaData::NewL(); |
|
151 CleanupStack::PushL(objectMetaData); |
|
152 for (TUint i = 0; i < count; i++) |
|
153 { |
|
154 TMTPTypeDataPair& element = aPropList.ElementL(i); |
|
155 TUint32 handle = element.Uint32(TMTPTypeDataPair::EOwnerHandle); |
|
156 // Get object handle every time for multiple objects. |
|
157 if (iFramework.ObjectMgr().ObjectL(handle, *objectMetaData)) |
|
158 { |
|
159 TUint16 formatCode = objectMetaData->Uint(CMTPObjectMetaData::EFormatCode); |
|
160 TUint16 propCode = element.Uint16(TMTPTypeDataPair::EDataCode); |
|
161 MMTPSvcObjectHandler* pHandler = iDataProvider.ObjectHandler(formatCode); |
|
162 if (pHandler) |
|
163 { |
|
164 // If the handler is not the last handle, need commit all properties now |
|
165 if (lastHandle != 0 && lastHandler && lastHandle != handle) |
|
166 { |
|
167 // Performance can be improved here |
|
168 TRAPD(err, lastHandler->CommitL()); |
|
169 if (KErrNone != err) |
|
170 { |
|
171 lastHandler->RollBack(); |
|
172 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
173 aParameter = errIndex; |
|
174 break; |
|
175 } |
|
176 // Record the next segment's first index number |
|
177 errIndex = i; |
|
178 } |
|
179 lastHandler = pHandler; |
|
180 lastHandle = handle; |
|
181 responseCode = pHandler->DeleteObjectPropertyL(*objectMetaData, propCode); |
|
182 } |
|
183 else |
|
184 { |
|
185 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
186 } |
|
187 } |
|
188 else |
|
189 { |
|
190 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
191 } |
|
192 if (responseCode != EMTPRespCodeOK) |
|
193 { |
|
194 aParameter = i; |
|
195 // All properties prior to the failed property will be updated. |
|
196 if (i != errIndex && lastHandler) |
|
197 { |
|
198 TRAPD(err, lastHandler->CommitL()); |
|
199 if (KErrNone != err) |
|
200 { |
|
201 lastHandler->RollBack(); |
|
202 aParameter = errIndex; |
|
203 } |
|
204 } |
|
205 break; |
|
206 } |
|
207 } |
|
208 CleanupStack::PopAndDestroy(objectMetaData); |
|
209 } |
|
210 else |
|
211 { |
|
212 // The element object handle fields should be either 0x00000000 or match with parameter 1. |
|
213 TUint16 formatCode = aObjectMetaData.Uint(CMTPObjectMetaData::EFormatCode); |
|
214 const TUint count(aPropList.NumberOfElements()); |
|
215 for (TUint i = 0; i < count; i++) |
|
216 { |
|
217 TMTPTypeDataPair& element = aPropList.ElementL(i); |
|
218 TUint32 handle = element.Uint32(TMTPTypeDataPair::EOwnerHandle); |
|
219 // Check dataset according to spec |
|
220 if (handle != aObjectMetaData.Uint(CMTPObjectMetaData::EHandle) && handle != KMTPHandleNone) |
|
221 { |
|
222 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
223 } |
|
224 else |
|
225 { |
|
226 TUint16 propCode = element.Uint16(TMTPTypeDataPair::EDataCode); |
|
227 MMTPSvcObjectHandler* pHandler = iDataProvider.ObjectHandler(formatCode); |
|
228 if (pHandler) |
|
229 { |
|
230 responseCode = pHandler->DeleteObjectPropertyL(aObjectMetaData, propCode); |
|
231 if (!lastHandler) |
|
232 { |
|
233 lastHandler = pHandler; |
|
234 } |
|
235 } |
|
236 else |
|
237 { |
|
238 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
239 } |
|
240 } |
|
241 if (responseCode != EMTPRespCodeOK) |
|
242 { |
|
243 aParameter = i; |
|
244 if (i != 0 && lastHandler) |
|
245 { |
|
246 TRAPD(err, lastHandler->CommitL()); |
|
247 if (KErrNone != err) |
|
248 { |
|
249 lastHandler->RollBack(); |
|
250 aParameter = errIndex; |
|
251 } |
|
252 } |
|
253 break; |
|
254 } |
|
255 } |
|
256 } |
|
257 // Commint for each case |
|
258 if (responseCode == EMTPRespCodeOK && lastHandler) |
|
259 { |
|
260 TRAPD(err, lastHandler->CommitL()); |
|
261 if (KErrNone != err) |
|
262 { |
|
263 lastHandler->RollBack(); |
|
264 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
265 aParameter = errIndex; |
|
266 } |
|
267 } |
|
268 __FLOG_VA((_L8("DeleteObjectPropList - Exit with responseCode = 0x%04X"), responseCode)); |
|
269 return responseCode; |
|
270 } |