lbstest/lbstestproduct/lbstestutils/src/tlbsutils.cpp
changeset 0 9cfd9a3ee49c
child 23 2965a06983dc
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file CT_Utils.cpp
       
    15 // This is the Cpp file which contains the utility functions common across the servers
       
    16 // 
       
    17 //
       
    18 
       
    19 // User includes
       
    20 #include "tlbsutils.h"
       
    21 #include "ctlbsconfigreader.h"
       
    22 #include <lbs/test/ctlbsasyncwaiter.h>
       
    23 #include "ctlbstestloggermacros.h"
       
    24 
       
    25 // Epoc includes
       
    26 #include <f32file.h>
       
    27 #include <e32math.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 // Lbs includes
       
    31 #include <lbsclasstypes.h>
       
    32 #include <lbssatellite.h>
       
    33 
       
    34 
       
    35 // defines
       
    36 #define BAD_MODULE_ID	0x87654321
       
    37 
       
    38 
       
    39 /**
       
    40 */
       
    41 EXPORT_C TLbsModuleUpdateItem::TLbsModuleUpdateItem()
       
    42 	{
       
    43 	}
       
    44 
       
    45 
       
    46 /**
       
    47 */
       
    48 EXPORT_C const TPositionExtendedSatelliteInfo& TLbsModuleUpdateItem::Position() const
       
    49 	{
       
    50 	return iPosition;
       
    51 	}
       
    52 
       
    53 /**
       
    54 */
       
    55 EXPORT_C void TLbsModuleUpdateItem::SetPosition(const TPositionExtendedSatelliteInfo& aPosition)
       
    56 	{
       
    57 	iPosition = aPosition;
       
    58 	}
       
    59 
       
    60 
       
    61 /**
       
    62 */
       
    63 EXPORT_C const TPositionGpsMeasurementInfo& TLbsModuleUpdateItem::Measurement() const
       
    64 	{
       
    65 	return iMeasurement;
       
    66 	}
       
    67 
       
    68 /**
       
    69 */
       
    70 EXPORT_C void TLbsModuleUpdateItem::SetMeasurement(const TPositionGpsMeasurementInfo& aMeasurement)
       
    71 	{
       
    72 	iMeasurement = aMeasurement;
       
    73 	}
       
    74 
       
    75 
       
    76 /**
       
    77 */
       
    78 EXPORT_C TInt TLbsModuleUpdateItem::Error() const
       
    79 	{
       
    80 	return iError;
       
    81 	}
       
    82 
       
    83 /**
       
    84 */
       
    85 EXPORT_C void TLbsModuleUpdateItem::SetDelay(TInt aDelay)
       
    86 	{
       
    87 	iDelay = aDelay;
       
    88 	}
       
    89 
       
    90 /**
       
    91 */
       
    92 EXPORT_C TInt TLbsModuleUpdateItem::Delay() const
       
    93 	{
       
    94 	return iDelay;
       
    95 	}
       
    96 
       
    97 /**
       
    98 */
       
    99 EXPORT_C void TLbsModuleUpdateItem::SetError(TInt aError)
       
   100 	{
       
   101 	iError = aError;
       
   102 	}
       
   103 
       
   104 
       
   105 
       
   106 EXPORT_C T_LbsUtils::T_LbsUtils()
       
   107 /** Constructor.
       
   108 */
       
   109 	{
       
   110 	}
       
   111 
       
   112 
       
   113 EXPORT_C T_LbsUtils::~T_LbsUtils()
       
   114 /** Destructor.
       
   115 */
       
   116 	{
       
   117 	}
       
   118 
       
   119 
       
   120 /*EXPORT_C static*/ /*void GetDefault_ModuleStatusInfo(TModuleConfiguredStatus& aStatusInfo)
       
   121 	{
       
   122 		(void)aStatusInfo;	
       
   123 	}
       
   124 */
       
   125 
       
   126 EXPORT_C void T_LbsUtils::ResetIntegrationModulesCountOfCancelsL()
       
   127 /** Sets the test integration modules count of cancels received from LBS to zero.
       
   128 */
       
   129 	{
       
   130 	// reset integration modules count of number of cancels recieved from LBS 
       
   131 	TPckgBuf<TCancelCount> cancelCountBuf;
       
   132 	TCancelCount& cancelCount = cancelCountBuf();
       
   133 	cancelCount.iCancelCount = 0;
       
   134 	TInt err = RProperty::Set(KUidSystemCategory, ELbsTestAGpsModuleCancelCount, cancelCountBuf);
       
   135 
       
   136 	if (err != KErrNone)
       
   137 		{
       
   138 		User::Leave(err);
       
   139 		}
       
   140 	
       
   141 	}
       
   142 
       
   143 EXPORT_C void T_LbsUtils::IncrementIntegrationModulesCountOfCancels()
       
   144 /** Gets the current test integration modules count of cancels received from LBS.
       
   145 */
       
   146 	{
       
   147 	TCancelCount readCount;
       
   148 	TPckg<TCancelCount> pckgount(readCount);
       
   149 	TInt err = RProperty::Get(KUidSystemCategory, ELbsTestAGpsModuleCancelCount, pckgount);
       
   150 	if (err != KErrNone)
       
   151 		{
       
   152 		// error deliberately ignored! If property is not defined just do nothing as counting of cancels is now not supported
       
   153 		return;
       
   154 		}
       
   155 	
       
   156 	TPckgBuf<TCancelCount> cancelCountBuf;
       
   157 	TCancelCount& cancelCount = cancelCountBuf();
       
   158 
       
   159 	TUint countOfNumberOfCancels = readCount.iCancelCount;
       
   160 	countOfNumberOfCancels++;
       
   161 	cancelCount.iCancelCount = countOfNumberOfCancels;
       
   162 	err = RProperty::Set(KUidSystemCategory, ELbsTestAGpsModuleCancelCount, cancelCountBuf);
       
   163 	}
       
   164 EXPORT_C TUint T_LbsUtils::IntegrationModulesCountOfCancelsL()
       
   165 	{
       
   166 	TCancelCount readCancelCount;
       
   167 	TPckg<TCancelCount> pckgCount(readCancelCount);
       
   168 	TInt err = RProperty::Get(KUidSystemCategory, ELbsTestAGpsModuleCancelCount, pckgCount);
       
   169 	if (err != KErrNone)
       
   170 		{
       
   171 		User::Leave(err);
       
   172 		}
       
   173 	return readCancelCount.iCancelCount;
       
   174 	}
       
   175 
       
   176 EXPORT_C void T_LbsUtils::CreateTestPropertiesL()
       
   177 /** Creates the test properties for the test module. To allow data to be passed between
       
   178 	test steps and the test module.
       
   179 */
       
   180 	{
       
   181 	const TSecurityPolicy KReadPolicy(ECapability_None);
       
   182 	const TSecurityPolicy KWritePolicy(ECapabilityWriteDeviceData);
       
   183 
       
   184 
       
   185 	// Create the test module data bus properties.
       
   186 	TInt err;
       
   187 	
       
   188 	// Data to the test module.
       
   189 	err = RProperty::Define(KUidSystemCategory, ELbsTestAGpsModuleIn, RProperty::ELargeByteArray, KReadPolicy, KWritePolicy, sizeof(TModuleDataIn));
       
   190 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
   191 	{
       
   192 		User::LeaveIfError(err);
       
   193 	}
       
   194 	
       
   195 	// Data from the test module.
       
   196 	err = RProperty::Define(KUidSystemCategory, ELbsTestAGpsModuleOut, RProperty::ELargeByteArray, KReadPolicy, KWritePolicy, sizeof(TModuleDataOut));
       
   197 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
   198 	{
       
   199 		User::LeaveIfError(err);
       
   200 	}
       
   201 
       
   202 	// Data from the test clock plugin.
       
   203 	err = RProperty::Define(KUidSystemCategory, ELbsTestClockPluginOut, RProperty::ELargeByteArray, KReadPolicy, KWritePolicy, sizeof(TClockPluginDataOut));
       
   204 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
   205 	{
       
   206 		User::LeaveIfError(err);
       
   207 	}
       
   208 	
       
   209 	// Data from the agps module count of cancels received from lbs
       
   210 	err = RProperty::Define(KUidSystemCategory, ELbsTestAGpsModuleCancelCount, RProperty::ELargeByteArray, KReadPolicy, KWritePolicy, sizeof(TCancelCount));
       
   211 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
   212 	{
       
   213 		User::LeaveIfError(err);
       
   214 	}
       
   215 	
       
   216 	// Creating the property for allowing the AGPS module to report when the mode it's running in changes
       
   217 	err = RProperty::Define(KUidSystemCategory, ELbsTestAGpsModuleModeChanges, RProperty::ELargeByteArray, KReadPolicy, KWritePolicy, sizeof(TLbsGpsOptionsArray));
       
   218 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
   219 		{
       
   220 			User::LeaveIfError(err);
       
   221 		}
       
   222 
       
   223 	// Create other test properties here also - just update the TLbsTestPropertyKeys enum don't add extra Categories.
       
   224 
       
   225 	}
       
   226 
       
   227 
       
   228 EXPORT_C void T_LbsUtils::GetConfigured_PosInfosL(const TDesC& aConfigFileName, const TDesC& aConfigSection, RPointerArray<TAny>& aPosInfoArr)
       
   229 /** Fills a position info array with values read from a configuration ini file.
       
   230 
       
   231 @param aConfigFileName	The name of the ini file to read. If the file name is empty (0 length) then
       
   232 						the array will contain a single pos info item with default values.
       
   233 @param aConfigSection	The section within the ini file to read data from.
       
   234 @param aPosInfoArr		The pos info array to which the items are added. The array will cleared of
       
   235 						existing items.
       
   236 */
       
   237 	{
       
   238 	// Clear array.
       
   239 	ResetAndDestroy_PosInfoArr(aPosInfoArr);
       
   240 
       
   241 	// Check for config file, if not present create a single default TPositionInfo.
       
   242 	if (aConfigFileName.Length() == 0)
       
   243 		{
       
   244 		TPositionSatelliteInfo* posInfo = new(ELeave) TPositionSatelliteInfo();
       
   245 		TPosition position;
       
   246 
       
   247 		position.SetCoordinate(DEFAULT_NOTIFY_POS_UPDATE_LATITUDE, DEFAULT_NOTIFY_POS_UPDATE_LONGITUDE, DEFAULT_NOTIFY_POS_UPDATE_ALTITUDE);
       
   248 		position.SetAccuracy(DEFAULT_NOTIFY_POS_UPDATE_HORIZONTAL_ACCURACY, DEFAULT_NOTIFY_POS_UPDATE_VERTICAL_ACCURACY);
       
   249 		position.SetCurrentTime();
       
   250 	
       
   251 		posInfo->SetPosition(position);
       
   252 
       
   253 		User::LeaveIfError(aPosInfoArr.Append(posInfo));			
       
   254 		}
       
   255 	
       
   256 	else
       
   257 		{
       
   258 		CPosInfoConfigReader* reader;
       
   259 	
       
   260 		reader = CPosInfoConfigReader::NewL(aConfigFileName, aConfigSection, aPosInfoArr);
       
   261 		CleanupStack::PushL(reader);
       
   262 		
       
   263 		reader->ProcessL();
       
   264 	
       
   265 		CleanupStack::PopAndDestroy(reader);
       
   266 		}
       
   267 	}
       
   268 
       
   269 EXPORT_C void T_LbsUtils::GetConfigured_UpdateArrayL(const TDesC& aConfigFileName, const TDesC& aConfigSection, RPointerArray<TLbsModuleUpdateItem>& aUpdateArr)
       
   270 /** Fills an updata array structure with values read from a configuration ini file.
       
   271 
       
   272 @param aConfigFileName	The name of the ini file to read. If the file name is empty (0 length) then
       
   273 						default values will be used.
       
   274 @param aConfigSection	The section within the ini file to read data from.
       
   275 @param aUpdateArr		The update array to be populated.
       
   276 */
       
   277 	{
       
   278 	// Use default values if file name not given.
       
   279 	if (aConfigFileName.Length() == 0)
       
   280 		{
       
   281 		// I am not sure we want to fill in the array with default values - ??
       
   282 		}
       
   283 	
       
   284 	else
       
   285 		{
       
   286 		CUpdateConfigReader* reader;
       
   287 	
       
   288 		reader = CUpdateConfigReader::NewL(aConfigFileName, aConfigSection, aUpdateArr);
       
   289 		CleanupStack::PushL(reader);
       
   290 		
       
   291 		reader->ProcessL();
       
   292 	
       
   293 		CleanupStack::PopAndDestroy(reader);
       
   294 		}
       
   295 	}
       
   296 
       
   297 
       
   298 // don't think we need this...
       
   299 EXPORT_C void T_LbsUtils::GetConfigured_ModuleStatusL(const TDesC& aConfigFileName, const TDesC& aConfigSection, TPositionModuleStatus& aModuleStatus, TBool& aDelayReportingModStatus)
       
   300 	{
       
   301 	// Use default values if file name not given.
       
   302 	if (aConfigFileName.Length() == 0)
       
   303 		{
       
   304 		aModuleStatus.SetDeviceStatus(TPositionModuleStatus::EDeviceReady);
       
   305 		aModuleStatus.SetDataQualityStatus(TPositionModuleStatus::EDataQualityNormal);
       
   306 		aDelayReportingModStatus = EFalse;
       
   307 		}
       
   308 	else
       
   309 		{
       
   310 		CModuleStatusConfigReader* reader;
       
   311 	
       
   312 		reader = CModuleStatusConfigReader::NewL(aConfigFileName, aConfigSection, aModuleStatus, aDelayReportingModStatus);
       
   313 		CleanupStack::PushL(reader);
       
   314 				
       
   315 		reader->ProcessL();
       
   316 	
       
   317 		CleanupStack::PopAndDestroy(reader);
       
   318 		}
       
   319 	}
       
   320 
       
   321 
       
   322 EXPORT_C void T_LbsUtils::GetConfigured_ModuleUpdateOptionsL(const TDesC& aConfigFileName, const TDesC& aConfigSection, TPositionUpdateOptions& aUpdateOpts)
       
   323 /** Fills a module updata options class/structure with values read from a configuration ini file.
       
   324 
       
   325 @param aConfigFileName	The name of the ini file to read. If the file name is empty (0 length) then
       
   326 						default values will be used.
       
   327 @param aConfigSection	The section within the ini file to read data from.
       
   328 @param aUpdateOpts		The modified update options structure.
       
   329 */
       
   330 	{
       
   331 	// Use default values if file name not given.
       
   332 	if (aConfigFileName.Length() == 0)
       
   333 		{
       
   334 		aUpdateOpts.SetUpdateInterval(0);
       
   335 		aUpdateOpts.SetUpdateTimeOut(0);
       
   336 		aUpdateOpts.SetMaxUpdateAge(0);
       
   337 		aUpdateOpts.SetAcceptPartialUpdates(EFalse);			
       
   338 		}
       
   339 	
       
   340 	else
       
   341 		{
       
   342 		CUpdateOptsConfigReader* reader;
       
   343 	
       
   344 		reader = CUpdateOptsConfigReader::NewL(aConfigFileName, aConfigSection, aUpdateOpts);
       
   345 		CleanupStack::PushL(reader);
       
   346 		
       
   347 		reader->ProcessL();
       
   348 	
       
   349 		CleanupStack::PopAndDestroy(reader);
       
   350 		}
       
   351 	}
       
   352 
       
   353 EXPORT_C void T_LbsUtils::GetConfigured_ClientDetailsL(const TDesC& aConfigFileName, const TDesC& aConfigSection, 
       
   354 						RArray<TCTClientDetails>& aClientDetailsArray)
       
   355 /** Gets the delays for each client with values read from a configuration ini file.
       
   356 
       
   357 @param aConfigFileName		The name of the ini file to read. If the file name is empty (0 length) then
       
   358 							default values will be used.
       
   359 @param aConfigSection		The section within the ini file to read data from.
       
   360 @param aClientDelayArray	The array of client delays.
       
   361 */
       
   362 	{
       
   363 	// Use default values if file name not given.
       
   364 	if (aConfigFileName.Length() == 0)
       
   365 		{ // by default have one client
       
   366 		TCTClientDetails client;
       
   367 		aClientDetailsArray.AppendL(client);
       
   368 		return;
       
   369 		}
       
   370 	
       
   371 	else
       
   372 		{
       
   373 		CClientDetailsConfigReader* reader;
       
   374 		reader = CClientDetailsConfigReader::NewL(aConfigFileName, aConfigSection, aClientDetailsArray);
       
   375 		CleanupStack::PushL(reader);
       
   376 		
       
   377 		reader->ProcessL();
       
   378 	
       
   379 		CleanupStack::PopAndDestroy(reader);
       
   380 		if(aClientDetailsArray.Count() == 0)
       
   381 			{ // by default have one client
       
   382 			TCTClientDetails client;
       
   383 			aClientDetailsArray.AppendL(client);
       
   384 			}
       
   385 		}
       
   386 	}
       
   387 
       
   388 EXPORT_C void T_LbsUtils::GetExpected_ModuleModes(const TDesC& aConfigFileName, const TDesC& aConfigSection, RPointerArray<TLbsGpsOptions>& aModuleModes)
       
   389 	{
       
   390 	if (aConfigFileName.Length() == 0)
       
   391 		{
       
   392 		return;
       
   393 		}
       
   394 	
       
   395 	CAgpsModuleModesConfigReader* reader;
       
   396 	reader = CAgpsModuleModesConfigReader::NewL(aConfigFileName, aConfigSection, aModuleModes);
       
   397 	CleanupStack::PushL(reader);
       
   398 	reader->ProcessL();
       
   399 	CleanupStack::PopAndDestroy(reader);
       
   400 	}
       
   401 
       
   402 
       
   403 EXPORT_C void T_LbsUtils::NotifyModuleOfConfigChangeL(const TModuleDataIn& aModuleDataIn)
       
   404 /** Notify the module of a configuration change.
       
   405 
       
   406 Used when the test harness has read a configuration file and wishes to notify the test module
       
   407 that it should also do a read of the configuration file. To ensure both the test harness and
       
   408 the test module are using the same reference data.
       
   409 	
       
   410 The ELbsTestAGpsModuleIn property is used to pass the ini file and section names to the
       
   411 test module. The ELbsTestAGpsModuleOut is then used to receive an response from the test module.
       
   412 
       
   413 @param aConfigFileName	The file name string to send to the test mdoule.
       
   414 @param aConfigSection	The ini section name string to send to the test module.
       
   415 */
       
   416 	{
       
   417 	// Ask to be notified when the module receives the ini file re-read request.
       
   418 
       
   419 	// Attach and subscribe to listen for data bus updates. Use the async waiter to process
       
   420 	// the update.
       
   421 	RProperty modDataOutProperty;
       
   422 	User::LeaveIfError(modDataOutProperty.Attach(KUidSystemCategory, ELbsTestAGpsModuleOut));
       
   423 
       
   424 	CT_LbsAsyncWaiter* waiter = CT_LbsAsyncWaiter::NewL();
       
   425 	CleanupStack::PushL(waiter);
       
   426 
       
   427 	modDataOutProperty.Subscribe(waiter->iStatus);
       
   428 
       
   429 
       
   430 	// Publish the file and section names to the module, to inform the module it has to
       
   431 	// carry out a re-read of the ini file.
       
   432 	TPckgBuf<TModuleDataIn> modDataInBuf;
       
   433 	TModuleDataIn& modDataIn = modDataInBuf();
       
   434 
       
   435 	// Copy across all the data items.
       
   436 	modDataIn.iRequestType = aModuleDataIn.iRequestType;
       
   437 	modDataIn.iConfigFileName = aModuleDataIn.iConfigFileName;
       
   438 	modDataIn.iConfigSection = aModuleDataIn.iConfigSection;
       
   439 	modDataIn.iAssDataEventType = aModuleDataIn.iAssDataEventType;
       
   440 	modDataIn.iAssDataTestMode = aModuleDataIn.iAssDataTestMode;
       
   441 	modDataIn.iKickOffEventType = aModuleDataIn.iKickOffEventType;
       
   442 	modDataIn.iTimeOut = aModuleDataIn.iTimeOut;
       
   443 	modDataIn.iError = aModuleDataIn.iError;
       
   444 	modDataIn.iTimeStampOffset = aModuleDataIn.iTimeStampOffset;
       
   445     modDataIn.iOptionsChangeReportMode = aModuleDataIn.iOptionsChangeReportMode;
       
   446     modDataIn.iOneOffTimeOut = aModuleDataIn.iOneOffTimeOut;
       
   447     
       
   448 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, ELbsTestAGpsModuleIn, modDataInBuf));
       
   449 
       
   450 	TBool noResponse = ETrue;
       
   451 
       
   452 	// Wait for the notification from the test module.	
       
   453 	while(noResponse)
       
   454 		{
       
   455 	waiter->StartAndWait();
       
   456 	User::LeaveIfError(waiter->Result());
       
   457 
       
   458 	// Now ensure the notification response was good.
       
   459 	TModuleDataOut modDataOut;
       
   460 	TPckg<TModuleDataOut> modDataOutPckg(modDataOut);
       
   461 
       
   462 	User::LeaveIfError(modDataOutProperty.Get(modDataOutPckg));
       
   463 
       
   464 		if ((TModuleDataOut::EModuleResponse == modDataOut.iRequestType) && (TModuleDataOut::EModuleResponseOk == modDataOut.iResponse)) 
       
   465 		{
       
   466 			noResponse = EFalse;
       
   467 			}
       
   468 		}
       
   469 
       
   470 	CleanupStack::PopAndDestroy(waiter);
       
   471 	}
       
   472 
       
   473 
       
   474 EXPORT_C void T_LbsUtils::WaitForModuleToRequestAssistanceDataL()
       
   475 /** Wait for notification that the test AGPS module as requested assistance data.
       
   476 
       
   477 	Blocking function used to determine when the test module has requested assistance data as part of its location update.
       
   478 */
       
   479 	{
       
   480 	RProperty modDataOutProperty;
       
   481 	User::LeaveIfError(modDataOutProperty.Attach(KUidSystemCategory, ELbsTestAGpsModuleOut));
       
   482 
       
   483 	CT_LbsAsyncWaiter* waiter = CT_LbsAsyncWaiter::NewL();
       
   484 	CleanupStack::PushL(waiter);
       
   485 
       
   486 	modDataOutProperty.Subscribe(waiter->iStatus);
       
   487 
       
   488 	// Wait for the notification from the test module.	
       
   489 	waiter->StartAndWait();
       
   490 	User::LeaveIfError(waiter->Result());
       
   491 
       
   492 	// Ensure the correct response is given.
       
   493 	TModuleDataOut modDataOut;
       
   494 	TPckg<TModuleDataOut> modDataOutPckg(modDataOut);
       
   495 
       
   496 	User::LeaveIfError(modDataOutProperty.Get(modDataOutPckg));
       
   497 	
       
   498 	if (TModuleDataOut::EModuleAssDataRequestedOk != modDataOut.iResponse)
       
   499 		{
       
   500 		User::LeaveIfError(KErrArgument);
       
   501 		}
       
   502 
       
   503 	CleanupStack::PopAndDestroy(waiter);
       
   504 	}
       
   505 
       
   506 EXPORT_C TBool T_LbsUtils::Compare_PosInfo(const TPositionInfoBase& aPosInfoSideA, const TPositionInfoBase& aPosInfoSideB)
       
   507 /** Compare two position info structures. Ensure all fields match excatly.
       
   508 
       
   509 @param aPosInfoSideA	The first structure to compare.
       
   510 @param aPosInfoSideB	The second structure to compare.
       
   511 @return					ETrue if both structure match excatly else EFalse.
       
   512 */
       
   513 	{
       
   514 	return Compare_PosInfo(aPosInfoSideA, aPosInfoSideB, EExactAccuracy);
       
   515 	}
       
   516 
       
   517 
       
   518 EXPORT_C TBool T_LbsUtils::Compare_PosInfo(const TPositionInfoBase& aPosInfoSideA, const TPositionInfoBase& aPosInfoSideB, TComparisonAccuracyType aCmpAccuracy)
       
   519 	{
       
   520 	// TODO compare base class items, such as module id, position mode, etc.
       
   521 
       
   522 	TUint32 typeA = aPosInfoSideA.PositionClassType();
       
   523 	TUint32 typeB = aPosInfoSideB.PositionClassType();
       
   524 	
       
   525 	// Compare TPositionInfo type items.
       
   526 	if(typeA & typeB & EPositionInfoClass)
       
   527 		{
       
   528 		TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Both positions are of type EPositionInfoClass");
       
   529 		const TPositionInfo& posInfoSideA = reinterpret_cast<const TPositionInfo&>(aPosInfoSideA);
       
   530 		const TPositionInfo& posInfoSideB = reinterpret_cast<const TPositionInfo&>(aPosInfoSideB);
       
   531 		
       
   532 		TPosition posSideA;
       
   533 		TPosition posSideB;
       
   534 		posInfoSideA.GetPosition(posSideA);
       
   535 		posInfoSideB.GetPosition(posSideB);
       
   536 
       
   537 		// Carry out an exact check when comparing items.
       
   538 		if (EExactAccuracy == aCmpAccuracy)
       
   539 			{
       
   540 			TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Comparing positions for exact match");
       
   541 			// Compare latitude. 
       
   542 			if (Math::IsNaN(posSideA.Latitude()) && Math::IsNaN(posSideB.Latitude()))
       
   543 				;
       
   544 			else if (posSideA.Latitude() != posSideB.Latitude())
       
   545 				{
       
   546 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   547 				TESTLOG3(ELogP1, "Latitudes %d and %d respectively", posSideA.Latitude(), posSideB.Latitude());
       
   548 				return EFalse;
       
   549 				}
       
   550 			
       
   551 			// Compare longitude.
       
   552 			if (Math::IsNaN(posSideA.Longitude()) && Math::IsNaN(posSideB.Longitude()))
       
   553 				;
       
   554 			else if (posSideA.Longitude() != posSideB.Longitude())
       
   555 				{
       
   556 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   557 				TESTLOG3(ELogP1, "Longitudes %d and %d respectively", posSideA.Longitude(), posSideB.Longitude());
       
   558 				return EFalse;
       
   559 				}		
       
   560 			
       
   561 			// Compare altitude.
       
   562 			if (Math::IsNaN(posSideA.Altitude()) && Math::IsNaN(posSideB.Altitude()))
       
   563 				;
       
   564 			else if (posSideA.Altitude() != posSideB.Altitude())
       
   565 				{
       
   566 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   567 				TESTLOG3(ELogP1, "Altitudes %d and %d respectively", posSideA.Altitude(), posSideB.Altitude());				
       
   568 				return EFalse;
       
   569 				}
       
   570 			
       
   571 			// Compare datum.
       
   572 			if (posSideA.Datum() != posSideB.Datum())
       
   573 				{
       
   574 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   575 				TESTLOG3(ELogP1, "Datums %d and %d respectively", posSideA.Datum(), posSideB.Datum());				
       
   576 				return EFalse;
       
   577 				}				
       
   578 			
       
   579 			// Compare horizontal accuracy.
       
   580 			if (Math::IsNaN(posSideA.HorizontalAccuracy()) && Math::IsNaN(posSideB.HorizontalAccuracy()))
       
   581 				;
       
   582 			else if (posSideA.HorizontalAccuracy() != posSideB.HorizontalAccuracy())
       
   583 				{
       
   584 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   585 				TESTLOG3(ELogP1, "Horizontal Accuracies %d and %d respectively", posSideA.HorizontalAccuracy(), posSideB.HorizontalAccuracy());				
       
   586 				return EFalse;
       
   587 				}		
       
   588 			
       
   589 			// Compare vertical accuracy.
       
   590 			if (Math::IsNaN(posSideA.VerticalAccuracy()) && Math::IsNaN(posSideB.VerticalAccuracy()))
       
   591 				;
       
   592 			else if (posSideA.VerticalAccuracy() != posSideB.VerticalAccuracy())
       
   593 				{
       
   594 				TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match!");
       
   595 				TESTLOG3(ELogP1, "Vertical Accuracies %d and %d respectively", posSideA.VerticalAccuracy(), posSideB.VerticalAccuracy());				
       
   596 				return EFalse;
       
   597 				}		
       
   598 			}
       
   599 		else
       
   600 			{
       
   601 			// Check latitude + longitude using horz accuracy.
       
   602 			TReal horzAct = posSideA.HorizontalAccuracy(); // Use the verify accuracy value (which is side A).
       
   603 			TReal distance ;			
       
   604 	
       
   605 			TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Comparing positions for 'rough' match");			
       
   606 		//	if(NAN != horzAct)
       
   607 				{
       
   608 				// The following is a temporary patch until TPositionInfo.Distance() is implemented:				
       
   609 /* 
       
   610 	from http://www.movable-type.co.uk/scripts/GIS-FAQ-5.1.html
       
   611 	
       
   612 	presuming a spherical Earth with radius R (see below), and the locations of the two points in spherical coordinates (longitude and latitude) are lon1,lat1 and lon2,lat2 then the
       
   613 
       
   614 	Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159):
       
   615 
       
   616 	dlon = lon2 - lon1
       
   617 	dlat = lat2 - lat1
       
   618 	a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2)
       
   619 	c = 2 * arcsin(min(1,sqrt(a)))
       
   620 	d = R * c
       
   621 
       
   622 	will give mathematically and computationally exact results. 
       
   623 	
       
   624 */				
       
   625 				const TReal pi = 3.141592653589793;
       
   626 				const TReal earthRadius = 6367 * 1000;	// earth radius in metres
       
   627 				
       
   628 				TReal32 latA = posSideA.Latitude() * (pi/180);
       
   629 				TReal32 latB = posSideB.Latitude() * (pi/180);
       
   630 				TReal32 lonA = posSideA.Longitude() * (pi/180);
       
   631 				TReal32 lonB = posSideB.Longitude() * (pi/180);
       
   632 				
       
   633 				TReal dlon = (lonB - lonA);	
       
   634 				TReal dlat = (latB - latA);
       
   635 				TReal sin_half_dlat, sin_half_dlon, coslatA, coslatB;
       
   636 				
       
   637 				Math::Sin(sin_half_dlat, dlat/2);
       
   638 				Math::Sin(sin_half_dlon, dlon/2);
       
   639 				Math::Cos(coslatA, latA);
       
   640 				Math::Cos(coslatB, latB);
       
   641 				
       
   642 				TReal a = (sin_half_dlat * sin_half_dlat) + (coslatA * coslatB * (sin_half_dlon * sin_half_dlon));
       
   643 				TReal sqrt_a;
       
   644 				Math::Sqrt(sqrt_a, a);
       
   645 				TReal arcsinmin;
       
   646 				
       
   647 				TReal min = Min(static_cast<TReal>(1), sqrt_a);
       
   648 				Math::ASin(arcsinmin, min);
       
   649 				
       
   650 				distance = earthRadius * (2 * arcsinmin);
       
   651 				
       
   652 				//__ASSERT_ALWAYS(!Math::IsNaN(distance), User::Panic(_L("Lbs Test Utils"), KErrGeneral));
       
   653 				if(Math::IsNaN(latA) || Math::IsNaN(lonA) || Math::IsNaN(horzAct))
       
   654 					{	
       
   655 					TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match because contains NaNs!");	
       
   656 					return EFalse;			
       
   657 					}
       
   658 				else if(distance > horzAct + 30)	// lrm allow for 30m discrepency for now TO DO figure out whether we should be able to check finer accuracy
       
   659 					{
       
   660 					TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Positions don't match because distance greater than reported accuracy + margin!");
       
   661 					return EFalse;
       
   662 					}
       
   663 				}
       
   664 				
       
   665 			/*	put back later:	
       
   666 			TReal32 horzAct = posSideA.HorizontalAccuracy(); // Use the verify accuracy value (which is side A).
       
   667 			TReal32 distance ;			
       
   668 			
       
   669 			posSideA.Distance(posSideB, distance);
       
   670 			if (distance > horzAct)
       
   671 				return EFalse;
       
   672 		
       
   673 			// Check altitude using vert accuracy.
       
   674 			TReal32 vertAct = posSideA.VerticalAccuracy(); // Use the verify accuracy value (which is side A).
       
   675 			TReal32 height = Abs(posSideA.Altitude() - posSideB.Altitude());
       
   676 			if (height > vertAct)
       
   677 				return EFalse;
       
   678 			*/
       
   679 			
       
   680 			}
       
   681 			
       
   682 		// TODO, we don't compare times, not sure if this is something we would do later on
       
   683 //		if (posSideA.Time() != posSideB.Time())
       
   684 //			return EFalse;
       
   685 		
       
   686 		return ETrue;
       
   687 		}
       
   688 
       
   689 	// Compare TPositionCourseInfo type items.		
       
   690 	if (typeA & typeB & EPositionCourseInfoClass)
       
   691 		{
       
   692 		TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Both positions are of type EPositionCourseInfoClass");
       
   693 		// TODO
       
   694 		}
       
   695 
       
   696 	// Compare TPositionSatelliteInfo type items.
       
   697 	if (typeA & typeB & EPositionSatelliteInfoClass)
       
   698 		{
       
   699 		TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfo() Both positions are of type EPositionSatelliteInfoClass");
       
   700 		// TODO
       
   701 		}
       
   702 
       
   703 /* For extended tests when we have them.
       
   704 	if (infoBase.PositionClassType() & EPositionClassTestExtension)
       
   705 		{
       
   706 		}
       
   707 */
       
   708 	return EFalse;
       
   709 	}
       
   710 	
       
   711 	
       
   712 EXPORT_C TBool T_LbsUtils::Compare_PosInfoArr(RPointerArray<TAny>& aPosInfoArrSideA, RPointerArray<TAny>& aPosInfoArrSideB)
       
   713 	{
       
   714 	return Compare_PosInfoArr(aPosInfoArrSideA, aPosInfoArrSideB, EExactAccuracy);
       
   715 	}
       
   716 
       
   717 EXPORT_C TBool T_LbsUtils::Compare_PosInfoArr(RPointerArray<TAny>& aPosInfoArrSideA, RPointerArray<TAny>& aPosInfoArrSideB, TComparisonAccuracyType aCmpAccuracy)
       
   718 	{
       
   719 	// Only compare items if the arrays are the same size.
       
   720 	if (aPosInfoArrSideA.Count() == aPosInfoArrSideB.Count())
       
   721 		{
       
   722 		TPositionInfoBase* posInfoA;
       
   723 		TPositionInfoBase* posInfoB;
       
   724 		TBool res;
       
   725 		
       
   726 		for (TInt i = 0; i < aPosInfoArrSideA.Count(); ++i)
       
   727 			{
       
   728 			posInfoA = reinterpret_cast<TPositionInfoBase*>(aPosInfoArrSideA[i]);
       
   729 			posInfoB = reinterpret_cast<TPositionInfoBase*>(aPosInfoArrSideB[i]);
       
   730 			
       
   731 			res = Compare_PosInfo(*posInfoA, *posInfoB, aCmpAccuracy);
       
   732 			if (!res)
       
   733 				return EFalse;
       
   734 			}
       
   735 		}
       
   736 	
       
   737 	else
       
   738 		{
       
   739 		TESTLOG(ELogP1, "T_LbsUtils::Compare_PosInfoArr() Failed because different number of positions in arrays being compared!");
       
   740 		return EFalse;
       
   741 		}
       
   742 	return ETrue;
       
   743 	}
       
   744 
       
   745 
       
   746 EXPORT_C void T_LbsUtils::ResetAndDestroy_PosInfoArr(RPointerArray<TAny>& aPosInfoArr)
       
   747 	{
       
   748 		for (TInt i = 0; i < aPosInfoArr.Count(); ++i)
       
   749 			delete aPosInfoArr[i];
       
   750 		aPosInfoArr.Reset();	
       
   751 	}
       
   752 
       
   753 
       
   754 EXPORT_C TPositionModuleId T_LbsUtils::GetNetworkModuleIdL(RPositionServer& aServer)
       
   755 	{
       
   756 	TPositionModuleId modId;
       
   757 
       
   758 	User::LeaveIfError(GetModIdByTechnology(aServer, TPositionModuleInfo::ETechnologyNetwork, modId));
       
   759 	
       
   760 	return modId;
       
   761 	}
       
   762 
       
   763 
       
   764 EXPORT_C TPositionModuleId T_LbsUtils::GetAGpsModuleIdL(RPositionServer& aServer)
       
   765 	{
       
   766 	TPositionModuleId modId;
       
   767 
       
   768 	User::LeaveIfError(GetModIdByTechnology(aServer, (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted), modId));
       
   769 	
       
   770 	return modId;
       
   771 	}
       
   772 	
       
   773 EXPORT_C TPositionModuleId T_LbsUtils::GetBadModuleId()
       
   774 	{
       
   775 	TPositionModuleId modId;
       
   776 	
       
   777 	modId.iUid = BAD_MODULE_ID;
       
   778 		
       
   779 	return modId;
       
   780 	}	
       
   781 
       
   782 
       
   783 EXPORT_C TBool T_LbsUtils::Compare_ModuleInfo(TPositionModuleInfo& aModInfoSideA, TPositionModuleInfo& aModInfoSideB)
       
   784 	{
       
   785 	// Compare all module information items and quality.
       
   786 	
       
   787 	// Compare module id.
       
   788 	if (aModInfoSideA.ModuleId() != aModInfoSideB.ModuleId())
       
   789 		{
       
   790 		return EFalse;
       
   791 		}	
       
   792 
       
   793 	//	Compare is available flag.
       
   794 	if (aModInfoSideA.IsAvailable() != aModInfoSideB.IsAvailable())
       
   795 		{
       
   796 		return EFalse;
       
   797 		}	
       
   798 
       
   799 	// Compare technology type.
       
   800 	if (aModInfoSideA.TechnologyType() != aModInfoSideB.TechnologyType())
       
   801 		{
       
   802 		return EFalse;
       
   803 		}	
       
   804 
       
   805 	//	Compare device location.
       
   806 	if (aModInfoSideA.DeviceLocation() != aModInfoSideB.DeviceLocation())
       
   807 		{
       
   808 		return EFalse;
       
   809 		}	
       
   810 
       
   811 	//	Compare capabilities.
       
   812 	if (aModInfoSideA.Capabilities() != aModInfoSideB.Capabilities())
       
   813 		{
       
   814 		return EFalse;
       
   815 		}	
       
   816 
       
   817 	// Compare each of the family classes. Use min and max enum values.
       
   818 	for (TInt i = EPositionInfoFamily; i <= EPositionUpdateOptionsFamily; i++)
       
   819 		{
       
   820 		if (aModInfoSideA.ClassesSupported(static_cast<TPositionClassFamily>(i)) != aModInfoSideB.ClassesSupported(static_cast<TPositionClassFamily>(i)))
       
   821 			{
       
   822 			return EFalse;
       
   823 			}	
       
   824 		}
       
   825 		
       
   826 	// Compare version.
       
   827 	if ((aModInfoSideA.Version().iMajor != aModInfoSideB.Version().iMajor) ||
       
   828 		(aModInfoSideA.Version().iMinor != aModInfoSideB.Version().iMinor) ||
       
   829 		(aModInfoSideA.Version().iBuild != aModInfoSideB.Version().iBuild))
       
   830 		{
       
   831 		return EFalse;
       
   832 		}	
       
   833 
       
   834 	// Compare module name.
       
   835 	TBuf<KPositionMaxModuleName> modNameSideA;
       
   836 	TBuf<KPositionMaxModuleName> modNameSideB;
       
   837 
       
   838 	aModInfoSideA.GetModuleName(modNameSideA);
       
   839 	aModInfoSideB.GetModuleName(modNameSideB);
       
   840 	if (0 != modNameSideA.Compare(modNameSideB))
       
   841 	{
       
   842 		return EFalse;
       
   843 	}
       
   844 
       
   845 	// Compare module quality.
       
   846 	TPositionQuality qualitySideA;
       
   847 	TPositionQuality qualitySideB;	
       
   848 	
       
   849 	aModInfoSideA.GetPositionQuality(qualitySideA);
       
   850 	aModInfoSideB.GetPositionQuality(qualitySideB);
       
   851 	
       
   852 	return Compare_PositionQuality(qualitySideA, qualitySideB);
       
   853 	}
       
   854 
       
   855 EXPORT_C TBool T_LbsUtils::Compare_ModuleStatus(TPositionModuleStatus& aModStatusSideA, TPositionModuleStatus& aModStatusSideB)
       
   856 	{
       
   857 	// Compare device status.
       
   858 	if (aModStatusSideA.DeviceStatus() != aModStatusSideB.DeviceStatus())
       
   859 		{
       
   860 		return EFalse;
       
   861 		}	
       
   862 
       
   863 	//	Compare quality status.
       
   864 	if (aModStatusSideA.DataQualityStatus() != aModStatusSideB.DataQualityStatus())
       
   865 		{
       
   866 		return EFalse;
       
   867 		}	
       
   868 		
       
   869 	return TRUE;
       
   870 	}
       
   871 	
       
   872 	
       
   873 EXPORT_C TBool Compare_ModuleUpdateOptions(TPositionUpdateOptions& aModUpdateOptsSideA, TPositionUpdateOptions& aModUpdateOptsSideB)
       
   874 	{
       
   875 	// Compare base class items.
       
   876 	if(aModUpdateOptsSideA.PositionClassSize() != aModUpdateOptsSideB.PositionClassSize())
       
   877 		{
       
   878 			return EFalse;
       
   879 		}
       
   880 
       
   881 	if(aModUpdateOptsSideA.PositionClassType() != aModUpdateOptsSideB.PositionClassType())
       
   882 		{
       
   883 			return EFalse;
       
   884 		}
       
   885 	
       
   886 	// Compare interval option.
       
   887 	if(aModUpdateOptsSideA.UpdateInterval() != aModUpdateOptsSideB.UpdateInterval())
       
   888 		{
       
   889 			return EFalse;
       
   890 		}
       
   891 	
       
   892 	// Compare timeout option.
       
   893 	if(aModUpdateOptsSideA.UpdateTimeOut() != aModUpdateOptsSideB.UpdateTimeOut())
       
   894 		{
       
   895 			return EFalse;
       
   896 		}
       
   897 
       
   898 	// Compare maxage option.
       
   899 	if(aModUpdateOptsSideA.MaxUpdateAge() != aModUpdateOptsSideB.MaxUpdateAge())
       
   900 		{
       
   901 			return EFalse;
       
   902 		}
       
   903 
       
   904 	// Compare partial update option.
       
   905 	if(aModUpdateOptsSideA.AcceptPartialUpdates() != aModUpdateOptsSideB.AcceptPartialUpdates()) 
       
   906 		{
       
   907 			return EFalse;
       
   908 		}
       
   909 		
       
   910 	return ETrue;
       
   911 	}
       
   912 
       
   913 
       
   914 EXPORT_C TBool T_LbsUtils::Compare_PositionQuality(TPositionQuality& aQualitySideA, TPositionQuality& aQualitySideB)
       
   915 /** Compare two position quality structures.
       
   916 
       
   917 @param aQualitySideA	
       
   918 @param aQualitySideB	
       
   919 */
       
   920 	{
       
   921 	// Check if each quality contains the same number of assigned quality items.
       
   922 	if (aQualitySideA.HighWaterMark() != aQualitySideB.HighWaterMark())
       
   923 	{
       
   924 		return EFalse;
       
   925 	}
       
   926 	
       
   927 	// Compare each quality item.
       
   928 	TInt endId = aQualitySideA.HighWaterMark();
       
   929 	
       
   930 	for (TInt i = 0; i <= endId; i++)
       
   931 		{
       
   932 		// Element for each side must be defined.
       
   933 		if (!aQualitySideA.IsDefined(i) || !aQualitySideB.IsDefined(i))
       
   934 			{
       
   935 			return EFalse;
       
   936 			}
       
   937 
       
   938 		// Now compare the actual element.
       
   939 		TPositionQualityItem::TResult res;
       
   940 		if (KErrNone != aQualitySideA.Compare(aQualitySideB, i, res))
       
   941 			{
       
   942 			return EFalse;	
       
   943 			}
       
   944 		if (TPositionQualityItem::EIsEqual != res)
       
   945 			{
       
   946 			return EFalse;
       
   947 			}
       
   948 		}
       
   949 
       
   950 	return ETrue;	
       
   951 	}
       
   952 
       
   953 
       
   954 /**
       
   955  *  Verifies that the supplied position is 'reasonable'
       
   956  *
       
   957  */
       
   958 EXPORT_C TBool T_LbsUtils::Verify_PositionIsValid(TPositionInfo& aPosInfo)
       
   959 	{
       
   960 	TBool valid = TRUE;
       
   961 	TPosition pos;
       
   962 	TReal32 alt;
       
   963 	TReal64 lat, longt;
       
   964 	
       
   965 	aPosInfo.GetPosition(pos);
       
   966 	
       
   967 	alt = pos.Altitude();
       
   968 	lat = pos.Latitude();
       
   969 	longt = pos.Longitude();
       
   970 	
       
   971 	// TO DO figure out what values are reasonable here (in Milton somewhere!?)
       
   972 	// We could use the normal verify posinfo stuff, and check to see if the values are roughly equal.
       
   973 	// Either update this func (add a parameter) or new func like the compare posinfo func we have
       
   974 	if(alt == 0 || lat == 0 || longt == 0)
       
   975 		{
       
   976 		valid = FALSE;
       
   977 		}
       
   978 	
       
   979 	
       
   980 	return valid;
       
   981 	}
       
   982 
       
   983 
       
   984 // May not be required.
       
   985 //EXPORT_C void T_LbsUtils::CreateSimpleAssistanceData(/*TLbsAssistanceDataGroup aDataMask, RDataReaderRootBase& aGpsRefTimeReader*/)
       
   986 //	{
       
   987 
       
   988 //	}
       
   989 
       
   990 /** Ensure the simple assistance data is correct. Typically the data is given by the simple
       
   991 	assistance data provider module used by the Net Sim.
       
   992 	
       
   993 @param aRefTimeReader The assistance data reader which holds the reference time data, the 
       
   994 						reader must be opened (use OpenL()) before calling this function.
       
   995 */
       
   996 EXPORT_C TBool T_LbsUtils::VerifySimpleAssistanceData(RUEPositioningGpsReferenceTimeReader& aRefTimeReader)
       
   997 	{    
       
   998 	TUint week;
       
   999 	TUint tow1MSec;	                                            
       
  1000 
       
  1001 	// Access the reference time values.
       
  1002 	aRefTimeReader.GetField(TUEPositioningGpsReferenceTime::EGpsWeek, week);
       
  1003 	aRefTimeReader.GetField(TUEPositioningGpsReferenceTime::EGpsTow1Msec, tow1MSec);
       
  1004 			
       
  1005 	// Verify the reference time values.
       
  1006 	TBool passed = ETrue;
       
  1007 	
       
  1008 	passed &= (week == KAssistanceData_RefTime_Week);
       
  1009 	passed &= (tow1MSec == KAssistanceData_RefTime_Tow1MSec);
       
  1010 
       
  1011 	return passed;
       
  1012 	}
       
  1013 
       
  1014 /** Create the module information depending on module id(i'e either agps_manager or network location manager) 
       
  1015     Fills a module info class/structure with values depending on the module id. 
       
  1016 
       
  1017     @param  aModuleId       module id within the ini file
       
  1018     @param  aModInfo		The modified module info structure.
       
  1019 */
       
  1020 EXPORT_C void T_LbsUtils::Create_ModuleInfoL(TPositionModuleId aModuleId, TPositionModuleInfo& aModInfo)
       
  1021 
       
  1022 	{  
       
  1023 	   TPositionQuality posQuality;
       
  1024 	
       
  1025 	// Use these values if the module is a-gps manager 
       
  1026 		if (aModuleId == (TUid::Uid(APGS_MODINFO_MODULE_ID)))
       
  1027 		 {
       
  1028 		 aModInfo.SetModuleId(TUid::Uid(APGS_MODINFO_MODULE_ID));
       
  1029 	     aModInfo.SetIsAvailable(AGPS_MODINFO_IS_AVAILABLE);
       
  1030 	     aModInfo.SetModuleName(AGPS_MODINFO_MOD_NAME);
       
  1031 	     aModInfo.SetTechnologyType(AGPS_MODINFO_TECHNOLOGY_TYPE);
       
  1032 	     aModInfo.SetDeviceLocation(AGPS_MODINFO_DEVICE_LOCATION);
       
  1033 	     aModInfo.SetCapabilities(AGPS_MODINFO_CAPABILITIES);
       
  1034 	      
       
  1035 	     // Classes Supported - this is a binary bitmap, but support for each class 
       
  1036     	// has to be set individually.
       
  1037 		
       
  1038 	 	TInt supportedClasses = AGPS_MODINFO_CLASSES_SUPPORTED_POSITION_FAMILY; 
       
  1039     	TPositionClassFamily currentClass = EPositionInfoFamily;
       
  1040     	while(currentClass <= EPositionUpdateOptionsFamily)
       
  1041         	{
       
  1042         	aModInfo.SetClassesSupported(currentClass, supportedClasses & 1); 
       
  1043         	supportedClasses >>= 1;
       
  1044         	currentClass = static_cast<TPositionClassFamily>(static_cast<TInt>(currentClass) + 1);   		
       
  1045         	}
       
  1046 	     	     
       
  1047 	     aModInfo.SetVersion(AGPS_MODINFO_VERSION);
       
  1048     	 posQuality.SetTimeToFirstFix(AGPS_MODINFO_TIME_TO_FIRST_FIX);
       
  1049 	     posQuality.SetTimeToNextFix(AGPS_MODINFO_TIME_TO_NEXT_FIX);
       
  1050     	 posQuality.SetHorizontalAccuracy(AGPS_MODINFO_HORIZONTAL_ACCURACY);
       
  1051 	     posQuality.SetVerticalAccuracy(AGPS_MODINFO_VERTICAL_ACCURACY);
       
  1052     	 posQuality.SetCostIndicator(AGPS_MODINFO_COST_INDICATOR);
       
  1053 	     posQuality.SetPowerConsumption(AGPS_MODINFO_POWER_CONSUMPTION);
       
  1054        	 aModInfo.SetPositionQuality(posQuality);
       
  1055       	 }
       
  1056 	
       
  1057 	//need to change after network location manager module is avaliable
       
  1058 	//Use these values if the module is network location manager
       
  1059 	   else if(aModuleId ==(TUid::Uid(NETWORK_MODINFO_MODULE_ID)))
       
  1060 		   {
       
  1061 		   aModInfo.SetModuleId(TUid::Uid(NETWORK_MODINFO_MODULE_ID));
       
  1062 	       aModInfo.SetIsAvailable(NETWORK_MODINFO_IS_AVAILABLE);
       
  1063 	       aModInfo.SetModuleName(NETWORK_MODINFO_MOD_NAME);
       
  1064 	       aModInfo.SetTechnologyType(NETWORK_MODINFO_TECHNOLOGY_TYPE);
       
  1065 	       aModInfo.SetDeviceLocation(NETWORK_MODINFO_DEVICE_LOCATION);
       
  1066 	       aModInfo.SetCapabilities(NETWORK_MODINFO_CAPABILITIES);
       
  1067 	       // Classes Supported - this is a binary bitmap, but support for each class 
       
  1068     	   // has to be set individually.
       
  1069 		
       
  1070 	 	   TInt supportedClasses = NETWORK_MODINFO_CLASSES_SUPPORTED_POSITION_FAMILY; 
       
  1071     	   TPositionClassFamily currentClass = EPositionInfoFamily;
       
  1072     	   while(currentClass <= EPositionUpdateOptionsFamily)
       
  1073         	{
       
  1074         	aModInfo.SetClassesSupported(currentClass, supportedClasses & 1); 
       
  1075         	supportedClasses >>= 1;
       
  1076         	currentClass = static_cast<TPositionClassFamily>(static_cast<TInt>(currentClass) + 1);   		
       
  1077         	}
       
  1078 	      	      
       
  1079 	       aModInfo.SetVersion(NETWORK_MODINFO_VERSION);
       
  1080     	   posQuality.SetTimeToFirstFix(NETWORK_MODINFO_TIME_TO_FIRST_FIX);
       
  1081 	       posQuality.SetTimeToNextFix(NETWORK_MODINFO_TIME_TO_NEXT_FIX);
       
  1082     	   posQuality.SetHorizontalAccuracy(NETWORK_MODINFO_HORIZONTAL_ACCURACY);
       
  1083 	       posQuality.SetVerticalAccuracy(NETWORK_MODINFO_VERTICAL_ACCURACY);
       
  1084     	   posQuality.SetCostIndicator(NETWORK_MODINFO_COST_INDICATOR);
       
  1085 	       posQuality.SetPowerConsumption(NETWORK_MODINFO_POWER_CONSUMPTION); 
       
  1086 	       aModInfo.SetPositionQuality(posQuality);
       
  1087 		  }
       
  1088 	  else
       
  1089 	     {
       
  1090 	       	User::Leave(KErrArgument);
       
  1091 	      
       
  1092 	     }  
       
  1093 	 }
       
  1094 
       
  1095 TInt T_LbsUtils::GetModIdByTechnology(RPositionServer& aServer, TPositionModuleInfo::TTechnologyType aTechnologyType, TPositionModuleId& aModuleId)
       
  1096 /** Searchs for a module which matches the required technology type. Once found the module id of the matched module
       
  1097 	is given. The first module found which supports the technology will be returned.
       
  1098 
       
  1099 @param aServer			A position server. A client must have a connection with the server.
       
  1100 @param aTechnologyType	The technology to match.
       
  1101 @param aModuleId		The returned module id of the module which supports the required technology.
       
  1102 @return					Err code:	KErrNone it module found.
       
  1103 									KErrNotFound if no module is found which matches the required technology.
       
  1104 									Any other system errors.
       
  1105 */
       
  1106 {
       
  1107 	TInt err;
       
  1108 	TUint numMods;
       
  1109 
       
  1110 	err = aServer.GetNumModules(numMods);
       
  1111 	if (KErrNone == err)
       
  1112 		{
       
  1113 		TInt i = 0;
       
  1114 		TPositionModuleInfo	modInfo;
       
  1115 		
       
  1116 		// Look at each module until we find the required technology type.
       
  1117 		while (i < numMods)
       
  1118 			{
       
  1119 			err = aServer.GetModuleInfoByIndex(i, modInfo);
       
  1120 		
       
  1121 			// Found it.
       
  1122 			if (modInfo.TechnologyType() == aTechnologyType && modInfo.IsAvailable())
       
  1123 				{
       
  1124 				aModuleId = modInfo.ModuleId();
       
  1125 				
       
  1126 				return err;
       
  1127 				}
       
  1128 			i++;
       
  1129 			}
       
  1130 		}
       
  1131 		
       
  1132 	else
       
  1133 	{
       
  1134 		return err;
       
  1135 	}
       
  1136 	
       
  1137 	return KErrNotFound;
       
  1138 }
       
  1139 
       
  1140 
       
  1141 /**
       
  1142  * Method for comparing base class member variables in Logevent types
       
  1143  */
       
  1144 TBool T_LbsUtils::Compare_LogBase(const CLbsLogEvent& aLogEventSideA, const CLbsLogEvent& aLogEventSideB)
       
  1145 {
       
  1146 	if(aLogEventSideA.Direction() != aLogEventSideB.Direction())
       
  1147 		return EFalse;
       
  1148 	
       
  1149 	if(aLogEventSideA.EventType() != aLogEventSideB.EventType())
       
  1150 		return EFalse;
       
  1151 	
       
  1152 	if(aLogEventSideA.RequestOutcome() != aLogEventSideB.RequestOutcome())
       
  1153 		return EFalse;
       
  1154 
       
  1155 	if(aLogEventSideA.IsCostInformationAvailable() != aLogEventSideB.IsCostInformationAvailable())
       
  1156 		return EFalse;
       
  1157 	else
       
  1158 		{
       
  1159 		//check cost info for each side
       
  1160 		if(aLogEventSideA.CostInformation() != aLogEventSideB.CostInformation())
       
  1161 		return EFalse;
       
  1162 		}
       
  1163 		
       
  1164 	TPositionInfoBase* sideAPosInfo = reinterpret_cast<TPositionInfoBase*>(aLogEventSideA.PositionInfo());
       
  1165 	TPositionInfoBase* sideBPosInfo = reinterpret_cast<TPositionInfoBase*>(aLogEventSideB.PositionInfo());
       
  1166 	if(sideAPosInfo != NULL)
       
  1167 		{
       
  1168 		// If the actual log has a non-NULL posinfo...
       
  1169 		if((*aLogEventSideA.PositionInfo()).ModuleId() != (*aLogEventSideB.PositionInfo()).ModuleId())
       
  1170 			return EFalse;	
       
  1171 		
       
  1172 		if(!Compare_PosInfo(*aLogEventSideA.PositionInfo(), *aLogEventSideB.PositionInfo()))
       
  1173 			return EFalse;	
       
  1174 		}
       
  1175 		else
       
  1176 		{	
       
  1177 			// else cheach that both sides have NULL
       
  1178 			if(!(sideAPosInfo == NULL && sideBPosInfo == NULL))
       
  1179 				return EFalse;	
       
  1180 		}
       
  1181 		
       
  1182 
       
  1183 
       
  1184 return ETrue;
       
  1185 }
       
  1186 /**
       
  1187  * Method for comparing SelfLocateLog
       
  1188  */
       
  1189 EXPORT_C TBool T_LbsUtils::Compare_SelfLocateLog(const CLbsSelfLocateLogEvent& aSelfLocateLogSideA, const CLbsSelfLocateLogEvent& aSelfLocateLogSideB)
       
  1190 {
       
  1191 	//Compare base class member variables
       
  1192 	if(!Compare_LogBase(aSelfLocateLogSideA, aSelfLocateLogSideB))
       
  1193 		return EFalse;
       
  1194 	
       
  1195 	if(aSelfLocateLogSideA.LocalApp() != aSelfLocateLogSideB.LocalApp())
       
  1196 		return EFalse;
       
  1197 	
       
  1198 	return ETrue;
       
  1199 }
       
  1200 
       
  1201 /**
       
  1202  * Method for comparing NetworkLocateLog
       
  1203  */
       
  1204 EXPORT_C TBool T_LbsUtils::Compare_NetworkLocateLog(const CLbsNetworkLocateLogEvent& aNetworkLocateLogSideA, const CLbsNetworkLocateLogEvent& aNetworkLocateLogSideB)
       
  1205 {
       
  1206 	//Compare base class member variables
       
  1207 	if(!Compare_LogBase(aNetworkLocateLogSideA, aNetworkLocateLogSideB))
       
  1208 		return EFalse;
       
  1209 	
       
  1210 	if(aNetworkLocateLogSideA.LocalApp() != aNetworkLocateLogSideB.LocalApp())
       
  1211 		return EFalse;
       
  1212 	
       
  1213 	return ETrue;
       
  1214 }
       
  1215 
       
  1216 /**
       
  1217  * Method for comparing ExternalLocateLog
       
  1218  */
       
  1219 EXPORT_C TBool T_LbsUtils::Compare_ExternalLocateLog(const CLbsExternalLocateLogEvent& aExternalLocateLogSideA, const CLbsExternalLocateLogEvent& aExternalLocateLogSideB)
       
  1220 {
       
  1221 	//Compare base class member variables
       
  1222 	if(!Compare_LogBase(aExternalLocateLogSideA, aExternalLocateLogSideB))
       
  1223 		return EFalse;
       
  1224 	
       
  1225 	if(!Compare_PosInfo(*aExternalLocateLogSideA.ReferenceLocation(), *aExternalLocateLogSideB.ReferenceLocation()))
       
  1226 			return EFalse;				
       
  1227 	
       
  1228 	if(aExternalLocateLogSideA.RequestOriginator() != aExternalLocateLogSideB.RequestOriginator())
       
  1229 		return EFalse;
       
  1230 	
       
  1231 	if(!Compare_ExternalRequestPrivacyRequestParams(aExternalLocateLogSideA.PrivacyRequestParams(), aExternalLocateLogSideB.PrivacyRequestParams()))
       
  1232 		return EFalse;
       
  1233 	
       
  1234 	if(!Compare_ExternalRequestPrivacyResponseParams(aExternalLocateLogSideA.PrivacyResponseParams(), aExternalLocateLogSideB.PrivacyResponseParams()))
       
  1235 		return EFalse;
       
  1236 	
       
  1237 return ETrue;
       
  1238 }
       
  1239 
       
  1240 
       
  1241 
       
  1242 /**
       
  1243  * Method for comparing X3PLog
       
  1244  */
       
  1245 EXPORT_C TBool T_LbsUtils::Compare_TransmitLocationLog(const CLbsTransmitLocationLogEvent& aX3PLogSideA, const CLbsTransmitLocationLogEvent& aX3PLogSideB)
       
  1246 {
       
  1247 	//Compare base class member variables
       
  1248 	if(!Compare_LogBase(aX3PLogSideA, aX3PLogSideB))
       
  1249 		return EFalse;
       
  1250 	
       
  1251 	if(aX3PLogSideA.X3PApp() != aX3PLogSideB.X3PApp())
       
  1252 		return EFalse;
       
  1253 	
       
  1254 	if(!Compare_Destinations(aX3PLogSideA.Destination(), aX3PLogSideB.Destination()))
       
  1255 		return EFalse;
       
  1256 	
       
  1257 	return ETrue;
       
  1258 }
       
  1259 
       
  1260 
       
  1261 /**
       
  1262  * Method for comparing AssistanceDataLog
       
  1263  */
       
  1264 EXPORT_C TBool T_LbsUtils::Compare_AssistanceDataLog(const CLbsAssistanceDataLogEvent& aAssistanceDataLogSideA, const CLbsAssistanceDataLogEvent& aAssistanceDataLogSideB)
       
  1265 {
       
  1266 	//Compare base class member variables
       
  1267 	if(!Compare_LogBase(aAssistanceDataLogSideA, aAssistanceDataLogSideB))
       
  1268 		return EFalse;
       
  1269 	
       
  1270 	if(aAssistanceDataLogSideA.RequestAssistanceDataType() != aAssistanceDataLogSideB.RequestAssistanceDataType())
       
  1271 		return EFalse;
       
  1272 	
       
  1273 
       
  1274 	if(aAssistanceDataLogSideA.ReceiveAssistanceDataType() != aAssistanceDataLogSideB.ReceiveAssistanceDataType())
       
  1275 		return EFalse;	
       
  1276 	
       
  1277 	return ETrue;
       
  1278 }
       
  1279 
       
  1280 
       
  1281 /**
       
  1282  * Method needed to compare external locate logs.
       
  1283  */
       
  1284 TBool T_LbsUtils::Compare_ExternalRequestPrivacyRequestParams(const TLbsLoggingPrivacyRequestParams& aLogPrivacyRequestParamsSideA, const TLbsLoggingPrivacyRequestParams& aLogPrivacyRequestParamsSideB)
       
  1285 {
       
  1286 	if(aLogPrivacyRequestParamsSideA.iSessionId != aLogPrivacyRequestParamsSideB.iSessionId)
       
  1287 		return EFalse;
       
  1288 	
       
  1289 	if(!Compare_ExternalRequestInfo(aLogPrivacyRequestParamsSideA.iRequestInfo, aLogPrivacyRequestParamsSideB.iRequestInfo))
       
  1290 		return EFalse;
       
  1291 	
       
  1292 	if(!Compare_ExternalRequestPrivacy(aLogPrivacyRequestParamsSideA.iRequestPrivacy, aLogPrivacyRequestParamsSideB.iRequestPrivacy))
       
  1293 		return EFalse;
       
  1294 	
       
  1295 	
       
  1296 	
       
  1297 	return ETrue;
       
  1298 }
       
  1299 
       
  1300 
       
  1301 /**
       
  1302  * Method needed to compare external locate logs.
       
  1303  * Compares TLbsExternalRequestInfo class.
       
  1304  */
       
  1305 TBool T_LbsUtils::Compare_ExternalRequestInfo(const TLbsExternalRequestInfo& aExternalRequestInfoSideA, const TLbsExternalRequestInfo& aExternalRequestInfoSideB)
       
  1306 {
       
  1307 	TLbsRequesterId requesterIdSideA, requesterIdSideB;
       
  1308 	TLbsClientName clientNameSideA, clientNameSideB;
       
  1309 	TLbsClientExternalId clientExternalIdSideA, clientExternalIdSideB;
       
  1310 	
       
  1311 	aExternalRequestInfoSideA.GetRequesterId(requesterIdSideA);
       
  1312 	aExternalRequestInfoSideA.GetClientName(clientNameSideA);
       
  1313 	aExternalRequestInfoSideA.GetClientExternalId(clientExternalIdSideA);	
       
  1314 	
       
  1315 	aExternalRequestInfoSideB.GetRequesterId(requesterIdSideB);
       
  1316 	aExternalRequestInfoSideB.GetClientName(clientNameSideB);
       
  1317 	aExternalRequestInfoSideB.GetClientExternalId(clientExternalIdSideB);	
       
  1318 	
       
  1319 	// If these values are different, then return false
       
  1320 	if(requesterIdSideA.Compare(requesterIdSideB))	// Should return 0 if equal
       
  1321 		return EFalse;
       
  1322 	
       
  1323 	if(clientNameSideA.Compare(clientNameSideB))
       
  1324 		return EFalse;
       
  1325 		
       
  1326 	if(clientExternalIdSideA.Compare(clientExternalIdSideB))
       
  1327 		return EFalse;
       
  1328 	
       
  1329 	
       
  1330 	return ETrue;
       
  1331 }
       
  1332 
       
  1333 
       
  1334 /**
       
  1335  * Method needed to compare external locate logs.
       
  1336  * Compares TLbsNetPosRequestPrivacy class.
       
  1337  */
       
  1338 TBool T_LbsUtils::Compare_ExternalRequestPrivacy(const TLbsNetPosRequestPrivacy& aExternalRequestPrivacySideA, const TLbsNetPosRequestPrivacy& aExternalRequestPrivacySideB)
       
  1339 {
       
  1340 	if(aExternalRequestPrivacySideA.RequestAdvice() != aExternalRequestPrivacySideB.RequestAdvice())
       
  1341 		return EFalse;
       
  1342 	
       
  1343 	if(aExternalRequestPrivacySideA.RequestAction() != aExternalRequestPrivacySideB.RequestAction())
       
  1344 		return EFalse;
       
  1345 	
       
  1346 	return ETrue;
       
  1347 }
       
  1348 
       
  1349 
       
  1350 /**
       
  1351  * Method needed to compare external locate logs.
       
  1352  * Compares TPrivacyResponseParams class.
       
  1353  */
       
  1354 TBool T_LbsUtils::Compare_ExternalRequestPrivacyResponseParams(const TLbsLoggingPrivacyResponseParams& aExternalRequestPrivacyResponseSideA, const TLbsLoggingPrivacyResponseParams& aExternalRequestPrivacyResponseSideB)
       
  1355 {
       
  1356 	if(aExternalRequestPrivacyResponseSideA.iSessionId != aExternalRequestPrivacyResponseSideB.iSessionId)
       
  1357 		return EFalse;
       
  1358 	
       
  1359 	if(aExternalRequestPrivacyResponseSideA.iResult != aExternalRequestPrivacyResponseSideB.iResult)
       
  1360 		return EFalse;
       
  1361 		
       
  1362 	return ETrue;
       
  1363 }
       
  1364 
       
  1365 /**
       
  1366  * Method needed to Transmit to 3rd party destinations
       
  1367  * Compares TDesC16.
       
  1368  */
       
  1369 TBool T_LbsUtils::Compare_Destinations(TDesC16& aDestinationFromRealLog, TDesC16& aDestinationFromExpectedLog)
       
  1370 	{
       
  1371 	if(aDestinationFromRealLog != aDestinationFromExpectedLog)
       
  1372 		return EFalse;
       
  1373 	
       
  1374 	return ETrue;
       
  1375 	}
       
  1376 	
       
  1377