28 #include "mtpimagedpconst.h" |
28 #include "mtpimagedpconst.h" |
29 #include "mtpimagedppanic.h" |
29 #include "mtpimagedppanic.h" |
30 #include "cmtpimagedpobjectpropertymgr.h" |
30 #include "cmtpimagedpobjectpropertymgr.h" |
31 #include "mtpimagedputilits.h" |
31 #include "mtpimagedputilits.h" |
32 #include "cmtpimagedp.h" |
32 #include "cmtpimagedp.h" |
33 // Class constants. |
33 #include "OstTraceDefinitions.h" |
34 __FLOG_STMT(_LIT8(KComponent,"ImageDeleteObject");) |
34 #ifdef OST_TRACE_COMPILER_IN_USE |
|
35 #include "cmtpimagedpdeleteobjectTraces.h" |
|
36 #endif |
|
37 |
|
38 |
35 /** |
39 /** |
36 Standard c++ constructor |
40 Standard c++ constructor |
37 */ |
41 */ |
38 CMTPImageDpDeleteObject::CMTPImageDpDeleteObject( |
42 CMTPImageDpDeleteObject::CMTPImageDpDeleteObject( |
39 MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, |
43 MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, |
40 CMTPImageDataProvider& aDataProvider) : |
44 CMTPImageDataProvider& aDataProvider) : |
41 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
45 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
42 iDataProvider(aDataProvider), |
46 iDataProvider(aDataProvider), |
43 iResponseCode( EMTPRespCodeOK ) |
47 iResponseCode( EMTPRespCodeOK ) |
44 { |
48 { |
45 __FLOG_OPEN(KMTPSubsystem, KComponent); |
49 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_CMTPIMAGEDPDELETEOBJECT_CONS_ENTRY ); |
46 __FLOG(_L8(">> CMTPImageDpDeleteObject")); |
50 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_CMTPIMAGEDPDELETEOBJECT_CONS_EXIT ); |
47 __FLOG(_L8("<< CMTPImageDpDeleteObject")); |
|
48 } |
51 } |
49 |
52 |
50 /** |
53 /** |
51 Two-phase construction method |
54 Two-phase construction method |
52 @param aFramework The data provider framework |
55 @param aFramework The data provider framework |
65 return self; |
68 return self; |
66 } |
69 } |
67 |
70 |
68 void CMTPImageDpDeleteObject::ConstructL() |
71 void CMTPImageDpDeleteObject::ConstructL() |
69 { |
72 { |
70 __FLOG(_L8(">> CMTPImageDpDeleteObject::ConstructL")); |
73 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_CONSTRUCTL_ENTRY ); |
71 iObjectMeta = CMTPObjectMetaData::NewL(); |
74 iObjectMeta = CMTPObjectMetaData::NewL(); |
72 __FLOG(_L8("<< CMTPImageDpDeleteObject::ConstructL")); |
75 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_CONSTRUCTL_EXIT ); |
73 } |
76 } |
74 /** |
77 /** |
75 Destructor |
78 Destructor |
76 */ |
79 */ |
77 CMTPImageDpDeleteObject::~CMTPImageDpDeleteObject() |
80 CMTPImageDpDeleteObject::~CMTPImageDpDeleteObject() |
78 { |
81 { |
79 __FLOG(_L8("~CMTPImageDpDeleteObject - Entry")); |
82 OstTraceFunctionEntry0( DUP1_CMTPIMAGEDPDELETEOBJECT_CMTPIMAGEDPDELETEOBJECT_DES_ENTRY ); |
80 Cancel(); |
83 Cancel(); |
81 delete iObjectMeta; |
84 delete iObjectMeta; |
82 iObjectsToDelete.Close(); |
85 iObjectsToDelete.Close(); |
83 __FLOG(_L8("~CMTPImageDpDeleteObject - Exit")); |
86 OstTraceFunctionExit0( DUP1_CMTPIMAGEDPDELETEOBJECT_CMTPIMAGEDPDELETEOBJECT_DES_EXIT ); |
84 __FLOG_CLOSE; |
|
85 } |
87 } |
86 |
88 |
87 /** |
89 /** |
88 Verify the request |
90 Verify the request |
89 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
91 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
90 */ |
92 */ |
91 |
93 |
92 TMTPResponseCode CMTPImageDpDeleteObject::CheckRequestL() |
94 TMTPResponseCode CMTPImageDpDeleteObject::CheckRequestL() |
93 { |
95 { |
94 __FLOG(_L8(">> CMTPImageDpDeleteObject::CheckRequestL")); |
96 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_CHECKREQUESTL_ENTRY ); |
95 TMTPResponseCode result = EMTPRespCodeOK; |
97 TMTPResponseCode result = EMTPRespCodeOK; |
96 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
98 TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
97 if ( handle != KMTPHandleAll ) |
99 if ( handle != KMTPHandleAll ) |
98 { |
100 { |
99 result = CheckStorageL( handle ); |
101 result = CheckStorageL( handle ); |
100 } |
102 } |
101 __FLOG(_L8("<< CMTPImageDpDeleteObject::CheckRequestL")); |
103 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_CHECKREQUESTL_EXIT ); |
102 return result; |
104 return result; |
103 } |
105 } |
104 |
106 |
105 /** |
107 /** |
106 DeleteObject request handler |
108 DeleteObject request handler |
107 */ |
109 */ |
108 void CMTPImageDpDeleteObject::ServiceL() |
110 void CMTPImageDpDeleteObject::ServiceL() |
109 { |
111 { |
110 __FLOG(_L8(">> CMTPImageDpDeleteObject::ServiceL")); |
112 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_SERVICEL_ENTRY ); |
111 |
113 |
112 //begin to find object |
114 //begin to find object |
113 iObjectsToDelete.Reset(); |
115 iObjectsToDelete.Reset(); |
114 iResponseCode = EMTPRespCodeOK; |
116 iResponseCode = EMTPRespCodeOK; |
115 iObjectsNotDelete = 0; |
117 iObjectsNotDelete = 0; |
118 |
120 |
119 // Check to see whether the request is to delete all images or a specific image |
121 // Check to see whether the request is to delete all images or a specific image |
120 if ( objectHandle == KMTPHandleAll ) |
122 if ( objectHandle == KMTPHandleAll ) |
121 { |
123 { |
122 //add for test |
124 //add for test |
123 __FLOG(_L8("delete all objects")); |
125 OstTrace0( TRACE_FLOW, CMTPIMAGEDPDELETEOBJECT_SERVICEL, "delete all objects" ); |
124 GetObjectHandlesL( KMTPStorageAll, formatCode, KMTPHandleNone ); |
126 GetObjectHandlesL( KMTPStorageAll, formatCode, KMTPHandleNone ); |
125 iObjectsNotDelete = iObjectsToDelete.Count(); |
127 iObjectsNotDelete = iObjectsToDelete.Count(); |
126 StartL(); |
128 StartL(); |
127 } |
129 } |
128 else |
130 else |
129 { |
131 { |
130 //add for test |
132 //add for test |
131 __FLOG(_L8("delete only one object")); |
133 OstTrace0( TRACE_FLOW, DUP1_CMTPIMAGEDPDELETEOBJECT_SERVICEL, "delete only one object" ); |
132 iObjectsNotDelete = 1; |
134 iObjectsNotDelete = 1; |
133 DeleteObjectL( objectHandle ); |
135 DeleteObjectL( objectHandle ); |
134 |
136 |
135 SendResponseL(); |
137 SendResponseL(); |
136 } |
138 } |
137 |
139 |
138 __FLOG(_L8("<< CMTPImageDpDeleteObject::ServiceL")); |
140 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_SERVICEL_EXIT ); |
139 } |
141 } |
140 |
142 |
141 void CMTPImageDpDeleteObject::RunL() |
143 void CMTPImageDpDeleteObject::RunL() |
142 { |
144 { |
143 __FLOG(_L8(">> CMTPImageDpDeleteObject::RunL")); |
145 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_RUNL_ENTRY ); |
144 |
146 |
145 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
147 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
146 |
148 |
147 if ( numObjectsToDelete > 0 ) |
149 if ( numObjectsToDelete > 0 ) |
148 { |
150 { |
150 iObjectsToDelete.Remove( 0 ); |
152 iObjectsToDelete.Remove( 0 ); |
151 } |
153 } |
152 |
154 |
153 // Start the process again to read the next row... |
155 // Start the process again to read the next row... |
154 StartL(); |
156 StartL(); |
155 |
157 |
156 __FLOG(_L8("<< CMTPImageDpDeleteObject::RunL")); |
158 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_RUNL_EXIT ); |
157 } |
159 } |
158 |
160 |
159 void CMTPImageDpDeleteObject::DoCancel() |
161 void CMTPImageDpDeleteObject::DoCancel() |
160 { |
162 { |
161 __FLOG(_L8(">> CMTPImageDpDeleteObject::DoCancel")); |
163 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_DOCANCEL_ENTRY ); |
162 |
164 |
163 TRAP_IGNORE( SendResponseL()); |
165 TRAP_IGNORE( SendResponseL()); |
164 |
166 |
165 __FLOG(_L8("<< CMTPImageDpDeleteObject::DoCancel")); |
167 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_DOCANCEL_EXIT ); |
166 } |
168 } |
167 |
169 |
168 /** |
170 /** |
169 Check whether the store on which the object resides is read only. |
171 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 |
172 @return ETrue if the store is read only, EFalse if read-write |
171 */ |
173 */ |
172 TMTPResponseCode CMTPImageDpDeleteObject::CheckStorageL(TUint32 aObjectHandle) |
174 TMTPResponseCode CMTPImageDpDeleteObject::CheckStorageL(TUint32 aObjectHandle) |
173 { |
175 { |
174 __FLOG(_L8(">> CMTPImageDpDeleteObject::CheckStorageL")); |
176 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_CHECKSTORAGEL_ENTRY ); |
175 TMTPResponseCode result = MTPImageDpUtilits::VerifyObjectHandleL( |
177 TMTPResponseCode result = MTPImageDpUtilits::VerifyObjectHandleL( |
176 iFramework, aObjectHandle, *iObjectMeta); |
178 iFramework, aObjectHandle, *iObjectMeta); |
177 if (EMTPRespCodeOK == result) |
179 if (EMTPRespCodeOK == result) |
178 { |
180 { |
179 TDriveNumber drive= static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber( |
181 TDriveNumber drive= static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber( |
180 iObjectMeta->Uint(CMTPObjectMetaData::EStorageId))); |
182 iObjectMeta->Uint(CMTPObjectMetaData::EStorageId))); |
181 User::LeaveIfError(drive); |
183 LEAVEIFERROR(drive, |
|
184 OstTraceExt2( TRACE_ERROR, CMTPIMAGEDPDELETEOBJECT_CHECKSTORAGEL, |
|
185 "No driver number for %d! error code %d",iObjectMeta->Uint(CMTPObjectMetaData::EStorageId), munged_err)); |
182 TVolumeInfo volumeInfo; |
186 TVolumeInfo volumeInfo; |
183 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
187 LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive), |
|
188 OstTraceExt2( TRACE_ERROR, DUP1_CMTPIMAGEDPDELETEOBJECT_CHECKSTORAGEL, |
|
189 "Gets volume information for driver %d failed! error code %d", drive, munged_err )); |
184 if (volumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected) |
190 if (volumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected) |
185 { |
191 { |
186 result = EMTPRespCodeStoreReadOnly; |
192 result = EMTPRespCodeStoreReadOnly; |
187 } |
193 } |
188 } |
194 } |
189 __FLOG(_L8("<< CMTPImageDpDeleteObject::CheckStorageL")); |
195 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_CHECKSTORAGEL_EXIT ); |
190 return result; |
196 return result; |
191 } |
197 } |
192 |
198 |
193 void CMTPImageDpDeleteObject::GetObjectHandlesL( TUint32 aStorageId, TUint32 aFormatCode, TUint32 aParentHandle ) |
199 void CMTPImageDpDeleteObject::GetObjectHandlesL( TUint32 aStorageId, TUint32 aFormatCode, TUint32 aParentHandle ) |
194 { |
200 { |
195 __FLOG(_L8(">> CMTPImageDpDeleteObject::GetObjectHandlesL")); |
201 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_GETOBJECTHANDLESL_ENTRY ); |
196 |
202 |
197 RMTPObjectMgrQueryContext context; |
203 RMTPObjectMgrQueryContext context; |
198 RArray<TUint> handles; |
204 RArray<TUint> handles; |
199 TMTPObjectMgrQueryParams params( aStorageId, aFormatCode, aParentHandle, iFramework.DataProviderId()); |
205 TMTPObjectMgrQueryParams params( aStorageId, aFormatCode, aParentHandle, iFramework.DataProviderId()); |
200 CleanupClosePushL( context ); // + context |
206 CleanupClosePushL( context ); // + context |
201 CleanupClosePushL( handles ); // + handles |
207 CleanupClosePushL( handles ); // + handles |
210 } |
216 } |
211 while ( !context.QueryComplete() ); |
217 while ( !context.QueryComplete() ); |
212 |
218 |
213 CleanupStack::PopAndDestroy( &handles ); // - handles |
219 CleanupStack::PopAndDestroy( &handles ); // - handles |
214 CleanupStack::PopAndDestroy( &context ); // - context |
220 CleanupStack::PopAndDestroy( &context ); // - context |
215 |
221 |
216 __FLOG(_L8("<< CMTPImageDpDeleteObject::GetObjectHandlesL")); |
222 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_GETOBJECTHANDLESL_EXIT ); |
217 } |
223 } |
218 |
224 |
219 void CMTPImageDpDeleteObject::DeleteObjectL( TUint32 aHandle ) |
225 void CMTPImageDpDeleteObject::DeleteObjectL( TUint32 aHandle ) |
220 { |
226 { |
221 __FLOG(_L8(">> CMTPImageDpDeleteObject::DeleteObjectL")); |
227 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL_ENTRY ); |
222 |
228 |
223 iFramework.ObjectMgr().ObjectL( aHandle, *iObjectMeta); |
229 iFramework.ObjectMgr().ObjectL( aHandle, *iObjectMeta); |
224 iDataProvider.PropertyMgr().SetCurrentObjectL(*iObjectMeta, EFalse); |
230 iDataProvider.PropertyMgr().SetCurrentObjectL(*iObjectMeta, EFalse); |
225 TUint16 protectionStatus = EMTPProtectionNoProtection; |
231 TUint16 protectionStatus = EMTPProtectionNoProtection; |
226 iDataProvider.PropertyMgr().GetPropertyL(EMTPObjectPropCodeProtectionStatus, protectionStatus); |
232 iDataProvider.PropertyMgr().GetPropertyL(EMTPObjectPropCodeProtectionStatus, protectionStatus); |
227 if(EMTPProtectionNoProtection == protectionStatus) |
233 if(EMTPProtectionNoProtection == protectionStatus) |
228 { |
234 { |
229 TInt err = iFramework.Fs().Delete(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
235 TInt err = iFramework.Fs().Delete(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
230 __FLOG_1(_L8("delete file error is %d"), err ); |
236 OstTrace1( TRACE_FLOW, CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL, "delete file error is %d", err ); |
231 switch ( err ) |
237 switch ( err ) |
232 { |
238 { |
233 case KErrInUse: |
239 case KErrInUse: |
234 //coverity[fallthrough] |
240 //coverity[fallthrough] |
235 case KErrAccessDenied: |
241 case KErrAccessDenied: |
236 //add for test |
242 //add for test |
237 __FLOG_1(_L8("err:%d"), err); |
243 OstTrace1( TRACE_FLOW, DUP1_CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL, "err:%d", err ); |
238 //add Suid to deleteobjectlist |
244 //add Suid to deleteobjectlist |
239 iDataProvider.AppendDeleteObjectsArrayL(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
245 iDataProvider.AppendDeleteObjectsArrayL(iObjectMeta->DesC(CMTPObjectMetaData::ESuid)); |
240 //coverity[unterminated_case] |
246 //coverity[unterminated_case] |
241 case KErrPathNotFound: |
247 case KErrPathNotFound: |
242 //if the file does not exist on device, remove it from objectstore |
248 //if the file does not exist on device, remove it from objectstore |
243 //coverity[fallthrough] |
249 //coverity[fallthrough] |
244 case KErrNone: |
250 case KErrNone: |
245 //add for test |
251 //add for test |
246 __FLOG(_L8("KErrNone")); |
252 OstTrace0( TRACE_NORMAL, DUP2_CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL, "KErrNone" ); |
247 //if the image object is new, we should update new picture count |
253 //if the image object is new, we should update new picture count |
248 if (MTPImageDpUtilits::IsNewPicture(*iObjectMeta)) |
254 if (MTPImageDpUtilits::IsNewPicture(*iObjectMeta)) |
249 { |
255 { |
250 iDataProvider.DecreaseNewPictures(1); |
256 iDataProvider.DecreaseNewPictures(1); |
251 } |
257 } |
253 iObjectsNotDelete--; |
259 iObjectsNotDelete--; |
254 iResponseCode = EMTPRespCodePartialDeletion; |
260 iResponseCode = EMTPRespCodePartialDeletion; |
255 break; |
261 break; |
256 default: |
262 default: |
257 //add for test |
263 //add for test |
258 __FLOG(_L8("default")); |
264 OstTrace0( TRACE_NORMAL, DUP3_CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL, "default" ); |
259 User::LeaveIfError( err ); |
265 LEAVEIFERROR( err, |
|
266 OstTraceExt2( TRACE_ERROR, DUP4_CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL, |
|
267 "delete %S failed! error code %d", iObjectMeta->DesC(CMTPObjectMetaData::ESuid), munged_err)); |
260 break; |
268 break; |
261 } |
269 } |
262 } |
270 } |
263 else if ( iResponseCode != EMTPRespCodePartialDeletion ) |
271 else if ( iResponseCode != EMTPRespCodePartialDeletion ) |
264 { |
272 { |
265 iResponseCode = EMTPRespCodeObjectWriteProtected; |
273 iResponseCode = EMTPRespCodeObjectWriteProtected; |
266 } |
274 } |
267 __FLOG(_L8("<< CMTPImageDpDeleteObject::DeleteObjectL")); |
275 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_DELETEOBJECTL_EXIT ); |
268 } |
276 } |
269 |
277 |
270 void CMTPImageDpDeleteObject::StartL() |
278 void CMTPImageDpDeleteObject::StartL() |
271 { |
279 { |
272 __FLOG(_L8(">> CMTPImageDpDeleteObject::StartL")); |
280 OstTraceFunctionEntry0( CMTPIMAGEDPDELETEOBJECT_STARTL_ENTRY ); |
273 |
281 |
274 if(iCancelled) |
282 if(iCancelled) |
275 { |
283 { |
276 __FLOG(_L8("Cancell the delete")); |
284 OstTrace0( TRACE_NORMAL, CMTPIMAGEDPDELETEOBJECT_STARTL, "Cancell the delete" ); |
277 CMTPRequestProcessor::SendResponseL(EMTPRespCodeTransactionCancelled); |
285 CMTPRequestProcessor::SendResponseL(EMTPRespCodeTransactionCancelled); |
278 iObjectsToDelete.Reset(); |
286 iObjectsToDelete.Reset(); |
279 iCancelled = EFalse; |
287 iCancelled = EFalse; |
|
288 OstTraceFunctionExit0( CMTPIMAGEDPDELETEOBJECT_STARTL_EXIT ); |
280 return; |
289 return; |
281 } |
290 } |
282 |
291 |
283 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
292 TInt numObjectsToDelete = iObjectsToDelete.Count(); |
284 |
293 |