lbs/lbsclient/src/ctlbsclientpostp203.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2001-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 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "ctlbsclientpostp203.h"
       
    20 #include "ctlbsrequester.h"
       
    21 #include <LbsPositionInfo.h>
       
    22 #include <Lbs.h>
       
    23 #include <LbsCommon.h>
       
    24 #include <LbsRequestor.h>
       
    25 #include <EPos_CPosModules.h>
       
    26 #include <EPos_CPosModuleUpdate.h>
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // Constructor.
       
    31 CT_LbsClientPosTp203::CT_LbsClientPosTp203(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    32     {  
       
    33     _LIT(KTestName, "TP203 - Periodic Update, default psy");
       
    34     SetTestStepName(KTestName); 
       
    35     }
       
    36 
       
    37 // Destructor
       
    38 CT_LbsClientPosTp203::~CT_LbsClientPosTp203()
       
    39     {
       
    40     RDebug::Print(_L("CT_LbsClientPosTp203::~CT_LbsClientPosTp203"));
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CPosTp203::CloseTest
       
    45 //
       
    46 // (other items were commented in a header).
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 void CT_LbsClientPosTp203::CloseTest()
       
    50     {
       
    51     RDebug::Print(_L("CT_LbsClientPosTp203::CloseTest"));
       
    52 
       
    53     delete iPeriodicTimer;
       
    54     iPeriodicTimer = NULL;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CPosTp203::StartL
       
    59 //
       
    60 // (other items were commented in a header).
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CT_LbsClientPosTp203::StartL()
       
    64     {
       
    65     const TInt KLongErrorInterval = 3000000;
       
    66     
       
    67 #ifdef __WINS__
       
    68     const TInt KNormalErrorInterval = 1500000;
       
    69 #else
       
    70     const TInt KNormalErrorInterval = 500000;
       
    71 #endif
       
    72     
       
    73     
       
    74     TInt numberOfRuns = 6;
       
    75     TInt normalInterval = 4500000;
       
    76     // Using the same interval as the slow psy (TestPsy3) to make things easy.
       
    77 	TTimeIntervalMicroSeconds interval = TTimeIntervalMicroSeconds(normalInterval);
       
    78     TTimeIntervalMicroSeconds shortInterval = TTimeIntervalMicroSeconds(1500000);
       
    79 
       
    80     // Will happen the first time when default is changed
       
    81     TInt longInterval = 8500000; 
       
    82     TInt errorInterval = KNormalErrorInterval;
       
    83 
       
    84     TInt requestUpdate = normalInterval;
       
    85 
       
    86     RPositionServer	posServer;
       
    87     CleanupClosePushL(posServer);
       
    88 	TInt err = posServer.Connect();
       
    89 	_LIT(KConnectErr, "Error when connecing to EPos server,  %d");
       
    90 	AssertTrueL(err == KErrNone, KConnectErr, err);  
       
    91     
       
    92 	SetupPsyL(iUidMultiPsy);
       
    93 
       
    94     RPositioner positioner;
       
    95     CleanupClosePushL(positioner);
       
    96     err = positioner.Open(posServer); // Use Default PSY
       
    97 	_LIT(KOpenErr, "Error when opening positioner,  %d");
       
    98 	AssertTrueL(err == KErrNone, KOpenErr, err);
       
    99 
       
   100 	TPositionInfo positionInfo = TPositionInfo();
       
   101 	TPositionUpdateOptions posOption;
       
   102 	posOption.SetUpdateInterval(interval);
       
   103 	
       
   104 	err = positioner.SetUpdateOptions(posOption);
       
   105 	_LIT(KUpdateErr, "Error when setting update interval,  %d");
       
   106 	AssertTrueL(err == KErrNone, KUpdateErr, err);
       
   107 
       
   108     _LIT(KService ,"Service");
       
   109 	positioner.SetRequestor(CRequestor::ERequestorService,
       
   110 							 CRequestor::EFormatApplication, KService);
       
   111 
       
   112     // Do a couple of request and check the times between requests.
       
   113     TTime now, startTime;
       
   114     TTimeIntervalMicroSeconds requestTime;
       
   115     _LIT(KErrorRequest, "Error in request");
       
   116     TRequestStatus status;
       
   117     TInt64 reqTime;
       
   118    
       
   119     for (TInt i = 0; i < numberOfRuns; i++)
       
   120         {
       
   121         TBuf<100> info;
       
   122         _LIT(KInfo, "Making request %d");
       
   123     	info.Format(KInfo, i);
       
   124         INFO_PRINTF1(info);
       
   125         if (i == 2)
       
   126             {
       
   127             _LIT(KSetTestPSY3, "Setting up TestPsy3");
       
   128             INFO_PRINTF1(KSetTestPSY3);
       
   129             SetupPsyL(iUidTestPsy3);
       
   130             User::After(1000000);
       
   131             requestUpdate = longInterval;
       
   132             errorInterval = KLongErrorInterval;
       
   133             }
       
   134         else
       
   135             {
       
   136             requestUpdate = normalInterval;
       
   137             errorInterval = KNormalErrorInterval;
       
   138             }
       
   139         
       
   140         _LIT(KWaitStatus1, "Waiting for status after NotifyPositionUpdate1");
       
   141         INFO_PRINTF1(KWaitStatus1);
       
   142         
       
   143         startTime.UniversalTime();
       
   144         positioner.NotifyPositionUpdate(positionInfo, status);
       
   145         User::WaitForRequest(status);
       
   146         now.UniversalTime();
       
   147         
       
   148         err = status.Int();
       
   149         AssertTrueL(err == KErrNone, KErrorRequest, err);
       
   150 
       
   151         requestTime = now.MicroSecondsFrom(startTime);
       
   152         _LIT(KError, "Request time, %d microsecs.");
       
   153         TBuf<100> buf;
       
   154         reqTime = requestTime.Int64();
       
   155         buf.Format(KError, reqTime);
       
   156         INFO_PRINTF1(buf);
       
   157         
       
   158         if (i != 0)
       
   159             {
       
   160             // Check that the time is ok, by accepting an error interval
       
   161             if (reqTime > (requestUpdate + errorInterval) || 
       
   162             	reqTime < (requestUpdate - errorInterval))
       
   163                 {
       
   164                 _LIT(KErrorInterval, "The update is not within valid range");
       
   165                 LogErrorAndLeaveL(KErrorInterval);
       
   166                 }
       
   167             }
       
   168         
       
   169         // Check that position was returned from correct PSY:
       
   170         if (i < 2)
       
   171         	{
       
   172         	VerifyPositionFromL(positionInfo, iUidMultiPsy);
       
   173         	}
       
   174         else
       
   175         	{
       
   176         	VerifyPositionFromL(positionInfo, iUidTestPsy3);
       
   177         	}
       
   178         }
       
   179     
       
   180 	_LIT(KSetUpdateOptions, "Calling SetUpdateOptions");
       
   181 	INFO_PRINTF1(KSetUpdateOptions);
       
   182 	posOption.SetUpdateInterval(shortInterval);
       
   183 	err = positioner.SetUpdateOptions(posOption);
       
   184 	AssertTrueL(err == KErrNone, KUpdateErr, err);
       
   185 
       
   186     // Set up three PSYs the two onces with top priorities supports tracking 
       
   187 	// and the third one does not
       
   188     CPosModules* db = CPosModules::OpenL();
       
   189     CleanupStack::PushL(db);
       
   190     CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
       
   191 
       
   192     _LIT(KSetPriority0, "Enabling Tracking PSY with priority 0");
       
   193 	INFO_PRINTF1(KSetPriority0);
       
   194     moduleUpdate->SetUpdateAvailability(ETrue);
       
   195 	User::After(1000000);
       
   196 	
       
   197     db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate);
       
   198     db->SetModulePriorityL(iUidTestTrackingPsy, 0);
       
   199 	User::After(1000000);
       
   200 	
       
   201 	
       
   202 	
       
   203 	_LIT(KSetPriority1, "Enabling Timer PSY with priority 1");
       
   204 	/*INFO_PRINTF1(KSetPriority1);
       
   205     db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate);
       
   206     db -> SetModulePriorityL(iUidTestTimerPsy, 1);
       
   207 	User::After(1000000);*/
       
   208 
       
   209 	_LIT(KSetPriority2, "Enabling Multi PSY with priority 2");
       
   210 	/*INFO_PRINTF1(KSetPriority2);
       
   211     db->UpdateModuleL(iUidMultiPsy, *moduleUpdate);
       
   212     db -> SetModulePriorityL(iUidMultiPsy, 2);
       
   213     User::After(1000000); // just to let the events happen in the server.*/
       
   214     
       
   215     
       
   216     // Make one request to ensure that Start tracking is called.
       
   217     positioner.NotifyPositionUpdate(positionInfo, status);
       
   218     _LIT(KWaitStatus2, "Waiting for status after NotifyPositionUpdate2");
       
   219     INFO_PRINTF1(KWaitStatus2);
       
   220     RDebug::Print(KWaitStatus2);    
       
   221     User::WaitForRequest(status);
       
   222     err = status.Int();
       
   223     AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err);
       
   224 
       
   225     TPosition pos;
       
   226     positionInfo.GetPosition(pos);    
       
   227     User::After(1000000);
       
   228 
       
   229     // TestTrackingPsy returns 65.0 for Tracking requests and 30.0 for ordinary position requests
       
   230     _LIT(KErrorAndLeave, "Wrong position returned from tracking PSY");
       
   231     if (pos.Latitude() != 65.0 || pos.Longitude() != 65.0 || pos.Altitude() != 65.0)
       
   232         {
       
   233         LogErrorAndLeaveL(KErrorAndLeave);
       
   234         }
       
   235 
       
   236 	INFO_PRINTF1(KSetPriority1);
       
   237     db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate);
       
   238     db -> SetModulePriorityL(iUidTestTimerPsy, 1);
       
   239 	User::After(2000000); // MH move
       
   240 	
       
   241     // Disable the psy with top priority, should result in switch of psy
       
   242     _LIT(KDisablePSY, "Disabling Tracking PSY");
       
   243     INFO_PRINTF1(KDisablePSY);
       
   244     moduleUpdate->SetUpdateAvailability(EFalse);
       
   245     db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate);
       
   246     // To let the events happen in the server.
       
   247     User::After(2000000); 
       
   248     
       
   249     // Make one request to enable tracking
       
   250     positioner.NotifyPositionUpdate(positionInfo, status);
       
   251     _LIT(KWaitStatus4, "Waiting for status after NotifyPositionUpdate4");
       
   252     INFO_PRINTF1(KWaitStatus4);
       
   253     RDebug::Print(KWaitStatus4);    
       
   254     User::WaitForRequest(status);
       
   255     err = status.Int();
       
   256     AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err);
       
   257 
       
   258     positionInfo.GetPosition(pos);
       
   259     
       
   260     // To let the events happen in the server.
       
   261     User::After(2000000);
       
   262         
       
   263     // TestTimerPsy returns 55.0 for Tracking requests and 20.0 for ordinary position requests
       
   264     if (pos.Latitude() != 55.0 || pos.Longitude() != 55.0 || pos.Altitude() != 55.0)
       
   265         {
       
   266         LogErrorAndLeaveL(KErrorAndLeave);
       
   267         }
       
   268 
       
   269     // Enable the psy with top priority, should result in switch back to that psy
       
   270     _LIT(KEnablePSY, "Enabling tracking PSY");
       
   271     INFO_PRINTF1(KEnablePSY);
       
   272     moduleUpdate->SetUpdateAvailability(ETrue);
       
   273     db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate);
       
   274     User::After(2000000); // just to let the events happen in the server.
       
   275 
       
   276 	// To enable tracking    
       
   277     positioner.NotifyPositionUpdate(positionInfo, status);
       
   278     _LIT(KWaitStatus6, "Waiting for status after NotifyPositionUpdate6");
       
   279     INFO_PRINTF1(KWaitStatus6);
       
   280     User::WaitForRequest(status);
       
   281     err = status.Int();
       
   282     AssertTrueL(err == KErrNone || err == KPositionQualityLoss, KErrorRequest, err);
       
   283 
       
   284     // To let the events happen in the server.
       
   285 	User::After(2000000); 
       
   286 
       
   287     positionInfo.GetPosition(pos);
       
   288     // TestTrackingPsy returns 65.0 for Tracking requests and 30.0 for ordinary position requests
       
   289     if (pos.Latitude() != 65.0 || pos.Longitude() != 65.0 || pos.Altitude() != 65.0)
       
   290         {
       
   291         LogErrorAndLeaveL(KErrorAndLeave);
       
   292         }
       
   293     
       
   294 	INFO_PRINTF1(KSetPriority2);
       
   295     db->UpdateModuleL(iUidMultiPsy, *moduleUpdate);
       
   296     db -> SetModulePriorityL(iUidMultiPsy, 2);
       
   297     // To let the events happen in the server. //MH
       
   298     User::After(1000000); 
       
   299 
       
   300     // Disable two psys with top priority that supports tracking.
       
   301     _LIT(KDisableTimer,"Disabling Timer and Tracking PSY");
       
   302     INFO_PRINTF1(KDisableTimer);
       
   303     moduleUpdate->SetUpdateAvailability(EFalse);
       
   304     db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate);
       
   305     db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate);
       
   306     User::After(2000000); // just to let the events happen in the server.
       
   307 
       
   308     positioner.NotifyPositionUpdate(positionInfo, status);
       
   309     _LIT(KWaitStatus8, "Waiting for status after NotifyPositionUpdate8");
       
   310     INFO_PRINTF1(KWaitStatus8);
       
   311     User::WaitForRequest(status);
       
   312     err = status.Int();
       
   313     AssertTrueL(err == KErrNone, KErrorRequest, err);
       
   314 
       
   315     if (iUidMultiPsy.iUid != positionInfo.ModuleId().iUid)
       
   316 		{
       
   317 		_LIT(KIncorrectPsyError,
       
   318            "Position from wrong PSY received");
       
   319 		LogErrorAndLeaveL(KIncorrectPsyError);
       
   320 		}
       
   321 
       
   322     // Disable a PSY during ongoing requesting
       
   323     // Enable the the top three PSYs
       
   324     _LIT(KEnableTimer,"Enabling Timer PSY");
       
   325 	INFO_PRINTF1(KEnableTimer);
       
   326     moduleUpdate->SetUpdateAvailability(ETrue);
       
   327     db->UpdateModuleL(iUidTestTimerPsy, *moduleUpdate);
       
   328     db->UpdateModuleL(iUidTestTrackingPsy, *moduleUpdate);
       
   329     moduleUpdate->SetUpdateAvailability(EFalse);
       
   330     db->UpdateModuleL(iUidMultiPsy, *moduleUpdate);
       
   331     // To let the events happen in the server.
       
   332     User::After(2000000); 
       
   333 
       
   334     const TInt KRequestInterval = 4000000;
       
   335     TCallBack callback(DisablePsyL, this);
       
   336     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
   337     TTimeIntervalMicroSeconds32 disableTime = TTimeIntervalMicroSeconds32(2000000);
       
   338     iPeriodicTimer->Start(disableTime, disableTime, callback);
       
   339     CT_LbsRequester* request = CT_LbsRequester::NewL(this, KRequestInterval, Logger());   // TTF = 0s
       
   340     CleanupStack::PushL(request);
       
   341 
       
   342     // To enable tracking
       
   343     _LIT(KRequest1, "Calling request->StartRequest1");
       
   344     INFO_PRINTF1(KRequest1);
       
   345     request->StartRequest(); // only one request should exist
       
   346 
       
   347     CActiveScheduler::Start();
       
   348 
       
   349     err = request ->CompletionCode();
       
   350     _LIT(KErrCode, "Competion code is not KErrNone");
       
   351     AssertTrueL(err == KErrNone, KErrCode, err);
       
   352 
       
   353     request->GetPositionInfo(positionInfo);
       
   354     User::After(2000000);    
       
   355    
       
   356     // Should get tracking data
       
   357     _LIT(KRequest2, "Calling request->StartRequest2");
       
   358     INFO_PRINTF1(KRequest2);
       
   359     request->StartRequest(); // only one request should exist in reqlog
       
   360 
       
   361     CActiveScheduler::Start();
       
   362 
       
   363     err = request ->CompletionCode();
       
   364     AssertTrueL(err == KErrNone, KErrCode, err);
       
   365 
       
   366     request ->GetPositionInfo(positionInfo);
       
   367     positionInfo.GetPosition(pos);
       
   368 
       
   369     if (iUidTestTimerPsy.iUid != positionInfo.ModuleId().iUid)
       
   370 		{
       
   371 		_LIT(KIncorrectPsyError,
       
   372            "Position from wrong PSY received");
       
   373 		LogErrorAndLeaveL(KIncorrectPsyError);
       
   374 		}
       
   375     // TestTimerPsy returns 55.0 for Tracking requests and 20.0 for ordinary position requests
       
   376     if (pos.Latitude() != 55.0 || pos.Longitude() != 55.0 || pos.Altitude() != 55.0)
       
   377         {
       
   378         LogErrorAndLeaveL(KErrorAndLeave);
       
   379         }
       
   380 
       
   381     _LIT(KSetPSY, "Setting up Tracking PSY");
       
   382 	INFO_PRINTF1(KSetPSY);
       
   383     SetupPsyL(iUidTestTrackingPsy);
       
   384     User::After(1500000); // just to let the events happen in the server.
       
   385 
       
   386     CT_LbsRequester* request2 = CT_LbsRequester::NewL(this, interval, Logger());   // TTF = 0s
       
   387     CleanupStack::PushL(request2);
       
   388 
       
   389     iPeriodicTimer->Start(disableTime, disableTime, callback);
       
   390     _LIT(KRequest3, "Calling request2->StartRequest");
       
   391     INFO_PRINTF1(KRequest3);
       
   392     request2->StartRequest(); // only one request should exist in reqlog
       
   393 
       
   394     CActiveScheduler::Start();
       
   395 
       
   396     err = request2 ->CompletionCode();
       
   397     _LIT(KErrNotFoundCode, "Competion code is not KErrNone");
       
   398     AssertTrueL(err == KErrNone, KErrNotFoundCode, err);
       
   399 
       
   400     CleanupStack::PopAndDestroy(request2);
       
   401     CleanupStack::PopAndDestroy(request);
       
   402     CleanupStack::PopAndDestroy(moduleUpdate);
       
   403     CleanupStack::PopAndDestroy(db);
       
   404 
       
   405     CleanupStack::PopAndDestroy(&positioner);
       
   406     CleanupStack::PopAndDestroy(&posServer);
       
   407     
       
   408     RDebug::Print(_L("CT_LbsClientPosTp203::StartL end"));
       
   409 	}
       
   410 
       
   411 TInt CT_LbsClientPosTp203::DisablePsyL(TAny* aSelf)
       
   412     {
       
   413     // Do not forget to cancel the timer
       
   414     CT_LbsClientPosTp203* self = static_cast<CT_LbsClientPosTp203*> (aSelf);
       
   415     self -> iPeriodicTimer -> Cancel();
       
   416     CPosModules* db = CPosModules::OpenL();
       
   417     CleanupStack::PushL(db);
       
   418     CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
       
   419     moduleUpdate->SetUpdateAvailability(EFalse);
       
   420     TUid trackingId;
       
   421     trackingId.iUid = KUidTestTrackingPsy;
       
   422     db->UpdateModuleL(trackingId, *moduleUpdate);
       
   423     CleanupStack::PopAndDestroy(moduleUpdate);
       
   424     CleanupStack::PopAndDestroy(db);
       
   425     return KErrNone;
       
   426     }
       
   427 
       
   428 void CT_LbsClientPosTp203::RequestCompleteL()
       
   429     {
       
   430     CActiveScheduler::Stop();
       
   431     }
       
   432 
       
   433 // End of File