|
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/cmtpsvcdeleteobject.cpp |
|
15 |
|
16 #include <mtp/mmtpdataproviderframework.h> |
|
17 #include <mtp/cmtpobjectmetadata.h> |
|
18 #include <mtp/mmtpobjectmgr.h> |
|
19 |
|
20 #include "cmtpsvcdeleteobject.h" |
|
21 #include "mtpdpconst.h" |
|
22 #include "mmtpservicedataprovider.h" |
|
23 #include "mmtpsvcobjecthandler.h" |
|
24 |
|
25 // Class constants. |
|
26 __FLOG_STMT(_LIT8(KComponent,"SvcDeleteObject");) |
|
27 |
|
28 EXPORT_C MMTPRequestProcessor* CMTPSvcDeleteObject::NewL(MMTPDataProviderFramework& aFramework, |
|
29 MMTPConnection& aConnection, |
|
30 MMTPServiceDataProvider& aDataProvider) |
|
31 { |
|
32 CMTPSvcDeleteObject* self = new (ELeave) CMTPSvcDeleteObject(aFramework, aConnection, aDataProvider); |
|
33 return self; |
|
34 } |
|
35 |
|
36 EXPORT_C CMTPSvcDeleteObject::~CMTPSvcDeleteObject() |
|
37 { |
|
38 __FLOG(_L8("~CMTPSvcDeleteObject - Entry")); |
|
39 iObjectHandles.Close(); |
|
40 delete iReceivedObjectMetaData; |
|
41 __FLOG(_L8("~CMTPSvcDeleteObject - Exit")); |
|
42 __FLOG_CLOSE; |
|
43 } |
|
44 |
|
45 CMTPSvcDeleteObject::CMTPSvcDeleteObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) : |
|
46 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), iDataProvider(aDataProvider), iDeleteError(KErrNone) |
|
47 { |
|
48 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
49 __FLOG(_L8("CMTPSvcDeleteObject - Constructed")); |
|
50 } |
|
51 |
|
52 /** |
|
53 DeleteObject request handler |
|
54 */ |
|
55 void CMTPSvcDeleteObject::LoadAllObjHandlesL(TUint32 aParentHandle) |
|
56 { |
|
57 __FLOG(_L8("LoadAllObjHandlesL - Entry")); |
|
58 const TUint32 KFormatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
59 RMTPObjectMgrQueryContext context; |
|
60 CleanupClosePushL(context); |
|
61 |
|
62 do |
|
63 { // Append all object handles with service dp's storage id. |
|
64 TUint32 storageId = iDataProvider.StorageId(); |
|
65 TMTPObjectMgrQueryParams params(storageId, KFormatCode, aParentHandle); |
|
66 iFramework.ObjectMgr().GetObjectHandlesL(params, context, iObjectHandles); |
|
67 } |
|
68 while (!context.QueryComplete()); |
|
69 CleanupStack::PopAndDestroy(&context); |
|
70 __FLOG(_L8("LoadAllObjHandlesL - Exit")); |
|
71 } |
|
72 |
|
73 void CMTPSvcDeleteObject::ServiceL() |
|
74 { |
|
75 __FLOG(_L8("ServiceL - Entry")); |
|
76 if (iFormatCode == EMTPFormatCodeAssociation) |
|
77 { |
|
78 // Framework may send deleteobject for a directory, allow framework do this. |
|
79 SendResponseL(EMTPRespCodeOK); |
|
80 return; |
|
81 } |
|
82 |
|
83 const TUint32 KHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
84 |
|
85 if (KHandle == KMTPHandleAll) |
|
86 { |
|
87 LoadAllObjHandlesL(KMTPHandleNoParent); |
|
88 iDeleteIndex = 0; |
|
89 iSuccessDeletion = EFalse; |
|
90 CompleteSelf(KErrNone); |
|
91 } |
|
92 else |
|
93 { |
|
94 TMTPResponseCode responseCode = iObjectHandler->DeleteObjectL(*iReceivedObjectMetaData); |
|
95 // Remove from framework. |
|
96 iFramework.ObjectMgr().RemoveObjectL(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid)); |
|
97 SendResponseL(responseCode); |
|
98 __FLOG_VA((_L8("Delete single object exit with response code = 0x%04X"), responseCode)); |
|
99 } |
|
100 __FLOG(_L8("ServiceL - Exit")); |
|
101 } |
|
102 |
|
103 void CMTPSvcDeleteObject::RunL() |
|
104 { |
|
105 __FLOG(_L8("RunL - Entry")); |
|
106 __FLOG_VA((_L8("the number of objects to be deleted is %d, iDeleteIndex is %d"), iObjectHandles.Count(), iDeleteIndex)); |
|
107 |
|
108 if (iStatus != KErrNone) |
|
109 { |
|
110 iDeleteError = iStatus.Int(); |
|
111 } |
|
112 |
|
113 CDesCArray* objectDeleted = new (ELeave) CDesCArrayFlat(KMTPDriveGranularity); |
|
114 CleanupStack::PushL(objectDeleted); |
|
115 |
|
116 TInt errCount = 0; |
|
117 TInt count = iObjectHandles.Count(); |
|
118 const TUint32 granularity = iDataProvider.OperationGranularity(); |
|
119 for (TInt i = 0; iDeleteIndex < count && i < granularity; ++i) |
|
120 { |
|
121 TUint handle = iObjectHandles[iDeleteIndex++]; |
|
122 iFramework.ObjectMgr().ObjectL(handle, *iReceivedObjectMetaData); |
|
123 if (DeleteObjectL(*iReceivedObjectMetaData) == EMTPRespCodeOK) |
|
124 { |
|
125 objectDeleted->AppendL(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid)); |
|
126 iSuccessDeletion = ETrue; |
|
127 } |
|
128 else |
|
129 { |
|
130 ++errCount; |
|
131 __FLOG_VA((_L8("Delete object failed, SUID:%S"), &(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid)))); |
|
132 } |
|
133 } |
|
134 |
|
135 // Remove object from framework |
|
136 iFramework.ObjectMgr().RemoveObjectsL(*objectDeleted); |
|
137 CleanupStack::PopAndDestroy(objectDeleted); |
|
138 |
|
139 if (iDeleteIndex >= count) |
|
140 { |
|
141 ProcessFinalPhaseL(); |
|
142 } |
|
143 else |
|
144 { |
|
145 TInt err = (errCount > 0) ? KErrGeneral : KErrNone; |
|
146 CompleteSelf(err); |
|
147 } |
|
148 __FLOG(_L8("RunL - Exit")); |
|
149 } |
|
150 |
|
151 /** |
|
152 Handle an error in the delete loop by storing the error code and continuing deleting. |
|
153 */ |
|
154 TInt CMTPSvcDeleteObject::RunError(TInt aError) |
|
155 { |
|
156 __FLOG(_L8("RunError - Entry")); |
|
157 CompleteSelf(aError); |
|
158 __FLOG(_L8("RunError - Exit")); |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 /** |
|
163 Complete myself |
|
164 */ |
|
165 void CMTPSvcDeleteObject::CompleteSelf(TInt aError) |
|
166 { |
|
167 __FLOG(_L8("CompleteSelf - Entry")); |
|
168 SetActive(); |
|
169 TRequestStatus* status = &iStatus; |
|
170 *status = KRequestPending; |
|
171 User::RequestComplete(status, aError); |
|
172 __FLOG(_L8("CompleteSelf - Exit")); |
|
173 } |
|
174 |
|
175 TMTPResponseCode CMTPSvcDeleteObject::CheckRequestL() |
|
176 { |
|
177 __FLOG(_L8("CheckRequestL - Entry")); |
|
178 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
179 if (EMTPRespCodeOK == responseCode) |
|
180 { |
|
181 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
182 iReceivedObjectMetaData = CMTPObjectMetaData::NewL(); |
|
183 // Check object handle with dataprovider id, if handle is valid, then ignore format code in parameter 2. |
|
184 if (objectHandle != KMTPHandleAll) |
|
185 { |
|
186 MMTPObjectMgr& objects = iFramework.ObjectMgr(); |
|
187 //Check whether object handle is valid |
|
188 // Framework may send a handle which is a directory and dp can't check id in this case |
|
189 if (objects.ObjectL(objectHandle, *iReceivedObjectMetaData)) |
|
190 { |
|
191 iFormatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode); |
|
192 if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId() && (iFormatCode != EMTPFormatCodeAssociation)) |
|
193 { |
|
194 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
195 __FLOG(_L8("DataProviderId dismatch")); |
|
196 } |
|
197 else |
|
198 { |
|
199 responseCode = CheckFmtAndSetHandler(iFormatCode); |
|
200 } |
|
201 } |
|
202 else |
|
203 { |
|
204 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
205 } |
|
206 } |
|
207 else |
|
208 { |
|
209 // Delete all objects for a format |
|
210 iFormatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
211 // Check format code |
|
212 if (iFormatCode != KMTPFormatsAll) |
|
213 { |
|
214 responseCode = CheckFmtAndSetHandler(iFormatCode); |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 __FLOG_VA((_L8("CheckRequestL Exit with response code = 0x%04X"), responseCode)); |
|
220 return responseCode; |
|
221 } |
|
222 |
|
223 void CMTPSvcDeleteObject::ProcessFinalPhaseL() |
|
224 { |
|
225 __FLOG(_L8("ProcessFinalPhaseL - Entry")); |
|
226 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
227 if (iDeleteError != KErrNone) |
|
228 { |
|
229 if (iSuccessDeletion) |
|
230 { |
|
231 responseCode = EMTPRespCodePartialDeletion; |
|
232 } |
|
233 else |
|
234 { |
|
235 responseCode = EMTPRespCodeStoreReadOnly; |
|
236 } |
|
237 } |
|
238 SendResponseL(responseCode); |
|
239 __FLOG_VA((_L8("ProcessFinalPhaseL - Exit with response code = 0x%04X"), responseCode)); |
|
240 } |
|
241 |
|
242 TMTPResponseCode CMTPSvcDeleteObject::CheckFmtAndSetHandler(TUint32 aFormatCode) |
|
243 { |
|
244 __FLOG(_L8("CheckFmtAndSetHandler - Entry")); |
|
245 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
246 iObjectHandler = iDataProvider.ObjectHandler(aFormatCode); |
|
247 if (!iObjectHandler) |
|
248 { |
|
249 responseCode = EMTPRespCodeInvalidObjectFormatCode; |
|
250 } |
|
251 __FLOG(_L8("CheckFmtAndSetHandler - Exit")); |
|
252 return responseCode; |
|
253 } |
|
254 |
|
255 TMTPResponseCode CMTPSvcDeleteObject::DeleteObjectL(const CMTPObjectMetaData& aObjectMetaData) |
|
256 { |
|
257 __FLOG(_L8("DeleteObjectL - Entry")); |
|
258 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
259 TUint16 formatCode = aObjectMetaData.Uint(CMTPObjectMetaData::EFormatCode); |
|
260 responseCode = CheckFmtAndSetHandler(formatCode); |
|
261 if (EMTPRespCodeOK == responseCode) |
|
262 { |
|
263 responseCode = iObjectHandler->DeleteObjectL(aObjectMetaData); |
|
264 } |
|
265 __FLOG(_L8("DeleteObjectL - Exit")); |
|
266 return responseCode; |
|
267 } |