|
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: Connection closer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "E32Std.h" |
|
21 #include <CIMPSSAPSettings.h> |
|
22 #include <ApSettingsHandlerUI.h> |
|
23 #include <ApUtils.h> |
|
24 #include <CPEngNWSessionSlotID2.h> |
|
25 #include <MPEngTransactionStatus2.h> |
|
26 |
|
27 #include "CCnUiConnCloser.h" |
|
28 |
|
29 #include "MCnUiConnectionHandler.h" |
|
30 #include "MCnUiClientPlugin.h" |
|
31 #include "MCnUiOpProgressStateObserver.h" |
|
32 |
|
33 #include "CnUiErrors.h" |
|
34 #include "CnUiPanics.h" |
|
35 #include "IMPSCommonUiDebugPrint.h" |
|
36 |
|
37 |
|
38 |
|
39 // ===================== TCloserStateProxy MEMBER FUNCTIONS =================== |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CCnUiConnCloser::TCloserStateProxy::TCloserStateProxy |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CCnUiConnCloser::TCloserStateProxy::TCloserStateProxy( TCnUiConnCloserState aInitial ) |
|
47 : iState( aInitial ), |
|
48 iObs( NULL ) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCnUiConnCloser::TCloserStateProxy::SetProgressObserver |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CCnUiConnCloser::TCloserStateProxy::SetProgressObserver( MCnUiOpProgressStateObserver* aObs ) |
|
57 { |
|
58 iObs = aObs; |
|
59 } |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CCnUiConnCloser::TCloserStateProxy::Set() |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CCnUiConnCloser::TCloserStateProxy::Set( TCnUiConnCloserState aNewState, |
|
67 TIMPSConnectionClient aClient ) |
|
68 { |
|
69 iState = aNewState; |
|
70 if ( iObs ) |
|
71 { |
|
72 iObs->HandleProgressStateEnter( iState, aClient ); |
|
73 } |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CCnUiConnCloser::TCloserStateProxy::operator TCnUiConnCloserState () |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 TCnUiConnCloserState CCnUiConnCloser::TCloserStateProxy::operator()() |
|
81 { |
|
82 return iState; |
|
83 } |
|
84 |
|
85 |
|
86 // ============================ MEMBER FUNCTIONS =============================== |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CCnUiConnCloser::CCnUiConnCloser |
|
90 // C++ default constructor can NOT contain any code, that |
|
91 // might leave. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CCnUiConnCloser::CCnUiConnCloser() |
|
95 : CActive( EPriorityStandard ), |
|
96 iState( ECnCloser_Idle ) |
|
97 { |
|
98 CActiveScheduler::Add( this ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CCnUiConnCloser::NewL |
|
103 // Two-phased constructor. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 CCnUiConnCloser* CCnUiConnCloser::NewL() |
|
107 { |
|
108 CCnUiConnCloser* self = new( ELeave ) CCnUiConnCloser; |
|
109 return self; |
|
110 } |
|
111 |
|
112 // Destructor |
|
113 CCnUiConnCloser::~CCnUiConnCloser() |
|
114 { |
|
115 CancelLogout(); |
|
116 delete iNWSessionSlotID; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CCnUiConnCloser::CopyNWSessionSlotL() |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 CPEngNWSessionSlotID2* CCnUiConnCloser::CopyNWSessionSlotL( CPEngNWSessionSlotID2& aSessionSlot ) |
|
124 { |
|
125 CPEngNWSessionSlotID2* tempSlot = aSessionSlot.CloneL(); |
|
126 return tempSlot; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CCnUiConnCloser::MakeLogoutForClient() |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 TInt CCnUiConnCloser::MakeLogoutForClient( TIMPSConnectionClient aClient, |
|
134 const CIMPSSAPSettings& aSap, |
|
135 MCnUiClientPlugin& aPlugin, |
|
136 MCnUiConnectionHandler& aConnHandler, |
|
137 MCnUiOpProgressStateObserver* aProgressObserver, |
|
138 CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
139 { |
|
140 CPEngNWSessionSlotID2* tempSlot = NULL; |
|
141 TRAPD( error, tempSlot = CopyNWSessionSlotL( aNWSessionSlotID ) ); |
|
142 if ( error ) |
|
143 { |
|
144 return error; |
|
145 } |
|
146 delete iNWSessionSlotID; |
|
147 iNWSessionSlotID = tempSlot; |
|
148 |
|
149 ResetCachedParameters(); |
|
150 ResetStateFlags(); |
|
151 |
|
152 //cache parameters to be later accessible |
|
153 iState.SetProgressObserver( aProgressObserver ); |
|
154 iClient = aClient; |
|
155 iSap = &aSap; |
|
156 iPlugin = &aPlugin; |
|
157 iConnHandler = &aConnHandler; |
|
158 |
|
159 |
|
160 //issue SAP connection close |
|
161 TInt logoutStatusCode = KErrNone; |
|
162 TRAP( logoutStatusCode, HandleClientLoggoutRequestL() ); |
|
163 if ( logoutStatusCode == KErrNone ) |
|
164 { |
|
165 //Connection close request OK, wait steps to complete if needed |
|
166 |
|
167 //some processing steps started, wait here with scheduler loop |
|
168 WaitCompletion(); |
|
169 // setting to null, this actually cannot leave so ignoring the leave code |
|
170 TInt ignore; |
|
171 TRAP( ignore, iConnHandler->SetSessionSlotL( NULL ) ); |
|
172 |
|
173 //Logout completed. |
|
174 TBool clientLoggedIn = ETrue; |
|
175 TRAPD( err, clientLoggedIn = aConnHandler.TheClientLoggedInL( aClient ) ) |
|
176 if ( err != KErrNone ) |
|
177 { |
|
178 //logout status retrieve failed, return it as error |
|
179 logoutStatusCode = err; |
|
180 } |
|
181 |
|
182 else if ( !clientLoggedIn ) |
|
183 { |
|
184 //If the tried client isn't anymore logged in ==> logout was succesful |
|
185 //despite what so ever error has been reported |
|
186 logoutStatusCode = KErrNone; |
|
187 } |
|
188 |
|
189 else |
|
190 { |
|
191 //In other cases report the errors as they appear |
|
192 if ( iCanceled ) |
|
193 { |
|
194 //if canceled, force the status be KErrCancel |
|
195 logoutStatusCode = KErrCancel; |
|
196 } |
|
197 else |
|
198 { |
|
199 logoutStatusCode = iStatus.Int(); |
|
200 } |
|
201 } |
|
202 } |
|
203 |
|
204 ResetCachedParameters(); |
|
205 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiConnCloser::MakeLogoutForClient() logoutStatus=%d" ), logoutStatusCode ); |
|
206 return logoutStatusCode; |
|
207 } |
|
208 |
|
209 |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CCnUiConnCloser::CancelLogout() |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CCnUiConnCloser::CancelLogout() |
|
216 { |
|
217 if ( IsActive() ) |
|
218 { |
|
219 CActive::Cancel(); |
|
220 } |
|
221 } |
|
222 |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CCnUiConnCloser::ConnectionReallyClosed() |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 TBool CCnUiConnCloser::ConnectionReallyClosed() |
|
229 { |
|
230 return iConnectionReallyClosed; |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CCnUiConnCloser::WaitCompletion() |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CCnUiConnCloser::WaitCompletion() |
|
240 { |
|
241 //wait with the scheduler loop |
|
242 IMPSCUI_DP_TXT( "CCnUiConnCloser::WaitCompletion() - starting wait" ); |
|
243 if ( !iWait.IsStarted() ) |
|
244 { |
|
245 // Code scanner warning "active object called without checking |
|
246 // whether it is active or cancelling it first" ignored because |
|
247 // CActiveSchedulerWait is not an active object |
|
248 iWait.Start(); // CSI: 10 # See above |
|
249 } |
|
250 IMPSCUI_DP_TXT( "CCnUiConnCloser::WaitCompletion() - wait done" ); |
|
251 } |
|
252 |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CCnUiConnCloser::Completed() |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CCnUiConnCloser::Completed() |
|
259 { |
|
260 //break away from the waiting scheduler loop |
|
261 if ( iWait.IsStarted() ) |
|
262 { |
|
263 iWait.AsyncStop(); |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CCnUiConnCloser::HandleClientLoggoutRequestL() |
|
270 // State handler. |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CCnUiConnCloser::HandleClientLoggoutRequestL() |
|
274 { |
|
275 //logout for client is needed |
|
276 if ( iConnHandler->TheClientLoggedInL( iClient ) ) |
|
277 { |
|
278 //client is logged in, notify plug-in about conn close |
|
279 iPlugin->ConnectionCloseInitL( *iSap ); |
|
280 |
|
281 //and issue the plug-in to do its stuff |
|
282 IssuePluginPreLoggoutProcessingL(); |
|
283 } |
|
284 |
|
285 //if client isn't logged in ==> all ok from logout point of view |
|
286 } |
|
287 |
|
288 |
|
289 |
|
290 // ----------------------------------------------------------------------------- |
|
291 // CCnUiConnCloser::IssuePluginPreLoggoutProcessingL() |
|
292 // Transition to next state. |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CCnUiConnCloser::IssuePluginPreLoggoutProcessingL() |
|
296 { |
|
297 //progress to next state by issuing the client |
|
298 //plug-in processing... |
|
299 |
|
300 //initialize the request status & issue plug-in processing |
|
301 iStatus = KErrNone; |
|
302 |
|
303 // logout has to succeed no matter what |
|
304 TRAPD( err, iPlugin->DoPreLogoutProsessingL( iStatus ) ); |
|
305 |
|
306 if ( ( iStatus == KRequestPending ) && ( err == KErrNone ) ) |
|
307 { |
|
308 //plug-in started a real asynchronous operation |
|
309 //==> wait it to complete |
|
310 |
|
311 iState.Set( ECnCloser_ProcessingPlugin, iClient ); |
|
312 SetActive(); |
|
313 } |
|
314 |
|
315 else |
|
316 { |
|
317 //plug-in didn't start any asynchronous operation |
|
318 //progress directly to connection close |
|
319 IssueSapConnectionCloseL(); |
|
320 } |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CCnUiConnCloser::IssueSapConnectionCloseL() |
|
326 // Transition to next state. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CCnUiConnCloser::IssueSapConnectionCloseL() |
|
330 { |
|
331 //progress to next state by issuing the real |
|
332 //connection close if needed |
|
333 iConnHandler->CloseSapConnectionL( *iNWSessionSlotID, *this ); |
|
334 iState.Set( ECnCloser_ClosingSAPConnection, iClient ); |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CCnUiConnCloser::ResetCachedParameters() |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 void CCnUiConnCloser::ResetCachedParameters() |
|
344 { |
|
345 //cache parameters to be later accessible |
|
346 iState.SetProgressObserver( NULL ); |
|
347 iConnHandler = NULL; |
|
348 iPlugin = NULL; |
|
349 iSap = NULL; |
|
350 } |
|
351 |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CCnUiConnCloser::ResetStateFlags() |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CCnUiConnCloser::ResetStateFlags() |
|
358 { |
|
359 ///set state to idle |
|
360 iState.Set( ECnCloser_Idle, iClient ); |
|
361 iCanceled = EFalse; |
|
362 iConnectionReallyClosed = EFalse; |
|
363 |
|
364 //initially there hasn't happened any errors |
|
365 iStatus = KErrNone; |
|
366 } |
|
367 |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CCnUiConnCloser::HandleNWSessionOperationCompleteL() |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 void CCnUiConnCloser::HandleNWSessionOperationCompleteL( |
|
374 MPEngTransactionStatus2& aStatus, |
|
375 CPEngNWSessionSlot2& /* aNWSessionSlot */, |
|
376 TInt /* aNWSessionSlotOperation */ ) |
|
377 { |
|
378 IMPSCUI_DP_TXT( "CCnUiConnOpener::HandleNWSessionOperationCompleteL()" ); |
|
379 iTransactionStatus = &aStatus; |
|
380 iStatus = aStatus.Status(); |
|
381 HandleOperationCompletionsL(); |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CCnUiConnCloser::HandleNWSessionOperationCompleteL() |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 void CCnUiConnCloser::HandleNWSessionOperationNotifyError( |
|
389 TInt aError, |
|
390 CPEngNWSessionSlot2& /* aNWSessionSlot */, |
|
391 TInt /* aNWSessionSlotOperation */ ) |
|
392 { |
|
393 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiConnCloser::HandleNWSessionOperationNotifyError [%d]" ), aError ); |
|
394 |
|
395 //RunL() has leaved. Stop the processing & store leave code. |
|
396 Completed(); |
|
397 iStatus = aError; |
|
398 } |
|
399 |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CCnUiConnCloser::RunL() |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 void CCnUiConnCloser::RunL() |
|
406 { |
|
407 HandleOperationCompletionsL(); |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CCnUiConnCloser::DoCancel() |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 void CCnUiConnCloser::DoCancel() |
|
415 { |
|
416 //cancel the operation step currently running... |
|
417 switch ( iState() ) |
|
418 { |
|
419 case ECnCloser_ProcessingPlugin: |
|
420 { |
|
421 iPlugin->CancelPreLogoutProsessing(); |
|
422 iCanceled = ETrue; |
|
423 break; |
|
424 } |
|
425 |
|
426 case ECnCloser_ClosingSAPConnection: |
|
427 { |
|
428 //closing the SAP connection |
|
429 iConnHandler->CancelSapConnectionClose( *iNWSessionSlotID ); |
|
430 iCanceled = ETrue; |
|
431 break; |
|
432 } |
|
433 |
|
434 //flow through |
|
435 case ECnCloser_Idle: |
|
436 default: |
|
437 { |
|
438 //nothing to do |
|
439 break; |
|
440 } |
|
441 } |
|
442 |
|
443 //break away from scheduler loop... |
|
444 Completed(); |
|
445 } |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // CCnUiConnCloser::RunError() |
|
449 // ----------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CCnUiConnCloser::RunError( TInt aError ) |
|
452 { |
|
453 IMPSCUI_DP( D_IMPSCUI_LIT( "CCnUiConnCloser::HandleNWSessionOperationCompleteL [%d]" ), aError ); |
|
454 |
|
455 //HandleNWSessionOperationCompleteL() has left. Stop the processing & store leave code. |
|
456 Completed(); |
|
457 iStatus = aError; |
|
458 return KErrNone; |
|
459 } |
|
460 |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // CCnUiConnCloser::HandleOperationCompletionsL() |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 void CCnUiConnCloser::HandleOperationCompletionsL() |
|
467 { |
|
468 IMPSCUI_DP_TXT( "CCnUiConnCloser::HandleOperationCompletionsL" ); |
|
469 |
|
470 switch ( iState() ) |
|
471 { |
|
472 case ECnCloser_ProcessingPlugin: |
|
473 { |
|
474 IMPSCUI_DP( D_IMPSCUI_LIT( "HandleNWSessionOperationCompleteL - state=ECnCloser_ProcessingPlugin, status=%d" ), iStatus ); |
|
475 |
|
476 //ignore possible errors propagating from plug-in logout processing |
|
477 //(logout _can't_ fail to some plug-in stuff) |
|
478 |
|
479 iStatus = KErrNone; |
|
480 IssueSapConnectionCloseL(); |
|
481 break; |
|
482 } |
|
483 |
|
484 |
|
485 case ECnCloser_ClosingSAPConnection: |
|
486 { |
|
487 IMPSCUI_DP( D_IMPSCUI_LIT( "HandleNWSessionOperationCompleteL - state=ECnCloser_ClosingSAPConnection, status=%d" ), iStatus ); |
|
488 //connection close completed, no more steps to do. |
|
489 |
|
490 //if connection close failed, the possible |
|
491 //errors are handled from outside of the wait loop |
|
492 |
|
493 if ( iStatus == KErrNone ) |
|
494 { |
|
495 //connection was closed really |
|
496 //store it so it will be available to external clients |
|
497 iConnectionReallyClosed = ETrue; |
|
498 |
|
499 //set also the current client as logged out |
|
500 if ( iConnHandler ) |
|
501 { |
|
502 iConnHandler->LogoutTheClientL( iClient ); |
|
503 } |
|
504 Completed(); |
|
505 } |
|
506 |
|
507 break; |
|
508 } |
|
509 |
|
510 |
|
511 //Flow trough... |
|
512 case ECnCloser_Idle: |
|
513 default: |
|
514 { |
|
515 IMPSCUI_DP( D_IMPSCUI_LIT( "HandleNWSessionOperationCompleteL - state=ECnCloser_Idle, status=%d" ), iStatus ); |
|
516 //not allowed state completed |
|
517 CnUiPanicOrLeaveL( EIMPSConnCloserUnknownState, KErrUnknown ); |
|
518 break; |
|
519 } |
|
520 } |
|
521 } |
|
522 // End of File |