networkprotocolmodules/suplprotocolmodule/SuplProtocol/test/src/suplgatewayobserver.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 // Protocol Module gateway observer class implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include "suplgatewayobserver.h"
       
    20 
       
    21 const TInt KGatewayTimerId = 0x10101011;
       
    22 const TInt KGatewayTimerDurationInMicroSec = 1000000;
       
    23 
       
    24 CSuplGatewayObserver* CSuplGatewayObserver::NewL()
       
    25 	{
       
    26 	CSuplGatewayObserver* self = new (ELeave) CSuplGatewayObserver();
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 
       
    34 CSuplGatewayObserver::CSuplGatewayObserver()
       
    35 	{
       
    36 	}
       
    37 
       
    38 
       
    39 CSuplGatewayObserver::~CSuplGatewayObserver()
       
    40 	{
       
    41 	delete iTimer;
       
    42 	delete iScheduler;
       
    43 	}
       
    44 
       
    45 
       
    46 void CSuplGatewayObserver::ConstructL()
       
    47 	{
       
    48 	iScheduler = (CActiveSchedulerWait*) new CActiveSchedulerWait;
       
    49 	iTimer = CLbsCallbackTimer::NewL(*this);
       
    50 	SetDefaultCapabilities();
       
    51 	}
       
    52 
       
    53 
       
    54 void CSuplGatewayObserver::ResetWasObserverCalled()
       
    55 	{
       
    56 	iWasObserverCalled = EFalse;
       
    57 	iCallBackResult = ENone;
       
    58 	}
       
    59 
       
    60 
       
    61 void CSuplGatewayObserver::WaitForCallBack()
       
    62 	{
       
    63 	if (!iWasObserverCalled)
       
    64 		{
       
    65 		iScheduler->Start();
       
    66 		}
       
    67 	}
       
    68 
       
    69 
       
    70 void CSuplGatewayObserver::SignalObserverCallBack(const TCallBackResult aResult)
       
    71 	{
       
    72 	iTimer->Cancel();
       
    73 	iWasObserverCalled = ETrue;
       
    74 	iCallBackResult = aResult;
       
    75 	if (iScheduler->IsStarted())
       
    76 		{
       
    77 		iScheduler->AsyncStop();
       
    78 		}
       
    79 	}
       
    80 
       
    81 
       
    82 TBool CSuplGatewayObserver::WasObserverCalled() const
       
    83 	{
       
    84 	return iWasObserverCalled;
       
    85 	}
       
    86 
       
    87 
       
    88 TInt CSuplGatewayObserver::CallBackResult() const
       
    89 	{
       
    90 	return iCallBackResult;
       
    91 	}
       
    92 
       
    93 
       
    94 TInt CSuplGatewayObserver::AssistanceDataError() const
       
    95 	{
       
    96 	return iAssistanceDataError;
       
    97 	}
       
    98 
       
    99 
       
   100 TLbsAsistanceDataGroup CSuplGatewayObserver::AssistanceDataSetMask() const
       
   101 	{
       
   102 	return iAssistanceDataSetMask;
       
   103 	}
       
   104 	
       
   105 TLbsAsistanceDataGroup CSuplGatewayObserver::AssistanceDataErrorMask() const
       
   106 	{
       
   107 	return iAssistanceDataErrorMask;
       
   108 	}
       
   109 
       
   110 TLbsAsistanceDataGroup CSuplGatewayObserver::ProvidedDataSetMask() const
       
   111 	{
       
   112 	return iProvidedDataSetMask;
       
   113 	}
       
   114 
       
   115 
       
   116 const TLbsNetSessionId& CSuplGatewayObserver::SessionIdValue() const
       
   117 	{
       
   118 	return iSessionIdValue;
       
   119 	}
       
   120 
       
   121 
       
   122 TInt CSuplGatewayObserver::SessionCloseReason() const
       
   123 	{
       
   124 	return iSessionCloseReason;
       
   125 	}
       
   126 
       
   127 
       
   128 TBool CSuplGatewayObserver::IsLocEmergency() const
       
   129 	{
       
   130 	return iLocEmergency;
       
   131 	}
       
   132 
       
   133 
       
   134 const MLbsNetworkProtocolObserver::TLbsNetProtocolService& CSuplGatewayObserver::LocType() const
       
   135 	{
       
   136 	return iLocReqType;
       
   137 	}
       
   138 
       
   139 
       
   140 const TLbsNetPosRequestQuality& CSuplGatewayObserver::LocQuality() const
       
   141 	{
       
   142 	return iLocQuality;
       
   143 	}
       
   144 
       
   145 
       
   146 const TPosition& CSuplGatewayObserver::ReferencePos() const
       
   147 	{
       
   148 	return iReferencePos;
       
   149 	}
       
   150 
       
   151 
       
   152 const TLbsNetPosRequestPrivacy& 
       
   153 	CSuplGatewayObserver::PrivacyNotifType() const
       
   154 	{
       
   155 	return iPrivacyNotifType;
       
   156 	}
       
   157 
       
   158 
       
   159 void CSuplGatewayObserver::RequesterId(TDes8& aId) const
       
   160 	{
       
   161 	iRequestInfo.GetRequesterId(aId);
       
   162 	}
       
   163 
       
   164 TBool CSuplGatewayObserver::IsPrivReqReceived()
       
   165 	{
       
   166 	TBool ret = iPrivReqReceived;
       
   167 	//Clear flag for future tests
       
   168 	//(compiler won't allow to just set to EFalse)
       
   169 	iPrivReqReceived = EFalse;
       
   170 	return ret;
       
   171 	}
       
   172 
       
   173 
       
   174 void CSuplGatewayObserver::GetCurrentCapabilities(TLbsNetPosCapabilities& aCapabilities) const
       
   175 	{
       
   176 	aCapabilities = iCapabilities;
       
   177 	}
       
   178 
       
   179 void CSuplGatewayObserver::SetDefaultCapabilities() 
       
   180 	{
       
   181 	TInt numMethods = 3;
       
   182 	TLbsNetPosMethod posMethods[KLbsMaxNetPosMethods];
       
   183 	posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   184 	posMethods[1].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   185 	posMethods[2].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal);
       
   186 	TInt err = iCapabilities.SetPosMethods(posMethods, numMethods);
       
   187 	}
       
   188 
       
   189 void CSuplGatewayObserver::SetCurrentCapabilities(const TLbsNetPosCapabilities& aCapabilities)
       
   190 	{
       
   191 	iCapabilities = aCapabilities;
       
   192 	}
       
   193 
       
   194 
       
   195 void CSuplGatewayObserver::ProcessStatusUpdate(TLbsNetProtocolServiceMask /*aActiveServiceMask*/)
       
   196 	{
       
   197 #pragma message ("Not using ProcessStatusUpdate")
       
   198 	}
       
   199 
       
   200 
       
   201 void CSuplGatewayObserver::ProcessLocationRequest(const TLbsNetSessionId& aSessionId, TBool aEmergency,
       
   202 	TLbsNetProtocolService aType,
       
   203 	const TLbsNetPosRequestQuality& aQuality,
       
   204 	const TLbsNetPosRequestMethod& aMethod)
       
   205 	{
       
   206 #pragma message ("Not using position request method")
       
   207 	iSessionIdValue = aSessionId;
       
   208 	iLocEmergency = aEmergency;
       
   209 	iLocReqType = aType;
       
   210 	iLocQuality = aQuality;
       
   211 	iMethod = aMethod;
       
   212 	SignalObserverCallBack(EProcessLocationRequest);
       
   213 	}
       
   214 
       
   215 
       
   216 void CSuplGatewayObserver::ProcessSessionComplete(const TLbsNetSessionId& aSessionId, TInt aReason)
       
   217 	{
       
   218 	iSessionIdValue = aSessionId;
       
   219 	iSessionCloseReason = aReason;
       
   220 	SignalObserverCallBack(EProcessSessionComplete);
       
   221 	}
       
   222 
       
   223 
       
   224 void CSuplGatewayObserver::ProcessAssistanceData(TLbsAsistanceDataGroup aDataMask,
       
   225 			const RLbsAssistanceDataBuilderSet& aData, TInt aReason, const TLbsNetSessionIdArray& /*aSessionIdArray*/)
       
   226 	{
       
   227 	
       
   228 	// iAssistanceDataError only stores error reasons
       
   229 	// (do not store KErrNone as sometimes valid assistance data is reported
       
   230 	// straigt after invalid assistance data and that would reset the error 
       
   231 	// reason to KErrNone, which is not what the tests expect).
       
   232 	if (aReason != KErrNone)
       
   233 	{
       
   234 	iAssistanceDataError = aReason;
       
   235 	iAssistanceDataErrorMask = aDataMask;
       
   236 	}
       
   237 
       
   238 
       
   239 	if (aReason == KErrNone)
       
   240 	{
       
   241 	iAssistanceDataSetMask = aDataMask;
       
   242 
       
   243 	RLbsAssistanceDataBuilderSet& localData = const_cast<RLbsAssistanceDataBuilderSet&>(aData);
       
   244 
       
   245 	iProvidedDataSetMask = 0;
       
   246 	RUEPositioningGpsAlmanacBuilder* dataItem;
       
   247 	if ((KErrNone == localData.GetDataBuilder(dataItem)) &&
       
   248 		(dataItem->IsDataAvailable()))
       
   249 		{
       
   250 		iProvidedDataSetMask |= EAssistanceDataAlmanac;
       
   251 		}
       
   252 
       
   253 	RBadSatListBuilder* dataItem1;
       
   254 	if ((KErrNone == localData.GetDataBuilder(dataItem1)) &&
       
   255 		(dataItem1->IsDataAvailable()))
       
   256 		{
       
   257 		iProvidedDataSetMask |= EAssistanceDataBadSatList;
       
   258 		}
       
   259 
       
   260 	RUEPositioningGpsIonosphericModelBuilder* dataItem2;
       
   261 	if ((KErrNone == localData.GetDataBuilder(dataItem2)) &&
       
   262 		(dataItem2->IsDataAvailable()))
       
   263 		{
       
   264 		iProvidedDataSetMask |= EAssistanceDataIonosphericModel;
       
   265 		}
       
   266 
       
   267 	RUEPositioningGpsNavigationModelBuilder* dataItem3;
       
   268 	if ((KErrNone == localData.GetDataBuilder(dataItem3)) &&
       
   269 		(dataItem3->IsDataAvailable()))
       
   270 		{
       
   271 		iProvidedDataSetMask |= EAssistanceDataNavigationModel;
       
   272 		}
       
   273 
       
   274 	RReferenceLocationBuilder* dataItem4;
       
   275 	if ((KErrNone == localData.GetDataBuilder(dataItem4)) &&
       
   276 		(dataItem4->IsDataAvailable()))
       
   277 		{
       
   278 		iProvidedDataSetMask |= EAssistanceDataReferenceLocation;
       
   279 		}
       
   280 
       
   281 	RUEPositioningGpsReferenceTimeBuilder* dataItem5;
       
   282 	if ((KErrNone == localData.GetDataBuilder(dataItem5)) &&
       
   283 		(dataItem5->IsDataAvailable()))
       
   284 		{
       
   285 		iProvidedDataSetMask |= EAssistanceDataReferenceTime;
       
   286 		}
       
   287 
       
   288 	RUEPositioningGpsUtcModelBuilder* dataItem6;
       
   289 	if ((KErrNone == localData.GetDataBuilder(dataItem6)) &&
       
   290 		(dataItem6->IsDataAvailable()))
       
   291 		{
       
   292 		iProvidedDataSetMask |= EAssistanceDataPositioningGpsUtcModel;
       
   293 		}
       
   294 
       
   295 	RUEPositioningGpsAcquisitionAssistanceBuilder* dataItem7;
       
   296 	if ((KErrNone == localData.GetDataBuilder(dataItem7)) &&
       
   297 		(dataItem7->IsDataAvailable()))
       
   298 		{
       
   299 		iProvidedDataSetMask |= EAssistanceDataAquisitionAssistance;
       
   300 		}
       
   301 	}
       
   302 
       
   303 	SignalObserverCallBack(EProcessAssistanceData);
       
   304 	}
       
   305 
       
   306 
       
   307 void CSuplGatewayObserver::ProcessLocationUpdate(const TLbsNetSessionId& aSessionId, 
       
   308 									const TPositionInfoBase& aLocation)
       
   309 	{
       
   310 	iSessionIdValue = aSessionId;
       
   311 	reinterpret_cast <const TPositionInfo&> (aLocation).GetPosition(iReferencePos);
       
   312 	SignalObserverCallBack(EProcessLocationUpdate);
       
   313 	
       
   314 	
       
   315 	// When Reference Location is reported by SUPL, assistance data are reported straight
       
   316 	// after, overwritting this callback's result. This flag is an additional way to remember
       
   317 	// that ProcessLocationUpdate has been called and should only be checked after receiving
       
   318 	// assistance data when reference location was expected.
       
   319 	iRefLocNotified = ETrue;
       
   320 	}
       
   321 
       
   322 
       
   323 void CSuplGatewayObserver::ProcessPrivacyRequest(const TLbsNetSessionId& aSessionId, TBool /*aEmergency*/, 
       
   324 									const TLbsNetPosRequestPrivacy& aNotification,
       
   325 									const TLbsExternalRequestInfo& aRequestInfo)
       
   326 	{
       
   327 	iPrivReqReceived = ETrue;
       
   328 	
       
   329 	iSessionIdValue = aSessionId;
       
   330 	iPrivacyNotifType = aNotification;
       
   331 	iRequestInfo = aRequestInfo;
       
   332 	SignalObserverCallBack(EProcessPrivacyRequest);
       
   333 	}
       
   334 
       
   335 /** Handle a timeout
       
   336 */
       
   337 void CSuplGatewayObserver::OnTimerEventL(TInt aTimerId)
       
   338 	{
       
   339 	if (KGatewayTimerId == aTimerId)
       
   340 		{
       
   341 		SignalObserverCallBack(ETimeout);
       
   342 		}	
       
   343 	}
       
   344 
       
   345 /** Handle a timer error
       
   346 */
       
   347 TInt CSuplGatewayObserver::OnTimerError(TInt aTimerId, TInt aError)
       
   348 	{
       
   349 	(void)aError;
       
   350 	
       
   351 	if (KGatewayTimerId == aTimerId)
       
   352 		{
       
   353 		SignalObserverCallBack(ETimerError);
       
   354 		}
       
   355 	return aError;
       
   356 	}
       
   357 
       
   358 TBool CSuplGatewayObserver::IsMoreObserverActivity()
       
   359 	{
       
   360 	TBool ret;
       
   361 	ResetWasObserverCalled();
       
   362 	iTimer->EventAfter(TTimeIntervalMicroSeconds32(KGatewayTimerDurationInMicroSec),KGatewayTimerId);
       
   363 	WaitForCallBack();
       
   364 	ret = ETimeout == CallBackResult()? EFalse : ETrue;
       
   365 	ResetWasObserverCalled();
       
   366 	return ret;
       
   367 	}
       
   368 
       
   369 
       
   370 TBool CSuplGatewayObserver::IsRefLocNotified()
       
   371 {
       
   372 	return iRefLocNotified;
       
   373 }