|
1 // Copyright (c) 2000-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 // Source for Base classes in States and State Machines |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "CAgentSMBase.h" |
|
23 #include "AgentPanic.h" |
|
24 #include <connectprog.h> |
|
25 |
|
26 // |
|
27 // Agent State Base |
|
28 // |
|
29 |
|
30 EXPORT_C CAgentStateBase::CAgentStateBase(MAgentStateMachineEnv& aSMObserver) |
|
31 : CActive(EPriorityStandard),iSMObserver(&aSMObserver) |
|
32 /** |
|
33 Constructor |
|
34 */ |
|
35 { |
|
36 CActiveScheduler::Add(this); |
|
37 } |
|
38 |
|
39 EXPORT_C CAgentStateBase::~CAgentStateBase() |
|
40 /** |
|
41 Destructor |
|
42 */ |
|
43 { |
|
44 Cancel(); |
|
45 } |
|
46 |
|
47 EXPORT_C void CAgentStateBase::JumpToRunl(TInt aError) |
|
48 /** |
|
49 * Jump directly to the RunL of the object |
|
50 * @note Typically used in the case of errors, or when asynchronous requests do not need to be issued by this state |
|
51 */ |
|
52 { |
|
53 SetActive(); |
|
54 TRequestStatus* statusPtr=&iStatus; |
|
55 User::RequestComplete(statusPtr,aError); |
|
56 } |
|
57 |
|
58 // |
|
59 // Agent State Machine Base |
|
60 // |
|
61 |
|
62 EXPORT_C CAgentSMBase::CAgentSMBase(MAgentNotify& aControllerObserver, CDialogProcessor* aDlgPrc, CCommsDbAccess& aDbAccess) |
|
63 : CActive(EPriorityStandard),iControllerObserver(&aControllerObserver),iDlgPrc(aDlgPrc), |
|
64 iDb(&aDbAccess),iContinueConnection(ETrue),iSMPhase(EConnecting) |
|
65 /** |
|
66 Constructor |
|
67 |
|
68 @param aControllerObserver |
|
69 @param aDlgPrc |
|
70 @param aDbAccess |
|
71 */ |
|
72 { |
|
73 CActiveScheduler::Add(this); |
|
74 } |
|
75 |
|
76 EXPORT_C CAgentSMBase::~CAgentSMBase() |
|
77 /** |
|
78 Destructor |
|
79 */ |
|
80 { |
|
81 Cancel(); |
|
82 delete iState; |
|
83 } |
|
84 |
|
85 void CAgentSMBase::ProcessState() |
|
86 { |
|
87 CAgentStateBase* nextiState=NULL; |
|
88 TRAPD(ret,nextiState=iState->NextStateL(iContinueConnection)); |
|
89 iContinueConnection=ETrue; |
|
90 if(ret==KErrNone) // Next state instantiated succesfully |
|
91 { |
|
92 __ASSERT_DEBUG(nextiState, StateMachineAgentPanic(Agent::ENullStateOnProcessState)); |
|
93 delete iState; |
|
94 iState=nextiState; |
|
95 iStatus=KRequestPending; |
|
96 iState->StartState(); |
|
97 if (!IsActive()) |
|
98 SetActive(); |
|
99 } |
|
100 else |
|
101 CompleteState(ret); |
|
102 } |
|
103 |
|
104 void CAgentSMBase::StartConnect() |
|
105 { |
|
106 iStatus = KRequestPending; |
|
107 iState->StartState(); |
|
108 SetActive(); |
|
109 } |
|
110 |
|
111 void CAgentSMBase::CancelConnect() |
|
112 { |
|
113 iContinueConnection=EFalse; |
|
114 Cancel(); |
|
115 } |
|
116 |
|
117 EXPORT_C void CAgentSMBase::ConnectionContinuation(TSMContinueConnectType aConnectionAction) |
|
118 { |
|
119 switch(aConnectionAction) |
|
120 { |
|
121 case ECallBack : |
|
122 iCallBack=ETrue; |
|
123 iSMPhase=EConnecting; |
|
124 break; |
|
125 case EReconnect : |
|
126 iIsReconnect=ETrue; |
|
127 iCallBack=EFalse; |
|
128 iSMPhase=EConnecting; |
|
129 break; |
|
130 case EDisconnect : |
|
131 iContinueConnection=EFalse; |
|
132 iSMPhase=EDisconnecting; |
|
133 break; |
|
134 default : |
|
135 AgentPanic(Agent::EIllegalActionType); |
|
136 break; |
|
137 } |
|
138 ProcessState(); |
|
139 } |
|
140 |
|
141 EXPORT_C void CAgentSMBase::PreventConnectionRetries() |
|
142 { |
|
143 iControllerObserver->PreventConnectionRetries(); |
|
144 } |
|
145 |
|
146 EXPORT_C void CAgentSMBase::ServiceStarted() |
|
147 { |
|
148 if(!iIsReconnect&&!iCallBack) |
|
149 { |
|
150 iControllerObserver->ServiceStarted(); |
|
151 } |
|
152 } |
|
153 |
|
154 void CAgentSMBase::ConnectCompleteReset() |
|
155 { |
|
156 iSMPhase=EConnected; |
|
157 Cancel(); |
|
158 iIsReconnect=EFalse; |
|
159 } |
|
160 |
|
161 EXPORT_C void CAgentSMBase::ConnectionComplete(TInt aProgress,TInt aError) |
|
162 { |
|
163 ConnectCompleteReset(); |
|
164 iControllerObserver->ConnectionComplete(aProgress, aError); |
|
165 } |
|
166 |
|
167 EXPORT_C void CAgentSMBase::ConnectionComplete(TInt aError) |
|
168 { |
|
169 ConnectCompleteReset(); |
|
170 iControllerObserver->ConnectionComplete(aError); |
|
171 } |
|
172 |
|
173 EXPORT_C void CAgentSMBase::DisconnectComplete() |
|
174 { |
|
175 Cancel(); |
|
176 iSMPhase=EDisconnected; |
|
177 iCallBack=EFalse; |
|
178 iControllerObserver->DisconnectComplete(); |
|
179 } |
|
180 |
|
181 EXPORT_C void CAgentSMBase::UpdateProgress(TInt aProgress,TInt aError) |
|
182 { |
|
183 iControllerObserver->UpdateProgress(aProgress, aError); |
|
184 } |
|
185 |
|
186 EXPORT_C TInt CAgentSMBase::Notification(TAgentToNifEventType aEvent, TAny* aInfo) |
|
187 { |
|
188 return iControllerObserver->Notification(aEvent, aInfo); |
|
189 } |
|
190 |
|
191 EXPORT_C void CAgentSMBase::GetLastError(TInt& aError) |
|
192 /** |
|
193 Gets the latest error code returned during a connection operation. |
|
194 |
|
195 @param aError |
|
196 @return KErrNone, or another error code that might have been |
|
197 returned by a connection operation. |
|
198 */ |
|
199 { |
|
200 aError=KErrNone; |
|
201 } |
|
202 |
|
203 EXPORT_C TInt CAgentSMBase::IncomingConnectionReceived() |
|
204 { |
|
205 return iControllerObserver->IncomingConnectionReceived(); |
|
206 } |
|
207 |
|
208 EXPORT_C void CAgentSMBase::RunL() |
|
209 { |
|
210 if(iStatus==KErrNone) |
|
211 { |
|
212 ProcessState(); |
|
213 } |
|
214 else if(iSMPhase==EConnecting) |
|
215 { |
|
216 ConnectionComplete(iStatus.Int()); |
|
217 } |
|
218 else if(iSMPhase==EDisconnecting) |
|
219 { |
|
220 DisconnectComplete(); |
|
221 } |
|
222 } |
|
223 |
|
224 EXPORT_C void CAgentSMBase::DoCancel() |
|
225 { |
|
226 iState->Cancel(); |
|
227 if(iStatus==KRequestPending) |
|
228 { |
|
229 CompleteState(KErrCancel); |
|
230 } |
|
231 } |
|
232 |
|
233 EXPORT_C CDialogProcessor* CAgentSMBase::DlgPrc() |
|
234 { |
|
235 return iDlgPrc; |
|
236 } |
|
237 |
|
238 EXPORT_C CCommsDbAccess* CAgentSMBase::Db() |
|
239 { |
|
240 return iDb; |
|
241 } |
|
242 |
|
243 EXPORT_C void CAgentSMBase::CompleteState(TInt aError) |
|
244 { |
|
245 if (!IsActive()) |
|
246 SetActive(); |
|
247 TRequestStatus* status=&iStatus; |
|
248 User::RequestComplete(status,aError); |
|
249 } |
|
250 |
|
251 |