|
1 // Copyright (c) 2007-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/cmtptypearray.h> |
|
17 |
|
18 #include "cmtpdataprovider.h" |
|
19 #include "cmtpcopyobject.h" |
|
20 #include "cmtpparserrouter.h" |
|
21 #include "mtpproxydppanic.h" |
|
22 #include "cmtpobjectbrowser.h" |
|
23 #include "mtpdppanic.h" |
|
24 #include "cmtpobjectmgr.h" |
|
25 |
|
26 __FLOG_STMT( _LIT8( KComponent,"PrxyCopyObj" ); ) |
|
27 const TUint KInvalidDpId = 0xFF; |
|
28 |
|
29 /** |
|
30 Two-phase construction method |
|
31 @param aFramework The data provider framework |
|
32 @param aConnection The connection from which the request comes |
|
33 @return a pointer to the created request processor object |
|
34 */ |
|
35 MMTPRequestProcessor* CMTPCopyObject::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
36 { |
|
37 CMTPCopyObject* self = new (ELeave) CMTPCopyObject(aFramework, aConnection); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 /** |
|
45 Destructor |
|
46 */ |
|
47 CMTPCopyObject::~CMTPCopyObject() |
|
48 { |
|
49 iSingletons.Close(); |
|
50 iTargetDps.Close(); |
|
51 iNewHandleParentStack.Close(); |
|
52 iHandleDepths.Close(); |
|
53 iHandles.Close(); |
|
54 delete iObjBrowser; |
|
55 |
|
56 __FLOG( _L8("+/-Dtor") ); |
|
57 __FLOG_CLOSE; |
|
58 } |
|
59 |
|
60 /** |
|
61 Constructor |
|
62 */ |
|
63 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
64 CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
65 { |
|
66 __FLOG_OPEN( KMTPSubsystem, KComponent ); |
|
67 __FLOG( _L8("+/-Ctor") ); |
|
68 } |
|
69 |
|
70 /** |
|
71 Second phase constructor. |
|
72 */ |
|
73 void CMTPCopyObject::ConstructL() |
|
74 { |
|
75 __FLOG( _L8("+ConstructL") ); |
|
76 iSingletons.OpenL(); |
|
77 iOwnerDp = KInvalidDpId; |
|
78 __FLOG( _L8("-ConstructL") ); |
|
79 } |
|
80 |
|
81 /** |
|
82 DeleteObject request handler |
|
83 */ |
|
84 void CMTPCopyObject::ServiceL() |
|
85 { |
|
86 __FLOG( _L8("+ServiceL") ); |
|
87 iTargetDps.Reset(); |
|
88 CMTPParserRouter& router(iSingletons.Router()); |
|
89 CMTPParserRouter::TRoutingParameters params(Request(), iConnection); |
|
90 router.ParseOperationRequestL(params); |
|
91 router.RouteOperationRequestL(params, iTargetDps); |
|
92 |
|
93 BrowseHandlesL(); |
|
94 |
|
95 __FLOG( _L8("-ServiceL") ); |
|
96 } |
|
97 |
|
98 void CMTPCopyObject::ProxyReceiveDataL(MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
99 { |
|
100 Panic(EMTPWrongRequestPhase); |
|
101 } |
|
102 |
|
103 void CMTPCopyObject::ProxySendDataL(const MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
104 { |
|
105 Panic(EMTPWrongRequestPhase); |
|
106 } |
|
107 |
|
108 #ifdef _DEBUG |
|
109 void CMTPCopyObject::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
110 #else |
|
111 void CMTPCopyObject::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
112 #endif |
|
113 { |
|
114 __FLOG( _L8("+ProxySendResponseL") ); |
|
115 __ASSERT_DEBUG(((&iCurrentRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
116 |
|
117 if ( aStatus == KErrNone ) |
|
118 { |
|
119 if ( iIsCopyingFolder ) |
|
120 { |
|
121 iNewHandleParentStack.AppendL( aResponse.Uint32( TMTPTypeResponse::EResponseParameter1 ) ); |
|
122 } |
|
123 if ( KMTPHandleNone == iRespHandle ) |
|
124 { |
|
125 iRespHandle = aResponse.Uint32( TMTPTypeResponse::EResponseParameter1 ); |
|
126 } |
|
127 } |
|
128 |
|
129 MMTPType::CopyL(aResponse, iResponse); |
|
130 TRequestStatus* status = &aStatus; |
|
131 User::RequestComplete(status, KErrNone); |
|
132 __FLOG( _L8("-ProxySendResponseL") ); |
|
133 } |
|
134 |
|
135 #ifdef _DEBUG |
|
136 void CMTPCopyObject::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
137 #else |
|
138 void CMTPCopyObject::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/) |
|
139 #endif |
|
140 { |
|
141 __FLOG( _L8("+ProxyTransactionCompleteL") ); |
|
142 __ASSERT_DEBUG(((&iCurrentRequest == &aRequest) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
143 TInt err((iResponse.Uint16(TMTPTypeResponse::EResponseCode) == EMTPRespCodeOK) ? KErrNone : KErrGeneral); |
|
144 if (err == KErrNone) |
|
145 { |
|
146 iCurrentHandle--; |
|
147 Schedule(err); |
|
148 } |
|
149 else |
|
150 { |
|
151 SendResponseL( iResponse.Uint16( TMTPTypeResponse::EResponseCode ) ); |
|
152 } |
|
153 __FLOG( _L8("-ProxyTransactionCompleteL") ); |
|
154 } |
|
155 |
|
156 void CMTPCopyObject::RunL() |
|
157 { |
|
158 __FLOG( _L8("+RunL") ); |
|
159 |
|
160 __FLOG_1( _L8("iStatus == %d"), iStatus.Int() ); |
|
161 |
|
162 if ( iStatus == KErrNone ) |
|
163 { |
|
164 NextObjectHandleL(); |
|
165 if ( iOwnerDp != KInvalidDpId ) |
|
166 { |
|
167 CMTPDataProvider& dp = iSingletons.DpController().DataProviderL( iOwnerDp ); |
|
168 dp.ExecuteProxyRequestL( iCurrentRequest, Connection(), *this ); |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 SendResponseL( iResponse.Uint16( TMTPTypeResponse::EResponseCode ) ); |
|
174 } |
|
175 __FLOG( _L8("-RunL") ); |
|
176 } |
|
177 |
|
178 TInt CMTPCopyObject::RunError(TInt /*aError*/) |
|
179 { |
|
180 TRAP_IGNORE(SendResponseL(EMTPRespCodeGeneralError)); |
|
181 return KErrNone; |
|
182 } |
|
183 |
|
184 /** |
|
185 Completes the current asynchronous request with the specified |
|
186 completion code. |
|
187 @param aError The asynchronous request completion request. |
|
188 */ |
|
189 void CMTPCopyObject::Schedule(TInt aError) |
|
190 { |
|
191 TRequestStatus* status = &iStatus; |
|
192 User::RequestComplete(status, aError); |
|
193 SetActive(); |
|
194 } |
|
195 |
|
196 /** |
|
197 Sends a response to the initiator. |
|
198 @param aCode MTP response code |
|
199 */ |
|
200 void CMTPCopyObject::SendResponseL(TUint16 aCode) |
|
201 { |
|
202 const TMTPTypeRequest& req(Request()); |
|
203 iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aCode); |
|
204 iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, req.Uint32(TMTPTypeRequest::ERequestSessionID)); |
|
205 iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, req.Uint32(TMTPTypeRequest::ERequestTransactionID)); |
|
206 iFramework.SendResponseL(iResponse, req, Connection()); |
|
207 } |
|
208 |
|
209 void CMTPCopyObject::BrowseHandlesL() |
|
210 { |
|
211 __FLOG( _L8("+BrowseHandlesL") ); |
|
212 |
|
213 delete iObjBrowser; |
|
214 iObjBrowser = NULL; |
|
215 iObjBrowser = CMTPObjectBrowser::NewL( iFramework ); |
|
216 |
|
217 iHandles.Reset(); |
|
218 iHandleDepths.Reset(); |
|
219 iNewHandleParentStack.Reset(); |
|
220 |
|
221 iRespHandle = KMTPHandleNone; |
|
222 |
|
223 MMTPType::CopyL( Request(), iCurrentRequest ); |
|
224 |
|
225 CMTPObjectBrowser::TBrowseCallback callback = { CMTPCopyObject::OnBrowseObjectL, this }; |
|
226 TUint32 handle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
227 TUint32 newHandleParent = Request().Uint32( TMTPTypeRequest::ERequestParameter3 ); |
|
228 iNewHandleParentStack.AppendL( newHandleParent ); |
|
229 iObjBrowser->GoL( KMTPFormatsAll, handle, KMaxTUint32, callback ); |
|
230 __FLOG_1( _L8("iHandles.Count() = %d"), iHandles.Count() ); |
|
231 |
|
232 if ( iHandles.Count() > 0 ) |
|
233 { |
|
234 iCurrentHandle = iHandles.Count() - 1; |
|
235 Schedule( KErrNone ); |
|
236 } |
|
237 else |
|
238 { |
|
239 SendResponseL( EMTPRespCodeInvalidObjectHandle ); |
|
240 } |
|
241 |
|
242 __FLOG( _L8("-BrowseHandlesL") ); |
|
243 } |
|
244 |
|
245 void CMTPCopyObject::NextObjectHandleL() |
|
246 { |
|
247 __FLOG( _L8("+NextObjectHandleL") ); |
|
248 __ASSERT_DEBUG( ( iNewHandleParentStack.Count() > 0 ), User::Invariant() ); |
|
249 iOwnerDp = KInvalidDpId; |
|
250 if ( iCurrentHandle >=0 ) |
|
251 { |
|
252 __FLOG_1( _L8("iCurrentHandle = %d"), iCurrentHandle ); |
|
253 TUint32 handle = iHandles[iCurrentHandle]; |
|
254 TUint32 depth = iHandleDepths[iCurrentHandle]; |
|
255 __FLOG_1( _L8("depth = %d"), depth ); |
|
256 if ( iCurrentHandle != ( iHandles.Count() - 1 ) ) |
|
257 { |
|
258 TUint32 previousDepth = iHandleDepths[iCurrentHandle+1]; |
|
259 __FLOG_1( _L8("previousDepth = %d"), previousDepth ); |
|
260 if ( depth < previousDepth ) |
|
261 { |
|
262 // Completed copying folder and all its sub-folder and files, pop all copied folders' handle which are not shallower than the current one. |
|
263 |
|
264 // Step 1: pop the previous handle itself if it is am empty folder |
|
265 if ( iIsCopyingFolder ) |
|
266 { |
|
267 iNewHandleParentStack.Remove( iNewHandleParentStack.Count() - 1 ); |
|
268 } |
|
269 // Step 2: pop the other folders' handle which are not shallower than the current one |
|
270 TUint32 loopCount = previousDepth - depth; |
|
271 for ( TUint i = 0; i < loopCount; i++ ) |
|
272 { |
|
273 iNewHandleParentStack.Remove( iNewHandleParentStack.Count() - 1 ); |
|
274 } |
|
275 } |
|
276 else if ( ( depth == previousDepth ) && iIsCopyingFolder ) |
|
277 { |
|
278 // Completed copying empty folder, pop its handle |
|
279 iNewHandleParentStack.Remove( iNewHandleParentStack.Count() - 1 ); |
|
280 } |
|
281 } |
|
282 |
|
283 iIsCopyingFolder = EFalse; |
|
284 iOwnerDp = iSingletons.ObjectMgr().ObjectOwnerId( handle ); |
|
285 if ( iOwnerDp == KInvalidDpId ) |
|
286 { |
|
287 SendResponseL( EMTPRespCodeInvalidObjectHandle ); |
|
288 } |
|
289 else |
|
290 { |
|
291 iCurrentRequest.SetUint32( TMTPTypeRequest::ERequestParameter1, handle ); |
|
292 iCurrentRequest.SetUint32( TMTPTypeRequest::ERequestParameter3, iNewHandleParentStack[iNewHandleParentStack.Count()-1] ); |
|
293 } |
|
294 if ( iOwnerDp==iSingletons.DpController().DeviceDpId() ) |
|
295 { |
|
296 iIsCopyingFolder = ETrue; |
|
297 } |
|
298 } |
|
299 else |
|
300 { |
|
301 iResponse.SetUint32( TMTPTypeResponse::EResponseParameter1, iRespHandle ); |
|
302 SendResponseL( iResponse.Uint16( TMTPTypeResponse::EResponseCode ) ); |
|
303 } |
|
304 |
|
305 __FLOG( _L8("-NextObjectHandleL") ); |
|
306 } |
|
307 |
|
308 void CMTPCopyObject::OnBrowseObjectL( TAny* aSelf, TUint aHandle, TUint32 aCurDepth ) |
|
309 { |
|
310 CMTPCopyObject* self = reinterpret_cast< CMTPCopyObject* >( aSelf ); |
|
311 if ( self->iTargetDps.Find(self->iSingletons.ObjectMgr().ObjectOwnerId(aHandle)) != KErrNotFound ) |
|
312 { |
|
313 self->iHandles.AppendL( aHandle ); |
|
314 self->iHandleDepths.AppendL( aCurDepth ); |
|
315 } |
|
316 } |
|
317 |