|
1 // Copyright (c) 2006-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 // This file provides the implementation of the class for |
|
15 // the X3P protocol state handler |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 @released |
|
23 */ |
|
24 |
|
25 #include "cx3pstatemachine.h" |
|
26 #include "cx3pstatehandler.h" |
|
27 |
|
28 |
|
29 /** Static constructor. |
|
30 @param aMachine A reference to the parent state machine. |
|
31 @return A new instance of the CX3pStateHandler class |
|
32 */ |
|
33 CX3pStateHandler* CX3pStateHandler::NewL(CStateMachineBase& aMachine) |
|
34 { |
|
35 CX3pStateHandler* self = new (ELeave) CX3pStateHandler(aMachine); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 /** Standard constructor. |
|
44 @param aMachine A reference to the parent state machine. |
|
45 */ |
|
46 CX3pStateHandler::CX3pStateHandler(CStateMachineBase& aMachine) |
|
47 : CStateHandlerBase(aMachine) |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 /** Standard destructor. |
|
53 */ |
|
54 CX3pStateHandler::~CX3pStateHandler() |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 /** Private second-stage constructor. |
|
60 */ |
|
61 void CX3pStateHandler::ConstructL() |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 /** Initialise state attributes |
|
67 */ |
|
68 void CX3pStateHandler::Initialise() |
|
69 { |
|
70 } |
|
71 |
|
72 |
|
73 /** Perform entry actions. |
|
74 This is called from the state machine to perform any actions |
|
75 associated with entering the current state. |
|
76 */ |
|
77 void CX3pStateHandler::EntryActions() |
|
78 { |
|
79 CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone; |
|
80 |
|
81 // Retrieve current state and act accordingly |
|
82 CX3pStateMachine& x3pMachine = reinterpret_cast <CX3pStateMachine&> (iMachine); |
|
83 switch(x3pMachine.CurrentState()) |
|
84 { |
|
85 |
|
86 case CX3pStateMachine::EStateNull: |
|
87 break; |
|
88 |
|
89 case CX3pStateMachine::EStateClientReqRecvd: |
|
90 // No action required |
|
91 break; |
|
92 |
|
93 case CX3pStateMachine::EStateNetSessStarted: |
|
94 // Forward X3P request to network |
|
95 netError = x3pMachine.Observer().Network()->MoLrReq(x3pMachine.Destination()); |
|
96 // If this succeeded then start a timer for the anticipated response |
|
97 if (CNetworkInterface::ENone == netError) |
|
98 { |
|
99 x3pMachine.StartX3pReqTimer(); |
|
100 } |
|
101 break; |
|
102 |
|
103 case CX3pStateMachine::EStateMeasureDataRecvd: |
|
104 // No action required |
|
105 break; |
|
106 |
|
107 case CX3pStateMachine::EStateNetBasedLocSent: |
|
108 // Send network location to gateway |
|
109 x3pMachine.Observer().Gateway()->NetworkLocationInd( |
|
110 x3pMachine.SessionId(), |
|
111 x3pMachine.ReferenceLoc()); |
|
112 break; |
|
113 |
|
114 case CX3pStateMachine::EStateLocReqByNet: |
|
115 // Send location request to gateway |
|
116 x3pMachine.Observer().Gateway()->LocationReq( |
|
117 x3pMachine.SessionId(), |
|
118 EFalse, // this is NOT emergency related |
|
119 x3pMachine.LocReqType(), |
|
120 x3pMachine.LocReqQuality(), |
|
121 x3pMachine.PosMethod()); |
|
122 // Start a timer for the anticipated response |
|
123 x3pMachine.StartLocRespTimer(); |
|
124 break; |
|
125 |
|
126 case CX3pStateMachine::EStateLocRespRecvd: |
|
127 // No action required |
|
128 break; |
|
129 |
|
130 case CX3pStateMachine::EStateLocSentToNet: |
|
131 // Forward location response to network - but not if an error was reported |
|
132 if (KErrNone <= x3pMachine.LocRespReason()) |
|
133 { |
|
134 netError = x3pMachine.Observer().Network()->LocationResp(x3pMachine.LocRespPosition()); |
|
135 |
|
136 if (CNetworkInterface::ENone == netError) |
|
137 { |
|
138 x3pMachine.StartFacResultTimer(); |
|
139 x3pMachine.ResponseSent(); |
|
140 } |
|
141 } |
|
142 break; |
|
143 |
|
144 case CX3pStateMachine::EStateNetSessToClose: |
|
145 // If we had received a location request, but an error or cancellation was |
|
146 // reported, forward this location error to the network (if response not sent yet) |
|
147 if (x3pMachine.IsLocReqReceived() && (KErrNone > x3pMachine.LocRespReason()) && |
|
148 (!x3pMachine.IsLocRespSent())) |
|
149 { |
|
150 netError = x3pMachine.Observer().Network()->LocationResp(x3pMachine.LocRespReason()); |
|
151 x3pMachine.ResponseSent(); |
|
152 } |
|
153 break; |
|
154 |
|
155 case CX3pStateMachine::EStateNetResultSent: |
|
156 // Send network result location to gateway if no error or cancellation ocurred in LBS. |
|
157 if (x3pMachine.IsLocRespSent() && (KErrNone <= x3pMachine.LocRespReason())) |
|
158 { |
|
159 |
|
160 x3pMachine.Observer().Gateway()->NetworkLocationInd( |
|
161 x3pMachine.SessionId(), |
|
162 x3pMachine.NetResultLoc()); |
|
163 } |
|
164 break; |
|
165 |
|
166 case CX3pStateMachine::EStateClientSessToClose: |
|
167 // No action required |
|
168 break; |
|
169 |
|
170 case CX3pStateMachine::EStateSessionsClosed: |
|
171 // No action required |
|
172 break; |
|
173 |
|
174 case CX3pStateMachine::EStateCancelling: |
|
175 // No action required |
|
176 break; |
|
177 |
|
178 default: |
|
179 User::Panic(KProtocolModulePanic, EProtocolModuleX3pState); |
|
180 break; |
|
181 } |
|
182 |
|
183 // Handle any network-related error |
|
184 if (CNetworkInterface::ENone != netError) |
|
185 { |
|
186 x3pMachine.Observer().NetworkErrorReported(); |
|
187 } |
|
188 |
|
189 } |
|
190 |
|
191 |
|
192 /** Perform exit actions. |
|
193 This is called from the state machine to perform any actions |
|
194 associated with exiting from the current state. |
|
195 */ |
|
196 void CX3pStateHandler::ExitActions() |
|
197 { |
|
198 CNetworkInterface::TNetworkError netError = CNetworkInterface::ENone; |
|
199 |
|
200 // Retrieve current state and act accordingly |
|
201 CX3pStateMachine& x3pMachine = reinterpret_cast <CX3pStateMachine&> (iMachine); |
|
202 switch(x3pMachine.CurrentState()) |
|
203 { |
|
204 |
|
205 case CX3pStateMachine::EStateNull: |
|
206 x3pMachine.SetStillCancelling(EFalse); |
|
207 break; |
|
208 |
|
209 case CX3pStateMachine::EStateClientReqRecvd: |
|
210 // no action required |
|
211 break; |
|
212 |
|
213 case CX3pStateMachine::EStateNetSessStarted: |
|
214 // no action required |
|
215 break; |
|
216 |
|
217 case CX3pStateMachine::EStateMeasureDataRecvd: |
|
218 // no action required |
|
219 break; |
|
220 |
|
221 case CX3pStateMachine::EStateNetBasedLocSent: |
|
222 // no action required |
|
223 break; |
|
224 |
|
225 case CX3pStateMachine::EStateLocReqByNet: |
|
226 // no action required |
|
227 break; |
|
228 |
|
229 case CX3pStateMachine::EStateLocRespRecvd: |
|
230 // no action required |
|
231 break; |
|
232 |
|
233 case CX3pStateMachine::EStateLocSentToNet: |
|
234 // no action required |
|
235 break; |
|
236 |
|
237 case CX3pStateMachine::EStateClientSessToClose: |
|
238 // Send a session completion to the gateway BUT not if we are |
|
239 // silently cancelling the client session |
|
240 if (!x3pMachine.IsSilentClientCancel()) |
|
241 { |
|
242 x3pMachine.Observer().Gateway()->SessionCompleteInd( |
|
243 x3pMachine.SessionId(),x3pMachine.ClientCloseReason()); |
|
244 } |
|
245 break; |
|
246 |
|
247 case CX3pStateMachine::EStateNetSessToClose: |
|
248 // Forward session completion to network if network is okay |
|
249 if (!x3pMachine.IsNetworkConnectionError()) |
|
250 { |
|
251 netError = x3pMachine.Observer().Network()->MoLrCompleteInd(x3pMachine.NetworkCloseReason()); |
|
252 } |
|
253 break; |
|
254 |
|
255 case CX3pStateMachine::EStateNetResultSent: |
|
256 // no action required |
|
257 break; |
|
258 |
|
259 case CX3pStateMachine::EStateSessionsClosed: |
|
260 // no action required |
|
261 break; |
|
262 |
|
263 case CX3pStateMachine::EStateCancelling: |
|
264 // Ensure that certain state transitions are prohibited when cancelling. |
|
265 x3pMachine.SetStillCancelling(ETrue); |
|
266 break; |
|
267 |
|
268 default: |
|
269 User::Panic(KProtocolModulePanic, EProtocolModuleX3pState); |
|
270 break; |
|
271 } |
|
272 |
|
273 // Handle any network-related error |
|
274 if (CNetworkInterface::ENone != netError) |
|
275 { |
|
276 x3pMachine.Observer().NetworkErrorReported(); |
|
277 } |
|
278 |
|
279 } |
|
280 |
|
281 |