lbs/lbstestutils/inc/ctlbsconfigreader.h
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file ctlbsconfigreader.h
       
    15 // This is the header file which contains the ini file configuration reader classes
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __CT_LBS_CONFIG_READER_H__
       
    20 #define __CT_LBS_CONFIG_READER_H__
       
    21 
       
    22 
       
    23 // Epoc includes
       
    24 #include <e32cmn.h>
       
    25 
       
    26 // LBS includes
       
    27 #include <lbs.h>
       
    28 #include <lbscommon.h>
       
    29 #include <lbspositioninfo.h>
       
    30 #include <LbsLocDataSourceGpsBase.h>
       
    31 
       
    32 // LBS test includes
       
    33 #include "tlbsutils.h"
       
    34 
       
    35 // Forward Declaration
       
    36 
       
    37 
       
    38 
       
    39 const TInt KMaxSentence = 200;
       
    40 const TInt KMaxFields = 20;
       
    41 const TInt KMaxIniFileBuffer = 100;
       
    42 const TInt KMaxConfigReaderIniFileName = 100;
       
    43 
       
    44 class CConfigReaderBase : public CBase
       
    45 	{
       
    46 public:
       
    47     virtual ~CConfigReaderBase();
       
    48 
       
    49 	/** Main entry function which reads the ini file, fills out the data items defined in the
       
    50 		derived classes. Once NewL as been called to construct the object, this should then be
       
    51 		called. */
       
    52 	void ProcessL();
       
    53 
       
    54 protected:
       
    55 	/** Converts a string to a TInt value. */
       
    56 	void ExtractValueL(const TPtrC8& aField, TInt& aValue);
       
    57 	
       
    58 	/** Converts a string to a TReal32 value. */
       
    59 	void ExtractValueL(const TPtrC8& aField, TReal32& aValue);
       
    60 	
       
    61 	/** Converts a string to a TReal64 value. */
       
    62 	void ExtractValueL(const TPtrC8& aField, TReal64& aValue);
       
    63 
       
    64 //	void ExtractDegreesL(const TPtrC8& aField, TReal64& aDegrees); this maybe handy so we can have lat, long in degrees not raw real numbers...
       
    65 //	void ExtractTimeL(const TPtrC8& aTime, TDateTime& aTheTime);
       
    66 //	void ExtractDateL(const TPtrC8& aDate, TDateTime& aTheDate);
       
    67 
       
    68 //	Derived classes provide the implementation.
       
    69 	/** Parses a full sentence read from the ini file. */
       
    70 	virtual void HandleSentenceL()=0;
       
    71 	
       
    72 	/** Fills the data item (detailed in the derived class) with default values. */
       
    73 	virtual void DefaultData()=0;
       
    74 	
       
    75 	/** Fills the data item (detailed in the derived class) with values parsed from the sentence. */
       
    76 	virtual void ExtractDataL()=0;
       
    77 	
       
    78 	CConfigReaderBase(const TDesC &aConfigFileName);
       
    79 	
       
    80 	CConfigReaderBase(const TDesC& aConfigFileName, const TDesC& aConfigSection);
       
    81 	
       
    82 private:
       
    83 	/** Adds valid sentence character to the field. Once the field delimiter is found the field
       
    84 		is appended to the field array. */
       
    85 	void AppendFieldChar(TUint aChar);
       
    86 	
       
    87 	/** Process sentences read from the ini file buffer. A complete valid sentence is passed
       
    88 		to HandeSentenceL() to allow the derived class to process the sentence fields into
       
    89 		it's data items. */
       
    90 	void ProcessStringL(const TDesC8& aData);
       
    91 
       
    92 private:	
       
    93 //	enum TReadState {EWantStart, EWantTerminator};
       
    94 
       
    95 	enum TReadState {/*	EStart, */
       
    96 						EStartSection,
       
    97 						EProcessSection,
       
    98 						EStartSentence,
       
    99 						EProcessSentence,
       
   100 						EHalt};
       
   101 
       
   102 
       
   103 	//const TDesC iConfigFileName;	// can we try this, but we will not be able to add the path
       
   104 	/** Configuration ini filename to open and read. */
       
   105 	TBuf<KMaxConfigReaderIniFileName> iConfigFileName;
       
   106 	TBuf<KMaxSentence> iConfigSection;
       
   107 	
       
   108 	/** State machine variable used while processing a sentence. */
       
   109 	TReadState iReadState;
       
   110 
       
   111 	/** The sentence buffer, to store a valid sentence ready for processing. */
       
   112 	TBuf8<KMaxSentence> iSentence;
       
   113 	
       
   114 
       
   115 	TBuf8<KMaxSentence> iReadSection;
       
   116 
       
   117 protected:
       
   118 	/** Field array. Each field is delimited by a ',' or '*' and will be converted into the
       
   119 		member variable of the data item defined in the derived class. */
       
   120 	TPtrC8 iFields[KMaxFields];
       
   121 	
       
   122 	/** Number of fields in the field array. */
       
   123 	TInt iNumFields;
       
   124 	
       
   125 	/** Where the field starts in the sentence string. */
       
   126 	TInt iFieldStart;
       
   127 	
       
   128 	/** Length of the field. */
       
   129 	TInt iFieldLength;
       
   130 	};
       
   131 
       
   132 
       
   133 
       
   134 // Default values for TPosition,
       
   135 #define DEFAULT_NOTIFY_POS_UPDATE_LATITUDE            49.2
       
   136 #define DEFAULT_NOTIFY_POS_UPDATE_LONGITUDE            3.5
       
   137 #define DEFAULT_NOTIFY_POS_UPDATE_ALTITUDE            50.0
       
   138 #define DEFAULT_NOTIFY_POS_UPDATE_HORIZONTAL_ACCURACY  2.0
       
   139 #define DEFAULT_NOTIFY_POS_UPDATE_VERTICAL_ACCURACY    3.0
       
   140 
       
   141 // TCourse and
       
   142 #define DEFAULT_NOTIFY_POS_UPDATE_SPEED             26.66f
       
   143 #define DEFAULT_NOTIFY_POS_UPDATE_HEADING           25.0
       
   144 #define DEFAULT_NOTIFY_POS_UPDATE_SPEED_ACCURACY    2.0
       
   145 #define DEFAULT_NOTIFY_POS_UPDATE_HEADING_ACCURACY  10.0
       
   146 
       
   147 // TSatelliteData - first satellite
       
   148 #define DEFAULT_NOTIFY_POS_UPDATE_SATELLITE_ID1      10
       
   149 #define DEFAULT_NOTIFY_POS_UPDATE_AZIMUTH1           50.0
       
   150 #define DEFAULT_NOTIFY_POS_UPDATE_ELEVATION1         27.0
       
   151 #define DEFAULT_NOTIFY_POS_UPDATE_IS_USED1           ETrue
       
   152 #define DEFAULT_NOTIFY_POS_UPDATE_SIGNAL_STRENGTH1   4
       
   153 
       
   154 // TSatelliteData - second stellite
       
   155 #define DEFAULT_NOTIFY_POS_UPDATE_SATELLITE_ID2      11
       
   156 #define DEFAULT_NOTIFY_POS_UPDATE_AZIMUTH2           47.0
       
   157 #define DEFAULT_NOTIFY_POS_UPDATE_ELEVATION2         30.0
       
   158 #define DEFAULT_NOTIFY_POS_UPDATE_IS_USED2           EFalse
       
   159 #define DEFAULT_NOTIFY_POS_UPDATE_SIGNAL_STRENGTH2   3
       
   160 
       
   161 
       
   162 
       
   163 
       
   164 class CUpdateConfigReader : public CConfigReaderBase
       
   165 	{
       
   166 public:
       
   167 
       
   168 	enum TUpdateFields
       
   169 		{
       
   170 		EUpdateType = 0,	// Must be present
       
   171 		EUpdateRepeat,
       
   172 		ENumOfMeasurements,
       
   173 
       
   174 		// TCoordinate
       
   175 		EPosLatitude,			/** TCoordinate.iLatitude, TReal64 */
       
   176 		EPosLongitude,			/** TCoordinate.iLongitude, TReal64 */
       
   177 		EPosAltitude,			/** TCoordinate.iAltitude, TReal32 */
       
   178 	
       
   179 		// TLocalitiy
       
   180 		EPosHorzAccuracy,		/** TLocality.iHorizontalAccuracy, TReal32 */
       
   181 		EPosVertAccuracy,		/** TLocality.iVerticalAccuracy, TReal32 */
       
   182 
       
   183 		// Optional
       
   184 		EUpdateErr,
       
   185 		EUpdateDelay			/** Time to delay, can be negative to force early update */
       
   186 	};
       
   187 
       
   188 
       
   189 	static CUpdateConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, RPointerArray<TLbsModuleUpdateItem>& aUpdateArr);
       
   190 
       
   191 protected:
       
   192 	void HandleSentenceL();
       
   193 
       
   194 	void DefaultData();
       
   195 	void ExtractDataL();
       
   196 		
       
   197 private:
       
   198 	CUpdateConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, RPointerArray<TLbsModuleUpdateItem>& aUpdateArr);
       
   199 	void ConstructL();  
       
   200 
       
   201 	RPointerArray<TLbsModuleUpdateItem>& iUpdateArr;
       
   202 	TLbsModuleUpdateItem* iUpdate;
       
   203 	};
       
   204 
       
   205 
       
   206 
       
   207 
       
   208 class CPosInfoConfigReader : public CConfigReaderBase
       
   209 	{
       
   210 public:
       
   211 
       
   212 	enum TPosInfoFields
       
   213 		{
       
   214 		EPosType = 0,	// Must be present
       
   215 		EposRepeat,
       
   216 
       
   217 		// TCoordinate
       
   218 		EPosLatitude,			/** TCoordinate.iLatitude, TReal64 */
       
   219 		EPosLongitude,			/** TCoordinate.iLongitude, TReal64 */
       
   220 		EPosAltitude,			/** TCoordinate.iAltitude, TReal32 */
       
   221 		EPosDatum,				/** TCoordinate.iDatum, TUid */
       
   222 	
       
   223 		// TLocalitiy
       
   224 		EPosHorzAccuracy,		/** TLocality.iHorizontalAccuracy, TReal32 */
       
   225 		EPosVertAccuracy,		/** TLocality.iVerticalAccuracy, TReal32 */
       
   226 	
       
   227 		// TPosition
       
   228 	//	EPosTime,	/** TPosition.iTime, TTime */	// see comment below
       
   229 	
       
   230 		// TCourse
       
   231 		EPosSpeed,				/** TCourse.iSpeed, TReal32 */
       
   232 		EPosHeading,			/** TCourse.iHeading, TReal32 */
       
   233 		EPosSpeedAccuracy,		/** TCourse.iSpeedAccuracy, TReal32 */
       
   234 		EPosHeadingAccuracy,	/** TCourse.iHeadingAccuracy, TReal32 */
       
   235 	};
       
   236 
       
   237 
       
   238 	static CPosInfoConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, RPointerArray<TAny>& aPosInfoArr);
       
   239 
       
   240 protected:
       
   241 	void HandleSentenceL();
       
   242 
       
   243 	void DefaultData();
       
   244 	void ExtractDataL();
       
   245 		
       
   246 private:
       
   247 	CPosInfoConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, RPointerArray<TAny>& aPosInfoArr);
       
   248 	void ConstructL();  
       
   249 
       
   250 	RPointerArray<TAny>& iPosInfoArr;
       
   251 	TPositionInfoBase* iPosInfo;
       
   252 	};
       
   253 
       
   254 
       
   255 
       
   256 /** CModuleStatusConfigReader is a reader class to process module status sentences.
       
   257 	Once processed the aModuleStatus item will be filled with field values held in
       
   258 	the sentence.
       
   259 	
       
   260 	The supported sentence is "modstatus", which MUST start with '$' and end with '*',
       
   261 	fields MUST be delimted by ',' and the sentence MUST NOT contain any white space.
       
   262 
       
   263 	$modstatus,device_field,data_quality_field*
       
   264 
       
   265 		where device_field is one of
       
   266 			device_error
       
   267 			device_disable
       
   268 			device_inactive
       
   269 			device_initialising
       
   270 			device_standby
       
   271 			device_ready
       
   272 			device_active
       
   273 
       
   274 		where data_quality_field is one of 
       
   275 			data_quality_loss
       
   276 			data_quality_partial
       
   277 			data_quality_normal
       
   278 			
       
   279 */
       
   280 class CModuleStatusConfigReader : public CConfigReaderBase
       
   281 	{
       
   282 public:
       
   283 
       
   284 	enum TModuleStatusFields
       
   285 		{
       
   286 		EModuleStatusType = 0,	// Must be present, only 1 type 'modstatus'.
       
   287 
       
   288 		// TPositionModuleStatus fields.
       
   289 		EModuleStatusDevice,		/**	TPositionModuleStatus.iDeviceStatus, TDeviceStatus */
       
   290 		EModuleStatusDataQuality	/** TPositionModuleStatus.iDataQualityStatus, TDataQualityStatus */
       
   291 	};
       
   292 
       
   293 	static CModuleStatusConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, TPositionModuleStatus& aModuleStatus);
       
   294 
       
   295 protected:
       
   296 	/** Converts a string to a TPositionModuleStatus::TDeviceStatus enum value. */
       
   297 	void ExtractValueDevice(const TPtrC8& aField, TPositionModuleStatus::TDeviceStatus& aValue);
       
   298 	
       
   299 	/** Converts a string to a TPositionModuleStatus::TDataQualityStatus enum value. */
       
   300 	void ExtractValueDataQuality(const TPtrC8& aField, TPositionModuleStatus::TDataQualityStatus& aValue);
       
   301 
       
   302 	/** See CConfigReaderBase for comments. */
       
   303 	void HandleSentenceL();
       
   304 	void DefaultData();
       
   305 	void ExtractDataL();
       
   306 	
       
   307 private:
       
   308 	CModuleStatusConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, TPositionModuleStatus& aModuleStatus);
       
   309 
       
   310 	/** Reference to the module status data item to be setup. */
       
   311 	TPositionModuleStatus& iModuleStatus;
       
   312 	};
       
   313 
       
   314 
       
   315 
       
   316 /* and a class reader for module update options
       
   317 updateoptions,100,100,100,false
       
   318 interval,
       
   319 timeout
       
   320 maxage
       
   321 partialupdates
       
   322 */
       
   323 
       
   324 class CUpdateOptsConfigReader : public CConfigReaderBase
       
   325 	{
       
   326 public:
       
   327 
       
   328 	enum TUpdateOptsFields
       
   329 		{
       
   330 		EUpdateOptsType = 0,	// Must be present, only 1 type 'updateoptions'
       
   331 
       
   332 		// TPositionUpdateOptions
       
   333 		EUpdateOptsInterval,		/**	TPositionUpdateOptions.iUpdateInterval, TTimeIntervalMicroSeconds */
       
   334 		EUpdateOptsTimeOut,			/** TPositionUpdateOptions.iUpdateTimeOut, TTimeIntervalMicroSeconds */
       
   335 		EUpdateOptsMaxAge,			/** TPositionUpdateOptions.iMaxUpdateAge, TTimeIntervalMicroSeconds */
       
   336 		EUpdateOptsPartialUpdates	/** TBool TPositionUpdateOptions.iAcceptPartialUpdates, TBool */
       
   337 	};
       
   338 
       
   339 
       
   340 	static CUpdateOptsConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, TPositionUpdateOptions& aUpdateOpts);
       
   341 
       
   342 protected:
       
   343 	/** Converts string to a TTimeIntervalMicroSeconds value. */
       
   344 	void ExtractValueL(const TPtrC8& aField, TTimeIntervalMicroSeconds& aValue);
       
   345 	
       
   346 	/** Converts string to a TBool value. */
       
   347 	void ExtractValue(const TPtrC8& aField, TBool& aValue);
       
   348 
       
   349 	void HandleSentenceL();
       
   350 
       
   351 	void DefaultData();
       
   352 	void ExtractDataL();
       
   353 	
       
   354 private:
       
   355 	CUpdateOptsConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, TPositionUpdateOptions& aUpdateOpts);
       
   356 
       
   357 	TPositionUpdateOptions& iUpdateOpts;
       
   358 	};
       
   359 
       
   360 /*
       
   361  * Class reader for the expected modes in which the module is asked to run
       
   362  */
       
   363 class CAgpsModuleModesConfigReader : public CConfigReaderBase
       
   364 	{
       
   365 private:
       
   366 	enum TModuleModesFields
       
   367 		{
       
   368 		EModuleModesType = 0,			// must be present and needs to be 'modulemodes'
       
   369 		EGpsModeField, 					// the GPS mode
       
   370 		EBegginingOfGpsOptionsArray		// where the array of gps options items starts
       
   371 		};
       
   372 public:
       
   373 	static CAgpsModuleModesConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, 
       
   374 					RPointerArray<TLbsGpsOptions>& aModuleModes);
       
   375 private:
       
   376 	CAgpsModuleModesConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, 
       
   377 					RPointerArray<TLbsGpsOptions>& aModuleModes);
       
   378 	void HandleSentenceL();
       
   379 	
       
   380 	void DefaultData();
       
   381 	void ExtractDataL();
       
   382 
       
   383 private:
       
   384 	RPointerArray<TLbsGpsOptions>& iModuleModes;
       
   385 	};
       
   386 
       
   387 /*
       
   388  * Class reader for details of all clients making requests in a test
       
   389  */
       
   390 class CClientDetailsConfigReader : public CConfigReaderBase
       
   391 	{
       
   392 public:
       
   393 	static CClientDetailsConfigReader* NewL(const TDesC &aConfigFileName, const TDesC& aConfigSection, 
       
   394 					RArray<TCTClientDetails>& aClientDetailsArray);
       
   395 private:
       
   396 	CClientDetailsConfigReader(const TDesC &aConfigFileName, const TDesC& aConfigSection, 
       
   397 					RArray<TCTClientDetails>& aClientDetailsArray);
       
   398 	void HandleSentenceL();
       
   399 	
       
   400 	void DefaultData();
       
   401 	void ExtractDataL();
       
   402 
       
   403 private:
       
   404 	RArray<TCTClientDetails>& iClientDetailsArray;
       
   405 	};
       
   406 #endif //__CT_LBS_CONFIG_READER_H__