locationmgmt/networkgateway/src/netgateway.cpp
changeset 0 9cfd9a3ee49c
child 48 81c9bee26a45
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2005-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 // Client API to the LBS Network Simulator for 
       
    15 // the (test) LBS protocol module.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22  @released
       
    23 */
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <e32debug.h>
       
    27 #include <ecom/ecom.h>
       
    28 #ifdef SYMBIAN_FEATURE_MANAGER
       
    29 	#include <featdiscovery.h>
       
    30 	#include <featureuids.h>
       
    31 #endif
       
    32 #include <lbs/lbslocerrors.h>
       
    33 #include <lbs/lbsadmin.h>
       
    34 #include <lbs/lbslocclasstypes.h>
       
    35 #include <lbs/lbsassistancedatabase.h>
       
    36 #include <lbs/lbsassistancedatabuilderset.h>
       
    37 #include <lbs/lbsnetcommon.h>
       
    38 #include "lbscommoninternaldatatypes.h"
       
    39 #include "LbsExtendModuleInfo.h"
       
    40 #include "LbsInternalInterface.h"
       
    41 #include "lbsdevloggermacros.h"
       
    42 #include "netgateway.h"
       
    43 #include "netregstatusmonitor.h"
       
    44 #include <lbs/lbsgpsmeasurement.h>
       
    45 #include "netgatewayasynccallback.h"
       
    46 #include "netobserver.h"
       
    47 #include "lbsnrhngmsgs.h"
       
    48 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    49 #include "lbsnetextintversions.h"
       
    50 #endif
       
    51 
       
    52 const TInt KLbsLogQueueSize = 10;
       
    53 
       
    54 // Privacy protocol module UID. This module is only currently used
       
    55 // in standalone privacy mode, but this may change if this module
       
    56 // is extended to support more than just privacy requests 
       
    57 const TUid KPrivacyProtocolModuleUid = { 0x1028373C };
       
    58 
       
    59 // Pre-defined technology type for autonomous.
       
    60 const TPositionModuleInfo::TTechnologyType KAutonomous = (TPositionModuleInfo::ETechnologyTerminal);
       
    61 
       
    62 // Pre-defined technology type for terminal-based (TB).
       
    63 const TPositionModuleInfo::TTechnologyType KTerminalBased = (TPositionModuleInfo::ETechnologyTerminal
       
    64 															 | TPositionModuleInfo::ETechnologyAssisted);
       
    65 
       
    66 // Pre-defined technology type for terminal-assisted (TA).
       
    67 const TPositionModuleInfo::TTechnologyType KTerminalAssisted = (TPositionModuleInfo::ETechnologyNetwork
       
    68 																| TPositionModuleInfo::ETechnologyAssisted);
       
    69 
       
    70 // Convert TLbsNetSessionId to TLbsNetSessionIdInt
       
    71 #define TLBSNETSESSIONIDINT(sessionId) \
       
    72 	TLbsNetSessionIdInt(sessionId.SessionOwner(), sessionId.SessionNum())
       
    73 
       
    74 // Convert TLbsNetSessionIdInt to TLbsNetSessionId
       
    75 #define TLBSNETSESSIONID(sessionId) \
       
    76 	TLbsNetSessionId(sessionId.SessionOwner(), sessionId.SessionNum())
       
    77 
       
    78 
       
    79 //
       
    80 // CNetworkGateway
       
    81 //
       
    82 
       
    83 /**
       
    84 */
       
    85 CNetworkGateway* CNetworkGateway::NewL()
       
    86 	{
       
    87 	CNetworkGateway* self = new (ELeave) CNetworkGateway;
       
    88 	CleanupStack::PushL(self);
       
    89 	self->ConstructL();
       
    90 	CleanupStack::Pop(self);
       
    91 	return self;	
       
    92 	}
       
    93 
       
    94 /**
       
    95 */
       
    96 CNetworkGateway::CNetworkGateway()
       
    97     {
       
    98     for (TInt index = 0; index < EInvalidSession; index++)
       
    99        {
       
   100        iModuleForSession[index] = NULL;
       
   101        }
       
   102 	}
       
   103 
       
   104 /**
       
   105 */	
       
   106 CNetworkGateway::~CNetworkGateway()
       
   107 	{
       
   108 	LBSLOG(ELogP9, "->S CLbsNetworkProtocolBase::~ClbsNetworkProtocolBase() ProtocolModule\n");
       
   109 
       
   110 	delete iExternalLogEvent;
       
   111 	
       
   112 	iLogger.Close();
       
   113 	
       
   114 	DeleteLoadedModules();
       
   115 	
       
   116 	delete iNetworkRequestChannel;
       
   117 	delete iPSYChannel;
       
   118 	delete iNetworkRegistrationStatusMonitor;
       
   119 	delete iAgpsChannel;
       
   120 	delete iNetworkLocationChannel;
       
   121 	delete iAdmin;
       
   122 	delete iCloseDownRequestDetector;
       
   123 	delete iRejectPrivacyRequest;
       
   124 	
       
   125 	REComSession::FinalClose();
       
   126 	#if defined(_DEBUG)
       
   127 		if(iOomListener)
       
   128 			{
       
   129 			iOomListener->Cancel();
       
   130 			delete iOomListener;
       
   131 			}
       
   132 	#endif 
       
   133 	
       
   134 	// Close the Subsession with the Location Monitor
       
   135 	if ( iLocMonSubSession.SubSessionHandle() )
       
   136         {
       
   137         iLocMonSubSession.Close();
       
   138         }
       
   139 	// Close the session with the Location Monitor
       
   140 	if ( iLocMonSession.Handle() )
       
   141         {
       
   142         iLocMonSession.Close();
       
   143         }
       
   144 	}
       
   145 
       
   146 /**
       
   147 */	
       
   148 void CNetworkGateway::ConstructL()
       
   149 	{
       
   150 	RProcess process;
       
   151 	iCloseDownRequestDetector = CLbsCloseDownRequestDetector::NewL(this, process.SecureId());
       
   152 	
       
   153 	iAdmin = CLbsAdmin::NewL();
       
   154 
       
   155 #ifdef SYMBIAN_FEATURE_MANAGER
       
   156 	TBool locationManagementSupported = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KLocationManagement);
       
   157 #else
       
   158 	TBool locationManagementSupported(ETrue);
       
   159 #endif
       
   160 	if(locationManagementSupported)
       
   161 		{
       
   162 		iNetworkLocationChannel = CNetworkLocationChannel::NewL(*this);
       
   163 		iAgpsChannel = CAgpsChannel::NewL(*this);
       
   164 		iNetworkRegistrationStatusMonitor = CNetworkRegistrationStatusMonitor::NewL(*this);
       
   165 		}
       
   166 	
       
   167 	iNetworkRequestChannel = CNetworkRequestChannel::NewL(*this);
       
   168 	iPSYChannel = CPsyRequestChannel::NewL(*this, RLbsNetChannel::EChannelNG2SUPLPSY);
       
   169 	
       
   170 	User::LeaveIfError(iAdmin->Get(KLbsProtocolModuleLoading, iLoadInfo));
       
   171 
       
   172 	TLbsAdminProtocolModulesInfo homeModules;
       
   173 	User::LeaveIfError(iAdmin->Get(KLbsSettingHomeProtocolModule, homeModules));
       
   174 	TLbsAdminProtocolModulesInfo roamingModules;
       
   175 	User::LeaveIfError(iAdmin->Get(KLbsSettingRoamingProtocolModule, roamingModules));
       
   176 	
       
   177 	homeModules.GetModuleIds(iHomePmUidArray, iHomePmCount);
       
   178 	roamingModules.GetModuleIds(iRoamingPmUidArray,iRoamingPmCount);
       
   179 	
       
   180 	// Use the default protocol modules
       
   181 	iHomePmUid		= iHomePmUidArray[0];
       
   182 	iRoamingPmUid	= iRoamingPmUidArray[0];
       
   183 
       
   184 	// Populate the list of all protocol modules with the home modules
       
   185 	for(TInt homeIndex = 0; homeIndex < iHomePmCount; homeIndex++)
       
   186 		{
       
   187 		CProtocolModuleInfo* info = CProtocolModuleInfo::NewL(iHomePmUidArray[homeIndex], NULL, NULL, ETrue, EFalse);
       
   188 		iModules[homeIndex] = info;
       
   189 		}
       
   190 	iPmCount = iHomePmCount;
       
   191 	
       
   192 	// Populate the list of all protocol modules with the roaming modules
       
   193 	for(TInt roamingIndex = 0; roamingIndex < iRoamingPmCount; roamingIndex++)
       
   194 		{
       
   195 		TLbsProtocolModuleId pmId = iRoamingPmUidArray[roamingIndex];
       
   196 		TBool alreadyPresent = EFalse;
       
   197 		
       
   198 		for(TInt index = 0; index < iHomePmCount; index++)
       
   199 			{
       
   200 			if(pmId == iModules[index]->ModuleUid())
       
   201 				{
       
   202 				alreadyPresent = ETrue;
       
   203 				iModules[index]->SetRoaming(); // If already present then set it as roaming as well
       
   204 				}
       
   205 			}
       
   206 		
       
   207 		// If not present create it
       
   208 		if(!alreadyPresent)
       
   209 			{
       
   210 			CProtocolModuleInfo* info = CProtocolModuleInfo::NewL(pmId, NULL, NULL, EFalse, ETrue);
       
   211 			iModules[iPmCount] = info;
       
   212 			iPmCount++;
       
   213 			}
       
   214 		}
       
   215 
       
   216 	if (iHomePmUid == KPrivacyProtocolModuleUid)
       
   217 		{
       
   218 		TRAPD(err, LoadProtocolModuleL(iHomePmUid));
       
   219 		iRegistrationStatus = RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork;
       
   220 		if (err != KErrNone)
       
   221 			{
       
   222 			LBSLOG_ERR3(ELogP3, "Error creating privacy protocol module UID 0x%x: %d",iHomePmUid , err);
       
   223 			}
       
   224 		}
       
   225 	else if(iLoadInfo.LoadingStrategy()==TLbsAdminProtocolModuleLoadingInfo::EProtocolModuleLoadingAll)
       
   226 		{
       
   227 		for(TUint index = 0; index < iPmCount; index++)
       
   228 			{
       
   229 			TRAPD(err, LoadProtocolModuleL(iModules[index]->ModuleUid()));
       
   230 			if (err != KErrNone)
       
   231 				{
       
   232 				LBSLOG_ERR3(ELogP3, "Error creating protocol module, err:%d uid:0x%h", err, (iModules[index]->ModuleUid()).iUid);
       
   233 				}
       
   234 			}
       
   235 		}
       
   236 	
       
   237 	iRejectPrivacyRequest = CRejectPrivacyRequestCallback::NewL();
       
   238 	
       
   239 	iLogger.Open(KLbsLogQueueSize);
       
   240 	#if defined(_DEBUG)
       
   241 		// For OOM testing. The listener will force an error on the next heap 
       
   242 		// allocation when it is kicked by test code.
       
   243 		iOomListener = CLbsOomListener::NewL();
       
   244 		iOomListener->StartGettingRequests();
       
   245 	#endif  
       
   246 	
       
   247 	// Establish a session with the Location Monitor 
       
   248 	if(KErrNone == iLocMonSession.Connect())
       
   249 	    {
       
   250         // Open subsession  
       
   251         iLocMonSubSession.OpenL(iLocMonSession);
       
   252 	    }
       
   253 	}
       
   254 
       
   255 /** Set flag indicating from which protocol module the latest network message originated.
       
   256 */
       
   257 void CNetworkGateway::SetReceivingProtocolModule(TLbsProtocolModuleId aId)
       
   258 	{
       
   259 	iReceivingModuleId = aId;
       
   260 	}
       
   261 
       
   262 /** Select and load a Network Protocol Module.
       
   263 
       
   264 Depending on admin options, two protocol modules are loaded at gateway initialisation
       
   265 or a single module is loaded when the phone registers.
       
   266 Loading is a 'one-off' process, nothing further is loaded (and nothing is unloaded) till phone reboots
       
   267 */
       
   268 void CNetworkGateway::LoadProtocolModuleL(TLbsProtocolModuleId aModuleId)
       
   269 	{
       
   270 	if(aModuleId != KLbsProtocolNullModuleId)
       
   271 	    {
       
   272         CProtocolModuleInfo* moduleInfo = ModuleInfo(aModuleId);
       
   273         CLbsNetworkProtocolBase* module = NULL;
       
   274         
       
   275         if(moduleInfo)
       
   276             {
       
   277             CNetObserver* obs = new (ELeave) CNetObserver(this, aModuleId);
       
   278             moduleInfo->SetObserver(obs);
       
   279             
       
   280             TLbsNetProtocolModuleParams params(*obs);
       
   281             LBSLOG(ELogP9, "->S CLbsNetworkProtocolBase::NewL() ProtocolModule\n");
       
   282             LBSLOG2(ELogP9, "  > TLbsProtocolModuleId moduleId  = 0x%08X\n", aModuleId);
       
   283             module = CLbsNetworkProtocolBase::NewL(aModuleId, params);
       
   284             
       
   285             moduleInfo->SetProtocolModule(module);
       
   286             }
       
   287 	    }
       
   288 	}
       
   289 
       
   290 //---------------------------------------------------------------------------------------------------
       
   291 // Messages from a Protocol Module (MLbsNetworkProtocolObserver)
       
   292 //---------------------------------------------------------------------------------------------------
       
   293 void CNetworkGateway::GetCurrentCapabilities(TLbsNetPosCapabilities& aCapabilities) const
       
   294 	{
       
   295 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::GetCurrentCapabilities() ProtocolModule\n");
       
   296 	LBSLOG(ELogP2, "CNetworkGateway::GetCurrentCapabilities:");
       
   297 	LBS_RDEBUG("ProtMod", "LBS", "GetCurrentCapabilities");
       
   298 
       
   299 	// This call is not necessarily associated with a session, don't try to filter on current protocol module */
       
   300 
       
   301 	TPositionModuleInfoExtended::TDeviceGpsModeCapabilities deviceGpsModeCaps(TPositionModuleInfo::ETechnologyUnknown);
       
   302 
       
   303 	// Get the capabilities information to fill in the position method(s) for aCapabilities.
       
   304 	TInt err = LbsModuleInfo::GetDeviceCapabilities(KLbsGpsLocManagerUid, deviceGpsModeCaps);
       
   305 
       
   306 #ifdef ENABLE_LBS_DEV_LOGGER
       
   307 	if (err != KErrNone)
       
   308 		{
       
   309 		LBSLOG_WARN2(ELogP3, "Error reading module info (%d), defaulting to 'unknown' pos method", err);
       
   310 		}
       
   311 #endif // ENABLE_LBS_DEV_LOGGER
       
   312 	
       
   313 	// Convert the module capabilities into a TLbsNetPosCapabilities..
       
   314 	CLbsAdmin::TGpsMode adminGpsMode = GetAdminGpsMode();
       
   315 	switch (deviceGpsModeCaps)
       
   316 		{
       
   317 		case TPositionModuleInfoExtended::EDeviceGpsModeTerminalBased:
       
   318 			{
       
   319 			TLbsNetPosMethod methods[2];
       
   320 			methods[0].SetPosMethod(KLbsPositioningMeansGps, KTerminalBased);
       
   321 			methods[1].SetPosMethod(KLbsPositioningMeansGps, KAutonomous);
       
   322 			aCapabilities.SetPosMethods(methods, 2);
       
   323 			
       
   324 #ifdef ENABLE_LBS_DEV_LOGGER
       
   325 			// Report a warning if the admin setting contradicts
       
   326 			// the module capabilities.
       
   327 			if (adminGpsMode != CLbsAdmin::EGpsPreferTerminalBased
       
   328 				&& adminGpsMode != CLbsAdmin::EGpsAlwaysTerminalBased
       
   329 				&& adminGpsMode != CLbsAdmin::EGpsAutonomous)
       
   330 				{
       
   331 				LBSLOG_WARN3(ELogP3, 
       
   332 							 "KLbsSettingXXXGpsMode (%d) contradicts GPS module capabilties (0x%x)!", 
       
   333 							 adminGpsMode,
       
   334 							 deviceGpsModeCaps);
       
   335 				}
       
   336 #endif // ENABLE_LBS_DEV_LOGGER
       
   337 			break;
       
   338 			}
       
   339 		case TPositionModuleInfoExtended::EDeviceGpsModeTerminalAssisted:
       
   340 			{
       
   341 			TLbsNetPosMethod method;
       
   342 			method.SetPosMethod(KLbsPositioningMeansGps, KTerminalAssisted);
       
   343 			aCapabilities.SetPosMethods(&method, 1);
       
   344 			
       
   345 #ifdef ENABLE_LBS_DEV_LOGGER
       
   346 			// Report a warning if the admin setting contradicts
       
   347 			// the module capabilities.
       
   348 			if (adminGpsMode != CLbsAdmin::EGpsPreferTerminalAssisted
       
   349 				&& adminGpsMode != CLbsAdmin::EGpsAlwaysTerminalAssisted)
       
   350 				{
       
   351 				LBSLOG_WARN3(ELogP3, 
       
   352 							 "KLbsSettingXXXGpsMode (%d) contradicts GPS module capabilties (0x%x)!", 
       
   353 							 adminGpsMode,
       
   354 							 deviceGpsModeCaps);
       
   355 				}
       
   356 #endif // ENABLE_LBS_DEV_LOGGER
       
   357 			break;
       
   358 			}
       
   359 		case TPositionModuleInfoExtended::EDeviceGpsModeSimultaneousTATB:
       
   360 		case (TPositionModuleInfoExtended::EDeviceGpsModeTerminalBased
       
   361 			  | TPositionModuleInfoExtended::EDeviceGpsModeTerminalAssisted):
       
   362 			{
       
   363 			// If the module supports both TA and TB, then check the admin
       
   364 			// settings to find the 'preferred' one to put first in the 
       
   365 			// list of supported modes.			
       
   366 			TLbsNetPosMethod methods[3];
       
   367 			switch (adminGpsMode)
       
   368 				{
       
   369 				case CLbsAdmin::EGpsAlwaysTerminalAssisted:
       
   370 				case CLbsAdmin::EGpsPreferTerminalAssisted:
       
   371 					{
       
   372 					methods[0].SetPosMethod(KLbsPositioningMeansGps, KTerminalAssisted);
       
   373 					methods[1].SetPosMethod(KLbsPositioningMeansGps, KTerminalBased);
       
   374 					break;
       
   375 					}
       
   376 				case CLbsAdmin::EGpsAutonomous:
       
   377 				case CLbsAdmin::EGpsAlwaysTerminalBased:
       
   378 				case CLbsAdmin::EGpsPreferTerminalBased:
       
   379 				default:
       
   380 					{
       
   381 					methods[0].SetPosMethod(KLbsPositioningMeansGps, KTerminalBased);
       
   382 					methods[1].SetPosMethod(KLbsPositioningMeansGps, KTerminalAssisted);
       
   383 					break;
       
   384 					}
       
   385 				}
       
   386 			methods[2].SetPosMethod(KLbsPositioningMeansGps, KAutonomous);
       
   387 			aCapabilities.SetPosMethods(methods, 3);
       
   388 			break;
       
   389 			}
       
   390 		case TPositionModuleInfoExtended::EDeviceGpsModeAutonomous:
       
   391 			{
       
   392 			TLbsNetPosMethod method;
       
   393 			method.SetPosMethod(KLbsPositioningMeansGps, KAutonomous);
       
   394 			aCapabilities.SetPosMethods(&method, 1);
       
   395 
       
   396 #ifdef ENABLE_LBS_DEV_LOGGER
       
   397 			// Report a warning if the admin setting contradicts
       
   398 			// the module capabilities.
       
   399 			if (adminGpsMode != CLbsAdmin::EGpsAutonomous)
       
   400 				{
       
   401 				LBSLOG_WARN3(ELogP3, 
       
   402 							 "KLbsSettingXXXGpsMode (%d) contradicts GPS module capabilties (0x%x)!", 
       
   403 							 adminGpsMode,
       
   404 							 deviceGpsModeCaps);
       
   405 				}
       
   406 #endif // ENABLE_LBS_DEV_LOGGER
       
   407 			break;
       
   408 			}
       
   409 		case TPositionModuleInfoExtended::EDeviceGpsModeNone:
       
   410 		default:
       
   411 			{
       
   412 			// If the capabilities are not known or unrecognised, set unknown pos method.
       
   413 			TLbsNetPosMethod method;
       
   414 			method.SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyUnknown);
       
   415 			aCapabilities.SetPosMethods(&method, 1);
       
   416 			LBSLOG_WARN3(ELogP3, 
       
   417 						 "Unrecognised GPS module capabilities (%d), defaulting to TPositionModuleInfo::ETechnologyUnknown", 
       
   418 						 adminGpsMode, 
       
   419 						 deviceGpsModeCaps);
       
   420 			break;
       
   421 			}
       
   422 		}
       
   423 	}
       
   424 
       
   425 void CNetworkGateway::ProcessStatusUpdate(TLbsNetProtocolServiceMask /*aActiveServiceMask*/)
       
   426 	{
       
   427 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessStatusUpdate() ProtocolModule\n");
       
   428 	LBSLOG(ELogP2, "CNetworkGateway::ProcessStatusUpdate:");
       
   429 	LBS_RDEBUG("ProtMod", "LBS", "ProcessStatusUpdate");
       
   430 	//LBSLOG2(ELogP2, "Active Service Mask : 0x%x", aActiveServiceMask);
       
   431 	
       
   432 	// TODO: It is TBD exactly what/where this update should go.
       
   433 	// For now, just consume it.
       
   434 	}
       
   435 
       
   436 void CNetworkGateway::ProcessPrivacyRequest(const TLbsNetSessionId& aSessionId,
       
   437 										    TBool aEmergency, 
       
   438 										    const TLbsNetPosRequestPrivacy& aPrivacy,
       
   439 										    const TLbsExternalRequestInfo& aRequestInfo)
       
   440 	{
       
   441 	LBS_RDEBUG("ProtMod", "LBS", "ProcessPrivacyRequest");
       
   442 	__ASSERT_ALWAYS((aRequestInfo.ClassType() == EExternalRequestInfoClass)
       
   443 					|| (aRequestInfo.ClassType() == (EExternalRequestInfoClass 
       
   444 													| EExternalRequestInfoClass2)),
       
   445 					User::Panic(_L("LbsNetGateway"), 2));
       
   446 	
       
   447 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessPrivacyRequest() ProtocolModule\n");
       
   448 	LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
   449 	LBSLOG_SESSIONID(aSessionId);
       
   450 	LBSLOG2(ELogP9, "  > TBool aEmergency  = %d\n", aEmergency);
       
   451 	LBSLOG(ELogP9, "  > TLbsNetPosRequestPrivacy aPrivacy  =\n");
       
   452 	LBSLOG_POSREQUESTPRIVACY(aPrivacy);
       
   453 	
       
   454 	/** LBSLOGGER - Start Logging */
       
   455 	// -------------------------------------------------------------------------
       
   456 
       
   457 	TInt err = KErrNone;
       
   458 	if(iExternalLogEvent == NULL)
       
   459 		TRAP(err, iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(aSessionId.SessionOwner(), NULL, NULL));
       
   460 	if (err == KErrNone)
       
   461 		{
       
   462 		TLbsLoggingPrivacyRequestParams params;
       
   463 		params.iSessionId = aSessionId;
       
   464 		// Only TLbsExternalRequestInfo is logged, so if aRequestInfo
       
   465 		// is a TLbsExternalRequestInfo2, the string(s) will be truncated.
       
   466 		params.iRequestInfo = aRequestInfo;
       
   467 		params.iRequestPrivacy =  aPrivacy;
       
   468 		iExternalLogEvent->SetPrivacyRequestParams(params);
       
   469 		}
       
   470 	LBSLOG(ELogP9, "  < TLbsExternalRequestInfo aRequestInfo  =\n");
       
   471 	//LBSLOG_TLBSEXTERNALREQ(aRequestInfo);
       
   472 	
       
   473 
       
   474 	// Convert aPrivacy to TLbsNetPosRequestPrivacyInt
       
   475 	// because it is used to createTLbsNetMtLrRequestMsg.
       
   476 	TLbsNetPosRequestPrivacyInt privacyInt;
       
   477 	privacyInt.SetRequestAdvice((TLbsNetPosRequestPrivacyInt::TLbsRequestAdviceInt)
       
   478 			aPrivacy.RequestAdvice());
       
   479 	privacyInt.SetRequestAction((TLbsNetPosRequestPrivacyInt::TLbsRequestActionInt)
       
   480 			aPrivacy.RequestAction());
       
   481 		
       
   482 	TLbsNetMtLrRequestMsg msg(
       
   483 			TLBSNETSESSIONIDINT(aSessionId),
       
   484 			aEmergency, privacyInt, aRequestInfo);
       
   485 
       
   486 	if(ValidPm(aSessionId.SessionOwner()))
       
   487 		{
       
   488 		iNetworkRequestChannel->SendNetRequestMessage(msg);
       
   489 		}
       
   490 	else
       
   491 		{
       
   492 		//Not a valid PM, reject this message(rather than silently ignore??)
       
   493 		iRejectPrivacyRequest->CallBack((ModuleInfo(aSessionId.SessionOwner()))->ProtocolModule(), aSessionId);	
       
   494 		}
       
   495 	// -------------------------------------------------------------------------
       
   496 	/** LBSLOGGER - End Logging */
       
   497 	}
       
   498 
       
   499 void CNetworkGateway::ProcessLocationRequest(const TLbsNetSessionId& aSessionId,
       
   500 											 TBool aEmergency,
       
   501 											 TLbsNetProtocolService aService, 
       
   502 											 const TLbsNetPosRequestQuality& aQuality,
       
   503 											 const TLbsNetPosRequestMethod& aMethod)
       
   504 	{
       
   505 	LBS_RDEBUG("ProtMod", "LBS", "ProcessLocationRequest");
       
   506 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessLocationRequest() ProtocolModule\n");
       
   507 	LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
   508 	LBSLOG_SESSIONID(aSessionId);
       
   509 	LBSLOG2(ELogP9, "  > TBool aEmergency  = %d\n", aEmergency);
       
   510 	LBSLOG2(ELogP9, "  > TLbsNetProtocolService aService  = 0x%02X\n", aService);
       
   511 	LBSLOG(ELogP9, "  > TLbsNetPosRequestQuality aQuality  = \n");
       
   512 	LBSLOG_POSREQUESTQUALITY(aQuality);	
       
   513 	LBSLOG(ELogP9, "  > TLbsNetPosRequestMethod aMethod  =\n");
       
   514 	LBSLOG_POSREQUESTMETHOD(aMethod);
       
   515 	
       
   516 	// If the received message is from a protocol module that is not registered reject it
       
   517 	if(!ValidPm(iReceivingModuleId))
       
   518 		{
       
   519 		return;
       
   520 		}
       
   521 	// Convert aQuality to TLbsNetPosRequestQualityInt
       
   522 	// because it is needed to create TLbsNetLocationRequestMsg.
       
   523 	TLbsNetPosRequestQualityInt qualityInt;
       
   524 	ConvertToTLbsNetPosRequestQualityInt(aQuality, qualityInt);
       
   525 	
       
   526 	// Convert aMethod to TLbsNetPosRequestMethodInt
       
   527 	// because it is needed to create TLbsNetLocationRequestMsg.
       
   528 	 TLbsNetPosRequestMethodInt methodInternal;
       
   529 	 TLbsNetPosMethodInt posMethodInternal[KLbsMaxNetPosMethodsInt];
       
   530 	 for (int i = 0; i < aMethod.NumPosMethods(); i++)
       
   531 		{
       
   532 		TLbsNetPosMethod posMethodTemp;
       
   533 		aMethod.GetPosMethod(i, posMethodTemp);
       
   534 		posMethodInternal[i].SetPosMethod(posMethodTemp.PosMeans(),
       
   535 				 (TPositionModuleInfoInt::TTechnologyTypeInt) posMethodTemp.PosMode());
       
   536 		}
       
   537 	 methodInternal.SetPosMethods(posMethodInternal, aMethod.NumPosMethods());
       
   538 	 methodInternal.SetGpsTimingOfCellFramesRequested(aMethod.GpsTimingOfCellFramesRequested());
       
   539 	
       
   540 	// Send message into the NRH.
       
   541 	TLbsNetLocationRequestMsg msg(
       
   542 			TLBSNETSESSIONIDINT(aSessionId), 
       
   543 			aEmergency,
       
   544 			(TLbsNetworkEnumInt::TLbsNetProtocolServiceInt) aService,
       
   545 			qualityInt,
       
   546 			methodInternal);
       
   547 	iNetworkRequestChannel->SendNetRequestMessage(msg);
       
   548 	
       
   549 		
       
   550 	/** LBSLOGGER - Start Logging */
       
   551 	// -------------------------------------------------------------------------
       
   552 	if (iExternalLogEvent == NULL)
       
   553 		{
       
   554 		TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(aSessionId.SessionOwner(), NULL, NULL));
       
   555 		}
       
   556 	else
       
   557 		{
       
   558 		iExternalLogEvent->SetRequestOriginator(aSessionId.SessionOwner());
       
   559 		}
       
   560 	// -------------------------------------------------------------------------
       
   561 	/** LBSLOGGER - End Logging */
       
   562 	}
       
   563 
       
   564 void CNetworkGateway::ProcessSessionComplete(const TLbsNetSessionId& aSessionId,
       
   565 											 TInt  aReason)
       
   566 	{
       
   567 	LBS_RDEBUG_ARGINT("ProtMod", "LBS", "ProcessSessionComplete",aReason);
       
   568 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessSessionComplete() ProtocolModule\n");
       
   569 	LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
   570 	LBSLOG_SESSIONID(aSessionId);
       
   571 	LBSLOG2(ELogP9, "  > aReason  = %d\n", aReason);
       
   572 	
       
   573 	// If this is a PM that is calling us
       
   574 	if ( ModuleInfo(aSessionId.SessionOwner()) )
       
   575 		{
       
   576 		// If we are registered, silently ignore any message from a now invalid PM.
       
   577 		// Otherwise, could be temporaily unregistered, so send on message in hope that
       
   578 		// phone will shortly re-register as home/roaming.
       
   579 		if(!ValidPm(iReceivingModuleId))
       
   580 			{
       
   581 			return;
       
   582 			}
       
   583 		}
       
   584 
       
   585 	// The NRH gets all session complete messages and may ignore
       
   586 	// them if the Session Owner is NLM or AGPS manager, but
       
   587 	// no Location Request processing is taking place.
       
   588 	TLbsNetSessionCompleteMsg msgNRH(TLBSNETSESSIONIDINT(aSessionId), aReason);
       
   589 	iNetworkRequestChannel->SendNetRequestMessage(msgNRH);
       
   590 	
       
   591 	if (aSessionId.SessionOwner() == KLbsGpsLocManagerUid)
       
   592 		{
       
   593 		if(iAgpsChannel)
       
   594 			{
       
   595 			iAgpsChannel->SendSessionComplete(aReason, TLBSNETSESSIONIDINT(aSessionId));
       
   596 			}
       
   597 		}
       
   598 	else if (aSessionId.SessionOwner() == KLbsNetLocManagerUid)
       
   599 		{
       
   600 		if(iNetworkLocationChannel)
       
   601 			{
       
   602 			TLbsNetLocNetworkLocationCompleteMsg msgNLM(TLBSNETSESSIONIDINT(aSessionId), aReason);
       
   603 			iNetworkLocationChannel->SendNetworkLocationMessage(msgNLM);
       
   604 			}
       
   605 		}
       
   606 	else if (aSessionId.SessionOwner() == KLbsSuplPsyUid)
       
   607 	    {
       
   608         if(iPSYChannel)
       
   609             {
       
   610             iPSYChannel->SendNetworkResponse(msgNRH);
       
   611             }
       
   612 	    }
       
   613 	// else the session owner is NRH (KLbsNetRequestHandlerUid)
       
   614 	// or a network-MTLR (owner id may vary) and the msg goes only to the NRH.}
       
   615 		
       
   616 		
       
   617 	/** LBSLOGGER - Start Logging */
       
   618 	// -------------------------------------------------------------------------
       
   619 	//ASSERT(iExternalLogEvent != NULL);
       
   620 	if (iExternalLogEvent != NULL)
       
   621 		{
       
   622 		if (!iCancelled)
       
   623 			{
       
   624 			switch (aReason)
       
   625 				{
       
   626 				case KErrNone:
       
   627 					{
       
   628 					iExternalLogEvent->SetRequestOutcome(ELbsRequestOutcomeSuccess);
       
   629 					break;
       
   630 					}
       
   631 				case KErrCancel:
       
   632 					{
       
   633 					iExternalLogEvent->SetRequestOutcome(ELbsRequestOutcomeCancel);
       
   634 					break;
       
   635 					}
       
   636 				default:
       
   637 					{
       
   638 					iExternalLogEvent->SetRequestOutcome(ELbsRequestOutcomeFail);
       
   639 					}
       
   640 				};
       
   641 			}
       
   642 		else
       
   643 			{
       
   644 			iExternalLogEvent->SetRequestOutcome(ELbsRequestOutcomeCancel);
       
   645 			}
       
   646 
       
   647 		iLogger.AddEvent(*iExternalLogEvent);
       
   648 		
       
   649 		delete iExternalLogEvent;
       
   650 		iExternalLogEvent = NULL;
       
   651 		iSeenLocationUpdate = EFalse;
       
   652 		iCancelled = EFalse;
       
   653 		}
       
   654 	// -------------------------------------------------------------------------
       
   655 	/** LBSLOGGER - End Logging */
       
   656 	}
       
   657 
       
   658 void CNetworkGateway::ProcessAssistanceData(TLbsAsistanceDataGroup aDataMask,
       
   659 											const RLbsAssistanceDataBuilderSet& aData,
       
   660 						   					TInt aReason)
       
   661 	{
       
   662 	LBS_RDEBUG_ARGINT("ProtMod", "LBS", "ProcessAssistanceData", aReason);
       
   663 
       
   664 	if(iAgpsChannel)
       
   665 		{
       
   666 		LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessAssistanceData() ProtocolModule\n");
       
   667 		LBSLOG2(ELogP9, "  > TLbsAsistanceDataGroup aDataMask  = 0x%08x\n", aDataMask);
       
   668 		LBSLOG2(ELogP9, "  > TInt aReason  = %d\n", aReason);
       
   669 
       
   670 		iAgpsChannel->SendAssistanceDataResponse(aReason, 
       
   671 				(TLbsAsistanceDataGroupInt) aDataMask, aData);
       
   672 		}
       
   673 	}
       
   674 	
       
   675 void CNetworkGateway::ProcessAssistanceData(TLbsAsistanceDataGroup aDataMask,
       
   676 								const RLbsAssistanceDataBuilderSet& aData,
       
   677 								TInt aReason,
       
   678 								const TLbsNetSessionIdArray& /*aSessionIdArray*/)
       
   679 	{
       
   680 	LBS_RDEBUG_ARGINT("ProtMod", "LBS", "ProcessAssistanceData", aReason);
       
   681 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessAssistanceData() v2 ProtocolModule\n");
       
   682 
       
   683 	// We do not attempt to filter out the assistance data based upon whether it came from an
       
   684 	// invalid protocol module. Assistance data is valid regardless of where it came from and
       
   685 	// is allowed to arrive at any time.
       
   686 	
       
   687 	// The session ID array is currently not used.
       
   688 	ProcessAssistanceData(aDataMask, aData, aReason);
       
   689 	}
       
   690 
       
   691 void CNetworkGateway::ProcessLocationUpdate(const TLbsNetSessionId& aSessionId,
       
   692 											 const TPositionInfoBase& aPosInfo)
       
   693 	{
       
   694 	LBS_RDEBUG("ProtMod", "LBS", "ProcessLocationUpdate");
       
   695 	LBSLOG(ELogP9, "<-A MLbsNetworkProtocolObserver::ProcessLocationUpdate() ProtocolModule\n");
       
   696 	LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
   697 	LBSLOG_SESSIONID(aSessionId);
       
   698 	LBSLOG(ELogP9, "  > TPositionInfoBase aPosInfo  = \n");
       
   699 	LBSLOG_TPOSITIONINFOBASE(aPosInfo);
       
   700 
       
   701 	// If the received message is from a protocol module that is not registered reject it
       
   702 	if(!ValidPm(iReceivingModuleId))
       
   703 		{
       
   704 		return;
       
   705 		}
       
   706 
       
   707 	/** LBSLOGGER - Start Logging */
       
   708 	// -------------------------------------------------------------------------
       
   709 	TPositionInfoBase* posInfo = const_cast<TPositionInfoBase*>(&aPosInfo);
       
   710 	if (iSeenLocationUpdate)
       
   711 		{
       
   712 		//ASSERT(iExternalLogEvent != NULL);
       
   713 		// In MOLR we see two reference positions
       
   714 		
       
   715 		if(iExternalLogEvent)
       
   716 		    {
       
   717 		    iLogger.AddEvent(*iExternalLogEvent);
       
   718 		    delete iExternalLogEvent;
       
   719 		    iExternalLogEvent = NULL;
       
   720 		    }
       
   721 		}
       
   722 	
       
   723 	if (iExternalLogEvent == NULL)
       
   724 		{
       
   725 		TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(aSessionId.SessionOwner(), posInfo, NULL));
       
   726 		}
       
   727 	else
       
   728 		{
       
   729 		if(posInfo->PositionClassType() != EPositionGpsMeasurementInfoClass)
       
   730 			{
       
   731 			iExternalLogEvent->SetReferenceLocation(posInfo);
       
   732 			}
       
   733 		}
       
   734 	iSeenLocationUpdate = ETrue;
       
   735 	// -------------------------------------------------------------------------
       
   736 	/** LBSLOGGER - End Logging */
       
   737 	
       
   738 	// Route Ref and FNP positions to the Location monitor if those are not NAN 
       
   739 	TPosition pos;
       
   740 	const TPositionInfo& positionInfo = reinterpret_cast <const TPositionInfo&> (aPosInfo);
       
   741 	positionInfo.GetPosition(pos);
       
   742 	if (iLocMonSubSession.SubSessionHandle() && !(Math::IsNaN(pos.Latitude()) ||Math::IsNaN(pos.Longitude())))
       
   743         {
       
   744         iLocMonSubSession.SetLastKnownPosition(aPosInfo);          
       
   745         }
       
   746 		
       
   747 	// Route only manager Ref and FNP positions to the P&S bus
       
   748 	if (aSessionId.SessionOwner() == KLbsGpsLocManagerUid ||
       
   749 		aSessionId.SessionOwner() == KLbsNetLocManagerUid)
       
   750 		{
       
   751 		if(iNetworkLocationChannel)
       
   752 			{
       
   753 		iNetworkLocationChannel->SetNetworkPosition(TLBSNETSESSIONIDINT(aSessionId), aPosInfo);
       
   754 			}
       
   755 		}
       
   756 	
       
   757 	if (aSessionId.SessionOwner() == KLbsSuplPsyUid) 
       
   758         {
       
   759         if(iPSYChannel)
       
   760             {
       
   761             TLbsCellLocationResponseMsg msg(TLBSNETSESSIONIDINT(aSessionId), KErrNone, aPosInfo);
       
   762             iPSYChannel->SendNetworkResponse(msg);
       
   763             }
       
   764         }
       
   765 	
       
   766 	// Route all but AGPS manager Ref and FNP positions to the NRH
       
   767 	if (aSessionId.SessionOwner() != KLbsGpsLocManagerUid) 
       
   768 		{
       
   769 		TTime actualTime;
       
   770 		actualTime.UniversalTime();
       
   771 
       
   772 		TLbsNetLocationUpdateMsg msgNRH(TLBSNETSESSIONIDINT(aSessionId), KErrNone, aPosInfo, actualTime);
       
   773 		
       
   774 		iNetworkRequestChannel->SendNetRequestMessage(msgNRH);
       
   775 		}
       
   776 	}
       
   777 
       
   778 //---------------------------------------------------------------------------------------------------
       
   779 // Messages from the Network Location Manager (MNetworkLocationObserver)
       
   780 //---------------------------------------------------------------------------------------------------
       
   781 void CNetworkGateway::ProcessNetworkLocationMessage(const TLbsNetLocMsgBase& aMessage)
       
   782 	{
       
   783 	LBSLOG(ELogP2, "CNetworkGateway::ProcessNetworkLocationMessage:");
       
   784 	LBSLOG2(ELogP3, "Type : %d", aMessage.Type());
       
   785 	
       
   786 	switch (aMessage.Type())
       
   787 		{
       
   788 		case TLbsNetLocMsgBase::ENetLocMsgNetworkLocationRequest:
       
   789 			{
       
   790 			const TLbsNetLocNetworkLocationRequestMsg& req = static_cast<const TLbsNetLocNetworkLocationRequestMsg&>(aMessage);
       
   791 			TLbsNetPosRequestQuality quality;
       
   792 			ConvertToTLbsNetPosRequestQuality(req.Quality(), quality);
       
   793 			TLbsNetPosRequestOptions options;
       
   794 			options.SetRequestQuality(quality);
       
   795 
       
   796             // This is first message in network location session, so store the PM used.
       
   797             iModuleForSession[ENetworkLocation] = DefaultPm();
       
   798 
       
   799 			/** LBSLOGGER - Start Logging */
       
   800 			// -------------------------------------------------------------------------
       
   801 			if (iExternalLogEvent == NULL)
       
   802 				{
       
   803 				TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(req.SessionId().SessionOwner(), NULL, NULL));
       
   804 				}
       
   805 			// -------------------------------------------------------------------------
       
   806 			/** LBSLOGGER - End Logging */
       
   807 
       
   808 			// As this is first message in network location session, we send to the current PM if this exists.
       
   809 			if (DefaultPm())
       
   810 				{
       
   811 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RequestNetworkLocation() ProtocolModule\n");
       
   812 				LBSLOG(ELogP9, "  > TLbsNetLocNetworkLocationRequestMsg reg.SessionId()  = \n");
       
   813 				LBSLOG_SESSIONID(req.SessionId());
       
   814 				LBSLOG(ELogP9, "  > TLbsNetPosRequestOptions options  =\n");
       
   815 				// coverity[uninit_use_in_call]
       
   816 				// We're only logging quality here, so it does not matter that other parts of options are not initialsed
       
   817 				LBSLOG_POSREQUESTOPTIONS(options);
       
   818 
       
   819 				LBS_RDEBUG("LBS", "ProtMod", "RequestNetworkLocation");
       
   820 				DefaultPm()->RequestNetworkLocation(TLBSNETSESSIONID(req.SessionId()), options);
       
   821 				}
       
   822 			else
       
   823 				{
       
   824 				// No protocol module to send the request to,
       
   825 				// so send a 'no network available' error back instead!
       
   826 				ProcessSessionComplete(
       
   827 						TLBSNETSESSIONID(req.SessionId()), KErrPositionNetworkUnavailable);
       
   828 				}
       
   829 			break;
       
   830 			}
       
   831 		case TLbsNetLocMsgBase::ENetLocMsgNetworkLocationCancel:
       
   832 			{
       
   833 			const TLbsNetLocNetworkLocationCancelMsg& cancel = static_cast<const TLbsNetLocNetworkLocationCancelMsg&>(aMessage);
       
   834 
       
   835 			// Always send message to the PM with which we initiated the session.
       
   836 			if (iModuleForSession[ENetworkLocation])
       
   837 				{
       
   838 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::CancelNetworkLocation() ProtocolModule\n");
       
   839 				LBSLOG(ELogP9, "  > TLbsNetLocNetworkLocationRequestMsg cancel.SessionId()  = \n");
       
   840 				LBSLOG_SESSIONID(cancel.SessionId());
       
   841 				LBSLOG2(ELogP9, "  > TInt cancel.Reason()  = %d\n", cancel.Reason());
       
   842 
       
   843 				LBS_RDEBUG_ARGINT("LBS", "ProtMod", "CancelNetworkLocation", cancel.Reason());
       
   844 				iModuleForSession[ENetworkLocation]->CancelNetworkLocation(TLBSNETSESSIONID(cancel.SessionId()), cancel.Reason());
       
   845 				}
       
   846 			else
       
   847 				{
       
   848 				// We should only get here if the registration status is ENotRegistered. 
       
   849 				// Therefore we cannot send the message to a protocol module so discard the Cancel.
       
   850 				LBSLOG(ELogP9, "CNetworkGateway::ProcessNetworkLocationMessage: LocationCancel but ENotRegistered, discard Cancel");
       
   851 				}
       
   852 			iCancelled = ETrue;
       
   853 			break;
       
   854 			}
       
   855 		case TLbsNetLocMsgBase::ENetLocMsgNetworkLocationComplete:
       
   856 		default:
       
   857 			{
       
   858 			break;
       
   859 			}
       
   860 		}
       
   861 	}
       
   862 
       
   863 //---------------------------------------------------------------------------------------------------
       
   864 // Messages from the Network PSYs (MPsyRequestObserver)
       
   865 //---------------------------------------------------------------------------------------------------
       
   866 void CNetworkGateway::ProcessPsyMessage(const TLbsNetInternalMsgBase& aMessage)
       
   867     {
       
   868     LBSLOG(ELogP2, "CNetworkGateway::ProcessPsyMessage:");
       
   869     LBSLOG2(ELogP2, "Type : %d", aMessage.Type());
       
   870             
       
   871     switch (aMessage.Type())
       
   872         {
       
   873         case TLbsNetInternalMsgBase::ECellLocationRequest:
       
   874             {
       
   875             const TLbsCellLocationRequestMsg& reqMsg = reinterpret_cast<const TLbsCellLocationRequestMsg&>(aMessage);
       
   876 
       
   877             TLbsNetPosRequestQuality quality;
       
   878             TLbsNetPosRequestQualityInt qualityInt;
       
   879             
       
   880             reqMsg.Options().GetRequestQuality(qualityInt);
       
   881             ConvertToTLbsNetPosRequestQuality(qualityInt, quality);
       
   882             
       
   883             TLbsNetPosRequestOptions options;
       
   884             options.SetRequestQuality(quality);
       
   885             options.SetNewClientConnected(reqMsg.Options().NewClientConnected());
       
   886 
       
   887             TUid pmUid = reqMsg.ProtocolModule(); 
       
   888             CProtocolModuleInfo* modInfo = ModuleInfo(pmUid);
       
   889             
       
   890             if(modInfo)
       
   891                 {
       
   892                 CLbsNetworkProtocolBase* pm = modInfo->ProtocolModule();
       
   893                 pm->RequestNetworkLocation(TLBSNETSESSIONID(reqMsg.SessionId()), options);
       
   894             
       
   895                 // This is first message in network location session, so store the PM used.
       
   896                 if(reqMsg.SessionId().SessionOwner() == KLbsNetLocManagerUid)
       
   897                     {
       
   898                     iModuleForSession[ENetworkLocation] = pm;
       
   899                     }
       
   900                 else
       
   901                     {
       
   902                     iModuleForSession[EPSYLocation] = pm;
       
   903                     }
       
   904                 }
       
   905             else
       
   906                 {
       
   907                 // No protocol module to send the request to
       
   908                 ProcessSessionComplete(TLBSNETSESSIONID(reqMsg.SessionId()), KErrPositionNetworkUnavailable);
       
   909                 }
       
   910             break;
       
   911             }
       
   912 
       
   913         case TLbsNetInternalMsgBase::ECellLocationCancel:
       
   914             {
       
   915             const TLbsCellLocationCancelMsg& cancelMsg = reinterpret_cast<const TLbsCellLocationCancelMsg&>(aMessage);
       
   916 
       
   917             CLbsNetworkProtocolBase* pm;
       
   918             if(cancelMsg.SessionId().SessionOwner() == KLbsNetLocManagerUid)
       
   919                 {
       
   920                 pm = iModuleForSession[ENetworkLocation];
       
   921                 }
       
   922             else
       
   923                 {
       
   924                 pm = iModuleForSession[EPSYLocation];
       
   925                 }
       
   926             
       
   927             // Always send message to the PM with which we initiated the session.
       
   928             if (pm)
       
   929                 {
       
   930                 pm->CancelNetworkLocation(TLBSNETSESSIONID(cancelMsg.SessionId()), cancelMsg.Reason());
       
   931                 }
       
   932             else
       
   933                 {
       
   934                 // We should only get here if the registration status is ENotRegistered. 
       
   935                 // Therefore we cannot send the message to a protocol module so discard the Cancel.
       
   936                 LBSLOG(ELogP9, "CNetworkGateway::ProcessPsyMessage: LocationCancel but ENotRegistered, discard Cancel");
       
   937                 }
       
   938             iCancelled = ETrue;
       
   939             break;
       
   940             }
       
   941         default:
       
   942             {
       
   943              break;
       
   944             }
       
   945        }
       
   946     }
       
   947 
       
   948 //---------------------------------------------------------------------------------------------------
       
   949 // Messages from the AGPS Manager (MAgpsObserver)
       
   950 //---------------------------------------------------------------------------------------------------
       
   951 void CNetworkGateway::OnAssistanceDataRequest(TLbsAsistanceDataGroupInt aDataMask)
       
   952 	{
       
   953 	LBSLOG(ELogP1, "CNetworkGateway::OnAssistanceDataRequest:");
       
   954 	LBSLOG2(ELogP2, "Assistance Data Request. Data Mask : 0x%x", aDataMask);
       
   955 
       
   956 	LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RequestAssistanceData() ProtocolModule\n");
       
   957 	LBSLOG2(ELogP9, "  > TLbsAsistanceDataGroupInt aDataMask  = 0x%08X\n", aDataMask);
       
   958 
       
   959 	// Check there is at least one protocol module before attempting to send assistance data 
       
   960 	if (DefaultPm())
       
   961 		{
       
   962 		CLbsNetworkProtocolBase* pm = NULL;
       
   963 		CLbsNetworkProtocolBase2* pm2 = NULL;
       
   964 		
       
   965 		for(TUint index = 0; index < iPmCount; index++)
       
   966 			{
       
   967 			LBS_RDEBUG_ARGINT("LBS", "ProtMod", "RequestAssistanceData", aDataMask);
       
   968 			pm = (iModules[index])->ProtocolModule();
       
   969 
       
   970 			if(pm)
       
   971 				{
       
   972 				pm2 = reinterpret_cast<CLbsNetworkProtocolBase2*> 
       
   973 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   974 				(pm->ExtendedInterface(CLbsNetworkProtocolBase::EExtInterface2,0,0));
       
   975 #else
       
   976 				(pm->ExtendedInterface(ELbsNetExtInterface2,0,0));
       
   977 #endif
       
   978 				if(pm2 != NULL)
       
   979 					{
       
   980 					const TLbsNetSessionIdArray dummySessIdArray;
       
   981 					pm2->RequestAssistanceData(aDataMask, dummySessIdArray);
       
   982 					}
       
   983 				else
       
   984 					{
       
   985 					pm->RequestAssistanceData(aDataMask);
       
   986 					}
       
   987 				}
       
   988 			}
       
   989 		}
       
   990 	else
       
   991 		{
       
   992 		// Shouldn't get here as logic error but gateway does not panic in release mode.
       
   993 		LBSLOG_ERR(ELogP3, "CNetworkGateway::OnAssistanceDataRequest: Could not identify where to send assistance data request");
       
   994 
       
   995 
       
   996 		if(aDataMask != EAssistanceDataNone)
       
   997 			{
       
   998 			// No protocol module to send the request to, so send
       
   999 			// a 'no network available' error back!
       
  1000 			RLbsAssistanceDataBuilderSet dummyBuilderSet;
       
  1001 			ProcessAssistanceData(aDataMask, dummyBuilderSet, KErrPositionNetworkUnavailable);
       
  1002 			}
       
  1003 		}
       
  1004 	}
       
  1005 	
       
  1006 /**
       
  1007 From AGPS Manager
       
  1008 */
       
  1009 void CNetworkGateway::OnSelfLocationRequest(const TLbsNetSessionIdInt& aSessionId, 
       
  1010 											const TLbsNetPosRequestOptionsAssistanceInt& aOptions)
       
  1011 	{
       
  1012 	LBSLOG(ELogP1, "CNetworkGateway::OnSelfLocationRequest");
       
  1013 	LBSLOG4(ELogP2, "Self Location Request. SessionId : (%d, %d). Data Mask : 0x%x", aSessionId.SessionOwner().iUid,
       
  1014 											  										aSessionId.SessionNum(),
       
  1015 											  										aOptions.DataRequestMask());
       
  1016 
       
  1017     // First message in MO-LR session as far as the gateway is concerned, so store the (ptr to) module.
       
  1018     iModuleForSession[ESelfLocation] = DefaultPm();
       
  1019 
       
  1020 	if (DefaultPm())
       
  1021 		{
       
  1022 		// Generate log for RequestSelfLocation message that we are send to the current protocol module
       
  1023 		LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RequestSelfLocation() ProtocolModule");
       
  1024 		LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
  1025 		LBSLOG_SESSIONID(aSessionId);
       
  1026 		LBSLOG(ELogP9, "  > TLbsNetPosRequestOptionsAssistance aOptions  =\n");
       
  1027 		LBSLOG_REQUESTOPTIONSASSISTANCE(aOptions);
       
  1028 		LBS_RDEBUG("LBS", "ProtMod", "RequestSelfLocation");
       
  1029 
       
  1030 		TLbsNetPosRequestOptionsAssistance optionsAssistance;
       
  1031 		ConvertToTLbsNetPosRequestOptionsAssistance(aOptions, optionsAssistance);
       
  1032 
       
  1033 		DefaultPm()->RequestSelfLocation(TLBSNETSESSIONID(aSessionId), optionsAssistance);
       
  1034 		}
       
  1035 	else
       
  1036 		{
       
  1037 		// No protocol module to send the request to...
       
  1038     	if (TPositionModuleInfo::ETechnologyTerminal == aOptions.PosMode())
       
  1039 	    	{
       
  1040 		    // If the positioning method is autonomous, just complete the session
       
  1041 			ProcessSessionComplete(TLBSNETSESSIONID(aSessionId), KErrNone);
       
  1042 	   		}
       
  1043 		else
       
  1044  	   		{
       
  1045  	   		// otherwise send a 'no network available' error  back to the application 
       
  1046  	   		// (regardless of whether data mask is zero or not). Also, send appropriate 
       
  1047  	   		// session complete message.
       
  1048 			RLbsAssistanceDataBuilderSet dummyBuilderSet;
       
  1049 			ProcessAssistanceData(EAssistanceDataNone, dummyBuilderSet, KErrPositionNetworkUnavailable);
       
  1050 			ProcessSessionComplete(TLBSNETSESSIONID(aSessionId), KErrPositionNetworkUnavailable);
       
  1051 			}
       
  1052 		}
       
  1053 	}
       
  1054 
       
  1055 /**
       
  1056 From AGPS Manager
       
  1057 */
       
  1058 void CNetworkGateway::OnSelfLocationCancel(const TLbsNetSessionIdInt& aSessionId, TInt aReason)
       
  1059 	{
       
  1060 	LBSLOG(ELogP1, "CNetworkGateway::OnSelfLocationCancel");
       
  1061 	LBSLOG4(ELogP2, "Self Location Cancel. SessionId : (%d, %d). Reason    : %d\n", aSessionId.SessionOwner().iUid, 
       
  1062 											  										aSessionId.SessionNum(),
       
  1063 																					aReason);
       
  1064 	/** LBSLOGGER - Start Logging */
       
  1065 	// -------------------------------------------------------------------------
       
  1066 	if (iExternalLogEvent == NULL)
       
  1067 		{
       
  1068 		TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(aSessionId.SessionOwner(), NULL, NULL));
       
  1069 		}
       
  1070 	// -------------------------------------------------------------------------
       
  1071 	/** LBSLOGGER - End Logging */
       
  1072 
       
  1073 	if (iModuleForSession[ESelfLocation])
       
  1074 		{
       
  1075 		LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::CancelSelfLocation() ProtocolModule\n");
       
  1076 		LBSLOG(ELogP9, "  > TLbsNetSessionId aSessionId  = \n");
       
  1077 		LBSLOG_SESSIONID(aSessionId);
       
  1078 		LBSLOG2(ELogP9, "  > TInt aReason  = %d\n", aReason);
       
  1079 		LBS_RDEBUG_ARGINT("LBS", "ProtMod", "CancelSelfLocation", aReason);
       
  1080 
       
  1081 		iModuleForSession[ESelfLocation]->CancelSelfLocation(TLBSNETSESSIONID(aSessionId), aReason);
       
  1082 		}
       
  1083 	else
       
  1084 		{
       
  1085 		// Shouldn't get here as logic error but gateway does not panic in release mode.
       
  1086 		LBSLOG_ERR(ELogP3, "CNetworkGateway::OnSelfLocationCancel: Cancel message but no default PM");
       
  1087 		__ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));
       
  1088 		}
       
  1089 	}
       
  1090 
       
  1091 /**
       
  1092 From AGPS Manager
       
  1093 */
       
  1094 void CNetworkGateway::OnSystemStatusAdvice(TBool aTracking)
       
  1095 	{
       
  1096 	LBSLOG(ELogP2, "CNetworkGateway::OnSystemStatusAdvice");
       
  1097 	// NG must have a cache if more statuses added
       
  1098 	
       
  1099 	LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::AdviceSystemStatus() ProtocolModule\n");
       
  1100 
       
  1101 	CLbsNetworkProtocolBase::TLbsSystemStatus tracking;
       
  1102 	tracking = (aTracking) ? CLbsNetworkProtocolBase::ESystemStatusClientTracking : CLbsNetworkProtocolBase::ESystemStatusNone;
       
  1103 	LBSLOG2(ELogP9, "  > TLbsSystemStatus sStatus  = 0x%02X\n", tracking);
       
  1104 
       
  1105 	CLbsNetworkProtocolBase* pm = NULL;
       
  1106 	for(TUint index = 0; index < iPmCount; index++)
       
  1107 		{
       
  1108 		pm = (iModules[index])->ProtocolModule();
       
  1109 		if(pm)
       
  1110 			{
       
  1111 			pm->AdviceSystemStatus(tracking);
       
  1112 			}
       
  1113 		}
       
  1114 	}
       
  1115 
       
  1116 //---------------------------------------------------------------------------------------------------
       
  1117 // Messages from the Network Request Handler (MNetworkRequestObserver)
       
  1118 //---------------------------------------------------------------------------------------------------
       
  1119 /** Process incoming messages from the Network Request Handler.
       
  1120 
       
  1121 This function is called for each message that is received from the NRH.
       
  1122 In most cases it determines which protocol module is being used for the session
       
  1123 and passes the message contents to that module by calling the appropriate function
       
  1124 on the api.
       
  1125 */	
       
  1126 void CNetworkGateway::ProcessNetRequestMessage(const TLbsNetInternalMsgBase& aMessage)
       
  1127 	{
       
  1128 	LBSLOG(ELogP2, "CNetworkGateway::ProcessNetRequestMessage:");
       
  1129 	LBSLOG2(ELogP2, "Type : %d", aMessage.Type());
       
  1130 			
       
  1131 	switch (aMessage.Type())
       
  1132 		{
       
  1133 		case TLbsNetInternalMsgBase::ELocationResponse:
       
  1134 			{
       
  1135 			const TLbsNetLocationResponseMsg& msg = reinterpret_cast<const TLbsNetLocationResponseMsg&>(aMessage);
       
  1136 
       
  1137 			/** LBSLOGGER - Start Logging */
       
  1138 			// -------------------------------------------------------------------------
       
  1139 			// log the GPS location response positioninfo
       
  1140 			if (iExternalLogEvent != NULL)
       
  1141 				{
       
  1142 				TPositionInfoBase* posInfo = const_cast<TPositionInfoBase*>(&msg.PositionInfo());
       
  1143 				if(posInfo->PositionClassType() != EPositionGpsMeasurementInfoClass)
       
  1144 					{
       
  1145 					iExternalLogEvent->SetPositionInfo(posInfo);
       
  1146 					}
       
  1147 				}
       
  1148 			// -------------------------------------------------------------------------
       
  1149 			/** LBSLOGGER - End Logging */
       
  1150 				
       
  1151 			// Determine the original protocol module.
       
  1152 			TSessionTypes sessionType;
       
  1153 			CLbsNetworkProtocolBase* originalPM = FindOriginalPMFromID(TLBSNETSESSIONID(msg.SessionId()), sessionType);
       
  1154 			__ASSERT_DEBUG(sessionType != EInvalidSession,
       
  1155 						   User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));
       
  1156 			if (originalPM)
       
  1157 				{
       
  1158 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RespondLocationRequest() ProtocolModule\n");
       
  1159 				LBSLOG(ELogP9, "  > TLbsNetLocationResponseMsg msg.SessionId()  = \n");
       
  1160 				LBSLOG_SESSIONID(msg.SessionId());
       
  1161 				LBSLOG2(ELogP9, "  > TInt msg.Reason()  = %d\n", msg.Reason());
       
  1162 				LBSLOG(ELogP9, "  > TPositionInfoBase msg.PositionInfo()  =\n");
       
  1163 				LBSLOG_TPOSITIONINFOBASE(msg.PositionInfo());
       
  1164 				LBS_RDEBUG_ARGINT("LBS", "ProtMod", "RespondLocationRequest", msg.Reason());
       
  1165 
       
  1166 				originalPM->RespondLocationRequest(TLBSNETSESSIONID(msg.SessionId()), msg.Reason(), msg.PositionInfo());
       
  1167 				}
       
  1168 			else
       
  1169 				{
       
  1170 				// Shouldn't get here, logic error but gateway does not panic in release mode!
       
  1171 				LBSLOG_ERR(ELogP3, "CNetworkGateway::ProcessNetRequestMessage: For RespondLocationRequest could not find original protocol module");
       
  1172 				__ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));
       
  1173 				}
       
  1174 			break;
       
  1175 
       
  1176 			}
       
  1177 		case TLbsNetInternalMsgBase::ETransmitLocationRequest:
       
  1178 			{
       
  1179 			const TLbsNetTransmitLocationRequestMsg& msg = reinterpret_cast<const TLbsNetTransmitLocationRequestMsg&>(aMessage);
       
  1180 
       
  1181 			/** LBSLOGGER - Start Logging */
       
  1182 			// -------------------------------------------------------------------------
       
  1183 			if (iExternalLogEvent == NULL)
       
  1184 				{
       
  1185 				TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(msg.SessionId().SessionOwner(), NULL, NULL));
       
  1186 				}
       
  1187 			// -------------------------------------------------------------------------
       
  1188 			/** LBSLOGGER - End Logging */
       
  1189 
       
  1190             // This message is the first part of what must be an x3p session as far as the gateway is concerned,
       
  1191             // so store the (ptr to) module.
       
  1192             iModuleForSession[EX3p] = DefaultPm();
       
  1193 
       
  1194 			if (DefaultPm())
       
  1195 				{
       
  1196 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RequestTransmitLocation() ProtocolModule\n");
       
  1197 				LBSLOG(ELogP9, "  > TLbsNetTransmitLocationRequestMsg msg.SessionId()  = \n");
       
  1198 				LBSLOG_SESSIONID(msg.SessionId());
       
  1199 				LBSLOG2(ELogP9, "  > TDesC msg.Destination()  = %S\n", &msg.Destination());
       
  1200 				LBSLOG2(ELogP9, "  > TInt msg.Priority()  = %d\n", msg.Priority());
       
  1201 
       
  1202 				// Request extended module interface
       
  1203 				CLbsNetworkProtocolBase2* networkProtocolExt = 
       
  1204 					reinterpret_cast<CLbsNetworkProtocolBase2*>
       
  1205 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
  1206 					(DefaultPm()->ExtendedInterface(CLbsNetworkProtocolBase::EExtInterface2,0,0));
       
  1207 #else
       
  1208 					(DefaultPm()->ExtendedInterface(ELbsNetExtInterface2,0,0));
       
  1209 #endif
       
  1210 	
       
  1211 				if (networkProtocolExt != NULL)
       
  1212 					{
       
  1213 					TLbsNetPosRequestOptionsTechnology optionsTech;
       
  1214 		
       
  1215 					ConvertToTLbsNetPosRequestOptionsTechnology(msg.Options(), optionsTech);
       
  1216 					LBS_RDEBUG("LBS", "ProtMod", "RequestTransmitLocation");
       
  1217 					networkProtocolExt->RequestTransmitLocation(
       
  1218 															TLBSNETSESSIONID(msg.SessionId()),
       
  1219 															msg.Destination(),
       
  1220 															msg.Priority(),
       
  1221 															optionsTech);
       
  1222 					}
       
  1223 				else 
       
  1224 					{
       
  1225 					// Fall-back to using old API as the module doesn't support the new one
       
  1226 										LBS_RDEBUG("LBS", "ProtMod", "RequestTransmitLocation");
       
  1227 										DefaultPm()->RequestTransmitLocation(TLBSNETSESSIONID(msg.SessionId()),
       
  1228 															msg.Destination(),
       
  1229 															msg.Priority());
       
  1230 					}
       
  1231 				}
       
  1232 			else
       
  1233 				{
       
  1234 				// No network protocol module to send the request to,
       
  1235 				// so send a 'no network available' error back!
       
  1236 				ProcessSessionComplete(TLBSNETSESSIONID(msg.SessionId()), KErrPositionNetworkUnavailable);
       
  1237 				}
       
  1238 			break;
       
  1239 			}
       
  1240 		case TLbsNetInternalMsgBase::ETransmitLocationCancel:
       
  1241 			{
       
  1242 			const TLbsNetTransmitLocationCancelMsg& msg = reinterpret_cast<const TLbsNetTransmitLocationCancelMsg&>(aMessage);
       
  1243 
       
  1244 			// Logging
       
  1245 			iCancelled = ETrue;
       
  1246 			
       
  1247 			// Always transmit cancel to PM dealing with the original request (must have been an x3p session).
       
  1248 			if (iModuleForSession[EX3p])
       
  1249 				{
       
  1250 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::CancelTransmitLocation() ProtocolModule\n");
       
  1251 				LBSLOG(ELogP9, "  > TLbsNetTransmitLocationCancelMsg msg.SessionId()  = \n");
       
  1252 				LBSLOG_SESSIONID(msg.SessionId());
       
  1253 				LBSLOG2(ELogP9, "  > TInt msg.Reason()  = %d\n", msg.Reason());
       
  1254 
       
  1255 				LBS_RDEBUG_ARGINT("LBS", "ProtMod", "CancelTransmitLocation", msg.Reason());
       
  1256 				iModuleForSession[EX3p]->CancelTransmitLocation(TLBSNETSESSIONID(msg.SessionId()),
       
  1257 																msg.Reason());
       
  1258 				}
       
  1259 			else
       
  1260 				{
       
  1261 				// Shouldn't get here, logic error but gateway does not panic in release mode!
       
  1262 				LBSLOG_ERR(ELogP3, "CNetworkGateway::ProcessNetRequestMessage: No stored Protocol Module for x3p TransmitLocationCancel msg");
       
  1263 				__ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));			
       
  1264 				}
       
  1265 
       
  1266 			break;
       
  1267 			}
       
  1268 		case TLbsNetInternalMsgBase::ECancelFromPrivacyController:
       
  1269 
       
  1270  			{
       
  1271  			const TLbsNetCancelFromPrivacyControllerMsg& msg = reinterpret_cast<const TLbsNetCancelFromPrivacyControllerMsg&>(aMessage);
       
  1272  
       
  1273    			/** LBSLOGGER - Start Logging */
       
  1274    			// -------------------------------------------------------------------------
       
  1275    			if (iExternalLogEvent == NULL)
       
  1276    				{
       
  1277    				TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(msg.SessionId().SessionOwner(), NULL, NULL));
       
  1278    				}
       
  1279    			// -------------------------------------------------------------------------
       
  1280    			/** LBSLOGGER - End Logging */
       
  1281 			 				
       
  1282 			// Always transmit cancel to PM dealing with the original request. Must have been MT-LR
       
  1283 			TSessionTypes sessionType;
       
  1284 			CLbsNetworkProtocolBase* originalPM = FindOriginalPMFromID(TLBSNETSESSIONID(msg.SessionId()), sessionType);
       
  1285 			__ASSERT_DEBUG(sessionType == EMtlrHome || sessionType == EMtlrRoaming,
       
  1286 						   User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType)); 			 
       
  1287 			if (originalPM)
       
  1288 				{
       
  1289 
       
  1290    				// Request extended module interface
       
  1291    				CLbsNetworkProtocolBase2* networkProtocolExt = 
       
  1292    					reinterpret_cast<CLbsNetworkProtocolBase2*>
       
  1293 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
  1294    					(originalPM->ExtendedInterface(CLbsNetworkProtocolBase::EExtInterface2,0,0));
       
  1295 #else
       
  1296    					(originalPM->ExtendedInterface(ELbsNetExtInterface2,0,0));
       
  1297 #endif
       
  1298 
       
  1299    				if (networkProtocolExt != NULL)
       
  1300    					{
       
  1301    					LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::CancelExternalLocation() ProtocolModule\n");
       
  1302    					LBSLOG(ELogP9, "  > TLbsNetTransmitLocationRequestMsg msg.SessionId()  = \n");
       
  1303    					LBSLOG_SESSIONID(msg.SessionId());
       
  1304  					LBSLOG2(ELogP9, "  > TInt msg.Reason()  = %d\n", msg.Reason());
       
  1305 
       
  1306    					// Use extended API
       
  1307    					networkProtocolExt->CancelExternalLocation(TLBSNETSESSIONID(msg.SessionId()),
       
  1308    															msg.Reason());
       
  1309    					}
       
  1310    				else 
       
  1311    					{
       
  1312    					// do nothing if its the old type of protocol module 
       
  1313    					}
       
  1314    				}
       
  1315    			else
       
  1316    				{
       
  1317 				// Shouldn't get here, logic error but gateway does not panic in release mode!
       
  1318 				LBSLOG_ERR(ELogP3, "CNetworkGateway::ProcessNetRequestMessage: Continuation message but no stored session info");
       
  1319 				__ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));
       
  1320 
       
  1321    				// No network protocol module to which we can send the request, so send
       
  1322    				// a 'no network available' error back. This is probably marginally tidier than not doing so.
       
  1323    				ProcessSessionComplete(TLBSNETSESSIONID(msg.SessionId()), KErrPositionNetworkUnavailable);
       
  1324 
       
  1325    				}
       
  1326    			break;
       
  1327    			}
       
  1328 			
       
  1329 		case TLbsNetInternalMsgBase::EPrivacyResponse:
       
  1330 			{
       
  1331 			const TLbsNetMtLrReponseMsg& msg = reinterpret_cast<const TLbsNetMtLrReponseMsg&>(aMessage);
       
  1332 
       
  1333 			// Always transmit RespondPrivacyRequest to PM dealing with the original request (must be MTLR session).
       
  1334 			TSessionTypes sessionType;
       
  1335 			CLbsNetworkProtocolBase* originalPM = FindOriginalPMFromID(TLBSNETSESSIONID(msg.SessionId()), sessionType);
       
  1336 			__ASSERT_DEBUG(sessionType == EMtlrHome || sessionType == EMtlrRoaming,
       
  1337 							User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType)); 			 
       
  1338 
       
  1339 			if (originalPM)
       
  1340 				{
       
  1341 				LBSLOG(ELogP9, "->A CLbsNetworkProtocolBase::RespondPrivacyRequest() ProtocolModule\n");
       
  1342 				LBSLOG(ELogP9, "  > TLbsNetMtLrReponseMsg msg.SessionId()  = \n");
       
  1343 				LBSLOG_SESSIONID(msg.SessionId());
       
  1344 				LBSLOG2(ELogP9, "  > TLbsNetMtLrReponseMsg msg.Response()  = %d", msg.Response());
       
  1345 
       
  1346 				LBS_RDEBUG_ARGINT("LBS", "ProtMod", "RespondPrivacyRequest", msg.Response());
       
  1347 
       
  1348    				CLbsNetworkProtocolBase2* networkProtocolExt = 
       
  1349    					reinterpret_cast<CLbsNetworkProtocolBase2*>
       
  1350 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
  1351    					(originalPM->ExtendedInterface(CLbsNetworkProtocolBase::EExtInterface2,0,0));
       
  1352 #else
       
  1353    					(originalPM->ExtendedInterface(ELbsNetExtInterface2,0,0));
       
  1354 #endif
       
  1355 
       
  1356 							
       
  1357 				if (networkProtocolExt != NULL)
       
  1358 					{
       
  1359 					const CLbsNetworkProtocolBase::TLbsPrivacyResponse resp = (const CLbsNetworkProtocolBase::TLbsPrivacyResponse&) msg.Response();
       
  1360 												
       
  1361 					networkProtocolExt->RespondPrivacyRequest(TLBSNETSESSIONID(msg.SessionId()), resp, msg.Reason());
       
  1362 					}
       
  1363 				else 
       
  1364 					{
       
  1365 					originalPM->RespondPrivacyRequest(TLBSNETSESSIONID(msg.SessionId()), (const CLbsNetworkProtocolBase::TLbsPrivacyResponse&) msg.Response());
       
  1366 					}
       
  1367 				}
       
  1368 			else
       
  1369 				{
       
  1370 				// Shouldn't get here, logic error but gateway does not panic in release mode!
       
  1371 				LBSLOG_ERR(ELogP1, "CNetworkGateway::ProcessNetRequestMessage: No stored Protocol Module for Privacy Response msg");
       
  1372 				__ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedSessionIdOrType));
       
  1373 				}
       
  1374 												    
       
  1375 			/** LBSLOGGER - Start Logging */
       
  1376 			// -------------------------------------------------------------------------
       
  1377 			if (iExternalLogEvent == NULL)
       
  1378 				{
       
  1379 				TRAP_IGNORE(iExternalLogEvent = CLbsExternalLocateLogEvent::NewL(msg.SessionId().SessionOwner(), NULL, NULL));
       
  1380 				}
       
  1381 			if (iExternalLogEvent != NULL)
       
  1382 				{
       
  1383 				TLbsLoggingPrivacyResponseParams params;
       
  1384 				params.iSessionId.SetSessionOwner(msg.SessionId().SessionOwner());
       
  1385 				params.iSessionId.SetSessionNum(msg.SessionId().SessionNum());
       
  1386 				params.iResult = static_cast<CLbsNetworkProtocolBase::TLbsPrivacyResponse>(msg.Response());
       
  1387 				iExternalLogEvent->SetPrivacyResponseParams(params);
       
  1388 				}
       
  1389 			// -------------------------------------------------------------------------
       
  1390 			/** LBSLOGGER - End Logging */
       
  1391 												    
       
  1392 			break;
       
  1393 			}
       
  1394 		default:
       
  1395 			{
       
  1396 			break;
       
  1397 			}
       
  1398 		}
       
  1399 	}
       
  1400 
       
  1401 //---------------------------------------------------------------------------------------------------
       
  1402 // Messages from the Network Registration Status Monitor (MNetworkRegistrationStatusObserver)
       
  1403 //---------------------------------------------------------------------------------------------------
       
  1404 void CNetworkGateway::OnNetworkRegistrationStatusChange(
       
  1405 		RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus aStatus)
       
  1406 	{
       
  1407 	LBSLOG(ELogP2, "CNetworkGateway::OnNetworkRegistrationStatusChange:");
       
  1408 	LBSLOG2(ELogP2, "Status : %d", aStatus);
       
  1409 	
       
  1410 	iRegistrationStatus = aStatus;
       
  1411 	
       
  1412 	// If we're loading by status and there is already one set of protocol
       
  1413 	//  modules loaded do not allow another set to be loaded.
       
  1414 	if( iLoadInfo.LoadingStrategy() == TLbsAdminProtocolModuleLoadingInfo::EProtocolModuleLoadingByStatus )
       
  1415 		{
       
  1416 		if( aStatus == RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork && ModuleInfo(iRoamingPmUid) )
       
  1417 		    {
       
  1418 		    if( ModuleInfo(iRoamingPmUid)->ProtocolModule() )
       
  1419 		        {
       
  1420 		        return;
       
  1421 		        }
       
  1422 		    }
       
  1423 		else if( aStatus == RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork && ModuleInfo(iHomePmUid) )
       
  1424 			{
       
  1425 			if( ModuleInfo(iHomePmUid)->ProtocolModule() )
       
  1426 			    {
       
  1427                 return;
       
  1428 			    }
       
  1429 			}
       
  1430 		}
       
  1431 
       
  1432 	switch (aStatus)
       
  1433 		{
       
  1434 		case RLbsNetworkRegistrationStatus::ENotRegistered:
       
  1435 			{
       
  1436 			// Handled by iRegistrationStatus being set to ENotRegistered
       
  1437 			break;
       
  1438 			}
       
  1439 
       
  1440 		case RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork:
       
  1441 			{
       
  1442 			for(TUint index = 0; index < iPmCount; index++)
       
  1443 				{
       
  1444 				if( iModules[index]->Home() && (!iModules[index]->ProtocolModule()) )
       
  1445 					{
       
  1446 					TRAPD(err, LoadProtocolModuleL(iModules[index]->ModuleUid()));
       
  1447 					if (err != KErrNone)
       
  1448 						{
       
  1449 						LBSLOG_ERR2(ELogP3, "Error creating protocol module: %d", err);
       
  1450 						}
       
  1451 					}
       
  1452 				}
       
  1453 			break;
       
  1454 			}
       
  1455 		case RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork:
       
  1456 			{
       
  1457 			for(TUint index = 0; index < iPmCount; index++)
       
  1458 				{
       
  1459 				if( iModules[index]->Roaming() && (!iModules[index]->ProtocolModule()) )
       
  1460 					{
       
  1461 					TRAPD(err, LoadProtocolModuleL(iModules[index]->ModuleUid()));
       
  1462 					if (err != KErrNone)
       
  1463 						{
       
  1464 						LBSLOG_ERR2(ELogP3, "Error creating protocol module: %d", err);
       
  1465 						}
       
  1466 					}
       
  1467 				}
       
  1468 			break;
       
  1469 			}
       
  1470 		
       
  1471 		// Should never be at Registration Unknown, nor any state not dealt with above...
       
  1472 		case RLbsNetworkRegistrationStatus::ENetworkRegistrationUnknown:
       
  1473 		default:
       
  1474 			{
       
  1475 			// Programming error we are not going to recover from..
       
  1476 			User::Panic(KLbsNGFault, ENGUnexpectedMsgType);
       
  1477 			}
       
  1478 		}
       
  1479 	}
       
  1480 
       
  1481 //---------------------------------------------------------------------------------------------------
       
  1482 // Other, private.
       
  1483 //---------------------------------------------------------------------------------------------------
       
  1484 
       
  1485 /* Observer that is called when LbsRoot has requested the Network Gateway to shutdown.
       
  1486 */
       
  1487 void CNetworkGateway::OnProcessCloseDown()
       
  1488 	{
       
  1489 	// For now, simply close down as soon as possible.
       
  1490 	// In future the close down may need to be asynchronous,
       
  1491 	// to allow the buffers in CAgpsChannel and CNetRequestChannel
       
  1492 	// to be processed normally.
       
  1493 	CActiveScheduler::Stop();
       
  1494 	}
       
  1495 
       
  1496 /* Called when LbsRoot wants the Lbs system to reset the internal state
       
  1497    of data buffers, etc. For the Network Gateway, the main thing is to 
       
  1498    set 'invalid' assistance data in the interface to the agps manager.
       
  1499 */
       
  1500 void CNetworkGateway::OnProcessReset()
       
  1501 	{
       
  1502 	// Send a set of 'invalid' assistance data to the AGPS manager
       
  1503 	TRAP_IGNORE(ResetAssistanceDataBufferL());
       
  1504 	}
       
  1505 
       
  1506 /* Reset the assistance data channel by sending invalid
       
  1507    assistance data to it.
       
  1508 */
       
  1509 void CNetworkGateway::ResetAssistanceDataBufferL()
       
  1510 	{
       
  1511 	if(iAgpsChannel)
       
  1512 		{
       
  1513 		TLbsAsistanceDataGroup dataMask = EAssistanceDataAquisitionAssistance |
       
  1514 										  EAssistanceDataBadSatList |
       
  1515 										  EAssistanceDataNavigationModel |
       
  1516 										  EAssistanceDataReferenceTime |
       
  1517 										  EAssistanceDataIonosphericModel |
       
  1518 										  EAssistanceDataDgpsCorrections |
       
  1519 										  EAssistanceDataReferenceLocation |
       
  1520 										  EAssistanceDataAlmanac |
       
  1521 										  EAssistanceDataPositioningGpsUtcModel;
       
  1522 		
       
  1523 		RLbsAssistanceDataBuilderSet builderSet;
       
  1524 		CleanupClosePushL(builderSet);
       
  1525 		builderSet.OpenL();
       
  1526 		
       
  1527 		TTime invalidTimeStamp(0);
       
  1528 		
       
  1529 		RUEPositioningGpsAlmanacBuilder* almanacPtr;
       
  1530 		User::LeaveIfError(builderSet.GetDataBuilder(almanacPtr));
       
  1531 		almanacPtr->SetTimeStamp(invalidTimeStamp);
       
  1532 			
       
  1533 		RUEPositioningGpsIonosphericModelBuilder* ionosphericPtr;
       
  1534 		User::LeaveIfError(builderSet.GetDataBuilder(ionosphericPtr));
       
  1535 		ionosphericPtr->SetTimeStamp(invalidTimeStamp);
       
  1536 		
       
  1537 		RUEPositioningGpsNavigationModelBuilder* navigationPtr;
       
  1538 		User::LeaveIfError(builderSet.GetDataBuilder(navigationPtr));
       
  1539 		navigationPtr->SetTimeStamp(invalidTimeStamp);
       
  1540 		
       
  1541 		RUEPositioningGpsReferenceTimeBuilder* referenceTimePtr;
       
  1542 		User::LeaveIfError(builderSet.GetDataBuilder(referenceTimePtr));
       
  1543 		referenceTimePtr->SetTimeStamp(invalidTimeStamp);
       
  1544 		
       
  1545 		RUEPositioningGpsUtcModelBuilder*  utcPtr;
       
  1546 		User::LeaveIfError(builderSet.GetDataBuilder(utcPtr));
       
  1547 		utcPtr->SetTimeStamp(invalidTimeStamp);
       
  1548 		
       
  1549 		RUEPositioningGpsAcquisitionAssistanceBuilder* acquisitionPtr;
       
  1550 		User::LeaveIfError(builderSet.GetDataBuilder(acquisitionPtr));
       
  1551 		acquisitionPtr->SetTimeStamp(invalidTimeStamp);
       
  1552 		
       
  1553 		RBadSatListBuilder* badSatPtr;
       
  1554 		User::LeaveIfError(builderSet.GetDataBuilder(badSatPtr));
       
  1555 		badSatPtr->SetTimeStamp(invalidTimeStamp);
       
  1556 		
       
  1557 		RReferenceLocationBuilder* referenceLocationPtr;
       
  1558 		User::LeaveIfError(builderSet.GetDataBuilder(referenceLocationPtr));
       
  1559 		referenceLocationPtr->SetTimeStamp(invalidTimeStamp);
       
  1560 	
       
  1561 		// Send this invalid data to the assistance data channel	
       
  1562 		iAgpsChannel->SendAssistanceDataResponse(KErrNotReady,
       
  1563 											 dataMask,
       
  1564 									 		 builderSet);
       
  1565 	
       
  1566 		CleanupStack::PopAndDestroy(&builderSet);
       
  1567 		}
       
  1568 	}
       
  1569 
       
  1570 /** Get the preferred GPS mode to use based on admin settings.
       
  1571 
       
  1572 There are separate hoem and roaming settings for the preferred GPS mode to use,
       
  1573 so need to check the current network registration status to read the correct
       
  1574 setting. If the status is not home or roaming (i.e. unregistered), use the
       
  1575 roaming setting instead.
       
  1576 */
       
  1577 CLbsAdmin::TGpsMode CNetworkGateway::GetAdminGpsMode() const
       
  1578 	{
       
  1579 	RLbsNetworkRegistrationStatus::TLbsNetworkRegistrationStatus netRegStatus(RLbsNetworkRegistrationStatus::ENetworkRegistrationUnknown);
       
  1580 	netRegStatus = iNetworkRegistrationStatusMonitor->GetCurrentNetworkRegistrationStatus();
       
  1581 	if (netRegStatus == RLbsNetworkRegistrationStatus::ENotRegistered)
       
  1582 		{
       
  1583 		// Unregistered status may just be temporary, so use the last good
       
  1584 		// registration status instead of the current status.
       
  1585 		netRegStatus = iNetworkRegistrationStatusMonitor->GetLastGoodNetworkRegistrationStatus();
       
  1586 		}
       
  1587 
       
  1588 	TLbsAdminSetting setting(KLbsSettingHomeGpsMode);
       
  1589 	switch (netRegStatus)
       
  1590 		{
       
  1591 		case RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork:
       
  1592 			{
       
  1593 			setting = KLbsSettingHomeGpsMode;
       
  1594 			break;
       
  1595 			}
       
  1596 		case RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork:
       
  1597 		default:
       
  1598 			{
       
  1599 			setting = KLbsSettingRoamingGpsMode;
       
  1600 			break;
       
  1601 			}
       
  1602 		}
       
  1603 	
       
  1604 	CLbsAdmin::TGpsMode adminGpsMode(CLbsAdmin::EGpsModeUnknown);
       
  1605 	TInt err = iAdmin->Get(setting, adminGpsMode);
       
  1606 
       
  1607 	// If our call to find admin setting was broken, use most likely setting...
       
  1608 	if (err != KErrNone)
       
  1609 		{
       
  1610 		LBSLOG_ERR2(ELogP2, "Error %d with get of Gps Admin Mode\n", err); 
       
  1611 		adminGpsMode = CLbsAdmin::EGpsPreferTerminalBased;
       
  1612 		}
       
  1613 
       
  1614 	return adminGpsMode;
       
  1615 	}
       
  1616 
       
  1617 CLbsNetworkProtocolBase* CNetworkGateway::DefaultPm()
       
  1618 	{
       
  1619 	if(iRegistrationStatus == RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork)
       
  1620 		return ModuleInfo(iHomePmUid)->ProtocolModule();
       
  1621 	else if(iRegistrationStatus == RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork)
       
  1622 		return ModuleInfo(iRoamingPmUid)->ProtocolModule();
       
  1623 	
       
  1624 	return NULL;
       
  1625 	}
       
  1626 
       
  1627 TBool CNetworkGateway::ValidPm(TUid aPmUid)
       
  1628 	{
       
  1629 	if(ModuleInfo(aPmUid))
       
  1630 		{
       
  1631 		if((ModuleInfo(aPmUid))->ProtocolModule())
       
  1632 			{
       
  1633 			if( (iRegistrationStatus == RLbsNetworkRegistrationStatus::ERegisteredHomeNetwork && (ModuleInfo(aPmUid))->Home()) ||
       
  1634 				(iRegistrationStatus == RLbsNetworkRegistrationStatus::ERegisteredRoamingNetwork && (ModuleInfo(aPmUid))->Roaming()) )
       
  1635 				{
       
  1636 				return ETrue;
       
  1637 				}
       
  1638 			}
       
  1639 		}
       
  1640 		
       
  1641 	return EFalse;
       
  1642 	}
       
  1643 
       
  1644 CLbsNetworkProtocolBase* CNetworkGateway::FindOriginalPMFromID(const TLbsNetSessionId& aId, TSessionTypes& aType)
       
  1645 	{
       
  1646 	TUid id = aId.SessionOwner();
       
  1647 
       
  1648 	if (ModuleInfo(id)) // If the request was from a protocol module
       
  1649 		{
       
  1650 		aType = ((ModuleInfo(id))->Home()) ? EMtlrHome : EMtlrRoaming; 
       
  1651 		return  (ModuleInfo(id))->ProtocolModule();
       
  1652 		}
       
  1653 	else if (id == KLbsNetLocManagerUid)
       
  1654         {
       
  1655         aType = ENetworkLocation;
       
  1656         return iModuleForSession[ENetworkLocation];
       
  1657         }
       
  1658     else if (id == KLbsSuplPsyUid)
       
  1659         {
       
  1660         aType = EPSYLocation;
       
  1661         return iModuleForSession[EPSYLocation];
       
  1662         }
       
  1663     else if (id == KLbsNetRequestHandlerUid)
       
  1664         {
       
  1665         aType = EX3p;
       
  1666         return iModuleForSession[EX3p];
       
  1667         }
       
  1668     else if (id == KLbsGpsLocManagerUid)
       
  1669         {
       
  1670         aType = ESelfLocation;
       
  1671         return iModuleForSession[ESelfLocation];
       
  1672         }
       
  1673     else
       
  1674         {
       
  1675         aType = EInvalidSession;
       
  1676         return DefaultPm();
       
  1677         }
       
  1678 	}
       
  1679 
       
  1680 CProtocolModuleInfo* CNetworkGateway::ModuleInfo(TLbsProtocolModuleId aUid)
       
  1681 	{
       
  1682 	for(TUint index = 0; index < iPmCount; index++)
       
  1683 		{
       
  1684 		if(iModules[index]->ModuleUid() == aUid)
       
  1685 			{
       
  1686 			return iModules[index];
       
  1687 			}
       
  1688 		}
       
  1689 	
       
  1690 	return NULL; 
       
  1691 	}
       
  1692 
       
  1693 void CNetworkGateway::DeleteLoadedModules()
       
  1694 	{
       
  1695 	for(TUint index = 0; index < iPmCount; index++)
       
  1696 		{
       
  1697 		delete(iModules[index]);
       
  1698 		}
       
  1699 	iPmCount = 0;
       
  1700 	}
       
  1701 
       
  1702 CProtocolModuleInfo* CProtocolModuleInfo::NewL(TLbsProtocolModuleId aModuleId, CNetObserver* aObs, CLbsNetworkProtocolBase* aNetworkProtocol, TBool aHome, TBool aRoaming)
       
  1703 	{
       
  1704 	CProtocolModuleInfo* self = new (ELeave) CProtocolModuleInfo(aModuleId, aObs, aNetworkProtocol, aHome, aRoaming);
       
  1705 	CleanupStack::PushL(self);
       
  1706 	self->ConstructL();
       
  1707 	CleanupStack::Pop(self);
       
  1708 	return self;	
       
  1709 	}
       
  1710 
       
  1711 CProtocolModuleInfo::~CProtocolModuleInfo()
       
  1712 	{
       
  1713 	delete iObs;
       
  1714 	delete iNetworkProtocol;
       
  1715 	}
       
  1716 
       
  1717 CProtocolModuleInfo::CProtocolModuleInfo(TLbsProtocolModuleId aModuleId, CNetObserver* aObs, CLbsNetworkProtocolBase* aNetworkProtocol, TBool aHome, TBool aRoaming):
       
  1718 	iModuleId(aModuleId),
       
  1719 	iObs(aObs),
       
  1720 	iNetworkProtocol(aNetworkProtocol),
       
  1721 	iHome(aHome),
       
  1722 	iRoaming(aRoaming)
       
  1723 	{
       
  1724 	}
       
  1725 
       
  1726 void CProtocolModuleInfo::ConstructL()
       
  1727 	{
       
  1728 	}
       
  1729 
       
  1730 TLbsProtocolModuleId CProtocolModuleInfo::ModuleUid()
       
  1731 	{
       
  1732 	return iModuleId;
       
  1733 	}
       
  1734 
       
  1735 void CProtocolModuleInfo::SetObserver(CNetObserver* aObserver)
       
  1736 	{
       
  1737 	iObs = aObserver;
       
  1738 	}
       
  1739 
       
  1740 CNetObserver* CProtocolModuleInfo::Observer()
       
  1741 	{
       
  1742 	return iObs;
       
  1743 	}
       
  1744 
       
  1745 void CProtocolModuleInfo::SetProtocolModule(CLbsNetworkProtocolBase* aProtocolModule)
       
  1746 	{
       
  1747 	iNetworkProtocol = aProtocolModule;
       
  1748 	}
       
  1749 
       
  1750 CLbsNetworkProtocolBase* CProtocolModuleInfo::ProtocolModule()
       
  1751 	{
       
  1752 	return iNetworkProtocol;
       
  1753 	}
       
  1754 
       
  1755 void CProtocolModuleInfo::SetHome()
       
  1756 	{
       
  1757 	iHome = ETrue;
       
  1758 	}
       
  1759 
       
  1760 TBool CProtocolModuleInfo::Home()
       
  1761 	{
       
  1762 	return iHome;
       
  1763 	}
       
  1764 	
       
  1765 void CProtocolModuleInfo::SetRoaming()
       
  1766 	{
       
  1767 	iRoaming = ETrue;
       
  1768 	}
       
  1769 
       
  1770 TBool CProtocolModuleInfo::Roaming()
       
  1771 	{
       
  1772 	return iRoaming;
       
  1773 	}
       
  1774 void CNetworkGateway::ConvertToTLbsNetPosRequestQualityInt(
       
  1775 			const TLbsNetPosRequestQuality& aSource,
       
  1776 			TLbsNetPosRequestQualityInt& aDest) const
       
  1777 	
       
  1778 	{
       
  1779 	aDest.SetMaxFixTime(aSource.MaxFixTime());
       
  1780 	aDest.SetMaxFixAge(aSource.MaxFixAge());
       
  1781 	aDest.SetMinHorizontalAccuracy(aSource.MinHorizontalAccuracy());
       
  1782 	aDest.SetMinVerticalAccuracy(aSource.MinVerticalAccuracy());
       
  1783 	}
       
  1784 	
       
  1785 void CNetworkGateway::ConvertToTLbsNetPosRequestQuality(
       
  1786 			const TLbsNetPosRequestQualityInt& aSource,
       
  1787 			TLbsNetPosRequestQuality& aDest) const
       
  1788 	{
       
  1789 	aDest.SetMaxFixTime(aSource.MaxFixTime());
       
  1790 	aDest.SetMaxFixAge(aSource.MaxFixAge());
       
  1791 	aDest.SetMinHorizontalAccuracy(aSource.MinHorizontalAccuracy());
       
  1792 	aDest.SetMinVerticalAccuracy(aSource.MinVerticalAccuracy());
       
  1793 	}
       
  1794 
       
  1795 void CNetworkGateway::ConvertToTLbsNetPosRequestOptions(
       
  1796 			const TLbsNetPosRequestOptionsInt& aSource,
       
  1797 			TLbsNetPosRequestOptions& aDest) const
       
  1798 	{
       
  1799 	aDest.SetNewClientConnected(aSource.NewClientConnected());
       
  1800 	
       
  1801 	TLbsNetPosRequestQualityInt qualityInt;
       
  1802 	aSource.GetRequestQuality(qualityInt);
       
  1803 	TLbsNetPosRequestQuality quality;
       
  1804 	ConvertToTLbsNetPosRequestQuality(qualityInt, quality);
       
  1805 	aDest.SetRequestQuality(quality);
       
  1806 	}
       
  1807 
       
  1808 void CNetworkGateway::ConvertToTLbsNetPosRequestOptionsAssistance(
       
  1809 			const TLbsNetPosRequestOptionsAssistanceInt& aSource,
       
  1810 			TLbsNetPosRequestOptionsAssistance& aDest) const
       
  1811 	{
       
  1812 	aDest.SetNewClientConnected(aSource.NewClientConnected());
       
  1813 	
       
  1814 	TLbsNetPosRequestQualityInt qualityInt;
       
  1815 	aSource.GetRequestQuality(qualityInt);
       
  1816 	TLbsNetPosRequestQuality quality;
       
  1817 	ConvertToTLbsNetPosRequestQuality(qualityInt, quality);
       
  1818 	aDest.SetRequestQuality(quality);
       
  1819 	
       
  1820 	aDest.SetDataRequestMask((TLbsAsistanceDataGroupInt) aSource.DataRequestMask());
       
  1821 	aDest.SetPosMode((TPositionModuleInfo::TTechnologyType) aSource.PosMode());	
       
  1822 	}
       
  1823 
       
  1824 void CNetworkGateway::ConvertToTLbsNetPosRequestOptionsTechnology(
       
  1825 			const TLbsNetPosRequestOptionsTechnologyInt& aSource,
       
  1826 			TLbsNetPosRequestOptionsTechnology& aDest) const
       
  1827 	{
       
  1828 	aDest.SetNewClientConnected(aSource.NewClientConnected());
       
  1829 	
       
  1830 	TLbsNetPosRequestQualityInt qualityInt;
       
  1831 	aSource.GetRequestQuality(qualityInt);
       
  1832 	TLbsNetPosRequestQuality quality;
       
  1833 	ConvertToTLbsNetPosRequestQuality(qualityInt, quality);
       
  1834 	aDest.SetRequestQuality(quality);
       
  1835 	aDest.SetPosMode(aSource.PosMode());
       
  1836 	}
       
  1837