locationrequestmgmt/networkrequesthandler/src/x3phandler.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <e32std.h>
       
    20 
       
    21 // LBS-specific
       
    22 #include <lbs.h>
       
    23 #include <lbs/lbsx3p.h>
       
    24 #include "lbsdevloggermacros.h"
       
    25 
       
    26 #include "lbsnrhserver.h"
       
    27 #include "x3phandler.h"
       
    28 #include "ngmessageswitch.h"
       
    29 
       
    30 
       
    31 const TInt KReservedRequestsNum = 4;
       
    32 
       
    33 
       
    34 CX3pHandler::CX3pHandler(CNGMessageSwitch& aMessageSwitch, MX3pStatusHandler& aX3pStatusHandler, CLbsAdmin& aLbsAdmin) : 
       
    35 	iMessageSwitch(aMessageSwitch),
       
    36 	iNextSessionId(1),
       
    37 	iAdmin(aLbsAdmin),
       
    38 	iReceivedFinalNetPosInfo(EFalse),
       
    39 	iX3pStatusHandler(aX3pStatusHandler)
       
    40     {
       
    41 	
       
    42     }
       
    43 
       
    44 CX3pHandler* CX3pHandler::NewL(CNGMessageSwitch& aMessageSwitch, MX3pStatusHandler& aX3pStatusHandler, CLbsAdmin& aLbsAdmin)
       
    45     {
       
    46 	CX3pHandler* self;
       
    47 	self = new (ELeave) CX3pHandler(aMessageSwitch, aX3pStatusHandler, aLbsAdmin);
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL();
       
    50 	CleanupStack::Pop(self);
       
    51 	return(self);	
       
    52     }
       
    53 
       
    54 CX3pHandler::~CX3pHandler()
       
    55 	{
       
    56 	iX3pObservers.Close();
       
    57 	iX3pRequests.ResetAndDestroy();
       
    58 	}
       
    59     
       
    60 void CX3pHandler::ConstructL()
       
    61     {
       
    62 	iMessageSwitch.RegisterObserver(this);
       
    63 	TInt err = iAdmin.Get(KLbsSettingBehaviourMode, iLbsBehaviourMode);
       
    64 	if (err != KErrNone)
       
    65 		{
       
    66 		iLbsBehaviourMode = CLbsAdmin::ELbsBehaviourCustom1;
       
    67 		}	
       
    68 	
       
    69 	// get device mode capabilities:
       
    70 	err = LbsModuleInfo::GetDeviceCapabilities(KLbsGpsLocManagerUid, iDeviceGpsModeCaps);
       
    71 	if(err != KErrNone)
       
    72 		{
       
    73 		// Assume module supports hybrid if it has not reported its capabilities in module info file
       
    74 		iDeviceGpsModeCaps = TPositionModuleInfoExtended::EDeviceGpsModeSimultaneousTATB;
       
    75 		}
       
    76 	
       
    77 	iX3pRequests.ReserveL(KReservedRequestsNum);
       
    78 	iX3pObservers.ReserveL(KReservedRequestsNum);
       
    79 	
       
    80     iActiveRequestIndex = KErrNotFound;
       
    81     
       
    82     UpdateX3pStatus();
       
    83     }
       
    84 
       
    85 void CX3pHandler::TransmitLocationRequestL(const TDesC& aDestinationID,
       
    86 										   TUint aTransmitPriority, 
       
    87 										   const TLbsTransmitPositionOptions& aTransmitOptions,
       
    88 										   TLbsNetSessionIdInt& aSessionId)
       
    89 	{
       
    90 	LBSLOG(ELogP1, "CX3pHandler::TransmitLocationRequestL:");
       
    91 	
       
    92 	// Generate a new session Id
       
    93 	TLbsNetSessionIdInt sessionId(KLbsNetRequestHandlerUid, iNextSessionId++);
       
    94 
       
    95     // Create an instance for this request.
       
    96     CX3pRequest* newRequest = 0;
       
    97 	newRequest = CX3pRequest::NewL(this, sessionId,
       
    98 								   aDestinationID,
       
    99 								   aTransmitPriority,
       
   100 								   aTransmitOptions);
       
   101 	CleanupStack::PushL(newRequest);
       
   102 	iX3pRequests.AppendL(newRequest);
       
   103 	CleanupStack::Pop(newRequest);
       
   104 	
       
   105 	// Write the session Id back to the caller
       
   106 	aSessionId = sessionId;
       
   107 
       
   108     //
       
   109     // The timeout (if specified) runs from the time the request was made, so 
       
   110     // start the request timer now, even if we're not going to action the 
       
   111     // request yet
       
   112     //
       
   113 	newRequest->StartTimer();
       
   114 	
       
   115 	//
       
   116 	// The new request has been added. Now see if there is a request being
       
   117 	// actioned at the moment. If not, start this one
       
   118 	//
       
   119 	TInt newRequestIndex = iX3pRequests.Count() - 1;
       
   120 	TInt currentRequestIndex = iActiveRequestIndex;
       
   121 	if(iActiveRequestIndex == KErrNotFound)
       
   122 	    {
       
   123 		currentRequestIndex = newRequestIndex;
       
   124 	    }
       
   125 	else
       
   126 	    {
       
   127         // 
       
   128         // If there is an active request, see if its priority is lower than 
       
   129         // the new one. If so, action the new one.
       
   130         // The Network Gateway handles the necessary cancellations.
       
   131         //
       
   132         if(iActiveRequest->TransmitPriority() > aTransmitPriority)
       
   133             {
       
   134             LBSLOG3(ELogP2, "New X3P (priority %d) overrides currently active X3P (priority %d)", 
       
   135             				aTransmitPriority, 
       
   136             				iActiveRequest->TransmitPriority());
       
   137             				
       
   138 		    currentRequestIndex = newRequestIndex;
       
   139             }
       
   140 	    }
       
   141 	if(currentRequestIndex != iActiveRequestIndex)
       
   142 	    {
       
   143 	    iActiveRequestIndex = currentRequestIndex;
       
   144 		ActivateRequest();
       
   145 	    }
       
   146 	}
       
   147 
       
   148 void CX3pHandler::TransmitLocationCancel(const TLbsNetSessionIdInt& aSessionId)
       
   149 	{
       
   150 	LBSLOG(ELogP1, "CX3pHandler::TransmitLocationCancel:");
       
   151 
       
   152 	// There is a chance that we get a 'cancel' for an X3P request
       
   153 	// that has already finished normally, so first check that
       
   154 	// the sessionId is one that is currently active.
       
   155 	TInt requestIndex = FindSessionById(aSessionId);
       
   156 	if(requestIndex != KErrNotFound)
       
   157 		{
       
   158 		// Forward the cancel message onto the network
       
   159 		iMessageSwitch.SendX3pCancel(aSessionId, KErrCancel);
       
   160 		}
       
   161 	}
       
   162     
       
   163 void CX3pHandler::ActivateRequest()	    
       
   164 	{
       
   165 	if(iActiveRequestIndex != KErrNotFound)
       
   166 		{
       
   167 		iActiveRequest = iX3pRequests[iActiveRequestIndex];
       
   168 		
       
   169 		// Get the technology type to use for this request from the admin settings.
       
   170 		TPositionModuleInfo::TTechnologyType mode;
       
   171 		GetAdminTechnologyType(mode);
       
   172 		TLbsNetPosRequestOptionsTechnologyInt options;
       
   173 		options.SetPosMode(mode);
       
   174 		
       
   175 		iMessageSwitch.SendX3pRequest(iActiveRequest->SessionId(),
       
   176 									  iActiveRequest->DestinationId(),
       
   177 									  iActiveRequest->TransmitPriority(),
       
   178 									  options);
       
   179 		
       
   180 		// Reset the final network position flag
       
   181 		iReceivedFinalNetPosInfo = EFalse;
       
   182 		}
       
   183 	}
       
   184 
       
   185 /* Called when a pending request has timed out before it was completed.
       
   186  */
       
   187 void CX3pHandler::OnRequestTimeout(const TLbsNetSessionIdInt& aTimedOutRequestId)
       
   188     {
       
   189 	if(aTimedOutRequestId.SessionNum() != 0)
       
   190 		{
       
   191 		HandleTimedOutRequest(aTimedOutRequestId);
       
   192 		}
       
   193     }
       
   194 
       
   195 /*
       
   196 */
       
   197 TInt CX3pHandler::HighestPriorityIndex()
       
   198     {
       
   199     TInt index = KErrNotFound;
       
   200     const TInt count = iX3pRequests.Count();
       
   201     if (count > 0)
       
   202     	{
       
   203     	CX3pRequest* highPriorityReq = iX3pRequests[0];
       
   204     	index = 0;
       
   205     	for (TInt i = 1; i < count; i++)
       
   206     		{
       
   207     		CX3pRequest* request = iX3pRequests[i];
       
   208     		if (request->TransmitPriority() > 
       
   209     			highPriorityReq->TransmitPriority())
       
   210     			{
       
   211     			index = i;
       
   212     			highPriorityReq = request;
       
   213     			}
       
   214     		}
       
   215    		}
       
   216 
       
   217 	return (index);
       
   218 	}
       
   219 
       
   220 
       
   221 /* Look through the array of requests to find the one with a session Id
       
   222    equal to the input aSessionId.
       
   223    
       
   224    Set the reference parameter aSessionIndex to the array index of the
       
   225    request, and return a pointer to the request.
       
   226    If no request is found with the specified aSessionId, then return NULL.
       
   227 */
       
   228 TInt CX3pHandler::FindSessionById(const TLbsNetSessionIdInt& aSessionId)
       
   229     {
       
   230     TInt retVal = KErrNotFound;
       
   231 	TInt requestCount = iX3pRequests.Count();
       
   232 	for (TInt i = 0; i < requestCount; ++i)
       
   233 	    {
       
   234 		if(iX3pRequests[i]->SessionId() == aSessionId)
       
   235 		    {
       
   236 		    retVal = i;
       
   237 		    break;
       
   238 		    }
       
   239 	    }
       
   240 	return(retVal);    
       
   241     }
       
   242 
       
   243 /* Search the array following a delete to find the index
       
   244    of the currently active request, looking for it by its session ID.
       
   245 */
       
   246 void CX3pHandler::RecalculateActiveIndex(const TLbsNetSessionIdInt& aSessionId)
       
   247     {
       
   248 	iActiveRequestIndex = FindSessionById(aSessionId);
       
   249     }
       
   250 
       
   251 void CX3pHandler::HandleTimedOutRequest(const TLbsNetSessionIdInt& aRequestId)
       
   252     {
       
   253 	// Send a cancel message to the network,
       
   254 	//  with KErrTimedOut as the reason
       
   255 	iMessageSwitch.SendX3pCancel(aRequestId, KErrTimedOut);	
       
   256     }
       
   257 
       
   258 
       
   259 void CX3pHandler::HandleCompletedRequest(const TLbsNetSessionIdInt& aRequestId, TInt aReason)
       
   260     {
       
   261     TInt err = aReason;
       
   262     TBool isTerminalAssistedPos = EFalse;
       
   263     //
       
   264     // There's a possibility this request ID won't be found, if a Transmit
       
   265     // Cancel was received after the request had been sent off. If this
       
   266     // is the case, just ignore the completion.
       
   267     //
       
   268 	TInt requestIndex = FindSessionById(aRequestId);
       
   269 	if(requestIndex != KErrNotFound)
       
   270 		{
       
   271 		if (!iReceivedFinalNetPosInfo)
       
   272 			{
       
   273 			TInt ret = iMessageSwitch.GetNetworkFinalPosition(aRequestId, iFinalNetPosInfo);
       
   274 			if (err == KErrNone && ret != KErrNone)
       
   275 				{
       
   276 				err = ret;
       
   277 				}
       
   278 			}
       
   279 
       
   280 		// Add the ID of the module supplying the update. This is either 
       
   281 		// the GPS Location Manager or the Network Location Manager (if 
       
   282 		// the Position Mode is not one of those below, leave the Module Id
       
   283 		// unchanged).
       
   284 		TPositionModuleInfo::TTechnologyType posMode = iFinalNetPosInfo.PositionMode();
       
   285 		if(posMode == (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted))
       
   286 			{
       
   287 			iFinalNetPosInfo.SetModuleId(KLbsGpsLocManagerUid);
       
   288 			}
       
   289 		else
       
   290 			if(posMode == (TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted))
       
   291 				{
       
   292 				iFinalNetPosInfo.SetModuleId(KLbsNetLocManagerUid);
       
   293 				isTerminalAssistedPos = ETrue;
       
   294 				}
       
   295 
       
   296 		// It may be that the network has modified the position update, 
       
   297 		// so we need to check that it satisfies the quality criteria and report
       
   298 		// it if not.
       
   299 		if(aReason == KErrNone) // network thinks it's OK
       
   300 			{
       
   301 			if(!iX3pRequests[requestIndex]->FixIsAccurate(iFinalNetPosInfo, isTerminalAssistedPos))
       
   302 				{
       
   303 				err = KPositionQualityLoss;
       
   304 				}
       
   305 			}
       
   306 				
       
   307 		// Notify observers of the completed session
       
   308 		const TInt count = iX3pObservers.Count();
       
   309 		for (TInt i = 0; i < count; i++)
       
   310 			{
       
   311 			iX3pObservers[i]->OnTransmitLocationComplete(
       
   312 									aRequestId, 
       
   313 									iFinalNetPosInfo,
       
   314 									err);
       
   315 			}
       
   316 		
       
   317 		// Remove the request from the list
       
   318 		delete iX3pRequests[requestIndex];
       
   319 		iX3pRequests.Remove(requestIndex);
       
   320 
       
   321 		// If the completed request was being actioned, start the next
       
   322 		// one if there is one.
       
   323 		if(requestIndex == iActiveRequestIndex)
       
   324 			{
       
   325 			iActiveRequestIndex = HighestPriorityIndex();
       
   326 			if(iActiveRequestIndex != KErrNotFound)
       
   327 				{
       
   328 				ActivateRequest();
       
   329 				}
       
   330 		}
       
   331 		else
       
   332 			{
       
   333 			// The array has been changed by the removal of an entry.
       
   334 			// Make sure iActiveRequestIndex is correct for the active
       
   335 			// entry.
       
   336 			TLbsNetSessionIdInt activeSessionId = iActiveRequest->SessionId();
       
   337 			RecalculateActiveIndex(activeSessionId);
       
   338 			}    
       
   339 		}
       
   340 	
       
   341  	// Tell the AGPS interface handler the current state
       
   342  	// of the X3P handler.
       
   343  	UpdateX3pStatus();
       
   344 	}
       
   345 
       
   346 /*
       
   347 */
       
   348 void CX3pHandler::OnMTLRRequest(const TLbsNetSessionIdInt& /*SessionId*/,
       
   349 				  TLbsNetworkEnumInt::TLbsNetProtocolServiceInt  /*aSessionType*/, 
       
   350 				   TBool /*aIsEmergency*/,
       
   351 				   const TLbsExternalRequestInfo& /*aExternalRequestInfo*/,
       
   352 				   const TLbsNetPosRequestPrivacyInt& /*aNetPosRequestPrivacy*/)
       
   353 	{
       
   354 	// We do not need to know about MT-LR requests so ignore this call.
       
   355 	}
       
   356 
       
   357 void CX3pHandler::OnNetLocResponse(const TLbsNetSessionIdInt& aSessionId,
       
   358 								 const TLbsNetPosRequestQualityInt& aQuality)
       
   359 	{
       
   360 	// Check if this Network Location Response
       
   361 	// is for a X3P that is currently in progress
       
   362 	TInt requestIndex = FindSessionById(aSessionId);
       
   363 	if (requestIndex != KErrNotFound)
       
   364 		{
       
   365 		iX3pRequests[requestIndex]->SetRequestQuality(aQuality);
       
   366 		}
       
   367 	}
       
   368 
       
   369 /*
       
   370 */
       
   371 void CX3pHandler::OnSessionComplete(const TLbsNetSessionIdInt& aSessionId, TInt aReason)
       
   372 	{
       
   373 	// Check if this Network Location Response
       
   374 	// is for a X3P that is currently in progress
       
   375 	TInt requestIndex = FindSessionById(aSessionId);
       
   376 	if (requestIndex != KErrNotFound)
       
   377 		{
       
   378 		HandleCompletedRequest(aSessionId, aReason);
       
   379 		}
       
   380 	}
       
   381 
       
   382 /* Called during a TransmitLocation request, at the point where the network provides the
       
   383 handset with a network-based Reference Location.
       
   384 
       
   385 The Reference Location (aRefPosInfo) will be sent back to the client's session, and the session
       
   386 will forward it back to the client if the client wants it.
       
   387 
       
   388 Values of aIsEmengency and aQuality are not relevant for the CX3pHandler (they are for
       
   389 other observers)
       
   390 */
       
   391 void CX3pHandler::OnNetLocRequest(const TLbsNetSessionIdInt& aSessionId,
       
   392 					const TLbsNetPosRequestMethodInt& aNetPosMethod,
       
   393 					 TLbsNetworkEnumInt::TLbsNetProtocolServiceInt /*aSessionType*/, 
       
   394 					 TBool /*aIsEmergency*/,
       
   395 					 const TLbsNetPosRequestQualityInt& /*aQuality*/)
       
   396 	{
       
   397 	TBool hybridMode = EFalse;
       
   398 	TLbsNetPosMethodInt posMethod;
       
   399 	
       
   400 	const TPositionModuleInfo::TTechnologyType KTerminalAssistedMode = (
       
   401 				TPositionModuleInfo::ETechnologyNetwork |
       
   402 				TPositionModuleInfo::ETechnologyAssisted);
       
   403 				
       
   404 	// Does the hardware support hybrid mode?
       
   405 	if(iDeviceGpsModeCaps & TPositionModuleInfoExtended::EDeviceGpsModeSimultaneousTATB )
       
   406 		{
       
   407 		TInt methodCount = aNetPosMethod.NumPosMethods();
       
   408 		for(TInt i = 0; (i < methodCount) && !hybridMode; ++i)
       
   409 			{
       
   410 			aNetPosMethod.GetPosMethod(i, posMethod);
       
   411 			hybridMode = (posMethod.PosMode() & KTerminalAssistedMode) == KTerminalAssistedMode;
       
   412 			}
       
   413 		}
       
   414 	
       
   415 	// Custom1: If the hybrid mode and a first request, then re-start the timer
       
   416 	if (hybridMode 
       
   417 		&& (aSessionId.SessionOwner() == KLbsNetRequestHandlerUid) 
       
   418 		&& (iLbsBehaviourMode == CLbsAdmin::ELbsBehaviourCustom1))
       
   419 		{
       
   420 		TInt requestIndex = FindSessionById(aSessionId);
       
   421 		if(requestIndex != KErrNotFound)
       
   422 			{
       
   423 			// The timer can be re-started only once
       
   424 			iX3pRequests[requestIndex]->ReStartTimerOnce();
       
   425 	   		}
       
   426 	   	}
       
   427 	}
       
   428 
       
   429 /** Called when a reference position arrives from the network.
       
   430 */
       
   431 void CX3pHandler::OnNetLocReferenceUpdate(const TLbsNetSessionIdInt& aSessionId, 
       
   432 								 		  const TPositionInfoBase& aPosInfo)
       
   433 	{
       
   434     // There's a possibility this request ID won't be found, if a Transmit
       
   435     // Cancel was received after the request had been sent off. If this
       
   436     // is the case, just ignore the completion.
       
   437 	if (aSessionId.SessionOwner() == KLbsNetRequestHandlerUid)
       
   438 		{
       
   439 		iRefPosInfo = static_cast<const TPositionInfo&>(aPosInfo);
       
   440 
       
   441 		TInt requestIndex = FindSessionById(aSessionId);
       
   442 		if(requestIndex != KErrNotFound)
       
   443 			{
       
   444 			iRefPosInfo.SetModuleId(KLbsGpsLocManagerUid);
       
   445 			iRefPosInfo.SetPositionMode(TPositionModuleInfo::ETechnologyNetwork);
       
   446 			iRefPosInfo.SetPositionModeReason(EPositionModeReasonNone);
       
   447 			iRefPosInfo.SetUpdateType(EPositionUpdateGeneral);
       
   448 		
       
   449 	   		// Notify observers of the completed session
       
   450 	   		const TInt count = iX3pObservers.Count();
       
   451 	   		for (TInt i = 0; i < count; i++)
       
   452 	   			{
       
   453 	   			iX3pObservers[i]->OnReferenceLocationAvailable(
       
   454 	   									aSessionId, 
       
   455 	  									iRefPosInfo);
       
   456 	   			}
       
   457 	   		}
       
   458 	   	}	
       
   459 	}
       
   460 
       
   461 /** Callend when a final location arrives from the network.
       
   462 */
       
   463 void CX3pHandler::OnNetLocFinalUpdate(
       
   464 		const TLbsNetSessionIdInt& aSessionId, 
       
   465 		const TPositionInfoBase& aPosInfo)
       
   466 	{
       
   467 	// If the final network position is for an active X3P, 
       
   468 	// then store it for when the X3P is completed.
       
   469 	TInt requestIndex = FindSessionById(aSessionId);
       
   470 	if (requestIndex != KErrNotFound)
       
   471 		{
       
   472 		if (requestIndex == iActiveRequestIndex)
       
   473 			{
       
   474 			iReceivedFinalNetPosInfo = ETrue;
       
   475 			iFinalNetPosInfo = static_cast<const TPositionInfo&>(aPosInfo);
       
   476 			}
       
   477 		}
       
   478 	}
       
   479 
       
   480 TInt CX3pHandler::OnTransmitPosition(const TDesC& aDestinationId,
       
   481 									 TUint aTransmitPriority,
       
   482 									 const TLbsTransmitPositionOptions& aTransmitOptions,
       
   483 									 TLbsNetSessionIdInt& aSessionId)
       
   484 	{
       
   485 	TInt err(KErrNone);
       
   486 	TRAP(err, TransmitLocationRequestL(aDestinationId, aTransmitPriority,
       
   487 									   aTransmitOptions, aSessionId));
       
   488 	
       
   489  	// Tell the AGPS interface handler the current state
       
   490  	// of the X3P handler.
       
   491  	UpdateX3pStatus();
       
   492 	
       
   493 	return err;
       
   494 	}
       
   495 	
       
   496 void CX3pHandler::OnCancelTransmitPosition(const TLbsNetSessionIdInt& aSessionId)
       
   497 	{
       
   498 	TransmitLocationCancel(aSessionId);
       
   499 	}
       
   500 
       
   501 /* Add an observer (actually a client X3P subsession)
       
   502 */
       
   503 void CX3pHandler::AddObserverL(MX3pHandlerObserver* aObserver)
       
   504  	{
       
   505  	iX3pObservers.AppendL(aObserver);
       
   506  	
       
   507  	// Tell the AGPS interface handler the current state
       
   508  	// of the X3P handler.
       
   509  	UpdateX3pStatus();
       
   510  	}
       
   511 
       
   512 /* Remove an observer (actually a client X3P subsession)
       
   513 */
       
   514 void CX3pHandler::RemoveObserver(MX3pHandlerObserver* aObserver)
       
   515  	{
       
   516  	TInt index = iX3pObservers.Find(aObserver);
       
   517  	if (index != KErrNotFound)
       
   518  		{
       
   519  		iX3pObservers.Remove(index);
       
   520  		}
       
   521  
       
   522  	// Tell the AGPS interface handler the current state
       
   523  	// of the X3P handler.
       
   524  	UpdateX3pStatus();
       
   525  	}
       
   526 
       
   527 /** Send the current X3P status to the status handler - for power mode advice.
       
   528 */
       
   529 void CX3pHandler::UpdateX3pStatus()
       
   530 	{
       
   531 	
       
   532 	MX3pStatusHandler::TX3pStatus status(MX3pStatusHandler::EX3pStatusIdle);
       
   533 	if (iActiveRequestIndex != KErrNotFound)
       
   534 		{
       
   535 		// There is a currently active request, so we are 'active'
       
   536 		status = MX3pStatusHandler::EX3pStatusActive;
       
   537 		}
       
   538 	else
       
   539 		{
       
   540 	 	if (iX3pObservers.Count() >= 1)
       
   541 	 		{
       
   542 		 	// If there is one or more observer (i.e. session) in the array,
       
   543 		 	// then set the X3P status to 'connected', in case the GPS hardware
       
   544 		 	// needs to be informed to go into a warm-up state.
       
   545 	 		status = MX3pStatusHandler::EX3pStatusConnected;
       
   546 	 		}
       
   547 	 	else if (iX3pObservers.Count() == 0)
       
   548 	 		{
       
   549 	 	 	// If there are no observers (i.e. sessions), then tell
       
   550 	 	 	// the X3P status handler that we are 'idle', since there are no
       
   551 	 	 	// outstanding X3P requests or sessions connected.
       
   552 	 		status = MX3pStatusHandler::EX3pStatusIdle;
       
   553 	 		}
       
   554 		}
       
   555 	// Update the X3P status. 
       
   556 	iX3pStatusHandler.SetX3pStatus(status);
       
   557 	}
       
   558 
       
   559 void CX3pHandler::GetAdminTechnologyType(TPositionModuleInfo::TTechnologyType& aMode)
       
   560 	{
       
   561 	aMode = TPositionModuleInfo::ETechnologyUnknown;
       
   562 	
       
   563 	// Determine the current technology type from the admin settings
       
   564 	RLbsNetworkRegistrationStatus lbsNetRegStatus;
       
   565 	TRAPD(err, lbsNetRegStatus.OpenL());
       
   566 	if(err != KErrNone)
       
   567 	    {
       
   568         // Netreg status could not be determined mode will be ETechnologyUnknown
       
   569         return;
       
   570 	    }
       
   571     RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus netRegStatus;
       
   572     err = lbsNetRegStatus.GetNetworkRegistrationStatus(netRegStatus);
       
   573 	lbsNetRegStatus.Close();			    
       
   574     if (err == KErrNone)
       
   575     	{
       
   576     	TLbsAdminSetting setting;
       
   577     	switch (netRegStatus)
       
   578     		{
       
   579     		case RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork:
       
   580     			setting = KLbsSettingHomeGpsMode;
       
   581     			break;
       
   582     		case RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork:
       
   583     			setting = KLbsSettingRoamingGpsMode;
       
   584 				break;
       
   585     		default:
       
   586     			// default to using the roaming setting
       
   587     			LBSLOG_WARN2(ELogP3, 
       
   588     						 "CX3pHandler::GetAdminTechnologyType: unkown network registration status (%d), defaulting to roaming.", 
       
   589     						 netRegStatus);
       
   590     			setting = KLbsSettingRoamingGpsMode;
       
   591     			break;
       
   592     		}
       
   593     	
       
   594 		CLbsAdmin::TGpsMode gpsMode;
       
   595 		err = iAdmin.Get(setting, gpsMode);
       
   596 		if (err == KErrNone)
       
   597 			{
       
   598 			switch (gpsMode)
       
   599 				{
       
   600 				case CLbsAdmin::EGpsModeUnknown:
       
   601 					aMode = (TPositionModuleInfo::ETechnologyUnknown);
       
   602 					break;
       
   603 					
       
   604 				case CLbsAdmin::EGpsPreferTerminalBased:
       
   605 					aMode = (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   606 					break;
       
   607 					
       
   608 				case CLbsAdmin::EGpsAlwaysTerminalBased:
       
   609 					aMode = (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   610 					break;
       
   611 					
       
   612 				case CLbsAdmin::EGpsAutonomous:
       
   613 					aMode = (TPositionModuleInfo::ETechnologyTerminal);
       
   614 					break;
       
   615 					
       
   616 				case CLbsAdmin::EGpsPreferTerminalAssisted:
       
   617 					aMode = (TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   618 					break;
       
   619 					
       
   620 				case CLbsAdmin::EGpsAlwaysTerminalAssisted:
       
   621 					aMode = (TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   622 					break;
       
   623 				
       
   624 				default:
       
   625 					aMode = (TPositionModuleInfo::ETechnologyUnknown);
       
   626 					 			// default to using the roaming setting
       
   627     				LBSLOG_WARN2(ELogP3, 
       
   628     						 "CX3pHandler::GetAdminTechnologyType: unkown TGpsMode (%d), defaulting to TPositionModuleInfo::ETechnologyUnknown.", 
       
   629     						 gpsMode);
       
   630 					break;
       
   631 				}
       
   632 			}
       
   633 	   	}
       
   634 	}
       
   635 
       
   636