|
1 /* |
|
2 * Copyright (c) 2004 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: Access handler of the network session |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngPureDataHandler.h" |
|
20 |
|
21 #include "PEngTransAdapterPanics.h" |
|
22 #include "CPEngSendDataOperation.h" |
|
23 #include "MPEngSessionManager.h" |
|
24 #include "MPEngAccessHandler.h" |
|
25 |
|
26 // Packet logger |
|
27 #include "PEngPacketLogger.h" |
|
28 |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KOpIdInitvalue = 1000; |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPEngPureDataHandler::CPEngPureDataHandler |
|
38 // C++ default constructor can NOT contain any code, that might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPEngPureDataHandler::CPEngPureDataHandler( |
|
42 MPEngSessionManager& aSessManager, |
|
43 MPEngAccessHandler& aAccessHandler, |
|
44 const CPEngSessionSlotId& aSessionId, |
|
45 RImpsEng& aSessClient ) |
|
46 : iCount( 1 ), // init to 1 |
|
47 iSessionManager( aSessManager ), |
|
48 iAccessHandler( aAccessHandler ), |
|
49 iSessionId( aSessionId ), |
|
50 iSessClient( aSessClient ), |
|
51 iOpidIterator( KOpIdInitvalue ) |
|
52 { |
|
53 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::CPEngPureDataHandler" ) ); |
|
54 iAccessHandler.Open(); // CSI: 65 # |
|
55 iSessionManager.OpenRef(); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CPEngPureDataHandler::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CPEngPureDataHandler::ConstructL( |
|
64 RImpsEng& aSessClient ) |
|
65 { |
|
66 iPureClient.RegisterL( aSessClient, // main client |
|
67 this, // Observer |
|
68 EImpsServicePresence, // Type of service |
|
69 ETrue, // Incoming data interest |
|
70 ETrue ); // Any content type |
|
71 iPureClient.RegisterErrorObserverL( *this ); |
|
72 TInt bufferSize ( iPureClient.MaxTransactionContentLengthL() ); |
|
73 |
|
74 // if size is zero, leave cause WV Engine is not ready |
|
75 if ( bufferSize == 0 ) |
|
76 { |
|
77 User::Leave( KErrNotReady ); |
|
78 } |
|
79 iTrasferBuffer = HBufC8::NewL( bufferSize ); |
|
80 #ifdef PENG_ENABLE_DEBUG_PRINT |
|
81 // init logs connection Id |
|
82 iConnectionLogsId = PEngPacketLogger::GetConnectionId(); |
|
83 #endif |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CPEngPureDataHandler::NewLC() |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CPEngPureDataHandler* CPEngPureDataHandler::NewL( |
|
92 RImpsEng& aSessClient, |
|
93 MPEngSessionManager& aSessManager, |
|
94 MPEngAccessHandler& aAccessHandler, |
|
95 const CPEngSessionSlotId& aSessionId ) |
|
96 { |
|
97 CPEngPureDataHandler* self = new ( ELeave ) CPEngPureDataHandler( |
|
98 aSessManager, |
|
99 aAccessHandler, |
|
100 aSessionId, |
|
101 aSessClient ); |
|
102 CleanupClosePushL( *self ); |
|
103 self->ConstructL( aSessClient ); |
|
104 CleanupStack::Pop(); |
|
105 return self; |
|
106 } |
|
107 |
|
108 |
|
109 // Destructor |
|
110 CPEngPureDataHandler::~CPEngPureDataHandler() |
|
111 { |
|
112 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::~CPEngPureDataHandler" ) ); |
|
113 |
|
114 delete iTrasferBuffer; |
|
115 iIncomingData.ResetAndDestroy(); |
|
116 |
|
117 if ( iIncReqStatus ) |
|
118 { |
|
119 User::RequestComplete( iIncReqStatus, KErrCancel ); |
|
120 } |
|
121 iPureClient.Unregister(); |
|
122 iSessionManager.ClosePureDataHandler(); |
|
123 // destroy arrays, operations are canceled |
|
124 iOperations.ResetAndDestroy(); |
|
125 iAccessHandler.UnregisterSessionObserver( *this ); |
|
126 iAccessHandler.Close(); |
|
127 } |
|
128 |
|
129 |
|
130 // ============================================================================= |
|
131 // =============== New Functions of the MPEngPureDataHandler =================== |
|
132 // ============================================================================= |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CPEngPureDataHandler::Close() |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CPEngPureDataHandler::Close() |
|
139 { |
|
140 iCount--; |
|
141 if ( iCount == 0 ) |
|
142 { |
|
143 delete this; |
|
144 } |
|
145 } |
|
146 |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CPEngPureDataHandler::TransferBufferL() |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 TPtr8 CPEngPureDataHandler::TransferBufferL() |
|
153 { |
|
154 TPtr8 buf = iTrasferBuffer->Des(); |
|
155 buf.Zero(); |
|
156 return buf; |
|
157 } |
|
158 |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CPEngPureDataHandler::SendDataL() |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CPEngPureDataHandler::SendDataL( |
|
165 TRequestStatus& aStatus ) |
|
166 { |
|
167 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::SendDataL:" ) ); |
|
168 |
|
169 if ( iTrasferBuffer->Length() == 0 ) |
|
170 { |
|
171 // buffer is empty, nothing to send, leave |
|
172 User::Leave( KErrArgument ); |
|
173 } |
|
174 // allocate slot in array by adding NULL pointer and removing it |
|
175 iOperations.AppendL( NULL ); |
|
176 iOperations.Remove( iOperations.Count() - 1 ); |
|
177 CPEngSendDataOperation* operation = |
|
178 CPEngSendDataOperation::NewLC(); |
|
179 |
|
180 TInt opId( iPureClient.SendPureDataL( *iTrasferBuffer ) ); |
|
181 operation->SetIds( opId, iOpidIterator++ ); |
|
182 |
|
183 #ifdef PENG_ENABLE_DEBUG_PRINT |
|
184 iConnectionLogsId = PEngPacketLogger::WriteOutPacket( |
|
185 *iTrasferBuffer, |
|
186 operation->LogId(), |
|
187 opId, |
|
188 iConnectionLogsId, |
|
189 iSessionId.UserId(), |
|
190 iSessionId.ServiceAddress() ); |
|
191 #endif |
|
192 |
|
193 iOperations.Append( operation ); |
|
194 CleanupStack::Pop(); // operation |
|
195 // now it is safe to set request status |
|
196 operation->SetRequestStatus( aStatus ); |
|
197 aStatus = KRequestPending; |
|
198 return opId; |
|
199 } |
|
200 |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPEngPureDataHandler::ResponseLC() |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 HBufC8* CPEngPureDataHandler::ResponseL( |
|
207 TInt aTransId ) |
|
208 { |
|
209 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::ResponseL - id: %d" ), aTransId ); |
|
210 // is it incoming data request |
|
211 if ( aTransId == 0 ) |
|
212 { |
|
213 if ( iIncomingData.Count() == 0 ) |
|
214 { |
|
215 User::Leave( KErrNotFound ); |
|
216 } |
|
217 // take first one from the array |
|
218 HBufC8* buff = iIncomingData[ 0 ]; |
|
219 iIncomingData.Remove( 0 ); |
|
220 return buff; |
|
221 } |
|
222 // try to find operation |
|
223 TInt x( FindOperationL( aTransId, CPEngSendDataOperation::OperationId ) ); |
|
224 // is operation completed? |
|
225 TRequestStatus* status = iOperations[ x ]->Status(); |
|
226 if ( status && ( *status == KRequestPending ) ) |
|
227 { |
|
228 User::Leave( KErrNotReady ); |
|
229 } |
|
230 |
|
231 // send buffer and remove operation |
|
232 HBufC8* buff = iOperations[ x ]->Response(); |
|
233 delete iOperations[ x ]; |
|
234 iOperations.Remove( x ); |
|
235 return buff; |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CPEngPureDataHandler::CancelSending() |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CPEngPureDataHandler::CancelSending( |
|
244 TInt aTransId ) |
|
245 { |
|
246 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::CancelSending - id: %d" ), |
|
247 aTransId ); |
|
248 |
|
249 // try to find operation |
|
250 TInt x( FindOperation( aTransId, CPEngSendDataOperation::OperationId ) ); |
|
251 if ( x == KErrNotFound ) |
|
252 { |
|
253 // nothing to cancel |
|
254 return; |
|
255 } |
|
256 TRequestStatus* status = iOperations[ x ]->Status(); |
|
257 if ( status && ( *status == KRequestPending ) ) |
|
258 { |
|
259 // operation pending, cancel it |
|
260 iPureClient.CancelTransaction( aTransId ); |
|
261 iOperations[ x ]->CompletedOperation( KErrCancel ); |
|
262 } |
|
263 delete iOperations[ x ]; |
|
264 iOperations.Remove( x ); |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CPEngPureDataHandler::ListenIncomingData() |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CPEngPureDataHandler::ListenIncomingData( |
|
273 TRequestStatus& aStatus ) |
|
274 { |
|
275 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::ListenIncomingData" ) ); |
|
276 |
|
277 __ASSERT_DEBUG( !iIncReqStatus, |
|
278 User::Panic( KPEngTransferAdapterPanic, |
|
279 EListenerAlreadyActive ) |
|
280 ); |
|
281 iIncReqStatus = &aStatus; |
|
282 aStatus = KRequestPending; |
|
283 return iIncomingData.Count(); |
|
284 } |
|
285 |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CPEngPureDataHandler::CancelListening() |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CPEngPureDataHandler::CancelListening() |
|
292 { |
|
293 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::CancelListening" ) ); |
|
294 |
|
295 if ( iIncReqStatus ) |
|
296 { |
|
297 User::RequestComplete( iIncReqStatus, KErrCancel ); |
|
298 iIncReqStatus = NULL; |
|
299 } |
|
300 } |
|
301 |
|
302 |
|
303 // ============================================================================= |
|
304 // =============== New Functions of the MImpsPureHandler ======================= |
|
305 // ============================================================================= |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CPEngPureDataHandler::HandlePureDataL() |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CPEngPureDataHandler::HandlePureDataL( |
|
312 TInt aOpId, |
|
313 const TDesC8& aBuffer, |
|
314 TImpsCspIdentifier& /* aCspId*/ ) |
|
315 { |
|
316 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::HandlePureDataL - id: %d" ), |
|
317 aOpId ); |
|
318 |
|
319 // is it incoming data handler |
|
320 if ( aOpId == 0 ) |
|
321 { |
|
322 #ifdef PENG_ENABLE_DEBUG_PRINT |
|
323 iConnectionLogsId = PEngPacketLogger::WriteNotifyPacket( |
|
324 aBuffer, |
|
325 iLastServerOpId, |
|
326 iConnectionLogsId, |
|
327 iSessionId.UserId(), |
|
328 iSessionId.ServiceAddress() ); |
|
329 #endif |
|
330 |
|
331 HBufC8* buff = aBuffer.AllocLC(); |
|
332 iIncomingData.AppendL( buff ); |
|
333 CleanupStack::Pop(); // buff |
|
334 if ( iIncReqStatus ) |
|
335 { |
|
336 User::RequestComplete( iIncReqStatus, KErrNone ); |
|
337 iIncReqStatus = NULL; |
|
338 } |
|
339 return; |
|
340 } |
|
341 |
|
342 // get buffer and store it in the correct Operation if it is our operation |
|
343 TInt x( FindOperationL( aOpId, CPEngSendDataOperation::OperationId ) ); |
|
344 if ( x != KErrNotFound ) |
|
345 { |
|
346 #ifdef PENG_ENABLE_DEBUG_PRINT |
|
347 iConnectionLogsId = PEngPacketLogger::WriteInPacket( |
|
348 aBuffer, |
|
349 iOperations[ x ]->LogId(), |
|
350 aOpId, |
|
351 iConnectionLogsId, |
|
352 iSessionId.UserId(), |
|
353 iSessionId.ServiceAddress() ); |
|
354 |
|
355 iLastServerOpId = iOperations[ x ]->LogId(); |
|
356 #endif |
|
357 iOperations[ x ]->SetResponse( aBuffer.AllocL() ); |
|
358 iOperations[ x ]->CompletedOperation( KErrNone ); |
|
359 } |
|
360 } |
|
361 |
|
362 |
|
363 // ============================================================================= |
|
364 // =============== New Functions of the MImpsErrorHandler ====================== |
|
365 // ============================================================================= |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CPEngPureDataHandler::HandleErrorL() |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CPEngPureDataHandler::HandleErrorL( |
|
372 TInt aStatus, |
|
373 TInt aOpId, |
|
374 const TDesC* /*aDescription*/, |
|
375 const CImpsDetailed* /* aDetailedRes*/, |
|
376 TImpsCspIdentifier& /*aCspId*/ ) |
|
377 { |
|
378 PENG_DP( D_PENG_LIT( "CPEngPureDataHandler::HandleErrorL - id: %d, %d" ), |
|
379 aStatus, |
|
380 aOpId ); |
|
381 |
|
382 // get buffer and store it in the correct Operation |
|
383 TInt x( FindOperationL( aOpId, CPEngSendDataOperation::OperationId ) ); |
|
384 #ifdef PENG_ENABLE_DEBUG_PRINT |
|
385 iConnectionLogsId = PEngPacketLogger::WriteError( |
|
386 aStatus, |
|
387 iOperations[ x ]->LogId(), |
|
388 aOpId, |
|
389 iConnectionLogsId, |
|
390 iSessionId.UserId(), |
|
391 iSessionId.ServiceAddress() ); |
|
392 |
|
393 #endif |
|
394 iOperations[ x ]->CompletedOperation( aStatus ); |
|
395 } |
|
396 |
|
397 |
|
398 // ============================================================================= |
|
399 // ============== New Functions of the MPEngSessionStatusObserver ============== |
|
400 // ============================================================================= |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // CPEngPureDataHandler::HandleErrorL() |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CPEngPureDataHandler::StatusChangedL( |
|
408 TPEngNWSessionSlotState aNewState, |
|
409 TPEngNWSessionSlotEvent /*aNewEvent*/ ) |
|
410 { |
|
411 if ( aNewState == EPEngNWPresenceSessionClosed ) |
|
412 { |
|
413 // cancel all operations |
|
414 iOperations.ResetAndDestroy(); |
|
415 } |
|
416 } |
|
417 |
|
418 |
|
419 // ============================================================================= |
|
420 // =============== New Functions of main class ================================= |
|
421 // ============================================================================= |
|
422 |
|
423 // ----------------------------------------------------------------------------- |
|
424 // CPEngPureDataHandler::Open() |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 void CPEngPureDataHandler::Open() |
|
428 { |
|
429 iCount++; |
|
430 } |
|
431 |
|
432 |
|
433 // ============================================================================= |
|
434 // =============== New private Functions of the base class ===================== |
|
435 // ============================================================================= |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CPEngPureDataHandler::FindOperation() |
|
439 // Find operation in array |
|
440 // (other items were commented in a header). |
|
441 // ----------------------------------------------------------------------------- |
|
442 // |
|
443 TInt CPEngPureDataHandler::FindOperation( |
|
444 TInt aOpId, |
|
445 TInt ( CPEngSendDataOperation:: *aIdFunc )() const ) const |
|
446 { |
|
447 TInt count ( iOperations.Count() ); |
|
448 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
449 { |
|
450 if ( aOpId == ( ( *iOperations[ x ] ).*aIdFunc )() ) |
|
451 { |
|
452 return x; |
|
453 } |
|
454 } |
|
455 return KErrNotFound; |
|
456 } |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CPEngPureDataHandler::FindOperationL() |
|
460 // Find operation in array, leave if not found |
|
461 // (other items were commented in a header). |
|
462 // ----------------------------------------------------------------------------- |
|
463 // |
|
464 TInt CPEngPureDataHandler::FindOperationL( |
|
465 TInt aOpId, |
|
466 TInt ( CPEngSendDataOperation:: *aIdFunc )() const ) const |
|
467 { |
|
468 TInt x ( FindOperation( aOpId, aIdFunc ) ); |
|
469 if ( x == KErrNotFound ) |
|
470 { |
|
471 User::Leave( KErrNotFound ); |
|
472 } |
|
473 return x; |
|
474 } |
|
475 // End of File |
|
476 |
|
477 |