|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implement the operation: DeleteObject |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mmtpobjectmgr.h> |
|
21 #include <mtp/cmtpobjectmetadata.h> |
|
22 |
|
23 #include "cdeleteobject.h" |
|
24 #include "mmmtpdplogger.h" |
|
25 #include "mmmtpdpconfig.h" |
|
26 #include "cmmmtpdpmetadataaccesswrapper.h" |
|
27 |
|
28 // static const TInt KMTPDriveGranularity = 5; |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // Verification data for the DeleteObject request |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 const TMTPRequestElementInfo KMTPDeleteObjectPolicy[] = |
|
35 { |
|
36 { |
|
37 TMTPTypeRequest::ERequestParameter1, |
|
38 EMTPElementTypeObjectHandle, |
|
39 EMTPElementAttrWrite, |
|
40 1, |
|
41 KMTPHandleAll, |
|
42 0 |
|
43 }, |
|
44 }; |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CDeleteObject::NewL |
|
48 // Two-phase construction method |
|
49 // CDeleteObject is an abstract class and shouldn't be instaniated. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C MMmRequestProcessor* CDeleteObject::NewL( MMTPDataProviderFramework& aFramework, |
|
53 MMTPConnection& aConnection, |
|
54 MMmMtpDpConfig& aDpConfig ) |
|
55 { |
|
56 CDeleteObject* self = new (ELeave) CDeleteObject( aFramework, aConnection, aDpConfig ); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 void CDeleteObject::ConstructL() |
|
64 { |
|
65 CActiveScheduler::Add( this ); |
|
66 SetPSStatus(); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CDeleteObject::~CDeleteObject |
|
71 // Destructor |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CDeleteObject::~CDeleteObject() |
|
75 { |
|
76 Cancel(); |
|
77 iObjectsToDelete.Close(); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CDeleteObject::CDeleteObject |
|
82 // Standard c++ constructor |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CDeleteObject::CDeleteObject( MMTPDataProviderFramework& aFramework, |
|
86 MMTPConnection& aConnection, |
|
87 MMmMtpDpConfig& aDpConfig ) : |
|
88 CRequestProcessor( aFramework, |
|
89 aConnection, |
|
90 sizeof( KMTPDeleteObjectPolicy ) / sizeof( TMTPRequestElementInfo ), |
|
91 KMTPDeleteObjectPolicy ), |
|
92 iObjectMgr( aFramework.ObjectMgr() ), |
|
93 iFs( aFramework.Fs() ), |
|
94 iObjectsToDelete( KMmMtpRArrayGranularity ), |
|
95 iDeleteError( KErrNone ), |
|
96 iDpConfig( aDpConfig ) |
|
97 { |
|
98 PRINT( _L( "Operation: DeleteObject(0x100B)" ) ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CDeleteObject::ServiceL |
|
103 // DeleteObject request handler |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C void CDeleteObject::ServiceL() |
|
107 { |
|
108 iObjectsToDelete.Reset(); |
|
109 iDeleteError = KErrNone; |
|
110 TUint32 objectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
111 |
|
112 PRINT3( _L( "MM MTP <> CDeleteObject::ServiceL, objectHandle = 0x%x, numObject = %d, iDeleteError = %d" ), |
|
113 objectHandle, |
|
114 iObjectsToDelete.Count(), |
|
115 iDeleteError ); |
|
116 |
|
117 // Check to see whether the request is to delete all files or a specific file/directory |
|
118 if ( objectHandle == KMTPHandleAll ) |
|
119 { |
|
120 iIsMultiDelete = ETrue; |
|
121 // Get the complete list of all the media files that are to be deleted |
|
122 GetObjectHandlesL( KMTPStorageAll, KMTPHandleNoParent ); |
|
123 StartL(); |
|
124 } |
|
125 else |
|
126 { |
|
127 iIsMultiDelete = EFalse; |
|
128 // Not Owned the object |
|
129 // TODO: need to check if this is best way and if it is applicable to other processors |
|
130 CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( objectHandle ); |
|
131 |
|
132 if ( objectInfo->Uint( CMTPObjectMetaData::EFormatCode ) == EMTPFormatCodeAssociation ) |
|
133 { |
|
134 TUint parentHandle = objectInfo->Uint( CMTPObjectMetaData::EHandle ); |
|
135 GetObjectHandlesL( KMTPStorageAll, parentHandle ); |
|
136 if ( iObjectsToDelete.Count() > 0 ) |
|
137 iIsMultiDelete = ETrue; |
|
138 StartL(); |
|
139 } |
|
140 else |
|
141 { |
|
142 DeleteObjectL( *objectInfo ); |
|
143 ProcessFinalPhaseL(); |
|
144 } |
|
145 } |
|
146 |
|
147 PRINT( _L( "MM MTP <= CDeleteObject::ServiceL" ) ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // MTPDeleteObject::StartL |
|
152 // Control the deletion |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CDeleteObject::StartL() |
|
156 { |
|
157 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
|
158 PRINT2( _L( "MM MTP <> CDeleteObject::StartL, numObjectsToDelete = %d, iDeleteError = %d" ), |
|
159 numObjectsToDelete, |
|
160 iDeleteError ); |
|
161 |
|
162 TBool isOk = iDeleteError == KErrNone || iDeleteError == KErrNotFound; |
|
163 if ( numObjectsToDelete > 0 && isOk ) |
|
164 { |
|
165 //Set the active object going to delete the file |
|
166 TRequestStatus* status = &iStatus; |
|
167 User::RequestComplete( status, KErrNone ); |
|
168 SetActive(); |
|
169 } |
|
170 else |
|
171 { |
|
172 ProcessFinalPhaseL(); |
|
173 } |
|
174 PRINT( _L( "MM MTP <= CDeleteObject::StartL" ) ); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CDeleteObject::RunL |
|
179 // AO Run method, deletes a selection of files on the system |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 EXPORT_C void CDeleteObject::RunL() |
|
183 { |
|
184 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
|
185 PRINT1( _L( "MM MTP => CDeleteObject::RunL, numObjectsToDelete = %d" ), |
|
186 numObjectsToDelete ); |
|
187 |
|
188 if ( numObjectsToDelete > 0 ) |
|
189 { |
|
190 // Get the next object |
|
191 CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo |
|
192 |
|
193 TUint32 handle = iObjectsToDelete[0]; |
|
194 iObjectMgr.ObjectL( handle, *objectInfo ); |
|
195 TFileName fileName( objectInfo->DesC( CMTPObjectMetaData::ESuid ) ); |
|
196 PRINT2( _L( "MM MTP <> CDeleteObject::RunL delete object handle is 0x%x, fileName is %S" ), handle, &fileName ); |
|
197 |
|
198 if ( objectInfo->Uint( CMTPObjectMetaData::EFormatCode ) == EMTPFormatCodeAssociation ) |
|
199 { |
|
200 TUint parentHandle = objectInfo->Uint( CMTPObjectMetaData::EHandle ); |
|
201 GetObjectHandlesL( KMTPStorageAll, parentHandle ); |
|
202 } |
|
203 else |
|
204 { |
|
205 DeleteObjectL( *objectInfo ); |
|
206 } |
|
207 |
|
208 CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo |
|
209 |
|
210 iObjectsToDelete.Remove( 0 ); |
|
211 } |
|
212 |
|
213 // Start the process again to read the next row... |
|
214 StartL(); |
|
215 PRINT( _L( "MM MTP <= CDeleteObject::RunL" ) ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CDeleteObject::DeleteObjectL() |
|
220 // Deletes the object from the file system and the object from the store |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CDeleteObject::DeleteObjectL( const CMTPObjectMetaData& aObjectInfo ) |
|
224 { |
|
225 TFileName fileName( aObjectInfo.DesC( CMTPObjectMetaData::ESuid ) ); |
|
226 PRINT1( _L( "MM MTP <> CDeleteObject::DeleteObjectL fileName = %S" ), &fileName ); |
|
227 |
|
228 TParsePtrC parse( fileName ); |
|
229 iDpConfig.GetWrapperL().SetStorageRootL( parse.Drive() ); |
|
230 |
|
231 // To capture special situation: After copy, move, rename playlist folder name, |
|
232 // record in MPX is not inlined with framework db, playlist should not be deleted |
|
233 // until next session. |
|
234 // This is used to keep the same behavior in mass storage and device file manager. |
|
235 if ( aObjectInfo.Uint(CMTPObjectMetaData::EFormatCode ) |
|
236 == EMTPFormatCodeAbstractAudioVideoPlaylist |
|
237 && !iDpConfig.GetWrapperL().IsExistL( fileName ) ) |
|
238 { |
|
239 iDeleteError = KErrGeneral; |
|
240 PRINT( _L( "MM MTP <= CDeleteObject::DeleteObjectL playlist file not exist in the MPX DB" ) ); |
|
241 return; |
|
242 } |
|
243 |
|
244 // 1. Delete object from file system |
|
245 TEntry fileInfo; |
|
246 iFs.Entry( fileName, fileInfo ); |
|
247 if ( fileInfo.IsReadOnly() ) |
|
248 { |
|
249 iDeleteError = KErrAccessDenied; |
|
250 PRINT1( _L( "MM MTP <= CDeleteObject::DeleteObjectL, \"%S\" is a read-only file"), &fileName ); |
|
251 return; |
|
252 } |
|
253 iDeleteError = iFs.Delete( fileName ); |
|
254 if ( iDeleteError != KErrNone && iDeleteError != KErrNotFound ) |
|
255 { |
|
256 PRINT1( _L( "MM MTP <= CDeleteObject::DeleteObjectL, Delete from file system failed, err = %d" ), iDeleteError ); |
|
257 return; |
|
258 } |
|
259 |
|
260 // 2. Delete object from metadata db |
|
261 TRAP( iDeleteError, iDpConfig.GetWrapperL().DeleteObjectL( fileName, aObjectInfo.Uint( CMTPObjectMetaData::EFormatCode ) )); |
|
262 PRINT1( _L( "MM MTP <> CDeleteObject::DeleteObjectL, Delete from Media DB, err = %d" ), iDeleteError ); |
|
263 |
|
264 // 3. Delete object from framework db |
|
265 iObjectMgr.RemoveObjectL( aObjectInfo.Uint( CMTPObjectMetaData::EHandle ) ); |
|
266 |
|
267 PRINT( _L( "MM MTP <= CDeleteObject::DeleteObjectL" ) ); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CDeleteObject::DoCancel |
|
272 // Used to cancel the deletion of the files |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C void CDeleteObject::DoCancel() |
|
276 { |
|
277 TRAP_IGNORE( ProcessFinalPhaseL() ); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CDeleteObject::ProcessFinalPhaseL |
|
282 // Delete all of the associations if file deletion was successful |
|
283 // Then signals that the deletion has been completed |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CDeleteObject::ProcessFinalPhaseL() |
|
287 { |
|
288 PRINT( _L( "MM MTP => CDeleteObject::ProcessFinalPhaseL" ) ); |
|
289 |
|
290 TInt num = iObjectsToDelete.Count(); |
|
291 TBool isOk = iDeleteError == KErrNone || iDeleteError == KErrNotFound; |
|
292 |
|
293 if ( num == 0 && isOk ) |
|
294 { |
|
295 SendResponseL( EMTPRespCodeOK ); |
|
296 } |
|
297 else if ( iIsMultiDelete && !isOk ) |
|
298 { |
|
299 SendResponseL( EMTPRespCodePartialDeletion ); |
|
300 } |
|
301 else if( !iIsMultiDelete && iDeleteError == KErrAccessDenied ) |
|
302 { |
|
303 SendResponseL( EMTPRespCodeObjectWriteProtected ); |
|
304 } |
|
305 else |
|
306 { |
|
307 SendResponseL( EMTPRespCodeAccessDenied ); |
|
308 } |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CDeleteObject::GetObjectHandlesL |
|
313 // Gets all object handles (for GetObjectHandlesL) |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CDeleteObject::GetObjectHandlesL( TUint32 aStorageId, |
|
317 TUint32 aParentHandle ) |
|
318 { |
|
319 PRINT2( _L( "MM MTP => CDeleteObject::GetObjectHandlesL, StorageId = 0x%x, ParentHandle = 0x%x" ), |
|
320 aStorageId, aParentHandle ); |
|
321 RMTPObjectMgrQueryContext context; |
|
322 RArray<TUint> handles; |
|
323 CleanupClosePushL( context ); // + context |
|
324 CleanupClosePushL( handles ); // + handles |
|
325 |
|
326 TMTPObjectMgrQueryParams params( aStorageId, KMTPFormatsAll, aParentHandle ); |
|
327 |
|
328 do |
|
329 { |
|
330 iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles ); |
|
331 |
|
332 for ( TInt i = 0; i < handles.Count(); i++ ) |
|
333 { |
|
334 if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) |
|
335 == iFramework.DataProviderId() ) |
|
336 { |
|
337 iObjectsToDelete.Append( handles[i] ); |
|
338 } |
|
339 // TODO: should not know dp id of device dp, |
|
340 // else if ( iFramework.ObjectMgr().ObjectOwnerId( handles[i] ) == 0 ) // We know that the device dp id is always 0, otherwise the whole MTP won't work. |
|
341 // iParentHandles.AppendL( handles[i] ); |
|
342 else |
|
343 { |
|
344 CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo |
|
345 iObjectMgr.ObjectL( handles[i], *objectInfo ); |
|
346 if ( EMTPFormatCodeAssociation == objectInfo->Uint( CMTPObjectMetaData::EFormatCode ) ) |
|
347 { |
|
348 GetObjectHandlesL( KMTPStorageAll, handles[i] ); |
|
349 } |
|
350 CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo |
|
351 } |
|
352 } |
|
353 } |
|
354 while ( !context.QueryComplete() ); |
|
355 |
|
356 CleanupStack::PopAndDestroy( &handles ); // - handles |
|
357 CleanupStack::PopAndDestroy( &context ); // - context |
|
358 |
|
359 PRINT( _L( "MM MTP <= CDeleteObject::GetObjectHandlesL" ) ); |
|
360 } |
|
361 |
|
362 // end of file |