lbsapitest/lbshaitest/lbsclient/lbsapi/src/T_RPositionServerData.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "t_rpositionserverdata.h"
       
    20 
       
    21 /**
       
    22  * Literals for names or values of scriptable parameters and default values.
       
    23  */
       
    24 
       
    25 /**
       
    26  * UID of a position module. Uid for "GPS", "A-GPS" or "NB".
       
    27  * May also be KParameterValueDefault.
       
    28  */
       
    29 _LIT( KModuleId, "ModuleId" );
       
    30 /**
       
    31  * Allowed device status. One of _TDeviceStatus values.
       
    32  * May also be KParameterValueAny.
       
    33  */
       
    34 _LIT( KDeviceStatus, "DeviceStatus" );
       
    35 
       
    36 /**
       
    37  * Allowed device status. One of _TDataQualityStatus values.
       
    38  * May also be KParameterValueAny.
       
    39  */
       
    40 _LIT( KDataQualityStatus, "DataQualityStatus" );
       
    41 /**
       
    42  * A parameter value that means that the parameter is not checked against
       
    43  * any reference value.
       
    44  */
       
    45 _LIT( KParameterValueAny, "Any" );
       
    46 
       
    47 /** A parameter value that means that the system default should be used.*/
       
    48 _LIT( KParameterValueDefault, "Default" );
       
    49 
       
    50 /** A parameter value that means that no value should be used.*/
       
    51 _LIT( KParameterValueNone, "None" );
       
    52 
       
    53 /*@{*/
       
    54 //Command literals 
       
    55 _LIT(KCmdConnect, 							"Connect");
       
    56 _LIT(KCmdClose,	 							"Close");
       
    57 _LIT(KCmdGetModuleInfoByIndex,				"GetModuleInfoByIndex");
       
    58 _LIT(KCmdGetModuleStatus,					"GetModuleStatus");
       
    59 /*@}*/
       
    60 
       
    61 /**
       
    62  * Two phase constructor
       
    63  *
       
    64  * @leave	system wide error
       
    65  */
       
    66 CT_RPositionServerData* CT_RPositionServerData::NewL()
       
    67 	{
       
    68 	CT_RPositionServerData* ret = new (ELeave) CT_RPositionServerData();
       
    69 	CleanupStack::PushL(ret);
       
    70 	ret->ConstructL();
       
    71 	CleanupStack::Pop(ret);
       
    72 	return ret;
       
    73 	}
       
    74 
       
    75 /**
       
    76  * Private constructor. First phase construction
       
    77  */
       
    78 CT_RPositionServerData::CT_RPositionServerData()
       
    79 	:
       
    80 	iPositionServer()
       
    81 	{
       
    82 	}
       
    83 
       
    84 /**
       
    85  * Second phase construction
       
    86  * @internalComponent
       
    87  * @return	N/A
       
    88  * @pre		None
       
    89  * @post	None
       
    90  * @leave	system wide error
       
    91  */
       
    92 void CT_RPositionServerData::ConstructL()
       
    93 	{
       
    94 	}
       
    95 
       
    96 /**
       
    97  * Public destructor
       
    98  */
       
    99 CT_RPositionServerData::~CT_RPositionServerData()
       
   100 	{
       
   101 	DestroyData();
       
   102 	}
       
   103 
       
   104 /**
       
   105  * Return a pointer to the object that the data wraps
       
   106  *
       
   107  * @return	NULL
       
   108  */
       
   109 TAny* CT_RPositionServerData::GetObject()
       
   110 	{
       
   111 	return &iPositionServer;
       
   112 	}
       
   113 
       
   114 /**
       
   115  * Helper Destructor
       
   116  */
       
   117 void CT_RPositionServerData::DestroyData()
       
   118 	{	
       
   119 	}
       
   120 
       
   121 /**
       
   122  * Process a command read from the Ini file
       
   123  * @param aCommand 		   -	The command to process
       
   124  * @param aSection		   -	The section get from the *.ini file of the project T_Wlan
       
   125  * @param aAsyncErrorIndex -	Command index dor async calls to returns errors to
       
   126  * @return TBool		   -    ETrue if the command is process
       
   127  * @leave				   -	system wide error
       
   128  */
       
   129 TBool CT_RPositionServerData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   130 	{
       
   131 	TBool ret = ETrue;
       
   132 	
       
   133 	if (aCommand == KCmdConnect)
       
   134 		{
       
   135 		DoCmdConnect();
       
   136 		}
       
   137 	else if (aCommand == KCmdGetModuleInfoByIndex)
       
   138 		{
       
   139 		DoCmdGetModuleInfoByIndex();
       
   140 		}
       
   141 	else if (aCommand == KCmdGetModuleStatus)
       
   142 		{
       
   143 		DoCmdGetModuleStatus(aSection);
       
   144 		}
       
   145 	else if (aCommand == KCmdClose)
       
   146 		{
       
   147 		DoCmdClose();
       
   148 		}
       
   149 	else
       
   150 		{
       
   151 		ERR_PRINTF1(_L("Unknown command."));
       
   152 		ret=EFalse;
       
   153 		}
       
   154 	return ret;
       
   155 	}
       
   156 
       
   157 /**
       
   158  * This method is used to test opening a session with the position server
       
   159  * (RPositionServer::Connect()).
       
   160  */
       
   161 void CT_RPositionServerData::DoCmdConnect()
       
   162 	{
       
   163 	INFO_PRINTF1(_L("*START*CT_RPositionerData::DoCmdConnectPositionServer"));
       
   164 	TInt err = iPositionServer.Connect();
       
   165 	if (err!=KErrNone)
       
   166 		{
       
   167 		ERR_PRINTF2(_L("Could not connect to position server. Error: %d"), err);
       
   168 		SetError(err);
       
   169 		}
       
   170 	INFO_PRINTF1(_L("*END*CT_RPositionerData::DoCmdConnectPositionServer"));
       
   171 	}
       
   172 
       
   173 /**
       
   174  * This method is used to test closing the client handle to position server
       
   175  * (RPositionServer::Close()).
       
   176  */
       
   177 void CT_RPositionServerData::DoCmdClose()
       
   178 	{
       
   179 	INFO_PRINTF1(_L("*START*CT_RPositionerData::DoCmdClosePositionServer"));
       
   180 	iPositionServer.Close();
       
   181 	INFO_PRINTF1(_L("*END*CT_RPositionerData::DoCmdClosePositionServer"));
       
   182 	}
       
   183 
       
   184 /**
       
   185  * This method is used to test getting the details of the specified module
       
   186  * (RPositionServer::GetModuleInfoByIndex()).
       
   187  */
       
   188 void CT_RPositionServerData::DoCmdGetModuleInfoByIndex()
       
   189 	{
       
   190 	INFO_PRINTF1(_L("*START*CT_RPositionServerData::DoCmdGetModuleInfoByIndex"));
       
   191 	TUint numModules;
       
   192 	TInt err = iPositionServer.GetNumModules(numModules);
       
   193 	if (err!=KErrNone)
       
   194 		{
       
   195 		ERR_PRINTF2(_L("Could not get number of module ID's. Error: %d"), err);
       
   196 		SetError(err);
       
   197 		}
       
   198 	for (TInt i=0;i<numModules;i++)
       
   199 		{
       
   200 		TPositionModuleInfo modInfo;
       
   201 		err = iPositionServer.GetModuleInfoByIndex(i, modInfo);
       
   202 		if(err!=KErrNone)
       
   203 			{
       
   204 			ERR_PRINTF3(_L("Could not get module info at index %d. Error: %d"), i, err);
       
   205 			SetError(err);
       
   206 			}
       
   207 		INFO_PRINTF3(_L("Given position [%d] module id:   %d"), i, modInfo.ModuleId());
       
   208 		TBuf<50> moduleName;
       
   209 		modInfo.GetModuleName(moduleName);
       
   210 		INFO_PRINTF3(_L("Given position [%d] module name: %S"), i, &moduleName);
       
   211 		}
       
   212 	INFO_PRINTF1(_L("*END*CT_RPositionServerData::DoCmdGetModuleInfoByIndex"));
       
   213 	}
       
   214 
       
   215 void CT_RPositionServerData::DoCmdGetModuleStatus(const TTEFSectionName& aSection)
       
   216 	{
       
   217 	INFO_PRINTF1(_L("*START*CT_RPositionServerData::DoCmdGetModuleStatus"));
       
   218 	TBool dataOk=ETrue;
       
   219 
       
   220 	TPtrC16 moduleIdPtr;
       
   221 	if (!GetStringFromConfig(aSection, KModuleId, moduleIdPtr))
       
   222 		{
       
   223 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KModuleId);
       
   224 		SetBlockResult(EFail);
       
   225 		dataOk = EFalse;
       
   226 		}
       
   227 	if(dataOk)
       
   228 		{
       
   229 		if (moduleIdPtr.Compare(KParameterValueDefault)==0)
       
   230 			{
       
   231 			INFO_PRINTF1(_L("Getting default module ID."));
       
   232 			TInt err = iPositionServer.GetDefaultModuleId(iPositionModuleId);
       
   233 			if (err!=KErrNone)
       
   234 				{
       
   235 				ERR_PRINTF2(_L("Could not set requestor. Error: %d"), err);
       
   236 				SetError(err);
       
   237 				}
       
   238 			}
       
   239 		else if (moduleIdPtr.Compare(KParameterValueNone)==0)
       
   240 			{
       
   241 			INFO_PRINTF1(_L("No module ID will be used."));
       
   242 			}
       
   243 		else
       
   244 			{
       
   245 			TInt id;
       
   246 			if (!GetIntFromConfig(aSection, KModuleId, id))
       
   247 				{
       
   248 				ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KModuleId);
       
   249 				SetBlockResult(EFail);
       
   250 				dataOk = EFalse;
       
   251 				}
       
   252 			if(dataOk)
       
   253 				{
       
   254 				INFO_PRINTF2(_L("Using module ID: %d"),id);
       
   255 				iPositionModuleId.iUid = id;
       
   256 				}
       
   257 			}
       
   258 		}
       
   259 	
       
   260 	TPtrC deviceStatusPtr;
       
   261 	if (!GetStringFromConfig(aSection, KDeviceStatus, deviceStatusPtr))
       
   262 		{
       
   263 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDeviceStatus);
       
   264 		SetBlockResult(EFail);
       
   265 		dataOk=EFalse;
       
   266 		}
       
   267 	TPtrC dataQualityStatusPtr;
       
   268 	if (!GetStringFromConfig(aSection, KDataQualityStatus, dataQualityStatusPtr))
       
   269 		{
       
   270 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDataQualityStatus);
       
   271 		SetBlockResult(EFail);
       
   272 		dataOk=EFalse;
       
   273 		}
       
   274 
       
   275 	
       
   276 	if(dataOk)
       
   277 		{
       
   278 		// Verify position module status if needed
       
   279 		if (deviceStatusPtr.Compare(KParameterValueAny) != 0 ||
       
   280 			dataQualityStatusPtr.Compare(KParameterValueAny) != 0)
       
   281 			{
       
   282 			INFO_PRINTF1(_L("Checking device status"));
       
   283 			
       
   284 			TPositionModuleStatus posModuleStatus;
       
   285 			TInt err = iPositionServer.GetModuleStatus(posModuleStatus, iPositionModuleId);
       
   286 			if (err!=KErrNone)
       
   287 				{
       
   288 				ERR_PRINTF2(_L("Could not get module status. Error: %d"), err);
       
   289 				SetError(err);
       
   290 				}
       
   291 
       
   292 			// Verify device status if needed
       
   293 			if (deviceStatusPtr.Compare(KParameterValueAny) != 0)
       
   294 				{
       
   295 				TInt deviceStatus;
       
   296 				if (!GetIntFromConfig(aSection, KDeviceStatus, deviceStatus))
       
   297 					{
       
   298 					ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDeviceStatus);
       
   299 					SetBlockResult(EFail);
       
   300 					dataOk=EFalse;
       
   301 					}
       
   302 				if(dataOk)
       
   303 					{
       
   304 					if (deviceStatus != posModuleStatus.DeviceStatus())
       
   305 						{
       
   306 						ERR_PRINTF1(_L("Actual device status:"));
       
   307 						switch (posModuleStatus.DeviceStatus())
       
   308 							{
       
   309 							case TPositionModuleStatus::EDeviceUnknown:
       
   310 								INFO_PRINTF1(_L("EDeviceUnknown"));
       
   311 								break;
       
   312 							case TPositionModuleStatus::EDeviceError:
       
   313 								INFO_PRINTF1(_L("EDeviceError"));
       
   314 								break;
       
   315 							case TPositionModuleStatus::EDeviceDisabled:
       
   316 								INFO_PRINTF1(_L("EDeviceDisabled"));
       
   317 								break;
       
   318 							case TPositionModuleStatus::EDeviceInactive:
       
   319 								INFO_PRINTF1(_L("EDeviceInactive"));
       
   320 								break;
       
   321 							case TPositionModuleStatus::EDeviceInitialising:
       
   322 								INFO_PRINTF1(_L("EDeviceInitialising"));
       
   323 								break;
       
   324 							case TPositionModuleStatus::EDeviceStandBy:
       
   325 								INFO_PRINTF1(_L("EDeviceStandBy"));
       
   326 								break;
       
   327 							case TPositionModuleStatus::EDeviceReady:
       
   328 								INFO_PRINTF1(_L("EDeviceReady"));
       
   329 								break;
       
   330 							case TPositionModuleStatus::EDeviceActive:
       
   331 								INFO_PRINTF1(_L("EDeviceActive"));
       
   332 								break;
       
   333 							default:
       
   334 								INFO_PRINTF1(_L("Unknown request"));
       
   335 							}
       
   336 						ERR_PRINTF1(_L("Expected device status:"));
       
   337 						switch (deviceStatus)
       
   338 							{
       
   339 							case TPositionModuleStatus::EDeviceUnknown:
       
   340 								INFO_PRINTF1(_L("EDeviceUnknown"));
       
   341 								break;
       
   342 							case TPositionModuleStatus::EDeviceError:
       
   343 								INFO_PRINTF1(_L("EDeviceError"));
       
   344 								break;
       
   345 							case TPositionModuleStatus::EDeviceDisabled:
       
   346 								INFO_PRINTF1(_L("EDeviceDisabled"));
       
   347 								break;
       
   348 							case TPositionModuleStatus::EDeviceInactive:
       
   349 								INFO_PRINTF1(_L("EDeviceInactive"));
       
   350 								break;
       
   351 							case TPositionModuleStatus::EDeviceInitialising:
       
   352 								INFO_PRINTF1(_L("EDeviceInitialising"));
       
   353 								break;
       
   354 							case TPositionModuleStatus::EDeviceStandBy:
       
   355 								INFO_PRINTF1(_L("EDeviceStandBy"));
       
   356 								break;
       
   357 							case TPositionModuleStatus::EDeviceReady:
       
   358 								INFO_PRINTF1(_L("EDeviceReady"));
       
   359 								break;
       
   360 							case TPositionModuleStatus::EDeviceActive:
       
   361 								INFO_PRINTF1(_L("EDeviceActive"));
       
   362 								break;
       
   363 							default:
       
   364 								INFO_PRINTF2(_L("Unknown request: %d"),deviceStatus);
       
   365 							}
       
   366 						ERR_PRINTF1(_L("Actual device status is not equal to the expected value."));
       
   367 						SetBlockResult(EFail);
       
   368 						}
       
   369 					}
       
   370 				}
       
   371 			// Verify data quality status if needed:
       
   372 			if (dataQualityStatusPtr.Compare( KParameterValueAny ) != 0)
       
   373 				{
       
   374 				TInt dataQualityStatus;
       
   375 				if (!GetIntFromConfig(aSection, KDataQualityStatus, dataQualityStatus))
       
   376 					{
       
   377 					ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDataQualityStatus);
       
   378 					SetBlockResult(EFail);
       
   379 					dataOk=EFalse;
       
   380 					}
       
   381 				if(dataOk)
       
   382 					{
       
   383 					if (dataQualityStatus != posModuleStatus.DataQualityStatus())
       
   384 						{
       
   385 						ERR_PRINTF1(_L("Actual data quality status:"));
       
   386 						switch (posModuleStatus.DataQualityStatus())
       
   387 							{
       
   388 							case TPositionModuleStatus::EDataQualityUnknown:
       
   389 								INFO_PRINTF1(_L("EDataQualityUnknown"));
       
   390 								break;
       
   391 							case TPositionModuleStatus::EDataQualityLoss:
       
   392 								INFO_PRINTF1(_L("EDataQualityLoss"));
       
   393 								break;
       
   394 							case TPositionModuleStatus::EDataQualityPartial:
       
   395 								INFO_PRINTF1(_L("EDataQualityPartial"));
       
   396 								break;
       
   397 							case TPositionModuleStatus::EDataQualityNormal:
       
   398 								INFO_PRINTF1(_L("EDataQualityNormal"));
       
   399 								break;
       
   400 							default:
       
   401 								INFO_PRINTF1(_L("Unknown request"));
       
   402 							}
       
   403 						ERR_PRINTF1(_L("Expected data quality status:"));
       
   404 						switch (dataQualityStatus)
       
   405 							{
       
   406 							case TPositionModuleStatus::EDataQualityUnknown:
       
   407 								INFO_PRINTF1(_L("EDataQualityUnknown"));
       
   408 								break;
       
   409 							case TPositionModuleStatus::EDataQualityLoss:
       
   410 								INFO_PRINTF1(_L("EDataQualityLoss"));
       
   411 								break;
       
   412 							case TPositionModuleStatus::EDataQualityPartial:
       
   413 								INFO_PRINTF1(_L("EDataQualityPartial"));
       
   414 								break;
       
   415 							case TPositionModuleStatus::EDataQualityNormal:
       
   416 								INFO_PRINTF1(_L("EDataQualityNormal"));
       
   417 								break;
       
   418 							default:
       
   419 								INFO_PRINTF2(_L("Unknown request: %d"), dataQualityStatus);
       
   420 							}
       
   421 						ERR_PRINTF1(_L("Actual data quality status is not equal to the expected value."));
       
   422 						SetBlockResult(EFail);
       
   423 						}
       
   424 					}
       
   425 				}
       
   426 			}
       
   427 		else
       
   428 			{
       
   429 			INFO_PRINTF1(_L("No need to check device status"));
       
   430 			}
       
   431 		}
       
   432 	INFO_PRINTF1(_L("*END*CT_RPositionServerData::DoCmdGetModuleStatus"));
       
   433 	}
       
   434 
       
   435