|
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 that manages |
|
15 // protocol aspects of Test Protocol Module operation. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 @released |
|
23 */ |
|
24 |
|
25 #include <e32base.h> |
|
26 #include <lbs/lbslocdatasourcegpsbase.h> |
|
27 #include "cconfigmanager.h" |
|
28 #include "cmolrstatemachine.h" |
|
29 #include "cmtlrstatemachine.h" |
|
30 #include "cx3pstatemachine.h" |
|
31 #include "cnetlocstatemachine.h" |
|
32 #include "cprotocolmanager.h" |
|
33 #include "cassistdatamgr.h" |
|
34 #include "lbsdevloggermacros.h" |
|
35 |
|
36 #ifdef ENABLE_LBS_DEV_LOGGER |
|
37 #include <lbs/lbsnetclasstypes.h> |
|
38 #endif |
|
39 |
|
40 /** The unique ID of this plug-in implementation. |
|
41 This corresponds to the implementation UID specified in the .rss file |
|
42 for this protocol module. |
|
43 */ |
|
44 const TInt KPluginUidValue = 0x10281D70; |
|
45 const TUid KPluginUid = { KPluginUidValue }; |
|
46 |
|
47 |
|
48 /** Static constructor. |
|
49 @param aGateway A reference to the protocol manager observer |
|
50 @return A new instance of the CProtocolManager class |
|
51 */ |
|
52 CProtocolManager* CProtocolManager::NewL(MProtocolMgrObserver& aGateway) |
|
53 { |
|
54 CProtocolManager* self = new (ELeave) CProtocolManager(aGateway); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 |
|
61 |
|
62 /** Standard constructor. |
|
63 @param aGateway A reference to the protocol manager observer |
|
64 */ |
|
65 CProtocolManager::CProtocolManager(MProtocolMgrObserver& aGateway) |
|
66 : iGateway(aGateway), iLbsStatus(CLbsNetworkProtocolBase::ESystemStatusNone), |
|
67 iActiveServiceMask(MLbsNetworkProtocolObserver::EServiceNone) |
|
68 { |
|
69 iInternalSessionId.SetSessionOwner(KPluginUid); |
|
70 iInternalSessionId.SetSessionNum(0); |
|
71 |
|
72 LBSLOG(ELogP2, "CProtocolManager::CProtocolManager() CurrentOp --> EOpNone\n"); |
|
73 iCurrentOp.iOperation = CConfigManager::EOpNone; |
|
74 iCurrentOp.iPriority = CConfigManager::EPriorityNone; |
|
75 } |
|
76 |
|
77 |
|
78 /** Standard destructor. |
|
79 */ |
|
80 CProtocolManager::~CProtocolManager() |
|
81 { |
|
82 delete iAssistMgr; |
|
83 delete iNetLoc; |
|
84 delete iX3p; |
|
85 delete iMtLr; |
|
86 delete iMoLr; |
|
87 delete iConfig; |
|
88 delete iNetwork; |
|
89 } |
|
90 |
|
91 |
|
92 /** Private second-stage constructor. |
|
93 */ |
|
94 void CProtocolManager::ConstructL() |
|
95 { |
|
96 iNetwork = CNetworkInterface::NewL(*this); |
|
97 iNetwork->Connect(); |
|
98 |
|
99 iConfig = CConfigManager::NewL(); |
|
100 iMoLr = CMoLrStateMachine::NewL(*this); |
|
101 iMtLr = CMtLrStateMachine::NewL(*this); |
|
102 iX3p = CX3pStateMachine::NewL(*this); |
|
103 iNetLoc = CNetLocStateMachine::NewL(*this); |
|
104 iAssistMgr = CAssistDataMgr::NewL(); |
|
105 } |
|
106 |
|
107 |
|
108 /** Identify active state machine |
|
109 @param aActiveMachine A reference to a pointer that identifies the active |
|
110 state machine. This pointer is set to NULL if there is no active machine. |
|
111 */ |
|
112 void CProtocolManager::GetActiveStateMachine(CStateMachineBase*& aActiveMachine) const |
|
113 { |
|
114 //LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() \n"); |
|
115 if (CStateMachineBase::EStateActive == iMtLr->State()) |
|
116 { |
|
117 LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() Active Machine = MTLR\n"); |
|
118 aActiveMachine = iMtLr; |
|
119 } |
|
120 else if (CStateMachineBase::EStateActive == iMoLr->State()) |
|
121 { |
|
122 LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() Active Machine = MOLR\n"); |
|
123 aActiveMachine = iMoLr; |
|
124 } |
|
125 else if (CStateMachineBase::EStateActive == iX3p->State()) |
|
126 { |
|
127 LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() Active Machine = X3P\n"); |
|
128 aActiveMachine = iX3p; |
|
129 } |
|
130 else if (CStateMachineBase::EStateActive == iNetLoc->State()) |
|
131 { |
|
132 LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() Active Machine = NBLR\n"); |
|
133 aActiveMachine = iNetLoc; |
|
134 } |
|
135 else |
|
136 { |
|
137 LBSLOG(ELogP2, "CProtocolManager::GetActiveStateMachine() No Active Machine\n"); |
|
138 aActiveMachine = NULL; |
|
139 } |
|
140 |
|
141 } |
|
142 |
|
143 |
|
144 /** Identify a state machine that is currently cancelling. |
|
145 @param aCancellingMachine A reference to a pointer that identifies the cancelling |
|
146 state machine. This pointer is set to NULL if there is no cancelling machine. |
|
147 */ |
|
148 void CProtocolManager::GetCancellingStateMachine(CStateMachineBase*& aCancellingMachine) const |
|
149 { |
|
150 |
|
151 if (CStateMachineBase::EStateCancelling == iMtLr->State()) |
|
152 { |
|
153 aCancellingMachine = iMtLr; |
|
154 } |
|
155 else if (CStateMachineBase::EStateCancelling == iMoLr->State()) |
|
156 { |
|
157 aCancellingMachine = iMoLr; |
|
158 } |
|
159 else if (CStateMachineBase::EStateCancelling == iX3p->State()) |
|
160 { |
|
161 aCancellingMachine = iX3p; |
|
162 } |
|
163 else if (CStateMachineBase::EStateCancelling == iNetLoc->State()) |
|
164 { |
|
165 aCancellingMachine = iNetLoc; |
|
166 } |
|
167 else |
|
168 { |
|
169 aCancellingMachine = NULL; |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 /** Identify a state machine that is currently queued. |
|
175 This will identify a state machine that is queued and ready to be started. |
|
176 Priority is given to MT-LR because whilst another machine is cancelling |
|
177 an MT-LR emergency request may be briefly queued. |
|
178 |
|
179 @param aQueuedMachine A reference to a pointer that identifies a queued |
|
180 state machine. This pointer is set to NULL if there is no queued machine. |
|
181 */ |
|
182 void CProtocolManager::GetQueuedStateMachine(CStateMachineBase*& aQueuedMachine) const |
|
183 { |
|
184 if (iMtLr->IsMachineQueued()) |
|
185 { |
|
186 aQueuedMachine = iMtLr; |
|
187 } |
|
188 else if (iMoLr->IsMachineQueued()) |
|
189 { |
|
190 aQueuedMachine = iMoLr; |
|
191 } |
|
192 else if (iX3p->IsMachineQueued()) |
|
193 { |
|
194 aQueuedMachine = iX3p; |
|
195 } |
|
196 else if (iNetLoc->IsMachineQueued()) |
|
197 { |
|
198 aQueuedMachine = iNetLoc; |
|
199 } |
|
200 else |
|
201 { |
|
202 aQueuedMachine = NULL; |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 |
|
208 /** Resolve the conflict between an active procedure and a new request. |
|
209 @param aNewOp The type of operation that is represented by the new request. |
|
210 @param aNewPriority The priority of the new request - optional. |
|
211 @return TBool An indication if the |
|
212 */ |
|
213 CConfigManager::TConflictResult CProtocolManager::ResolveConflict( |
|
214 CConfigManager::TConflictOp aNewOp, |
|
215 CConfigManager::TConflictPriority aNewPriority) |
|
216 { |
|
217 CConfigManager::TConflictResult conflictResult = CConfigManager::EConflictNone; |
|
218 CStateMachineBase* activeMachine; |
|
219 CStateMachineBase* cancellingMachine; |
|
220 GetActiveStateMachine(activeMachine); |
|
221 GetCancellingStateMachine(cancellingMachine); |
|
222 |
|
223 LBSLOG3(ELogP2, "CProtocolManager::ResolveConflict() Current op = %d, New op = %d\n", iCurrentOp.iOperation, aNewOp); |
|
224 |
|
225 // One special case relates to an existing MT-LR that is awaiting the |
|
226 // measurement control after a privacy reject. This MT-LR sequence can be |
|
227 // cancelled once a new request arrives. |
|
228 if ((iMtLr == activeMachine) && (iMtLr->IsRejectedWaitingMeasureControl())) |
|
229 { |
|
230 iMtLr->CancelMachine(CStateMachineBase::ECancelNone); |
|
231 conflictResult = CConfigManager::EConflictCancelCurrent; |
|
232 } |
|
233 // There is an operation already in the process of being cancelled, |
|
234 // so queue the new request until this completes. |
|
235 else if (NULL != cancellingMachine) |
|
236 { |
|
237 LBSLOG(ELogP2, "CProtocolManager::ResolveConflict() Queing new request while previous op cancelled\n"); |
|
238 conflictResult = CConfigManager::EConflictQueueNew; |
|
239 } |
|
240 else |
|
241 { |
|
242 CConfigManager::TConflictOperation newOp; |
|
243 newOp.iOperation = aNewOp; |
|
244 newOp.iPriority = aNewPriority; |
|
245 |
|
246 // A special case is when tracking is set on and it is not a new MO-LR request. |
|
247 // If there is not a current active operation, or MOLR is active, then |
|
248 // there may be a need to cancel a tracking 'session'. |
|
249 if ((iLbsStatus & CLbsNetworkProtocolBase::ESystemStatusClientTracking) && |
|
250 (CConfigManager::EOpMoLr != aNewOp) && |
|
251 ((NULL == activeMachine) || (iMoLr == activeMachine))) |
|
252 { |
|
253 // Use a fake MO-LR to obtain a conflict decision. |
|
254 CConfigManager::TConflictOperation fakeMoLrOp; |
|
255 fakeMoLrOp.iOperation = CConfigManager::EOpMoLr; |
|
256 fakeMoLrOp.iPriority = CConfigManager::EPriorityNone; |
|
257 conflictResult = iConfig->ConflictDecision(fakeMoLrOp, newOp); |
|
258 |
|
259 // Should tracking be cancelled? |
|
260 if ((CConfigManager::EConflictCancelCurrent == conflictResult) || |
|
261 (CConfigManager::EConflictQueueCurrent == conflictResult)) |
|
262 { |
|
263 // Turn tracking off |
|
264 iLbsStatus = CLbsNetworkProtocolBase::ESystemStatusNone; |
|
265 if (NULL == activeMachine) |
|
266 { |
|
267 // Cancel tracking session if we have no active operation and |
|
268 // there has been a preceding MOLR session |
|
269 if ((iMoLr->SessionId().SessionOwner().iUid != 0) || |
|
270 (iMoLr->SessionId().SessionNum() != 0)) |
|
271 { |
|
272 Gateway()->SessionCompleteInd(iMoLr->SessionId(), KErrPositionHighPriorityReceive); |
|
273 } |
|
274 conflictResult = CConfigManager::EConflictNone; |
|
275 } |
|
276 } |
|
277 } |
|
278 // If we have an active operation which needs a conflict decision |
|
279 else if( (NULL != activeMachine) /*&& (iCurrentOp.iOperation != CConfigManager::EOpNone)*/) |
|
280 { |
|
281 conflictResult = iConfig->ConflictDecision(iCurrentOp, newOp); |
|
282 } |
|
283 else |
|
284 { |
|
285 // no tracking and no active operation = no conflict |
|
286 } |
|
287 |
|
288 // Perform any initial action arising from conflict decision |
|
289 switch (conflictResult) |
|
290 { |
|
291 // Current operation must be cancelled |
|
292 case CConfigManager::EConflictCancelCurrent: |
|
293 // Indicate if the source of cancellation is the network or LBS |
|
294 if ((CConfigManager::EOpMtLr == aNewOp) || |
|
295 (CConfigManager::EOpNiLr == aNewOp)) |
|
296 { |
|
297 LBSLOG(ELogP2, "CProtocolManager::ResolveConflict() Cancelling state machine, client\n"); |
|
298 activeMachine->CancelMachine(CStateMachineBase::ECancelNetworkCancel, KErrPositionHighPriorityReceive); |
|
299 } |
|
300 else |
|
301 { |
|
302 LBSLOG(ELogP2, "CProtocolManager::ResolveConflict() Cancelling state machine, network\n"); |
|
303 activeMachine->CancelMachine(CStateMachineBase::ECancelClientCancel, KErrPositionHighPriorityReceive); |
|
304 } |
|
305 break; |
|
306 |
|
307 // Queue the current operation before performing new operation |
|
308 // Note: At present we only have a requirement to queue an X3P timer |
|
309 // and the functionality to support this is as follows: |
|
310 // (a) cancel current operation BUT without cancelling LBS session |
|
311 // (b) silently consume any LBS responses that relate to this session |
|
312 // (c) proceed with the new operation |
|
313 // (d) wait for LBS (NRH) to repeat the X3P timer request |
|
314 case CConfigManager::EConflictQueueCurrent: |
|
315 activeMachine->CancelMachine(CStateMachineBase::ECancelClientCancelSilent, KErrPositionHighPriorityReceive); |
|
316 break; |
|
317 |
|
318 // Other conflict results require no further action here |
|
319 default: |
|
320 break; |
|
321 }; |
|
322 } |
|
323 |
|
324 LBSLOG2(ELogP2, "CProtocolManager::ResolveConflict() returning conflict result %d\n", conflictResult); |
|
325 return conflictResult; |
|
326 } |
|
327 |
|
328 |
|
329 /** Handle LBS request for Assistance Data |
|
330 @param aDataRequestMask A mask identifying the set of data requested. |
|
331 */ |
|
332 void CProtocolManager::AssistanceDataReq(TLbsAsistanceDataGroup aDataRequestMask) |
|
333 { |
|
334 // Pass request to the assistance data manager to process |
|
335 TBool noAssistanceNeeded = iAssistMgr->ProcessDataRequest(aDataRequestMask); |
|
336 |
|
337 // No assistance needed? |
|
338 if (noAssistanceNeeded) |
|
339 { |
|
340 // Do nothing! |
|
341 } |
|
342 // Check if the requested data mask was entirely invalid |
|
343 else if (iAssistMgr->RequestErrorMask() == aDataRequestMask) |
|
344 { |
|
345 // Report the request error now |
|
346 DoAssistanceDataActions(); |
|
347 } |
|
348 else |
|
349 { |
|
350 // Check if we have an active state machine |
|
351 CStateMachineBase* activeMachine; |
|
352 GetActiveStateMachine(activeMachine); |
|
353 if (NULL != activeMachine) |
|
354 { |
|
355 // Advise state machine of assistance data request |
|
356 activeMachine->AssistanceDataReq(); |
|
357 } |
|
358 else |
|
359 { |
|
360 // Store assistance data error |
|
361 iAssistMgr->Error(KErrGeneral); |
|
362 |
|
363 // Report the error |
|
364 DoAssistanceDataActions(); |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 |
|
370 /** Handle LBS request for self locate |
|
371 @param aSessionId The session ID supplied by LBS. |
|
372 @param aDataRequestMask A mask identifying the set of data requested. |
|
373 */ |
|
374 void CProtocolManager::SelfLocationReq(const TLbsNetSessionId& aSessionId, |
|
375 const TLbsNetPosRequestOptionsBase& aOptions) |
|
376 { |
|
377 |
|
378 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq()\n"); |
|
379 const TLbsNetPosRequestOptionsAssistance options = reinterpret_cast<const TLbsNetPosRequestOptionsAssistance&> (aOptions); |
|
380 // Pass assistance data mask to the assistance data manager to process |
|
381 TBool noAssistanceNeeded = iAssistMgr->ProcessDataRequest(options.DataRequestMask()); |
|
382 |
|
383 // Was assistance data request entirely invalid |
|
384 if (iAssistMgr->RequestErrorMask() == options.DataRequestMask() && |
|
385 !noAssistanceNeeded) |
|
386 { |
|
387 // Ensure this error is reported |
|
388 DoAssistanceDataActions(); |
|
389 noAssistanceNeeded = ETrue; |
|
390 } |
|
391 |
|
392 // Is there already an MO-LR active? |
|
393 if (CStateMachineBase::EStateActive == iMoLr->State()) |
|
394 { |
|
395 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq() Previously we would've ignored this request!!!!!!\n"); |
|
396 } |
|
397 |
|
398 CConfigManager::TConflictResult conflictResult = ResolveConflict(CConfigManager::EOpMoLr); |
|
399 // Resolve any conflicts arising |
|
400 switch (conflictResult) |
|
401 { |
|
402 // Start MO-LR |
|
403 case CConfigManager::EConflictNone: |
|
404 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq() No conflict\n"); |
|
405 // Network interaction is not required under these circumstances: |
|
406 // (a) GPS mode is autonomous OR |
|
407 // (b) this is an old client AND no assistance data was requested |
|
408 if (TPositionModuleInfo::ETechnologyTerminal == options.PosMode() || |
|
409 (!options.NewClientConnected() && noAssistanceNeeded)) |
|
410 { |
|
411 // End the LBS session |
|
412 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq() Ending session due to autonomous OR old client not requiring ass data\n"); |
|
413 Gateway()->SessionCompleteInd(aSessionId, KErrNone); |
|
414 } |
|
415 else |
|
416 { |
|
417 // Status update sent to LBS |
|
418 StatusUpdate(CConfigManager::EOpMoLr, ETrue); // ETrue=new operation |
|
419 // Need to set the assistance data manager as if no data |
|
420 // has been received yet, and all previous data has been reported, |
|
421 // to ensure that any existing set of data is reported to LBS. |
|
422 iAssistMgr->DataReported(); |
|
423 iAssistMgr->SetDataNotReceived(); |
|
424 iMoLr->MoLrReq(aSessionId); |
|
425 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq() CurrentOp --> EOpMoLr\n"); |
|
426 iCurrentOp.iOperation = CConfigManager::EOpMoLr; |
|
427 iCurrentOp.iPriority = CConfigManager::EPriorityNone; |
|
428 } |
|
429 break; |
|
430 |
|
431 // Reject the new request |
|
432 case CConfigManager::EConflictRejectNew: |
|
433 LBSLOG(ELogP2, "CProtocolManager::SelfLocationReq() Conflict: Rejecting new request\n"); |
|
434 Gateway()->SessionCompleteInd(aSessionId, KErrServerBusy); |
|
435 break; |
|
436 |
|
437 // New request is queued whilst current operation continues |
|
438 // or current operation is being cancelled. |
|
439 case CConfigManager::EConflictQueueNew: |
|
440 case CConfigManager::EConflictCancelCurrent: |
|
441 case CConfigManager::EConflictQueueCurrent: |
|
442 LBSLOG2(ELogP2, "CProtocolManager::SelfLocationReq() Conflict %d: Queueing new request\n", conflictResult); |
|
443 iMoLr->QueueMoLrReq(aSessionId); |
|
444 break; |
|
445 |
|
446 default: |
|
447 break; |
|
448 }; |
|
449 } |
|
450 |
|
451 |
|
452 /** Handle LBS completion of self locate |
|
453 @param aSessionId The session to be completed. |
|
454 @param aReason Completion reason value. |
|
455 */ |
|
456 void CProtocolManager::SelfLocationCompleteInd(const TLbsNetSessionId& aSessionId, |
|
457 TInt aReason) |
|
458 { |
|
459 // Check we have an active self locate and valid session ID, |
|
460 // otherwise silently consume this completion indication. |
|
461 if ((CStateMachineBase::EStateActive == iMoLr->State()) && |
|
462 (aSessionId == iMoLr->SessionId())) |
|
463 { |
|
464 iMoLr->CancelMachine(CStateMachineBase::ECancelClientCancel, aReason); |
|
465 } |
|
466 } |
|
467 |
|
468 |
|
469 /** Handle LBS system status indication |
|
470 @param aStatus The status indication from LBS. |
|
471 */ |
|
472 void CProtocolManager::SystemStatusInd(CLbsNetworkProtocolBase::TLbsSystemStatus aStatus) |
|
473 { |
|
474 iLbsStatus = aStatus; |
|
475 } |
|
476 |
|
477 |
|
478 /** Handle LBS Location Response |
|
479 @param aSessionId The session ID for which this response is provided. |
|
480 @param aReason An error response; KErrNone if position is okay. |
|
481 @param aPosInfo The location response information |
|
482 */ |
|
483 void CProtocolManager::LocationResp(const TLbsNetSessionId& aSessionId, TInt aReason, const TPositionInfoBase& aPosInfo) |
|
484 { |
|
485 // Check we have an active state machine to handle this |
|
486 CStateMachineBase* activeMachine; |
|
487 GetActiveStateMachine(activeMachine); |
|
488 |
|
489 // Special requirement to allow MT-LR to receive late responses |
|
490 if ((NULL == activeMachine) && |
|
491 (CStateMachineBase::EStateCancelling == iMtLr->State())) |
|
492 { |
|
493 activeMachine = iMtLr; |
|
494 } |
|
495 |
|
496 // Check there is an active state machine and that session ID is legitimate, |
|
497 // otherwise silently consume this location response. |
|
498 if ((NULL != activeMachine) && (aSessionId == activeMachine->SessionId())) |
|
499 { |
|
500 activeMachine->LocationResp(aReason, aPosInfo); |
|
501 } |
|
502 |
|
503 } |
|
504 |
|
505 |
|
506 /** Handle LBS Privacy Response |
|
507 @param aResponse Privacy response value. |
|
508 */ |
|
509 void CProtocolManager::PrivacyResp(const TLbsNetSessionId& aSessionId, |
|
510 const CLbsNetworkProtocolBase::TLbsPrivacyResponse& aResponse) |
|
511 { |
|
512 // Check we have an active MT-LR state machine and valid session ID, |
|
513 // otherwise silently consume this privacy response. |
|
514 if ((CStateMachineBase::EStateActive == iMtLr->State()) && |
|
515 (aSessionId == iMtLr->SessionId())) |
|
516 { |
|
517 iMtLr->PrivacyResp(aResponse); |
|
518 } |
|
519 } |
|
520 |
|
521 |
|
522 /** Handle LBS Network Based Location Request |
|
523 */ |
|
524 void CProtocolManager::NetworkBasedLocationReq(const TLbsNetSessionId& aSessionId, |
|
525 const TLbsNetPosRequestOptionsBase& /*aOptions*/) |
|
526 { |
|
527 LBSLOG2(ELogP2, "CProtocolManager::NetworkBasedLocationReq() session id %d\n", aSessionId.SessionNum()); |
|
528 // Resolve any conflicts arising |
|
529 switch (ResolveConflict(CConfigManager::EOpNbLr)) |
|
530 { |
|
531 // Start Network Based Location |
|
532 case CConfigManager::EConflictNone: |
|
533 // Status update sent to LBS |
|
534 StatusUpdate(CConfigManager::EOpNbLr, ETrue); // ETrue=new operation |
|
535 iNetLoc->NetLocReq(aSessionId); |
|
536 LBSLOG(ELogP2, "CProtocolManager::NetworkBasedLocationReq() CurrentOp --> EOpNbLr\n"); |
|
537 iCurrentOp.iOperation = CConfigManager::EOpNbLr; |
|
538 iCurrentOp.iPriority = CConfigManager::EPriorityNone; |
|
539 break; |
|
540 |
|
541 // Reject the new request |
|
542 case CConfigManager::EConflictRejectNew: |
|
543 Gateway()->SessionCompleteInd(aSessionId, KErrServerBusy); |
|
544 break; |
|
545 |
|
546 // New request is queued whilst current operation continues |
|
547 // or current operation is being cancelled. |
|
548 case CConfigManager::EConflictQueueNew: |
|
549 case CConfigManager::EConflictCancelCurrent: |
|
550 case CConfigManager::EConflictQueueCurrent: |
|
551 LBSLOG2(ELogP2, "CProtocolManager::NetworkBasedLocationReq() Queueing NetLocrequest with session id %d\n", aSessionId.SessionNum()); |
|
552 iNetLoc->QueueNetLocReq(aSessionId); |
|
553 break; |
|
554 |
|
555 default: |
|
556 break; |
|
557 }; |
|
558 } |
|
559 |
|
560 |
|
561 /** Handle LBS Completion of a Network Based Location Request |
|
562 */ |
|
563 void CProtocolManager::NetworkBasedLocationCompleteInd(const TLbsNetSessionId& aSessionId, |
|
564 TInt aReason) |
|
565 { |
|
566 LBSLOG2(ELogP2, "CProtocolManager::NetworkBasedLocationCompleteInd() session id %d\n", aSessionId.SessionNum()); |
|
567 // Check we have an active Network Based Loc state machine and valid session ID, |
|
568 // otherwise silently consume this completion indication. |
|
569 if ((CStateMachineBase::EStateActive == iNetLoc->State()) && |
|
570 (aSessionId == iNetLoc->SessionId())) |
|
571 { |
|
572 iNetLoc->CancelMachine(CStateMachineBase::ECancelClientCancel, aReason); |
|
573 } |
|
574 } |
|
575 |
|
576 |
|
577 /** Handle LBS Transmit Location Request |
|
578 */ |
|
579 void CProtocolManager::TransmitLocationReq(const TLbsNetSessionId& aSessionId, const TDesC& aDest, TInt aPriority) |
|
580 { |
|
581 CConfigManager::TConflictPriority priority; |
|
582 switch(aPriority) |
|
583 { |
|
584 case 0x10: // Timer |
|
585 priority = CConfigManager::EPriorityLow; |
|
586 break; |
|
587 |
|
588 case 0x08: // Menu |
|
589 priority = CConfigManager::EPriorityMedium; |
|
590 break; |
|
591 |
|
592 case 0x02: // Push |
|
593 priority = CConfigManager::EPriorityHigh; |
|
594 break; |
|
595 |
|
596 default: |
|
597 priority = CConfigManager::EPriorityNone; |
|
598 break; |
|
599 }; |
|
600 |
|
601 // Resolve any conflicts arising |
|
602 switch (ResolveConflict(CConfigManager::EOpX3p, priority)) |
|
603 { |
|
604 // Start X3P |
|
605 case CConfigManager::EConflictNone: |
|
606 // Status update sent to LBS |
|
607 StatusUpdate(CConfigManager::EOpX3p, ETrue); // ETrue=new operation |
|
608 iX3p->X3pReq(aSessionId, aDest); |
|
609 LBSLOG(ELogP2, "CProtocolManager::TransmitLocationReq() CurrentOp --> EOpX3p\n"); |
|
610 iCurrentOp.iOperation = CConfigManager::EOpX3p; |
|
611 iCurrentOp.iPriority = priority; |
|
612 break; |
|
613 |
|
614 // Reject the new request |
|
615 case CConfigManager::EConflictRejectNew: |
|
616 Gateway()->SessionCompleteInd(aSessionId, KErrServerBusy); |
|
617 break; |
|
618 |
|
619 // New request is queued whilst current operation continues |
|
620 // or current operation is being cancelled. |
|
621 case CConfigManager::EConflictQueueNew: |
|
622 case CConfigManager::EConflictCancelCurrent: |
|
623 case CConfigManager::EConflictQueueCurrent: |
|
624 iX3p->QueueX3pReq(aSessionId, aDest); |
|
625 break; |
|
626 |
|
627 default: |
|
628 break; |
|
629 }; |
|
630 } |
|
631 |
|
632 |
|
633 /** Handle LBS Completion of a Transmit Location Request |
|
634 */ |
|
635 void CProtocolManager::TransmitLocationCompleteInd(const TLbsNetSessionId& aSessionId, TInt aReason) |
|
636 { |
|
637 // Check we have an active X3P state machine and valid session ID, |
|
638 // otherwise silently consume this completion indication |
|
639 if ((CStateMachineBase::EStateActive == iX3p->State()) && |
|
640 (aSessionId == iX3p->SessionId())) |
|
641 { |
|
642 // Cancel |
|
643 iX3p->CancelMachine(CStateMachineBase::ECancelClientCancel, aReason); |
|
644 } |
|
645 } |
|
646 |
|
647 |
|
648 // |
|
649 // MNetworkObserver methods |
|
650 // |
|
651 |
|
652 |
|
653 /** Get a new session ID |
|
654 @see MNetworkObserver::NewSession() |
|
655 */ |
|
656 const TLbsNetSessionId& CProtocolManager::NewSessionId() |
|
657 { |
|
658 iInternalSessionId.IncrSession(); |
|
659 return iInternalSessionId; |
|
660 } |
|
661 |
|
662 |
|
663 /** Handle Network Measurement Control indication |
|
664 @see MNetworkObserver |
|
665 */ |
|
666 void CProtocolManager::MeasurementControlInd(const TPositionInfoBase& aPosInfo, |
|
667 const RLbsAssistanceDataBuilderSet& aData, const TLbsNetPosRequestQuality& aQuality, |
|
668 const TLbsNetPosRequestMethod& aPosMethod) |
|
669 { |
|
670 LBSLOG(ELogP2, "CProtocolManager::MeasurementControlInd()\n"); |
|
671 // Store assistance data |
|
672 iAssistMgr->StoreData(aData); |
|
673 |
|
674 // Check if we have an active state machine to handle this |
|
675 CStateMachineBase* activeMachine; |
|
676 GetActiveStateMachine(activeMachine); |
|
677 CStateMachineBase* cancellingMachine; |
|
678 GetCancellingStateMachine(cancellingMachine); |
|
679 if (NULL != activeMachine) |
|
680 { |
|
681 // Is this the first measurement control received? |
|
682 if (!activeMachine->IsLocReqReceived()) |
|
683 { |
|
684 // Forward the measurement and control to the state machine |
|
685 activeMachine->MeasurementControlInd(aPosInfo, aQuality, aPosMethod); |
|
686 } |
|
687 else |
|
688 { |
|
689 // Advise state machine of pending assistance data |
|
690 activeMachine->AdditionalAssistDataInd(); |
|
691 } |
|
692 } |
|
693 // Any cancelling state machine? |
|
694 else if (NULL != cancellingMachine) |
|
695 { |
|
696 // Forward the measurement and control to the state machine |
|
697 cancellingMachine->MeasurementControlInd(aPosInfo, aQuality, aPosMethod); |
|
698 } |
|
699 else |
|
700 { |
|
701 // If there is no active or cancelling operation then this can be |
|
702 // interpreted as a network induced location request (NI-LR). |
|
703 |
|
704 // We must perform conflict decision-making before handling this |
|
705 CConfigManager::TConflictPriority priority; |
|
706 priority = (iMtLr->IsEmergency()) ? CConfigManager::EPriorityEmergency : CConfigManager::EPriorityNone; |
|
707 switch (ResolveConflict(CConfigManager::EOpNiLr, priority)) |
|
708 { |
|
709 // Start NI-LR |
|
710 case CConfigManager::EConflictNone: |
|
711 { |
|
712 // Status update sent to LBS |
|
713 StatusUpdate(CConfigManager::EOpNiLr, ETrue); // ETrue=new operation |
|
714 // The NI-LR requires a new session |
|
715 iMtLr->SessionId(NewSessionId()); |
|
716 LBSLOG(ELogP2, "CProtocolManager::MeasurementControlInd() CurrentOp --> EOpNiLr\n"); |
|
717 iCurrentOp.iOperation = CConfigManager::EOpNiLr; |
|
718 iCurrentOp.iPriority = priority; |
|
719 |
|
720 // Forward the measurement and control to the MT-LR state machine |
|
721 iMtLr->MeasurementControlInd(aPosInfo, aQuality, aPosMethod); |
|
722 } |
|
723 break; |
|
724 |
|
725 // Reject the new request |
|
726 case CConfigManager::EConflictRejectNew: |
|
727 { |
|
728 CNetworkInterface::TNetworkError netError = |
|
729 Network()->LocationResp(KErrServerBusy); |
|
730 // Handle network-related error |
|
731 if (CNetworkInterface::ENone != netError) |
|
732 { |
|
733 NetworkErrorReported(); |
|
734 } |
|
735 } |
|
736 break; |
|
737 |
|
738 // We don't do anything for other conflict responses because we |
|
739 // could only be in the process of cancelling an active operation |
|
740 // for which this measurement control becomes redundant. |
|
741 default: |
|
742 break; |
|
743 }; |
|
744 } |
|
745 } |
|
746 |
|
747 |
|
748 /** Handle Network Measurement Control error indication |
|
749 @see MNetworkObserver |
|
750 */ |
|
751 void CProtocolManager::MeasurementControlErrorInd(TInt aReason) |
|
752 { |
|
753 LBSLOG2(ELogP2, "CProtocolManager::NetworkErrorInd(%d)\n", aReason); |
|
754 // Store assistance data error |
|
755 iAssistMgr->Error(aReason); |
|
756 |
|
757 // Check if we have an active state machine to handle this, |
|
758 // otherwise silently consume this error indication. |
|
759 CStateMachineBase* activeMachine; |
|
760 GetActiveStateMachine(activeMachine); |
|
761 if (NULL != activeMachine) |
|
762 { |
|
763 // Advise state machine of error |
|
764 activeMachine->MeasurementControlErrorInd(aReason); |
|
765 } |
|
766 } |
|
767 |
|
768 |
|
769 /** Handle Network MT-LR request |
|
770 @see MNetworkObserver |
|
771 */ |
|
772 void CProtocolManager::MtLrReq(const TLbsExternalRequestInfo& aReqInfo, |
|
773 const TLbsNetPosRequestPrivacy& aPrivacy) |
|
774 { |
|
775 // Resolve any conflicts arising |
|
776 CConfigManager::TConflictPriority priority; |
|
777 priority = (iMtLr->IsEmergency()) ? CConfigManager::EPriorityEmergency : CConfigManager::EPriorityNone; |
|
778 switch (ResolveConflict(CConfigManager::EOpMtLr, priority)) |
|
779 { |
|
780 // Start MT-LR |
|
781 case CConfigManager::EConflictNone: |
|
782 // Status update sent to LBS |
|
783 StatusUpdate(CConfigManager::EOpMtLr, ETrue); // ETrue=new operation |
|
784 iMtLr->MtLrReq(aReqInfo, aPrivacy); |
|
785 LBSLOG(ELogP2, "CProtocolManager::MtLrReq() CurrentOp --> EOpMtLr\n"); |
|
786 iCurrentOp.iOperation = CConfigManager::EOpMtLr; |
|
787 iCurrentOp.iPriority = priority; |
|
788 break; |
|
789 |
|
790 // Reject the new request |
|
791 case CConfigManager::EConflictRejectNew: |
|
792 Network()->MtLrResp(CLbsNetworkProtocolBase::EPrivacyResponseRejected); |
|
793 break; |
|
794 |
|
795 // New request is queued whilst current operation continues |
|
796 // or current operation is being cancelled. |
|
797 case CConfigManager::EConflictQueueNew: |
|
798 case CConfigManager::EConflictCancelCurrent: |
|
799 case CConfigManager::EConflictQueueCurrent: |
|
800 iMtLr->QueueMtLrReq(aReqInfo, aPrivacy); |
|
801 break; |
|
802 |
|
803 default: |
|
804 break; |
|
805 }; |
|
806 } |
|
807 |
|
808 |
|
809 /** Handle Network MT-LR cancel indication |
|
810 @see MNetworkObserver |
|
811 */ |
|
812 void CProtocolManager::MtLrCancelInd(TInt aReason) |
|
813 { |
|
814 // If we have an active state machine then forward the indication, |
|
815 // otherwise silently consume this cancel indication. |
|
816 if (CStateMachineBase::EStateActive == iMtLr->State()) |
|
817 { |
|
818 iMtLr->MtLrCancelInd(aReason); |
|
819 } |
|
820 } |
|
821 |
|
822 |
|
823 /** Handle Network session result indication |
|
824 @see MNetworkObserver |
|
825 */ |
|
826 void CProtocolManager::NetworkResultInd(TInt aResult, const TPositionInfoBase* aPosInfo) |
|
827 { |
|
828 LBSLOG2(ELogP2, "CProtocolManager::NetworkErrorInd() Result = %d\n", aResult); |
|
829 // Check we have an active state machine to handle this, |
|
830 // otherwise silently consume this indication. |
|
831 CStateMachineBase* activeMachine; |
|
832 GetActiveStateMachine(activeMachine); |
|
833 |
|
834 if (NULL != activeMachine) |
|
835 { |
|
836 // Pass the indication on to the active state machine |
|
837 if (CStateMachineBase::EStateActive == iMoLr->State()) |
|
838 { |
|
839 iMoLr->SessionResult(aResult, aPosInfo); |
|
840 } |
|
841 |
|
842 if (CStateMachineBase::EStateActive == iX3p->State()) |
|
843 { |
|
844 iX3p->SessionResult(aResult, aPosInfo); |
|
845 } |
|
846 } |
|
847 } |
|
848 |
|
849 |
|
850 /** Handle Network error indication |
|
851 @see MNetworkObserver |
|
852 */ |
|
853 void CProtocolManager::NetworkErrorInd(TInt aReason) |
|
854 { |
|
855 LBSLOG2(ELogP2, "CProtocolManager::NetworkErrorInd(%d)\n", aReason); |
|
856 // Ensure any active state machine is informed of this problem |
|
857 CStateMachineBase* stateMachine; |
|
858 GetActiveStateMachine(stateMachine); |
|
859 if (NULL != stateMachine) |
|
860 { |
|
861 // Advise state machine of error |
|
862 stateMachine->NetworkErrorInd(); |
|
863 |
|
864 // Store assistance data error. This is only reported if the |
|
865 // state machine indicates that assistance data actions should |
|
866 // be performed. |
|
867 if (stateMachine->IsAssistanceDataActionReq()) |
|
868 { |
|
869 iAssistMgr->Error(aReason); |
|
870 } |
|
871 } |
|
872 } |
|
873 |
|
874 |
|
875 /** Network request for LBS capabilities |
|
876 @see MNetworkObserver |
|
877 */ |
|
878 void CProtocolManager::GetCapabilities(TLbsNetPosCapabilities& aCapabilities) |
|
879 { |
|
880 Gateway()->GetCapabilities(aCapabilities); |
|
881 } |
|
882 |
|
883 /** Network request for reseting of assistance data |
|
884 @see MNetworkObserver |
|
885 */ |
|
886 void CProtocolManager::ResetAssistanceData(TLbsAssistanceDataGroup aMask) |
|
887 { |
|
888 iAssistMgr->ResetData(); |
|
889 Gateway()->ResetAssistanceData(aMask, iAssistMgr->ValidData()); |
|
890 } |
|
891 |
|
892 // MStateMachineObserver methods |
|
893 |
|
894 /** Gateway interface pointer. |
|
895 @see MStateMachineObserver |
|
896 */ |
|
897 MProtocolMgrObserver* CProtocolManager::Gateway() |
|
898 { |
|
899 return &iGateway; |
|
900 } |
|
901 |
|
902 |
|
903 /** Network interface pointer. |
|
904 @see MStateMachineObserver |
|
905 */ |
|
906 CNetworkInterface* CProtocolManager::Network() |
|
907 { |
|
908 return iNetwork; |
|
909 } |
|
910 |
|
911 |
|
912 /** State machine procedure complete notification |
|
913 @see MStateMachineObserver |
|
914 */ |
|
915 void CProtocolManager::ProcedureCompleteInd() |
|
916 { |
|
917 LBSLOG(ELogP2, "CProtocolManager::ProcedureCompleteInd() CurrentOp --> None\n"); |
|
918 // Status update sent to LBS |
|
919 StatusUpdate(iCurrentOp.iOperation, EFalse); // EFalse=operation ended |
|
920 |
|
921 iCurrentOp.iOperation = CConfigManager::EOpNone; |
|
922 iCurrentOp.iPriority = CConfigManager::EPriorityNone; |
|
923 |
|
924 // Identify if any request was queued and if this is the case |
|
925 // start the relevant state machine. |
|
926 CStateMachineBase* queuedMachine; |
|
927 GetQueuedStateMachine(queuedMachine); |
|
928 if (NULL != queuedMachine) |
|
929 { |
|
930 // Set the current operation appropriately: |
|
931 if(queuedMachine == iMtLr) |
|
932 { |
|
933 iCurrentOp.iOperation = CConfigManager::EOpMtLr; |
|
934 } |
|
935 else if(queuedMachine == iMoLr) |
|
936 { |
|
937 iCurrentOp.iOperation = CConfigManager::EOpMoLr; |
|
938 } |
|
939 else if(queuedMachine == iX3p) |
|
940 { |
|
941 // TO DO - how do we know what priority to use here!? |
|
942 iCurrentOp.iOperation = CConfigManager::EOpX3p; |
|
943 } |
|
944 else |
|
945 { |
|
946 ASSERT(queuedMachine == iNetLoc); |
|
947 iCurrentOp.iOperation = CConfigManager::EOpNbLr; |
|
948 } |
|
949 |
|
950 // Set Current Operation appropriately: |
|
951 queuedMachine->StartQueuedMachine(); |
|
952 } |
|
953 } |
|
954 |
|
955 |
|
956 /** Handle Measurement Control timeout |
|
957 @see MStateMachineObserver |
|
958 */ |
|
959 void CProtocolManager::MeasurementControlTimeout() |
|
960 { |
|
961 // Store assistance data error |
|
962 iAssistMgr->Error(KErrTimedOut); |
|
963 |
|
964 // Check if we have an active state machine to handle this, |
|
965 // otherwise silently consume this indication. |
|
966 CStateMachineBase* activeMachine; |
|
967 GetActiveStateMachine(activeMachine); |
|
968 if (NULL != activeMachine) |
|
969 { |
|
970 // Advise state machine of error |
|
971 activeMachine->MeasurementControlTimeout(); |
|
972 } |
|
973 } |
|
974 |
|
975 |
|
976 /** Handle network error reported |
|
977 @see MStateMachineObserver |
|
978 */ |
|
979 void CProtocolManager::NetworkErrorReported() |
|
980 { |
|
981 NetworkErrorInd(KErrDisconnected); |
|
982 } |
|
983 |
|
984 |
|
985 /** Perform assistance data request action. |
|
986 This is called by state machines when they are in suitable state to |
|
987 handle assistance data actions. |
|
988 |
|
989 The actions will arises from preceding assistance data requests and responses |
|
990 which have been processed by the assistance data manager. |
|
991 @see CAssistDataMgr::ProcessDataRequest() |
|
992 @see CAssistDataMgr::StoreData() |
|
993 @see CAssistDataMgr::Error() |
|
994 |
|
995 @see MStateMachineObserver |
|
996 */ |
|
997 void CProtocolManager::DoAssistanceDataActions() |
|
998 { |
|
999 // Is there a data response error to be reported to LBS? |
|
1000 if (iAssistMgr->IsErrorToBeReported()) |
|
1001 { |
|
1002 // note: send any available valid data anyway |
|
1003 Gateway()->AssistanceDataInd(iAssistMgr->ErrorGroupMask(), iAssistMgr->ValidData(), iAssistMgr->ErrorReason()); |
|
1004 iAssistMgr->ErrorReported(); |
|
1005 } |
|
1006 |
|
1007 // Is there valid data to be reported to LBS? |
|
1008 if (iAssistMgr->IsDataToBeReported()) |
|
1009 { |
|
1010 Gateway()->AssistanceDataInd(iAssistMgr->ValidGroupMask(), iAssistMgr->ValidData(), KErrNone); |
|
1011 iAssistMgr->DataReported(); |
|
1012 } |
|
1013 |
|
1014 // Is there a request error to be reported to LBS? |
|
1015 if (iAssistMgr->IsRequestErrorToBeReported()) |
|
1016 { |
|
1017 Gateway()->AssistanceDataInd(iAssistMgr->RequestErrorMask(), iAssistMgr->ValidData(), KErrArgument); |
|
1018 iAssistMgr->RequestErrorReported(); |
|
1019 } |
|
1020 |
|
1021 // Is data required from the network? |
|
1022 if (iAssistMgr->IsDataToBeRequested()) |
|
1023 { |
|
1024 iAssistMgr->SendingRequest(); |
|
1025 Network()->MeasurementControlReq(iAssistMgr->RequestMask()); |
|
1026 // Start the timer for receiving additional assistance data |
|
1027 CStateMachineBase* activeMachine; |
|
1028 GetActiveStateMachine(activeMachine); |
|
1029 if (NULL != activeMachine) |
|
1030 { |
|
1031 activeMachine->StartAssistDataTimer(); |
|
1032 } |
|
1033 iAssistMgr->RequestSent(); |
|
1034 } |
|
1035 } |
|
1036 |
|
1037 |
|
1038 |
|
1039 /** Inform LBS of status update. |
|
1040 This is called when a new operation starts or when a current operation ends. |
|
1041 |
|
1042 @param aOperation Indicates the type of operation |
|
1043 @param aIsOperationStarting ETrue if operation is starting |
|
1044 */ |
|
1045 void CProtocolManager::StatusUpdate( |
|
1046 CConfigManager::TConflictOp aOperation, |
|
1047 TBool aIsOperationStarting) |
|
1048 { |
|
1049 MLbsNetworkProtocolObserver::TLbsNetProtocolServiceMask mask = MLbsNetworkProtocolObserver::EServiceNone; |
|
1050 switch (aOperation) |
|
1051 { |
|
1052 case CConfigManager::EOpMoLr: |
|
1053 mask = MLbsNetworkProtocolObserver::EServiceSelfLocation; |
|
1054 break; |
|
1055 case CConfigManager::EOpNbLr: |
|
1056 mask = MLbsNetworkProtocolObserver::EServiceNetworkLocation; |
|
1057 break; |
|
1058 case CConfigManager::EOpMtLr: |
|
1059 mask = MLbsNetworkProtocolObserver::EServiceMobileTerminated; |
|
1060 break; |
|
1061 case CConfigManager::EOpNiLr: |
|
1062 mask = MLbsNetworkProtocolObserver::EServiceNetworkInduced; |
|
1063 break; |
|
1064 case CConfigManager::EOpX3p: |
|
1065 mask = MLbsNetworkProtocolObserver::EServiceTransmitThirdParty; |
|
1066 break; |
|
1067 |
|
1068 case CConfigManager::EOpNone: |
|
1069 default: |
|
1070 break; |
|
1071 }; |
|
1072 |
|
1073 if (aIsOperationStarting) |
|
1074 { |
|
1075 iActiveServiceMask |= mask; |
|
1076 } |
|
1077 else |
|
1078 { |
|
1079 iActiveServiceMask &= ~mask; |
|
1080 } |
|
1081 #pragma message ("Status updates ommitted for now") |
|
1082 // Gateway()->StatusUpdate(iActiveServiceMask); |
|
1083 } |