|
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 @file |
|
17 @internalTechnology |
|
18 */ |
|
19 #include <bautils.h> |
|
20 #include <mtp/cmtptypearray.h> |
|
21 #include <mtp/cmtpobjectmetadata.h> |
|
22 #include <mtp/mmtpdataproviderframework.h> |
|
23 #include <mtp/mmtpobjectmgr.h> |
|
24 #include <mtp/mtpprotocolconstants.h> |
|
25 #include <mtp/mmtpstoragemgr.h> |
|
26 #include <mtp/tmtptyperequest.h> |
|
27 #include "cmtpimagedpdeleteobject.h" |
|
28 #include "mtpimagedpconst.h" |
|
29 #include "mtpimagedppanic.h" |
|
30 #include "cmtpimagedpobjectpropertymgr.h" |
|
31 #include "mtpimagedputilits.h" |
|
32 #include "cmtpimagedp.h" |
|
33 // Class constants. |
|
34 __FLOG_STMT(_LIT8(KComponent,"ImageDeleteObject");) |
|
35 /** |
|
36 Standard c++ constructor |
|
37 */ |
|
38 CMTPImageDpDeleteObject::CMTPImageDpDeleteObject( |
|
39 MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, |
|
40 CMTPImageDataProvider& aDataProvider) : |
|
41 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
42 iDataProvider(aDataProvider), |
|
43 iResponseCode( EMTPRespCodeOK ) |
|
44 { |
|
45 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
46 __FLOG(_L8(">> CMTPImageDpDeleteObject")); |
|
47 __FLOG(_L8("<< CMTPImageDpDeleteObject")); |
|
48 } |
|
49 |
|
50 /** |
|
51 Two-phase construction method |
|
52 @param aFramework The data provider framework |
|
53 @param aConnection The connection from which the request comes |
|
54 @return a pointer to the created request processor object |
|
55 */ |
|
56 MMTPRequestProcessor* CMTPImageDpDeleteObject::NewL( |
|
57 MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, |
|
58 CMTPImageDataProvider& aDataProvider) |
|
59 { |
|
60 CMTPImageDpDeleteObject* self = new (ELeave) CMTPImageDpDeleteObject( |
|
61 aFramework, aConnection, aDataProvider); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 void CMTPImageDpDeleteObject::ConstructL() |
|
69 { |
|
70 __FLOG(_L8(">> CMTPImageDpDeleteObject::ConstructL")); |
|
71 iObjectMeta = CMTPObjectMetaData::NewL(); |
|
72 __FLOG(_L8("<< CMTPImageDpDeleteObject::ConstructL")); |
|
73 } |
|
74 /** |
|
75 Destructor |
|
76 */ |
|
77 CMTPImageDpDeleteObject::~CMTPImageDpDeleteObject() |
|
78 { |
|
79 __FLOG(_L8("~CMTPImageDpDeleteObject - Entry")); |
|
80 Cancel(); |
|
81 delete iObjectMeta; |
|
82 iObjectsToDelete.Close(); |
|
83 __FLOG(_L8("~CMTPImageDpDeleteObject - Exit")); |
|
84 __FLOG_CLOSE; |
|
85 } |
|
86 |
|
87 /** |
|
88 Verify the request |
|
89 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
|
90 */ |
|
91 |
|
92 TMTPResponseCode CMTPImageDpDeleteObject::CheckRequestL() |
|
93 { |
|
94 __FLOG(_L8(">> CMTPImageDpDeleteObject::CheckRequestL")); |
|
95 TMTPResponseCode result = EMTPRespCodeOK; |
|
96 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
97 if ( handle != KMTPHandleAll ) |
|
98 { |
|
99 result = CheckStorageL( handle ); |
|
100 } |
|
101 __FLOG(_L8("<< CMTPImageDpDeleteObject::CheckRequestL")); |
|
102 return result; |
|
103 } |
|
104 |
|
105 /** |
|
106 DeleteObject request handler |
|
107 */ |
|
108 void CMTPImageDpDeleteObject::ServiceL() |
|
109 { |
|
110 __FLOG(_L8(">> CMTPImageDpDeleteObject::ServiceL")); |
|
111 |
|
112 //begin to find object |
|
113 iObjectsToDelete.Reset(); |
|
114 iResponseCode = EMTPRespCodeOK; |
|
115 iObjectsNotDelete = 0; |
|
116 TUint32 objectHandle( Request().Uint32( TMTPTypeRequest::ERequestParameter1 )); |
|
117 TUint32 formatCode( Request().Uint32( TMTPTypeRequest::ERequestParameter2 )); |
|
118 |
|
119 // Check to see whether the request is to delete all images or a specific image |
|
120 if ( objectHandle == KMTPHandleAll ) |
|
121 { |
|
122 //add for test |
|
123 __FLOG(_L8("delete all objects")); |
|
124 GetObjectHandlesL( KMTPStorageAll, formatCode, KMTPHandleNone ); |
|
125 iObjectsNotDelete = iObjectsToDelete.Count(); |
|
126 StartL(); |
|
127 } |
|
128 else |
|
129 { |
|
130 //add for test |
|
131 __FLOG(_L8("delete only one object")); |
|
132 iObjectsNotDelete = 1; |
|
133 DeleteObjectL( objectHandle ); |
|
134 |
|
135 SendResponseL(); |
|
136 } |
|
137 |
|
138 __FLOG(_L8("<< CMTPImageDpDeleteObject::ServiceL")); |
|
139 } |
|
140 |
|
141 void CMTPImageDpDeleteObject::RunL() |
|
142 { |
|
143 __FLOG(_L8(">> CMTPImageDpDeleteObject::RunL")); |
|
144 |
|
145 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
|
146 |
|
147 if ( numObjectsToDelete > 0 ) |
|
148 { |
|
149 DeleteObjectL( iObjectsToDelete[0] ); |
|
150 iObjectsToDelete.Remove( 0 ); |
|
151 } |
|
152 |
|
153 // Start the process again to read the next row... |
|
154 StartL(); |
|
155 |
|
156 __FLOG(_L8("<< CMTPImageDpDeleteObject::RunL")); |
|
157 } |
|
158 |
|
159 void CMTPImageDpDeleteObject::DoCancel() |
|
160 { |
|
161 __FLOG(_L8(">> CMTPImageDpDeleteObject::DoCancel")); |
|
162 |
|
163 TRAP_IGNORE( SendResponseL()); |
|
164 |
|
165 __FLOG(_L8("<< CMTPImageDpDeleteObject::DoCancel")); |
|
166 } |
|
167 |
|
168 /** |
|
169 Check whether the store on which the object resides is read only. |
|
170 @return ETrue if the store is read only, EFalse if read-write |
|
171 */ |
|
172 TMTPResponseCode CMTPImageDpDeleteObject::CheckStorageL(TUint32 aObjectHandle) |
|
173 { |
|
174 __FLOG(_L8(">> CMTPImageDpDeleteObject::CheckStorageL")); |
|
175 TMTPResponseCode result = MTPImageDpUtilits::VerifyObjectHandleL( |
|
176 iFramework, aObjectHandle, *iObjectMeta); |
|
177 if (EMTPRespCodeOK == result) |
|
178 { |
|
179 TDriveNumber drive= static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber( |
|
180 iObjectMeta->Uint(CMTPObjectMetaData::EStorageId))); |
|
181 User::LeaveIfError(drive); |
|
182 TVolumeInfo volumeInfo; |
|
183 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
|
184 if (volumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected) |
|
185 { |
|
186 result = EMTPRespCodeStoreReadOnly; |
|
187 } |
|
188 } |
|
189 __FLOG(_L8("<< CMTPImageDpDeleteObject::CheckStorageL")); |
|
190 return result; |
|
191 } |
|
192 |
|
193 void CMTPImageDpDeleteObject::GetObjectHandlesL( TUint32 aStorageId, TUint32 aFormatCode, TUint32 aParentHandle ) |
|
194 { |
|
195 __FLOG(_L8(">> CMTPImageDpDeleteObject::GetObjectHandlesL")); |
|
196 |
|
197 RMTPObjectMgrQueryContext context; |
|
198 RArray<TUint> handles; |
|
199 TMTPObjectMgrQueryParams params( aStorageId, aFormatCode, aParentHandle, iFramework.DataProviderId()); |
|
200 CleanupClosePushL( context ); // + context |
|
201 CleanupClosePushL( handles ); // + handles |
|
202 |
|
203 do |
|
204 { |
|
205 iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles ); |
|
206 for ( TInt i = 0; i < handles.Count(); i++) |
|
207 { |
|
208 iObjectsToDelete.Append( handles[i] ); |
|
209 } |
|
210 } |
|
211 while ( !context.QueryComplete() ); |
|
212 |
|
213 CleanupStack::PopAndDestroy( &handles ); // - handles |
|
214 CleanupStack::PopAndDestroy( &context ); // - context |
|
215 |
|
216 __FLOG(_L8("<< CMTPImageDpDeleteObject::GetObjectHandlesL")); |
|
217 } |
|
218 |
|
219 void CMTPImageDpDeleteObject::DeleteObjectL( TUint32 aHandle ) |
|
220 { |
|
221 __FLOG(_L8(">> CMTPImageDpDeleteObject::DeleteObjectL")); |
|
222 |
|
223 iFramework.ObjectMgr().ObjectL( aHandle, *iObjectMeta); |
|
224 iDataProvider.PropertyMgr().SetCurrentObjectL(*iObjectMeta, EFalse); |
|
225 TUint16 protectionStatus = EMTPProtectionNoProtection; |
|
226 iDataProvider.PropertyMgr().GetPropertyL(EMTPObjectPropCodeProtectionStatus, protectionStatus); |
|
227 if(EMTPProtectionNoProtection == protectionStatus) |
|
228 { |
|
229 TInt err = iFramework.Fs().Delete(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
230 __FLOG_1(_L8("delete file error is %d"), err ); |
|
231 switch ( err ) |
|
232 { |
|
233 case KErrInUse: |
|
234 case KErrAccessDenied: |
|
235 //add for test |
|
236 __FLOG_1(_L8("err:%d"), err); |
|
237 //add Suid to deleteobjectlist |
|
238 iDataProvider.AppendDeleteObjectsArrayL(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
239 case KErrNone: |
|
240 //add for test |
|
241 __FLOG(_L8("KErrNone")); |
|
242 iFramework.ObjectMgr().RemoveObjectL( iObjectMeta->Uint(CMTPObjectMetaData::EHandle )); |
|
243 iObjectsNotDelete--; |
|
244 iResponseCode = EMTPRespCodePartialDeletion; |
|
245 break; |
|
246 default: |
|
247 //add for test |
|
248 __FLOG(_L8("default")); |
|
249 User::LeaveIfError( err ); |
|
250 break; |
|
251 } |
|
252 } |
|
253 else if ( iResponseCode != EMTPRespCodePartialDeletion ) |
|
254 { |
|
255 iResponseCode = EMTPRespCodeObjectWriteProtected; |
|
256 } |
|
257 __FLOG(_L8("<< CMTPImageDpDeleteObject::DeleteObjectL")); |
|
258 } |
|
259 |
|
260 void CMTPImageDpDeleteObject::StartL() |
|
261 { |
|
262 __FLOG(_L8(">> CMTPImageDpDeleteObject::StartL")); |
|
263 |
|
264 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
|
265 |
|
266 if ( numObjectsToDelete > 0 ) |
|
267 { |
|
268 //Set the active object going to delete the file |
|
269 TRequestStatus* status = &iStatus; |
|
270 User::RequestComplete( status, KErrNone ); |
|
271 SetActive(); |
|
272 } |
|
273 else |
|
274 { |
|
275 SendResponseL(); |
|
276 } |
|
277 __FLOG(_L8("<< CMTPImageDpDeleteObject::StartL")); |
|
278 } |
|
279 |
|
280 void CMTPImageDpDeleteObject::SendResponseL() |
|
281 { |
|
282 __FLOG(_L8(">> CMTPImageDpDeleteObject::SendResponseL")); |
|
283 |
|
284 if ( iResponseCode == EMTPRespCodePartialDeletion && iObjectsNotDelete == 0 ) |
|
285 { |
|
286 iResponseCode = EMTPRespCodeOK; |
|
287 } |
|
288 CMTPRequestProcessor::SendResponseL( iResponseCode ); |
|
289 |
|
290 __FLOG(_L8("<< CMTPImageDpDeleteObject::SendResponseL")); |
|
291 } |
|
292 |