networkprotocolmodules/networkprotocolmodule/LbsProtocolModule/src/cassistdatamgr.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     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 // This file provides the implementation of the class that manages
       
    15 // assistance data during an active location request.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <lbs/lbsnetcommon.h>
       
    21 #include <lbs/lbsnetprotocolbase.h>
       
    22 #include "cassistdatamgr.h"
       
    23 #include "lbsprotocolmoduleerrors.h"
       
    24 
       
    25 /** Constant to identify an empty set of assistance data.
       
    26 */
       
    27 const TInt KAssistDataEmpty = 0;
       
    28 
       
    29 
       
    30 /** Static constructor.
       
    31 @return A new instance of the CAssistDataMgr class.
       
    32 */  
       
    33 CAssistDataMgr* CAssistDataMgr::NewL()
       
    34 	{
       
    35 	CAssistDataMgr* self = new (ELeave) CAssistDataMgr();
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL();
       
    38 	CleanupStack::Pop(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 
       
    43 /** Standard constructor.
       
    44 */  
       
    45 CAssistDataMgr::CAssistDataMgr()
       
    46 	{
       
    47 	}
       
    48 
       
    49 
       
    50 /** Standard destructor.
       
    51 */  
       
    52 CAssistDataMgr::~CAssistDataMgr()
       
    53 	{
       
    54 	iValidData.Close();
       
    55 	}
       
    56 
       
    57 
       
    58 /** Private second-stage constructor.
       
    59 */  
       
    60 void CAssistDataMgr::ConstructL()
       
    61 	{
       
    62 	iValidData.OpenL();
       
    63 	ResetData();
       
    64 	}
       
    65 
       
    66 
       
    67 /** Valid data content.
       
    68 This is called to retrieve currently stored valid assistance data.
       
    69 @return A reference to the stored RLbsAssistanceDataBuilderSet
       
    70 	containing the valid assistance data.
       
    71 */  
       
    72 const RLbsAssistanceDataBuilderSet& CAssistDataMgr::ValidData()
       
    73 	{
       
    74 	return iValidData;
       
    75 	}
       
    76 
       
    77 
       
    78 /** Retrieve the request data mask to send to the network.
       
    79 This is called to retrieve the data mask for any data that
       
    80 is currently missing and is to be requested from the network.
       
    81 @return A reference to the required set of assistance data.
       
    82 */  
       
    83 const TLbsAsistanceDataGroup& CAssistDataMgr::RequestMask() const
       
    84 	{
       
    85 	return iMissingDataMask;
       
    86 	}
       
    87 
       
    88 
       
    89 /** Retrieve the valid data group mask.
       
    90 This is called to retrieve the data group mask which represents
       
    91 the valid set of data available to be sent to LBS.
       
    92 @return A reference to the valid data group mask.
       
    93 */  
       
    94 const TLbsAsistanceDataGroup& CAssistDataMgr::ValidGroupMask() const
       
    95 	{
       
    96 	return iValidDataMask;
       
    97 	}
       
    98 
       
    99 
       
   100 /** Retrieve the erroneous data group mask.
       
   101 This is called to retrieve the data group mask which represents
       
   102 the erroneous set of data requested by LBS.
       
   103 @return A reference to the erroneous data group mask.
       
   104 */  
       
   105 const TLbsAsistanceDataGroup& CAssistDataMgr::ErrorGroupMask() const
       
   106 	{
       
   107 	return iErrorDataMask;
       
   108 	}
       
   109 
       
   110 
       
   111 /** Retrieve the erroneous request data mask.
       
   112 This is called to retrieve the data mask which represents
       
   113 the erroneous parts of a request from LBS.
       
   114 @return A reference to the erroneous request data mask.
       
   115 */  
       
   116 const TLbsAsistanceDataGroup& CAssistDataMgr::RequestErrorMask() const
       
   117 	{
       
   118 	return iRequestErrorMask;
       
   119 	}
       
   120 
       
   121 
       
   122 /** Indicates if an assistance data error is to be reported to LBS.
       
   123 The protocol manager calls this method when it decides what assistance data
       
   124 actions need to be performed. 
       
   125 @see CProtocolManager::DoAssistanceDataActions()
       
   126 @return TBool ETrue if assistance data error to be reported to LBS.
       
   127 */  
       
   128 TBool CAssistDataMgr::IsErrorToBeReported() const
       
   129 	{
       
   130 	return !(KErrNone == iDataResponseError);
       
   131 	}
       
   132 
       
   133 
       
   134 /** Indicates if assistance data request error to be reported to LBS.
       
   135 The protocol manager calls this method when it decides what assistance data
       
   136 actions need to be performed. 
       
   137 @see CProtocolManager::DoAssistanceDataActions()
       
   138 @return TBool ETrue if assistance data request error to be reported to LBS.
       
   139 */  
       
   140 TBool CAssistDataMgr::IsRequestErrorToBeReported() const
       
   141 	{
       
   142 	return !(KAssistDataEmpty == iRequestErrorMask);
       
   143 	}
       
   144 
       
   145 
       
   146 /** Indicates if assistance data is to be requested from network.
       
   147 The protocol manager calls this method when it decides what assistance data
       
   148 actions need to be performed. 
       
   149 @see CProtocolManager::DoAssistanceDataActions()
       
   150 @return TBool ETrue if data is to be requested from network.
       
   151 */  
       
   152 TBool CAssistDataMgr::IsDataToBeRequested() const
       
   153 	{
       
   154 	// If there is missing data AND not currently expecting a response
       
   155 	// then a request for data is to be requested.
       
   156 	// (Don't re-request data that has already been requested)
       
   157 	return ((KAssistDataEmpty != iMissingDataMask) && !iExpectingResponse);
       
   158 	}
       
   159 
       
   160 
       
   161 
       
   162 /** Indicates if received assistance data is to be reported to LBS.
       
   163 The protocol manager calls this method when it decides what assistance data
       
   164 actions need to be performed. 
       
   165 @see CProtocolManager::DoAssistanceDataActions()
       
   166 @return TBool ETrue if received assistance data is to be reported to LBS.
       
   167 */  
       
   168 TBool CAssistDataMgr::IsDataToBeReported() const
       
   169 	{
       
   170 	return iIsResponseWaiting;
       
   171 	}
       
   172 
       
   173 
       
   174 /** Assistance data error reason value.
       
   175 This is called to retrieve assistance data error reason value.
       
   176 @return TInt Assistance data error reason value.
       
   177 */  
       
   178 TInt CAssistDataMgr::ErrorReason() const
       
   179 	{
       
   180 	return iDataResponseError;
       
   181 	}
       
   182 
       
   183 
       
   184 /** Assistance data response has been sent to LBS.
       
   185 This is called by the protocol manager when it has sent a
       
   186 pending assistance data response to LBS.
       
   187 This resets internal status information to ensure further
       
   188 assistance data actions only occur when necessary.
       
   189 */  
       
   190 void CAssistDataMgr::DataReported()
       
   191 	{
       
   192 	iIsResponseWaiting = EFalse;
       
   193 	}
       
   194 
       
   195 
       
   196 /** Assistance data error response has been sent to LBS.
       
   197 This is called by the protocol manager when it has sent a
       
   198 pending assistance data error response to LBS.
       
   199 This resets internal status information to ensure further
       
   200 assistance data actions only occur when necessary.
       
   201 */  
       
   202 void CAssistDataMgr::ErrorReported()
       
   203 	{
       
   204 	iDataResponseError = KErrNone;
       
   205 	iErrorDataMask = KAssistDataEmpty;
       
   206 	}
       
   207 
       
   208 
       
   209 /** Assistance data request error has been sent to LBS.
       
   210 This is called by the protocol manager when it has sent a
       
   211 pending assistance data request error to LBS.
       
   212 This resets internal status information to ensure further
       
   213 assistance data actions only occur when necessary.
       
   214 */  
       
   215 void CAssistDataMgr::RequestErrorReported()
       
   216 	{
       
   217 	iRequestErrorMask = KAssistDataEmpty;
       
   218 	}
       
   219 
       
   220 
       
   221 /** Assistance data request has been sent to network.
       
   222 This is called by the protocol manager when it has sent a
       
   223 pending assistance data request to the network.
       
   224 This sets internal status information to ensure further
       
   225 assistance data actions only occur as necessary and to identify
       
   226 the set of data that any reported error would relate to.
       
   227 */
       
   228 void CAssistDataMgr::RequestSent()
       
   229 	{
       
   230 	iErrorDataMask = iMissingDataMask;
       
   231 	iMissingDataMask = KAssistDataEmpty;
       
   232 	}
       
   233 
       
   234 
       
   235 /** Assistance data request is being sent to network.
       
   236 This is called by the protocol manager prior to an attempt to
       
   237 sending an assistance data request to the network.
       
   238 This sets internal status information to ensure that a
       
   239 related response is expected.
       
   240 */  
       
   241 void CAssistDataMgr::SendingRequest()
       
   242 	{
       
   243 	iExpectingResponse = ETrue;
       
   244 	}
       
   245 
       
   246 
       
   247 /** Reset data.
       
   248 This is called to initialise the assistance data storage and
       
   249 internal status information that is used to control related
       
   250 assistance data actions.
       
   251 */  
       
   252 void CAssistDataMgr::ResetData()
       
   253 	{
       
   254 	iDataResponseError = KErrNone;
       
   255 	iDataRequestMask = KAssistDataEmpty;
       
   256 	iRequestErrorMask = KAssistDataEmpty;
       
   257 	iMissingDataMask = KAssistDataEmpty;
       
   258 	iErrorDataMask = KAssistDataEmpty;
       
   259 	iValidDataMask = KAssistDataEmpty;
       
   260 	iExpectingResponse = EFalse;
       
   261 	iIsResponseWaiting = EFalse;
       
   262 	iIsDataReported = EFalse;
       
   263 
       
   264 	iValidData.ClearAllBuilders();
       
   265 	}
       
   266 
       
   267 
       
   268 /** Set internal attributes to indicate no data has been received.
       
   269 This is called by the protocol manager when it needs to set the
       
   270 assistance data manager as if there has been no data received yet.
       
   271 This ensures that newly arrived data is reported to LBS even if
       
   272 it was sent during preceding protocol procedures.
       
   273 */  
       
   274 void CAssistDataMgr::SetDataNotReceived()
       
   275 	{
       
   276 	iIsDataReported = EFalse;
       
   277 	}
       
   278 
       
   279 
       
   280 /** Set error reason.
       
   281 This is called to store an error to be reported for the requested
       
   282 assistance data. It is presumed that an error can only be associated
       
   283 with the most recently requested set.
       
   284 
       
   285 @param aReason The assistance data error.
       
   286 */  
       
   287 void CAssistDataMgr::Error(TInt aReason)
       
   288 	{
       
   289 	// Record the error
       
   290 	iDataResponseError = aReason;
       
   291 	if (!iIsDataReported)
       
   292 		{
       
   293 		iIsDataReported = ETrue;
       
   294 		}
       
   295 
       
   296 	// Adjust the data request mask to avoid re-requesting this data
       
   297 	if (KAssistDataEmpty != iDataRequestMask)
       
   298 		{
       
   299 		iDataRequestMask ^= iErrorDataMask;
       
   300 		}
       
   301 
       
   302 	}
       
   303 
       
   304 
       
   305 /** Store assistance data.
       
   306 This is called by the protocol manager when assistance data is received
       
   307 from the network.
       
   308 
       
   309 The data is added to the current stored data and compared with the 
       
   310 requested data to determine if any is missing.
       
   311 
       
   312 The protocol manager (and state machines) must decide when to perform related
       
   313 assistance data actions, according to other prevailing conditions.
       
   314 @see CProtocolManager::DoAssistanceDataActions()
       
   315 
       
   316 @param aData The set of assistance data provided by the network.
       
   317 */
       
   318 void CAssistDataMgr::StoreData(const RLbsAssistanceDataBuilderSet& aData)
       
   319 	{
       
   320 	// Set internal attributes relating to data requests/responses
       
   321 	iExpectingResponse = EFalse;
       
   322 	iIsResponseWaiting = ETrue;
       
   323 	if (!iIsDataReported)
       
   324 		{
       
   325 		iIsDataReported = ETrue;
       
   326 		}
       
   327 
       
   328 	// Add the new data to the stored valid data
       
   329 	TRAPD(error, iValidData.MergeL(const_cast<RLbsAssistanceDataBuilderSet&>(aData)));
       
   330 	if (KErrNone != error)
       
   331 		{
       
   332 		// The merge failed...and this can only be due to a failed memory allocation
       
   333 		// when opening an unopened data model. This should NEVER happen because we
       
   334 		// always open the entire data set during construction.
       
   335 		// So, there is nothing we can do with this error other than attempting
       
   336 		// to request any missing data again.
       
   337 		}
       
   338 
       
   339 	// Identify missing data by comparing the set of stored data with the 
       
   340 	// requested set. The value of iMissingDataMask identifies missing items.
       
   341 	//
       
   342 	// In future this may need to accumulate data which arrives in segments
       
   343 	// before sending it onwards to LBS e.g. Almanac data.
       
   344 
       
   345 	if (iDataRequestMask & EAssistanceDataAlmanac)
       
   346 		{
       
   347 		RUEPositioningGpsAlmanacBuilder* dataItem;
       
   348 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   349 			(!dataItem->IsDataAvailable()))
       
   350 			{
       
   351 			iMissingDataMask |= EAssistanceDataAlmanac;
       
   352 			}
       
   353 		}
       
   354 
       
   355 	if (iDataRequestMask & EAssistanceDataBadSatList)
       
   356 		{
       
   357 		RBadSatListBuilder* dataItem;
       
   358 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   359 			(!dataItem->IsDataAvailable()))
       
   360 			{
       
   361 			iMissingDataMask |= EAssistanceDataBadSatList;
       
   362 			}
       
   363 		}
       
   364 
       
   365 	if (iDataRequestMask & EAssistanceDataIonosphericModel)
       
   366 		{
       
   367 		RUEPositioningGpsIonosphericModelBuilder* dataItem;
       
   368 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   369 			(!dataItem->IsDataAvailable()))
       
   370 			{
       
   371 			iMissingDataMask |= EAssistanceDataIonosphericModel;
       
   372 			}
       
   373 		}
       
   374 
       
   375 	if (iDataRequestMask & EAssistanceDataNavigationModel)
       
   376 		{
       
   377 		RUEPositioningGpsNavigationModelBuilder* dataItem;
       
   378 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   379 			(!dataItem->IsDataAvailable()))
       
   380 			{
       
   381 			iMissingDataMask |= EAssistanceDataNavigationModel;
       
   382 			}
       
   383 		}
       
   384 
       
   385 	if (iDataRequestMask & EAssistanceDataReferenceLocation)
       
   386 		{
       
   387 		RReferenceLocationBuilder* dataItem;
       
   388 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   389 			(!dataItem->IsDataAvailable()))
       
   390 			{
       
   391 			iMissingDataMask |= EAssistanceDataReferenceLocation;
       
   392 			}
       
   393 		}
       
   394 
       
   395 	if (iDataRequestMask & EAssistanceDataReferenceTime)
       
   396 		{
       
   397 		RUEPositioningGpsReferenceTimeBuilder* dataItem;
       
   398 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   399 			(!dataItem->IsDataAvailable()))
       
   400 			{
       
   401 			iMissingDataMask |= EAssistanceDataReferenceTime;
       
   402 			}
       
   403 		}
       
   404 
       
   405 	if (iDataRequestMask & EAssistanceDataPositioningGpsUtcModel)
       
   406 		{
       
   407 		RUEPositioningGpsUtcModelBuilder* dataItem;
       
   408 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   409 			(!dataItem->IsDataAvailable()))
       
   410 			{
       
   411 			iMissingDataMask |= EAssistanceDataPositioningGpsUtcModel;
       
   412 			}
       
   413 		}
       
   414 
       
   415 	if (iDataRequestMask & EAssistanceDataAquisitionAssistance)
       
   416 		{
       
   417 		RUEPositioningGpsAcquisitionAssistanceBuilder* dataItem;
       
   418 		if ((KErrNone != iValidData.GetDataBuilder(dataItem)) ||
       
   419 			(!dataItem->IsDataAvailable()))
       
   420 			{
       
   421 			iMissingDataMask |= EAssistanceDataAquisitionAssistance;
       
   422 			}
       
   423 		}
       
   424 
       
   425 	// Make a note of the current valid set of data
       
   426 	iValidDataMask = 0;
       
   427 	RUEPositioningGpsAlmanacBuilder* dataItem1;
       
   428 	if ((KErrNone == iValidData.GetDataBuilder(dataItem1)) &&
       
   429 		(dataItem1->IsDataAvailable()))
       
   430 		{
       
   431 		iValidDataMask |= EAssistanceDataAlmanac;
       
   432 		}
       
   433 
       
   434 	RBadSatListBuilder* dataItem2;
       
   435 	if ((KErrNone == iValidData.GetDataBuilder(dataItem2)) &&
       
   436 		(dataItem2->IsDataAvailable()))
       
   437 		{
       
   438 		iValidDataMask |= EAssistanceDataBadSatList;
       
   439 		}
       
   440 
       
   441 	RUEPositioningGpsIonosphericModelBuilder* dataItem3;
       
   442 	if ((KErrNone == iValidData.GetDataBuilder(dataItem3)) &&
       
   443 		(dataItem3->IsDataAvailable()))
       
   444 		{
       
   445 		iValidDataMask |= EAssistanceDataIonosphericModel;
       
   446 		}
       
   447 
       
   448 	RUEPositioningGpsNavigationModelBuilder* dataItem4;
       
   449 	if ((KErrNone == iValidData.GetDataBuilder(dataItem4)) &&
       
   450 		(dataItem4->IsDataAvailable()))
       
   451 		{
       
   452 		iValidDataMask |= EAssistanceDataNavigationModel;
       
   453 		}
       
   454 
       
   455 	RReferenceLocationBuilder* dataItem5;
       
   456 	if ((KErrNone == iValidData.GetDataBuilder(dataItem5)) &&
       
   457 		(dataItem5->IsDataAvailable()))
       
   458 		{
       
   459 		iValidDataMask |= EAssistanceDataReferenceLocation;
       
   460 		}
       
   461 
       
   462 	RUEPositioningGpsReferenceTimeBuilder* dataItem6;
       
   463 	if ((KErrNone == iValidData.GetDataBuilder(dataItem6)) &&
       
   464 		(dataItem6->IsDataAvailable()))
       
   465 		{
       
   466 		iValidDataMask |= EAssistanceDataReferenceTime;
       
   467 		}
       
   468 
       
   469 	RUEPositioningGpsUtcModelBuilder* dataItem7;
       
   470 	if ((KErrNone == iValidData.GetDataBuilder(dataItem7)) &&
       
   471 		(dataItem7->IsDataAvailable()))
       
   472 		{
       
   473 		iValidDataMask |= EAssistanceDataPositioningGpsUtcModel;
       
   474 		}
       
   475 
       
   476 	RUEPositioningGpsAcquisitionAssistanceBuilder* dataItem8;
       
   477 	if ((KErrNone == iValidData.GetDataBuilder(dataItem8)) &&
       
   478 		(dataItem8->IsDataAvailable()))
       
   479 		{
       
   480 		iValidDataMask |= EAssistanceDataAquisitionAssistance;
       
   481 		}
       
   482 
       
   483 	}
       
   484 
       
   485 
       
   486 /** Process assistance data request.
       
   487 This is called by the protocol manager to process an assistance data request
       
   488 received from LBS.
       
   489 
       
   490 The method identifies any errors in the request and any new data items to be 
       
   491 requested from the network. If this is a cancellation request then this is 
       
   492 reported in the method return value.
       
   493 
       
   494 The protocol manager (and state machines) must decide when to perform related
       
   495 assistance data actions, according to other prevailing conditions.
       
   496 @see CProtocolManager::DoAssistanceDataActions()
       
   497 
       
   498 @param aDataRequest The set of assistance data requested by LBS.
       
   499 @return TBool ETrue if this request represents a cancellation
       
   500 */
       
   501 TBool CAssistDataMgr::ProcessDataRequest(const TLbsAsistanceDataGroup& aDataRequest)
       
   502 	{
       
   503 	if (KAssistDataEmpty != aDataRequest)
       
   504 		{
       
   505 		// Identify (in)valid parts of the request.
       
   506 		TLbsAsistanceDataGroup validSet = EAssistanceDataAquisitionAssistance
       
   507 										 | EAssistanceDataBadSatList
       
   508 										 | EAssistanceDataNavigationModel
       
   509 										 | EAssistanceDataReferenceTime
       
   510 										 | EAssistanceDataIonosphericModel
       
   511 										 | EAssistanceDataDgpsCorrections
       
   512 										 | EAssistanceDataReferenceLocation
       
   513 										 | EAssistanceDataAlmanac
       
   514 										 | EAssistanceDataPositioningGpsUtcModel;
       
   515 
       
   516 		// Set the request error mask for any invalid parts of the request
       
   517 		iRequestErrorMask |= aDataRequest & ~validSet;
       
   518 
       
   519 		// Identify additional data that must be requested.
       
   520 		// If this is the first set of requested data then we do not
       
   521 		// treat this as missing unless we have received the initial
       
   522 		// set of data (or error) from the network.
       
   523 		if ((KAssistDataEmpty != iDataRequestMask) || (iIsDataReported))
       
   524 			{
       
   525 			iMissingDataMask |= iDataRequestMask ^
       
   526 								(iDataRequestMask | (aDataRequest & validSet));
       
   527 			iMissingDataMask &= (aDataRequest & validSet) ^ 
       
   528 								(iValidDataMask & (aDataRequest & validSet));
       
   529 			}
       
   530 
       
   531 		// Set the data request mask to represent valid items only
       
   532 		iDataRequestMask |= aDataRequest & validSet;
       
   533 
       
   534 		// Make sure that if we do not need to request any new data that we
       
   535 		// pass back any data that is being re-requested as soon as possible
       
   536 		if ((KAssistDataEmpty == iMissingDataMask) && (iValidDataMask & aDataRequest & validSet))
       
   537 			{
       
   538 			iIsResponseWaiting = ETrue;
       
   539 			}
       
   540 
       
   541 		}
       
   542 
       
   543 	return (KAssistDataEmpty == aDataRequest) ? ETrue : EFalse;
       
   544 	}
       
   545