|
1 // Copyright (c) 2003-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 /** |
|
17 @file PsdStates.cpp |
|
18 */ |
|
19 |
|
20 #include <comms-infras/cagentsmbase.h> |
|
21 #include <etelpckt.h> |
|
22 #include <connectprog.h> // for circuit-switched progress enums |
|
23 #include <netconerror.h> |
|
24 #include "psdlogger.h" |
|
25 |
|
26 #include "psdstates.h" |
|
27 #include "psdagt.h" |
|
28 #include "psdprog.h" |
|
29 |
|
30 #include "debuglogger.h" |
|
31 #include <logengevents.h> |
|
32 |
|
33 CPsdOutInit::CPsdOutInit(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
34 : CPsdInitBase(aObserver,aPsdSM,aDb) |
|
35 /** |
|
36 Constructor |
|
37 */ |
|
38 {} |
|
39 |
|
40 CPsdOutInit::~CPsdOutInit() |
|
41 /** |
|
42 Destructor |
|
43 */ |
|
44 {} |
|
45 |
|
46 CAgentStateBase* CPsdOutInit::NextStateL(TBool aContinue) |
|
47 /** |
|
48 Called by the genconn state machine frame work to move the state machine to the next state |
|
49 function creates the next state in the state machine |
|
50 |
|
51 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
52 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
53 */ |
|
54 { |
|
55 if (iStatus==KErrNone && aContinue) // which it will be if there has been no error so far |
|
56 return new (ELeave) CPsdOutCheckConfig(iSMObserver,iSM,iDbPsd); |
|
57 else |
|
58 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
59 } |
|
60 |
|
61 CPsdOutCheckConfig::CPsdOutCheckConfig(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
62 : CPsdCheckConfig(aObserver,aPsdSM,aDb) |
|
63 /** |
|
64 Constructor |
|
65 */ |
|
66 {} |
|
67 |
|
68 CPsdOutCheckConfig::~CPsdOutCheckConfig() |
|
69 /** |
|
70 Destructor |
|
71 */ |
|
72 {} |
|
73 |
|
74 CAgentStateBase* CPsdOutCheckConfig::NextStateL(TBool aContinue) |
|
75 /** |
|
76 move the state machine to the next state function creates the next state in the state machine. |
|
77 |
|
78 @see CAgentStateBase* CPsdOutInit::NextStateL(TBool aContinue) |
|
79 */ |
|
80 { |
|
81 if (iStatus==KErrNone && aContinue) // which it will be if there has been no error so far |
|
82 return new (ELeave) CPsdNetworkCheck(iSMObserver,iSM,iDbPsd); |
|
83 else |
|
84 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
85 } |
|
86 |
|
87 #ifndef INCOMING_NOT_SUPORTED |
|
88 |
|
89 CPsdInInit::CPsdInInit(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
90 : CPsdInitBase(aObserver,aPsdSM,aDb) |
|
91 /** |
|
92 Constructor |
|
93 */ |
|
94 {} |
|
95 |
|
96 CPsdInInit::~CPsdInInit() |
|
97 /** |
|
98 Destructor |
|
99 */ |
|
100 {} |
|
101 |
|
102 void CPsdInInit::DoStartStateL() |
|
103 /** |
|
104 Internal function that initialises the state machine for an incoming connection |
|
105 overriding the virtual function in the base class |
|
106 |
|
107 Check first of all whether we are allowed to do inbound |
|
108 */ |
|
109 { |
|
110 TBool allowed = iDbPsd->IsIncomingAllowedL(); |
|
111 if (!allowed) |
|
112 User::Leave(KErrAccessDenied); |
|
113 CPsdInitBase::DoStartStateL(); |
|
114 } |
|
115 |
|
116 CAgentStateBase* CPsdInInit::NextStateL(TBool aContinue) |
|
117 /** |
|
118 Called by the genconn state machine frame work to move the state machine to the next state |
|
119 function creates the next state in the state machine |
|
120 |
|
121 @see CAgentStateBase* CPsdOutInit::NextStateL(TBool aContinue) |
|
122 */ |
|
123 { |
|
124 if (iStatus==KErrNone && aContinue) // which it will be if there has been no error so far |
|
125 return new (ELeave) CPsdInCheckConfig(iSMObserver,iSM,iDbPsd); |
|
126 else |
|
127 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
128 } |
|
129 |
|
130 CPsdInCheckConfig::CPsdInCheckConfig(MAgentObserver* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
131 : CPsdCheckConfig(aObserver,aPsdSM,aDb) |
|
132 /** |
|
133 Constructor |
|
134 */ |
|
135 {} |
|
136 |
|
137 CPsdInCheckConfig::~CPsdInCheckConfig() |
|
138 /** |
|
139 Destructor |
|
140 */ |
|
141 {} |
|
142 |
|
143 CAgentStateBase* CPsdInCheckConfig::NextStateL(TBool aContinue) |
|
144 /** |
|
145 @see CAgentStateBase* CPsdOutInit::NextStateL(TBool aContinue) |
|
146 */ |
|
147 { |
|
148 if (iStatus==KErrNone && aContinue) // which it will be if there has been no error so far |
|
149 return new (ELeave) CPsdWaitForIncoming(iSMObserver,iSM,iDbPsd); |
|
150 else |
|
151 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
152 } |
|
153 #endif // #ifndef INCOMING_NOT_SUPORTED |
|
154 |
|
155 CPsdInitBase::CPsdInitBase(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
156 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
157 /** |
|
158 Constructor |
|
159 */ |
|
160 { |
|
161 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
162 } |
|
163 |
|
164 CPsdInitBase::~CPsdInitBase() |
|
165 /** |
|
166 Desctructor |
|
167 */ |
|
168 { |
|
169 Cancel(); |
|
170 } |
|
171 |
|
172 void CPsdInitBase::StartState() |
|
173 /** |
|
174 Function called by the genconn state machine framework to start the state |
|
175 */ |
|
176 { |
|
177 TRAPD(ret,DoStartStateL()); |
|
178 if (ret!=KErrNone) |
|
179 JumpToRunl(ret); |
|
180 } |
|
181 |
|
182 void CPsdInitBase::DoStartStateL() |
|
183 /** |
|
184 Internal function that performs all the initialisation of the common resources |
|
185 held by the state machine for use by subsequent states |
|
186 */ |
|
187 { |
|
188 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
189 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tInitialising");) |
|
190 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1()); |
|
191 |
|
192 iSMObserver->PreventConnectionRetries(); |
|
193 // |
|
194 // PSD AGX does not allow any more connection retries. It assumes that GenConn has |
|
195 // already done the packet network availability check, so we would only get to this stage |
|
196 // should there be packet network (or if it was unknown). |
|
197 |
|
198 RTelServer& etel = iSM->TelServer(); |
|
199 RPhone& phone = iSM->Phone(); |
|
200 RPacketService& packetNetwork = iSM->PacketNetwork(); |
|
201 |
|
202 User::LeaveIfError(etel.Connect()); |
|
203 TBuf<KCommsDbSvrMaxFieldLength> tsyName; |
|
204 iSM->BaseEnv().Db()->GetTsyNameL(tsyName); |
|
205 User::LeaveIfError(etel.LoadPhoneModule(tsyName)); |
|
206 iSM->SetTsyLoaded(ETrue); |
|
207 |
|
208 User::LeaveIfError(etel.SetExtendedErrorGranularity(RTelServer::EErrorExtended)); |
|
209 |
|
210 RTelServer::TPhoneInfo info; |
|
211 TInt r=tsyName.Locate('.'); |
|
212 if (r!=KErrNotFound) |
|
213 tsyName.SetLength(r); |
|
214 GetPhoneInfoL(tsyName,info); // If this leaves, TSY should be unloaded |
|
215 // when RTelServer handle is closed. |
|
216 User::LeaveIfError(phone.Open(etel,info.iName)); |
|
217 User::LeaveIfError(packetNetwork.Open(phone)); |
|
218 |
|
219 // |
|
220 RPhone::TStatus status; |
|
221 User::LeaveIfError(phone.GetStatus(status)); |
|
222 if (status.iModemDetected==RPhone::EDetectedNotPresent || status.iModemDetected==RPhone::EDetectedUnknown) |
|
223 { |
|
224 phone.Initialise(iStatus); |
|
225 SetActive(); |
|
226 } |
|
227 else // status.iModemDetected==RPhone::EDetectedPresent |
|
228 JumpToRunl(KErrNone); |
|
229 } |
|
230 |
|
231 |
|
232 void CPsdInitBase::GetPhoneInfoL(const TDesC& aLoadedTsyName, RTelServer::TPhoneInfo& aInfo) |
|
233 /** |
|
234 Function obtains the info on the phone object implemented in the TSY |
|
235 |
|
236 Assumes aloadedTsyName has no ".TSY" appendage |
|
237 Finds the phone information for the TSY just loaded. |
|
238 Assumes just one phone in that TSY - or that every phone in it is equally useful. |
|
239 |
|
240 @param name of the loaded Tsy. |
|
241 @param information about the phone. |
|
242 */ |
|
243 { |
|
244 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
245 |
|
246 TInt count; |
|
247 User::LeaveIfError(iSM->TelServer().EnumeratePhones(count)); |
|
248 if (count<=0) |
|
249 User::Leave(KErrNotFound); |
|
250 TBool found=EFalse; |
|
251 for (TInt i=0; i<count; i++) |
|
252 { |
|
253 TBuf<KCommsDbSvrMaxFieldLength> currentTsyName; |
|
254 User::LeaveIfError(iSM->TelServer().GetTsyName(i,currentTsyName)); |
|
255 |
|
256 TInt r=currentTsyName.Locate('.'); |
|
257 if (r!=KErrNotFound) |
|
258 currentTsyName.SetLength(r); |
|
259 if (currentTsyName.CompareF(aLoadedTsyName)==KErrNone) |
|
260 { |
|
261 User::LeaveIfError(iSM->TelServer().GetPhoneInfo(i,aInfo)); |
|
262 found=ETrue; |
|
263 break; |
|
264 } |
|
265 } |
|
266 |
|
267 if (!found) |
|
268 User::Leave(KErrNotFound); |
|
269 } |
|
270 |
|
271 |
|
272 void CPsdInitBase::RunL() |
|
273 /** |
|
274 Complete state for the initialisation state for both incomming and outgoing connections. |
|
275 */ |
|
276 { |
|
277 __FLOG_STMT(_LIT8(logString2,"Packet Data:\tInitialised");) |
|
278 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString2()); |
|
279 if (iStatus!=KErrNone) |
|
280 iSMObserver->ConnectionComplete(EPsdStartingConfiguration,iStatus.Int()); // correct progress? |
|
281 else |
|
282 iSM->BaseEnv().CompleteState(KErrNone); // this tells the SM to move onto the next state |
|
283 } |
|
284 |
|
285 void CPsdInitBase::DoCancel() |
|
286 /** |
|
287 Cancell the asynchronous request of initialisation state for both incomming and outgoing connections. |
|
288 */ |
|
289 { |
|
290 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
291 |
|
292 iSM->Phone().InitialiseCancel(); |
|
293 } |
|
294 |
|
295 CPsdCheckConfig::CPsdCheckConfig(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
296 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
297 /** |
|
298 Constructor |
|
299 */ |
|
300 {} |
|
301 |
|
302 CPsdCheckConfig::~CPsdCheckConfig() |
|
303 /** |
|
304 Destructor |
|
305 */ |
|
306 { |
|
307 Cancel(); |
|
308 } |
|
309 |
|
310 void CPsdCheckConfig::StartState() |
|
311 /** |
|
312 Start checking Configuration states. |
|
313 */ |
|
314 { |
|
315 JumpToRunl(KErrNone); |
|
316 } |
|
317 |
|
318 void CPsdCheckConfig::DoInitL() |
|
319 { |
|
320 RPacketService& packetNetwork = iSM->PacketNetwork(); |
|
321 |
|
322 const CPsdContextConfig& config = iSM->Config(); |
|
323 if(!config.IsConfigSupportedL(packetNetwork,iSM->Direction()) ) |
|
324 { |
|
325 User::Leave(KErrNotSupported); |
|
326 } |
|
327 __FLOG_STMT(_LIT8(logString2,"Packet Data:\tChecked Config");) |
|
328 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString2()); |
|
329 } |
|
330 |
|
331 void CPsdCheckConfig::RunL() |
|
332 /** |
|
333 Complete state for the config checking state for both incomming and outgoing connections. |
|
334 */ |
|
335 { |
|
336 TRAPD(ret,DoInitL()); |
|
337 iStatus=ret; |
|
338 if (iStatus!=KErrNone) |
|
339 iSMObserver->ConnectionComplete(EPsdStartingConfiguration,ret); // correct progress? |
|
340 else |
|
341 iSM->BaseEnv().CompleteState(KErrNone); // this tells the SM to move onto the next state |
|
342 } |
|
343 |
|
344 void CPsdCheckConfig::DoCancel() |
|
345 /** |
|
346 Need do nothing since StartState() already triggered the request status. |
|
347 */ |
|
348 {} |
|
349 |
|
350 CPsdNetworkCheck::CPsdNetworkCheck(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
351 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
352 /** |
|
353 Constructor |
|
354 */ |
|
355 { |
|
356 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
357 } |
|
358 |
|
359 CPsdNetworkCheck::~CPsdNetworkCheck() |
|
360 /** |
|
361 Destructor |
|
362 */ |
|
363 { |
|
364 Cancel(); |
|
365 } |
|
366 |
|
367 void CPsdNetworkCheck::StartState() |
|
368 /** |
|
369 Function called by the genconn state machine framework to start the state |
|
370 */ |
|
371 { |
|
372 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
373 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
374 |
|
375 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tChecking network availability");) |
|
376 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1()); |
|
377 |
|
378 iSubState = EGettingInitialStatus; |
|
379 iSM->PacketNetwork().GetNtwkRegStatus(iStatus,iRegStatus); |
|
380 SetActive(); |
|
381 } |
|
382 |
|
383 void CPsdNetworkCheck::DoNetworkCheck() |
|
384 /** |
|
385 Checking for Network |
|
386 */ |
|
387 |
|
388 { |
|
389 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
390 |
|
391 if (iRegStatus==RPacketService::ERegistrationDenied || |
|
392 iRegStatus==RPacketService::ENotRegisteredNotSearching || |
|
393 iRegStatus==RPacketService::ENotRegisteredAndNotAvailable) |
|
394 { |
|
395 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tNo network");) |
|
396 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1()); |
|
397 JumpToRunl(KErrNetConNoGPRSNetwork); |
|
398 return; |
|
399 } |
|
400 if (iRegStatus==RPacketService::ERegisteredOnHomeNetwork || |
|
401 iRegStatus==RPacketService::ERegisteredRoaming || |
|
402 iRegStatus==RPacketService::ENotRegisteredButAvailable || |
|
403 iRegStatus==RPacketService::EUnknown) |
|
404 { |
|
405 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tReg status %d. Proceeding");) |
|
406 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),iRegStatus); |
|
407 |
|
408 iSM->BaseEnv().CompleteState(KErrNone); |
|
409 return; |
|
410 } |
|
411 |
|
412 __ASSERT_ALWAYS(iRegStatus==RPacketService::ENotRegisteredSearching,PanicAgt(EPsdInvalidNtwkRegistration)); |
|
413 |
|
414 iSM->PacketNetwork().NotifyChangeOfNtwkRegStatus(iStatus,iRegStatus); |
|
415 SetActive(); |
|
416 } |
|
417 |
|
418 void CPsdNetworkCheck::RunL() |
|
419 /** |
|
420 iRegStatus should have been updated, if aError is KErrNone |
|
421 |
|
422 Complete Connection for the Network Check state. |
|
423 */ |
|
424 { |
|
425 if(iSubState == EGettingInitialStatus) |
|
426 { |
|
427 if(iStatus==KErrNotSupported) |
|
428 //tsy could not provide the information |
|
429 { |
|
430 iRegStatus=RPacketService::EUnknown; |
|
431 iStatus=KErrNone; |
|
432 } |
|
433 iSubState = EWaitingForStatusChange; |
|
434 } |
|
435 if (iStatus==KErrNone) |
|
436 DoNetworkCheck(); |
|
437 else |
|
438 iSMObserver->ConnectionComplete(EPsdStartingConfiguration,iStatus.Int()); |
|
439 } |
|
440 |
|
441 void CPsdNetworkCheck::DoCancel() |
|
442 /** |
|
443 Cancell Asynchronous request of network check state. |
|
444 */ |
|
445 { |
|
446 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
447 |
|
448 iSM->PacketNetwork().CancelAsyncRequest(EPacketNotifyChangeOfNtwkRegStatus); |
|
449 } |
|
450 |
|
451 CAgentStateBase* CPsdNetworkCheck::NextStateL(TBool aContinue) |
|
452 /** |
|
453 Called by the genconn state machine frame work to move the state machine to the next state |
|
454 function creates the next state in the state machine |
|
455 |
|
456 @see CAgentStateBase* CPsdOutInit::NextStateL(TBool aContinue). |
|
457 */ |
|
458 { |
|
459 if (iStatus==KErrNone && aContinue) |
|
460 return new (ELeave) CPsdCreateContext(iSMObserver,iSM,iDbPsd); |
|
461 else |
|
462 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
463 } |
|
464 |
|
465 #ifndef INCOMING_NOT_SUPORTED |
|
466 |
|
467 CPsdWaitForIncoming::CPsdWaitForIncoming(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
468 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
469 /** |
|
470 Constructor |
|
471 */ |
|
472 { |
|
473 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
474 } |
|
475 |
|
476 CPsdWaitForIncoming::~CPsdWaitForIncoming() |
|
477 /** |
|
478 Destructor |
|
479 */ |
|
480 { |
|
481 Cancel(); |
|
482 } |
|
483 |
|
484 void CPsdWaitForIncoming::StartState() |
|
485 /** |
|
486 Function called by the genconn state machine framework to start the state |
|
487 */ |
|
488 { |
|
489 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
490 |
|
491 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tWaiting for incoming Packet request");) |
|
492 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
493 |
|
494 iSM->PacketNetwork().NotifyContextActivationRequested(iStatus,iPdpTypeRequested,iAddressRequested); |
|
495 SetActive(); |
|
496 } |
|
497 |
|
498 void CPsdWaitForIncoming::RunL() |
|
499 /** |
|
500 Rejects any incoming request for an IP address that isn't in our Incoming context config |
|
501 |
|
502 Complete Connection for wait for incomming state. |
|
503 */ |
|
504 { |
|
505 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
506 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
507 |
|
508 if (iStatus==KErrNone) |
|
509 { |
|
510 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tReceived network context activation request");) |
|
511 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
512 |
|
513 if(iSM->Config().QueryIfIncommingConnectionAcceptable(iPdpTypeRequested,iAddressRequested) ) |
|
514 { |
|
515 iSMObserver->UpdateProgress(EPsdAnsweringIncoming,KErrNone); |
|
516 TInt ret = iSMObserver->IncomingConnectionReceived(); // to switch NIFMAN to connecting |
|
517 // if this returns an error, it means NIFMAN is already |
|
518 // connected (this can only happen in the "window" |
|
519 // during callback |
|
520 if (ret==KErrNone) |
|
521 iSM->BaseEnv().CompleteState(KErrNone); |
|
522 else |
|
523 { |
|
524 iSM->PacketNetwork().RejectActivationRequest(); |
|
525 StartState(); |
|
526 } |
|
527 } |
|
528 else // wrong address |
|
529 { |
|
530 iSM->PacketNetwork().RejectActivationRequest(); // how long will this take? Should it be |
|
531 // asynchronous? |
|
532 StartState(); |
|
533 } |
|
534 } |
|
535 else |
|
536 iSMObserver->ConnectionComplete(EPsdAnsweringIncoming,iStatus.Int()); |
|
537 } |
|
538 |
|
539 void CPsdWaitForIncoming::DoCancel() |
|
540 /** |
|
541 Cancell Asynchronous request of wait for incomming state. |
|
542 */ |
|
543 { |
|
544 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
545 |
|
546 iSM->PacketNetwork().CancelAsyncRequest(EPacketNotifyContextActivationRequested); |
|
547 } |
|
548 |
|
549 CAgentStateBase* CPsdWaitForIncoming::NextStateL(TBool aContinue) |
|
550 /** |
|
551 Called by the genconn state machine frame work to move the state machine to the next state |
|
552 function creates the next state in the state machine |
|
553 |
|
554 Assumes cancelling a notification will result in KErrCancel being passed back in iStatus |
|
555 |
|
556 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
557 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
558 */ |
|
559 { |
|
560 if (iStatus==KErrNone && aContinue) |
|
561 return new (ELeave) CPsdCreateContext(iSMObserver,iSM,iDbPsd); |
|
562 else |
|
563 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
564 } |
|
565 #endif // #ifndef INCOMING_NOT_SUPORTED |
|
566 |
|
567 CPsdCreateContext::CPsdCreateContext(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
568 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
569 /** |
|
570 Constructor |
|
571 */ |
|
572 { |
|
573 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
574 } |
|
575 |
|
576 CPsdCreateContext::~CPsdCreateContext() |
|
577 /** |
|
578 Destructor |
|
579 */ |
|
580 { |
|
581 Cancel(); |
|
582 } |
|
583 |
|
584 void CPsdCreateContext::StartState() |
|
585 /** |
|
586 Function called by the genconn state machine framework to start the state |
|
587 */ |
|
588 { |
|
589 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
590 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
591 |
|
592 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCreating context");) |
|
593 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
594 |
|
595 RPacketService& packetNetwork = iSM->PacketNetwork(); |
|
596 RPacketContext& context = iSM->Context(); |
|
597 |
|
598 TName name; |
|
599 TInt ret = context.OpenNewContext(packetNetwork,name); |
|
600 if (ret==KErrNone) |
|
601 { |
|
602 iSMObserver->UpdateProgress(EPsdStartingConfiguration,KErrNone); |
|
603 context.SetConfig(iStatus,iSM->Config().PackedConfig()); |
|
604 SetActive(); |
|
605 } |
|
606 else |
|
607 JumpToRunl(ret); |
|
608 } |
|
609 |
|
610 void CPsdCreateContext::RunL() |
|
611 /** |
|
612 Don't want to do any processing after SetConfig, just move to next state. |
|
613 |
|
614 Complete Connection for Create Context state. |
|
615 */ |
|
616 { |
|
617 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
618 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
619 |
|
620 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCompleted with error %d");) |
|
621 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),iStatus.Int()); |
|
622 |
|
623 if (iStatus==KErrNone) |
|
624 { |
|
625 // Have added new configure qos state that follows this one |
|
626 // therefore don't report config completion until that state has finished |
|
627 iSM->BaseEnv().CompleteState(KErrNone); |
|
628 } |
|
629 else |
|
630 { |
|
631 // There is now another configuration state so we are still in starting configuration now |
|
632 iSMObserver->ConnectionComplete(EPsdStartingConfiguration,iStatus.Int()); |
|
633 } |
|
634 } |
|
635 |
|
636 void CPsdCreateContext::DoCancel() |
|
637 /** |
|
638 Cancell Asynchronous request of create context state. |
|
639 */ |
|
640 { |
|
641 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
642 |
|
643 iSM->Context().CancelAsyncRequest(EPacketContextSetConfig); |
|
644 } |
|
645 |
|
646 CAgentStateBase* CPsdCreateContext::NextStateL(TBool aContinue) |
|
647 /** |
|
648 Called by the genconn state machine frame work to move the state machine to the next state |
|
649 function creates the next state in the state machine |
|
650 |
|
651 iStatus will be KErrNone if there has been no error so far. If the state has been cancelled, |
|
652 iStatus should be KErrCancel. (can we rely on this?) |
|
653 |
|
654 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
655 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
656 */ |
|
657 { |
|
658 if (iStatus==KErrNone && aContinue) |
|
659 // New state |
|
660 return new (ELeave) CPsdCreateQoS(iSMObserver,iSM,iDbPsd); |
|
661 else |
|
662 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
663 } |
|
664 |
|
665 CPsdCreateQoS::CPsdCreateQoS(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
666 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
667 /** |
|
668 Constructor |
|
669 */ |
|
670 { |
|
671 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
672 } |
|
673 |
|
674 CPsdCreateQoS::~CPsdCreateQoS() |
|
675 /** |
|
676 Destructor |
|
677 */ |
|
678 { |
|
679 Cancel(); |
|
680 } |
|
681 |
|
682 void CPsdCreateQoS::StartState() |
|
683 /** |
|
684 Function called by the genconn state machine framework to start the state |
|
685 */ |
|
686 { |
|
687 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
688 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
689 |
|
690 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCreating QoS");) |
|
691 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
692 |
|
693 RPacketContext& context = iSM->Context(); |
|
694 RPacketQoS& qoS = iSM->QoS(); |
|
695 |
|
696 TName name; |
|
697 TInt ret = qoS.OpenNewQoS(context,name); |
|
698 if (ret==KErrNone) |
|
699 { |
|
700 qoS.SetProfileParameters(iStatus,iSM->QoSConfig().PackedQoSConfig()); |
|
701 SetActive(); |
|
702 } |
|
703 else if (ret == KErrNotSupported)//the TSY doesn't support QoS -> flag it |
|
704 { |
|
705 iSM->SetQoSSupported(EFalse); |
|
706 JumpToRunl(KErrNone); |
|
707 } |
|
708 else |
|
709 JumpToRunl(ret); |
|
710 } |
|
711 |
|
712 void CPsdCreateQoS::RunL() |
|
713 /** |
|
714 Don't want to do any processing after SetProfileParameters, just move to next state. |
|
715 |
|
716 Complete Connection for Create QoS state. |
|
717 */ |
|
718 { |
|
719 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
720 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
721 |
|
722 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCompleted with error %d");) |
|
723 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),iStatus.Int()); |
|
724 |
|
725 if (iStatus==KErrNone) |
|
726 { |
|
727 iSMObserver->UpdateProgress(EPsdFinishedConfiguration,KErrNone); |
|
728 iSM->BaseEnv().CompleteState(KErrNone); |
|
729 } |
|
730 else |
|
731 iSMObserver->ConnectionComplete(EPsdFinishedConfiguration,iStatus.Int()); |
|
732 } |
|
733 |
|
734 void CPsdCreateQoS::DoCancel() |
|
735 /** |
|
736 Cancell Asynchronous request of create QoS state. |
|
737 */ |
|
738 { |
|
739 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
740 |
|
741 if(iSM->IsQoSSupported()) |
|
742 iSM->QoS().CancelAsyncRequest(EPacketQoSSetProfileParams); |
|
743 } |
|
744 |
|
745 CAgentStateBase* CPsdCreateQoS::NextStateL(TBool aContinue) |
|
746 /** |
|
747 Called by the genconn state machine frame work to move the state machine to the next state |
|
748 function creates the next state in the state machine |
|
749 |
|
750 iStatus will be KErrNone if there has been no error so far. If the state has been cancelled, |
|
751 iStatus should be KErrCancel. (can we rely on this?) |
|
752 |
|
753 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
754 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
755 */ |
|
756 { |
|
757 if (iStatus==KErrNone && aContinue) |
|
758 return new (ELeave) CPsdActivateContext(iSMObserver,iSM,iDbPsd); |
|
759 else |
|
760 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
761 } |
|
762 |
|
763 CPsdActivateContext::CPsdActivateContext(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
764 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
765 /** |
|
766 Constructor |
|
767 */ |
|
768 { |
|
769 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
770 } |
|
771 |
|
772 CPsdActivateContext::~CPsdActivateContext() |
|
773 /** |
|
774 Destructor |
|
775 */ |
|
776 { |
|
777 Cancel(); |
|
778 } |
|
779 |
|
780 void CPsdActivateContext::StartState() |
|
781 /** |
|
782 Function called by the genconn state machine framework to start the state |
|
783 */ |
|
784 { |
|
785 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
786 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
787 |
|
788 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tActivating context");) |
|
789 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
790 |
|
791 iSMObserver->UpdateProgress(EPsdStartingActivation,KErrNone); |
|
792 // Check if the context is already active since in the reconnect case it may be |
|
793 RPacketContext::TContextStatus contextStatus; |
|
794 iSM->Context().GetStatus(contextStatus); |
|
795 |
|
796 iSubState = EActivatingContext; |
|
797 if( !((contextStatus==RPacketContext::EStatusActive) |
|
798 ||(contextStatus==RPacketContext::EStatusSuspended) |
|
799 ||(contextStatus==RPacketContext::EStatusActivating)) ) |
|
800 { |
|
801 // Context not active so activate it |
|
802 iSM->Context().Activate(iStatus); |
|
803 SetActive(); |
|
804 } |
|
805 else |
|
806 { |
|
807 // Context already active so move to the RunL |
|
808 JumpToRunl(KErrNone); |
|
809 } |
|
810 } |
|
811 |
|
812 void CPsdActivateContext::RunL() |
|
813 /** |
|
814 Complete Connection for Activate Context state. |
|
815 */ |
|
816 { |
|
817 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
818 __ASSERT_DEBUG(iSMObserver,User::Invariant()); |
|
819 |
|
820 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCompleted with error %d");) |
|
821 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),iStatus.Int()); |
|
822 |
|
823 if( (iSubState==EActivatingContext&&(iStatus==KErrNone || iStatus==KErrNotSupported) ) |
|
824 ||(iSubState==ELoaningCommPort&&iStatus==KErrNone) ) |
|
825 { |
|
826 if(iSubState==EActivatingContext) |
|
827 { |
|
828 iSM->Context().LoanCommPort(iStatus,iCommport); |
|
829 SetActive(); |
|
830 iSubState=ELoaningCommPort; |
|
831 } |
|
832 else |
|
833 { |
|
834 // Substate == ELoaningCommPort |
|
835 TRAPD(ret,iSM->BaseEnv().Db()->SetCommPortL(iCommport)); |
|
836 if (ret!=KErrNone) |
|
837 { |
|
838 iStatus=ret; |
|
839 iSMObserver->ConnectionComplete(EPsdFinishedActivation,iStatus.Int()); |
|
840 } |
|
841 else |
|
842 { |
|
843 iSMObserver->UpdateProgress(EPsdFinishedActivation,KErrNone);// may want to do this when it really |
|
844 // activates |
|
845 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tHanding control to PPP");) |
|
846 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
847 |
|
848 iSMObserver->ServiceStarted(); |
|
849 iSM->BaseEnv().CompleteState(KErrNone); |
|
850 } |
|
851 } |
|
852 } |
|
853 else |
|
854 iSMObserver->ConnectionComplete(EPsdFinishedActivation,iStatus.Int()); |
|
855 } |
|
856 |
|
857 void CPsdActivateContext::DoCancel() |
|
858 /** |
|
859 Cancell Asynchronous request of activate context state. |
|
860 */ |
|
861 { |
|
862 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
863 |
|
864 iSM->Context().CancelAsyncRequest(EPacketContextActivate); |
|
865 } |
|
866 |
|
867 CAgentStateBase* CPsdActivateContext::NextStateL(TBool aContinue) |
|
868 /** |
|
869 Called by the genconn state machine frame work to move the state machine to the next state |
|
870 function creates the next state in the state machine |
|
871 |
|
872 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
873 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
874 */ |
|
875 { |
|
876 if (iStatus==KErrNone && aContinue) |
|
877 return CPsdOpen::NewL(iSMObserver,iSM,iDbPsd); |
|
878 else |
|
879 return new (ELeave) CPsdRecoverCommPort(iSMObserver,iSM,iDbPsd); |
|
880 } |
|
881 |
|
882 CPsdOpen* CPsdOpen::NewL(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
883 /** |
|
884 Constructing an object of class CPsdOpen,pushing it to the clean up stack and popping it out. |
|
885 */ |
|
886 { |
|
887 CPsdOpen* state = new (ELeave) CPsdOpen(aObserver,aPsdSM,aDb); |
|
888 CleanupStack::PushL(state); |
|
889 state->ConstructL(); |
|
890 CleanupStack::Pop(); |
|
891 return state; |
|
892 } |
|
893 |
|
894 CPsdOpen::CPsdOpen(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
895 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
896 /** |
|
897 Constructor |
|
898 */ |
|
899 { |
|
900 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
901 } |
|
902 |
|
903 void CPsdOpen::ConstructL() |
|
904 /** |
|
905 2nd Phase Construction |
|
906 */ |
|
907 {} |
|
908 |
|
909 CPsdOpen::~CPsdOpen() |
|
910 /** |
|
911 Destructor |
|
912 */ |
|
913 { |
|
914 delete iContextChangeMonitor; |
|
915 Cancel(); |
|
916 } |
|
917 |
|
918 void CPsdOpen::StartState() |
|
919 /** |
|
920 Function called by the genconn state machine framework to start the state |
|
921 */ |
|
922 { |
|
923 __ASSERT_DEBUG(iSM && iSMObserver,User::Invariant()); |
|
924 |
|
925 |
|
926 iSM->Context().GetStatus(iContextStatus); |
|
927 |
|
928 if (iContextStatus==RPacketContext::EStatusActive) |
|
929 { |
|
930 LogActive(); |
|
931 TRAPD(err,WatchForConfigChangesL()); |
|
932 if(err != KErrNone) |
|
933 { |
|
934 iSMObserver->ConnectionComplete(KConnectionOpen,err); |
|
935 return; |
|
936 } |
|
937 } |
|
938 |
|
939 //Either, we've successfully handled the active state or we have to |
|
940 //wait for TSY to tell us it has become active. This is because calling Activate() |
|
941 //doesn't necessarily mean it's activated in the network - have to wait for PPP to do its |
|
942 //stuff. |
|
943 RequestStatusChange(); |
|
944 |
|
945 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tCalling ConnectionComplete");) |
|
946 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1()); |
|
947 |
|
948 iSMObserver->Notification(EAgentToNifEventTypeModifyInitialTimer,NULL); |
|
949 iSMObserver->UpdateProgress(KConnectionOpen,KErrNone); // I think NIFMAN just swallows this after |
|
950 // a ConnectComplete(Open) |
|
951 iSMObserver->ConnectionComplete(KConnectionOpen,KErrNone); |
|
952 } |
|
953 |
|
954 void CPsdOpen::LogActive() |
|
955 /** |
|
956 This internal function starts the logging and also starts watching for the connection quality |
|
957 dropping below minimum acceptable values |
|
958 |
|
959 This is called every time state goes to Active. Only want to log the first time, as |
|
960 ensuing times it could be a Suspended->Active transition. |
|
961 */ |
|
962 { |
|
963 if (!iEventLoggerStarted) |
|
964 { |
|
965 TBuf<KCommsDbSvrMaxFieldLength> remoteParty; |
|
966 remoteParty.Zero(); |
|
967 TRAPD(err, iDbPsd->GetRemotePartyL(remoteParty)); |
|
968 // logg err |
|
969 if(err != KErrNone) |
|
970 { |
|
971 #ifdef __FLOG_ACTIVE |
|
972 _LIT8(logString1,"CPsdOpen:\t Error in getting remote party %d."); |
|
973 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),err); |
|
974 #endif |
|
975 } |
|
976 iEventLoggerStarted = ETrue; |
|
977 if (!iSM->BaseEnv().IsReconnect()) |
|
978 { |
|
979 if (iSM->Direction()==ECommDbConnectionDirectionOutgoing) |
|
980 iSM->Logger()->LogDataAddEvent(R_LOG_CON_CONNECTED, remoteParty,R_LOG_DIR_OUT,KNullDesC,KLogPacketDataEventTypeUid); |
|
981 else |
|
982 iSM->Logger()->LogDataAddEvent(R_LOG_CON_CONNECTED, remoteParty,R_LOG_DIR_IN,KNullDesC,KLogPacketDataEventTypeUid); |
|
983 iSM->DataLogger()->Start(); |
|
984 } |
|
985 else |
|
986 { |
|
987 //the logevent is already existing, we just have reconnected then update the status of the connection |
|
988 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_CONNECTED, KLogPacketDataEventTypeUid); |
|
989 // no need to start again the datalogger since it has not been stopped previously |
|
990 } |
|
991 } |
|
992 } |
|
993 |
|
994 void CPsdOpen::WatchForConfigChangesL() |
|
995 /** |
|
996 Watch for Configuration changes in the open state |
|
997 */ |
|
998 { |
|
999 // Should only be called once the context is active |
|
1000 if(!iContextChangeMonitor) |
|
1001 { |
|
1002 //start watching for changes in the context status |
|
1003 iContextChangeMonitor = CPsdContextChangeMonitor::NewL(iSM,this); |
|
1004 } |
|
1005 } |
|
1006 |
|
1007 void CPsdOpen::RequestStatusChange() |
|
1008 /** |
|
1009 Request for the change of status in the open state. |
|
1010 */ |
|
1011 { |
|
1012 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
1013 |
|
1014 iSM->Context().NotifyStatusChange(iStatus,iContextStatus); |
|
1015 SetActive(); |
|
1016 } |
|
1017 |
|
1018 void CPsdOpen::RunL() |
|
1019 /** |
|
1020 No need for this state ever to call CompleteState(), because we are expecting the state |
|
1021 machine to be told to Disconnect from above, which means this state will have NextStateL() |
|
1022 called on it. |
|
1023 |
|
1024 Update progress for open state. |
|
1025 */ |
|
1026 { |
|
1027 __ASSERT_DEBUG(iSM && iSMObserver,User::Invariant()); |
|
1028 |
|
1029 __FLOG_STMT(_LIT8(logString1,"PacketData:\tStatus change to %s\0");) |
|
1030 |
|
1031 if (iStatus==KErrNone) |
|
1032 { |
|
1033 switch (iContextStatus) |
|
1034 { |
|
1035 case RPacketContext::EStatusSuspended: |
|
1036 { |
|
1037 __FLOG_STMT(const TText8 value[] = "suspended";) |
|
1038 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1039 iSMObserver->Notification(EAgentToNifEventTypeDisableTimers,NULL); |
|
1040 iSMObserver->UpdateProgress(EPsdSuspended,KErrNone); |
|
1041 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_SUSPENDED, KLogPacketDataEventTypeUid); |
|
1042 RequestStatusChange(); |
|
1043 } |
|
1044 break; |
|
1045 case RPacketContext::EStatusActive: |
|
1046 { |
|
1047 // if reconnect happened then the logger is allready started and we just do an update |
|
1048 if (!iEventLoggerStarted) |
|
1049 { |
|
1050 __FLOG_STMT(const TText8 value[] = "log active";) |
|
1051 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1052 WatchForConfigChangesL(); //those 2 functions should have been called in start state but |
|
1053 LogActive(); //RPacketContext was not EStatusActive at that time |
|
1054 } |
|
1055 else // the LogCallStart() has completed |
|
1056 { |
|
1057 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_CONNECTED, KLogPacketDataEventTypeUid); |
|
1058 __FLOG_STMT(const TText8 value[] = "active";) |
|
1059 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1060 } |
|
1061 iSMObserver->Notification(EAgentToNifEventTypeEnableTimers,NULL); |
|
1062 iSMObserver->UpdateProgress(KConnectionOpen,KErrNone); |
|
1063 RequestStatusChange(); |
|
1064 } |
|
1065 break; |
|
1066 case RPacketContext::EStatusDeactivating: |
|
1067 { |
|
1068 __FLOG_STMT(const TText8 value[] = "deactivating";) |
|
1069 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1070 iSMObserver->UpdateProgress(EPsdStartingDeactivation,KErrNone); |
|
1071 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_DISCONNECTING, KLogPacketDataEventTypeUid); |
|
1072 RequestStatusChange(); |
|
1073 } |
|
1074 break; |
|
1075 case RPacketContext::EStatusInactive: |
|
1076 { |
|
1077 __FLOG_STMT(const TText8 value[] = "inactive";) |
|
1078 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1079 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_DISCONNECTED, KLogPacketDataEventTypeUid); |
|
1080 } |
|
1081 break; |
|
1082 case RPacketContext::EStatusDeleted: |
|
1083 { |
|
1084 __FLOG_STMT(const TText8 value[] = "deleted";) |
|
1085 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1086 iSMObserver->UpdateProgress(EPsdFinishedDeactivation,KErrNone); |
|
1087 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_DISCONNECTED, KLogPacketDataEventTypeUid); |
|
1088 } |
|
1089 break; |
|
1090 case RPacketContext::EStatusActivating: |
|
1091 { |
|
1092 __FLOG_STMT(const TText8 value[] = "activating";) |
|
1093 __FLOG_STATIC1(KPsdAgxLogFolder(),KPsdAgxLogFile(),TRefByValue<const TDesC8>(logString1()),&value); |
|
1094 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_CONNECTING, KLogPacketDataEventTypeUid); |
|
1095 RequestStatusChange(); |
|
1096 } |
|
1097 break; |
|
1098 default: |
|
1099 PanicAgt(EPsdUnknownContextState); |
|
1100 break; |
|
1101 }; |
|
1102 } |
|
1103 // no way to signal upwards that there's been an error. |
|
1104 // Have to rely on the agent's client to close down, or PPP to detect it's gone down |
|
1105 } |
|
1106 |
|
1107 void CPsdOpen::DoCancel() |
|
1108 /** |
|
1109 The SM shouldn't call Cancel() on us because CancelConnect can never be called on it. |
|
1110 But we must Cancel ourselves when leaving the state. |
|
1111 |
|
1112 Cancell Asynchronous request of open state. |
|
1113 */ |
|
1114 { |
|
1115 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
1116 // the only pending request is RequestStatusChange, do not cancel the logging request which is in the queue. |
|
1117 iSM->Context().CancelAsyncRequest(EPacketContextNotifyStatusChange); |
|
1118 } |
|
1119 |
|
1120 CAgentStateBase* CPsdOpen::NextStateL(TBool /*aContinue*/) |
|
1121 /** |
|
1122 Called by the genconn state machine frame work to move the state machine to the next state |
|
1123 function creates the next state in the state machine |
|
1124 |
|
1125 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
1126 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
1127 */ |
|
1128 { |
|
1129 Cancel(); |
|
1130 return new (ELeave) CPsdRecoverCommPort(iSMObserver,iSM,iDbPsd); |
|
1131 } |
|
1132 |
|
1133 void CPsdOpen::ReportContextBelowAcceptableQuality() |
|
1134 /** |
|
1135 Callback function from CPsdContextChangeMonitor object |
|
1136 when called launches a dialog to inform the user that the |
|
1137 connection has dropped below acceptable quality |
|
1138 */ |
|
1139 { |
|
1140 // The connection has gone below the acceptable level of quality |
|
1141 // so put up a dialog asking the user what they want to do |
|
1142 iSM->BaseEnv().DlgPrc()->QoSWarning(*this); |
|
1143 } |
|
1144 |
|
1145 void CPsdOpen::MDPOQoSWarningComplete(TInt aError, TBool aResponse) |
|
1146 /** |
|
1147 Callback from the QoS warning dialog |
|
1148 |
|
1149 @param TInt aError indication if an error occured in the dialog |
|
1150 @param TBool flag indicating the response from the dialog. ETrue means disconnect |
|
1151 */ |
|
1152 { |
|
1153 // Callback from the QoS warning dialog |
|
1154 // aResponse == True means disconnect |
|
1155 if((aResponse)&&(aError == KErrNone)) |
|
1156 { |
|
1157 // Disconnect |
|
1158 // Request Nifman to disconnect |
|
1159 iSMObserver->Notification(EAgentToNifEventTypeDisableConnection,NULL); |
|
1160 } |
|
1161 } |
|
1162 |
|
1163 void CPsdOpen::ReportError(TInt aError) |
|
1164 /** |
|
1165 Report error in open state. |
|
1166 |
|
1167 @param aError, error code for error occurs during open state. |
|
1168 */ |
|
1169 { |
|
1170 JumpToRunl(aError); |
|
1171 } |
|
1172 |
|
1173 |
|
1174 CPsdRecoverCommPort::CPsdRecoverCommPort(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
1175 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
1176 /** |
|
1177 Constructor |
|
1178 */ |
|
1179 { |
|
1180 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
1181 } |
|
1182 |
|
1183 CPsdRecoverCommPort::~CPsdRecoverCommPort() |
|
1184 /** |
|
1185 Destructor |
|
1186 */ |
|
1187 { |
|
1188 Cancel(); |
|
1189 } |
|
1190 |
|
1191 void CPsdRecoverCommPort::StartState() |
|
1192 /** |
|
1193 Function called by the genconn state machine framework to start the state |
|
1194 */ |
|
1195 { |
|
1196 __ASSERT_DEBUG(iSM && iSMObserver,User::Invariant()); |
|
1197 |
|
1198 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tRecovering Comm Port to ETel");) |
|
1199 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
1200 |
|
1201 iSMObserver->UpdateProgress(EPsdStartingDeactivation,KErrNone); |
|
1202 iSM->Context().RecoverCommPort(iStatus); |
|
1203 SetActive(); |
|
1204 } |
|
1205 |
|
1206 void CPsdRecoverCommPort::RunL() |
|
1207 /** |
|
1208 Complete state for Recover comm port state. |
|
1209 */ |
|
1210 { |
|
1211 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
1212 // what can we do with errors at this stage in the game? |
|
1213 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tRecovered Comm Port");) |
|
1214 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
1215 |
|
1216 iSM->BaseEnv().CompleteState(KErrNone); |
|
1217 } |
|
1218 |
|
1219 void CPsdRecoverCommPort::DoCancel() |
|
1220 /** |
|
1221 Cancell Asynchronous request of comm port state. |
|
1222 */ |
|
1223 { |
|
1224 iSM->Context().CancelAsyncRequest(EPacketContextRecoverCommPort); |
|
1225 } |
|
1226 |
|
1227 CAgentStateBase* CPsdRecoverCommPort::NextStateL(TBool /*aContinue*/) |
|
1228 /** |
|
1229 Called by the genconn state machine frame work to move the state machine to the next state |
|
1230 function creates the next state in the state machine |
|
1231 |
|
1232 Ignoring aContinue because the end is in sight now. |
|
1233 If the SM has been asked to reconnect by PPP, we need to go back and |
|
1234 activate the context again. |
|
1235 |
|
1236 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
1237 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
1238 */ |
|
1239 { |
|
1240 if (iSM->BaseEnv().IsReconnect()) |
|
1241 { |
|
1242 return new (ELeave) CPsdActivateContext(iSMObserver,iSM,iDbPsd); |
|
1243 } |
|
1244 else |
|
1245 { |
|
1246 iSM->Logger()->LogDataUpdateEvent(R_LOG_CON_DISCONNECTED, KLogPacketDataEventTypeUid); |
|
1247 // request to update and close log |
|
1248 iSM->DataLogger()->StopL(); |
|
1249 return new (ELeave) CPsdCloseLog(iSMObserver,iSM,iDbPsd); |
|
1250 } |
|
1251 } |
|
1252 |
|
1253 // |
|
1254 // |
|
1255 // CPsdCloseLog |
|
1256 // |
|
1257 // This class ensures that the asynchronous "final data transfer logging" completes |
|
1258 // before the asynchronous Log Call End happens. |
|
1259 |
|
1260 CPsdCloseLog::CPsdCloseLog(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
1261 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
1262 /** |
|
1263 Constructor |
|
1264 */ |
|
1265 { |
|
1266 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
1267 } |
|
1268 |
|
1269 CPsdCloseLog::~CPsdCloseLog() |
|
1270 /** |
|
1271 Destructor |
|
1272 */ |
|
1273 { |
|
1274 Cancel(); |
|
1275 } |
|
1276 |
|
1277 void CPsdCloseLog::StartState() |
|
1278 /** |
|
1279 Function called by the genconn state machine framework to start the state |
|
1280 */ |
|
1281 { |
|
1282 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tClosing Log");) |
|
1283 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1()); |
|
1284 // We need to make sure that logging is finished before closing everything. |
|
1285 // forward iStatus to the logger, which will be responsible to complete iStatus when it is finished. |
|
1286 iStatus = KRequestPending; |
|
1287 SetActive(); |
|
1288 iSM->Logger()->LogDataNotifyLastEventUpdate(&iStatus); |
|
1289 } |
|
1290 |
|
1291 void CPsdCloseLog::RunL() |
|
1292 /** |
|
1293 Complete state for Close Log state. |
|
1294 */ |
|
1295 { |
|
1296 iSM->BaseEnv().CompleteState(KErrNone); |
|
1297 } |
|
1298 |
|
1299 void CPsdCloseLog::DoCancel() |
|
1300 /** |
|
1301 Cancell Asynchronous request of close log state. |
|
1302 */ |
|
1303 { |
|
1304 iSM->Logger()->Cancel(); //cancel because we will delete everything |
|
1305 } |
|
1306 |
|
1307 CAgentStateBase* CPsdCloseLog::NextStateL(TBool /*aContinue*/) |
|
1308 /** |
|
1309 Called by the genconn state machine frame work to move the state machine to the next state |
|
1310 function creates the next state in the state machine |
|
1311 |
|
1312 Ignoring aContinue because the end is in sight now. |
|
1313 If the context is still active, SM moves to Deactivation state |
|
1314 otherwise proceed to Closure state |
|
1315 |
|
1316 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
1317 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
1318 */ |
|
1319 { |
|
1320 RPacketContext::TContextStatus contextstatus; |
|
1321 iSM->Context().GetStatus(contextstatus); |
|
1322 if (contextstatus==RPacketContext::EStatusActive || contextstatus==RPacketContext::EStatusSuspended) |
|
1323 return new (ELeave) CPsdDeactivation(iSMObserver,iSM,iDbPsd); |
|
1324 else |
|
1325 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
1326 } |
|
1327 |
|
1328 CPsdDeactivation::CPsdDeactivation(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
1329 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
1330 /** |
|
1331 Constructor |
|
1332 */ |
|
1333 { |
|
1334 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
1335 } |
|
1336 |
|
1337 CPsdDeactivation::~CPsdDeactivation() |
|
1338 /** |
|
1339 Destructor |
|
1340 */ |
|
1341 { |
|
1342 Cancel(); |
|
1343 } |
|
1344 |
|
1345 void CPsdDeactivation::StartState() |
|
1346 /** |
|
1347 Function called by the genconn state machine framework to start the state |
|
1348 */ |
|
1349 { |
|
1350 __ASSERT_DEBUG(iSM,User::Invariant()); |
|
1351 |
|
1352 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tDeactivating Context");) |
|
1353 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
1354 |
|
1355 iSM->Context().Deactivate(iStatus); |
|
1356 SetActive(); |
|
1357 } |
|
1358 |
|
1359 void CPsdDeactivation::RunL() |
|
1360 /** |
|
1361 Complete state for deactivation state. |
|
1362 */ |
|
1363 { |
|
1364 __ASSERT_DEBUG(iSM && iSMObserver,User::Invariant()); |
|
1365 |
|
1366 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tDeactivated Context");) |
|
1367 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
1368 |
|
1369 iSMObserver->UpdateProgress(EPsdFinishedDeactivation,KErrNone); |
|
1370 iSM->BaseEnv().CompleteState(KErrNone); |
|
1371 |
|
1372 } |
|
1373 |
|
1374 void CPsdDeactivation::DoCancel() |
|
1375 /** |
|
1376 Cancell Asynchronous request of deactivation state. |
|
1377 */ |
|
1378 { |
|
1379 iSM->Context().CancelAsyncRequest(EPacketContextDeactivate); |
|
1380 } |
|
1381 |
|
1382 CAgentStateBase* CPsdDeactivation::NextStateL(TBool /*aContinue*/) |
|
1383 /** |
|
1384 Called by the genconn state machine frame work to move the state machine to the next state |
|
1385 function creates the next state in the state machine |
|
1386 |
|
1387 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
1388 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
1389 */ |
|
1390 { |
|
1391 return new (ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
1392 } |
|
1393 |
|
1394 // |
|
1395 // |
|
1396 // CPsdClosure |
|
1397 // |
|
1398 |
|
1399 CPsdClosure::CPsdClosure(MAgentStateMachineEnv* aObserver,MPsdEnv* aPsdSM, MPsdCommDbAccess* aDb) |
|
1400 : CAgentStateBase(*aObserver),iSM(aPsdSM),iDbPsd(aDb) |
|
1401 /** |
|
1402 Constructor |
|
1403 */ |
|
1404 { |
|
1405 __ASSERT_DEBUG(aObserver&&aPsdSM&&aDb, User::Invariant()); |
|
1406 } |
|
1407 |
|
1408 CPsdClosure::~CPsdClosure() |
|
1409 /** |
|
1410 Destructor |
|
1411 */ |
|
1412 { |
|
1413 Cancel(); |
|
1414 } |
|
1415 |
|
1416 void CPsdClosure::StartState() |
|
1417 /** |
|
1418 Function called by the genconn state machine framework to start the state |
|
1419 */ |
|
1420 { |
|
1421 iSubState = EClosureStart; |
|
1422 JumpToRunl(KErrNone); |
|
1423 } |
|
1424 |
|
1425 void CPsdClosure::RunL() |
|
1426 /** |
|
1427 Complete Disconnection for closure state. |
|
1428 */ |
|
1429 { |
|
1430 __ASSERT_DEBUG(iSM && iSMObserver,User::Invariant()); |
|
1431 |
|
1432 __FLOG_STMT(_LIT8(logString1,"Packet Data:\tClosing down");) |
|
1433 __FLOG_STATIC(KPsdAgxLogFolder(),KPsdAgxLogFile(),logString1); |
|
1434 |
|
1435 RTelServer& etel = iSM->TelServer(); |
|
1436 RPhone& phone = iSM->Phone(); |
|
1437 RPacketService& packetNetwork = iSM->PacketNetwork(); |
|
1438 RPacketContext& context = iSM->Context(); |
|
1439 RPacketQoS& qoS = iSM->QoS(); |
|
1440 |
|
1441 if(iSubState == EClosureStart) |
|
1442 { |
|
1443 if (qoS.SubSessionHandle()!=0) |
|
1444 { |
|
1445 qoS.Close(); |
|
1446 } |
|
1447 |
|
1448 if (context.SubSessionHandle()!=0) |
|
1449 { |
|
1450 TInt aError=KErrNone; |
|
1451 if (context.GetLastErrorCause(aError)==KErrNone) |
|
1452 iSM->ErrorCause()=aError; |
|
1453 iSubState = EDeletingContext; |
|
1454 context.Delete(iStatus); |
|
1455 SetActive(); |
|
1456 return; // break out and wait for delete to complete |
|
1457 } |
|
1458 else |
|
1459 { |
|
1460 // Advance to end sub state |
|
1461 iSubState = EClosureEnd; |
|
1462 } |
|
1463 } |
|
1464 if(iSubState == EDeletingContext) |
|
1465 { |
|
1466 // context delete completed so now close it down |
|
1467 context.Close(); |
|
1468 // Advance to end sub state |
|
1469 iSubState = EClosureEnd; |
|
1470 } |
|
1471 // Intentional fallthrough |
|
1472 if(iSubState == EClosureEnd) |
|
1473 { |
|
1474 packetNetwork.Close(); |
|
1475 phone.Close(); |
|
1476 if(iSM->TsyLoaded()) |
|
1477 { |
|
1478 TBuf<KCommsDbSvrMaxFieldLength> tsyName; |
|
1479 iSM->BaseEnv().Db()->GetTsyNameL(tsyName); |
|
1480 User::LeaveIfError(etel.UnloadPhoneModule(tsyName)); |
|
1481 iSM->SetTsyLoaded(EFalse); |
|
1482 } |
|
1483 etel.Close(); // Phone module unloaded automatically |
|
1484 iSMObserver->DisconnectComplete(); |
|
1485 } |
|
1486 } |
|
1487 |
|
1488 void CPsdClosure::DoCancel() |
|
1489 /** |
|
1490 Cancell Asynchronous request of closure state. |
|
1491 */ |
|
1492 {} |
|
1493 |
|
1494 CAgentStateBase* CPsdClosure::NextStateL(TBool /*aContinue*/) |
|
1495 /** |
|
1496 Called by the genconn state machine frame work to move the state machine to the next state |
|
1497 function creates the next state in the state machine |
|
1498 |
|
1499 @param TBool aContinue flag indicating if the state machine wishes to continue the connection or close it down |
|
1500 @return CAgentStateBase* pointer to the next state in the state machine the calling function takes ownership of the returned object |
|
1501 */ |
|
1502 { |
|
1503 return new(ELeave) CPsdClosure(iSMObserver,iSM,iDbPsd); |
|
1504 } |