locationrequestmgmt/networkrequesthandler/src/x3prequest.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 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 #include <e32std.h>
       
    19 #include <e32test.h>
       
    20 
       
    21 // LBS-specific
       
    22 #include <lbs.h>
       
    23 #include <lbs/lbsx3p.h>
       
    24 #include "lbstimer.h"
       
    25 #include <lbs/lbslocdatasourcegpsbase.h>
       
    26 
       
    27 #include "x3prequest.h"
       
    28 #include "nrhpanic.h"
       
    29 
       
    30 
       
    31 CX3pRequest::CX3pRequest(MX3pRequestObserver* aObserver,
       
    32 						 const TLbsNetSessionIdInt& aSessionId,
       
    33 						 TUint aTransmitPriority) :
       
    34 	iObserver(aObserver),
       
    35 	iSessionId(aSessionId),
       
    36 	iTransmitPriority(aTransmitPriority),
       
    37 	iQualityParametersReceived(EFalse),
       
    38 	iTimerReStarted(EFalse)
       
    39     {
       
    40     }
       
    41 
       
    42 CX3pRequest::~CX3pRequest()
       
    43     {
       
    44 	iTimer->Cancel();
       
    45 	delete iTimer;
       
    46     }
       
    47 
       
    48 CX3pRequest* CX3pRequest::NewL(MX3pRequestObserver* aObserver,
       
    49 							   const TLbsNetSessionIdInt& aSessionId, 
       
    50 							   const TDesC& aDestinationId,
       
    51 							   TUint aTransmitPriority, 
       
    52 							   const TLbsTransmitPositionOptions& aTransmitOptions)
       
    53     {
       
    54 	CX3pRequest* self = new (ELeave) CX3pRequest(aObserver, aSessionId, aTransmitPriority);
       
    55 	CleanupStack::PushL(self);
       
    56 	self->ConstructL(aDestinationId, aTransmitOptions);
       
    57 	CleanupStack::Pop(self);
       
    58 	return(self);		
       
    59     }
       
    60     
       
    61 void CX3pRequest::ConstructL(const TDesC& aDestinationId,
       
    62 							 const TLbsTransmitPositionOptions& aTransmitOptions)
       
    63 	{
       
    64 	iTransmitOptions = aTransmitOptions;
       
    65 	iDestinationId = aDestinationId;
       
    66 	iTimer = CLbsCallbackTimer::NewL(*this);
       
    67 	}
       
    68 
       
    69 void CX3pRequest::StartTimer()
       
    70 	{
       
    71 	if(iTransmitOptions.TimeOut() != 0)
       
    72 		{
       
    73 		iTimer->Cancel();
       
    74 		iTimer->EventAfter(iTransmitOptions.TimeOut(), 1);
       
    75 		}
       
    76 	}
       
    77 	
       
    78 void CX3pRequest::ReStartTimerOnce()
       
    79 	{
       
    80 	if (!iTimerReStarted)
       
    81 		{
       
    82 		StartTimer();
       
    83 		iTimerReStarted = ETrue;
       
    84 		}
       
    85 	}
       
    86 
       
    87 void CX3pRequest::SetRequestQuality(const TLbsNetPosRequestQualityInt& aRequestQuality)
       
    88 	{
       
    89 	iRequestQuality = aRequestQuality;
       
    90 	iQualityParametersReceived = ETrue;
       
    91 	}
       
    92 	
       
    93 TBool CX3pRequest::FixIsAccurate(const TPositionInfo& aPosInfo, TBool aTerminalAssistedPos)
       
    94 	{    
       
    95 	TBool fixIsAccurate = EFalse;
       
    96     
       
    97     if(!iQualityParametersReceived) 
       
    98     	{
       
    99     	// Nothing to compare it against. Assume it's OK
       
   100     	// (Don't think this can happen)
       
   101     	return(ETrue);
       
   102     	}
       
   103     	
       
   104 	// Compare the accuracy to the request values.
       
   105 	TPosition pos;
       
   106 	aPosInfo.GetPosition(pos);
       
   107 
       
   108 	if (pos.HorizontalAccuracy() <= iRequestQuality.MinHorizontalAccuracy() &&
       
   109 		pos.VerticalAccuracy() <= iRequestQuality.MinVerticalAccuracy())
       
   110 		{
       
   111 		fixIsAccurate = ETrue;
       
   112 		}
       
   113 
       
   114 	// For network-calculated position, first check whether the data is valid. If any of 
       
   115 	// longitude, latitude, or horizontal accuracy is missing, or horizontal 
       
   116 	// accuracy is zero, then it's not valid, so there's no point going any 
       
   117 	// further.
       
   118 	if(aTerminalAssistedPos)
       
   119 		{
       
   120 		if (Math::IsNaN(pos.Latitude()) || 
       
   121 			Math::IsNaN(pos.Longitude()) || 
       
   122 			Math::IsNaN(pos.HorizontalAccuracy()) || 
       
   123 			(pos.HorizontalAccuracy() == 0))
       
   124 			{
       
   125 			fixIsAccurate = EFalse;
       
   126 			}
       
   127 		}
       
   128 
       
   129 	return(fixIsAccurate);
       
   130     }
       
   131 
       
   132 const TLbsNetSessionIdInt& CX3pRequest::SessionId()
       
   133     {
       
   134     return(iSessionId);
       
   135     }
       
   136     
       
   137 const TDesC& CX3pRequest::DestinationId()
       
   138     {
       
   139     return(iDestinationId);
       
   140     }
       
   141     
       
   142 TUint CX3pRequest::TransmitPriority()
       
   143     {
       
   144     return(iTransmitPriority);
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------- 
       
   148 // CX3pRequest::OnTimerEventL
       
   149 // Description: The Location Update timer has expired.
       
   150 // Cancel the request, and pass on the response if any has been received,
       
   151 // otherwise report failure.
       
   152 // ----------------------------------------------------------------------------- 
       
   153 //
       
   154 void CX3pRequest::OnTimerEventL(TInt /*aTimerId*/)
       
   155 	{	
       
   156    	iObserver->OnRequestTimeout(iSessionId);
       
   157 	}
       
   158 
       
   159 /** Called if OnTimerEventL leaves */
       
   160 TInt CX3pRequest::OnTimerError(TInt /*aTimerId*/, 
       
   161 								TInt aError)
       
   162 	{
       
   163 	__ASSERT_DEBUG(EFalse, Panic(ENrhPanicX3pTimerError));
       
   164 	return(aError);
       
   165 	}