|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mtp/mtpprotocolconstants.h> |
|
20 #include <mtp/tmtptyperequest.h> |
|
21 #include <mtp/mmtpdataproviderframework.h> |
|
22 #include <mtp/tmtptypeevent.h> |
|
23 #include <mtp/mmtpconnection.h> |
|
24 #include <mtp/mmtpobjectmgr.h> |
|
25 #include <e32property.h> |
|
26 #include <MtpPrivatePSKeys.h> |
|
27 |
|
28 #include "crequestprocessor.h" |
|
29 #include "crequestchecker.h" |
|
30 #include "mmmtpdplogger.h" |
|
31 |
|
32 static const TInt KNullBufferSize = 4096; |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CRequestProcessor::CRequestProcessor |
|
36 // Standard c++ constructor |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CRequestProcessor::CRequestProcessor( MMTPDataProviderFramework& aFramework, |
|
40 MMTPConnection& aConnection, |
|
41 TInt aElementCount, |
|
42 const TMTPRequestElementInfo* aElements ): |
|
43 CActive( EPriorityStandard ), |
|
44 iFramework( aFramework ), |
|
45 iConnection( aConnection ), |
|
46 iElementCount( aElementCount ), |
|
47 iElements( aElements ) |
|
48 { |
|
49 // CActiveScheduler::Add( this ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CRequestProcessor::~CRequestProcessor |
|
54 // Destructor |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CRequestProcessor::~CRequestProcessor() |
|
58 { |
|
59 // Cancel(); |
|
60 iNullBuffer.Close(); |
|
61 delete iRequestChecker; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CRequestProcessor::Release |
|
66 // Relese (delete) this request processor |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C void CRequestProcessor::Release() |
|
70 { |
|
71 delete this; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CRequestProcessor::SendResponseL |
|
76 // Send a response to the initiator |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C void CRequestProcessor::SendResponseL( TMTPResponseCode aResponseCode, |
|
80 TInt aParameterCount, |
|
81 TUint32* aParams ) |
|
82 { |
|
83 PRINT2( _L( "MM MTP <> CRequestProcessor::SendResponseL iTransactionCode = %d, aResponseCode = 0x%x" ), |
|
84 iTransactionCode, |
|
85 aResponseCode ); |
|
86 __ASSERT_DEBUG( aParameterCount < TMTPTypeRequest::ENumElements, User::Invariant() ); |
|
87 |
|
88 iResponse.SetUint16( TMTPTypeResponse::EResponseCode, aResponseCode ); |
|
89 iResponse.SetUint32( TMTPTypeResponse::EResponseSessionID, iSessionId ); |
|
90 iResponse.SetUint32( TMTPTypeResponse::EResponseTransactionID, iTransactionCode ); |
|
91 |
|
92 TInt i = 0; |
|
93 for( i = 0; i < aParameterCount; i++ ) |
|
94 { |
|
95 iResponse.SetUint32( TMTPTypeResponse::EResponseParameter1 + i, aParams[i] ); |
|
96 } |
|
97 |
|
98 i += TMTPTypeResponse::EResponseParameter1; |
|
99 while( i < TMTPTypeResponse::EResponseParameter5 ) |
|
100 { |
|
101 iResponse.SetUint32( i, 0 ); |
|
102 i++; |
|
103 } |
|
104 |
|
105 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
106 iFramework.SendResponseL( iResponse, *iRequest, iConnection ); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CRequestProcessor::Request |
|
111 // The current active request |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C const TMTPTypeRequest& CRequestProcessor::Request() const |
|
115 { |
|
116 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
117 return *iRequest; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CRequestProcessor::Connection |
|
122 // The connection from which the current request comes |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C MMTPConnection& CRequestProcessor::Connection() const |
|
126 { |
|
127 return iConnection; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CRequestProcessor::UsbDisconnect |
|
132 // Rollback when WMP closed and disconnect the USB cable, |
|
133 // during the transferring file |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C void CRequestProcessor::UsbDisconnect() |
|
137 { |
|
138 // TODO: reset the CenRep value |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CRequestProcessor::CompleteRequestL |
|
143 // Signal to the framework that the current request transaction has completed |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CRequestProcessor::CompleteRequestL() |
|
147 { |
|
148 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
149 iFramework.TransactionCompleteL( *iRequest, iConnection ); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CRequestProcessor::SendDataL |
|
154 // Send data to the initiator |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 EXPORT_C void CRequestProcessor::SendDataL( const MMTPType& aData ) |
|
158 { |
|
159 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
160 iFramework.SendDataL( aData, *iRequest, iConnection ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CRequestProcessor::ReceiveDataL |
|
165 // Receive data from the initiator |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CRequestProcessor::ReceiveDataL( MMTPType& aData ) |
|
169 { |
|
170 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
171 iFramework.ReceiveDataL( aData, *iRequest, iConnection ); |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CRequestProcessor::HandleRequestL |
|
176 // Handle the request |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C TBool CRequestProcessor::HandleRequestL( const TMTPTypeRequest& aRequest, |
|
180 TMTPTransactionPhase aPhase ) |
|
181 { |
|
182 iRequest = &aRequest; |
|
183 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
184 TBool result = EFalse; |
|
185 switch( aPhase ) |
|
186 { |
|
187 case ERequestPhase: |
|
188 ExtractSessionTransactionId(); |
|
189 result = DoHandleRequestPhaseL(); |
|
190 break; |
|
191 |
|
192 case EDataIToRPhase: |
|
193 result = DoHandleDataIToRPhaseL(); |
|
194 break; |
|
195 |
|
196 case EDataRToIPhase: |
|
197 result = DoHandleRToIPhaseL(); |
|
198 break; |
|
199 |
|
200 case EResponsePhase: |
|
201 if ( iResponseCode != EMTPRespCodeOK && HasDataphase() ) |
|
202 { |
|
203 SendResponseL( iResponseCode ); |
|
204 iNullBuffer.Close(); |
|
205 PRINT1( _L( "MM MTP <> CRequestProcessor::HandleRequestL SendResponse 0x%x" ), iResponseCode ); |
|
206 } |
|
207 else |
|
208 { |
|
209 result = DoHandleResponsePhaseL(); |
|
210 } |
|
211 break; |
|
212 |
|
213 case ECompletingPhase: |
|
214 result = DoHandleCompletingPhaseL(); |
|
215 break; |
|
216 |
|
217 default: |
|
218 PRINT( _L( "MM MTP <> CRequestProcessor::HandleRequestL default" ) ); |
|
219 break; |
|
220 } |
|
221 |
|
222 return result; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CRequestProcessor::HandleEventL |
|
227 // Handle the event |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 EXPORT_C void CRequestProcessor::HandleEventL( const TMTPTypeEvent& aEvent ) |
|
231 { |
|
232 TUint16 eventCode = aEvent.Uint16( TMTPTypeEvent::EEventCode ); |
|
233 iCancelled = ( eventCode == EMTPEventCodeCancelTransaction ); |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CRequestProcessor::Match |
|
238 // Check whether the processor can process the request |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C TBool CRequestProcessor::Match( const TMTPTypeRequest& aRequest, |
|
242 MMTPConnection& aConnection ) const |
|
243 { |
|
244 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
245 TBool result = ( ( &aRequest == iRequest ) && ( &iConnection == &aConnection ) ); |
|
246 return result; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CRequestProcessor::Match |
|
251 // Check whether the processor can process the event |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C TBool CRequestProcessor::Match( const TMTPTypeEvent& aEvent, |
|
255 MMTPConnection& aConnection ) const |
|
256 { |
|
257 TUint32 eventSessionId = aEvent.Uint32( TMTPTypeEvent::EEventSessionID ); |
|
258 TUint32 eventTransactionCode = aEvent.Uint32( TMTPTypeEvent::EEventTransactionID ); |
|
259 |
|
260 TBool result = EFalse; |
|
261 if ( ( iSessionId == eventSessionId ) |
|
262 && ( iTransactionCode == eventTransactionCode ) |
|
263 && ( &iConnection == &aConnection ) ) |
|
264 { |
|
265 result = ETrue; |
|
266 } |
|
267 return result; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CRequestProcessor::DoHandleRequestPhaseL |
|
272 // Handle the request phase of the current request |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C TBool CRequestProcessor::DoHandleRequestPhaseL() |
|
276 { |
|
277 TRAPD( err, iResponseCode = CheckRequestL() ); |
|
278 PRINT2( _L( "MM MTP <> CRequestProcessor::DoHandleRequestPhaseL iResponseCode = 0x%x, CheckRequestL err = %d" ), |
|
279 iResponseCode, err ); |
|
280 if ( ( err != KErrNone ) || ( iResponseCode != EMTPRespCodeOK ) ) |
|
281 { |
|
282 if ( HasDataphase() ) |
|
283 { |
|
284 // If we have a dataphase |
|
285 // we need to read in the data and discard it |
|
286 iNullBuffer.Close(); |
|
287 iNullBuffer.CreateMaxL( KNullBufferSize ); |
|
288 iNull.SetBuffer( iNullBuffer ); |
|
289 ReceiveDataL( iNull ); |
|
290 } |
|
291 else |
|
292 { |
|
293 if ( err != KErrNone ) |
|
294 { |
|
295 User::Leave( err ); |
|
296 } |
|
297 SendResponseL( iResponseCode ); |
|
298 } |
|
299 } |
|
300 else |
|
301 { |
|
302 TRAP( err, ServiceL() ); |
|
303 PRINT1( _L( "MM MTP <> CRequestProcessor::DoHandleRequestPhaseL ServiceL err = %d" ), err ); |
|
304 if ( err != KErrNone ) |
|
305 { |
|
306 iResponseCode = EMTPRespCodeGeneralError; |
|
307 if ( HasDataphase() ) |
|
308 { |
|
309 // If we have a dataphase |
|
310 // we need to read in the data and discard it |
|
311 iNullBuffer.Close(); |
|
312 iNullBuffer.CreateMaxL( KNullBufferSize ); |
|
313 iNull.SetBuffer( iNullBuffer ); |
|
314 ReceiveDataL( iNull ); |
|
315 } |
|
316 else |
|
317 { |
|
318 User::Leave( err ); |
|
319 } |
|
320 } |
|
321 } |
|
322 |
|
323 return EFalse; |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CRequestProcessor::DoHandleDataIToRPhaseL |
|
328 // Handle the receiving data phase of the current request |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C TBool CRequestProcessor::DoHandleDataIToRPhaseL() |
|
332 { |
|
333 User::Invariant(); |
|
334 return EFalse; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CRequestProcessor::DoHandleRToIPhaseL |
|
339 // Handle the sending data phase of the current request |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C TBool CRequestProcessor::DoHandleRToIPhaseL() |
|
343 { |
|
344 User::Invariant(); |
|
345 return EFalse; |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CRequestProcessor::DoHandleResponsePhaseL |
|
350 // Handle the response phase of the current request |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 EXPORT_C TBool CRequestProcessor::DoHandleResponsePhaseL() |
|
354 { |
|
355 TMTPResponseCode responseCode = ( iCancelled ? EMTPRespCodeIncompleteTransfer : EMTPRespCodeOK ); |
|
356 SendResponseL( responseCode ); |
|
357 return EFalse; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CRequestProcessor::DoHandleCompletingPhaseL |
|
362 // Handle the completing phase of the current request |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C TBool CRequestProcessor::DoHandleCompletingPhaseL() |
|
366 { |
|
367 CompleteRequestL(); |
|
368 return ETrue; |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CRequestProcessor::CheckRequestL |
|
373 // Check the current request |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 EXPORT_C TMTPResponseCode CRequestProcessor::CheckRequestL() |
|
377 { |
|
378 if ( !iRequestChecker ) |
|
379 { |
|
380 iRequestChecker = CRequestChecker::NewL( iFramework, iConnection ); |
|
381 } |
|
382 __ASSERT_DEBUG( iRequest, User::Invariant() ); |
|
383 return iRequestChecker->VerifyRequestL( *iRequest, iElementCount, iElements ); |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CRequestProcessor::RunL |
|
388 // part of active object framework, provide default implementation |
|
389 // ----------------------------------------------------------------------------- |
|
390 // |
|
391 EXPORT_C void CRequestProcessor::RunL() |
|
392 { |
|
393 |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CRequestProcessor::DoCancel |
|
398 // part of active object framework, provide default implementation |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C void CRequestProcessor::DoCancel() |
|
402 { |
|
403 |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CRequestProcessor::RunError |
|
408 // part of active object framework, provide default implementation |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 EXPORT_C TInt CRequestProcessor::RunError( TInt aError ) |
|
412 { |
|
413 PRINT1( _L( "MM MTP <> CRequestProcessor RunError = %d" ), aError ); |
|
414 TRAP_IGNORE( SendResponseL( EMTPRespCodeGeneralError ) ); |
|
415 return KErrNone; |
|
416 } |
|
417 |
|
418 EXPORT_C TBool CRequestProcessor::HasDataphase() const |
|
419 { |
|
420 return EFalse; |
|
421 } |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CRequestProcessor::SetPSStatus |
|
425 // Set P&S Status to avoid MPX access conflict |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CRequestProcessor::SetPSStatus() |
|
429 { |
|
430 TInt mtpStatus; |
|
431 RProperty::Get( KMtpPSUid, KMtpPSStatus, mtpStatus); |
|
432 |
|
433 if ( mtpStatus != EMtpPSStatusActive ) |
|
434 { |
|
435 TInt err = RProperty::Set( KMtpPSUid, KMtpPSStatus, EMtpPSStatusActive ); |
|
436 PRINT1( _L("MM MTP <> CRequestProcessor::SetPSStatus err = %d" ), err ); |
|
437 } |
|
438 } |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // CRequestProcessor::ExtractSessionTransactionId |
|
442 // retrieve the session id and transaction code from the current request |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 void CRequestProcessor::ExtractSessionTransactionId() |
|
446 { |
|
447 iSessionId = iRequest->Uint32( TMTPTypeRequest::ERequestSessionID ); |
|
448 iTransactionCode = iRequest->Uint32( TMTPTypeRequest::ERequestTransactionID ); |
|
449 |
|
450 PRINT2( _L( "MM MTP <> CRequestProcessor iSessionId = %d, iTransactionCode = %d" ), |
|
451 iSessionId, |
|
452 iTransactionCode ); |
|
453 } |
|
454 |
|
455 EXPORT_C TUint32 CRequestProcessor::SessionId() |
|
456 { |
|
457 return iSessionId; |
|
458 } |
|
459 |
|
460 // end of file |