lbs/lbsclient/src/ctlbsclientstep.cpp
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 CT_LbsClientStep.cpp
       
    15 // This is the class implementation for the LBS Client Test Step Base
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "ctlbsclientstep.h"
       
    20 
       
    21 #include "tlbsutils.h"
       
    22 #include "ctlbsasyncwaiter.h"
       
    23 
       
    24 
       
    25 #define REFPOS_LAT				52.2
       
    26 #define REFPOS_LONG				0.2
       
    27 #define REFPOS_ALT				10
       
    28 #define REFPOS_HORZ_ACCURACY	100
       
    29 #define REFPOS_VERT_ACCURACY	100
       
    30 
       
    31 /**
       
    32  * @return - TVerdict
       
    33  * Implementation of CTestStep base class virtual
       
    34  * It is used for doing all initialisation common to derived classes in here.
       
    35  * Make it being able to leave if there are any errors here as there's no point in
       
    36  * trying to run a test step if anything fails.
       
    37  * The leave will be picked up by the framework.
       
    38  */
       
    39 TVerdict CT_LbsClientStep::doTestStepPreambleL()
       
    40 	{
       
    41 	// Process some common pre setting to test steps then set SetTestStepResult to EFail or Epass.
       
    42 	INFO_PRINTF1(_L(">>CT_LbsClientStep::doTestStepPreambleL()"));
       
    43 	SetTestStepResult(EPass);
       
    44 
       
    45 	return TestStepResult();
       
    46 	}
       
    47 
       
    48 
       
    49 /**
       
    50  * @return - TVerdict
       
    51  * Implementation of CTestStep base class virtual
       
    52  * It is used for doing all after test treatment common to derived classes in here.
       
    53  * Make it being able to leave
       
    54  * The leave will be picked up by the framework.
       
    55  */
       
    56 TVerdict CT_LbsClientStep::doTestStepPostambleL()
       
    57 	{
       
    58 	// Process some common post setting to test steps then set SetTestStepResult to EFail or Epass.
       
    59 	INFO_PRINTF1(_L(">>CT_LbsClientStep::doTestStepPostabmleL()"));
       
    60 
       
    61 	//SetTestStepResult(EPass);  // or EFail
       
    62 	return TestStepResult();
       
    63 	}
       
    64 
       
    65 
       
    66 CT_LbsClientStep::~CT_LbsClientStep()
       
    67 	{
       
    68 	}
       
    69 
       
    70 
       
    71 CT_LbsClientStep::CT_LbsClientStep(CT_LbsClientServer& aParent) : iParent(aParent)
       
    72 	{
       
    73 	}
       
    74 
       
    75 
       
    76 TInt CT_LbsClientStep::DoNotifyUpdateL(TPositionInfoBase& aPosInfo)
       
    77 {
       
    78 	return  GetLocationL(aPosInfo, EDoNotifyPosUpdate);
       
    79 }
       
    80 
       
    81 TInt CT_LbsClientStep::DoLastKnownPosL(TPositionInfoBase& aPosInfo)
       
    82 {
       
    83 	return GetLocationL(aPosInfo, EDoLastKnownPos);
       
    84 }
       
    85 
       
    86 
       
    87 TInt CT_LbsClientStep::GetLocationL(TPositionInfoBase& aPosInfo, TUint32 aNotifyCallType)
       
    88 {
       
    89 	// Use wrapper active object for the async call below.
       
    90 	CT_LbsAsyncWaiter*	waiter = CT_LbsAsyncWaiter::NewL();
       
    91 	CleanupStack::PushL(waiter);
       
    92 
       
    93 	// Set requestor, note we use the same values as DUMMY_REQUESTOR so we don't have
       
    94 	// to include the header file from the test server, to keep code generic when test pos server goes.
       
    95 		
       
    96 	// TODO: NOTE for the new server, there is no requirement to SetRequestor so we can
       
    97 	// remove later.
       
    98 	User::LeaveIfError(iPositioner.SetRequestor(	CRequestor::ERequestorService,
       
    99 													CRequestor::EFormatApplication,
       
   100 													_L("Tom Tom")));
       
   101 
       
   102 	// Determine the position function to call and get the actual position
       
   103 	if (EDoNotifyPosUpdate == aNotifyCallType)
       
   104 		{
       
   105 		iPositioner.NotifyPositionUpdate(aPosInfo, waiter->iStatus);
       
   106 		}
       
   107 	else if (EDoLastKnownPos == aNotifyCallType)
       
   108 		{
       
   109 		iPositioner.GetLastKnownPosition(aPosInfo, waiter->iStatus);
       
   110 		}
       
   111 		
       
   112 	else
       
   113 		User::LeaveIfError(KErrArgument);
       
   114 		
       
   115 	// Wait for and process the result.
       
   116 	waiter->StartAndWait();
       
   117 
       
   118 	TInt err = waiter->Result();
       
   119 	if (KErrNone == err)
       
   120 		{
       
   121 		INFO_PRINTF1(_L("position obtained successfully"));
       
   122 	
       
   123 		const TPositionInfo& posInfo = reinterpret_cast<const TPositionInfo&>(aPosInfo);
       
   124 		
       
   125 
       
   126 		TPosition pos;
       
   127 		posInfo.GetPosition(pos);
       
   128 		TReal32 lat 	= pos.Latitude();
       
   129 		TReal32 lng 	= pos.Longitude();
       
   130 		TReal32 hac  	= pos.HorizontalAccuracy();
       
   131 		TReal vac		= pos.VerticalAccuracy();
       
   132 
       
   133 		INFO_PRINTF2(_L("lat: %f"),lat);
       
   134 		INFO_PRINTF2(_L("lng: %f"),lng);
       
   135 		INFO_PRINTF2(_L("hac: %f"),hac);
       
   136 		INFO_PRINTF2(_L("vac: %f"),vac);
       
   137 
       
   138 		}
       
   139 	else
       
   140 		{
       
   141 		INFO_PRINTF2(_L("position update failed with error %d"), err);
       
   142 		}
       
   143 
       
   144 	CleanupStack::PopAndDestroy(waiter);
       
   145 
       
   146 	return err;
       
   147 }
       
   148 
       
   149 
       
   150 	
       
   151 TInt CT_LbsClientStep::OpenNetSim()
       
   152 	{
       
   153 	// Connect to net sim.
       
   154 	TInt err = iNetSim.ConnectL(NULL);
       
   155 	if (err)
       
   156 		{
       
   157 		return err;
       
   158 		}
       
   159 
       
   160 
       
   161 	// Set the reference position, which also be used for any required verification.
       
   162 	iRefPos.SetCoordinate(REFPOS_LAT, REFPOS_LONG, REFPOS_ALT);
       
   163 	iRefPos.SetAccuracy(REFPOS_HORZ_ACCURACY, REFPOS_VERT_ACCURACY);
       
   164 	iRefPos.SetCurrentTime();
       
   165 
       
   166 	if (!iNetSim.SetReferenceLocation(iRefPos))
       
   167 		{
       
   168 		iNetSim.Close();
       
   169 
       
   170 		return KErrGeneral;
       
   171 		}	
       
   172 		
       
   173 
       
   174 	// Set plugin to use.
       
   175 	TUid pluginUid;
       
   176 	if(iParent.iSharedData->iTestModuleInUse)
       
   177 		{
       
   178 		pluginUid = TUid::Uid(KSimpleAssistanceDataProviderPluginUidValue);
       
   179 		}
       
   180 	else
       
   181 		{
       
   182 		pluginUid = TUid::Uid(KSuplAssistanceDataProviderPluginUidValue);
       
   183 		}
       
   184 	if (!iNetSim.SetAssistanceDataProvider(pluginUid))
       
   185 		{
       
   186 		iNetSim.Close();
       
   187 
       
   188 		return KErrGeneral;
       
   189 		}
       
   190 		
       
   191 	return err;
       
   192 	}
       
   193 
       
   194 void CT_LbsClientStep::SendResetAssistanceData(TLbsAssistanceDataGroup aMask)
       
   195 	{
       
   196 	iNetSim.SendResetAssistanceData(aMask);
       
   197 	}
       
   198 
       
   199 void CT_LbsClientStep::CloseNetSim()
       
   200 	{
       
   201 	iNetSim.Close();	
       
   202 	}