|
1 // Copyright (c) 2006-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 #include <mtp/cmtpobjectmetadata.h> |
|
17 #include <mtp/cmtpstoragemetadata.h> |
|
18 #include <mtp/mmtpdataproviderframework.h> |
|
19 #include <mtp/mtpprotocolconstants.h> |
|
20 #include <mtp/tmtptyperequest.h> |
|
21 #include <mtp/cmtptypearray.h> |
|
22 |
|
23 #include "cmtpdataprovider.h" |
|
24 #include "cmtpdataprovidercontroller.h" |
|
25 #include "cmtpdeleteobject.h" |
|
26 #include "cmtpobjectmgr.h" |
|
27 #include "cmtpparserrouter.h" |
|
28 #include "cmtpstoragemgr.h" |
|
29 #include "mtpproxydppanic.h" |
|
30 #include "rmtpframework.h" |
|
31 #include "cmtpobjectbrowser.h" |
|
32 #include "mtpdppanic.h" |
|
33 |
|
34 __FLOG_STMT( _LIT8( KComponent,"PrxyDelObj" ); ) |
|
35 const TUint KInvalidDpId = 0xFF; |
|
36 |
|
37 /** |
|
38 Two-phase construction method |
|
39 @param aFramework The data provider framework |
|
40 @param aConnection The connection from which the request comes |
|
41 @return a pointer to the created request processor object |
|
42 */ |
|
43 MMTPRequestProcessor* CMTPDeleteObject::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
44 { |
|
45 CMTPDeleteObject* self = new (ELeave) CMTPDeleteObject(aFramework, aConnection); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 /** |
|
53 Destructor |
|
54 */ |
|
55 CMTPDeleteObject::~CMTPDeleteObject() |
|
56 { |
|
57 iSingletons.Close(); |
|
58 iTargetDps.Close(); |
|
59 iHandles.Close(); |
|
60 delete iObjBrowser; |
|
61 |
|
62 __FLOG( _L8("+/-Dtor") ); |
|
63 __FLOG_CLOSE; |
|
64 } |
|
65 |
|
66 /** |
|
67 Constructor |
|
68 */ |
|
69 CMTPDeleteObject::CMTPDeleteObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
70 CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
71 iDeletedObjectsNumber(0) |
|
72 { |
|
73 __FLOG_OPEN( KMTPSubsystem, KComponent ); |
|
74 __FLOG( _L8("+/-Ctor") ); |
|
75 } |
|
76 |
|
77 /** |
|
78 Second phase constructor. |
|
79 */ |
|
80 void CMTPDeleteObject::ConstructL() |
|
81 { |
|
82 __FLOG( _L8("+ConstructL") ); |
|
83 |
|
84 iSingletons.OpenL(); |
|
85 iOwnerDp = KInvalidDpId; |
|
86 __FLOG( _L8("-ConstructL") ); |
|
87 } |
|
88 |
|
89 /** |
|
90 DeleteObject request handler |
|
91 */ |
|
92 void CMTPDeleteObject::ServiceL() |
|
93 { |
|
94 __FLOG( _L8("+ServiceL") ); |
|
95 iTargetDps.Reset(); |
|
96 CMTPParserRouter& router(iSingletons.Router()); |
|
97 CMTPParserRouter::TRoutingParameters params(Request(), iConnection); |
|
98 router.ParseOperationRequestL(params); |
|
99 router.RouteOperationRequestL(params, iTargetDps); |
|
100 |
|
101 BrowseHandlesL(); |
|
102 |
|
103 __FLOG( _L8("-ServiceL") ); |
|
104 } |
|
105 |
|
106 void CMTPDeleteObject::ProxyReceiveDataL(MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
107 { |
|
108 Panic(EMTPWrongRequestPhase); |
|
109 } |
|
110 |
|
111 void CMTPDeleteObject::ProxySendDataL(const MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
112 { |
|
113 Panic(EMTPWrongRequestPhase); |
|
114 } |
|
115 |
|
116 #ifdef _DEBUG |
|
117 void CMTPDeleteObject::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
118 #else |
|
119 void CMTPDeleteObject::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
120 #endif |
|
121 { |
|
122 __ASSERT_DEBUG(( ( (iRequest == &aRequest) || ( &iCurrentRequest == &aRequest ) ) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
123 MMTPType::CopyL(aResponse, iResponse); |
|
124 TRequestStatus* status = &aStatus; |
|
125 User::RequestComplete(status, KErrNone); |
|
126 } |
|
127 |
|
128 #ifdef _DEBUG |
|
129 void CMTPDeleteObject::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
130 #else |
|
131 void CMTPDeleteObject::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/) |
|
132 #endif |
|
133 { |
|
134 __ASSERT_DEBUG(( ( (iRequest == &aRequest) || ( &iCurrentRequest == &aRequest ) ) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
135 TInt err(KErrNone); |
|
136 TUint16 responseCode = iResponse.Uint16(TMTPTypeResponse::EResponseCode); |
|
137 |
|
138 //Delete one object successfully |
|
139 if (responseCode == EMTPRespCodeOK) |
|
140 { |
|
141 ++iDeletedObjectsNumber; |
|
142 } |
|
143 //if object is write-protected or assocation object is not empty, we continue to schedule the AO to delete the |
|
144 //following objects. If it is not the 2 cases, just schedule with KErrGeneral so that we can sendresponse directly |
|
145 //in RunL |
|
146 else if (responseCode != EMTPRespCodeObjectWriteProtected && responseCode != EMTPRespCodeAccessDenied) |
|
147 { |
|
148 err = KErrGeneral; |
|
149 } |
|
150 |
|
151 ++iCurrentHandle; |
|
152 Schedule(err); |
|
153 } |
|
154 |
|
155 void CMTPDeleteObject::RunL() |
|
156 { |
|
157 __FLOG( _L8("+RunL") ); |
|
158 |
|
159 if ( iStatus == KErrNone ) |
|
160 { |
|
161 NextObjectHandleL(); |
|
162 if ( iOwnerDp != KInvalidDpId ) |
|
163 { |
|
164 CMTPDataProvider& dp = iSingletons.DpController().DataProviderL( iOwnerDp ); |
|
165 dp.ExecuteProxyRequestL( iCurrentRequest, Connection(), *this ); |
|
166 } |
|
167 } |
|
168 else |
|
169 { |
|
170 SendResponseL( iResponse.Uint16( TMTPTypeResponse::EResponseCode ) ); |
|
171 } |
|
172 |
|
173 __FLOG( _L8("-RunL") ); |
|
174 } |
|
175 |
|
176 /** |
|
177 Completes the current asynchronous request with the specified |
|
178 completion code. |
|
179 @param aError The asynchronous request completion request. |
|
180 */ |
|
181 void CMTPDeleteObject::Schedule(TInt aError) |
|
182 { |
|
183 TRequestStatus* status = &iStatus; |
|
184 User::RequestComplete(status, aError); |
|
185 SetActive(); |
|
186 } |
|
187 |
|
188 /** |
|
189 Sends a response to the initiator. |
|
190 @param aCode MTP response code |
|
191 */ |
|
192 void CMTPDeleteObject::SendResponseL(TUint16 aCode) |
|
193 { |
|
194 const TMTPTypeRequest& req(Request()); |
|
195 iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aCode); |
|
196 iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, req.Uint32(TMTPTypeRequest::ERequestSessionID)); |
|
197 iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, req.Uint32(TMTPTypeRequest::ERequestTransactionID)); |
|
198 iFramework.SendResponseL(iResponse, req, Connection()); |
|
199 } |
|
200 |
|
201 void CMTPDeleteObject::BrowseHandlesL() |
|
202 { |
|
203 __FLOG( _L8("+BrowseHandlesL") ); |
|
204 |
|
205 delete iObjBrowser; |
|
206 iObjBrowser = NULL; |
|
207 iObjBrowser = CMTPObjectBrowser::NewL( iFramework ); |
|
208 |
|
209 iHandles.Reset(); |
|
210 iCurrentHandle = 0; |
|
211 iDeletedObjectsNumber = 0; |
|
212 MMTPType::CopyL( Request(), iCurrentRequest ); |
|
213 |
|
214 CMTPObjectBrowser::TBrowseCallback callback = { CMTPDeleteObject::OnBrowseObjectL, this }; |
|
215 TUint32 handle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
216 TUint32 fmtCode = KMTPFormatsAll; |
|
217 if ( KMTPHandleAll == handle ) |
|
218 { |
|
219 fmtCode= Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
220 } |
|
221 iObjBrowser->GoL( fmtCode, handle, KMaxTUint32, callback ); |
|
222 |
|
223 if ( 0 == iHandles.Count() ) |
|
224 { |
|
225 SendResponseL( EMTPRespCodeOK ); |
|
226 } |
|
227 else |
|
228 { |
|
229 Schedule( KErrNone ); |
|
230 } |
|
231 |
|
232 __FLOG( _L8("-BrowseHandlesL") ); |
|
233 } |
|
234 |
|
235 void CMTPDeleteObject::NextObjectHandleL() |
|
236 { |
|
237 __FLOG( _L8("+NextObjectHandleL") ); |
|
238 |
|
239 iOwnerDp = KInvalidDpId; |
|
240 if ( iCurrentHandle < iHandles.Count() ) |
|
241 { |
|
242 TUint32 handle = iHandles[iCurrentHandle]; |
|
243 iOwnerDp = iSingletons.ObjectMgr().ObjectOwnerId( handle ); |
|
244 if ( iOwnerDp == KInvalidDpId ) |
|
245 { |
|
246 SendResponseL(EMTPRespCodeInvalidObjectHandle); |
|
247 } |
|
248 else |
|
249 { |
|
250 iCurrentRequest.SetUint32( TMTPTypeRequest::ERequestParameter1, handle ); |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 if (iDeletedObjectsNumber == iHandles.Count()) |
|
256 { |
|
257 SendResponseL(EMTPRespCodeOK); |
|
258 } |
|
259 else if (iDeletedObjectsNumber == 0) |
|
260 { |
|
261 SendResponseL(EMTPRespCodeObjectWriteProtected); |
|
262 } |
|
263 else |
|
264 { |
|
265 SendResponseL(EMTPRespCodePartialDeletion); |
|
266 } |
|
267 } |
|
268 |
|
269 __FLOG( _L8("-NextObjectHandleL") ); |
|
270 } |
|
271 |
|
272 void CMTPDeleteObject::OnBrowseObjectL( TAny* aSelf, TUint aHandle, TUint32 /*aCurDepth*/ ) |
|
273 { |
|
274 CMTPDeleteObject* self = reinterpret_cast< CMTPDeleteObject* >( aSelf ); |
|
275 if ( self->iTargetDps.Find(self->iSingletons.ObjectMgr().ObjectOwnerId(aHandle)) != KErrNotFound ) |
|
276 { |
|
277 self->iHandles.AppendL( aHandle ); |
|
278 } |
|
279 } |
|
280 |